lsvfs.c revision 47701
1/*
2 * lsvfs - list loaded VFSes
3 * Garrett A. Wollman, September 1994
4 * This file is in the public domain.
5 *
6 * $Id: lsvfs.c,v 1.11 1998/08/29 13:53:22 bde 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 %5d %s\n"
19#define HDRFMT "%-32.32s %5.5s %s\n"
20#define DASHES "-------------------------------- ----- ---------------\n"
21
22static const char *fmt_flags(int);
23
24int
25main(int argc, char **argv)
26{
27  int rv = 0;
28  struct vfsconf vfc;
29  struct ovfsconf *ovfcp;
30  argc--, argv++;
31
32  setvfsent(1);
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    while (ovfcp = getvfsent()) {
48      printf(FMT, ovfcp->vfc_name, ovfcp->vfc_refcount,
49             fmt_flags(ovfcp->vfc_flags));
50    }
51  }
52
53  endvfsent();
54  return rv;
55}
56
57static const char *
58fmt_flags(int flags)
59{
60  /*
61   * NB: if you add new flags, don't forget to add them here vvvvvv too.
62   */
63  static char buf[sizeof
64    "static, network, read-only, synthetic, loopback, unicode"];
65  int comma = 0;
66
67  buf[0] = '\0';
68
69  if(flags & VFCF_STATIC) {
70    if(comma++) strcat(buf, ", ");
71    strcat(buf, "static");
72  }
73
74  if(flags & VFCF_NETWORK) {
75    if(comma++) strcat(buf, ", ");
76    strcat(buf, "network");
77  }
78
79  if(flags & VFCF_READONLY) {
80    if(comma++) strcat(buf, ", ");
81    strcat(buf, "read-only");
82  }
83
84  if(flags & VFCF_SYNTHETIC) {
85    if(comma++) strcat(buf, ", ");
86    strcat(buf, "synthetic");
87  }
88
89  if(flags & VFCF_LOOPBACK) {
90    if(comma++) strcat(buf, ", ");
91    strcat(buf, "loopback");
92  }
93
94  if(flags & VFCF_UNICODE) {
95    if(comma++) strcat(buf, ", ");
96    strcat(buf, "unicode");
97  }
98
99  return buf;
100}
101