mount.c revision 1.1.1.3 1 1.1 cgd /*
2 1.1.1.2 mycroft * Copyright (c) 1980, 1989, 1993, 1994
3 1.1.1.2 mycroft * The Regents of the University of California. All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd */
33 1.1 cgd
34 1.1 cgd #ifndef lint
35 1.1.1.2 mycroft static char copyright[] =
36 1.1.1.2 mycroft "@(#) Copyright (c) 1980, 1989, 1993, 1994\n\
37 1.1.1.2 mycroft The Regents of the University of California. All rights reserved.\n";
38 1.1 cgd #endif /* not lint */
39 1.1 cgd
40 1.1 cgd #ifndef lint
41 1.1.1.3 lukem static char sccsid[] = "@(#)mount.c 8.25 (Berkeley) 5/8/95";
42 1.1 cgd #endif /* not lint */
43 1.1 cgd
44 1.1 cgd #include <sys/param.h>
45 1.1 cgd #include <sys/mount.h>
46 1.1.1.2 mycroft #include <sys/wait.h>
47 1.1.1.2 mycroft
48 1.1.1.2 mycroft #include <err.h>
49 1.1.1.2 mycroft #include <errno.h>
50 1.1 cgd #include <fstab.h>
51 1.1.1.3 lukem #include <pwd.h>
52 1.1.1.2 mycroft #include <signal.h>
53 1.1 cgd #include <stdio.h>
54 1.1 cgd #include <stdlib.h>
55 1.1.1.2 mycroft #include <string.h>
56 1.1.1.2 mycroft #include <unistd.h>
57 1.1 cgd
58 1.1.1.2 mycroft #include "pathnames.h"
59 1.1 cgd
60 1.1.1.3 lukem int debug, verbose;
61 1.1 cgd
62 1.1.1.3 lukem int checkvfsname __P((const char *, const char **));
63 1.1.1.2 mycroft char *catopt __P((char *, const char *));
64 1.1.1.2 mycroft struct statfs
65 1.1.1.2 mycroft *getmntpt __P((const char *));
66 1.1.1.3 lukem int hasopt __P((const char *, const char *));
67 1.1.1.2 mycroft const char
68 1.1.1.2 mycroft **makevfslist __P((char *));
69 1.1.1.2 mycroft void mangle __P((char *, int *, const char **));
70 1.1.1.2 mycroft int mountfs __P((const char *, const char *, const char *,
71 1.1.1.2 mycroft int, const char *, const char *));
72 1.1.1.3 lukem void prmount __P((struct statfs *));
73 1.1.1.2 mycroft void usage __P((void));
74 1.1.1.2 mycroft
75 1.1.1.2 mycroft /* From mount_ufs.c. */
76 1.1.1.2 mycroft int mount_ufs __P((int, char * const *));
77 1.1.1.2 mycroft
78 1.1.1.2 mycroft /* Map from mount otions to printable formats. */
79 1.1.1.2 mycroft static struct opt {
80 1.1.1.2 mycroft int o_opt;
81 1.1.1.2 mycroft const char *o_name;
82 1.1.1.2 mycroft } optnames[] = {
83 1.1.1.2 mycroft { MNT_ASYNC, "asynchronous" },
84 1.1.1.2 mycroft { MNT_EXPORTED, "NFS exported" },
85 1.1.1.2 mycroft { MNT_LOCAL, "local" },
86 1.1.1.2 mycroft { MNT_NODEV, "nodev" },
87 1.1.1.2 mycroft { MNT_NOEXEC, "noexec" },
88 1.1.1.2 mycroft { MNT_NOSUID, "nosuid" },
89 1.1.1.2 mycroft { MNT_QUOTA, "with quotas" },
90 1.1.1.2 mycroft { MNT_RDONLY, "read-only" },
91 1.1.1.2 mycroft { MNT_SYNCHRONOUS, "synchronous" },
92 1.1.1.2 mycroft { MNT_UNION, "union" },
93 1.1.1.2 mycroft { NULL }
94 1.1 cgd };
95 1.1 cgd
96 1.1.1.2 mycroft int
97 1.1.1.2 mycroft main(argc, argv)
98 1.1 cgd int argc;
99 1.1.1.2 mycroft char * const argv[];
100 1.1 cgd {
101 1.1.1.3 lukem const char *mntfromname, **vfslist, *vfstype;
102 1.1.1.2 mycroft struct fstab *fs;
103 1.1.1.2 mycroft struct statfs *mntbuf;
104 1.1.1.2 mycroft FILE *mountdfp;
105 1.1.1.2 mycroft pid_t pid;
106 1.1.1.2 mycroft int all, ch, i, init_flags, mntsize, rval;
107 1.1.1.2 mycroft char *options;
108 1.1.1.2 mycroft
109 1.1.1.2 mycroft all = init_flags = 0;
110 1.1.1.2 mycroft options = NULL;
111 1.1.1.2 mycroft vfslist = NULL;
112 1.1.1.2 mycroft vfstype = "ufs";
113 1.1.1.2 mycroft while ((ch = getopt(argc, argv, "adfo:rwt:uv")) != EOF)
114 1.1.1.2 mycroft switch (ch) {
115 1.1 cgd case 'a':
116 1.1 cgd all = 1;
117 1.1 cgd break;
118 1.1.1.2 mycroft case 'd':
119 1.1.1.2 mycroft debug = 1;
120 1.1.1.2 mycroft break;
121 1.1 cgd case 'f':
122 1.1.1.2 mycroft init_flags |= MNT_FORCE;
123 1.1.1.2 mycroft break;
124 1.1.1.2 mycroft case 'o':
125 1.1.1.2 mycroft if (*optarg)
126 1.1.1.2 mycroft options = catopt(options, optarg);
127 1.1 cgd break;
128 1.1 cgd case 'r':
129 1.1.1.2 mycroft init_flags |= MNT_RDONLY;
130 1.1.1.2 mycroft break;
131 1.1.1.2 mycroft case 't':
132 1.1.1.2 mycroft if (vfslist != NULL)
133 1.1.1.2 mycroft errx(1, "only one -t option may be specified.");
134 1.1.1.2 mycroft vfslist = makevfslist(optarg);
135 1.1.1.2 mycroft vfstype = optarg;
136 1.1 cgd break;
137 1.1 cgd case 'u':
138 1.1.1.2 mycroft init_flags |= MNT_UPDATE;
139 1.1 cgd break;
140 1.1 cgd case 'v':
141 1.1 cgd verbose = 1;
142 1.1 cgd break;
143 1.1 cgd case 'w':
144 1.1.1.2 mycroft init_flags &= ~MNT_RDONLY;
145 1.1 cgd break;
146 1.1 cgd case '?':
147 1.1 cgd default:
148 1.1 cgd usage();
149 1.1 cgd /* NOTREACHED */
150 1.1 cgd }
151 1.1 cgd argc -= optind;
152 1.1 cgd argv += optind;
153 1.1 cgd
154 1.1.1.2 mycroft #define BADTYPE(type) \
155 1.1.1.2 mycroft (strcmp(type, FSTAB_RO) && \
156 1.1.1.2 mycroft strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
157 1.1.1.2 mycroft
158 1.1.1.2 mycroft rval = 0;
159 1.1.1.2 mycroft switch (argc) {
160 1.1.1.2 mycroft case 0:
161 1.1.1.2 mycroft if (all)
162 1.1.1.2 mycroft while ((fs = getfsent()) != NULL) {
163 1.1.1.2 mycroft if (BADTYPE(fs->fs_type))
164 1.1.1.2 mycroft continue;
165 1.1.1.3 lukem if (checkvfsname(fs->fs_vfstype, vfslist))
166 1.1.1.3 lukem continue;
167 1.1.1.3 lukem if (hasopt(fs->fs_mntops, "noauto"))
168 1.1.1.2 mycroft continue;
169 1.1.1.2 mycroft if (mountfs(fs->fs_vfstype, fs->fs_spec,
170 1.1.1.2 mycroft fs->fs_file, init_flags, options,
171 1.1.1.2 mycroft fs->fs_mntops))
172 1.1.1.2 mycroft rval = 1;
173 1.1.1.2 mycroft }
174 1.1.1.2 mycroft else {
175 1.1.1.2 mycroft if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
176 1.1.1.2 mycroft err(1, "getmntinfo");
177 1.1.1.2 mycroft for (i = 0; i < mntsize; i++) {
178 1.1.1.3 lukem if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
179 1.1.1.2 mycroft continue;
180 1.1.1.3 lukem prmount(&mntbuf[i]);
181 1.1.1.2 mycroft }
182 1.1 cgd }
183 1.1 cgd exit(rval);
184 1.1.1.2 mycroft case 1:
185 1.1.1.2 mycroft if (vfslist != NULL)
186 1.1 cgd usage();
187 1.1 cgd
188 1.1.1.2 mycroft if (init_flags & MNT_UPDATE) {
189 1.1.1.2 mycroft if ((mntbuf = getmntpt(*argv)) == NULL)
190 1.1.1.2 mycroft errx(1,
191 1.1.1.2 mycroft "unknown special file or file system %s.",
192 1.1.1.2 mycroft *argv);
193 1.1.1.3 lukem if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL)
194 1.1.1.3 lukem mntfromname = fs->fs_spec;
195 1.1.1.3 lukem else
196 1.1.1.3 lukem mntfromname = mntbuf->f_mntfromname;
197 1.1.1.3 lukem rval = mountfs(mntbuf->f_fstypename, mntfromname,
198 1.1.1.3 lukem mntbuf->f_mntonname, init_flags, options, 0);
199 1.1.1.3 lukem break;
200 1.1 cgd }
201 1.1.1.3 lukem if ((fs = getfsfile(*argv)) == NULL &&
202 1.1.1.3 lukem (fs = getfsspec(*argv)) == NULL)
203 1.1.1.3 lukem errx(1, "%s: unknown special file or file system.",
204 1.1.1.3 lukem *argv);
205 1.1.1.3 lukem if (BADTYPE(fs->fs_type))
206 1.1.1.3 lukem errx(1, "%s has unknown file system type.",
207 1.1.1.3 lukem *argv);
208 1.1.1.3 lukem rval = mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file,
209 1.1.1.3 lukem init_flags, options, fs->fs_mntops);
210 1.1.1.2 mycroft break;
211 1.1.1.2 mycroft case 2:
212 1.1 cgd /*
213 1.1.1.2 mycroft * If -t flag has not been specified, and spec contains either
214 1.1.1.2 mycroft * a ':' or a '@' then assume that an NFS filesystem is being
215 1.1.1.2 mycroft * specified ala Sun.
216 1.1 cgd */
217 1.1.1.2 mycroft if (vfslist == NULL && strpbrk(argv[0], ":@") != NULL)
218 1.1.1.2 mycroft vfstype = "nfs";
219 1.1.1.2 mycroft rval = mountfs(vfstype,
220 1.1.1.2 mycroft argv[0], argv[1], init_flags, options, NULL);
221 1.1.1.2 mycroft break;
222 1.1.1.2 mycroft default:
223 1.1.1.2 mycroft usage();
224 1.1.1.2 mycroft /* NOTREACHED */
225 1.1 cgd }
226 1.1 cgd
227 1.1.1.2 mycroft /*
228 1.1.1.2 mycroft * If the mount was successfully, and done by root, tell mountd the
229 1.1.1.2 mycroft * good news. Pid checks are probably unnecessary, but don't hurt.
230 1.1.1.2 mycroft */
231 1.1.1.2 mycroft if (rval == 0 && getuid() == 0 &&
232 1.1.1.2 mycroft (mountdfp = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
233 1.1.1.2 mycroft if (fscanf(mountdfp, "%ld", &pid) == 1 &&
234 1.1.1.2 mycroft pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH)
235 1.1.1.2 mycroft err(1, "signal mountd");
236 1.1.1.2 mycroft (void)fclose(mountdfp);
237 1.1.1.2 mycroft }
238 1.1.1.2 mycroft
239 1.1.1.2 mycroft exit(rval);
240 1.1.1.2 mycroft }
241 1.1.1.2 mycroft
242 1.1.1.2 mycroft int
243 1.1.1.3 lukem hasopt(mntopts, option)
244 1.1.1.3 lukem const char *mntopts, *option;
245 1.1.1.3 lukem {
246 1.1.1.3 lukem int negative, found;
247 1.1.1.3 lukem char *opt, *optbuf;
248 1.1.1.3 lukem
249 1.1.1.3 lukem if (option[0] == 'n' && option[1] == 'o') {
250 1.1.1.3 lukem negative = 1;
251 1.1.1.3 lukem option += 2;
252 1.1.1.3 lukem } else
253 1.1.1.3 lukem negative = 0;
254 1.1.1.3 lukem optbuf = strdup(mntopts);
255 1.1.1.3 lukem found = 0;
256 1.1.1.3 lukem for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
257 1.1.1.3 lukem if (opt[0] == 'n' && opt[1] == 'o') {
258 1.1.1.3 lukem if (!strcasecmp(opt + 2, option))
259 1.1.1.3 lukem found = negative;
260 1.1.1.3 lukem } else if (!strcasecmp(opt, option))
261 1.1.1.3 lukem found = !negative;
262 1.1.1.3 lukem }
263 1.1.1.3 lukem free(optbuf);
264 1.1.1.3 lukem return (found);
265 1.1.1.3 lukem }
266 1.1.1.3 lukem
267 1.1.1.3 lukem int
268 1.1.1.2 mycroft mountfs(vfstype, spec, name, flags, options, mntopts)
269 1.1.1.2 mycroft const char *vfstype, *spec, *name, *options, *mntopts;
270 1.1 cgd int flags;
271 1.1 cgd {
272 1.1.1.2 mycroft /* List of directories containing mount_xxx subcommands. */
273 1.1.1.2 mycroft static const char *edirs[] = {
274 1.1.1.2 mycroft _PATH_SBIN,
275 1.1.1.2 mycroft _PATH_USRSBIN,
276 1.1.1.2 mycroft NULL
277 1.1.1.2 mycroft };
278 1.1.1.2 mycroft const char *argv[100], **edir;
279 1.1.1.2 mycroft struct statfs sf;
280 1.1 cgd pid_t pid;
281 1.1.1.2 mycroft int argc, i, status;
282 1.1.1.2 mycroft char *optbuf, execname[MAXPATHLEN + 1], mntpath[MAXPATHLEN];
283 1.1 cgd
284 1.1.1.2 mycroft if (realpath(name, mntpath) == NULL) {
285 1.1.1.3 lukem warn("realpath %s", mntpath);
286 1.1 cgd return (1);
287 1.1 cgd }
288 1.1 cgd
289 1.1.1.2 mycroft name = mntpath;
290 1.1 cgd
291 1.1.1.3 lukem if (mntopts == NULL)
292 1.1.1.3 lukem mntopts = "";
293 1.1.1.2 mycroft if (options == NULL) {
294 1.1.1.3 lukem if (*mntopts == '\0') {
295 1.1.1.2 mycroft options = "rw";
296 1.1.1.3 lukem } else {
297 1.1.1.2 mycroft options = mntopts;
298 1.1.1.3 lukem mntopts = "";
299 1.1.1.3 lukem }
300 1.1.1.2 mycroft }
301 1.1.1.2 mycroft optbuf = catopt(strdup(mntopts), options);
302 1.1 cgd
303 1.1.1.2 mycroft if (strcmp(name, "/") == 0)
304 1.1.1.2 mycroft flags |= MNT_UPDATE;
305 1.1.1.2 mycroft if (flags & MNT_FORCE)
306 1.1.1.2 mycroft optbuf = catopt(optbuf, "force");
307 1.1.1.2 mycroft if (flags & MNT_RDONLY)
308 1.1.1.2 mycroft optbuf = catopt(optbuf, "ro");
309 1.1.1.2 mycroft /*
310 1.1.1.2 mycroft * XXX
311 1.1.1.2 mycroft * The mount_mfs (newfs) command uses -o to select the
312 1.1.1.2 mycroft * optimisation mode. We don't pass the default "-o rw"
313 1.1.1.2 mycroft * for that reason.
314 1.1.1.2 mycroft */
315 1.1.1.2 mycroft if (flags & MNT_UPDATE)
316 1.1.1.2 mycroft optbuf = catopt(optbuf, "update");
317 1.1.1.2 mycroft
318 1.1.1.2 mycroft argc = 0;
319 1.1.1.2 mycroft argv[argc++] = vfstype;
320 1.1.1.2 mycroft mangle(optbuf, &argc, argv);
321 1.1.1.2 mycroft argv[argc++] = spec;
322 1.1.1.2 mycroft argv[argc++] = name;
323 1.1.1.2 mycroft argv[argc] = NULL;
324 1.1.1.2 mycroft
325 1.1.1.2 mycroft if (debug) {
326 1.1.1.2 mycroft (void)printf("exec: mount_%s", vfstype);
327 1.1.1.2 mycroft for (i = 1; i < argc; i++)
328 1.1.1.2 mycroft (void)printf(" %s", argv[i]);
329 1.1 cgd (void)printf("\n");
330 1.1.1.2 mycroft return (0);
331 1.1 cgd }
332 1.1 cgd
333 1.1.1.2 mycroft switch (pid = vfork()) {
334 1.1.1.2 mycroft case -1: /* Error. */
335 1.1.1.2 mycroft warn("vfork");
336 1.1.1.2 mycroft free(optbuf);
337 1.1.1.2 mycroft return (1);
338 1.1.1.2 mycroft case 0: /* Child. */
339 1.1.1.2 mycroft if (strcmp(vfstype, "ufs") == 0)
340 1.1.1.2 mycroft exit(mount_ufs(argc, (char * const *) argv));
341 1.1.1.2 mycroft
342 1.1.1.2 mycroft /* Go find an executable. */
343 1.1.1.2 mycroft edir = edirs;
344 1.1.1.2 mycroft do {
345 1.1.1.2 mycroft (void)snprintf(execname,
346 1.1.1.2 mycroft sizeof(execname), "%s/mount_%s", *edir, vfstype);
347 1.1.1.2 mycroft execv(execname, (char * const *)argv);
348 1.1.1.2 mycroft if (errno != ENOENT)
349 1.1.1.2 mycroft warn("exec %s for %s", execname, name);
350 1.1.1.2 mycroft } while (*++edir != NULL);
351 1.1 cgd
352 1.1.1.2 mycroft if (errno == ENOENT)
353 1.1.1.2 mycroft warn("exec %s for %s", execname, name);
354 1.1.1.2 mycroft exit(1);
355 1.1.1.2 mycroft /* NOTREACHED */
356 1.1.1.2 mycroft default: /* Parent. */
357 1.1.1.2 mycroft free(optbuf);
358 1.1 cgd
359 1.1.1.2 mycroft if (waitpid(pid, &status, 0) < 0) {
360 1.1.1.2 mycroft warn("waitpid");
361 1.1.1.2 mycroft return (1);
362 1.1 cgd }
363 1.1.1.2 mycroft
364 1.1.1.2 mycroft if (WIFEXITED(status)) {
365 1.1.1.2 mycroft if (WEXITSTATUS(status) != 0)
366 1.1.1.2 mycroft return (WEXITSTATUS(status));
367 1.1.1.2 mycroft } else if (WIFSIGNALED(status)) {
368 1.1.1.2 mycroft warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]);
369 1.1.1.2 mycroft return (1);
370 1.1 cgd }
371 1.1.1.2 mycroft
372 1.1.1.2 mycroft if (verbose) {
373 1.1.1.2 mycroft if (statfs(name, &sf) < 0) {
374 1.1.1.3 lukem warn("statfs %s", name);
375 1.1.1.2 mycroft return (1);
376 1.1.1.2 mycroft }
377 1.1.1.3 lukem prmount(&sf);
378 1.1 cgd }
379 1.1.1.2 mycroft break;
380 1.1 cgd }
381 1.1 cgd
382 1.1.1.2 mycroft return (0);
383 1.1 cgd }
384 1.1 cgd
385 1.1.1.2 mycroft void
386 1.1.1.3 lukem prmount(sfp)
387 1.1.1.3 lukem struct statfs *sfp;
388 1.1 cgd {
389 1.1.1.3 lukem int flags;
390 1.1.1.2 mycroft struct opt *o;
391 1.1.1.3 lukem struct passwd *pw;
392 1.1.1.2 mycroft int f;
393 1.1 cgd
394 1.1.1.3 lukem (void)printf("%s on %s", sfp->f_mntfromname, sfp->f_mntonname);
395 1.1.1.2 mycroft
396 1.1.1.3 lukem flags = sfp->f_flags & MNT_VISFLAGMASK;
397 1.1.1.2 mycroft for (f = 0, o = optnames; flags && o->o_opt; o++)
398 1.1.1.2 mycroft if (flags & o->o_opt) {
399 1.1.1.2 mycroft (void)printf("%s%s", !f++ ? " (" : ", ", o->o_name);
400 1.1.1.2 mycroft flags &= ~o->o_opt;
401 1.1.1.2 mycroft }
402 1.1.1.3 lukem if (sfp->f_owner) {
403 1.1.1.3 lukem (void)printf("%smounted by ", !f++ ? " (" : ", ");
404 1.1.1.3 lukem if ((pw = getpwuid(sfp->f_owner)) != NULL)
405 1.1.1.3 lukem (void)printf("%s", pw->pw_name);
406 1.1.1.3 lukem else
407 1.1.1.3 lukem (void)printf("%d", sfp->f_owner);
408 1.1.1.3 lukem }
409 1.1.1.2 mycroft (void)printf(f ? ")\n" : "\n");
410 1.1 cgd }
411 1.1 cgd
412 1.1 cgd struct statfs *
413 1.1 cgd getmntpt(name)
414 1.1.1.2 mycroft const char *name;
415 1.1 cgd {
416 1.1 cgd struct statfs *mntbuf;
417 1.1.1.2 mycroft int i, mntsize;
418 1.1 cgd
419 1.1 cgd mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
420 1.1.1.2 mycroft for (i = 0; i < mntsize; i++)
421 1.1.1.2 mycroft if (strcmp(mntbuf[i].f_mntfromname, name) == 0 ||
422 1.1.1.2 mycroft strcmp(mntbuf[i].f_mntonname, name) == 0)
423 1.1 cgd return (&mntbuf[i]);
424 1.1.1.2 mycroft return (NULL);
425 1.1 cgd }
426 1.1 cgd
427 1.1.1.2 mycroft char *
428 1.1.1.2 mycroft catopt(s0, s1)
429 1.1.1.2 mycroft char *s0;
430 1.1.1.2 mycroft const char *s1;
431 1.1.1.2 mycroft {
432 1.1.1.2 mycroft size_t i;
433 1.1.1.2 mycroft char *cp;
434 1.1.1.2 mycroft
435 1.1.1.2 mycroft if (s0 && *s0) {
436 1.1.1.2 mycroft i = strlen(s0) + strlen(s1) + 1 + 1;
437 1.1.1.2 mycroft if ((cp = malloc(i)) == NULL)
438 1.1.1.2 mycroft err(1, NULL);
439 1.1.1.2 mycroft (void)snprintf(cp, i, "%s,%s", s0, s1);
440 1.1.1.2 mycroft } else
441 1.1.1.2 mycroft cp = strdup(s1);
442 1.1.1.2 mycroft
443 1.1.1.2 mycroft if (s0)
444 1.1.1.2 mycroft free(s0);
445 1.1.1.2 mycroft return (cp);
446 1.1 cgd }
447 1.1 cgd
448 1.1.1.2 mycroft void
449 1.1.1.2 mycroft mangle(options, argcp, argv)
450 1.1.1.2 mycroft char *options;
451 1.1.1.2 mycroft int *argcp;
452 1.1.1.2 mycroft const char **argv;
453 1.1 cgd {
454 1.1.1.2 mycroft char *p, *s;
455 1.1.1.2 mycroft int argc;
456 1.1 cgd
457 1.1.1.2 mycroft argc = *argcp;
458 1.1.1.2 mycroft for (s = options; (p = strsep(&s, ",")) != NULL;)
459 1.1.1.2 mycroft if (*p != '\0')
460 1.1.1.2 mycroft if (*p == '-') {
461 1.1.1.2 mycroft argv[argc++] = p;
462 1.1.1.2 mycroft p = strchr(p, '=');
463 1.1.1.2 mycroft if (p) {
464 1.1.1.2 mycroft *p = '\0';
465 1.1.1.2 mycroft argv[argc++] = p+1;
466 1.1 cgd }
467 1.1.1.2 mycroft } else if (strcmp(p, "rw") != 0) {
468 1.1.1.2 mycroft argv[argc++] = "-o";
469 1.1.1.2 mycroft argv[argc++] = p;
470 1.1 cgd }
471 1.1 cgd
472 1.1.1.2 mycroft *argcp = argc;
473 1.1 cgd }
474 1.1 cgd
475 1.1.1.2 mycroft void
476 1.1.1.2 mycroft usage()
477 1.1 cgd {
478 1.1.1.2 mycroft
479 1.1.1.2 mycroft (void)fprintf(stderr,
480 1.1.1.2 mycroft "usage: mount %s %s\n mount %s\n mount %s\n",
481 1.1.1.2 mycroft "[-dfruvw] [-o options] [-t ufs | external_type]",
482 1.1.1.2 mycroft "special node",
483 1.1.1.2 mycroft "[-adfruvw] [-t ufs | external_type]",
484 1.1.1.2 mycroft "[-dfruvw] special | node");
485 1.1.1.2 mycroft exit(1);
486 1.1 cgd }
487