mount_lfs.c revision 1.7 1 /* $NetBSD: mount_lfs.c,v 1.7 1998/03/01 02:20:41 fvdl 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.4 (Berkeley) 4/26/95";
45 #else
46 __RCSID("$NetBSD: mount_lfs.c,v 1.7 1998/03/01 02:20:41 fvdl Exp $");
47 #endif
48 #endif /* not lint */
49
50 #include <sys/param.h>
51 #include <sys/mount.h>
52
53 #include <ufs/ufs/ufsmount.h>
54
55 #include <err.h>
56 #include <stdio.h>
57 #include <stdlib.h>
58 #include <string.h>
59 #include <unistd.h>
60
61 #include "mntopts.h"
62 #include "pathnames.h"
63
64 const struct mntopt mopts[] = {
65 MOPT_STDOPTS,
66 MOPT_UPDATE,
67 { NULL }
68 };
69
70 int main __P((int, char *[]));
71 void invoke_cleaner __P((char *));
72 void usage __P((void));
73
74 int short_rds, cleaner_debug;
75
76 int
77 main(argc, argv)
78 int argc;
79 char *argv[];
80 {
81 struct ufs_args args;
82 int ch, mntflags, noclean;
83 char *fs_name, *options;
84
85 options = NULL;
86 mntflags = noclean = 0;
87 while ((ch = getopt(argc, argv, "dno:s")) != -1)
88 switch (ch) {
89 case 'd':
90 cleaner_debug = 1;
91 break;
92 case 'n':
93 noclean = 1;
94 break;
95 case 'o':
96 getmntopts(optarg, mopts, &mntflags, 0);
97 break;
98 case 's':
99 short_rds = 1;
100 break;
101 case '?':
102 default:
103 usage();
104 }
105 argc -= optind;
106 argv += optind;
107
108 if (argc != 2)
109 usage();
110
111 args.fspec = argv[0]; /* the name of the device file */
112 fs_name = argv[1]; /* the mount point */
113
114 #define DEFAULT_ROOTUID -2
115 args.export.ex_root = DEFAULT_ROOTUID;
116 if (mntflags & MNT_RDONLY)
117 args.export.ex_flags = MNT_EXRDONLY;
118 else
119 args.export.ex_flags = 0;
120
121 if (mount(MOUNT_LFS, fs_name, mntflags, &args))
122 err(1, "%s", "");
123
124 if (!noclean)
125 invoke_cleaner(fs_name);
126 /* NOTREACHED */
127
128 exit(0);
129 }
130
131 void
132 invoke_cleaner(name)
133 char *name;
134 {
135 char *args[6], **ap = args;
136
137 /* Build the argument list. */
138 *ap++ = _PATH_LFS_CLEANERD;
139 if (short_rds)
140 *ap++ = "-s";
141 if (cleaner_debug)
142 *ap++ = "-d";
143 *ap++ = name;
144 *ap = NULL;
145
146 execv(args[0], args);
147 err(1, "exec %s", _PATH_LFS_CLEANERD);
148 }
149
150 void
151 usage()
152 {
153 (void)fprintf(stderr,
154 "usage: mount_lfs [-dns] [-o options] special node\n");
155 exit(1);
156 }
157