]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/gpt: export gpt_partition_type_uuid_{to,from}_string functions
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 23 Jan 2020 21:55:48 +0000 (22:55 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 23 Jan 2020 21:56:23 +0000 (22:56 +0100)
src/partition/repart.c
src/shared/gpt.c [new file with mode: 0644]
src/shared/gpt.h
src/shared/meson.build

index 9844de59610682e50bf2dbf52a3f1d87df308f8a..58fb9c7c5d33196043c79c91744e41a41b5cb780 100644 (file)
@@ -818,76 +818,6 @@ static void context_place_partitions(Context *context) {
         }
 }
 
-typedef struct GptPartitionType {
-        sd_id128_t uuid;
-        const char *name;
-} GptPartitionType;
-
-static const GptPartitionType gpt_partition_type_table[] = {
-        { GPT_ROOT_X86,              "root-x86"              },
-        { GPT_ROOT_X86_VERITY,       "root-x86-verity"       },
-        { GPT_ROOT_X86_64,           "root-x86-64"           },
-        { GPT_ROOT_X86_64_VERITY,    "root-x86-64-verity"    },
-        { GPT_ROOT_ARM,              "root-arm"              },
-        { GPT_ROOT_ARM_VERITY,       "root-arm-verity"       },
-        { GPT_ROOT_ARM_64,           "root-arm64"            },
-        { GPT_ROOT_ARM_64_VERITY,    "root-arm64-verity"     },
-        { GPT_ROOT_IA64,             "root-ia64"             },
-        { GPT_ROOT_IA64_VERITY,      "root-ia64-verity"      },
-#ifdef GPT_ROOT_NATIVE
-        { GPT_ROOT_NATIVE,           "root"                  },
-        { GPT_ROOT_NATIVE_VERITY,    "root-verity"           },
-#endif
-#ifdef GPT_ROOT_SECONDARY
-        { GPT_ROOT_SECONDARY,        "root-secondary"        },
-        { GPT_ROOT_SECONDARY_VERITY, "root-secondary-verity" },
-#endif
-        { GPT_ESP,                   "esp"                   },
-        { GPT_XBOOTLDR,              "xbootldr"              },
-        { GPT_SWAP,                  "swap"                  },
-        { GPT_HOME,                  "home"                  },
-        { GPT_SRV,                   "srv"                   },
-        { GPT_VAR,                   "var"                   },
-        { GPT_TMP,                   "tmp"                   },
-        { GPT_LINUX_GENERIC,         "linux-generic",        },
-};
-
-static const char *gpt_partition_type_uuid_to_string(sd_id128_t id) {
-        for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table); i++)
-                if (sd_id128_equal(id, gpt_partition_type_table[i].uuid))
-                        return gpt_partition_type_table[i].name;
-
-        return NULL;
-}
-
-static const char *gpt_partition_type_uuid_to_string_harder(
-                sd_id128_t id,
-                char buffer[static ID128_UUID_STRING_MAX]) {
-
-        const char *s;
-
-        assert(buffer);
-
-        s = gpt_partition_type_uuid_to_string(id);
-        if (s)
-                return s;
-
-        return id128_to_uuid_string(id, buffer);
-}
-
-static int gpt_partition_type_uuid_from_string(const char *s, sd_id128_t *ret) {
-        assert(s);
-        assert(ret);
-
-        for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table); i++)
-                if (streq(s, gpt_partition_type_table[i].name)) {
-                        *ret = gpt_partition_type_table[i].uuid;
-                        return 0;
-                }
-
-        return sd_id128_from_string(s, ret);
-}
-
 static int config_parse_type(
                 const char *unit,
                 const char *filename,
diff --git a/src/shared/gpt.c b/src/shared/gpt.c
new file mode 100644 (file)
index 0000000..024f4db
--- /dev/null
@@ -0,0 +1,74 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "gpt.h"
+#include "string-util.h"
+
+typedef struct GptPartitionType {
+        sd_id128_t uuid;
+        const char *name;
+} GptPartitionType;
+
+static const GptPartitionType gpt_partition_type_table[] = {
+        { GPT_ROOT_X86,              "root-x86"              },
+        { GPT_ROOT_X86_VERITY,       "root-x86-verity"       },
+        { GPT_ROOT_X86_64,           "root-x86-64"           },
+        { GPT_ROOT_X86_64_VERITY,    "root-x86-64-verity"    },
+        { GPT_ROOT_ARM,              "root-arm"              },
+        { GPT_ROOT_ARM_VERITY,       "root-arm-verity"       },
+        { GPT_ROOT_ARM_64,           "root-arm64"            },
+        { GPT_ROOT_ARM_64_VERITY,    "root-arm64-verity"     },
+        { GPT_ROOT_IA64,             "root-ia64"             },
+        { GPT_ROOT_IA64_VERITY,      "root-ia64-verity"      },
+#ifdef GPT_ROOT_NATIVE
+        { GPT_ROOT_NATIVE,           "root"                  },
+        { GPT_ROOT_NATIVE_VERITY,    "root-verity"           },
+#endif
+#ifdef GPT_ROOT_SECONDARY
+        { GPT_ROOT_SECONDARY,        "root-secondary"        },
+        { GPT_ROOT_SECONDARY_VERITY, "root-secondary-verity" },
+#endif
+        { GPT_ESP,                   "esp"                   },
+        { GPT_XBOOTLDR,              "xbootldr"              },
+        { GPT_SWAP,                  "swap"                  },
+        { GPT_HOME,                  "home"                  },
+        { GPT_SRV,                   "srv"                   },
+        { GPT_VAR,                   "var"                   },
+        { GPT_TMP,                   "tmp"                   },
+        { GPT_LINUX_GENERIC,         "linux-generic",        },
+};
+
+const char *gpt_partition_type_uuid_to_string(sd_id128_t id) {
+        for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table); i++)
+                if (sd_id128_equal(id, gpt_partition_type_table[i].uuid))
+                        return gpt_partition_type_table[i].name;
+
+        return NULL;
+}
+
+const char *gpt_partition_type_uuid_to_string_harder(
+                sd_id128_t id,
+                char buffer[static ID128_UUID_STRING_MAX]) {
+
+        const char *s;
+
+        assert(buffer);
+
+        s = gpt_partition_type_uuid_to_string(id);
+        if (s)
+                return s;
+
+        return id128_to_uuid_string(id, buffer);
+}
+
+int gpt_partition_type_uuid_from_string(const char *s, sd_id128_t *ret) {
+        assert(s);
+        assert(ret);
+
+        for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table); i++)
+                if (streq(s, gpt_partition_type_table[i].name)) {
+                        *ret = gpt_partition_type_table[i].uuid;
+                        return 0;
+                }
+
+        return sd_id128_from_string(s, ret);
+}
index 8e9b111857c40b722161bd200855e28a2269756c..a07bd630172501927a72178d9f843f6e1f567e98 100644 (file)
@@ -5,6 +5,8 @@
 
 #include "sd-id128.h"
 
+#include "id128-util.h"
+
 /* We only support root disk discovery for x86, x86-64, Itanium and ARM for
  * now, since EFI for anything else doesn't really exist, and we only
  * care for root partitions on the same disk as the EFI ESP. */
@@ -65,3 +67,9 @@
 #define GPT_FLAG_NO_AUTO (1ULL << 63)
 
 #define GPT_LINUX_GENERIC SD_ID128_MAKE(0f,c6,3d,af,84,83,47,72,8e,79,3d,69,d8,47,7d,e4)
+
+const char *gpt_partition_type_uuid_to_string(sd_id128_t id);
+const char *gpt_partition_type_uuid_to_string_harder(
+                sd_id128_t id,
+                char buffer[static ID128_UUID_STRING_MAX]);
+int gpt_partition_type_uuid_from_string(const char *s, sd_id128_t *ret);
index a7320fc4ed6ec044dac7df01c094a62be0ea0c2a..f51f4ee1f4674c9d99aeb38740d9221a339e2e0a 100644 (file)
@@ -85,6 +85,7 @@ shared_sources = files('''
         fstab-util.h
         generator.c
         generator.h
+        gpt.c
         gpt.h
         group-record-nss.c
         group-record-nss.h