Skip to content

Commit 69264e0

Browse files
authored
Merge pull request #1086 from cgwalters/blockdev-pttype
blockdev: Extend lsblk output with parttype and partuuid
2 parents c8e1fb8 + 85f33a9 commit 69264e0

File tree

2 files changed

+333
-0
lines changed

2 files changed

+333
-0
lines changed

blockdev/src/blockdev.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub struct Device {
2525
pub serial: Option<String>,
2626
pub model: Option<String>,
2727
pub partlabel: Option<String>,
28+
pub parttype: Option<String>,
29+
pub partuuid: Option<String>,
2830
pub children: Option<Vec<Device>>,
2931
pub size: u64,
3032
#[serde(rename = "maj:min")]
@@ -330,6 +332,24 @@ mod test {
330332
}
331333
}
332334

335+
#[test]
336+
fn test_parse_lsblk() {
337+
let fixture = include_str!("../tests/fixtures/lsblk.json");
338+
let devs: DevicesOutput = serde_json::from_str(&fixture).unwrap();
339+
let dev = devs.blockdevices.into_iter().next().unwrap();
340+
let children = dev.children.as_deref().unwrap();
341+
assert_eq!(children.len(), 3);
342+
let first_child = &children[0];
343+
assert_eq!(
344+
first_child.parttype.as_deref().unwrap(),
345+
"21686148-6449-6e6f-744e-656564454649"
346+
);
347+
assert_eq!(
348+
first_child.partuuid.as_deref().unwrap(),
349+
"3979e399-262f-4666-aabc-7ab5d3add2f0"
350+
);
351+
}
352+
333353
#[test]
334354
fn test_parse_sfdisk() -> Result<()> {
335355
let fixture = indoc::indoc! { r#"

blockdev/tests/fixtures/lsblk.json

Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
{
2+
"blockdevices": [
3+
{
4+
"alignment": 0,
5+
"id-link": null,
6+
"id": null,
7+
"disc-aln": 0,
8+
"dax": false,
9+
"disc-gran": 512,
10+
"disk-seq": 1,
11+
"disc-max": 2147483136,
12+
"disc-zero": false,
13+
"fsavail": null,
14+
"fsroots": [
15+
null
16+
],
17+
"fssize": null,
18+
"fstype": null,
19+
"fsused": null,
20+
"fsuse%": null,
21+
"fsver": null,
22+
"group": "disk",
23+
"hctl": null,
24+
"hotplug": false,
25+
"kname": "vda",
26+
"label": null,
27+
"log-sec": 512,
28+
"maj:min": "252:0",
29+
"maj": "252",
30+
"min": "0",
31+
"min-io": 512,
32+
"mode": "brw-rw----",
33+
"model": null,
34+
"mq": " 2",
35+
"name": "vda",
36+
"opt-io": 0,
37+
"owner": "root",
38+
"partflags": null,
39+
"partlabel": null,
40+
"partn": null,
41+
"parttype": null,
42+
"parttypename": null,
43+
"partuuid": null,
44+
"path": "/dev/vda",
45+
"phy-sec": 512,
46+
"pkname": null,
47+
"pttype": "gpt",
48+
"ptuuid": "6596b2ac-09cd-41a0-8229-74bc5157d879",
49+
"ra": 128,
50+
"rand": false,
51+
"rev": null,
52+
"rm": false,
53+
"ro": false,
54+
"rota": true,
55+
"rq-size": 256,
56+
"sched": "none",
57+
"serial": null,
58+
"size": 10737418240,
59+
"start": null,
60+
"state": null,
61+
"subsystems": "block:virtio:pci",
62+
"mountpoint": null,
63+
"mountpoints": [
64+
null
65+
],
66+
"tran": "virtio",
67+
"type": "disk",
68+
"uuid": null,
69+
"vendor": "0x1af4",
70+
"wsame": 0,
71+
"wwn": null,
72+
"zoned": "none",
73+
"zone-sz": 0,
74+
"zone-wgran": 0,
75+
"zone-app": 0,
76+
"zone-nr": 0,
77+
"zone-omax": 0,
78+
"zone-amax": 0,
79+
"children": [
80+
{
81+
"alignment": 0,
82+
"id-link": null,
83+
"id": null,
84+
"disc-aln": 0,
85+
"dax": false,
86+
"disc-gran": 512,
87+
"disk-seq": 1,
88+
"disc-max": 2147483136,
89+
"disc-zero": false,
90+
"fsavail": null,
91+
"fsroots": [
92+
null
93+
],
94+
"fssize": null,
95+
"fstype": null,
96+
"fsused": null,
97+
"fsuse%": null,
98+
"fsver": null,
99+
"group": "disk",
100+
"hctl": null,
101+
"hotplug": false,
102+
"kname": "vda1",
103+
"label": null,
104+
"log-sec": 512,
105+
"maj:min": "252:1",
106+
"maj": "252",
107+
"min": "1",
108+
"min-io": 512,
109+
"mode": "brw-rw----",
110+
"model": null,
111+
"mq": " 2",
112+
"name": "vda1",
113+
"opt-io": 0,
114+
"owner": "root",
115+
"partflags": null,
116+
"partlabel": "BIOS-BOOT",
117+
"partn": 1,
118+
"parttype": "21686148-6449-6e6f-744e-656564454649",
119+
"parttypename": "BIOS boot",
120+
"partuuid": "3979e399-262f-4666-aabc-7ab5d3add2f0",
121+
"path": "/dev/vda1",
122+
"phy-sec": 512,
123+
"pkname": "vda",
124+
"pttype": "gpt",
125+
"ptuuid": "6596b2ac-09cd-41a0-8229-74bc5157d879",
126+
"ra": 128,
127+
"rand": false,
128+
"rev": null,
129+
"rm": false,
130+
"ro": false,
131+
"rota": true,
132+
"rq-size": 256,
133+
"sched": "none",
134+
"serial": null,
135+
"size": 1048576,
136+
"start": 2048,
137+
"state": null,
138+
"subsystems": "block:virtio:pci",
139+
"mountpoint": null,
140+
"mountpoints": [
141+
null
142+
],
143+
"tran": "virtio",
144+
"type": "part",
145+
"uuid": null,
146+
"vendor": null,
147+
"wsame": 0,
148+
"wwn": null,
149+
"zoned": "none",
150+
"zone-sz": 0,
151+
"zone-wgran": 0,
152+
"zone-app": 0,
153+
"zone-nr": 0,
154+
"zone-omax": 0,
155+
"zone-amax": 0
156+
},{
157+
"alignment": 0,
158+
"id-link": null,
159+
"id": null,
160+
"disc-aln": 0,
161+
"dax": false,
162+
"disc-gran": 512,
163+
"disk-seq": 1,
164+
"disc-max": 2147483136,
165+
"disc-zero": false,
166+
"fsavail": null,
167+
"fsroots": [
168+
null
169+
],
170+
"fssize": null,
171+
"fstype": "vfat",
172+
"fsused": null,
173+
"fsuse%": null,
174+
"fsver": "FAT32",
175+
"group": "disk",
176+
"hctl": null,
177+
"hotplug": false,
178+
"kname": "vda2",
179+
"label": "EFI-SYSTEM",
180+
"log-sec": 512,
181+
"maj:min": "252:2",
182+
"maj": "252",
183+
"min": "2",
184+
"min-io": 512,
185+
"mode": "brw-rw----",
186+
"model": null,
187+
"mq": " 2",
188+
"name": "vda2",
189+
"opt-io": 0,
190+
"owner": "root",
191+
"partflags": null,
192+
"partlabel": "EFI-SYSTEM",
193+
"partn": 2,
194+
"parttype": "c12a7328-f81f-11d2-ba4b-00a0c93ec93b",
195+
"parttypename": "EFI System",
196+
"partuuid": "392375a5-8cb5-4f15-885f-0d6b410dcd6c",
197+
"path": "/dev/vda2",
198+
"phy-sec": 512,
199+
"pkname": "vda",
200+
"pttype": "gpt",
201+
"ptuuid": "6596b2ac-09cd-41a0-8229-74bc5157d879",
202+
"ra": 128,
203+
"rand": false,
204+
"rev": null,
205+
"rm": false,
206+
"ro": false,
207+
"rota": true,
208+
"rq-size": 256,
209+
"sched": "none",
210+
"serial": null,
211+
"size": 536870912,
212+
"start": 4096,
213+
"state": null,
214+
"subsystems": "block:virtio:pci",
215+
"mountpoint": null,
216+
"mountpoints": [
217+
null
218+
],
219+
"tran": "virtio",
220+
"type": "part",
221+
"uuid": "FB0A-EA04",
222+
"vendor": null,
223+
"wsame": 0,
224+
"wwn": null,
225+
"zoned": "none",
226+
"zone-sz": 0,
227+
"zone-wgran": 0,
228+
"zone-app": 0,
229+
"zone-nr": 0,
230+
"zone-omax": 0,
231+
"zone-amax": 0
232+
},{
233+
"alignment": 0,
234+
"id-link": null,
235+
"id": null,
236+
"disc-aln": 0,
237+
"dax": false,
238+
"disc-gran": 512,
239+
"disk-seq": 1,
240+
"disc-max": 2147483136,
241+
"disc-zero": false,
242+
"fsavail": 5746880512,
243+
"fsroots": [
244+
"/ostree/deploy/default/var", "/ostree/deploy/default/var", "/ostree/deploy/default/deploy/41b7689b3d723570fcea1942007139dbbd7a4dfa7225b1747b47ddb67b37955a.0/etc", "/boot", "/"
245+
],
246+
"fssize": 9932427264,
247+
"fstype": "ext4",
248+
"fsused": 3658899456,
249+
"fsuse%": "37%",
250+
"fsver": "1.0",
251+
"group": "disk",
252+
"hctl": null,
253+
"hotplug": false,
254+
"kname": "vda3",
255+
"label": "root",
256+
"log-sec": 512,
257+
"maj:min": "252:3",
258+
"maj": "252",
259+
"min": "3",
260+
"min-io": 512,
261+
"mode": "brw-rw----",
262+
"model": null,
263+
"mq": " 2",
264+
"name": "vda3",
265+
"opt-io": 0,
266+
"owner": "root",
267+
"partflags": null,
268+
"partlabel": "root",
269+
"partn": 3,
270+
"parttype": "0fc63daf-8483-4772-8e79-3d69d8477de4",
271+
"parttypename": "Linux filesystem",
272+
"partuuid": "61709da2-1972-4f44-88fd-9d87bf9efe9c",
273+
"path": "/dev/vda3",
274+
"phy-sec": 512,
275+
"pkname": "vda",
276+
"pttype": "gpt",
277+
"ptuuid": "6596b2ac-09cd-41a0-8229-74bc5157d879",
278+
"ra": 128,
279+
"rand": false,
280+
"rev": null,
281+
"rm": false,
282+
"ro": false,
283+
"rota": true,
284+
"rq-size": 256,
285+
"sched": "none",
286+
"serial": null,
287+
"size": 10197401600,
288+
"start": 1052672,
289+
"state": null,
290+
"subsystems": "block:virtio:pci",
291+
"mountpoint": "/sysroot",
292+
"mountpoints": [
293+
"/var", "/sysroot/ostree/deploy/default/var", "/etc", "/boot", "/sysroot"
294+
],
295+
"tran": "virtio",
296+
"type": "part",
297+
"uuid": "9b243e03-e7c5-4f76-83f0-9b4b3f18b0eb",
298+
"vendor": null,
299+
"wsame": 0,
300+
"wwn": null,
301+
"zoned": "none",
302+
"zone-sz": 0,
303+
"zone-wgran": 0,
304+
"zone-app": 0,
305+
"zone-nr": 0,
306+
"zone-omax": 0,
307+
"zone-amax": 0
308+
}
309+
]
310+
}
311+
]
312+
}
313+

0 commit comments

Comments
 (0)