mount.c (e25152834cdf3b353892835a4f3b157e066a8ed4) mount.c (e725ee7eb672a8501600552283d3d08a2f7b6847)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1980, 1989, 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

--- 46 unchanged lines hidden (view full) ---

55#include <pwd.h>
56#include <signal.h>
57#include <stdint.h>
58#include <stdio.h>
59#include <stdlib.h>
60#include <string.h>
61#include <unistd.h>
62#include <libutil.h>
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1980, 1989, 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

--- 46 unchanged lines hidden (view full) ---

55#include <pwd.h>
56#include <signal.h>
57#include <stdint.h>
58#include <stdio.h>
59#include <stdlib.h>
60#include <string.h>
61#include <unistd.h>
62#include <libutil.h>
63#include <libxo/xo.h>
63
64#include "extern.h"
65#include "mntopts.h"
66#include "pathnames.h"
67
64
65#include "extern.h"
66#include "mntopts.h"
67#include "pathnames.h"
68
69#define EXIT(a) { \
70 xo_close_container("mount"); \
71 xo_finish(); \
72 exit(a); \
73 }
74
68/* `meta' options */
69#define MOUNT_META_OPTION_FSTAB "fstab"
70#define MOUNT_META_OPTION_CURRENT "current"
71
72static int debug, fstab_style, verbose;
73
74struct cpa {
75 char **a;

--- 65 unchanged lines hidden (view full) ---

141static int
142exec_mountprog(const char *name, const char *execname, char *const argv[])
143{
144 pid_t pid;
145 int status;
146
147 switch (pid = fork()) {
148 case -1: /* Error. */
75/* `meta' options */
76#define MOUNT_META_OPTION_FSTAB "fstab"
77#define MOUNT_META_OPTION_CURRENT "current"
78
79static int debug, fstab_style, verbose;
80
81struct cpa {
82 char **a;

--- 65 unchanged lines hidden (view full) ---

148static int
149exec_mountprog(const char *name, const char *execname, char *const argv[])
150{
151 pid_t pid;
152 int status;
153
154 switch (pid = fork()) {
155 case -1: /* Error. */
149 warn("fork");
150 exit (1);
156 xo_warn("fork");
157 EXIT(1);
151 case 0: /* Child. */
152 /* Go find an executable. */
153 execvP(execname, _PATH_SYSPATH, argv);
154 if (errno == ENOENT) {
158 case 0: /* Child. */
159 /* Go find an executable. */
160 execvP(execname, _PATH_SYSPATH, argv);
161 if (errno == ENOENT) {
155 warn("exec %s not found", execname);
162 xo_warn("exec %s not found", execname);
156 if (execname[0] != '/') {
163 if (execname[0] != '/') {
157 warnx("in path: %s", _PATH_SYSPATH);
164 xo_warnx("in path: %s", _PATH_SYSPATH);
158 }
159 }
165 }
166 }
160 exit(1);
167 EXIT(1);
161 default: /* Parent. */
162 if (waitpid(pid, &status, 0) < 0) {
168 default: /* Parent. */
169 if (waitpid(pid, &status, 0) < 0) {
163 warn("waitpid");
170 xo_warn("waitpid");
164 return (1);
165 }
166
167 if (WIFEXITED(status)) {
168 if (WEXITSTATUS(status) != 0)
169 return (WEXITSTATUS(status));
170 } else if (WIFSIGNALED(status)) {
171 return (1);
172 }
173
174 if (WIFEXITED(status)) {
175 if (WEXITSTATUS(status) != 0)
176 return (WEXITSTATUS(status));
177 } else if (WIFSIGNALED(status)) {
171 warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]);
178 xo_warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]);
172 return (1);
173 }
174 break;
175 }
176
177 return (0);
178}
179
180static int
181specified_ro(const char *arg)
182{
183 char *optbuf, *opt;
184 int ret = 0;
185
186 optbuf = strdup(arg);
187 if (optbuf == NULL)
179 return (1);
180 }
181 break;
182 }
183
184 return (0);
185}
186
187static int
188specified_ro(const char *arg)
189{
190 char *optbuf, *opt;
191 int ret = 0;
192
193 optbuf = strdup(arg);
194 if (optbuf == NULL)
188 err(1, NULL);
195 xo_err(1, NULL);
189
190 for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
191 if (strcmp(opt, "ro") == 0) {
192 ret = 1;
193 break;
194 }
195 }
196 free(optbuf);

