1 #include <stdio.h>
2 #include <errno.h>
3 #include <sys/param.h>
4 #include <sys/ucred.h>
5 #include <sys/mount.h>
6
7 char *find_type(int t);
8 char *expand_flags(int f);
9
main(void)10 int main(void)
11 {
12 struct statfs *mntlist;
13 int n, i;
14
15 n = getmntinfo(&mntlist, MNT_NOWAIT);
16 if (n < 0) {
17 fprintf(stderr, "getmntinfo failed : %s\n", strerror(errno));
18 exit(1);
19 }
20 for(i=0; i<n; i++) {
21 printf("%s\t%s\t%s\t%s\t%x\n",
22 mntlist[i].f_mntonname,
23 mntlist[i].f_mntfromname,
24 mntlist[i].f_fstypename,
25 expand_flags(mntlist[i].f_flags),
26 mntlist[i].f_flags);
27 }
28 return 0;
29 }
30
expand_flags(int f)31 char *expand_flags(int f)
32 {
33 static char buf[1024];
34 buf[0] = 0;
35 if (f & MNT_RDONLY) strcat(buf, "ro,");
36 if (f & MNT_NOEXEC) strcat(buf, "noexec,");
37 if (f & MNT_NOSUID) strcat(buf, "nosuid,");
38 if (f & MNT_NOATIME) strcat(buf, "noatime,");
39 if (f & MNT_NODEV) strcat(buf, "nodev,");
40 if (f & MNT_SYNCHRONOUS) strcat(buf, "sync,");
41 if (f & MNT_ASYNC) strcat(buf, "async,");
42 if (f & MNT_QUOTA) strcat(buf, "quota,");
43 if (f & MNT_NOSYMFOLLOW) strcat(buf, "nosymfollow,");
44 if (f & MNT_SUIDDIR) strcat(buf, "suiddir,");
45 if (f & MNT_UNION) strcat(buf, "union,");
46 if (f & MNT_NOCLUSTERR) strcat(buf, "noclusterr,");
47 if (f & MNT_NOCLUSTERW) strcat(buf, "noclusterw,");
48 if (buf[0] == 0) return "-";
49 buf[strlen(buf)-1] = 0;
50 return buf;
51 }
52
53