162797Sbostic /*-
266471Sbostic * Copyright (c) 1993, 1994
362805Sbostic * The Regents of the University of California. All rights reserved.
462797Sbostic *
562797Sbostic * %sccs.include.redist.c%
662797Sbostic */
762797Sbostic
862797Sbostic #ifndef lint
962805Sbostic static char copyright[] =
1066471Sbostic "@(#) Copyright (c) 1993, 1994\n\
1162805Sbostic The Regents of the University of California. All rights reserved.\n";
1262797Sbostic #endif /* not lint */
1362797Sbostic
1462797Sbostic #ifndef lint
15*68900Smckusick static char sccsid[] = "@(#)mount_lfs.c 8.4 (Berkeley) 04/26/95";
1662797Sbostic #endif /* not lint */
1762797Sbostic
1862797Sbostic #include <sys/param.h>
1962797Sbostic #include <sys/mount.h>
20*68900Smckusick #include <ufs/ufs/ufsmount.h>
2162797Sbostic
2262797Sbostic #include <err.h>
2362797Sbostic #include <stdio.h>
2462797Sbostic #include <stdlib.h>
2562797Sbostic #include <string.h>
2662797Sbostic #include <unistd.h>
2762797Sbostic
2866471Sbostic #include "mntopts.h"
2962797Sbostic #include "pathnames.h"
3062797Sbostic
3166471Sbostic struct mntopt mopts[] = {
3266471Sbostic MOPT_STDOPTS,
3366471Sbostic MOPT_UPDATE,
3466471Sbostic { NULL }
3566471Sbostic };
3662797Sbostic
3766471Sbostic void usage __P((void));
3866471Sbostic void invoke_cleaner __P((char *));
3962797Sbostic
4062797Sbostic int short_rds, cleaner_debug;
4162797Sbostic
4262797Sbostic int
main(argc,argv)4362797Sbostic main(argc, argv)
4462797Sbostic int argc;
4562797Sbostic char *argv[];
4662797Sbostic {
4762797Sbostic struct ufs_args args;
4866471Sbostic int ch, mntflags, noclean;
4966471Sbostic char *fs_name, *options;
5062797Sbostic
5166471Sbostic options = NULL;
5262797Sbostic mntflags = noclean = 0;
5366471Sbostic while ((ch = getopt(argc, argv, "dno:s")) != EOF)
5466471Sbostic switch (ch) {
5566471Sbostic case 'd':
5666471Sbostic cleaner_debug = 1;
5762797Sbostic break;
5862797Sbostic case 'n':
5962797Sbostic noclean = 1;
6062797Sbostic break;
6166471Sbostic case 'o':
62*68900Smckusick getmntopts(optarg, mopts, &mntflags, 0);
6366471Sbostic break;
6462797Sbostic case 's':
6562797Sbostic short_rds = 1;
6662797Sbostic break;
6762797Sbostic case '?':
6862797Sbostic default:
6962797Sbostic usage();
7062797Sbostic }
7162797Sbostic argc -= optind;
7262797Sbostic argv += optind;
7362797Sbostic
7462797Sbostic if (argc != 2)
7562797Sbostic usage();
7662797Sbostic
7762797Sbostic args.fspec = argv[0]; /* the name of the device file */
7862797Sbostic fs_name = argv[1]; /* the mount point */
7962797Sbostic
8066471Sbostic #define DEFAULT_ROOTUID -2
8165843Sbostic args.export.ex_root = DEFAULT_ROOTUID;
8262797Sbostic if (mntflags & MNT_RDONLY)
8365843Sbostic args.export.ex_flags = MNT_EXRDONLY;
8462797Sbostic else
8565843Sbostic args.export.ex_flags = 0;
8662797Sbostic
87*68900Smckusick if (mount("lfs", fs_name, mntflags, &args))
8866471Sbostic err(1, NULL);
8962797Sbostic
9066471Sbostic if (!noclean)
9162797Sbostic invoke_cleaner(fs_name);
9266471Sbostic /* NOTREACHED */
9362797Sbostic
9462797Sbostic exit(0);
9562797Sbostic }
9662797Sbostic
9762797Sbostic void
invoke_cleaner(name)9862797Sbostic invoke_cleaner(name)
9962797Sbostic char *name;
10062797Sbostic {
10162797Sbostic char *args[6], **ap = args;
10262797Sbostic
10366471Sbostic /* Build the argument list. */
10462797Sbostic *ap++ = _PATH_LFS_CLEANERD;
10562797Sbostic if (short_rds)
10662797Sbostic *ap++ = "-s";
10762797Sbostic if (cleaner_debug)
10862797Sbostic *ap++ = "-d";
10962797Sbostic *ap++ = name;
11062797Sbostic *ap = NULL;
11162797Sbostic
11262797Sbostic execv(args[0], args);
11366471Sbostic err(1, "exec %s", _PATH_LFS_CLEANERD);
11462797Sbostic }
11566471Sbostic
11666471Sbostic void
usage()11766471Sbostic usage()
11866471Sbostic {
11966471Sbostic (void)fprintf(stderr,
12066471Sbostic "usage: mount_lfs [-dns] [-o options] special node\n");
12166471Sbostic exit(1);
12266471Sbostic }
123