just some refactoring to make things simpler.
return errno > 0 ? -errno : -EIO;
for (int i = 0; i < n; i++) {
- blkid_partition pp;
sd_id128_t id = SD_ID128_NULL;
- const char *sid;
+ blkid_partition pp;
errno = 0;
pp = blkid_partlist_get_partition(pl, i);
if (!streq_ptr(blkid_partition_get_name(pp), label))
continue;
- sid = blkid_partition_get_uuid(pp);
- if (sid) {
- r = sd_id128_from_string(sid, &id);
- if (r < 0)
- log_debug_errno(r, "Couldn't parse partition UUID %s, weird: %m", sid);
- if (!sd_id128_is_null(partition_uuid) && !sd_id128_equal(id, partition_uuid))
- continue;
- }
+ r = blkid_partition_get_uuid_id128(pp, &id);
+ if (r < 0)
+ log_debug_errno(r, "Failed to read partition UUID, ignoring: %m");
+ else if (!sd_id128_is_null(partition_uuid) && !sd_id128_equal(id, partition_uuid))
+ continue;
if (found)
return -ENOPKG;
return false;
}
- t = blkid_partition_get_uuid(pp);
- if (isempty(t)) {
- log_debug("Partition %u:%u has no UUID.",
- major(partition_devno), minor(partition_devno));
+ r = blkid_partition_get_uuid_id128(pp, &u);
+ if (r == -ENXIO) {
+ log_debug_errno(r, "Partition " DEVNUM_FORMAT_STR " has no UUID.", DEVNUM_FORMAT_VAL(partition_devno));
return false;
}
-
- r = sd_id128_from_string(t, &u);
if (r < 0) {
- log_debug_errno(r, "Failed to parse partition UUID \"%s\": %m", t);
+ log_debug_errno(r, "Failed to read partition UUID of " DEVNUM_FORMAT_STR ": %m", DEVNUM_FORMAT_VAL(partition_devno));
return false;
}
- log_debug("Automatically found partition %u:%u of right type " SD_ID128_FORMAT_STR ".",
- major(partition_devno), minor(partition_devno),
+ log_debug("Automatically found partition " DEVNUM_FORMAT_STR " of right type " SD_ID128_FORMAT_STR ".",
+ DEVNUM_FORMAT_VAL(partition_devno),
SD_ID128_FORMAT_VAL(pt_parsed));
if (ret_uuid)
#if HAVE_BLKID
# include <blkid.h>
+# include "sd-id128.h"
+
# include "macro.h"
+# include "string-util.h"
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(blkid_probe, blkid_free_probe, NULL);
+
+static inline int blkid_partition_get_uuid_id128(blkid_partition p, sd_id128_t *ret) {
+ const char *s;
+
+ assert(p);
+
+ s = blkid_partition_get_uuid(p);
+ if (isempty(s))
+ return -ENXIO;
+
+ return sd_id128_from_string(s, ret);
+}
+
+static inline int blkid_partition_get_type_id128(blkid_partition p, sd_id128_t *ret) {
+ const char *s;
+
+ assert(p);
+
+ s = blkid_partition_get_type_string(p);
+ if (isempty(s))
+ return -ENXIO;
+
+ return sd_id128_from_string(s, ret);
+}
#endif
}
if (is_gpt) {
- const char *stype, *sid, *fstype = NULL, *label;
+ const char *fstype = NULL, *label;
sd_id128_t type_id, id;
GptPartitionType type;
bool rw = true, growfs = false;
- sid = blkid_partition_get_uuid(pp);
- if (!sid)
- continue;
- if (sd_id128_from_string(sid, &id) < 0)
+ r = blkid_partition_get_uuid_id128(pp, &id);
+ if (r < 0) {
+ log_debug_errno(r, "Failed to read partition UUID, ignoring: %m");
continue;
+ }
- stype = blkid_partition_get_type_string(pp);
- if (!stype)
- continue;
- if (sd_id128_from_string(stype, &type_id) < 0)
+ r = blkid_partition_get_type_id128(pp, &type_id);
+ if (r < 0) {
+ log_debug_errno(r, "Failed to read partition type UUID, ignoring: %m");
continue;
+ }
type = gpt_partition_type_from_uuid(type_id);
_cleanup_close_ int mount_node_fd = -1;
_cleanup_free_ char *o = NULL;
sd_id128_t id = SD_ID128_NULL;
- const char *sid, *options = NULL;
+ const char *options = NULL;
/* First one wins */
if (m->partitions[PARTITION_XBOOTLDR].found)
return mount_node_fd;
}
- sid = blkid_partition_get_uuid(pp);
- if (sid)
- (void) sd_id128_from_string(sid, &id);
+ (void) blkid_partition_get_uuid_id128(pp, &id);
options = mount_options_from_designator(mount_options, PARTITION_XBOOTLDR);
if (options) {
#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);
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;
/* 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)
/* 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;