2 * lsvfs - list loaded VFSes
3 * Garrett A. Wollman, September 1994
4 * This file is in the public domain.
10 #include <sys/mount.h>
11 #include <sys/sysctl.h>
18 #define FMT "%-32.32s 0x%08x %5d %s\n"
19 #define HDRFMT "%-32.32s %10s %5.5s %s\n"
20 #define DASHES "-------------------------------- " \
21 "---------- ----- ---------------\n"
23 static struct flaglist {
25 const char str[32]; /* must be longer than the longest one. */
27 { .flag = VFCF_STATIC, .str = "static", },
28 { .flag = VFCF_NETWORK, .str = "network", },
29 { .flag = VFCF_READONLY, .str = "read-only", },
30 { .flag = VFCF_SYNTHETIC, .str = "synthetic", },
31 { .flag = VFCF_LOOPBACK, .str = "loopback", },
32 { .flag = VFCF_UNICODE, .str = "unicode", },
33 { .flag = VFCF_JAIL, .str = "jail", },
34 { .flag = VFCF_DELEGADMIN, .str = "delegated-administration", },
37 static const char *fmt_flags(int);
40 main(int argc, char **argv)
42 struct xvfsconf vfc, *xvfsp;
48 printf(HDRFMT, "Filesystem", "Num", "Refs", "Flags");
49 fputs(DASHES, stdout);
52 for (; argc > 0; argc--, argv++) {
53 if (getvfsbyname(*argv, &vfc) == 0) {
54 printf(FMT, vfc.vfc_name, vfc.vfc_typenum,
55 vfc.vfc_refcount, fmt_flags(vfc.vfc_flags));
57 warnx("VFS %s unknown or not loaded", *argv);
62 if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0)
63 err(1, "sysctl(vfs.conflist)");
64 xvfsp = malloc(buflen);
66 errx(1, "malloc failed");
67 if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0)
68 err(1, "sysctl(vfs.conflist)");
69 cnt = buflen / sizeof(struct xvfsconf);
71 for (i = 0; i < cnt; i++) {
72 printf(FMT, xvfsp[i].vfc_name, xvfsp[i].vfc_typenum,
73 xvfsp[i].vfc_refcount,
74 fmt_flags(xvfsp[i].vfc_flags));
85 static char buf[sizeof(struct flaglist) * sizeof(fl)];
89 for (i = 0; i < (int)nitems(fl); i++) {
90 if ((flags & fl[i].flag) != 0) {
91 strlcat(buf, fl[i].str, sizeof(buf));
92 strlcat(buf, ", ", sizeof(buf));
96 /* Zap the trailing comma + space. */
98 buf[strlen(buf) - 2] = '\0';