1
2
3
4
5 package oshi.driver.unix.solaris.disk;
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10 import oshi.annotation.concurrent.ThreadSafe;
11 import oshi.hardware.HWPartition;
12 import oshi.util.Constants;
13 import oshi.util.ExecutingCommand;
14 import oshi.util.ParseUtil;
15
16
17
18
19 @ThreadSafe
20 public final class Prtvtoc {
21
22 private static final String PRTVTOC_DEV_DSK = "prtvtoc /dev/dsk/";
23
24 private Prtvtoc() {
25 }
26
27 public static List<HWPartition> queryPartitions(String mount, int major) {
28 List<HWPartition> partList = new ArrayList<>();
29
30
31 List<String> prtvotc = ExecutingCommand.runNative(PRTVTOC_DEV_DSK + mount);
32
33 if (prtvotc.size() > 1) {
34 int bytesPerSector = 0;
35 String[] split;
36
37 for (String line : prtvotc) {
38
39
40 if (line.startsWith("*")) {
41 if (line.endsWith("bytes/sector")) {
42 split = ParseUtil.whitespaces.split(line);
43 if (split.length > 0) {
44 bytesPerSector = ParseUtil.parseIntOrDefault(split[1], 0);
45 }
46 }
47 } else if (bytesPerSector > 0) {
48
49
50
51
52
53 split = ParseUtil.whitespaces.split(line.trim());
54
55 if (split.length >= 6 && !"2".equals(split[0])) {
56
57 String identification = mount + "s" + split[0];
58
59 int minor = ParseUtil.parseIntOrDefault(split[0], 0);
60
61 String name;
62 switch (ParseUtil.parseIntOrDefault(split[1], 0)) {
63 case 0x01:
64 case 0x18:
65 name = "boot";
66 break;
67 case 0x02:
68 name = "root";
69 break;
70 case 0x03:
71 name = "swap";
72 break;
73 case 0x04:
74 name = "usr";
75 break;
76 case 0x05:
77 name = "backup";
78 break;
79 case 0x06:
80 name = "stand";
81 break;
82 case 0x07:
83 name = "var";
84 break;
85 case 0x08:
86 name = "home";
87 break;
88 case 0x09:
89 name = "altsctr";
90 break;
91 case 0x0a:
92 name = "cache";
93 break;
94 case 0x0b:
95 name = "reserved";
96 break;
97 case 0x0c:
98 name = "system";
99 break;
100 case 0x0e:
101 name = "public region";
102 break;
103 case 0x0f:
104 name = "private region";
105 break;
106 default:
107 name = Constants.UNKNOWN;
108 break;
109 }
110
111 String type;
112
113 switch (split[2]) {
114 case "00":
115 type = "wm";
116 break;
117 case "10":
118 type = "rm";
119 break;
120 case "01":
121 type = "wu";
122 break;
123 default:
124 type = "ru";
125 break;
126 }
127
128 long partSize = bytesPerSector * ParseUtil.parseLongOrDefault(split[4], 0L);
129
130 String mountPoint = "";
131 if (split.length > 6) {
132 mountPoint = split[6];
133 }
134 partList.add(
135 new HWPartition(identification, name, type, "", partSize, major, minor, mountPoint));
136 }
137 }
138 }
139 }
140 return partList;
141 }
142 }