lsvfs.c revision 27624
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.8 1997/03/03 17:21:57 bde 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 %5d %5d %s\n"
17#define HDRFMT "%-32.32s %5.5s %5.5s %s\n"
18#define DASHES "-------------------------------- ----- ----- ---------------\n"
19
20static const char *fmt_flags(int);
21
22int
23main(int argc, char **argv)
24{
25  int rv = 0;
26  struct vfsconf *vfc;
27  argc--, argv++;
28
29  setvfsent(1);
30
31  printf(HDRFMT, "Filesystem", "Index", "Refs", "Flags");
32  fputs(DASHES, stdout);
33
34  if(argc) {
35    for(; argc; argc--, argv++) {
36      vfc = getvfsbyname(*argv);
37      if(vfc) {
38        printf(FMT, vfc->vfc_name, vfc->vfc_index, vfc->vfc_refcount,
39               fmt_flags(vfc->vfc_flags));
40      } else {
41	warnx("VFS %s unknown or not loaded", *argv);
42        rv++;
43      }
44    }
45  } else {
46    while(vfc = getvfsent()) {
47      printf(FMT, vfc->vfc_name, vfc->vfc_index, vfc->vfc_refcount,
48             fmt_flags(vfc->vfc_flags));
49    }
50  }
51
52  endvfsent();
53  return rv;
54}
55
56static const char *
57fmt_flags(int flags)
58{
59  /*
60   * NB: if you add new flags, don't forget to add them here vvvvvv too.
61   */
62  static char buf[sizeof
63    "static, network, read-only, synthetic, loopback, unicode"];
64  int comma = 0;
65
66  buf[0] = '\0';
67
68  if(flags & VFCF_STATIC) {
69    if(comma++) strcat(buf, ", ");
70    strcat(buf, "static");
71  }
72
73  if(flags & VFCF_NETWORK) {
74    if(comma++) strcat(buf, ", ");
75    strcat(buf, "network");
76  }
77
78  if(flags & VFCF_READONLY) {
79    if(comma++) strcat(buf, ", ");
80    strcat(buf, "read-only");
81  }
82
83  if(flags & VFCF_SYNTHETIC) {
84    if(comma++) strcat(buf, ", ");
85    strcat(buf, "synthetic");
86  }
87
88  if(flags & VFCF_LOOPBACK) {
89    if(comma++) strcat(buf, ", ");
90    strcat(buf, "loopback");
91  }
92
93  if(flags & VFCF_UNICODE) {
94    if(comma++) strcat(buf, ", ");
95    strcat(buf, "unicode");
96  }
97
98  return buf;
99}
100