|
5 | 5 | *
|
6 | 6 | */
|
7 | 7 |
|
| 8 | +#include <sys/capsicum.h> |
8 | 9 | #include <sys/param.h>
|
9 | 10 | #include <sys/mount.h>
|
10 | 11 | #include <sys/sysctl.h>
|
11 | 12 |
|
| 13 | +#include <capsicum_helpers.h> |
12 | 14 | #include <err.h>
|
13 | 15 | #include <stdio.h>
|
14 | 16 | #include <stdlib.h>
|
@@ -38,41 +40,42 @@ static const char *fmt_flags(int);
|
38 | 40 | int
|
39 | 41 | main(int argc, char **argv)
|
40 | 42 | {
|
41 |
| - struct xvfsconf vfc, *xvfsp; |
| 43 | + struct xvfsconf *xvfsp; |
42 | 44 | size_t cnt, buflen;
|
43 | 45 | int rv = 0;
|
44 | 46 |
|
45 | 47 | argc--, argv++;
|
46 | 48 |
|
| 49 | + if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0) |
| 50 | + err(EXIT_FAILURE, "sysctl(vfs.conflist)"); |
| 51 | + if ((xvfsp = malloc(buflen)) == NULL) |
| 52 | + errx(EXIT_FAILURE, "malloc failed"); |
| 53 | + if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0) |
| 54 | + err(EXIT_FAILURE, "sysctl(vfs.conflist)"); |
| 55 | + cnt = buflen / sizeof(struct xvfsconf); |
| 56 | + |
| 57 | + caph_cache_catpages(); |
| 58 | + if (caph_enter() != 0) |
| 59 | + err(EXIT_FAILURE, "failed to enter capability mode"); |
| 60 | + |
47 | 61 | printf(HDRFMT, "Filesystem", "Num", "Refs", "Flags");
|
48 | 62 | fputs(DASHES, stdout);
|
49 | 63 |
|
50 |
| - if (argc > 0) { |
51 |
| - for (; argc > 0; argc--, argv++) { |
52 |
| - if (getvfsbyname(*argv, &vfc) == 0) { |
53 |
| - printf(FMT, vfc.vfc_name, vfc.vfc_typenum, |
54 |
| - vfc.vfc_refcount, fmt_flags(vfc.vfc_flags)); |
55 |
| - } else { |
56 |
| - warnx("VFS %s unknown or not loaded", *argv); |
57 |
| - rv++; |
| 64 | + for (size_t i = 0; i < cnt; i++) { |
| 65 | + if (argc > 0) { |
| 66 | + size_t j; |
| 67 | + for (j = 0; j < argc; j++) { |
| 68 | + if (strcmp(argv[j], xvfsp[i].vfc_name) == 0) |
| 69 | + break; |
58 | 70 | }
|
| 71 | + if (j == argc) |
| 72 | + continue; |
59 | 73 | }
|
60 |
| - } else { |
61 |
| - if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0) |
62 |
| - err(EXIT_FAILURE, "sysctl(vfs.conflist)"); |
63 |
| - if ((xvfsp = malloc(buflen)) == NULL) |
64 |
| - errx(EXIT_FAILURE, "malloc failed"); |
65 |
| - if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0) |
66 |
| - err(EXIT_FAILURE, "sysctl(vfs.conflist)"); |
67 |
| - cnt = buflen / sizeof(struct xvfsconf); |
68 |
| - |
69 |
| - for (size_t i = 0; i < cnt; i++) { |
70 |
| - printf(FMT, xvfsp[i].vfc_name, xvfsp[i].vfc_typenum, |
71 |
| - xvfsp[i].vfc_refcount, |
72 |
| - fmt_flags(xvfsp[i].vfc_flags)); |
73 |
| - } |
74 |
| - free(xvfsp); |
| 74 | + |
| 75 | + printf(FMT, xvfsp[i].vfc_name, xvfsp[i].vfc_typenum, |
| 76 | + xvfsp[i].vfc_refcount, fmt_flags(xvfsp[i].vfc_flags)); |
75 | 77 | }
|
| 78 | + free(xvfsp); |
76 | 79 |
|
77 | 80 | return (rv);
|
78 | 81 | }
|
|
0 commit comments