summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-05-31 13:44:00 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2023-05-31 13:48:13 +0200
commit7767b83f4a98a59b6d023f1296a5e2742c50453e (patch)
treed118c629ea74b4476055a1e1fb6a12844e61c955 /src/shared
parentgpt: Use FOREACH_ARRAY (diff)
downloadsystemd-7767b83f4a98a59b6d023f1296a5e2742c50453e.tar.xz
systemd-7767b83f4a98a59b6d023f1296a5e2742c50453e.zip
gpt: Add gpt_partition_type_override_architecture()
Let's add a function that allows changing the architecture of a given partition type.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/gpt.c12
-rw-r--r--src/shared/gpt.h2
2 files changed, 14 insertions, 0 deletions
diff --git a/src/shared/gpt.c b/src/shared/gpt.c
index 4df8724f41..dd96261888 100644
--- a/src/shared/gpt.c
+++ b/src/shared/gpt.c
@@ -248,6 +248,18 @@ int gpt_partition_type_from_string(const char *s, GptPartitionType *ret) {
return 0;
}
+GptPartitionType gpt_partition_type_override_architecture(GptPartitionType type, Architecture arch) {
+ assert(arch >= 0);
+
+ FOREACH_ARRAY(t, gpt_partition_type_table, ELEMENTSOF(gpt_partition_type_table) - 1)
+ if (t->designator == type.designator && t->arch == arch)
+ return *t;
+
+ /* If we can't find an entry with the same designator and the requested architecture, just return the
+ * original partition type. */
+ return type;
+}
+
Architecture gpt_partition_type_uuid_to_arch(sd_id128_t id) {
const GptPartitionType *pt;
diff --git a/src/shared/gpt.h b/src/shared/gpt.h
index bebfbc6116..8623a8664e 100644
--- a/src/shared/gpt.h
+++ b/src/shared/gpt.h
@@ -62,6 +62,8 @@ int gpt_partition_label_valid(const char *s);
GptPartitionType gpt_partition_type_from_uuid(sd_id128_t id);
int gpt_partition_type_from_string(const char *s, GptPartitionType *ret);
+GptPartitionType gpt_partition_type_override_architecture(GptPartitionType type, Architecture arch);
+
const char *gpt_partition_type_mountpoint_nulstr(GptPartitionType type);
bool gpt_partition_type_knows_read_only(GptPartitionType type);