-
Notifications
You must be signed in to change notification settings - Fork 1
/
listVolumes.m
85 lines (63 loc) · 2.52 KB
/
listVolumes.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/ucred.h>
#include <stdio.h>
/**
\brief determine if the volume mounted at `mountPointPath` is browsable
\returns 0 for no, 1 for yes, or -1 for an error.
**/
int isVolumeBrowseable(const char* mountPointPath)
{
int result = 0;
struct statfs stat;
int error = statfs(mountPointPath, &stat);
if (error == 0) {
result = (stat.f_flags & MNT_DONTBROWSE) == 0;
} else {
result = -1;
}
return result;
}
char* mountFlagsString(uint32_t flags)
{
char* output = NULL;
asprintf(&output, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
flags & MNT_RDONLY ? "MNT_RDONLY " : "",
flags & MNT_SYNCHRONOUS ? "MNT_SYNCHRONOUS " : "",
flags & MNT_NOEXEC ? "MNT_NOEXEC " : "",
flags & MNT_NOSUID ? "MNT_NOSUID " : "",
flags & MNT_NODEV ? "MNT_NODEV " : "",
flags & MNT_UNION ? "MNT_UNION " : "",
flags & MNT_ASYNC ? "MNT_ASYNC " : "",
flags & MNT_EXPORTED ? "MNT_EXPORTED " : "",
flags & MNT_QUARANTINE ? "MNT_QUARANTINE " : "",
flags & MNT_LOCAL ? "MNT_LOCAL " : "",
flags & MNT_QUOTA ? "MNT_QUOTA " : "",
flags & MNT_ROOTFS ? "MNT_ROOTFS " : "",
flags & MNT_DOVOLFS ? "MNT_DOVOLFS " : "",
flags & MNT_DONTBROWSE ? "MNT_DONTBROWSE " : "",
flags & MNT_IGNORE_OWNERSHIP ? "MNT_IGNORE_OWNERSHIP " : "",
flags & MNT_AUTOMOUNTED ? "MNT_AUTOMOUNTED " : "",
flags & MNT_JOURNALED ? "MNT_JOURNALED " : "",
flags & MNT_NOUSERXATTR ? "MNT_NOUSERXATTR " : "",
flags & MNT_DEFWRITE ? "MNT_DEFWRITE " : "",
flags & MNT_MULTILABEL ? "MNT_MULTILABEL " : "",
flags & MNT_NOATIME ? "MNT_NOATIME " : ""
);
return output;
}
int main (int argc, const char * argv[]) {
int numMounts = 0, i;
struct statfs * mountStats = NULL;
numMounts = getmntinfo(&mountStats, 0);
printf("There are %d file systems mounted:\n", numMounts);
for (i = 0; i < numMounts; ++i) {
char* flagsString = mountFlagsString(mountStats[i].f_flags);
printf("fs#%2d : %-40s %-40s %08x %d\n %s\n", i, mountStats[i].f_mntfromname, mountStats[i].f_mntonname, mountStats[i].f_flags,
isVolumeBrowseable(mountStats[i].f_mntonname),
flagsString);
free((void*)flagsString);
}
free((void*)mountStats);
return 0;
}