lsvfs.c revision 101651
12965Swollman/*
227624Scharnier * lsvfs - list loaded VFSes
32965Swollman * Garrett A. Wollman, September 1994
42965Swollman * This file is in the public domain.
57094Swollman *
62965Swollman */
72965Swollman
899112Sobrien#include <sys/cdefs.h>
999112Sobrien__FBSDID("$FreeBSD: head/usr.bin/lsvfs/lsvfs.c 101651 2002-08-10 20:19:04Z mux $");
1099112Sobrien
112965Swollman#include <sys/param.h>
122965Swollman#include <sys/mount.h>
1323350Sbde
1423350Sbde#include <err.h>
152965Swollman#include <stdio.h>
16101651Smux#include <stdlib.h>
1723350Sbde#include <string.h>
182965Swollman
1938619Sbde#define FMT "%-32.32s %5d %s\n"
2038619Sbde#define HDRFMT "%-32.32s %5.5s %s\n"
2138619Sbde#define DASHES "-------------------------------- ----- ---------------\n"
222965Swollman
237094Swollmanstatic const char *fmt_flags(int);
247094Swollman
252965Swollmanint
262965Swollmanmain(int argc, char **argv)
272965Swollman{
28101651Smux  int cnt, rv = 0, i;
29101651Smux  struct xvfsconf vfc, *xvfsp;
30101651Smux  size_t buflen;
312965Swollman  argc--, argv++;
322965Swollman
3338619Sbde  printf(HDRFMT, "Filesystem", "Refs", "Flags");
342965Swollman  fputs(DASHES, stdout);
352965Swollman
362965Swollman  if(argc) {
372965Swollman    for(; argc; argc--, argv++) {
3847701Sru      if (getvfsbyname(*argv, &vfc) == 0) {
3938619Sbde        printf(FMT, vfc.vfc_name, vfc.vfc_refcount, fmt_flags(vfc.vfc_flags));
402965Swollman      } else {
412984Swollman	warnx("VFS %s unknown or not loaded", *argv);
422965Swollman        rv++;
432965Swollman      }
442965Swollman    }
452965Swollman  } else {
46101651Smux    if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0)
47101651Smux      err(1, "sysctl(vfs.conflist)");
48101651Smux    xvfsp = malloc(buflen);
49101651Smux    if (xvfsp == NULL)
50101651Smux      errx(1, "malloc failed");
51101651Smux    if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0)
52101651Smux      err(1, "sysctl(vfs.conflist)");
53101651Smux    cnt = buflen / sizeof(struct xvfsconf);
54101651Smux
55101651Smux    for (i = 0; i < cnt; i++) {
56101651Smux      printf(FMT, xvfsp[i].vfc_name, xvfsp[i].vfc_refcount,
57101651Smux             fmt_flags(xvfsp[i].vfc_flags));
582965Swollman    }
59101651Smux    free(xvfsp);
602965Swollman  }
612965Swollman
622965Swollman  return rv;
632965Swollman}
642965Swollman
657094Swollmanstatic const char *
667094Swollmanfmt_flags(int flags)
677094Swollman{
687096Swollman  /*
697096Swollman   * NB: if you add new flags, don't forget to add them here vvvvvv too.
707096Swollman   */
7123350Sbde  static char buf[sizeof
7223350Sbde    "static, network, read-only, synthetic, loopback, unicode"];
737096Swollman  int comma = 0;
747096Swollman
757096Swollman  buf[0] = '\0';
767096Swollman
777096Swollman  if(flags & VFCF_STATIC) {
787096Swollman    if(comma++) strcat(buf, ", ");
797096Swollman    strcat(buf, "static");
807096Swollman  }
817096Swollman
827096Swollman  if(flags & VFCF_NETWORK) {
837096Swollman    if(comma++) strcat(buf, ", ");
847096Swollman    strcat(buf, "network");
857096Swollman  }
867096Swollman
877096Swollman  if(flags & VFCF_READONLY) {
887096Swollman    if(comma++) strcat(buf, ", ");
897096Swollman    strcat(buf, "read-only");
907096Swollman  }
917096Swollman
927096Swollman  if(flags & VFCF_SYNTHETIC) {
937096Swollman    if(comma++) strcat(buf, ", ");
947096Swollman    strcat(buf, "synthetic");
957096Swollman  }
967096Swollman
977096Swollman  if(flags & VFCF_LOOPBACK) {
987096Swollman    if(comma++) strcat(buf, ", ");
997096Swollman    strcat(buf, "loopback");
1007096Swollman  }
1017096Swollman
10223350Sbde  if(flags & VFCF_UNICODE) {
10323350Sbde    if(comma++) strcat(buf, ", ");
10423350Sbde    strcat(buf, "unicode");
10523350Sbde  }
10623350Sbde
1077096Swollman  return buf;
1087094Swollman}
109