1
2
3
4
5 package oshi.driver.unix.freebsd.disk;
6
7 import java.util.HashMap;
8 import java.util.List;
9 import java.util.Map;
10
11 import oshi.annotation.concurrent.ThreadSafe;
12 import oshi.util.Constants;
13 import oshi.util.ExecutingCommand;
14 import oshi.util.ParseUtil;
15 import oshi.util.tuples.Triplet;
16
17
18
19
20 @ThreadSafe
21 public final class GeomDiskList {
22
23 private static final String GEOM_DISK_LIST = "geom disk list";
24
25 private GeomDiskList() {
26 }
27
28
29
30
31
32
33 public static Map<String, Triplet<String, String, Long>> queryDisks() {
34
35 Map<String, Triplet<String, String, Long>> diskMap = new HashMap<>();
36
37 String diskName = null;
38 String descr = Constants.UNKNOWN;
39 String ident = Constants.UNKNOWN;
40 long mediaSize = 0L;
41
42 List<String> geom = ExecutingCommand.runNative(GEOM_DISK_LIST);
43 for (String line : geom) {
44 line = line.trim();
45
46 if (line.startsWith("Geom name:")) {
47
48 if (diskName != null) {
49 diskMap.put(diskName, new Triplet<>(descr, ident, mediaSize));
50 descr = Constants.UNKNOWN;
51 ident = Constants.UNKNOWN;
52 mediaSize = 0L;
53 }
54
55 diskName = line.substring(line.lastIndexOf(' ') + 1);
56 }
57
58 if (diskName != null) {
59 line = line.trim();
60 if (line.startsWith("Mediasize:")) {
61 String[] split = ParseUtil.whitespaces.split(line);
62 if (split.length > 1) {
63 mediaSize = ParseUtil.parseLongOrDefault(split[1], 0L);
64 }
65 }
66 if (line.startsWith("descr:")) {
67 descr = line.replace("descr:", "").trim();
68 }
69 if (line.startsWith("ident:")) {
70 ident = line.replace("ident:", "").replace("(null)", "").trim();
71 }
72 }
73 }
74 if (diskName != null) {
75 diskMap.put(diskName, new Triplet<>(descr, ident, mediaSize));
76 }
77 return diskMap;
78 }
79 }