diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-04-04 12:55:12 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-04-04 15:50:48 +0200 |
commit | cc97a3a5e826a2281953b001436f9168bcdd22f6 (patch) | |
tree | 73fbdb845101d0e733fc185c99c2c9ca6ee55449 /src/shared/gpt.c | |
parent | update TODO (diff) | |
download | systemd-cc97a3a5e826a2281953b001436f9168bcdd22f6.tar.xz systemd-cc97a3a5e826a2281953b001436f9168bcdd22f6.zip |
gpt: introduce common implementation of type uuid search loop
Diffstat (limited to '')
-rw-r--r-- | src/shared/gpt.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/shared/gpt.c b/src/shared/gpt.c index cd57447b8a..88b32ac102 100644 --- a/src/shared/gpt.c +++ b/src/shared/gpt.c @@ -65,14 +65,25 @@ const GptPartitionType gpt_partition_type_table[] = { {} }; -const char *gpt_partition_type_uuid_to_string(sd_id128_t id) { +static const GptPartitionType *gpt_partition_type_find_by_uuid(sd_id128_t id) { + for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table) - 1; i++) if (sd_id128_equal(id, gpt_partition_type_table[i].uuid)) - return gpt_partition_type_table[i].name; + return gpt_partition_type_table + i; return NULL; } +const char *gpt_partition_type_uuid_to_string(sd_id128_t id) { + const GptPartitionType *pt; + + pt = gpt_partition_type_find_by_uuid(id); + if (!pt) + return NULL; + + return pt->name; +} + const char *gpt_partition_type_uuid_to_string_harder( sd_id128_t id, char buffer[static SD_ID128_UUID_STRING_MAX]) { @@ -102,11 +113,13 @@ int gpt_partition_type_uuid_from_string(const char *s, sd_id128_t *ret) { } Architecture gpt_partition_type_uuid_to_arch(sd_id128_t id) { - for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table) - 1; i++) - if (sd_id128_equal(id, gpt_partition_type_table[i].uuid)) - return gpt_partition_type_table[i].arch; + const GptPartitionType *pt; + + pt = gpt_partition_type_find_by_uuid(id); + if (!pt) + return _ARCHITECTURE_INVALID; - return _ARCHITECTURE_INVALID; + return pt->arch; } int gpt_partition_label_valid(const char *s) { @@ -120,9 +133,11 @@ int gpt_partition_label_valid(const char *s) { } static GptPartitionType gpt_partition_type_from_uuid(sd_id128_t id) { - for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table) - 1; i++) - if (sd_id128_equal(id, gpt_partition_type_table[i].uuid)) - return gpt_partition_type_table[i]; + const GptPartitionType *pt; + + pt = gpt_partition_type_find_by_uuid(id); + if (pt) + return *pt; return (GptPartitionType) { .uuid = id, .arch = _ARCHITECTURE_INVALID }; } |