lsvfs.c revision 7096
1/*
2 * lsvfs - lsit loaded VFSes
3 * Garrett A. Wollman, September 1994
4 * This file is in the public domain.
5 *
6 * $Id: lsvfs.c,v 1.3 1995/03/16 18:37:47 wollman Exp $
7 */
8
9#include <sys/types.h>
10#include <sys/param.h>
11#include <sys/mount.h>
12#include <stdio.h>
13#include <err.h>
14
15#define FMT "%-32.32s %5d %5d %s\n"
16#define HDRFMT "%-32.32s %5.5s %5.5s %s\n"
17#define DASHES "-------------------------------- ----- ----- ---------------\n"
18
19static const char *fmt_flags(int);
20
21int
22main(int argc, char **argv)
23{
24  int rv = 0;
25  struct vfsconf *vfc;
26  argc--, argv++;
27
28  setvfsent(1);
29
30  printf(HDRFMT, "Filesystem", "Index", "Refs", "Flags");
31  fputs(DASHES, stdout);
32
33  if(argc) {
34    for(; argc; argc--, argv++) {
35      vfc = getvfsbyname(*argv);
36      if(vfc) {
37        printf(FMT, vfc->vfc_name, vfc->vfc_index, vfc->vfc_refcount,
38               fmt_flags(vfc->vfc_flags));
39      } else {
40	warnx("VFS %s unknown or not loaded", *argv);
41        rv++;
42      }
43    }
44  } else {
45    while(vfc = getvfsent()) {
46      printf(FMT, vfc->vfc_name, vfc->vfc_index, vfc->vfc_refcount,
47             vfc->vfc_flags);
48    }
49  }
50
51  endvfsent();
52  return rv;
53}
54
55static const char *
56fmt_flags(int flags)
57{
58  /*
59   * NB: if you add new flags, don't forget to add them here vvvvvv too.
60   */
61  static char buf[sizeof "static, network, read-only, synthetic, loopback"];
62  int comma = 0;
63
64  buf[0] = '\0';
65
66  if(flags & VFCF_STATIC) {
67    if(comma++) strcat(buf, ", ");
68    strcat(buf, "static");
69  }
70
71  if(flags & VFCF_NETWORK) {
72    if(comma++) strcat(buf, ", ");
73    strcat(buf, "network");
74  }
75
76  if(flags & VFCF_READONLY) {
77    if(comma++) strcat(buf, ", ");
78    strcat(buf, "read-only");
79  }
80
81  if(flags & VFCF_SYNTHETIC) {
82    if(comma++) strcat(buf, ", ");
83    strcat(buf, "synthetic");
84  }
85
86  if(flags & VFCF_LOOPBACK) {
87    if(comma++) strcat(buf, ", ");
88    strcat(buf, "loopback");
89  }
90
91  return buf;
92}
93
94