diff options
Diffstat (limited to 'usr.bin/lsvfs/lsvfs.c')
-rw-r--r-- | usr.bin/lsvfs/lsvfs.c | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/usr.bin/lsvfs/lsvfs.c b/usr.bin/lsvfs/lsvfs.c index 5477d96434ac..8925b8988cd3 100644 --- a/usr.bin/lsvfs/lsvfs.c +++ b/usr.bin/lsvfs/lsvfs.c @@ -5,10 +5,12 @@ * */ +#include <sys/capsicum.h> #include <sys/param.h> #include <sys/mount.h> #include <sys/sysctl.h> +#include <capsicum_helpers.h> #include <err.h> #include <stdio.h> #include <stdlib.h> @@ -38,41 +40,42 @@ static const char *fmt_flags(int); int main(int argc, char **argv) { - struct xvfsconf vfc, *xvfsp; + struct xvfsconf *xvfsp; size_t cnt, buflen; int rv = 0; argc--, argv++; + if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0) + err(EXIT_FAILURE, "sysctl(vfs.conflist)"); + if ((xvfsp = malloc(buflen)) == NULL) + errx(EXIT_FAILURE, "malloc failed"); + if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0) + err(EXIT_FAILURE, "sysctl(vfs.conflist)"); + cnt = buflen / sizeof(struct xvfsconf); + + caph_cache_catpages(); + if (caph_enter() != 0) + err(EXIT_FAILURE, "failed to enter capability mode"); + printf(HDRFMT, "Filesystem", "Num", "Refs", "Flags"); fputs(DASHES, stdout); - if (argc > 0) { - for (; argc > 0; argc--, argv++) { - if (getvfsbyname(*argv, &vfc) == 0) { - printf(FMT, vfc.vfc_name, vfc.vfc_typenum, - vfc.vfc_refcount, fmt_flags(vfc.vfc_flags)); - } else { - warnx("VFS %s unknown or not loaded", *argv); - rv++; + for (size_t i = 0; i < cnt; i++) { + if (argc > 0) { + int j; + for (j = 0; j < argc; j++) { + if (strcmp(argv[j], xvfsp[i].vfc_name) == 0) + break; } + if (j == argc) + continue; } - } else { - if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0) - err(EXIT_FAILURE, "sysctl(vfs.conflist)"); - if ((xvfsp = malloc(buflen)) == NULL) - errx(EXIT_FAILURE, "malloc failed"); - if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0) - err(EXIT_FAILURE, "sysctl(vfs.conflist)"); - cnt = buflen / sizeof(struct xvfsconf); - - for (size_t i = 0; i < cnt; i++) { - printf(FMT, xvfsp[i].vfc_name, xvfsp[i].vfc_typenum, - xvfsp[i].vfc_refcount, - fmt_flags(xvfsp[i].vfc_flags)); - } - free(xvfsp); + + printf(FMT, xvfsp[i].vfc_name, xvfsp[i].vfc_typenum, + xvfsp[i].vfc_refcount, fmt_flags(xvfsp[i].vfc_flags)); } + free(xvfsp); return (rv); } |