lsvfs.c revision 7096
12965Swollman/*
22965Swollman * lsvfs - lsit loaded VFSes
32965Swollman * Garrett A. Wollman, September 1994
42965Swollman * This file is in the public domain.
57094Swollman *
67096Swollman * $Id: lsvfs.c,v 1.3 1995/03/16 18:37:47 wollman Exp $
72965Swollman */
82965Swollman
92965Swollman#include <sys/types.h>
102965Swollman#include <sys/param.h>
112965Swollman#include <sys/mount.h>
122965Swollman#include <stdio.h>
132965Swollman#include <err.h>
142965Swollman
157094Swollman#define FMT "%-32.32s %5d %5d %s\n"
167094Swollman#define HDRFMT "%-32.32s %5.5s %5.5s %s\n"
177094Swollman#define DASHES "-------------------------------- ----- ----- ---------------\n"
182965Swollman
197094Swollmanstatic const char *fmt_flags(int);
207094Swollman
212965Swollmanint
222965Swollmanmain(int argc, char **argv)
232965Swollman{
242965Swollman  int rv = 0;
252965Swollman  struct vfsconf *vfc;
262965Swollman  argc--, argv++;
272965Swollman
282965Swollman  setvfsent(1);
292965Swollman
302965Swollman  printf(HDRFMT, "Filesystem", "Index", "Refs", "Flags");
312965Swollman  fputs(DASHES, stdout);
322965Swollman
332965Swollman  if(argc) {
342965Swollman    for(; argc; argc--, argv++) {
352965Swollman      vfc = getvfsbyname(*argv);
362965Swollman      if(vfc) {
372965Swollman        printf(FMT, vfc->vfc_name, vfc->vfc_index, vfc->vfc_refcount,
387094Swollman               fmt_flags(vfc->vfc_flags));
392965Swollman      } else {
402984Swollman	warnx("VFS %s unknown or not loaded", *argv);
412965Swollman        rv++;
422965Swollman      }
432965Swollman    }
442965Swollman  } else {
452965Swollman    while(vfc = getvfsent()) {
462965Swollman      printf(FMT, vfc->vfc_name, vfc->vfc_index, vfc->vfc_refcount,
472965Swollman             vfc->vfc_flags);
482965Swollman    }
492965Swollman  }
502965Swollman
512965Swollman  endvfsent();
522965Swollman  return rv;
532965Swollman}
542965Swollman
557094Swollmanstatic const char *
567094Swollmanfmt_flags(int flags)
577094Swollman{
587096Swollman  /*
597096Swollman   * NB: if you add new flags, don't forget to add them here vvvvvv too.
607096Swollman   */
617096Swollman  static char buf[sizeof "static, network, read-only, synthetic, loopback"];
627096Swollman  int comma = 0;
637096Swollman
647096Swollman  buf[0] = '\0';
657096Swollman
667096Swollman  if(flags & VFCF_STATIC) {
677096Swollman    if(comma++) strcat(buf, ", ");
687096Swollman    strcat(buf, "static");
697096Swollman  }
707096Swollman
717096Swollman  if(flags & VFCF_NETWORK) {
727096Swollman    if(comma++) strcat(buf, ", ");
737096Swollman    strcat(buf, "network");
747096Swollman  }
757096Swollman
767096Swollman  if(flags & VFCF_READONLY) {
777096Swollman    if(comma++) strcat(buf, ", ");
787096Swollman    strcat(buf, "read-only");
797096Swollman  }
807096Swollman
817096Swollman  if(flags & VFCF_SYNTHETIC) {
827096Swollman    if(comma++) strcat(buf, ", ");
837096Swollman    strcat(buf, "synthetic");
847096Swollman  }
857096Swollman
867096Swollman  if(flags & VFCF_LOOPBACK) {
877096Swollman    if(comma++) strcat(buf, ", ");
887096Swollman    strcat(buf, "loopback");
897096Swollman  }
907096Swollman
917096Swollman  return buf;
927094Swollman}
937094Swollman
94