DF-3178 / mount_ro.c
/* * DF-3178 — mount helper (read-only HPFS mount with direct mount(2)). * * Same pattern as the DF-3141 pack's mount_rw.c: base-system * mount_hpfs(8) forces MNT_RDONLY anyway, but we call mount(2) directly * so we control the flags; we keep MNT_RDONLY here so bmdeinit skips the * bitmap write-back and the demo is purely about the mount-time wiring. * * Usage: ./mount_ro /dev/vn0 /mnt * Build: cc -O2 -I/usr/src/sys -o mount_ro mount_ro.c (root only) */ #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; } |