Skip to content

Commit

Permalink
Merge pull request #1086 from cgwalters/blockdev-pttype
Browse files Browse the repository at this point in the history
blockdev: Extend lsblk output with parttype and partuuid
  • Loading branch information
cgwalters authored Feb 6, 2025
2 parents c8e1fb8 + 85f33a9 commit 69264e0
Show file tree
Hide file tree
Showing 2 changed files with 333 additions and 0 deletions.
20 changes: 20 additions & 0 deletions blockdev/src/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct Device {
pub serial: Option<String>,
pub model: Option<String>,
pub partlabel: Option<String>,
pub parttype: Option<String>,
pub partuuid: Option<String>,
pub children: Option<Vec<Device>>,
pub size: u64,
#[serde(rename = "maj:min")]
Expand Down Expand Up @@ -330,6 +332,24 @@ mod test {
}
}

#[test]
fn test_parse_lsblk() {
let fixture = include_str!("../tests/fixtures/lsblk.json");
let devs: DevicesOutput = serde_json::from_str(&fixture).unwrap();
let dev = devs.blockdevices.into_iter().next().unwrap();
let children = dev.children.as_deref().unwrap();
assert_eq!(children.len(), 3);
let first_child = &children[0];
assert_eq!(
first_child.parttype.as_deref().unwrap(),
"21686148-6449-6e6f-744e-656564454649"
);
assert_eq!(
first_child.partuuid.as_deref().unwrap(),
"3979e399-262f-4666-aabc-7ab5d3add2f0"
);
}