--- 18 unchanged lines hidden (view full) ---

215 return;
216 }
217
218 /*
219 * Refuse to send broadcast or group signals, this has
220 * happened due to the bugs in pidfile(3).
221 */
222 if (mountdpid <= 0) {
196
197 for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
198 if (strcmp(opt, "ro") == 0) {
199 ret = 1;
200 break;
201 }
202 }
203 free(optbuf);

--- 18 unchanged lines hidden (view full) ---

222 return;
223 }
224
225 /*
226 * Refuse to send broadcast or group signals, this has
227 * happened due to the bugs in pidfile(3).
228 */
229 if (mountdpid <= 0) {
223 warnx("mountd pid %d, refusing to send SIGHUP", mountdpid);
230 xo_warnx("mountd pid %d, refusing to send SIGHUP", mountdpid);
224 return;
225 }
226
227 /* We have mountd(8) PID in mountdpid varible, let's signal it. */
228 if (kill(mountdpid, SIGHUP) == -1)
231 return;
232 }
233
234 /* We have mountd(8) PID in mountdpid varible, let's signal it. */
235 if (kill(mountdpid, SIGHUP) == -1)
229 err(1, "signal mountd");
236 xo_err(1, "signal mountd");
230}
231
232int
233main(int argc, char *argv[])
234{
235 const char *mntfromname, **vfslist, *vfstype;
236 struct fstab *fs;
237 struct statfs *mntbuf;
238 int all, ch, i, init_flags, late, failok, mntsize, rval, have_fstab, ro;
239 int onlylate;
240 char *cp, *ep, *options;
241
242 all = init_flags = late = onlylate = 0;
243 ro = 0;
244 options = NULL;
245 vfslist = NULL;
246 vfstype = "ufs";
237}
238
239int
240main(int argc, char *argv[])
241{
242 const char *mntfromname, **vfslist, *vfstype;
243 struct fstab *fs;
244 struct statfs *mntbuf;
245 int all, ch, i, init_flags, late, failok, mntsize, rval, have_fstab, ro;
246 int onlylate;
247 char *cp, *ep, *options;
248
249 all = init_flags = late = onlylate = 0;
250 ro = 0;
251 options = NULL;
252 vfslist = NULL;
253 vfstype = "ufs";
254
255 argc = xo_parse_args(argc, argv);
256 if (argc < 0)
257 exit(1);
258 xo_open_container("mount");
259
247 while ((ch = getopt(argc, argv, "adF:fLlno:prt:uvw")) != -1)
248 switch (ch) {
249 case 'a':
250 all = 1;
251 break;
252 case 'd':
253 debug = 1;
254 break;

--- 25 unchanged lines hidden (view full) ---

280 verbose = 1;
281 break;
282 case 'r':
283 options = catopt(options, "ro");
284 ro = 1;
285 break;
286 case 't':
287 if (vfslist != NULL)
260 while ((ch = getopt(argc, argv, "adF:fLlno:prt:uvw")) != -1)
261 switch (ch) {
262 case 'a':
263 all = 1;
264 break;
265 case 'd':
266 debug = 1;
267 break;

--- 25 unchanged lines hidden (view full) ---

293 verbose = 1;
294 break;
295 case 'r':
296 options = catopt(options, "ro");
297 ro = 1;
298 break;
299 case 't':
300 if (vfslist != NULL)
288 errx(1, "only one -t option may be specified");
301 xo_errx(1, "only one -t option may be specified");
289 vfslist = makevfslist(optarg);
290 vfstype = optarg;
291 break;
292 case 'u':
293 init_flags |= MNT_UPDATE;
294 break;
295 case 'v':
296 verbose = 1;

--- 16 unchanged lines hidden (view full) ---

313 if ((init_flags & MNT_UPDATE) && (ro == 0))
314 options = catopt(options, "noro");
315
316 rval = 0;
317 switch (argc) {
318 case 0:
319 if ((mntsize = getmntinfo(&mntbuf,
320 verbose ? MNT_WAIT : MNT_NOWAIT)) == 0)
302 vfslist = makevfslist(optarg);
303 vfstype = optarg;
304 break;
305 case 'u':
306 init_flags |= MNT_UPDATE;
307 break;
308 case 'v':
309 verbose = 1;

--- 16 unchanged lines hidden (view full) ---

326 if ((init_flags & MNT_UPDATE) && (ro == 0))
327 options = catopt(options, "noro");
328
329 rval = 0;
330 switch (argc) {
331 case 0:
332 if ((mntsize = getmntinfo(&mntbuf,
333 verbose ? MNT_WAIT : MNT_NOWAIT)) == 0)
321 err(1, "getmntinfo");
334 xo_err(1, "getmntinfo");
322 if (all) {
323 while ((fs = getfsent()) != NULL) {
324 if (BADTYPE(fs->fs_type))
325 continue;
326 if (checkvfsname(fs->fs_vfstype, vfslist))
327 continue;
328 if (hasopt(fs->fs_mntops, "noauto"))
329 continue;

--- 12 unchanged lines hidden (view full) ---

342 options = update_options(options, fs->fs_mntops,
343 mntbuf->f_flags);
344 if (mountfs(fs->fs_vfstype, fs->fs_spec,
345 fs->fs_file, init_flags, options,
346 fs->fs_mntops) && !failok)
347 rval = 1;
348 }
349 } else if (fstab_style) {
335 if (all) {
336 while ((fs = getfsent()) != NULL) {
337 if (BADTYPE(fs->fs_type))
338 continue;
339 if (checkvfsname(fs->fs_vfstype, vfslist))
340 continue;
341 if (hasopt(fs->fs_mntops, "noauto"))
342 continue;

--- 12 unchanged lines hidden (view full) ---

355 options = update_options(options, fs->fs_mntops,
356 mntbuf->f_flags);
357 if (mountfs(fs->fs_vfstype, fs->fs_spec,
358 fs->fs_file, init_flags, options,
359 fs->fs_mntops) && !failok)
360 rval = 1;
361 }
362 } else if (fstab_style) {
363 xo_open_list("fstab");
350 for (i = 0; i < mntsize; i++) {
351 if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
352 continue;
364 for (i = 0; i < mntsize; i++) {
365 if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
366 continue;
367 xo_open_instance("fstab");
353 putfsent(&mntbuf[i]);
368 putfsent(&mntbuf[i]);
369 xo_close_instance("fstab");
354 }
370 }
371 xo_close_list("fstab");
355 } else {
372 } else {
373 xo_open_list("mounted");
356 for (i = 0; i < mntsize; i++) {
357 if (checkvfsname(mntbuf[i].f_fstypename,
358 vfslist))
359 continue;
360 if (!verbose &&
361 (mntbuf[i].f_flags & MNT_IGNORE) != 0)
362 continue;
374 for (i = 0; i < mntsize; i++) {
375 if (checkvfsname(mntbuf[i].f_fstypename,
376 vfslist))
377 continue;
378 if (!verbose &&
379 (mntbuf[i].f_flags & MNT_IGNORE) != 0)
380 continue;
381 xo_open_instance("mounted");
363 prmount(&mntbuf[i]);
382 prmount(&mntbuf[i]);
383 xo_close_instance("mounted");
364 }
384 }
385 xo_close_list("mounted");
365 }
386 }
366 exit(rval);
387 EXIT(rval);
367 case 1:
368 if (vfslist != NULL)
369 usage();
370
371 rmslashes(*argv, *argv);
372 if (init_flags & MNT_UPDATE) {
373 mntfromname = NULL;
374 have_fstab = 0;
375 if ((mntbuf = getmntpt(*argv)) == NULL)
388 case 1:
389 if (vfslist != NULL)
390 usage();
391
392 rmslashes(*argv, *argv);
393 if (init_flags & MNT_UPDATE) {
394 mntfromname = NULL;
395 have_fstab = 0;
396 if ((mntbuf = getmntpt(*argv)) == NULL)
376 errx(1, "not currently mounted %s", *argv);
397 xo_errx(1, "not currently mounted %s", *argv);
377 /*
378 * Only get the mntflags from fstab if both mntpoint
379 * and mntspec are identical. Also handle the special
380 * case where just '/' is mounted and 'spec' is not
381 * identical with the one from fstab ('/dev' is missing
382 * in the spec-string at boot-time).
383 */
384 if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL) {

--- 21 unchanged lines hidden (view full) ---

406 mntbuf->f_flags);
407 }
408 rval = mountfs(mntbuf->f_fstypename, mntfromname,
409 mntbuf->f_mntonname, init_flags, options, 0);
410 break;
411 }
412 if ((fs = getfsfile(*argv)) == NULL &&
413 (fs = getfsspec(*argv)) == NULL)
398 /*
399 * Only get the mntflags from fstab if both mntpoint
400 * and mntspec are identical. Also handle the special
401 * case where just '/' is mounted and 'spec' is not
402 * identical with the one from fstab ('/dev' is missing
403 * in the spec-string at boot-time).
404 */
405 if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL) {

--- 21 unchanged lines hidden (view full) ---

427 mntbuf->f_flags);
428 }
429 rval = mountfs(mntbuf->f_fstypename, mntfromname,
430 mntbuf->f_mntonname, init_flags, options, 0);
431 break;
432 }
433 if ((fs = getfsfile(*argv)) == NULL &&
434 (fs = getfsspec(*argv)) == NULL)
414 errx(1, "%s: unknown special file or file system",
435 xo_errx(1, "%s: unknown special file or file system",
415 *argv);
416 if (BADTYPE(fs->fs_type))
436 *argv);
437 if (BADTYPE(fs->fs_type))
417 errx(1, "%s has unknown file system type",
438 xo_errx(1, "%s has unknown file system type",
418 *argv);
419 rval = mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file,
420 init_flags, options, fs->fs_mntops);
421 break;
422 case 2:
423 /*
424 * If -t flag has not been specified, the path cannot be
425 * found, spec contains either a ':' or a '@', then assume

--- 29 unchanged lines hidden (view full) ---

455
456 /*
457 * If the mount was successfully, and done by root, tell mountd the
458 * good news.
459 */
460 if (rval == 0 && getuid() == 0)
461 restart_mountd();
462
439 *argv);
440 rval = mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file,
441 init_flags, options, fs->fs_mntops);
442 break;
443 case 2:
444 /*
445 * If -t flag has not been specified, the path cannot be
446 * found, spec contains either a ':' or a '@', then assume

--- 29 unchanged lines hidden (view full) ---

476
477 /*
478 * If the mount was successfully, and done by root, tell mountd the
479 * good news.
480 */
481 if (rval == 0 && getuid() == 0)
482 restart_mountd();
483
463 exit(rval);
484 EXIT(rval);
464}
465
466int
467ismounted(struct fstab *fs, struct statfs *mntbuf, int mntsize)
468{
469 char realfsfile[PATH_MAX];
470 int i;
471

--- 60 unchanged lines hidden (view full) ---

532
533static void
534append_arg(struct cpa *sa, char *arg)
535{
536 if (sa->c + 1 == sa->sz) {
537 sa->sz = sa->sz == 0 ? 8 : sa->sz * 2;
538 sa->a = realloc(sa->a, sizeof(*sa->a) * sa->sz);
539 if (sa->a == NULL)
485}
486
487int
488ismounted(struct fstab *fs, struct statfs *mntbuf, int mntsize)
489{
490 char realfsfile[PATH_MAX];
491 int i;
492

--- 60 unchanged lines hidden (view full) ---

553
554static void
555append_arg(struct cpa *sa, char *arg)
556{
557 if (sa->c + 1 == sa->sz) {
558 sa->sz = sa->sz == 0 ? 8 : sa->sz * 2;
559 sa->a = realloc(sa->a, sizeof(*sa->a) * sa->sz);
560 if (sa->a == NULL)
540 errx(1, "realloc failed");
561 xo_errx(1, "realloc failed");
541 }
542 sa->a[++sa->c] = arg;
543}
544
545int
546mountfs(const char *vfstype, const char *spec, const char *name, int flags,
547 const char *options, const char *mntopts)
548{
549 struct statfs sf;
550 int i, ret;
551 char *optbuf, execname[PATH_MAX], mntpath[PATH_MAX];
552 static struct cpa mnt_argv;
553
554 /* resolve the mountpoint with realpath(3) */
555 if (checkpath(name, mntpath) != 0) {
562 }
563 sa->a[++sa->c] = arg;
564}
565
566int
567mountfs(const char *vfstype, const char *spec, const char *name, int flags,
568 const char *options, const char *mntopts)
569{
570 struct statfs sf;
571 int i, ret;
572 char *optbuf, execname[PATH_MAX], mntpath[PATH_MAX];
573 static struct cpa mnt_argv;
574
575 /* resolve the mountpoint with realpath(3) */
576 if (checkpath(name, mntpath) != 0) {
556 warn("%s", mntpath);
577 xo_warn("%s", mntpath);
557 return (1);
558 }
559 name = mntpath;
560
561 if (mntopts == NULL)
562 mntopts = "";
563 optbuf = catopt(strdup(mntopts), options);
564

--- 26 unchanged lines hidden (view full) ---

591 strlcpy(execname, mountprog, sizeof(execname));
592
593 append_arg(&mnt_argv, strdup(spec));
594 append_arg(&mnt_argv, strdup(name));
595 append_arg(&mnt_argv, NULL);
596
597 if (debug) {
598 if (use_mountprog(vfstype))
578 return (1);
579 }
580 name = mntpath;
581
582 if (mntopts == NULL)
583 mntopts = "";
584 optbuf = catopt(strdup(mntopts), options);
585

--- 26 unchanged lines hidden (view full) ---

612 strlcpy(execname, mountprog, sizeof(execname));
613
614 append_arg(&mnt_argv, strdup(spec));
615 append_arg(&mnt_argv, strdup(name));
616 append_arg(&mnt_argv, NULL);
617
618 if (debug) {
619 if (use_mountprog(vfstype))
599 printf("exec: %s", execname);
620 xo_emit("{Lwc:exec}{:execname/%s}", execname);
600 else
621 else
601 printf("mount -t %s", vfstype);
622 xo_emit("{:execname/mount}{P: }{l:opts/-t}{P: }{l:opts/%s}", vfstype);
602 for (i = 1; i < mnt_argv.c; i++)
623 for (i = 1; i < mnt_argv.c; i++)
603 (void)printf(" %s", mnt_argv.a[i]);
604 (void)printf("\n");
624 xo_emit("{P: }{l:opts}", mnt_argv.a[i]);
625 xo_emit("\n");
605 free(optbuf);
606 free(mountprog);
607 mountprog = NULL;
608 return (0);
609 }
610
611 if (use_mountprog(vfstype)) {
612 ret = exec_mountprog(name, execname, mnt_argv.a);
613 } else {
614 ret = mount_fs(vfstype, mnt_argv.c, mnt_argv.a);
615 }
616
617 free(optbuf);
618 free(mountprog);
619 mountprog = NULL;
620
621 if (verbose) {
622 if (statfs(name, &sf) < 0) {
626 free(optbuf);
627 free(mountprog);
628 mountprog = NULL;
629 return (0);
630 }
631
632 if (use_mountprog(vfstype)) {
633 ret = exec_mountprog(name, execname, mnt_argv.a);
634 } else {
635 ret = mount_fs(vfstype, mnt_argv.c, mnt_argv.a);
636 }
637
638 free(optbuf);
639 free(mountprog);
640 mountprog = NULL;
641
642 if (verbose) {
643 if (statfs(name, &sf) < 0) {
623 warn("statfs %s", name);
644 xo_warn("statfs %s", name);
624 return (1);
625 }
645 return (1);
646 }
626 if (fstab_style)
647 if (fstab_style) {
648 xo_open_list("fstab");
649 xo_open_instance("fstab");
627 putfsent(&sf);
650 putfsent(&sf);
628 else
651 xo_close_instance("fstab");
652 xo_close_list("fstab");
653 } else {
654 xo_open_list("mounted");
655 xo_open_instance("mounted");
629 prmount(&sf);
656 prmount(&sf);
657 xo_close_instance("mounted");
658 xo_close_list("mounted");
659 }
630 }
631
632 return (ret);
633}
634
635void
636prmount(struct statfs *sfp)
637{
638 uint64_t flags;
639 unsigned int i;
640 struct mntoptnames *o;
641 struct passwd *pw;
660 }
661
662 return (ret);
663}
664
665void
666prmount(struct statfs *sfp)
667{
668 uint64_t flags;
669 unsigned int i;
670 struct mntoptnames *o;
671 struct passwd *pw;
672 char *fsidbuf;
642
673
643 (void)printf("%s on %s (%s", sfp->f_mntfromname, sfp->f_mntonname,
644 sfp->f_fstypename);
674 xo_emit("{:special}{L: on }{:node}{L: (}{:fstype}", sfp->f_mntfromname,
675 sfp->f_mntonname, sfp->f_fstypename);
645
646 flags = sfp->f_flags & MNT_VISFLAGMASK;
647 for (o = optnames; flags != 0 && o->o_opt != 0; o++)
648 if (flags & o->o_opt) {
676
677 flags = sfp->f_flags & MNT_VISFLAGMASK;
678 for (o = optnames; flags != 0 && o->o_opt != 0; o++)
679 if (flags & o->o_opt) {
649 (void)printf(", %s", o->o_name);
680 xo_emit("{D:, }{l:opts}", o->o_name);
650 flags &= ~o->o_opt;
651 }
652 /*
653 * Inform when file system is mounted by an unprivileged user
654 * or privileged non-root user.
655 */
656 if ((flags & MNT_USER) != 0 || sfp->f_owner != 0) {
681 flags &= ~o->o_opt;
682 }
683 /*
684 * Inform when file system is mounted by an unprivileged user
685 * or privileged non-root user.
686 */
687 if ((flags & MNT_USER) != 0 || sfp->f_owner != 0) {
657 (void)printf(", mounted by ");
688 xo_emit("{D:, }{L:mounted by }");
658 if ((pw = getpwuid(sfp->f_owner)) != NULL)
689 if ((pw = getpwuid(sfp->f_owner)) != NULL)
659 (void)printf("%s", pw->pw_name);
690 xo_emit("{:mounter}", pw->pw_name);
660 else
691 else
661 (void)printf("%d", sfp->f_owner);
692 xo_emit("{:mounter}", sfp->f_owner);
662 }
663 if (verbose) {
693 }
694 if (verbose) {
664 if (sfp->f_syncwrites != 0 || sfp->f_asyncwrites != 0)
665 (void)printf(", writes: sync %ju async %ju",
695 if (sfp->f_syncwrites != 0 || sfp->f_asyncwrites != 0) {
696 xo_open_container("writes");
697 xo_emit("{D:, }{Lwc:writes}{Lw:sync}{w:sync/%ju}{Lw:async}{:async/%ju}",
666 (uintmax_t)sfp->f_syncwrites,
667 (uintmax_t)sfp->f_asyncwrites);
698 (uintmax_t)sfp->f_syncwrites,
699 (uintmax_t)sfp->f_asyncwrites);
668 if (sfp->f_syncreads != 0 || sfp->f_asyncreads != 0)
669 (void)printf(", reads: sync %ju async %ju",
700 xo_close_container("writes");
701 }
702 if (sfp->f_syncreads != 0 || sfp->f_asyncreads != 0) {
703 xo_open_container("reads");
704 xo_emit("{D:, }{Lwc:reads}{Lw:sync}{w:sync/%ju}{Lw:async}{:async/%ju}",
670 (uintmax_t)sfp->f_syncreads,
671 (uintmax_t)sfp->f_asyncreads);
705 (uintmax_t)sfp->f_syncreads,
706 (uintmax_t)sfp->f_asyncreads);
707 xo_close_container("reads");
708 }
672 if (sfp->f_fsid.val[0] != 0 || sfp->f_fsid.val[1] != 0) {
709 if (sfp->f_fsid.val[0] != 0 || sfp->f_fsid.val[1] != 0) {
673 (void)printf(", fsid ");
710 fsidbuf = malloc(sizeof(sfp->f_fsid) * 2 + 1);
711 if (fsidbuf == NULL)
712 xo_errx(1, "malloc failed");
674 for (i = 0; i < sizeof(sfp->f_fsid); i++)
713 for (i = 0; i < sizeof(sfp->f_fsid); i++)
675 (void)printf("%02x", ((u_char *)&sfp->f_fsid)[i]);
714 sprintf(&fsidbuf[i * 2], "%02x",
715 ((u_char *)&sfp->f_fsid)[i]);
716 fsidbuf[i * 2] = '\0';
717 xo_emit("{D:, }{Lw:fsid}{:fsid}", fsidbuf);
718 free(fsidbuf);
676 }
677 }
719 }
720 }
678 (void)printf(")\n");
721 xo_emit("{D:)}\n");
679}
680
681struct statfs *
682getmntpt(const char *name)
683{
684 struct statfs *mntbuf;
685 int i, mntsize;
686

--- 11 unchanged lines hidden (view full) ---

698{
699 char *cp;
700
701 if (s1 == NULL || *s1 == '\0')
702 return (s0);
703
704 if (s0 && *s0) {
705 if (asprintf(&cp, "%s,%s", s0, s1) == -1)
722}
723
724struct statfs *
725getmntpt(const char *name)
726{
727 struct statfs *mntbuf;
728 int i, mntsize;
729

--- 11 unchanged lines hidden (view full) ---

741{
742 char *cp;
743
744 if (s1 == NULL || *s1 == '\0')
745 return (s0);
746
747 if (s0 && *s0) {
748 if (asprintf(&cp, "%s,%s", s0, s1) == -1)
706 errx(1, "asprintf failed");
749 xo_errx(1, "asprintf failed");
707 } else
708 cp = strdup(s1);
709
710 if (s0)
711 free(s0);
712 return (cp);
713}
714

--- 38 unchanged lines hidden (view full) ---

753 val = strchr(p, '=');
754 if (val != NULL) {
755 ++val;
756 if (*val != '\0')
757 mountprog = strdup(val);
758 }
759
760 if (mountprog == NULL) {
750 } else
751 cp = strdup(s1);
752
753 if (s0)
754 free(s0);
755 return (cp);
756}
757

--- 38 unchanged lines hidden (view full) ---

796 val = strchr(p, '=');
797 if (val != NULL) {
798 ++val;
799 if (*val != '\0')
800 mountprog = strdup(val);
801 }
802
803 if (mountprog == NULL) {
761 errx(1, "Need value for -o mountprog");
804 xo_errx(1, "Need value for -o mountprog");
762 }
763 continue;
764 } else if (strcmp(p, "userquota") == 0) {
765 continue;
766 } else if (strncmp(p, userquotaeq,
767 sizeof(userquotaeq) - 1) == 0) {
768 continue;
769 } else if (strcmp(p, "groupquota") == 0) {

--- 49 unchanged lines hidden (view full) ---

819 /*
820 * Remove previous contradictory arguments. Given option "foo" we
821 * remove all the "nofoo" options. Given "nofoo" we remove "nonofoo"
822 * and "foo" - so we can deal with possible options like "notice".
823 */
824 newopt = NULL;
825 for (p = expopt; (o = strsep(&p, ",")) != NULL;) {
826 if ((tmpopt = malloc( strlen(o) + 2 + 1 )) == NULL)
805 }
806 continue;
807 } else if (strcmp(p, "userquota") == 0) {
808 continue;
809 } else if (strncmp(p, userquotaeq,
810 sizeof(userquotaeq) - 1) == 0) {
811 continue;
812 } else if (strcmp(p, "groupquota") == 0) {

--- 49 unchanged lines hidden (view full) ---

862 /*
863 * Remove previous contradictory arguments. Given option "foo" we
864 * remove all the "nofoo" options. Given "nofoo" we remove "nonofoo"
865 * and "foo" - so we can deal with possible options like "notice".
866 */
867 newopt = NULL;
868 for (p = expopt; (o = strsep(&p, ",")) != NULL;) {
869 if ((tmpopt = malloc( strlen(o) + 2 + 1 )) == NULL)
827 errx(1, "malloc failed");
870 xo_errx(1, "malloc failed");
828
829 strcpy(tmpopt, "no");
830 strcat(tmpopt, o);
831 remopt(newopt, tmpopt);
832 free(tmpopt);
833
834 if (strncmp("no", o, 2) == 0)
835 remopt(newopt, o+2);

--- 26 unchanged lines hidden (view full) ---

862 }
863 *r = '\0';
864}
865
866void
867usage(void)
868{
869
871
872 strcpy(tmpopt, "no");
873 strcat(tmpopt, o);
874 remopt(newopt, tmpopt);
875 free(tmpopt);
876
877 if (strncmp("no", o, 2) == 0)
878 remopt(newopt, o+2);

--- 26 unchanged lines hidden (view full) ---

905 }
906 *r = '\0';
907}
908
909void
910usage(void)
911{
912
870 (void)fprintf(stderr, "%s\n%s\n%s\n",
913 xo_error("%s\n%s\n%s\n",
871"usage: mount [-adflpruvw] [-F fstab] [-o options] [-t ufs | external_type]",
872" mount [-dfpruvw] special | node",
873" mount [-dfpruvw] [-o options] [-t ufs | external_type] special node");
914"usage: mount [-adflpruvw] [-F fstab] [-o options] [-t ufs | external_type]",
915" mount [-dfpruvw] special | node",
916" mount [-dfpruvw] [-o options] [-t ufs | external_type] special node");
874 exit(1);
917 EXIT(1);
875}
876
877void
878putfsent(struct statfs *ent)
879{
880 struct fstab *fst;
881 char *opts, *rw;
882 int l;

--- 11 unchanged lines hidden (view full) ---

894 if (strncmp(ent->f_mntfromname, "<below>", 7) == 0 ||
895 strncmp(ent->f_mntfromname, "<above>", 7) == 0) {
896 strlcpy(ent->f_mntfromname,
897 (strnstr(ent->f_mntfromname, ":", 8) +1),
898 sizeof(ent->f_mntfromname));
899 }
900
901 l = strlen(ent->f_mntfromname);
918}
919
920void
921putfsent(struct statfs *ent)
922{
923 struct fstab *fst;
924 char *opts, *rw;
925 int l;

--- 11 unchanged lines hidden (view full) ---

937 if (strncmp(ent->f_mntfromname, "<below>", 7) == 0 ||
938 strncmp(ent->f_mntfromname, "<above>", 7) == 0) {
939 strlcpy(ent->f_mntfromname,
940 (strnstr(ent->f_mntfromname, ":", 8) +1),
941 sizeof(ent->f_mntfromname));
942 }
943
944 l = strlen(ent->f_mntfromname);
902 printf("%s%s%s%s", ent->f_mntfromname,
945 xo_emit("{:device}{P:/%s}{P:/%s}{P:/%s}",
946 ent->f_mntfromname,
903 l < 8 ? "\t" : "",
904 l < 16 ? "\t" : "",
905 l < 24 ? "\t" : " ");
906 l = strlen(ent->f_mntonname);
947 l < 8 ? "\t" : "",
948 l < 16 ? "\t" : "",
949 l < 24 ? "\t" : " ");
950 l = strlen(ent->f_mntonname);
907 printf("%s%s%s%s", ent->f_mntonname,
951 xo_emit("{:mntpoint}{P:/%s}{P:/%s}{P:/%s}",
952 ent->f_mntonname,
908 l < 8 ? "\t" : "",
909 l < 16 ? "\t" : "",
910 l < 24 ? "\t" : " ");
953 l < 8 ? "\t" : "",
954 l < 16 ? "\t" : "",
955 l < 24 ? "\t" : " ");
911 printf("%s\t", ent->f_fstypename);
956 xo_emit("{:fstype}{P:\t}", ent->f_fstypename);
912 l = strlen(opts);
957 l = strlen(opts);
913 printf("%s%s", opts,
958 xo_emit("{:opts}{P:/%s}", opts,
914 l < 8 ? "\t" : " ");
915 free(opts);
916
917 if ((fst = getfsspec(ent->f_mntfromname)))
959 l < 8 ? "\t" : " ");
960 free(opts);
961
962 if ((fst = getfsspec(ent->f_mntfromname)))
918 printf("\t%u %u\n", fst->fs_freq, fst->fs_passno);
963 xo_emit("{P:\t}{n:dump/%u}{P: }{n:pass/%u}\n",
964 fst->fs_freq, fst->fs_passno);
919 else if ((fst = getfsfile(ent->f_mntonname)))
965 else if ((fst = getfsfile(ent->f_mntonname)))
920 printf("\t%u %u\n", fst->fs_freq, fst->fs_passno);
966 xo_emit("{P:\t}{n:dump/%u}{P: }{n:pass/%u}\n",
967 fst->fs_freq, fst->fs_passno);
921 else if (strcmp(ent->f_fstypename, "ufs") == 0) {
922 if (strcmp(ent->f_mntonname, "/") == 0)
968 else if (strcmp(ent->f_fstypename, "ufs") == 0) {
969 if (strcmp(ent->f_mntonname, "/") == 0)
923 printf("\t1 1\n");
970 xo_emit("{P:\t}{n:dump/1}{P: }{n:pass/1}\n");
924 else
971 else
925 printf("\t2 2\n");
972 xo_emit("{P:\t}{n:dump/2}{P: }{n:pass/2}\n");
926 } else
973 } else
927 printf("\t0 0\n");
974 xo_emit("{P:\t}{n:dump/0}{P: }{n:pass/0}\n");
928}
929
930
931char *
932flags2opts(int flags)
933{
934 char *res;
935

--- 22 unchanged lines hidden ---
975}
976
977
978char *
979flags2opts(int flags)
980{
981 char *res;
982

--- 22 unchanged lines hidden ---