2 * lsvfs - list loaded VFSes
3 * Garrett A. Wollman, September 1994
4 * This file is in the public domain.
10 #include <sys/sysctl.h>
17 #define FMT "%-32.32s 0x%08x %5d %s\n"
18 #define HDRFMT "%-32.32s %10s %5.5s %s\n"
19 #define DASHES "-------------------------------- " \
20 "---------- ----- ---------------\n"
22 static struct flaglist {
24 const char str[32]; /* must be longer than the longest one. */
26 { .flag = VFCF_STATIC, .str = "static", },
27 { .flag = VFCF_NETWORK, .str = "network", },
28 { .flag = VFCF_READONLY, .str = "read-only", },
29 { .flag = VFCF_SYNTHETIC, .str = "synthetic", },
30 { .flag = VFCF_LOOPBACK, .str = "loopback", },
31 { .flag = VFCF_UNICODE, .str = "unicode", },
32 { .flag = VFCF_JAIL, .str = "jail", },
33 { .flag = VFCF_DELEGADMIN, .str = "delegated-administration", },
36 static const char *fmt_flags(int);
39 main(int argc, char **argv)
41 struct xvfsconf vfc, *xvfsp;
47 printf(HDRFMT, "Filesystem", "Num", "Refs", "Flags");
48 fputs(DASHES, stdout);
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));
56 warnx("VFS %s unknown or not loaded", *argv);
61 if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0)
62 err(1, "sysctl(vfs.conflist)");
63 xvfsp = malloc(buflen);
65 errx(1, "malloc failed");
66 if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0)
67 err(1, "sysctl(vfs.conflist)");
68 cnt = buflen / sizeof(struct xvfsconf);
70 for (i = 0; i < cnt; i++) {
71 printf(FMT, xvfsp[i].vfc_name, xvfsp[i].vfc_typenum,
72 xvfsp[i].vfc_refcount,
73 fmt_flags(xvfsp[i].vfc_flags));
84 static char buf[sizeof(struct flaglist) * sizeof(fl)];
88 for (i = 0; i < (int)nitems(fl); i++) {
89 if ((flags & fl[i].flag) != 0) {
90 strlcat(buf, fl[i].str, sizeof(buf));
91 strlcat(buf, ", ", sizeof(buf));
95 /* Zap the trailing comma + space. */
97 buf[strlen(buf) - 2] = '\0';