Partition *last = NULL;
struct fdisk_partition *p;
struct fdisk_parttype *pt;
- const char *pts, *ids, *label;
+ const char *pts, *label;
uint64_t sz, start;
bool found = false;
sd_id128_t ptid, id;
if (r < 0)
return log_error_errno(r, "Failed to parse partition type UUID %s: %m", pts);
- ids = fdisk_partition_get_uuid(p);
- if (!ids)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Found a partition without a UUID.");
-
- r = sd_id128_from_string(ids, &id);
+ r = fdisk_partition_get_uuid_as_id128(p, &id);
if (r < 0)
- return log_error_errno(r, "Failed to parse partition UUID %s: %m", ids);
+ return log_error_errno(r, "Failed to query partition UUID: %m");
label = fdisk_partition_get_name(p);
if (!isempty(label)) {
return 0;
}
+int fdisk_partition_get_uuid_as_id128(struct fdisk_partition *p, sd_id128_t *ret) {
+ const char *ids;
+
+ assert(p);
+ assert(ret);
+
+ ids = fdisk_partition_get_uuid(p);
+ if (!ids)
+ return -ENXIO;
+
+ return sd_id128_from_string(ids, ret);
+}
+
#endif
#include <libfdisk.h>
+#include "sd-id128.h"
+
#include "macro.h"
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct fdisk_context*, fdisk_unref_context, NULL);
int fdisk_new_context_fd(int fd, bool read_only, struct fdisk_context **ret);
+int fdisk_partition_get_uuid_as_id128(struct fdisk_partition *p, sd_id128_t *ret);
+
#endif
PartitionInfo *ret) {
_cleanup_free_ char *label_copy = NULL, *device = NULL;
- const char *pts, *ids, *label;
+ const char *pts, *label;
struct fdisk_partition *p;
struct fdisk_parttype *pt;
uint64_t start, size, flags;
if (r < 0)
return log_error_errno(r, "Failed to parse partition type UUID %s: %m", pts);
- ids = fdisk_partition_get_uuid(p);
- if (!ids)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Found a partition without a UUID.");
-
- r = sd_id128_from_string(ids, &id);
+ r = fdisk_partition_get_uuid_as_id128(p, &id);
if (r < 0)
- return log_error_errno(r, "Failed to parse partition UUID %s: %m", ids);
+ return log_error_errno(r, "Failed to read partition UUID: %m");
r = fdisk_partition_get_attrs_as_uint64(p, &flags);
if (r < 0)