lsvfs.c (1ba4a712dde6e6c613fc411a96958b4ade67de4c) | lsvfs.c (2a136300aceca6ec66907258618cf7fdae2a1025) |
---|---|
1/* | 1/* |
2 * lsvfs - list loaded VFSes | 2 * lsvfs - lsit loaded VFSes |
3 * Garrett A. Wollman, September 1994 4 * This file is in the public domain. | 3 * Garrett A. Wollman, September 1994 4 * This file is in the public domain. |
5 * | |
6 */ 7 | 5 */ 6 |
8#include <sys/cdefs.h> 9__FBSDID("$FreeBSD$"); 10 | 7#include <sys/types.h> |
11#include <sys/param.h> 12#include <sys/mount.h> | 8#include <sys/param.h> 9#include <sys/mount.h> |
13#include <sys/sysctl.h> 14 15#include <err.h> | |
16#include <stdio.h> | 10#include <stdio.h> |
17#include <stdlib.h> 18#include <string.h> | 11#include <err.h> |
19 | 12 |
20#define FMT "%-32.32s %5d %s\n" 21#define HDRFMT "%-32.32s %5.5s %s\n" 22#define DASHES "-------------------------------- ----- ---------------\n" | 13#define FMT "%-32.32s %5d %5d %5d\n" 14#define HDRFMT "%-32.32s %5.5s %5.5s %5.5s\n" 15#define DASHES "-------------------------------- ---- ---- ----\n" |
23 | 16 |
24static const char *fmt_flags(int); 25 | |
26int 27main(int argc, char **argv) 28{ | 17int 18main(int argc, char **argv) 19{ |
29 int cnt, rv = 0, i; 30 struct xvfsconf vfc, *xvfsp; 31 size_t buflen; | 20 int rv = 0; 21 struct vfsconf *vfc; |
32 argc--, argv++; 33 | 22 argc--, argv++; 23 |
34 printf(HDRFMT, "Filesystem", "Refs", "Flags"); | 24 setvfsent(1); 25 26 printf(HDRFMT, "Filesystem", "Index", "Refs", "Flags"); |
35 fputs(DASHES, stdout); 36 37 if(argc) { 38 for(; argc; argc--, argv++) { | 27 fputs(DASHES, stdout); 28 29 if(argc) { 30 for(; argc; argc--, argv++) { |
39 if (getvfsbyname(*argv, &vfc) == 0) { 40 printf(FMT, vfc.vfc_name, vfc.vfc_refcount, fmt_flags(vfc.vfc_flags)); | 31 vfc = getvfsbyname(*argv); 32 if(vfc) { 33 printf(FMT, vfc->vfc_name, vfc->vfc_index, vfc->vfc_refcount, 34 vfc->vfc_flags); |
41 } else { | 35 } else { |
42 warnx("VFS %s unknown or not loaded", *argv); | 36 warnx("VFS %s unknown or not loaded", name); |
43 rv++; 44 } 45 } 46 } else { | 37 rv++; 38 } 39 } 40 } 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)); | 41 while(vfc = getvfsent()) { 42 printf(FMT, vfc->vfc_name, vfc->vfc_index, vfc->vfc_refcount, 43 vfc->vfc_flags); |
59 } | 44 } |
60 free(xvfsp); | |
61 } 62 | 45 } 46 |
47 endvfsent(); |
|
63 return rv; 64} 65 | 48 return rv; 49} 50 |
66static const char * 67fmt_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 size_t len; 75 76 buf[0] = '\0'; 77 78 if(flags & VFCF_STATIC) 79 strlcat(buf, "static, ", sizeof(buf)); 80 if(flags & VFCF_NETWORK) 81 strlcat(buf, "network, ", sizeof(buf)); 82 if(flags & VFCF_READONLY) 83 strlcat(buf, "read-only, ", sizeof(buf)); 84 if(flags & VFCF_SYNTHETIC) 85 strlcat(buf, "synthetic, ", sizeof(buf)); 86 if(flags & VFCF_LOOPBACK) 87 strlcat(buf, "loopback, ", sizeof(buf)); 88 if(flags & VFCF_UNICODE) 89 strlcat(buf, "unicode, ", sizeof(buf)); 90 if(flags & VFCF_JAIL) 91 strlcat(buf, "jail, ", sizeof(buf)); 92 if(flags & VFCF_DELEGADMIN) 93 strlcat(buf, "delegated-administration, ", sizeof(buf)); 94 len = strlen(buf); 95 if (len > 2 && buf[len - 2] == ',') 96 buf[len - 2] = '\0'; 97 98 return buf; 99} | |