Handle hostnames with upper-case letters
[webmin.git] / mount / freebsd-mounts-2.c
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
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                 find_type(mntlist[i].f_type),
25                 expand_flags(mntlist[i].f_flags),
26                 mntlist[i].f_flags);
27         }
28 return 0;
29 }
30
31 char *type_name[] = { "none", "ufs", "nfs", "mfs", "msdos", "lfs",
32                       "lofs", "fdesc", "portal", "null", "umap", "kernfs",
33                       "procfs", "afs", "cd9660", "union", "devfs", "ext2fs",
34                       "tfs" };
35
36 char *find_type(int t)
37 {
38 if (t < 0 || t > 18) return "???";
39 else return type_name[t];
40 }
41
42 char *expand_flags(int f)
43 {
44 static char buf[1024];
45 buf[0] = 0;
46 if (f & MNT_RDONLY) strcat(buf, "ro,");
47 if (f & MNT_NOEXEC) strcat(buf, "noexec,");
48 if (f & MNT_NOSUID) strcat(buf, "nosuid,");
49 if (f & MNT_NOATIME) strcat(buf, "noatime,");
50 if (f & MNT_NODEV) strcat(buf, "nodev,");
51 if (f & MNT_SYNCHRONOUS) strcat(buf, "sync,");
52 if (f & MNT_ASYNC) strcat(buf, "async,");
53 if (f & MNT_QUOTA) strcat(buf, "quota,");
54 if (buf[0] == 0) return "-";
55 buf[strlen(buf)-1] = 0;
56 return buf;
57 }
58