diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-10-25 17:32:01 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-11-29 16:05:17 +0100 |
commit | e3b9a5ff26a2363c523cfbc4ae0eb7e09f6ce68d (patch) | |
tree | e75ab7a8846d880db17f7f756578fbe541baf07e /src/udev/udev-builtin-blkid.c | |
parent | Merge pull request #25385 from drvink/main (diff) | |
download | systemd-e3b9a5ff26a2363c523cfbc4ae0eb7e09f6ce68d.tar.xz systemd-e3b9a5ff26a2363c523cfbc4ae0eb7e09f6ce68d.zip |
blkid: add helpers that get gpt partition uuid as sd_id128_t
just some refactoring to make things simpler.
Diffstat (limited to 'src/udev/udev-builtin-blkid.c')
-rw-r--r-- | src/udev/udev-builtin-blkid.c | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/src/udev/udev-builtin-blkid.c b/src/udev/udev-builtin-blkid.c index 9f5646ffdd..9b5dfbe33b 100644 --- a/src/udev/udev-builtin-blkid.c +++ b/src/udev/udev-builtin-blkid.c @@ -119,8 +119,9 @@ static int find_gpt_root(sd_device *dev, blkid_probe pr, bool test) { #if defined(SD_GPT_ROOT_NATIVE) && ENABLE_EFI - _cleanup_free_ char *root_id = NULL, *root_label = NULL; + _cleanup_free_ char *root_label = NULL; bool found_esp_or_xbootldr = false; + sd_id128_t root_id = SD_ID128_NULL; int r; assert(pr); @@ -137,34 +138,32 @@ static int find_gpt_root(sd_device *dev, blkid_probe pr, bool test) { int nvals = blkid_partlist_numof_partitions(pl); for (int i = 0; i < nvals; i++) { blkid_partition pp; - const char *stype, *sid, *label; - sd_id128_t type; + const char *label; + sd_id128_t type, id; pp = blkid_partlist_get_partition(pl, i); if (!pp) continue; - sid = blkid_partition_get_uuid(pp); - if (!sid) + r = blkid_partition_get_uuid_id128(pp, &id); + if (r < 0) { + log_debug_errno(r, "Failed to get partition UUID, ignoring: %m"); continue; + } - label = blkid_partition_get_name(pp); /* returns NULL if empty */ - - stype = blkid_partition_get_type_string(pp); - if (!stype) + r = blkid_partition_get_type_id128(pp, &type); + if (r < 0) { + log_debug_errno(r, "Failed to get partition type UUID, ignoring: %m"); continue; + } - if (sd_id128_from_string(stype, &type) < 0) - continue; + label = blkid_partition_get_name(pp); /* returns NULL if empty */ if (sd_id128_in_set(type, SD_GPT_ESP, SD_GPT_XBOOTLDR)) { - sd_id128_t id, esp_or_xbootldr; + sd_id128_t esp_or_xbootldr; /* We found an ESP or XBOOTLDR, let's see if it matches the ESP/XBOOTLDR we booted from. */ - if (sd_id128_from_string(sid, &id) < 0) - continue; - r = efi_loader_get_device_part_uuid(&esp_or_xbootldr); if (r < 0) return r; @@ -182,10 +181,8 @@ static int find_gpt_root(sd_device *dev, blkid_probe pr, bool test) { /* We found a suitable root partition, let's remember the first one, or the one with * the newest version, as determined by comparing the partition labels. */ - if (!root_id || strverscmp_improved(label, root_label) > 0) { - r = free_and_strdup(&root_id, sid); - if (r < 0) - return r; + if (sd_id128_is_null(root_id) || strverscmp_improved(label, root_label) > 0) { + root_id = id; r = free_and_strdup(&root_label, label); if (r < 0) @@ -196,8 +193,8 @@ static int find_gpt_root(sd_device *dev, blkid_probe pr, bool test) { /* We found the ESP/XBOOTLDR on this disk, and also found a root partition, nice! Let's export its * UUID */ - if (found_esp_or_xbootldr && root_id) - udev_builtin_add_property(dev, test, "ID_PART_GPT_AUTO_ROOT_UUID", root_id); + if (found_esp_or_xbootldr && !sd_id128_is_null(root_id)) + udev_builtin_add_property(dev, test, "ID_PART_GPT_AUTO_ROOT_UUID", SD_ID128_TO_UUID_STRING(root_id)); #endif return 0; |