]> git.cameronkatri.com Git - apple_cmds.git/blob - adv_cmds/lsvfs/lsvfs.c
system_cmds: Fix wait4path BINDIR
[apple_cmds.git] / adv_cmds / lsvfs / lsvfs.c
1 /*
2 * Copyright (c) 1998-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #include <sys/mount.h>
24 #include <sys/types.h>
25 #include <sys/sysctl.h>
26
27 #include <err.h>
28 #include <errno.h>
29 #include <stdio.h>
30 #include <string.h>
31
32 #define FMT "%-32.32s %5d %s\n"
33 #define HDRFMT "%-32.32s %5.5s %s\n"
34 #define DASHES "-------------------------------- ----- ---------------\n"
35
36 static const char *fmt_flags(int flags);
37
38 int
39 main(int argc, char *argv[])
40 {
41 struct vfsconf vfc;
42 int mib[4], max, x;
43 size_t len;
44
45 printf(HDRFMT, "Filesystem", "Refs", "Flags");
46 fputs(DASHES, stdout);
47
48 if (argc > 1) {
49 for (x = 1; x < argc; x++)
50 if (getvfsbyname(argv[x], &vfc) == 0)
51 printf(FMT, vfc.vfc_name, vfc.vfc_refcount,
52 fmt_flags(vfc.vfc_flags));
53 else
54 warnx("VFS %s unknown or not loaded", argv[x]);
55 } else {
56 mib[0] = CTL_VFS;
57 mib[1] = VFS_GENERIC;
58 mib[2] = VFS_MAXTYPENUM;
59 len = sizeof(int);
60 if (sysctl(mib, 3, &max, &len, NULL, 0) != 0)
61 errx(1, "sysctl");
62 mib[2] = VFS_CONF;
63
64 len = sizeof(vfc);
65 for (x = 0; x < max; x++) {
66 mib[3] = x;
67 if (sysctl(mib, 4, &vfc, &len, NULL, 0) != 0) {
68 if (errno != ENOTSUP)
69 errx(1, "sysctl");
70 } else {
71 printf(FMT, vfc.vfc_name, vfc.vfc_refcount,
72 fmt_flags(vfc.vfc_flags));
73 }
74 }
75 }
76
77 return 0;
78 }
79
80 static const char *
81 fmt_flags(int flags)
82 {
83 static char buf[sizeof "local, dovolfs"];
84 int comma = 0;
85
86 buf[0] = '\0';
87
88 if(flags & MNT_LOCAL) {
89 if(comma++) strcat(buf, ", ");
90 strcat(buf, "local");
91 }
92
93 if(flags & MNT_DOVOLFS) {
94 if(comma++) strcat(buf, ", ");
95 strcat(buf, "dovolfs");
96 }
97
98 return buf;
99 }