summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-02-14 14:52:02 +0100
committerLennart Poettering <lennart@poettering.net>2022-02-14 15:13:23 +0100
commitb74163607b4e513288d38b7f16e230f5a61400c0 (patch)
tree9a48311cacb1cd135cb40586a24411810ef20672
parentMerge pull request #22505 from mrc0mmand/more-coverage-tweaks (diff)
downloadsystemd-b74163607b4e513288d38b7f16e230f5a61400c0.tar.xz
systemd-b74163607b4e513288d38b7f16e230f5a61400c0.zip
sd128: export sd_id128_to_uuid_string()
We expose various other forms of UUID helpers already, i.e. SD_ID128_UUID_FORMAT_STR and SD_ID128_MAKE_UUID_STR(), and we parse UUIDs, hence add a high-level helper for formatting UUIDs too. This doesn't add any new code, it just moves some helpers id128-util.[ch] → sd-id128.[ch], to make them public.
-rw-r--r--man/rules/meson.build7
-rw-r--r--man/sd_id128_to_string.xml20
-rw-r--r--src/home/homework-luks.c6
-rw-r--r--src/home/user-record-util.c6
-rw-r--r--src/libsystemd/libsystemd.sym5
-rw-r--r--src/libsystemd/sd-device/sd-device.c2
-rw-r--r--src/libsystemd/sd-id128/id128-util.c35
-rw-r--r--src/libsystemd/sd-id128/id128-util.h6
-rw-r--r--src/libsystemd/sd-id128/sd-id128.c28
-rw-r--r--src/nspawn/nspawn.c2
-rw-r--r--src/partition/repart.c22
-rw-r--r--src/shared/format-table.c6
-rw-r--r--src/shared/gpt.c4
-rw-r--r--src/shared/gpt.h2
-rw-r--r--src/shared/logs-show.c2
-rw-r--r--src/shared/mkfs-util.c4
-rw-r--r--src/shared/udev-util.c2
-rw-r--r--src/systemd/sd-id128.h3
-rw-r--r--src/test/test-id128.c6
-rw-r--r--src/veritysetup/veritysetup-generator.c4
20 files changed, 96 insertions, 76 deletions
diff --git a/man/rules/meson.build b/man/rules/meson.build
index 7200ecf681..793010f75f 100644
--- a/man/rules/meson.build
+++ b/man/rules/meson.build
@@ -641,7 +641,12 @@ manpages = [
['sd_id128_randomize', '3', [], ''],
['sd_id128_to_string',
'3',
- ['SD_ID128_STRING_MAX', 'SD_ID128_TO_STRING', 'sd_id128_from_string'],
+ ['SD_ID128_STRING_MAX',
+ 'SD_ID128_TO_STRING',
+ 'SD_ID128_TO_UUID_STRING',
+ 'SD_ID128_UUID_STRING_MAX',
+ 'sd_id128_from_string',
+ 'sd_id128_to_uuid_string'],
''],
['sd_is_fifo',
'3',
diff --git a/man/sd_id128_to_string.xml b/man/sd_id128_to_string.xml
index db64bc018d..e0338bae85 100644
--- a/man/sd_id128_to_string.xml
+++ b/man/sd_id128_to_string.xml
@@ -18,8 +18,11 @@
<refnamediv>
<refname>sd_id128_to_string</refname>
<refname>SD_ID128_TO_STRING</refname>
- <refname>sd_id128_from_string</refname>
<refname>SD_ID128_STRING_MAX</refname>
+ <refname>sd_id128_to_uuid_string</refname>
+ <refname>SD_ID128_TO_UUID_STRING</refname>
+ <refname>SD_ID128_UUID_STRING_MAX</refname>
+ <refname>sd_id128_from_string</refname>
<refpurpose>Format or parse 128-bit IDs as strings</refpurpose>
</refnamediv>
@@ -29,14 +32,23 @@
<funcsynopsisinfo>#define SD_ID128_STRING_MAX 33U</funcsynopsisinfo>
+ <funcsynopsisinfo>#define SD_ID128_UUID_STRING_MAX 37U</funcsynopsisinfo>
+
<funcsynopsisinfo>#define SD_ID128_TO_STRING(id) …</funcsynopsisinfo>
+ <funcsynopsisinfo>#define SD_ID128_TO_UUID_STRING(id) …</funcsynopsisinfo>
+
<funcprototype>
<funcdef>char *<function>sd_id128_to_string</function></funcdef>
<paramdef>sd_id128_t <parameter>id</parameter>, char <parameter>s</parameter>[static SD_ID128_STRING_MAX]</paramdef>
</funcprototype>
<funcprototype>
+ <funcdef>char *<function>sd_id128_uuid_string</function></funcdef>
+ <paramdef>sd_id128_t <parameter>id</parameter>, char <parameter>s</parameter>[static SD_ID128_UUID_STRING_MAX]</paramdef>
+ </funcprototype>
+
+ <funcprototype>
<funcdef>int <function>sd_id128_from_string</function></funcdef>
<paramdef>const char *<parameter>s</parameter>, sd_id128_t *<parameter>ret</parameter></paramdef>
</funcprototype>
@@ -58,6 +70,10 @@
which remains valid until the end of the current code block. This is usually the simplest way to acquire
a string representation of a 128-bit ID in a buffer that is valid in the current code block.</para>
+ <para><function>sd_id128_to_uuid_string()</function> and <function>SD_ID128_TO_UUID_STRING()</function>
+ are similar to these two functions/macros, but format the 128bit values as RFC4122 UUIDs, i.e. a series
+ of 36 lowercase hexadeciaml digits and dashes, terminated by a <constant>NUL</constant> byte.</para>
+
<para><function>sd_id128_from_string()</function> implements the reverse operation: it takes a 33
character string with 32 hexadecimal digits (either lowercase or uppercase, terminated by
<constant>NUL</constant>) and parses them back into a 128-bit ID returned in
@@ -65,7 +81,7 @@
ID formatted as RFC UUID. If <parameter>ret</parameter> is passed as <constant>NULL</constant> the
function will validate the passed ID string, but not actually return it in parsed form.</para>
- <para>Note that when parsing 37 character UUIDs this is done strictly in Big Endian byte order,
+ <para>Note that when formatting and parsing 36 character UUIDs this is done strictly in Big Endian byte order,
i.e. according to <ulink url="https://tools.ietf.org/html/rfc4122">RFC4122</ulink> Variant 1 rules, even
if the UUID encodes a different variant. This matches behaviour in various other Linux userspace
tools. It's probably wise to avoid UUIDs of other variant types.</para>
diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c
index 8063206358..b400d7307d 100644
--- a/src/home/homework-luks.c
+++ b/src/home/homework-luks.c
@@ -1762,7 +1762,7 @@ static int luks_format(
CRYPT_LUKS2,
user_record_luks_cipher(hr),
user_record_luks_cipher_mode(hr),
- ID128_TO_UUID_STRING(uuid),
+ SD_ID128_TO_UUID_STRING(uuid),
volume_key,
volume_key_size,
&(struct crypt_params_luks2) {
@@ -1917,7 +1917,7 @@ static int make_partition_table(
if (r < 0)
return log_error_errno(r, "Failed to set partition name: %m");
- r = fdisk_partition_set_uuid(p, ID128_TO_UUID_STRING(uuid));
+ r = fdisk_partition_set_uuid(p, SD_ID128_TO_UUID_STRING(uuid));
if (r < 0)
return log_error_errno(r, "Failed to set partition UUID: %m");
@@ -2745,7 +2745,7 @@ static int ask_cb(struct fdisk_context *c, struct fdisk_ask *ask, void *userdata
if (!result)
return log_oom();
- fdisk_ask_string_set_result(ask, id128_to_uuid_string(*(sd_id128_t*) userdata, result));
+ fdisk_ask_string_set_result(ask, sd_id128_to_uuid_string(*(sd_id128_t*) userdata, result));
break;
default:
diff --git a/src/home/user-record-util.c b/src/home/user-record-util.c
index f4578783f3..6a892d45b5 100644
--- a/src/home/user-record-util.c
+++ b/src/home/user-record-util.c
@@ -332,9 +332,9 @@ int user_record_add_binding(
r = json_build(&new_binding_entry,
JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_CONDITION(!!image_path, "imagePath", JSON_BUILD_STRING(image_path)),
- JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(partition_uuid), "partitionUuid", JSON_BUILD_STRING(ID128_TO_UUID_STRING(partition_uuid))),
- JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(luks_uuid), "luksUuid", JSON_BUILD_STRING(ID128_TO_UUID_STRING(luks_uuid))),
- JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(fs_uuid), "fileSystemUuid", JSON_BUILD_STRING(ID128_TO_UUID_STRING(fs_uuid))),
+ JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(partition_uuid), "partitionUuid", JSON_BUILD_STRING(SD_ID128_TO_UUID_STRING(partition_uuid))),
+ JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(luks_uuid), "luksUuid", JSON_BUILD_STRING(SD_ID128_TO_UUID_STRING(luks_uuid))),
+ JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(fs_uuid), "fileSystemUuid", JSON_BUILD_STRING(SD_ID128_TO_UUID_STRING(fs_uuid))),
JSON_BUILD_PAIR_CONDITION(!!luks_cipher, "luksCipher", JSON_BUILD_STRING(luks_cipher)),
JSON_BUILD_PAIR_CONDITION(!!luks_cipher_mode, "luksCipherMode", JSON_BUILD_STRING(luks_cipher_mode)),
JSON_BUILD_PAIR_CONDITION(luks_volume_key_size != UINT64_MAX, "luksVolumeKeySize", JSON_BUILD_UNSIGNED(luks_volume_key_size)),
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
index 2178668d11..2773d28b4b 100644
--- a/src/libsystemd/libsystemd.sym
+++ b/src/libsystemd/libsystemd.sym
@@ -769,3 +769,8 @@ global:
sd_event_add_inotify_fd;
sd_event_source_set_ratelimit_expire_callback;
} LIBSYSTEMD_249;
+
+LIBSYSTEMD_251 {
+global:
+ sd_id128_to_uuid_string;
+} LIBSYSTEMD_250;
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
index 27c91ea724..03fd70e572 100644
--- a/src/libsystemd/sd-device/sd-device.c
+++ b/src/libsystemd/sd-device/sd-device.c
@@ -2194,7 +2194,7 @@ _public_ int sd_device_trigger_with_uuid(
if (r < 0)
return r;
- j = strjoina(s, " ", ID128_TO_UUID_STRING(u));
+ j = strjoina(s, " ", SD_ID128_TO_UUID_STRING(u));
r = sd_device_set_sysattr_value(device, "uevent", j);
if (r < 0)
diff --git a/src/libsystemd/sd-id128/id128-util.c b/src/libsystemd/sd-id128/id128-util.c
index 7c66d1c2db..1068721dd4 100644
--- a/src/libsystemd/sd-id128/id128-util.c
+++ b/src/libsystemd/sd-id128/id128-util.c
@@ -12,29 +12,6 @@
#include "string-util.h"
#include "sync-util.h"
-char *id128_to_uuid_string(sd_id128_t id, char s[static ID128_UUID_STRING_MAX]) {
- unsigned n, k = 0;
-
- assert(s);
-
- /* Similar to sd_id128_to_string() but formats the result as UUID instead of plain hex chars */
-
- for (n = 0; n < 16; n++) {
-
- if (IN_SET(n, 4, 6, 8, 10))
- s[k++] = '-';
-
- s[k++] = hexchar(id.bytes[n] >> 4);
- s[k++] = hexchar(id.bytes[n] & 0xF);
- }
-
- assert(k == 36);
-
- s[k] = 0;
-
- return s;
-}
-
bool id128_is_valid(const char *s) {
size_t i, l;
@@ -153,13 +130,13 @@ int id128_write_fd(int fd, Id128Format f, sd_id128_t id, bool do_sync) {
assert(f < _ID128_FORMAT_MAX);
if (f != ID128_UUID) {
- sd_id128_to_string(id, buffer);
- buffer[32] = '\n';
- sz = 33;
+ assert_se(sd_id128_to_string(id, buffer));
+ buffer[SD_ID128_STRING_MAX - 1] = '\n';
+ sz = SD_ID128_STRING_MAX;
} else {
- id128_to_uuid_string(id, buffer);
- buffer[36] = '\n';
- sz = 37;
+ assert_se(sd_id128_to_uuid_string(id, buffer));
+ buffer[SD_ID128_UUID_STRING_MAX - 1] = '\n';
+ sz = SD_ID128_UUID_STRING_MAX;
}
r = loop_write(fd, buffer, sz, false);
diff --git a/src/libsystemd/sd-id128/id128-util.h b/src/libsystemd/sd-id128/id128-util.h
index b7327a1f07..17b180c10c 100644
--- a/src/libsystemd/sd-id128/id128-util.h
+++ b/src/libsystemd/sd-id128/id128-util.h
@@ -8,12 +8,6 @@
#include "hash-funcs.h"
#include "macro.h"
-#define ID128_UUID_STRING_MAX 37
-
-char *id128_to_uuid_string(sd_id128_t id, char s[static ID128_UUID_STRING_MAX]);
-
-#define ID128_TO_UUID_STRING(id) id128_to_uuid_string((id), (char[ID128_UUID_STRING_MAX]) {})
-
bool id128_is_valid(const char *s) _pure_;
typedef enum Id128Format {
diff --git a/src/libsystemd/sd-id128/sd-id128.c b/src/libsystemd/sd-id128/sd-id128.c
index 992b19130e..46269c2cc2 100644
--- a/src/libsystemd/sd-id128/sd-id128.c
+++ b/src/libsystemd/sd-id128/sd-id128.c
@@ -19,16 +19,36 @@
#include "util.h"
_public_ char *sd_id128_to_string(sd_id128_t id, char s[_SD_ARRAY_STATIC SD_ID128_STRING_MAX]) {
- unsigned n;
-
assert_return(s, NULL);
- for (n = 0; n < 16; n++) {
+ for (size_t n = 0; n < 16; n++) {
s[n*2] = hexchar(id.bytes[n] >> 4);
s[n*2+1] = hexchar(id.bytes[n] & 0xF);
}
- s[32] = 0;
+ s[SD_ID128_STRING_MAX-1] = 0;
+
+ return s;
+}
+
+_public_ char *sd_id128_to_uuid_string(sd_id128_t id, char s[_SD_ARRAY_STATIC SD_ID128_UUID_STRING_MAX]) {
+ size_t k = 0;
+
+ assert_return(s, NULL);
+
+ /* Similar to sd_id128_to_string() but formats the result as UUID instead of plain hex chars */
+
+ for (size_t n = 0; n < 16; n++) {
+
+ if (IN_SET(n, 4, 6, 8, 10))
+ s[k++] = '-';
+
+ s[k++] = hexchar(id.bytes[n] >> 4);
+ s[k++] = hexchar(id.bytes[n] & 0xF);
+ }
+
+ assert(k == SD_ID128_UUID_STRING_MAX - 1);
+ s[k] = 0;
return s;
}
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 8f17ab8810..144e58ae89 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -3453,7 +3453,7 @@ static int inner_child(
assert(!sd_id128_is_null(arg_uuid));
- if (asprintf(envp + n_env++, "container_uuid=%s", ID128_TO_UUID_STRING(arg_uuid)) < 0)
+ if (asprintf(envp + n_env++, "container_uuid=%s", SD_ID128_TO_UUID_STRING(arg_uuid)) < 0)
return log_oom();
if (fdset_size(fds) > 0) {
diff --git a/src/partition/repart.c b/src/partition/repart.c
index 0862a37a8d..abdf947dbf 100644
--- a/src/partition/repart.c
+++ b/src/partition/repart.c
@@ -1512,11 +1512,11 @@ static int fdisk_ask_cb(struct fdisk_context *c, struct fdisk_ask *ask, void *da
if (fdisk_ask_get_type(ask) != FDISK_ASKTYPE_STRING)
return -EINVAL;
- ids = new(char, ID128_UUID_STRING_MAX);
+ ids = new(char, SD_ID128_UUID_STRING_MAX);
if (!ids)
return -ENOMEM;
- r = fdisk_ask_string_set_result(ask, id128_to_uuid_string(*(sd_id128_t*) data, ids));
+ r = fdisk_ask_string_set_result(ask, sd_id128_to_uuid_string(*(sd_id128_t*) data, ids));
if (r < 0)
return r;
@@ -2030,7 +2030,7 @@ static int context_dump_partitions(Context *context, const char *node) {
LIST_FOREACH(partitions, p, context->partitions) {
_cleanup_free_ char *size_change = NULL, *padding_change = NULL, *partname = NULL;
- char uuid_buffer[ID128_UUID_STRING_MAX];
+ char uuid_buffer[SD_ID128_UUID_STRING_MAX];
const char *label, *activity = NULL;
if (p->dropped)
@@ -2176,7 +2176,7 @@ static int partition_hint(const Partition *p, const char *node, char **ret) {
else
id = p->type_uuid;
- buf = strdup(ID128_TO_UUID_STRING(id));
+ buf = strdup(SD_ID128_TO_UUID_STRING(id));
done:
if (!buf)
@@ -2624,7 +2624,7 @@ static int partition_encrypt(
CRYPT_LUKS2,
"aes",
"xts-plain64",
- ID128_TO_UUID_STRING(uuid),
+ SD_ID128_TO_UUID_STRING(uuid),
volume_key,
volume_key_size,
&(struct crypt_params_luks2) {
@@ -3304,7 +3304,7 @@ static uint64_t partition_merge_flags(Partition *p) {
if (gpt_partition_type_knows_no_auto(p->type_uuid))
SET_FLAG(f, GPT_FLAG_NO_AUTO, p->no_auto);
else {
- char buffer[ID128_UUID_STRING_MAX];
+ char buffer[SD_ID128_UUID_STRING_MAX];
log_warning("Configured NoAuto=%s for partition type '%s' that doesn't support it, ignoring.",
yes_no(p->no_auto),
gpt_partition_type_uuid_to_string_harder(p->type_uuid, buffer));
@@ -3315,7 +3315,7 @@ static uint64_t partition_merge_flags(Partition *p) {
if (gpt_partition_type_knows_read_only(p->type_uuid))
SET_FLAG(f, GPT_FLAG_READ_ONLY, p->read_only);
else {
- char buffer[ID128_UUID_STRING_MAX];
+ char buffer[SD_ID128_UUID_STRING_MAX];
log_warning("Configured ReadOnly=%s for partition type '%s' that doesn't support it, ignoring.",
yes_no(p->read_only),
gpt_partition_type_uuid_to_string_harder(p->type_uuid, buffer));
@@ -3326,7 +3326,7 @@ static uint64_t partition_merge_flags(Partition *p) {
if (gpt_partition_type_knows_growfs(p->type_uuid))
SET_FLAG(f, GPT_FLAG_GROWFS, p->growfs);
else {
- char buffer[ID128_UUID_STRING_MAX];
+ char buffer[SD_ID128_UUID_STRING_MAX];
log_warning("Configured GrowFileSystem=%s for partition type '%s' that doesn't support it, ignoring.",
yes_no(p->growfs),
gpt_partition_type_uuid_to_string_harder(p->type_uuid, buffer));
@@ -3374,7 +3374,7 @@ static int context_mangle_partitions(Context *context) {
if (!sd_id128_equal(p->new_uuid, p->current_uuid)) {
assert(!sd_id128_is_null(p->new_uuid));
- r = fdisk_partition_set_uuid(p->current_partition, ID128_TO_UUID_STRING(p->new_uuid));
+ r = fdisk_partition_set_uuid(p->current_partition, SD_ID128_TO_UUID_STRING(p->new_uuid));
if (r < 0)
return log_error_errno(r, "Failed to set partition UUID: %m");
@@ -3412,7 +3412,7 @@ static int context_mangle_partitions(Context *context) {
if (!t)
return log_oom();
- r = fdisk_parttype_set_typestr(t, ID128_TO_UUID_STRING(p->type_uuid));
+ r = fdisk_parttype_set_typestr(t, SD_ID128_TO_UUID_STRING(p->type_uuid));
if (r < 0)
return log_error_errno(r, "Failed to initialize partition type: %m");
@@ -3440,7 +3440,7 @@ static int context_mangle_partitions(Context *context) {
if (r < 0)
return log_error_errno(r, "Failed to set partition number: %m");
- r = fdisk_partition_set_uuid(q, ID128_TO_UUID_STRING(p->new_uuid));
+ r = fdisk_partition_set_uuid(q, SD_ID128_TO_UUID_STRING(p->new_uuid));
if (r < 0)
return log_error_errno(r, "Failed to set partition UUID: %m");
diff --git a/src/shared/format-table.c b/src/shared/format-table.c
index b95680b365..44b736d1fd 100644
--- a/src/shared/format-table.c
+++ b/src/shared/format-table.c
@@ -1699,11 +1699,11 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
case TABLE_UUID: {
char *p;
- p = new(char, ID128_UUID_STRING_MAX);
+ p = new(char, SD_ID128_UUID_STRING_MAX);
if (!p)
return NULL;
- d->formatted = id128_to_uuid_string(d->id128, p);
+ d->formatted = sd_id128_to_uuid_string(d->id128, p);
break;
}
@@ -2562,7 +2562,7 @@ static int table_data_to_json(TableData *d, JsonVariant **ret) {
return json_variant_new_string(ret, SD_ID128_TO_STRING(d->id128));
case TABLE_UUID:
- return json_variant_new_string(ret, ID128_TO_UUID_STRING(d->id128));
+ return json_variant_new_string(ret, SD_ID128_TO_UUID_STRING(d->id128));
case TABLE_UID:
if (!uid_is_valid(d->uid))
diff --git a/src/shared/gpt.c b/src/shared/gpt.c
index c01a57a5fb..cd57447b8a 100644
--- a/src/shared/gpt.c
+++ b/src/shared/gpt.c
@@ -75,7 +75,7 @@ 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]) {
+ char buffer[static SD_ID128_UUID_STRING_MAX]) {
const char *s;
@@ -85,7 +85,7 @@ const char *gpt_partition_type_uuid_to_string_harder(
if (s)
return s;
- return id128_to_uuid_string(id, buffer);
+ return sd_id128_to_uuid_string(id, buffer);
}
int gpt_partition_type_uuid_from_string(const char *s, sd_id128_t *ret) {
diff --git a/src/shared/gpt.h b/src/shared/gpt.h
index 00c829ca79..9604d6e86b 100644
--- a/src/shared/gpt.h
+++ b/src/shared/gpt.h
@@ -286,7 +286,7 @@
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]);
+ char buffer[static SD_ID128_UUID_STRING_MAX]);
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);
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index cf83eb6bca..acc1dc9b95 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -1510,7 +1510,7 @@ int add_matches_for_user_unit(sd_journal *j, const char *unit, uid_t uid) {
static int get_boot_id_for_machine(const char *machine, sd_id128_t *boot_id) {
_cleanup_close_pair_ int pair[2] = { -1, -1 };
_cleanup_close_ int pidnsfd = -1, mntnsfd = -1, rootfd = -1;
- char buf[ID128_UUID_STRING_MAX];
+ char buf[SD_ID128_UUID_STRING_MAX];
pid_t pid, child;
ssize_t k;
int r;
diff --git a/src/shared/mkfs-util.c b/src/shared/mkfs-util.c
index 061a2c2ef7..accd64f9e8 100644
--- a/src/shared/mkfs-util.c
+++ b/src/shared/mkfs-util.c
@@ -94,7 +94,7 @@ int make_filesystem(
bool discard) {
_cleanup_free_ char *mkfs = NULL, *mangled_label = NULL;
- char vol_id[CONST_MAX(ID128_UUID_STRING_MAX, 8 + 1)] = {};
+ char vol_id[CONST_MAX(SD_ID128_UUID_STRING_MAX, 8U + 1U)] = {};
int r;
assert(node);
@@ -144,7 +144,7 @@ int make_filesystem(
}
if (isempty(vol_id))
- id128_to_uuid_string(uuid, vol_id);
+ assert_se(sd_id128_to_uuid_string(uuid, vol_id));
r = safe_fork("(mkfs)", FORK_RESET_SIGNALS|FORK_RLIMIT_NOFILE_SAFE|FORK_DEATHSIG|FORK_LOG|FORK_WAIT|FORK_STDOUT_TO_STDERR, NULL);
if (r < 0)
diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c
index 32dfcdafc4..e2574b9af3 100644
--- a/src/shared/udev-util.c
+++ b/src/shared/udev-util.c
@@ -351,7 +351,7 @@ void log_device_uevent(sd_device *device, const char *str) {
strempty(str), isempty(str) ? "" : " ",
seqnum, strna(device_action_to_string(action)),
sd_id128_is_null(event_id) ? "" : ", UUID=",
- sd_id128_is_null(event_id) ? "" : id128_to_uuid_string(event_id, (char[ID128_UUID_STRING_MAX]){}));
+ sd_id128_is_null(event_id) ? "" : SD_ID128_TO_UUID_STRING(event_id));
}
int udev_rule_parse_value(char *str, char **ret_value, char **ret_endpos) {
diff --git a/src/systemd/sd-id128.h b/src/systemd/sd-id128.h
index e64f3200a3..f7d3244bb3 100644
--- a/src/systemd/sd-id128.h
+++ b/src/systemd/sd-id128.h
@@ -35,11 +35,14 @@ union sd_id128 {
};
#define SD_ID128_STRING_MAX 33U
+#define SD_ID128_UUID_STRING_MAX 37U
char *sd_id128_to_string(sd_id128_t id, char s[_SD_ARRAY_STATIC SD_ID128_STRING_MAX]);
+char *sd_id128_to_uuid_string(sd_id128_t id, char s[_SD_ARRAY_STATIC SD_ID128_UUID_STRING_MAX]);
int sd_id128_from_string(const char *s, sd_id128_t *ret);
#define SD_ID128_TO_STRING(id) sd_id128_to_string((id), (char[SD_ID128_STRING_MAX]) {})
+#define SD_ID128_TO_UUID_STRING(id) sd_id128_to_uuid_string((id), (char[SD_ID128_UUID_STRING_MAX]) {})
int sd_id128_randomize(sd_id128_t *ret);
diff --git a/src/test/test-id128.c b/src/test/test-id128.c
index 33c4f1a5ea..5da7b0ec1a 100644
--- a/src/test/test-id128.c
+++ b/src/test/test-id128.c
@@ -21,7 +21,7 @@
TEST(id128) {
sd_id128_t id, id2;
- char t[SD_ID128_STRING_MAX], q[ID128_UUID_STRING_MAX];
+ char t[SD_ID128_STRING_MAX], q[SD_ID128_UUID_STRING_MAX];
_cleanup_free_ char *b = NULL;
_cleanup_close_ int fd = -1;
@@ -53,7 +53,7 @@ TEST(id128) {
printf("waldi2: %s\n", b);
assert_se(streq(t, b));
- printf("waldi3: %s\n", id128_to_uuid_string(ID128_WALDI, q));
+ printf("waldi3: %s\n", sd_id128_to_uuid_string(ID128_WALDI, q));
assert_se(streq(q, UUID_WALDI));
b = mfree(b);
@@ -136,7 +136,7 @@ TEST(id128) {
assert_se(ftruncate(fd, 0) >= 0);
assert_se(sd_id128_randomize(&id) >= 0);
- assert_se(write(fd, id128_to_uuid_string(id, q), 36) == 36);
+ assert_se(write(fd, sd_id128_to_uuid_string(id, q), 36) == 36);
assert_se(lseek(fd, 0, SEEK_SET) == 0);
assert_se(id128_read_fd(fd, ID128_PLAIN, &id2) == -EINVAL);
diff --git a/src/veritysetup/veritysetup-generator.c b/src/veritysetup/veritysetup-generator.c
index e38bd04159..74d5580cbc 100644
--- a/src/veritysetup/veritysetup-generator.c
+++ b/src/veritysetup/veritysetup-generator.c
@@ -285,7 +285,7 @@ static int determine_device(
if (!*data_what) {
memcpy(&data_uuid, m, sizeof(data_uuid));
- *data_what = path_join("/dev/disk/by-partuuid", ID128_TO_UUID_STRING(data_uuid));
+ *data_what = path_join("/dev/disk/by-partuuid", SD_ID128_TO_UUID_STRING(data_uuid));
if (!*data_what)
return log_oom();
}
@@ -293,7 +293,7 @@ static int determine_device(
if (!*hash_what) {
memcpy(&verity_uuid, (uint8_t*) m + l - sizeof(verity_uuid), sizeof(verity_uuid));
- *hash_what = path_join("/dev/disk/by-partuuid", ID128_TO_UUID_STRING(verity_uuid));
+ *hash_what = path_join("/dev/disk/by-partuuid", SD_ID128_TO_UUID_STRING(verity_uuid));
if (!*hash_what)
return log_oom();
}