xref: /dragonfly/usr.bin/lsvfs/lsvfs.c (revision be908d4e)
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 #include <sys/param.h>
10 #include <sys/mount.h>
11 
12 #include <err.h>
13 #include <stdio.h>
14 #include <string.h>
15 
16 #define	FMT	"%-32.32s 0x%08x %5d  %s\n"
17 #define	HDRFMT	"%-32.32s %10s %5.5s  %s\n"
18 #define	DASHES	"-------------------------------- "	\
19 		"---------- -----  ---------------\n"
20 
21 static struct flaglist {
22 	int		flag;
23 	const char	str[32]; /* must be longer than the longest one. */
24 } fl[] = {
25 	{ .flag = VFCF_STATIC, .str = "static", },
26 	{ .flag = VFCF_NETWORK, .str = "network", },
27 	{ .flag = VFCF_READONLY, .str = "read-only", },
28 	{ .flag = VFCF_SYNTHETIC, .str = "synthetic", },
29 	{ .flag = VFCF_LOOPBACK, .str = "loopback", },
30 	{ .flag = VFCF_UNICODE, .str = "unicode", },
31 };
32 
33 static const char *fmt_flags(int);
34 
35 int
main(int argc,char ** argv)36 main(int argc, char **argv)
37 {
38 	int rv = 0;
39 	struct vfsconf vfc;
40 	struct ovfsconf *ovfcp;
41 	argc--, argv++;
42 
43 	setvfsent(1);
44 
45 	printf(HDRFMT, "Filesystem", "Num", "Refs", "Flags");
46 	fputs(DASHES, stdout);
47 
48 	if (argc) {
49 		for(; argc; argc--, argv++) {
50 			if (getvfsbyname(*argv, &vfc) == 0) {
51 				printf(FMT, vfc.vfc_name, vfc.vfc_typenum,
52 				    vfc.vfc_refcount,
53 				    fmt_flags(vfc.vfc_flags));
54 			} else {
55 				warnx("VFS %s unknown or not loaded", *argv);
56 				rv = 1;
57 			}
58 		}
59 	} else {
60 		while ((ovfcp = getvfsent()) != NULL) {
61 			if (getvfsbyname(ovfcp->vfc_name, &vfc) == 0) {
62 				printf(FMT, vfc.vfc_name, vfc.vfc_typenum,
63 				    vfc.vfc_refcount,
64 				    fmt_flags(vfc.vfc_flags));
65 			} else {
66 				warnx("VFS %s unknown or not loaded", *argv);
67 				rv = 1;
68 			}
69 		}
70 	}
71 
72 	endvfsent();
73 	return rv;
74 }
75 
76 static const char *
fmt_flags(int flags)77 fmt_flags(int flags)
78 {
79 	static char buf[sizeof(struct flaglist) * sizeof(fl)];
80 	size_t i;
81 
82 	buf[0] = '\0';
83 	for (i = 0; i < nitems(fl); i++)
84 		if (flags & fl[i].flag) {
85 			strlcat(buf, fl[i].str, sizeof(buf));
86 			strlcat(buf, ", ", sizeof(buf));
87 		}
88 	if (buf[0] != '\0')
89 		buf[strlen(buf) - 2] = '\0';
90 	return (buf);
91 }
92