diff --git a/man/rules/meson.build b/man/rules/meson.build
index 7ef26cb2c6..05b087db3e 100644
--- a/man/rules/meson.build
+++ b/man/rules/meson.build
@@ -119,7 +119,8 @@ manpages = [
['sd-hwdb', '3', [], ''],
['sd-id128',
'3',
- ['SD_ID128_CONST_STR',
+ ['SD_ID128_ALLF',
+ 'SD_ID128_CONST_STR',
'SD_ID128_FORMAT_STR',
'SD_ID128_FORMAT_VAL',
'SD_ID128_MAKE',
@@ -127,6 +128,10 @@ manpages = [
'SD_ID128_NULL',
'SD_ID128_UUID_FORMAT_STR',
'sd_id128_equal',
+ 'sd_id128_in_set',
+ 'sd_id128_in_set_sentinel',
+ 'sd_id128_in_setv',
+ 'sd_id128_is_allf',
'sd_id128_is_null',
'sd_id128_t'],
''],
diff --git a/man/sd-id128.xml b/man/sd-id128.xml
index 40a3cc59ae..1890f6d6a5 100644
--- a/man/sd-id128.xml
+++ b/man/sd-id128.xml
@@ -18,16 +18,21 @@
sd-id128
- sd_id128_t
+ SD_ID128_ALLF
+ SD_ID128_CONST_STR
+ SD_ID128_FORMAT_STR
+ SD_ID128_FORMAT_VAL
SD_ID128_MAKE
SD_ID128_MAKE_STR
SD_ID128_NULL
- SD_ID128_CONST_STR
- SD_ID128_FORMAT_STR
SD_ID128_UUID_FORMAT_STR
- SD_ID128_FORMAT_VAL
sd_id128_equal
+ sd_id128_in_set
+ sd_id128_in_set_sentinel
+ sd_id128_in_setv
+ sd_id128_is_allf
sd_id128_is_null
+ sd_id128_t
APIs for processing 128-bit IDs
@@ -65,8 +70,8 @@
union type:
typedef union sd_id128 {
- uint8_t bytes[16];
- uint64_t qwords[2];
+ uint8_t bytes[16];
+ uint64_t qwords[2];
} sd_id128_t;
This union type allows accessing the 128-bit ID as 16
@@ -85,7 +90,7 @@
#define SD_MESSAGE_COREDUMP SD_ID128_MAKE(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1)
- SD_ID128_NULL may be used to refer to the 128bit ID consisting of only
+ SD_ID128_NULL may be used to refer to the 128-bit ID consisting of only
NUL bytes.
SD_ID128_MAKE_STR() is similar to SD_ID128_MAKE(), but creates a
@@ -95,7 +100,7 @@
#define SD_MESSAGE_COREDUMP_STR SD_ID128_MAKE_STR(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1)
int main(int argc, char **argv) {
- puts("Match for coredumps: MESSAGE_ID=" SD_MESSAGE_COREDUMP_STR);
+ puts("Match for coredumps: MESSAGE_ID=" SD_MESSAGE_COREDUMP_STR);
}
@@ -104,7 +109,7 @@ int main(int argc, char **argv) {
following example code will output the string
"fc2e22bc6ee647b6b90729ab34a250b1":
int main(int argc, char *argv[]) {
- puts("Match for coredumps: %s", SD_ID128_CONST_STR(SD_MESSAGE_COREDUMP));
+ puts("Match for coredumps: %s", SD_ID128_CONST_STR(SD_MESSAGE_COREDUMP));
}
SD_ID128_FORMAT_STR and SD_ID128_FORMAT_VAL() may
@@ -113,10 +118,10 @@ int main(int argc, char **argv) {
format string, as shown in the following example:
int main(int argc, char *argv[]) {
- sd_id128_t id;
- id = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
- printf("The ID encoded in this C file is " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(id));
- return 0;
+ sd_id128_t id;
+ id = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
+ printf("The ID encoded in this C file is " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(id));
+ return 0;
}
SD_ID128_UUID_FORMAT_STR is similar to
@@ -127,21 +132,50 @@ int main(int argc, char **argv) {
Use sd_id128_equal() to compare two 128-bit IDs:
int main(int argc, char *argv[]) {
- sd_id128_t a, b, c;
- a = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
- b = SD_ID128_MAKE(f2,28,88,9c,5f,09,44,15,9d,d7,04,77,58,cb,e7,3e);
- c = a;
- assert(sd_id128_equal(a, c));
- assert(!sd_id128_equal(a, b));
- return 0;
+ sd_id128_t a, b, c;
+ a = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
+ b = SD_ID128_MAKE(f2,28,88,9c,5f,09,44,15,9d,d7,04,77,58,cb,e7,3e);
+ c = a;
+ assert(sd_id128_equal(a, c));
+ assert(!sd_id128_equal(a, b));
+ return 0;
}
- Use sd_id128_is_null() to check if an 128bit ID consists of only
+ Use sd_id128_is_null() to check if an 128-bit ID consists of only
NUL bytes:
+ assert(sd_id128_is_null(SD_ID128_NULL));
+
+ Similarly, use sd_id128_is_allf() to check if an 128-bit ID consists of only
+ 0xFF bytes (all bits on):
+
+ assert(sd_id128_is_allf(SD_ID128_ALLF));
+
+ For convenience, sd_id128_in_set() takes a list of IDs and
+ returns true if any are equal to the first argument:
+
int main(int argc, char *argv[]) {
- assert(sd_id128_is_null(SD_ID128_NULL));
-}
+ sd_id12_t a = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
+ assert(sd_id128_in_set(a, a));
+ assert(sd_id128_in_set(a, a, a));
+ assert(!sd_id128_in_set(a));
+ assert(!sd_id128_in_set(a,
+ SD_ID128_MAKE(f2,28,88,9c,5f,09,44,15,9d,d7,04,77,58,cb,e7,3e)
+ SD_ID128_MAKE(2f,88,28,5f,9c,44,09,9d,d7,15,77,04,bc,85,7e,e3)
+ SD_ID128_ALLF));
+ return 0;
+}
+
+
+ sd_id128_in_set() is defined as a macro over
+ sd_id128_in_set_sentinel(), adding the SD_ID128_NULL
+ sentinel. Since sd_id128_in_set_sentinel() uses SD_ID128_NULL
+ as the sentinel, SD_ID128_NULL cannot be otherwise placed in the argument list.
+
+
+ sd_id128_in_setv() is similar to
+ sd_id128_in_set_sentinel(), but takes a struct varargs
+ argument.
Note that new, randomized IDs may be generated with
systemd-id1281's
diff --git a/src/partition/repart.c b/src/partition/repart.c
index 356fd9152c..3e88d38205 100644
--- a/src/partition/repart.c
+++ b/src/partition/repart.c
@@ -3115,9 +3115,8 @@ static int partition_acquire_uuid(Context *context, Partition *p, sd_id128_t *re
if (p == q)
continue;
- if (sd_id128_equal(q->current_uuid, result.id) ||
- sd_id128_equal(q->new_uuid, result.id)) {
- log_warning("Partition UUID calculated from seed for partition %" PRIu64 " exists already, reverting to randomized UUID.", p->partno);
+ if (sd_id128_in_set(result.id, q->current_uuid, q->new_uuid)) {
+ log_warning("Partition UUID calculated from seed for partition %" PRIu64 " already used, reverting to randomized UUID.", p->partno);
r = sd_id128_randomize(&result.id);
if (r < 0)
diff --git a/src/shared/gpt.c b/src/shared/gpt.c
index 846b2fe48f..6b1a576138 100644
--- a/src/shared/gpt.c
+++ b/src/shared/gpt.c
@@ -108,52 +108,57 @@ int gpt_partition_label_valid(const char *s) {
}
bool gpt_partition_type_is_root(sd_id128_t id) {
- return sd_id128_equal(id, GPT_ROOT_X86) ||
- sd_id128_equal(id, GPT_ROOT_X86_64) ||
- sd_id128_equal(id, GPT_ROOT_ARM) ||
- sd_id128_equal(id, GPT_ROOT_ARM_64) ||
- sd_id128_equal(id, GPT_ROOT_IA64) ||
- sd_id128_equal(id, GPT_ROOT_RISCV32) ||
- sd_id128_equal(id, GPT_ROOT_RISCV64);
+ return sd_id128_in_set(id,
+ GPT_ROOT_X86,
+ GPT_ROOT_X86_64,
+ GPT_ROOT_ARM,
+ GPT_ROOT_ARM_64,
+ GPT_ROOT_IA64,
+ GPT_ROOT_RISCV32,
+ GPT_ROOT_RISCV64);
}
bool gpt_partition_type_is_root_verity(sd_id128_t id) {
- return sd_id128_equal(id, GPT_ROOT_X86_VERITY) ||
- sd_id128_equal(id, GPT_ROOT_X86_64_VERITY) ||
- sd_id128_equal(id, GPT_ROOT_ARM_VERITY) ||
- sd_id128_equal(id, GPT_ROOT_ARM_64_VERITY) ||
- sd_id128_equal(id, GPT_ROOT_IA64_VERITY) ||
- sd_id128_equal(id, GPT_ROOT_RISCV32_VERITY) ||
- sd_id128_equal(id, GPT_ROOT_RISCV64_VERITY);
+ return sd_id128_in_set(id,
+ GPT_ROOT_X86_VERITY,
+ GPT_ROOT_X86_64_VERITY,
+ GPT_ROOT_ARM_VERITY,
+ GPT_ROOT_ARM_64_VERITY,
+ GPT_ROOT_IA64_VERITY,
+ GPT_ROOT_RISCV32_VERITY,
+ GPT_ROOT_RISCV64_VERITY);
}
bool gpt_partition_type_is_usr(sd_id128_t id) {
- return sd_id128_equal(id, GPT_USR_X86) ||
- sd_id128_equal(id, GPT_USR_X86_64) ||
- sd_id128_equal(id, GPT_USR_ARM) ||
- sd_id128_equal(id, GPT_USR_ARM_64) ||
- sd_id128_equal(id, GPT_USR_IA64) ||
- sd_id128_equal(id, GPT_USR_RISCV32) ||
- sd_id128_equal(id, GPT_USR_RISCV64);
+ return sd_id128_in_set(id,
+ GPT_USR_X86,
+ GPT_USR_X86_64,
+ GPT_USR_ARM,
+ GPT_USR_ARM_64,
+ GPT_USR_IA64,
+ GPT_USR_RISCV32,
+ GPT_USR_RISCV64);
}
bool gpt_partition_type_is_usr_verity(sd_id128_t id) {
- return sd_id128_equal(id, GPT_USR_X86_VERITY) ||
- sd_id128_equal(id, GPT_USR_X86_64_VERITY) ||
- sd_id128_equal(id, GPT_USR_ARM_VERITY) ||
- sd_id128_equal(id, GPT_USR_ARM_64_VERITY) ||
- sd_id128_equal(id, GPT_USR_IA64_VERITY) ||
- sd_id128_equal(id, GPT_USR_RISCV32_VERITY) ||
- sd_id128_equal(id, GPT_USR_RISCV64_VERITY);
+ return sd_id128_in_set(id,
+ GPT_USR_X86_VERITY,
+ GPT_USR_X86_64_VERITY,
+ GPT_USR_ARM_VERITY,
+ GPT_USR_ARM_64_VERITY,
+ GPT_USR_IA64_VERITY,
+ GPT_USR_RISCV32_VERITY,
+ GPT_USR_RISCV64_VERITY);
}
bool gpt_partition_type_knows_read_only(sd_id128_t id) {
return gpt_partition_type_is_root(id) ||
gpt_partition_type_is_usr(id) ||
- sd_id128_equal(id, GPT_HOME) ||
- sd_id128_equal(id, GPT_SRV) ||
- sd_id128_equal(id, GPT_VAR) ||
- sd_id128_equal(id, GPT_TMP) ||
+ sd_id128_in_set(id,
+ GPT_HOME,
+ GPT_SRV,
+ GPT_VAR,
+ GPT_TMP) ||
gpt_partition_type_is_root_verity(id) || /* pretty much implied, but let's set the bit to make things really clear */
gpt_partition_type_is_usr_verity(id); /* ditto */
}
diff --git a/src/systemd/sd-id128.h b/src/systemd/sd-id128.h
index 02aa318a06..ab209c8c7d 100644
--- a/src/systemd/sd-id128.h
+++ b/src/systemd/sd-id128.h
@@ -18,6 +18,7 @@
***/
#include
+#include
#include
#include "_sd-common.h"
@@ -119,6 +120,32 @@ _sd_pure_ static __inline__ int sd_id128_is_allf(sd_id128_t a) {
#define SD_ID128_NULL ((const sd_id128_t) { .qwords = { 0, 0 }})
#define SD_ID128_ALLF ((const sd_id128_t) { .qwords = { UINT64_C(0xFFFFFFFFFFFFFFFF), UINT64_C(0xFFFFFFFFFFFFFFFF) }})
+_sd_pure_ static __inline__ int sd_id128_in_setv(sd_id128_t a, va_list ap) {
+ for (;;) {
+ sd_id128_t b = va_arg(ap, sd_id128_t);
+
+ if (sd_id128_is_null(b))
+ return 0;
+
+ if (sd_id128_equal(a, b))
+ return 1;
+ }
+}
+
+_sd_pure_ static __inline__ int sd_id128_in_set_sentinel(sd_id128_t a, ...) {
+ va_list ap;
+ int r;
+
+ va_start(ap, a);
+ r = sd_id128_in_setv(a, ap);
+ va_end(ap);
+
+ return r;
+}
+
+#define sd_id128_in_set(a, ...) \
+ sd_id128_in_set_sentinel(a, ##__VA_ARGS__, SD_ID128_NULL)
+
_SD_END_DECLARATIONS;
#endif
diff --git a/src/test/test-id128.c b/src/test/test-id128.c
index a0649b9deb..a61b35b9a3 100644
--- a/src/test/test-id128.c
+++ b/src/test/test-id128.c
@@ -31,6 +31,13 @@ int main(int argc, char *argv[]) {
assert_se(sd_id128_from_string(t, &id2) == 0);
assert_se(sd_id128_equal(id, id2));
+ assert_se(sd_id128_in_set(id, id));
+ assert_se(sd_id128_in_set(id, id2));
+ assert_se(sd_id128_in_set(id, id2, id));
+ assert_se(sd_id128_in_set(id, ID128_WALDI, id));
+ assert_se(!sd_id128_in_set(id));
+ assert_se(!sd_id128_in_set(id, ID128_WALDI));
+ assert_se(!sd_id128_in_set(id, ID128_WALDI, ID128_WALDI));
if (sd_booted() > 0) {
assert_se(sd_id128_get_machine(&id) == 0);