Changeset View
Standalone View
sbin/mount/mount.c
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | |||||
#include <pwd.h> | #include <pwd.h> | ||||
#include <signal.h> | #include <signal.h> | ||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <libutil.h> | #include <libutil.h> | ||||
#include <libxo/xo.h> | |||||
#include "extern.h" | #include "extern.h" | ||||
#include "mntopts.h" | #include "mntopts.h" | ||||
#include "pathnames.h" | #include "pathnames.h" | ||||
#define EXIT(a) { \ | |||||
imp: Minor nit: I'd align all the \ if they aren't already (it's hard to tell with phab sometimes… | |||||
Done Inline ActionsThis looks aligned in vim with freebsd.vim. me_cameronkatri.com: This looks aligned in vim with `freebsd.vim`. | |||||
xo_close_container("mount"); \ | |||||
xo_finish(); \ | |||||
exit(a); \ | |||||
} | |||||
/* `meta' options */ | /* `meta' options */ | ||||
#define MOUNT_META_OPTION_FSTAB "fstab" | #define MOUNT_META_OPTION_FSTAB "fstab" | ||||
#define MOUNT_META_OPTION_CURRENT "current" | #define MOUNT_META_OPTION_CURRENT "current" | ||||
static int debug, fstab_style, verbose; | static int debug, fstab_style, verbose; | ||||
struct cpa { | struct cpa { | ||||
char **a; | char **a; | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
static int | static int | ||||
exec_mountprog(const char *name, const char *execname, char *const argv[]) | exec_mountprog(const char *name, const char *execname, char *const argv[]) | ||||
{ | { | ||||
pid_t pid; | pid_t pid; | ||||
int status; | int status; | ||||
switch (pid = fork()) { | switch (pid = fork()) { | ||||
case -1: /* Error. */ | case -1: /* Error. */ | ||||
warn("fork"); | xo_warn("fork"); | ||||
Done Inline ActionsAren't these lines (151, 152) a suitable candidate for a macro? otis: Aren't these lines (151, 152) a suitable candidate for a macro? | |||||
exit (1); | EXIT(1); | ||||
case 0: /* Child. */ | case 0: /* Child. */ | ||||
/* Go find an executable. */ | /* Go find an executable. */ | ||||
execvP(execname, _PATH_SYSPATH, argv); | execvP(execname, _PATH_SYSPATH, argv); | ||||
if (errno == ENOENT) { | if (errno == ENOENT) { | ||||
warn("exec %s not found", execname); | xo_warn("exec %s not found", execname); | ||||
if (execname[0] != '/') { | if (execname[0] != '/') { | ||||
warnx("in path: %s", _PATH_SYSPATH); | xo_warnx("in path: %s", _PATH_SYSPATH); | ||||
} | } | ||||
} | } | ||||
exit(1); | EXIT(1); | ||||
default: /* Parent. */ | default: /* Parent. */ | ||||
if (waitpid(pid, &status, 0) < 0) { | if (waitpid(pid, &status, 0) < 0) { | ||||
warn("waitpid"); | xo_warn("waitpid"); | ||||
return (1); | return (1); | ||||
} | } | ||||
if (WIFEXITED(status)) { | if (WIFEXITED(status)) { | ||||
if (WEXITSTATUS(status) != 0) | if (WEXITSTATUS(status) != 0) | ||||
return (WEXITSTATUS(status)); | return (WEXITSTATUS(status)); | ||||
} else if (WIFSIGNALED(status)) { | } else if (WIFSIGNALED(status)) { | ||||
warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]); | xo_warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]); | ||||
return (1); | return (1); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
specified_ro(const char *arg) | specified_ro(const char *arg) | ||||
{ | { | ||||
char *optbuf, *opt; | char *optbuf, *opt; | ||||
int ret = 0; | int ret = 0; | ||||
optbuf = strdup(arg); | optbuf = strdup(arg); | ||||
if (optbuf == NULL) | if (optbuf == NULL) | ||||
err(1, NULL); | xo_err(1, NULL); | ||||
for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) { | for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) { | ||||
if (strcmp(opt, "ro") == 0) { | if (strcmp(opt, "ro") == 0) { | ||||
ret = 1; | ret = 1; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
free(optbuf); | free(optbuf); | ||||
Show All 18 Lines | if (errno != EEXIST) { | ||||
return; | return; | ||||
} | } | ||||
/* | /* | ||||
* Refuse to send broadcast or group signals, this has | * Refuse to send broadcast or group signals, this has | ||||
* happened due to the bugs in pidfile(3). | * happened due to the bugs in pidfile(3). | ||||
*/ | */ | ||||
if (mountdpid <= 0) { | if (mountdpid <= 0) { | ||||
warnx("mountd pid %d, refusing to send SIGHUP", mountdpid); | xo_warnx("mountd pid %d, refusing to send SIGHUP", mountdpid); | ||||
return; | return; | ||||
} | } | ||||
/* We have mountd(8) PID in mountdpid varible, let's signal it. */ | /* We have mountd(8) PID in mountdpid varible, let's signal it. */ | ||||
if (kill(mountdpid, SIGHUP) == -1) | if (kill(mountdpid, SIGHUP) == -1) | ||||
err(1, "signal mountd"); | xo_err(1, "signal mountd"); | ||||
} | } | ||||
int | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
const char *mntfromname, **vfslist, *vfstype; | const char *mntfromname, **vfslist, *vfstype; | ||||
struct fstab *fs; | struct fstab *fs; | ||||
struct statfs *mntbuf; | struct statfs *mntbuf; | ||||
int all, ch, i, init_flags, late, failok, mntsize, rval, have_fstab, ro; | int all, ch, i, init_flags, late, failok, mntsize, rval, have_fstab, ro; | ||||
int onlylate; | int onlylate; | ||||
char *cp, *ep, *options; | char *cp, *ep, *options; | ||||
all = init_flags = late = onlylate = 0; | all = init_flags = late = onlylate = 0; | ||||
ro = 0; | ro = 0; | ||||
options = NULL; | options = NULL; | ||||
vfslist = NULL; | vfslist = NULL; | ||||
vfstype = "ufs"; | vfstype = "ufs"; | ||||
argc = xo_parse_args(argc, argv); | |||||
if (argc < 0) | |||||
exit(1); | |||||
Done Inline ActionsThis doesn't make any sense. Negative return values from main are weird. imp: This doesn't make any sense. Negative return values from main are weird.
Better to do a xo_errx… | |||||
xo_open_container("mount"); | |||||
while ((ch = getopt(argc, argv, "adF:fLlno:prt:uvw")) != -1) | while ((ch = getopt(argc, argv, "adF:fLlno:prt:uvw")) != -1) | ||||
switch (ch) { | switch (ch) { | ||||
case 'a': | case 'a': | ||||
all = 1; | all = 1; | ||||
break; | break; | ||||
case 'd': | case 'd': | ||||
debug = 1; | debug = 1; | ||||
break; | break; | ||||
Show All 25 Lines | case 'p': | ||||
verbose = 1; | verbose = 1; | ||||
break; | break; | ||||
case 'r': | case 'r': | ||||
options = catopt(options, "ro"); | options = catopt(options, "ro"); | ||||
ro = 1; | ro = 1; | ||||
break; | break; | ||||
case 't': | case 't': | ||||
if (vfslist != NULL) | if (vfslist != NULL) | ||||
errx(1, "only one -t option may be specified"); | xo_errx(1, "only one -t option may be specified"); | ||||
vfslist = makevfslist(optarg); | vfslist = makevfslist(optarg); | ||||
vfstype = optarg; | vfstype = optarg; | ||||
break; | break; | ||||
case 'u': | case 'u': | ||||
init_flags |= MNT_UPDATE; | init_flags |= MNT_UPDATE; | ||||
break; | break; | ||||
case 'v': | case 'v': | ||||
verbose = 1; | verbose = 1; | ||||
Show All 16 Lines | #define BADTYPE(type) \ | ||||
if ((init_flags & MNT_UPDATE) && (ro == 0)) | if ((init_flags & MNT_UPDATE) && (ro == 0)) | ||||
options = catopt(options, "noro"); | options = catopt(options, "noro"); | ||||
rval = 0; | rval = 0; | ||||
switch (argc) { | switch (argc) { | ||||
case 0: | case 0: | ||||
if ((mntsize = getmntinfo(&mntbuf, | if ((mntsize = getmntinfo(&mntbuf, | ||||
verbose ? MNT_WAIT : MNT_NOWAIT)) == 0) | verbose ? MNT_WAIT : MNT_NOWAIT)) == 0) | ||||
err(1, "getmntinfo"); | xo_err(1, "getmntinfo"); | ||||
if (all) { | if (all) { | ||||
while ((fs = getfsent()) != NULL) { | while ((fs = getfsent()) != NULL) { | ||||
if (BADTYPE(fs->fs_type)) | if (BADTYPE(fs->fs_type)) | ||||
continue; | continue; | ||||
if (checkvfsname(fs->fs_vfstype, vfslist)) | if (checkvfsname(fs->fs_vfstype, vfslist)) | ||||
continue; | continue; | ||||
if (hasopt(fs->fs_mntops, "noauto")) | if (hasopt(fs->fs_mntops, "noauto")) | ||||
continue; | continue; | ||||
Show All 12 Lines | if (all) { | ||||
options = update_options(options, fs->fs_mntops, | options = update_options(options, fs->fs_mntops, | ||||
mntbuf->f_flags); | mntbuf->f_flags); | ||||
if (mountfs(fs->fs_vfstype, fs->fs_spec, | if (mountfs(fs->fs_vfstype, fs->fs_spec, | ||||
fs->fs_file, init_flags, options, | fs->fs_file, init_flags, options, | ||||
fs->fs_mntops) && !failok) | fs->fs_mntops) && !failok) | ||||
rval = 1; | rval = 1; | ||||
} | } | ||||
} else if (fstab_style) { | } else if (fstab_style) { | ||||
xo_open_list("fstab"); | |||||
for (i = 0; i < mntsize; i++) { | for (i = 0; i < mntsize; i++) { | ||||
if (checkvfsname(mntbuf[i].f_fstypename, vfslist)) | if (checkvfsname(mntbuf[i].f_fstypename, vfslist)) | ||||
continue; | continue; | ||||
xo_open_instance("fstab"); | |||||
putfsent(&mntbuf[i]); | putfsent(&mntbuf[i]); | ||||
xo_close_instance("fstab"); | |||||
} | } | ||||
xo_close_list("fstab"); | |||||
} else { | } else { | ||||
xo_open_list("mounted"); | |||||
for (i = 0; i < mntsize; i++) { | for (i = 0; i < mntsize; i++) { | ||||
if (checkvfsname(mntbuf[i].f_fstypename, | if (checkvfsname(mntbuf[i].f_fstypename, | ||||
vfslist)) | vfslist)) | ||||
continue; | continue; | ||||
if (!verbose && | if (!verbose && | ||||
(mntbuf[i].f_flags & MNT_IGNORE) != 0) | (mntbuf[i].f_flags & MNT_IGNORE) != 0) | ||||
continue; | continue; | ||||
xo_open_instance("mounted"); | |||||
prmount(&mntbuf[i]); | prmount(&mntbuf[i]); | ||||
xo_close_instance("mounted"); | |||||
} | } | ||||
xo_close_list("mounted"); | |||||
} | } | ||||
exit(rval); | EXIT(rval); | ||||
case 1: | case 1: | ||||
if (vfslist != NULL) | if (vfslist != NULL) | ||||
usage(); | usage(); | ||||
rmslashes(*argv, *argv); | rmslashes(*argv, *argv); | ||||
if (init_flags & MNT_UPDATE) { | if (init_flags & MNT_UPDATE) { | ||||
mntfromname = NULL; | mntfromname = NULL; | ||||
have_fstab = 0; | have_fstab = 0; | ||||
if ((mntbuf = getmntpt(*argv)) == NULL) | if ((mntbuf = getmntpt(*argv)) == NULL) | ||||
errx(1, "not currently mounted %s", *argv); | xo_errx(1, "not currently mounted %s", *argv); | ||||
/* | /* | ||||
* Only get the mntflags from fstab if both mntpoint | * Only get the mntflags from fstab if both mntpoint | ||||
* and mntspec are identical. Also handle the special | * and mntspec are identical. Also handle the special | ||||
* case where just '/' is mounted and 'spec' is not | * case where just '/' is mounted and 'spec' is not | ||||
* identical with the one from fstab ('/dev' is missing | * identical with the one from fstab ('/dev' is missing | ||||
* in the spec-string at boot-time). | * in the spec-string at boot-time). | ||||
*/ | */ | ||||
if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL) { | if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL) { | ||||
Show All 21 Lines | if (init_flags & MNT_UPDATE) { | ||||
mntbuf->f_flags); | mntbuf->f_flags); | ||||
} | } | ||||
rval = mountfs(mntbuf->f_fstypename, mntfromname, | rval = mountfs(mntbuf->f_fstypename, mntfromname, | ||||
mntbuf->f_mntonname, init_flags, options, 0); | mntbuf->f_mntonname, init_flags, options, 0); | ||||
break; | break; | ||||
} | } | ||||
if ((fs = getfsfile(*argv)) == NULL && | if ((fs = getfsfile(*argv)) == NULL && | ||||
(fs = getfsspec(*argv)) == NULL) | (fs = getfsspec(*argv)) == NULL) | ||||
errx(1, "%s: unknown special file or file system", | xo_errx(1, "%s: unknown special file or file system", | ||||
*argv); | *argv); | ||||
if (BADTYPE(fs->fs_type)) | if (BADTYPE(fs->fs_type)) | ||||
errx(1, "%s has unknown file system type", | xo_errx(1, "%s has unknown file system type", | ||||
*argv); | *argv); | ||||
rval = mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file, | rval = mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file, | ||||
init_flags, options, fs->fs_mntops); | init_flags, options, fs->fs_mntops); | ||||
break; | break; | ||||
case 2: | case 2: | ||||
/* | /* | ||||
* If -t flag has not been specified, the path cannot be | * If -t flag has not been specified, the path cannot be | ||||
* found, spec contains either a ':' or a '@', then assume | * found, spec contains either a ':' or a '@', then assume | ||||
Show All 29 Lines | #define BADTYPE(type) \ | ||||
/* | /* | ||||
* If the mount was successfully, and done by root, tell mountd the | * If the mount was successfully, and done by root, tell mountd the | ||||
* good news. | * good news. | ||||
*/ | */ | ||||
if (rval == 0 && getuid() == 0) | if (rval == 0 && getuid() == 0) | ||||
restart_mountd(); | restart_mountd(); | ||||
exit(rval); | EXIT(rval); | ||||
} | } | ||||
int | int | ||||
ismounted(struct fstab *fs, struct statfs *mntbuf, int mntsize) | ismounted(struct fstab *fs, struct statfs *mntbuf, int mntsize) | ||||
{ | { | ||||
char realfsfile[PATH_MAX]; | char realfsfile[PATH_MAX]; | ||||
int i; | int i; | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
append_arg(struct cpa *sa, char *arg) | append_arg(struct cpa *sa, char *arg) | ||||
{ | { | ||||
if (sa->c + 1 == sa->sz) { | if (sa->c + 1 == sa->sz) { | ||||
sa->sz = sa->sz == 0 ? 8 : sa->sz * 2; | sa->sz = sa->sz == 0 ? 8 : sa->sz * 2; | ||||
sa->a = realloc(sa->a, sizeof(*sa->a) * sa->sz); | sa->a = realloc(sa->a, sizeof(*sa->a) * sa->sz); | ||||
if (sa->a == NULL) | if (sa->a == NULL) | ||||
errx(1, "realloc failed"); | xo_errx(1, "realloc failed"); | ||||
} | } | ||||
sa->a[++sa->c] = arg; | sa->a[++sa->c] = arg; | ||||
} | } | ||||
int | int | ||||
mountfs(const char *vfstype, const char *spec, const char *name, int flags, | mountfs(const char *vfstype, const char *spec, const char *name, int flags, | ||||
const char *options, const char *mntopts) | const char *options, const char *mntopts) | ||||
{ | { | ||||
struct statfs sf; | struct statfs sf; | ||||
int i, ret; | int i, ret; | ||||
char *optbuf, execname[PATH_MAX], mntpath[PATH_MAX]; | char *optbuf, execname[PATH_MAX], mntpath[PATH_MAX]; | ||||
static struct cpa mnt_argv; | static struct cpa mnt_argv; | ||||
/* resolve the mountpoint with realpath(3) */ | /* resolve the mountpoint with realpath(3) */ | ||||
if (checkpath(name, mntpath) != 0) { | if (checkpath(name, mntpath) != 0) { | ||||
warn("%s", mntpath); | xo_warn("%s", mntpath); | ||||
return (1); | return (1); | ||||
} | } | ||||
name = mntpath; | name = mntpath; | ||||
if (mntopts == NULL) | if (mntopts == NULL) | ||||
mntopts = ""; | mntopts = ""; | ||||
optbuf = catopt(strdup(mntopts), options); | optbuf = catopt(strdup(mntopts), options); | ||||
Show All 26 Lines | if (mountprog != NULL) | ||||
strlcpy(execname, mountprog, sizeof(execname)); | strlcpy(execname, mountprog, sizeof(execname)); | ||||
append_arg(&mnt_argv, strdup(spec)); | append_arg(&mnt_argv, strdup(spec)); | ||||
append_arg(&mnt_argv, strdup(name)); | append_arg(&mnt_argv, strdup(name)); | ||||
append_arg(&mnt_argv, NULL); | append_arg(&mnt_argv, NULL); | ||||
if (debug) { | if (debug) { | ||||
if (use_mountprog(vfstype)) | if (use_mountprog(vfstype)) | ||||
printf("exec: %s", execname); | xo_emit("{Lwc:exec}{:execname/%s}", execname); | ||||
else | else | ||||
printf("mount -t %s", vfstype); | xo_emit("{:execname/mount}{P: }{l:opts/-t}{P: }{l:opts/%s}", vfstype); | ||||
for (i = 1; i < mnt_argv.c; i++) | for (i = 1; i < mnt_argv.c; i++) | ||||
(void)printf(" %s", mnt_argv.a[i]); | xo_emit("{P: }{l:opts}", mnt_argv.a[i]); | ||||
(void)printf("\n"); | xo_emit("\n"); | ||||
free(optbuf); | free(optbuf); | ||||
free(mountprog); | free(mountprog); | ||||
mountprog = NULL; | mountprog = NULL; | ||||
return (0); | return (0); | ||||
} | } | ||||
if (use_mountprog(vfstype)) { | if (use_mountprog(vfstype)) { | ||||
ret = exec_mountprog(name, execname, mnt_argv.a); | ret = exec_mountprog(name, execname, mnt_argv.a); | ||||
} else { | } else { | ||||
ret = mount_fs(vfstype, mnt_argv.c, mnt_argv.a); | ret = mount_fs(vfstype, mnt_argv.c, mnt_argv.a); | ||||
} | } | ||||
free(optbuf); | free(optbuf); | ||||
free(mountprog); | free(mountprog); | ||||
mountprog = NULL; | mountprog = NULL; | ||||
if (verbose) { | if (verbose) { | ||||
if (statfs(name, &sf) < 0) { | if (statfs(name, &sf) < 0) { | ||||
warn("statfs %s", name); | xo_warn("statfs %s", name); | ||||
return (1); | return (1); | ||||
} | } | ||||
if (fstab_style) | if (fstab_style) { | ||||
xo_open_list("fstab"); | |||||
xo_open_instance("fstab"); | |||||
putfsent(&sf); | putfsent(&sf); | ||||
else | xo_close_instance("fstab"); | ||||
xo_close_list("fstab"); | |||||
} else { | |||||
xo_open_list("mounted"); | |||||
xo_open_instance("mounted"); | |||||
prmount(&sf); | prmount(&sf); | ||||
xo_close_instance("mounted"); | |||||
xo_close_list("mounted"); | |||||
} | } | ||||
} | |||||
return (ret); | return (ret); | ||||
} | } | ||||
void | void | ||||
prmount(struct statfs *sfp) | prmount(struct statfs *sfp) | ||||
{ | { | ||||
uint64_t flags; | uint64_t flags; | ||||
unsigned int i; | unsigned int i; | ||||
struct mntoptnames *o; | struct mntoptnames *o; | ||||
struct passwd *pw; | struct passwd *pw; | ||||
char *fsidbuf; | |||||
(void)printf("%s on %s (%s", sfp->f_mntfromname, sfp->f_mntonname, | xo_emit("{:special}{L: on }{:node}{L: (}{:fstype}", sfp->f_mntfromname, | ||||
sfp->f_fstypename); | sfp->f_mntonname, sfp->f_fstypename); | ||||
Done Inline Actionsthis is indented too far. It should just be tab 4-spaces. imp: this is indented too far. It should just be tab 4-spaces.
| |||||
flags = sfp->f_flags & MNT_VISFLAGMASK; | flags = sfp->f_flags & MNT_VISFLAGMASK; | ||||
for (o = optnames; flags != 0 && o->o_opt != 0; o++) | for (o = optnames; flags != 0 && o->o_opt != 0; o++) | ||||
if (flags & o->o_opt) { | if (flags & o->o_opt) { | ||||
(void)printf(", %s", o->o_name); | xo_emit("{D:, }{l:opts}", o->o_name); | ||||
flags &= ~o->o_opt; | flags &= ~o->o_opt; | ||||
} | } | ||||
/* | /* | ||||
* Inform when file system is mounted by an unprivileged user | * Inform when file system is mounted by an unprivileged user | ||||
* or privileged non-root user. | * or privileged non-root user. | ||||
*/ | */ | ||||
if ((flags & MNT_USER) != 0 || sfp->f_owner != 0) { | if ((flags & MNT_USER) != 0 || sfp->f_owner != 0) { | ||||
(void)printf(", mounted by "); | xo_emit("{D:, }{L:mounted by }"); | ||||
if ((pw = getpwuid(sfp->f_owner)) != NULL) | if ((pw = getpwuid(sfp->f_owner)) != NULL) | ||||
(void)printf("%s", pw->pw_name); | xo_emit("{:mounter}", pw->pw_name); | ||||
else | else | ||||
(void)printf("%d", sfp->f_owner); | xo_emit("{:mounter}", sfp->f_owner); | ||||
} | } | ||||
if (verbose) { | if (verbose) { | ||||
if (sfp->f_syncwrites != 0 || sfp->f_asyncwrites != 0) | if (sfp->f_syncwrites != 0 || sfp->f_asyncwrites != 0) { | ||||
(void)printf(", writes: sync %ju async %ju", | xo_open_container("writes"); | ||||
xo_emit("{D:, }{Lwc:writes}{Lw:sync}{w:sync/%ju}{Lw:async}{:async/%ju}", | |||||
(uintmax_t)sfp->f_syncwrites, | (uintmax_t)sfp->f_syncwrites, | ||||
(uintmax_t)sfp->f_asyncwrites); | (uintmax_t)sfp->f_asyncwrites); | ||||
if (sfp->f_syncreads != 0 || sfp->f_asyncreads != 0) | xo_close_container("writes"); | ||||
(void)printf(", reads: sync %ju async %ju", | } | ||||
if (sfp->f_syncreads != 0 || sfp->f_asyncreads != 0) { | |||||
xo_open_container("reads"); | |||||
xo_emit("{D:, }{Lwc:reads}{Lw:sync}{w:sync/%ju}{Lw:async}{:async/%ju}", | |||||
(uintmax_t)sfp->f_syncreads, | (uintmax_t)sfp->f_syncreads, | ||||
(uintmax_t)sfp->f_asyncreads); | (uintmax_t)sfp->f_asyncreads); | ||||
xo_close_container("reads"); | |||||
} | |||||
if (sfp->f_fsid.val[0] != 0 || sfp->f_fsid.val[1] != 0) { | if (sfp->f_fsid.val[0] != 0 || sfp->f_fsid.val[1] != 0) { | ||||
(void)printf(", fsid "); | fsidbuf = malloc(sizeof(sfp->f_fsid) * 2 + 1); | ||||
if (fsidbuf == NULL) | |||||
Done Inline ActionsI'm not sure I understand the purpose of this, as asprintf will allocate the buffer and set fsidbuf to point to it. pstef: I'm not sure I understand the purpose of this, as asprintf will allocate the buffer and set… | |||||
Done Inline ActionsIf I don't do this, when using --libxo json the fsid will start with (null), I'm sure there is a better way to stop that but this worked. me_cameronkatri.com: If I don't do this, when using `--libxo json` the `fsid` will start with `(null)`, I'm sure… | |||||
Done Inline ActionsThere are some 32-bit ints in fsid_t and we want to interpret them as unsigned bytes and print using hexadecimal representation. So it's a matter of calculating the needed space once and using that space in a loop, like this: if (sfp->f_fsid.val[0] != 0 || sfp->f_fsid.val[1] != 0) { xo_emit("{D:, }{Lw:fsid}"); fsidbuf = malloc(sizeof(sfp->f_fsid) * 2 + 1); if (fsidbuf == NULL) xo_errx(1, "malloc failed"); for (i = 0; i < sizeof(sfp->f_fsid); i++) sprintf(&fsidbuf[i * 2], "%02x", ((u_char *)&sfp->f_fsid)[i]); fsidbuf[i * 2] = '\0'; xo_emit("{:fsid}", fsidbuf); free(fsidbuf); } pstef: There are some 32-bit ints in fsid_t and we want to interpret them as unsigned bytes and print… | |||||
Done Inline ActionsAnd then it seems the two xo_emit() calls can be folded into xo_emit("{D:, }{Lw:fsid}{:fsid}", fsidbuf); pstef: And then it seems the two xo_emit() calls can be folded into `xo_emit("{D:, }{Lw:fsid}{:fsid}"… | |||||
xo_errx(1, "malloc failed"); | |||||
for (i = 0; i < sizeof(sfp->f_fsid); i++) | for (i = 0; i < sizeof(sfp->f_fsid); i++) | ||||
(void)printf("%02x", ((u_char *)&sfp->f_fsid)[i]); | sprintf(&fsidbuf[i * 2], "%02x", | ||||
((u_char *)&sfp->f_fsid)[i]); | |||||
fsidbuf[i * 2] = '\0'; | |||||
xo_emit("{D:, }{Lw:fsid}{:fsid}", fsidbuf); | |||||
free(fsidbuf); | |||||
Done Inline ActionsProbably should check the return value of asprintf. pstef: Probably should check the return value of asprintf. | |||||
} | } | ||||
} | } | ||||
(void)printf(")\n"); | xo_emit("{D:)}\n"); | ||||
} | } | ||||
struct statfs * | struct statfs * | ||||
getmntpt(const char *name) | getmntpt(const char *name) | ||||
{ | { | ||||
struct statfs *mntbuf; | struct statfs *mntbuf; | ||||
int i, mntsize; | int i, mntsize; | ||||
Show All 11 Lines | |||||
{ | { | ||||
char *cp; | char *cp; | ||||
if (s1 == NULL || *s1 == '\0') | if (s1 == NULL || *s1 == '\0') | ||||
return (s0); | return (s0); | ||||
if (s0 && *s0) { | if (s0 && *s0) { | ||||
if (asprintf(&cp, "%s,%s", s0, s1) == -1) | if (asprintf(&cp, "%s,%s", s0, s1) == -1) | ||||
errx(1, "asprintf failed"); | xo_errx(1, "asprintf failed"); | ||||
} else | } else | ||||
cp = strdup(s1); | cp = strdup(s1); | ||||
if (s0) | if (s0) | ||||
free(s0); | free(s0); | ||||
return (cp); | return (cp); | ||||
} | } | ||||
Show All 38 Lines | if (*p != '\0') { | ||||
val = strchr(p, '='); | val = strchr(p, '='); | ||||
if (val != NULL) { | if (val != NULL) { | ||||
++val; | ++val; | ||||
if (*val != '\0') | if (*val != '\0') | ||||
mountprog = strdup(val); | mountprog = strdup(val); | ||||
} | } | ||||
if (mountprog == NULL) { | if (mountprog == NULL) { | ||||
errx(1, "Need value for -o mountprog"); | xo_errx(1, "Need value for -o mountprog"); | ||||
} | } | ||||
continue; | continue; | ||||
} else if (strcmp(p, "userquota") == 0) { | } else if (strcmp(p, "userquota") == 0) { | ||||
continue; | continue; | ||||
} else if (strncmp(p, userquotaeq, | } else if (strncmp(p, userquotaeq, | ||||
sizeof(userquotaeq) - 1) == 0) { | sizeof(userquotaeq) - 1) == 0) { | ||||
continue; | continue; | ||||
} else if (strcmp(p, "groupquota") == 0) { | } else if (strcmp(p, "groupquota") == 0) { | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | update_options(char *opts, char *fstab, int curflags) | ||||
/* | /* | ||||
* Remove previous contradictory arguments. Given option "foo" we | * Remove previous contradictory arguments. Given option "foo" we | ||||
* remove all the "nofoo" options. Given "nofoo" we remove "nonofoo" | * remove all the "nofoo" options. Given "nofoo" we remove "nonofoo" | ||||
* and "foo" - so we can deal with possible options like "notice". | * and "foo" - so we can deal with possible options like "notice". | ||||
*/ | */ | ||||
newopt = NULL; | newopt = NULL; | ||||
for (p = expopt; (o = strsep(&p, ",")) != NULL;) { | for (p = expopt; (o = strsep(&p, ",")) != NULL;) { | ||||
if ((tmpopt = malloc( strlen(o) + 2 + 1 )) == NULL) | if ((tmpopt = malloc( strlen(o) + 2 + 1 )) == NULL) | ||||
errx(1, "malloc failed"); | xo_errx(1, "malloc failed"); | ||||
strcpy(tmpopt, "no"); | strcpy(tmpopt, "no"); | ||||
strcat(tmpopt, o); | strcat(tmpopt, o); | ||||
remopt(newopt, tmpopt); | remopt(newopt, tmpopt); | ||||
free(tmpopt); | free(tmpopt); | ||||
if (strncmp("no", o, 2) == 0) | if (strncmp("no", o, 2) == 0) | ||||
remopt(newopt, o+2); | remopt(newopt, o+2); | ||||
Show All 26 Lines | remopt(char *string, const char *opt) | ||||
} | } | ||||
*r = '\0'; | *r = '\0'; | ||||
} | } | ||||
void | void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
(void)fprintf(stderr, "%s\n%s\n%s\n", | xo_error("%s\n%s\n%s\n", | ||||
"usage: mount [-adflpruvw] [-F fstab] [-o options] [-t ufs | external_type]", | "usage: mount [-adflpruvw] [-F fstab] [-o options] [-t ufs | external_type]", | ||||
Not Done Inline ActionsShould we update usage()? pstef: Should we update usage()? | |||||
Done Inline Actions
It doesn't look like any other commands show --libxo in their usage. me_cameronkatri.com: > Should we update usage()?
It doesn't look like any other commands show `--libxo` in their… | |||||
" mount [-dfpruvw] special | node", | " mount [-dfpruvw] special | node", | ||||
" mount [-dfpruvw] [-o options] [-t ufs | external_type] special node"); | " mount [-dfpruvw] [-o options] [-t ufs | external_type] special node"); | ||||
exit(1); | EXIT(1); | ||||
} | } | ||||
void | void | ||||
putfsent(struct statfs *ent) | putfsent(struct statfs *ent) | ||||
{ | { | ||||
struct fstab *fst; | struct fstab *fst; | ||||
char *opts, *rw; | char *opts, *rw; | ||||
int l; | int l; | ||||
Show All 11 Lines | putfsent(struct statfs *ent) | ||||
if (strncmp(ent->f_mntfromname, "<below>", 7) == 0 || | if (strncmp(ent->f_mntfromname, "<below>", 7) == 0 || | ||||
strncmp(ent->f_mntfromname, "<above>", 7) == 0) { | strncmp(ent->f_mntfromname, "<above>", 7) == 0) { | ||||
strlcpy(ent->f_mntfromname, | strlcpy(ent->f_mntfromname, | ||||
(strnstr(ent->f_mntfromname, ":", 8) +1), | (strnstr(ent->f_mntfromname, ":", 8) +1), | ||||
sizeof(ent->f_mntfromname)); | sizeof(ent->f_mntfromname)); | ||||
} | } | ||||
l = strlen(ent->f_mntfromname); | l = strlen(ent->f_mntfromname); | ||||
printf("%s%s%s%s", ent->f_mntfromname, | xo_emit("{:device}{P:/%s}{P:/%s}{P:/%s}", | ||||
ent->f_mntfromname, | |||||
l < 8 ? "\t" : "", | l < 8 ? "\t" : "", | ||||
l < 16 ? "\t" : "", | l < 16 ? "\t" : "", | ||||
l < 24 ? "\t" : " "); | l < 24 ? "\t" : " "); | ||||
l = strlen(ent->f_mntonname); | l = strlen(ent->f_mntonname); | ||||
printf("%s%s%s%s", ent->f_mntonname, | xo_emit("{:mntpoint}{P:/%s}{P:/%s}{P:/%s}", | ||||
ent->f_mntonname, | |||||
l < 8 ? "\t" : "", | l < 8 ? "\t" : "", | ||||
l < 16 ? "\t" : "", | l < 16 ? "\t" : "", | ||||
l < 24 ? "\t" : " "); | l < 24 ? "\t" : " "); | ||||
printf("%s\t", ent->f_fstypename); | xo_emit("{:fstype}{P:\t}", ent->f_fstypename); | ||||
l = strlen(opts); | l = strlen(opts); | ||||
printf("%s%s", opts, | xo_emit("{:opts}{P:/%s}", opts, | ||||
l < 8 ? "\t" : " "); | l < 8 ? "\t" : " "); | ||||
free(opts); | free(opts); | ||||
if ((fst = getfsspec(ent->f_mntfromname))) | if ((fst = getfsspec(ent->f_mntfromname))) | ||||
printf("\t%u %u\n", fst->fs_freq, fst->fs_passno); | xo_emit("{P:\t}{n:dump/%u}{P: }{n:pass/%u}\n", | ||||
fst->fs_freq, fst->fs_passno); | |||||
else if ((fst = getfsfile(ent->f_mntonname))) | else if ((fst = getfsfile(ent->f_mntonname))) | ||||
printf("\t%u %u\n", fst->fs_freq, fst->fs_passno); | xo_emit("{P:\t}{n:dump/%u}{P: }{n:pass/%u}\n", | ||||
fst->fs_freq, fst->fs_passno); | |||||
else if (strcmp(ent->f_fstypename, "ufs") == 0) { | else if (strcmp(ent->f_fstypename, "ufs") == 0) { | ||||
if (strcmp(ent->f_mntonname, "/") == 0) | if (strcmp(ent->f_mntonname, "/") == 0) | ||||
printf("\t1 1\n"); | xo_emit("{P:\t}{n:dump/1}{P: }{n:pass/1}\n"); | ||||
else | else | ||||
printf("\t2 2\n"); | xo_emit("{P:\t}{n:dump/2}{P: }{n:pass/2}\n"); | ||||
} else | } else | ||||
printf("\t0 0\n"); | xo_emit("{P:\t}{n:dump/0}{P: }{n:pass/0}\n"); | ||||
} | } | ||||
char * | char * | ||||
flags2opts(int flags) | flags2opts(int flags) | ||||
{ | { | ||||
char *res; | char *res; | ||||
Show All 22 Lines |
Minor nit: I'd align all the \ if they aren't already (it's hard to tell with phab sometimes, but I think there's a tab missing)