xref: /dragonfly/usr.bin/lsvfs/lsvfs.c (revision 70344474)
1 /*
2  * lsvfs - list loaded VFSes
3  * Garrett A. Wollman, September 1994
4  * This file is in the public domain.
5  *
6  * $FreeBSD: src/usr.bin/lsvfs/lsvfs.c,v 1.13.2.1 2001/07/30 09:59:16 dd Exp $
7  */
8 
9 #define _NEW_VFSCONF
10 
11 #include <sys/param.h>
12 #include <sys/mount.h>
13 
14 #include <err.h>
15 #include <stdio.h>
16 #include <string.h>
17 
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"
22 
23 static struct flaglist {
24 	int		flag;
25 	const char	str[32]; /* must be longer than the longest one. */
26 } fl[] = {
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 };
34 
35 static const char *fmt_flags(int);
36 
37 int
38 main(int argc, char **argv)
39 {
40 	int rv = 0;
41 	struct vfsconf vfc;
42 	struct ovfsconf *ovfcp;
43 	argc--, argv++;
44 
45 	setvfsent(1);
46 
47 	printf(HDRFMT, "Filesystem", "Num", "Refs", "Flags");
48 	fputs(DASHES, stdout);
49 
50 	if(argc) {
51 		for(; argc; argc--, argv++) {
52 			if (getvfsbyname(*argv, &vfc) == 0) {
53 				printf(FMT, vfc.vfc_name, vfc.vfc_typenum,
54 				    vfc.vfc_refcount,
55 				    fmt_flags(vfc.vfc_flags));
56 			} else {
57 				warnx("VFS %s unknown or not loaded", *argv);
58 				rv = 1;
59 			}
60 		}
61 	} else {
62 		while ((ovfcp = getvfsent()) != NULL) {
63 			if (getvfsbyname(ovfcp->vfc_name, &vfc) == 0) {
64 				printf(FMT, vfc.vfc_name, vfc.vfc_typenum,
65 				    vfc.vfc_refcount,
66 				    fmt_flags(vfc.vfc_flags));
67 			} else {
68 				warnx("VFS %s unknown or not loaded", *argv);
69 				rv = 1;
70 			}
71 		}
72 	}
73 
74 	endvfsent();
75 	return rv;
76 }
77 
78 static const char *
79 fmt_flags(int flags)
80 {
81 	static char buf[sizeof(struct flaglist) * sizeof(fl)];
82 	int i;
83 
84 	buf[0] = '\0';
85 	for (i = 0; i < (int)nitems(fl); i++)
86 		if (flags & fl[i].flag) {
87 			strlcat(buf, fl[i].str, sizeof(buf));
88 			strlcat(buf, ", ", sizeof(buf));
89 		}
90 	if (buf[0] != '\0')
91 		buf[strlen(buf) - 2] = '\0';
92 	return (buf);
93 }
94