blkid: add helpers that get gpt partition uuid as sd_id128_t

just some refactoring to make things simpler.
This commit is contained in:
Lennart Poettering
2022-11-29 16:05:17 +01:00
parent 0461375326
commit e3b9a5ff26
5 changed files with 69 additions and 54 deletions
+27
View File
@@ -4,7 +4,34 @@
#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
+11 -13
View File
@@ -627,22 +627,22 @@ static int dissect_image(
}
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);
@@ -966,7 +966,7 @@ static int dissect_image(
_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)
@@ -978,9 +978,7 @@ static int dissect_image(
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) {