xref: /original-bsd/sbin/mount_lfs/mount_lfs.c (revision 612877e1)
1 /*-
2  * Copyright (c) 1993, 1994
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char copyright[] =
10 "@(#) Copyright (c) 1993, 1994\n\
11 	The Regents of the University of California.  All rights reserved.\n";
12 #endif /* not lint */
13 
14 #ifndef lint
15 static char sccsid[] = "@(#)mount_lfs.c	8.3 (Berkeley) 03/27/94";
16 #endif /* not lint */
17 
18 #include <sys/param.h>
19 #include <sys/mount.h>
20 
21 #include <err.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 
27 #include "mntopts.h"
28 #include "pathnames.h"
29 
30 struct mntopt mopts[] = {
31 	MOPT_STDOPTS,
32 	MOPT_UPDATE,
33 	{ NULL }
34 };
35 
36 void	usage __P((void));
37 void	invoke_cleaner __P((char *));
38 
39 int short_rds, cleaner_debug;
40 
41 int
42 main(argc, argv)
43 	int argc;
44 	char *argv[];
45 {
46 	struct ufs_args args;
47 	int ch, mntflags, noclean;
48 	char *fs_name, *options;
49 
50 	options = NULL;
51 	mntflags = noclean = 0;
52 	while ((ch = getopt(argc, argv, "dno:s")) != EOF)
53 		switch (ch) {
54 		case 'd':
55 			cleaner_debug = 1;
56 			break;
57 		case 'n':
58 			noclean = 1;
59 			break;
60 		case 'o':
61 			getmntopts(optarg, mopts, &mntflags);
62 			break;
63 		case 's':
64 			short_rds = 1;
65 			break;
66 		case '?':
67 		default:
68 			usage();
69 		}
70 	argc -= optind;
71 	argv += optind;
72 
73 	if (argc != 2)
74 		usage();
75 
76         args.fspec = argv[0];	/* the name of the device file */
77 	fs_name = argv[1];	/* the mount point */
78 
79 #define DEFAULT_ROOTUID	-2
80 	args.export.ex_root = DEFAULT_ROOTUID;
81 	if (mntflags & MNT_RDONLY)
82 		args.export.ex_flags = MNT_EXRDONLY;
83 	else
84 		args.export.ex_flags = 0;
85 
86 	if (mount(MOUNT_LFS, fs_name, mntflags, &args))
87 		err(1, NULL);
88 
89 	if (!noclean)
90 		invoke_cleaner(fs_name);
91 		/* NOTREACHED */
92 
93 	exit(0);
94 }
95 
96 void
97 invoke_cleaner(name)
98 	char *name;
99 {
100 	char *args[6], **ap = args;
101 
102 	/* Build the argument list. */
103 	*ap++ = _PATH_LFS_CLEANERD;
104 	if (short_rds)
105 		*ap++ = "-s";
106 	if (cleaner_debug)
107 		*ap++ = "-d";
108 	*ap++ = name;
109 	*ap = NULL;
110 
111 	execv(args[0], args);
112 	err(1, "exec %s", _PATH_LFS_CLEANERD);
113 }
114 
115 void
116 usage()
117 {
118 	(void)fprintf(stderr,
119 		"usage: mount_lfs [-dns] [-o options] special node\n");
120 	exit(1);
121 }
122