]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - usr.bin/lsvfs/lsvfs.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / usr.bin / lsvfs / lsvfs.c
1 /*
2  * lsvfs - list loaded VFSes
3  * Garrett A. Wollman, September 1994
4  * This file is in the public domain.
5  *
6  */
7
8 #include <sys/cdefs.h>
9 __FBSDID("$FreeBSD$");
10
11 #include <sys/param.h>
12 #include <sys/mount.h>
13 #include <sys/sysctl.h>
14
15 #include <err.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19
20 #define FMT "%-32.32s %5d %s\n"
21 #define HDRFMT "%-32.32s %5.5s %s\n"
22 #define DASHES "-------------------------------- ----- ---------------\n"
23
24 static const char *fmt_flags(int);
25
26 int
27 main(int argc, char **argv)
28 {
29   int cnt, rv = 0, i; 
30   struct xvfsconf vfc, *xvfsp;
31   size_t buflen;
32   argc--, argv++;
33
34   printf(HDRFMT, "Filesystem", "Refs", "Flags");
35   fputs(DASHES, stdout);
36
37   if(argc) {
38     for(; argc; argc--, argv++) {
39       if (getvfsbyname(*argv, &vfc) == 0) {
40         printf(FMT, vfc.vfc_name, vfc.vfc_refcount, fmt_flags(vfc.vfc_flags));
41       } else {
42         warnx("VFS %s unknown or not loaded", *argv);
43         rv++;
44       }
45     }
46   } else {
47     if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0)
48       err(1, "sysctl(vfs.conflist)");
49     xvfsp = malloc(buflen);
50     if (xvfsp == NULL)
51       errx(1, "malloc failed");
52     if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0)
53       err(1, "sysctl(vfs.conflist)");
54     cnt = buflen / sizeof(struct xvfsconf);
55
56     for (i = 0; i < cnt; i++) {
57       printf(FMT, xvfsp[i].vfc_name, xvfsp[i].vfc_refcount,
58              fmt_flags(xvfsp[i].vfc_flags));
59     }
60     free(xvfsp);
61   }
62
63   return rv;
64 }
65
66 static const char *
67 fmt_flags(int flags)
68 {
69   /*
70    * NB: if you add new flags, don't forget to add them here vvvvvv too.
71    */
72   static char buf[sizeof
73     "static, network, read-only, synthetic, loopback, unicode, jail"];
74   int comma = 0;
75
76   buf[0] = '\0';
77
78   if(flags & VFCF_STATIC) {
79     if(comma++) strcat(buf, ", ");
80     strcat(buf, "static");
81   }
82
83   if(flags & VFCF_NETWORK) {
84     if(comma++) strcat(buf, ", ");
85     strcat(buf, "network");
86   }
87
88   if(flags & VFCF_READONLY) {
89     if(comma++) strcat(buf, ", ");
90     strcat(buf, "read-only");
91   }
92
93   if(flags & VFCF_SYNTHETIC) {
94     if(comma++) strcat(buf, ", ");
95     strcat(buf, "synthetic");
96   }
97
98   if(flags & VFCF_LOOPBACK) {
99     if(comma++) strcat(buf, ", ");
100     strcat(buf, "loopback");
101   }
102
103   if(flags & VFCF_UNICODE) {
104     if(comma++) strcat(buf, ", ");
105     strcat(buf, "unicode");
106   }
107
108   if(flags & VFCF_JAIL) {
109     if(comma++) strcat(buf, ", ");
110     strcat(buf, "jail");
111   }
112
113   return buf;
114 }