#include <sys/types.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <ufs/ufs/ufsmount.h>
#include <err.h>
#include <mntopts.h>
#include <puffs.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <rump/p2k.h>
#include <rump/ukfs.h>
const struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_NULL,
};
static void
usage(void)
{
fprintf(stderr, "%s: [-o args] fspec mountpoint\n", getprogname());
exit(1);
}
static struct mfs_args args;
static char *mntpath, *mntfile;
static int mntflags, altflags;
int
main(int argc, char *argv[])
{
struct stat sb;
mntoptparse_t mp;
void *membase;
int ch, fd, rdonly, shared;
setprogname(argv[0]);
puffs_unmountonsignal(SIGINT, true);
puffs_unmountonsignal(SIGTERM, true);
shared = mntflags = altflags = 0;
memset(&args, 0, sizeof(args));
while ((ch = getopt(argc, argv, "o:s")) != -1) {
switch (ch) {
case 'o':
mp = getmntopts(optarg, mopts, &mntflags, &altflags);
if (mp == NULL)
err(1, "getmntopts");
freemntopts(mp);
break;
case 's':
shared = 1;
break;
default:
usage();
break;
}
}
argc -= optind;
argv += optind;
if (argc != 2)
usage();
mntfile = argv[0];
mntpath = argv[1];
rdonly = mntflags & MNT_RDONLY;
if (stat(mntfile, &sb) == -1)
err(1, "stat fspec");
if (!S_ISREG(sb.st_mode))
errx(1, "fspec must be a regular file");
fd = open(mntfile, rdonly ? O_RDONLY: O_RDWR);
if (fd == -1)
err(1, "open fspec");
membase = mmap(NULL, sb.st_size, PROT_READ | (rdonly ? 0 : PROT_WRITE),
MAP_FILE | (shared ? MAP_SHARED : MAP_PRIVATE), fd, 0);
if (membase == MAP_FAILED)
err(1, "cannot mmap fspec");
args.fspec = mntfile;
args.base = membase;
args.size = sb.st_size;
if (p2k_run_fs(MOUNT_MFS, "/swabbie", mntpath,
0, &args, sizeof(args), 0) == -1)
err(1, "p2k");
return 0;
}