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