mount_lfs.c revision 1.5 1 /* $NetBSD: mount_lfs.c,v 1.5 1997/09/15 04:52:37 lukem Exp $ */
2
3 /*-
4 * Copyright (c) 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 #ifndef lint
38 __COPYRIGHT("@(#) Copyright (c) 1993, 1994\n\
39 The Regents of the University of California. All rights reserved.\n");
40 #endif /* not lint */
41
42 #ifndef lint
43 #if 0
44 static char sccsid[] = "@(#)mount_lfs.c 8.3 (Berkeley) 3/27/94";
45 #else
46 __RCSID("$NetBSD: mount_lfs.c,v 1.5 1997/09/15 04:52:37 lukem Exp $");
47 #endif
48 #endif /* not lint */
49
50 #include <sys/param.h>
51 #include <sys/mount.h>
52
53 #include <err.h>
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <string.h>
57 #include <unistd.h>
58
59 #include "mntopts.h"
60 #include "pathnames.h"
61
62 const struct mntopt mopts[] = {
63 MOPT_STDOPTS,
64 MOPT_UPDATE,
65 { NULL }
66 };
67
68 int main __P((int, char *[]));
69 void invoke_cleaner __P((char *));
70 void usage __P((void));
71
72 int short_rds, cleaner_debug;
73
74 int
75 main(argc, argv)
76 int argc;
77 char *argv[];
78 {
79 struct ufs_args args;
80 int ch, mntflags, noclean;
81 char *fs_name, *options;
82
83 options = NULL;
84 mntflags = noclean = 0;
85 while ((ch = getopt(argc, argv, "dno:s")) != -1)
86 switch (ch) {
87 case 'd':
88 cleaner_debug = 1;
89 break;
90 case 'n':
91 noclean = 1;
92 break;
93 case 'o':
94 getmntopts(optarg, mopts, &mntflags);
95 break;
96 case 's':
97 short_rds = 1;
98 break;
99 case '?':
100 default:
101 usage();
102 }
103 argc -= optind;
104 argv += optind;
105
106 if (argc != 2)
107 usage();
108
109 args.fspec = argv[0]; /* the name of the device file */
110 fs_name = argv[1]; /* the mount point */
111
112 #define DEFAULT_ROOTUID -2
113 args.export.ex_root = DEFAULT_ROOTUID;
114 if (mntflags & MNT_RDONLY)
115 args.export.ex_flags = MNT_EXRDONLY;
116 else
117 args.export.ex_flags = 0;
118
119 if (mount(MOUNT_LFS, fs_name, mntflags, &args))
120 err(1, "%s", "");
121
122 if (!noclean)
123 invoke_cleaner(fs_name);
124 /* NOTREACHED */
125
126 exit(0);
127 }
128
129 void
130 invoke_cleaner(name)
131 char *name;
132 {
133 char *args[6], **ap = args;
134
135 /* Build the argument list. */
136 *ap++ = _PATH_LFS_CLEANERD;
137 if (short_rds)
138 *ap++ = "-s";
139 if (cleaner_debug)
140 *ap++ = "-d";
141 *ap++ = name;
142 *ap = NULL;
143
144 execv(args[0], args);
145 err(1, "exec %s", _PATH_LFS_CLEANERD);
146 }
147
148 void
149 usage()
150 {
151 (void)fprintf(stderr,
152 "usage: mount_lfs [-dns] [-o options] special node\n");
153 exit(1);
154 }
155