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