sd_id128_t *ret_uuid) {
_cleanup_(blkid_free_probep) blkid_probe b = NULL;
- const char *fstype = NULL, *uuid = NULL;
+ const char *fstype = NULL;
sd_id128_t id;
int r;
if (!fstype)
return -ENOPKG;
- (void) sym_blkid_probe_lookup_value(b, "UUID", &uuid, NULL);
- if (!uuid)
+ r = blkid_probe_lookup_value_id128(b, "UUID", &id);
+ if (r == -ENXIO)
return -ENOPKG;
-
- r = sd_id128_from_string(uuid, &id);
if (r < 0)
return r;
#include "blkid-util.h"
#include "log.h"
+#include "parse-util.h"
#include "string-util.h"
#if HAVE_BLKID
return sd_id128_from_string(s, ret);
}
+int blkid_probe_lookup_value_id128(blkid_probe b, const char *field, sd_id128_t *ret) {
+ assert(b);
+ assert(field);
+
+ const char *u = NULL;
+ (void) sym_blkid_probe_lookup_value(b, field, &u, /* ret_size= */ NULL);
+ if (!u)
+ return -ENXIO;
+
+ return sd_id128_from_string(u, ret);
+}
+
+int blkid_probe_lookup_value_u64(blkid_probe b, const char *field, uint64_t *ret) {
+ assert(b);
+ assert(field);
+
+ const char *u = NULL;
+ (void) sym_blkid_probe_lookup_value(b, field, &u, /* ret_size= */ NULL);
+ if (!u)
+ return -ENXIO;
+
+ return safe_atou64(u, ret);
+}
#endif
_BLKID_SAFEPROBE_ERROR = -1,
};
+int blkid_probe_lookup_value_id128(blkid_probe b, const char *field, sd_id128_t *ret);
+int blkid_probe_lookup_value_u64(blkid_probe b, const char *field, uint64_t *ret);
#else
static inline int dlopen_libblkid(void) {
return -EOPNOTSUPP;
_cleanup_(blkid_free_probep) blkid_probe b = NULL;
_cleanup_free_ char *generic_node = NULL;
sd_id128_t generic_uuid = SD_ID128_NULL;
- const char *pttype = NULL, *sptuuid = NULL;
+ const char *pttype = NULL;
blkid_partlist pl;
int r, generic_nr = -1, n_partitions;
(void) sym_blkid_probe_lookup_value(b, "USAGE", &usage, NULL);
if (STRPTR_IN_SET(usage, "filesystem", "crypto")) {
_cleanup_free_ char *t = NULL, *n = NULL, *o = NULL;
- const char *fstype = NULL, *options = NULL, *suuid = NULL;
+ const char *fstype = NULL, *options = NULL;
_cleanup_close_ int mount_node_fd = -EBADF;
sd_id128_t uuid = SD_ID128_NULL;
PartitionPolicyFlags found_flags;
return -ENOPKG;
(void) sym_blkid_probe_lookup_value(b, "TYPE", &fstype, NULL);
- (void) sym_blkid_probe_lookup_value(b, "UUID", &suuid, NULL);
+
+ /* blkid will return FAT's serial number as UUID, hence it is quite possible that
+ * parsing this will fail. We'll ignore the ID, since it's just too short to be
+ * useful as true identifier. */
+ (void) blkid_probe_lookup_value_id128(b, "UUID", &uuid);
encrypted = streq_ptr(fstype, "crypto_LUKS");
return -ENOMEM;
}
- if (suuid) {
- /* blkid will return FAT's serial number as UUID, hence it is quite possible
- * that parsing this will fail. We'll ignore the ID, since it's just too
- * short to be useful as true identifier. */
- r = sd_id128_from_string(suuid, &uuid);
- if (r < 0)
- log_debug_errno(r, "Failed to parse file system UUID '%s', ignoring: %m", suuid);
- }
-
r = make_partition_devname(devname, diskseq, -1, flags, &n);
if (r < 0)
return r;
return -EPROTONOSUPPORT;
}
- (void) sym_blkid_probe_lookup_value(b, "PTUUID", &sptuuid, NULL);
- if (sptuuid) {
- r = sd_id128_from_string(sptuuid, &m->image_uuid);
- if (r < 0)
- log_debug_errno(r, "Failed to parse partition table UUID '%s', ignoring: %m", sptuuid);
- }
+ (void) blkid_probe_lookup_value_id128(b, "PTUUID", &m->image_uuid);
errno = 0;
pl = sym_blkid_probe_get_partitions(b);
SYNTHETIC_ERRNO(searching ? EADDRNOTAVAIL : ENODEV),
"File system \"%s\" has wrong type for an EFI System Partition (ESP).", node);
- errno = 0;
- r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_UUID", &v, NULL);
- if (r != 0)
- return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "Failed to probe partition entry UUID of \"%s\": %m", node);
- r = sd_id128_from_string(v, &uuid);
+ r = blkid_probe_lookup_value_id128(b, "PART_ENTRY_UUID", &uuid);
if (r < 0)
- return log_error_errno(r, "Partition \"%s\" has invalid UUID \"%s\".", node, v);
+ return log_error_errno(r, "Failed to probe partition entry UUID of \"%s\": %m", node);
errno = 0;
r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_NUMBER", &v, NULL);
if (r < 0)
return log_error_errno(r, "Failed to parse PART_ENTRY_NUMBER field.");
- errno = 0;
- r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_OFFSET", &v, NULL);
- if (r != 0)
- return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "Failed to probe partition offset of \"%s\": %m", node);
- r = safe_atou64(v, &pstart);
+ r = blkid_probe_lookup_value_u64(b, "PART_ENTRY_OFFSET", &pstart);
if (r < 0)
- return log_error_errno(r, "Failed to parse PART_ENTRY_OFFSET field.");
+ return log_error_errno(r, "Failed to probe partition offset of \"%s\": %m", node);
- errno = 0;
- r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_SIZE", &v, NULL);
- if (r != 0)
- return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "Failed to probe partition size of \"%s\": %m", node);
- r = safe_atou64(v, &psize);
+ r = blkid_probe_lookup_value_u64(b, "PART_ENTRY_SIZE", &psize);
if (r < 0)
- return log_error_errno(r, "Failed to parse PART_ENTRY_SIZE field.");
+ return log_error_errno(r, "Failed to probe partition size of \"%s\": %m", node);
#endif
if (ret_part)
searching ? SYNTHETIC_ERRNO(EADDRNOTAVAIL) : SYNTHETIC_ERRNO(ENODEV),
"%s: Partition has wrong PART_ENTRY_TYPE=%s for XBOOTLDR partition.", node, v);
- errno = 0;
- r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_UUID", &v, NULL);
+ r = blkid_probe_lookup_value_id128(b, "PART_ENTRY_UUID", &uuid);
if (r != 0)
return log_error_errno(errno_or_else(EIO), "%s: Failed to probe PART_ENTRY_UUID: %m", node);
- r = sd_id128_from_string(v, &uuid);
- if (r < 0)
- return log_error_errno(r, "%s: Partition has invalid UUID PART_ENTRY_TYPE=%s: %m", node, v);
} else if (streq(type, "dos")) {