]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fdisk-util: add fdisk_partition_get_type_as_id128() helper 25558/head
authorLennart Poettering <lennart@poettering.net>
Tue, 29 Nov 2022 11:06:35 +0000 (12:06 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 29 Nov 2022 11:07:15 +0000 (12:07 +0100)
Let's also add an easy accessor for the other per-partition UUID.

src/partition/repart.c
src/shared/fdisk-util.c
src/shared/fdisk-util.h
src/sysupdate/sysupdate-partition.c

index 375df04ad7f7720f13743045f964bc5aa431e198..95672f240d63a1608db5275db730bedc1dc25dd6 100644 (file)
@@ -2092,8 +2092,7 @@ static int context_load_partition_table(
                 _cleanup_free_ char *label_copy = NULL;
                 Partition *last = NULL;
                 struct fdisk_partition *p;
-                struct fdisk_parttype *pt;
-                const char *pts, *label;
+                const char *label;
                 uint64_t sz, start;
                 bool found = false;
                 sd_id128_t ptid, id;
@@ -2111,17 +2110,9 @@ static int context_load_partition_table(
                     fdisk_partition_has_partno(p) <= 0)
                         return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Found a partition without a position, size or number.");
 
-                pt = fdisk_partition_get_type(p);
-                if (!pt)
-                        return log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to acquire type of partition: %m");
-
-                pts = fdisk_parttype_get_string(pt);
-                if (!pts)
-                        return log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to acquire type of partition as string: %m");
-
-                r = sd_id128_from_string(pts, &ptid);
+                r = fdisk_partition_get_type_as_id128(p, &ptid);
                 if (r < 0)
-                        return log_error_errno(r, "Failed to parse partition type UUID %s: %m", pts);
+                        return log_error_errno(r, "Failed to query partition type UUID: %m");
 
                 r = fdisk_partition_get_uuid_as_id128(p, &id);
                 if (r < 0)
index 9aba3230430b968a300539a3e05dfc174d951630..eeed1840aab93dd09edcb1a0522a0725f819460e 100644 (file)
@@ -39,4 +39,22 @@ int fdisk_partition_get_uuid_as_id128(struct fdisk_partition *p, sd_id128_t *ret
         return sd_id128_from_string(ids, ret);
 }
 
+int fdisk_partition_get_type_as_id128(struct fdisk_partition *p, sd_id128_t *ret) {
+        struct fdisk_parttype *pt;
+        const char *pts;
+
+        assert(p);
+        assert(ret);
+
+        pt = fdisk_partition_get_type(p);
+        if (!pt)
+                return -ENXIO;
+
+        pts = fdisk_parttype_get_string(pt);
+        if (!pts)
+                return -ENXIO;
+
+        return sd_id128_from_string(pts, ret);
+}
+
 #endif
index 91c3ce46bd35fe5fa0965cb55e816dd06e28d32a..7f34a042ec52fe12062569e3367e5a1a44ea6ff4 100644 (file)
@@ -17,5 +17,6 @@ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct fdisk_table*, fdisk_unref_table, 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);
+int fdisk_partition_get_type_as_id128(struct fdisk_partition *p, sd_id128_t *ret);
 
 #endif
index 486f9f19ddc5d3781c5c681836c1d3fa469c6011..bd0486d99ed50e93714298941e408b0234584dc8 100644 (file)
@@ -106,9 +106,8 @@ int read_partition_info(
                 PartitionInfo *ret) {
 
         _cleanup_free_ char *label_copy = NULL, *device = NULL;
-        const char *pts, *label;
+        const char *label;
         struct fdisk_partition *p;
-        struct fdisk_parttype *pt;
         uint64_t start, size, flags;
         sd_id128_t ptid, id;
         GptPartitionType type;
@@ -147,17 +146,9 @@ int read_partition_info(
         if (!label)
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Found a partition without a label.");
 
-        pt = fdisk_partition_get_type(p);
-        if (!pt)
-                return log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to acquire type of partition: %m");
-
-        pts = fdisk_parttype_get_string(pt);
-        if (!pts)
-                return log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to acquire type of partition as string: %m");
-
-        r = sd_id128_from_string(pts, &ptid);
+        r = fdisk_partition_get_type_as_id128(p, &ptid);
         if (r < 0)
-                return log_error_errno(r, "Failed to parse partition type UUID %s: %m", pts);
+                return log_error_errno(r, "Failed to read partition type UUID: %m");
 
         r = fdisk_partition_get_uuid_as_id128(p, &id);
         if (r < 0)