1
2
3
4
5 package oshi.driver.mac.disk;
6
7 import java.nio.charset.StandardCharsets;
8 import java.util.HashMap;
9 import java.util.Map;
10
11 import com.sun.jna.Native;
12 import com.sun.jna.platform.mac.SystemB;
13 import com.sun.jna.platform.mac.SystemB.Statfs;
14
15 import oshi.annotation.concurrent.ThreadSafe;
16
17
18
19
20 @ThreadSafe
21 public final class Fsstat {
22
23 private Fsstat() {
24 }
25
26
27
28
29
30
31 public static Map<String, String> queryPartitionToMountMap() {
32 Map<String, String> mountPointMap = new HashMap<>();
33
34
35 int numfs = queryFsstat(null, 0, 0);
36
37 Statfs s = new Statfs();
38
39 Statfs[] fs = (Statfs[]) s.toArray(numfs);
40
41 queryFsstat(fs, numfs * fs[0].size(), SystemB.MNT_NOWAIT);
42
43
44 for (Statfs f : fs) {
45 String mntFrom = Native.toString(f.f_mntfromname, StandardCharsets.UTF_8);
46 mountPointMap.put(mntFrom.replace("/dev/", ""), Native.toString(f.f_mntonname, StandardCharsets.UTF_8));
47 }
48 return mountPointMap;
49 }
50
51 private static int queryFsstat(Statfs[] buf, int bufsize, int flags) {
52 return SystemB.INSTANCE.getfsstat64(buf, bufsize, flags);
53 }
54
55 }