#[test]
fn test_parse_sfdisk() -> Result<()> {
let fixture = indoc::indoc! { r#"
Expand Down
313 changes: 313 additions & 0 deletions blockdev/tests/fixtures/lsblk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,313 @@
{
"blockdevices": [
{
"alignment": 0,
"id-link": null,
"id": null,
"disc-aln": 0,
"dax": false,
"disc-gran": 512,
"disk-seq": 1,
"disc-max": 2147483136,
"disc-zero": false,
"fsavail": null,
"fsroots": [
null
],
"fssize": null,
"fstype": null,
"fsused": null,
"fsuse%": null,
"fsver": null,
"group": "disk",
"hctl": null,
"hotplug": false,
"kname": "vda",
"label": null,
"log-sec": 512,
"maj:min": "252:0",
"maj": "252",
"min": "0",
"min-io": 512,
"mode": "brw-rw----",
"model": null,
"mq": " 2",
"name": "vda",
"opt-io": 0,
"owner": "root",
"partflags": null,
"partlabel": null,
"partn": null,
"parttype": null,
"parttypename": null,
"partuuid": null,
"path": "/dev/vda",
"phy-sec": 512,
"pkname": null,
"pttype": "gpt",
"ptuuid": "6596b2ac-09cd-41a0-8229-74bc5157d879",
"ra": 128,
"rand": false,
"rev": null,
"rm": false,
"ro": false,
"rota": true,
"rq-size": 256,
"sched": "none",
"serial": null,
"size": 10737418240,
"start": null,
"state": null,
"subsystems": "block:virtio:pci",
"mountpoint": null,
"mountpoints": [
null
],
"tran": "virtio",
"type": "disk",
"uuid": null,
"vendor": "0x1af4",
"wsame": 0,
"wwn": null,
"zoned": "none",
"zone-sz": 0,
"zone-wgran": 0,
"zone-app": 0,
"zone-nr": 0,
"zone-omax": 0,
"zone-amax": 0,
"children": [
{
"alignment": 0,
"id-link": null,
"id": null,
"disc-aln": 0,
"dax": false,
"disc-gran": 512,
"disk-seq": 1,
"disc-max": 2147483136,
"disc-zero": false,
"fsavail": null,
"fsroots": [
null
],
"fssize": null,
"fstype": null,
"fsused": null,
"fsuse%": null,
"fsver": null,
"group": "disk",
"hctl": null,
"hotplug": false,
"kname": "vda1",
"label": null,
"log-sec": 512,
"maj:min": "252:1",
"maj": "252",
"min": "1",
"min-io": 512,
"mode": "brw-rw----",
"model": null,
"mq": " 2",
"name": "vda1",
"opt-io": 0,
"owner": "root",
"partflags": null,
"partlabel": "BIOS-BOOT",
"partn": 1,
"parttype": "21686148-6449-6e6f-744e-656564454649",
"parttypename": "BIOS boot",
"partuuid": "3979e399-262f-4666-aabc-7ab5d3add2f0",
"path": "/dev/vda1",
"phy-sec": 512,
"pkname": "vda",
"pttype": "gpt",
"ptuuid": "6596b2ac-09cd-41a0-8229-74bc5157d879",
"ra": 128,
"rand": false,
"rev": null,
"rm": false,
"ro": false,
"rota": true,
"rq-size": 256,
"sched": "none",
"serial": null,
"size": 1048576,
"start": 2048,
"state": null,
"subsystems": "block:virtio:pci",
"mountpoint": null,
"mountpoints": [
null
],
"tran": "virtio",
"type": "part",
"uuid": null,
"vendor": null,
"wsame": 0,
"wwn": null,
"zoned": "none",
"zone-sz": 0,
"zone-wgran": 0,
"zone-app": 0,
"zone-nr": 0,
"zone-omax": 0,
"zone-amax": 0
},{
"alignment": 0,
"id-link": null,
"id": null,
"disc-aln": 0,
"dax": false,
"disc-gran": 512,
"disk-seq": 1,
"disc-max": 2147483136,
"disc-zero": false,
"fsavail": null,
"fsroots": [
null
],
"fssize": null,
"fstype": "vfat",
"fsused": null,
"fsuse%": null,
"fsver": "FAT32",
"group": "disk",
"hctl": null,
"hotplug": false,
"kname": "vda2",
"label": "EFI-SYSTEM",
"log-sec": 512,
"maj:min": "252:2",
"maj": "252",
"min": "2",
"min-io": 512,
"mode": "brw-rw----",
"model": null,
"mq": " 2",
"name": "vda2",
"opt-io": 0,
"owner": "root",
"partflags": null,
"partlabel": "EFI-SYSTEM",
"partn": 2,
"parttype": "c12a7328-f81f-11d2-ba4b-00a0c93ec93b",
"parttypename": "EFI System",
"partuuid": "392375a5-8cb5-4f15-885f-0d6b410dcd6c",
"path": "/dev/vda2",
"phy-sec": 512,
"pkname": "vda",
"pttype": "gpt",
"ptuuid": "6596b2ac-09cd-41a0-8229-74bc5157d879",
"ra": 128,
"rand": false,
"rev": null,
"rm": false,
"ro": false,
"rota": true,
"rq-size": 256,
"sched": "none",
"serial": null,
"size": 536870912,
"start": 4096,
"state": null,
"subsystems": "block:virtio:pci",
"mountpoint": null,
"mountpoints": [
null
],
"tran": "virtio",
"type": "part",
"uuid": "FB0A-EA04",
"vendor": null,
"wsame": 0,
"wwn": null,
"zoned": "none",
"zone-sz": 0,
"zone-wgran": 0,
"zone-app": 0,
"zone-nr": 0,
"zone-omax": 0,
"zone-amax": 0
},{
"alignment": 0,
"id-link": null,
"id": null,
"disc-aln": 0,
"dax": false,
"disc-gran": 512,
"disk-seq": 1,
"disc-max": 2147483136,
"disc-zero": false,
"fsavail": 5746880512,
"fsroots": [
"/ostree/deploy/default/var", "/ostree/deploy/default/var", "/ostree/deploy/default/deploy/41b7689b3d723570fcea1942007139dbbd7a4dfa7225b1747b47ddb67b37955a.0/etc", "/boot", "/"
],
"fssize": 9932427264,
"fstype": "ext4",
"fsused": 3658899456,
"fsuse%": "37%",
"fsver": "1.0",
"group": "disk",
"hctl": null,
"hotplug": false,
"kname": "vda3",
"label": "root",
"log-sec": 512,
"maj:min": "252:3",
"maj": "252",
"min": "3",
"min-io": 512,
"mode": "brw-rw----",
"model": null,
"mq": " 2",
"name": "vda3",
"opt-io": 0,
"owner": "root",
"partflags": null,
"partlabel": "root",
"partn": 3,
"parttype": "0fc63daf-8483-4772-8e79-3d69d8477de4",
"parttypename": "Linux filesystem",
"partuuid": "61709da2-1972-4f44-88fd-9d87bf9efe9c",
"path": "/dev/vda3",
"phy-sec": 512,
"pkname": "vda",
"pttype": "gpt",
"ptuuid": "6596b2ac-09cd-41a0-8229-74bc5157d879",
"ra": 128,
"rand": false,
"rev": null,
"rm": false,
"ro": false,
"rota": true,
"rq-size": 256,
"sched": "none",
"serial": null,
"size": 10197401600,
"start": 1052672,
"state": null,
"subsystems": "block:virtio:pci",
"mountpoint": "/sysroot",
"mountpoints": [
"/var", "/sysroot/ostree/deploy/default/var", "/etc", "/boot", "/sysroot"
],
"tran": "virtio",
"type": "part",
"uuid": "9b243e03-e7c5-4f76-83f0-9b4b3f18b0eb",
"vendor": null,
"wsame": 0,
"wwn": null,
"zoned": "none",
"zone-sz": 0,
"zone-wgran": 0,
"zone-app": 0,
"zone-nr": 0,
"zone-omax": 0,
"zone-amax": 0
}
]
}
]
}

0 comments on commit 69264e0

Please sign in to comment.