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