daemon/inspect_fs_windows.ml: Ignore blank disks in drive mapping

If HKLM\System\MountedDevices references a blank disk, then when we
try to search for the actual backing device we will get an error from
parted:

  parted: /dev/sdb: parted exited with status 1: Error: /dev/sdb: unrecognised disk label: Invalid argument

Just ignore these errors instead of failing inspection.

Fixes: https://issues.redhat.com/browse/RHEL-108803
Reported-by: Ameen Barakat
Thanks: Ming Xie
(cherry picked from commit 1c00248ac1)
This commit is contained in:
Richard W.M. Jones
2025-08-14 15:17:59 +01:00
parent 3720994fca
commit 98d94d847f

View File

@@ -389,8 +389,18 @@ and map_registry_disk_blob_mbr devices blob =
let device =
List.find (
fun dev ->
Parted.part_get_parttype dev = "msdos" &&
try
Parted.part_get_parttype dev = "msdos" &&
pread dev 4 0x01b8 = diskid
with Unix.Unix_error (EINVAL, "parted", msg) ->
(* Errors can happen here if the disk is empty. Just ignore
* them. It means the drive mapping might have missing
* entries but that's not important. (RHEL-108803)
*)
if verbose () then
eprintf "map_registry_disk_blob_mbr: parted returned: \
%s (ignored)\n" msg;
false
) devices in
(* Next 8 bytes are the offset of the partition in bytes(!) given as
@@ -428,14 +438,21 @@ and map_registry_disk_blob_gpt partitions blob =
let partition =
List.find (
fun part ->
let partnum = Devsparts.part_to_partnum part in
let device = Devsparts.part_to_dev part in
let typ = Parted.part_get_parttype device in
if typ <> "gpt" then false
else (
let guid = Sfdisk.part_get_gpt_guid device partnum in
String.lowercase_ascii guid = blob_guid
)
try
let partnum = Devsparts.part_to_partnum part in
let device = Devsparts.part_to_dev part in
let typ = Parted.part_get_parttype device in
if typ <> "gpt" then false
else (
let guid = Sfdisk.part_get_gpt_guid device partnum in
String.lowercase_ascii guid = blob_guid
)
with Unix.Unix_error (EINVAL, "parted", msg) ->
(* See comment in MBR code above (RHEL-108803) *)
if verbose () then
eprintf "map_registry_disk_blob_gpt: parted returned: \
%s (ignored)\n" msg;
false
) partitions in
Some partition
with