]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd128: export sd_id128_to_uuid_string()
authorLennart Poettering <lennart@poettering.net>
Mon, 14 Feb 2022 13:52:02 +0000 (14:52 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 14 Feb 2022 14:13:23 +0000 (15:13 +0100)
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.

20 files changed:
man/rules/meson.build
man/sd_id128_to_string.xml
src/home/homework-luks.c
src/home/user-record-util.c
src/libsystemd/libsystemd.sym
src/libsystemd/sd-device/sd-device.c
src/libsystemd/sd-id128/id128-util.c
src/libsystemd/sd-id128/id128-util.h
src/libsystemd/sd-id128/sd-id128.c
src/nspawn/nspawn.c
src/partition/repart.c
src/shared/format-table.c
src/shared/gpt.c
src/shared/gpt.h
src/shared/logs-show.c
src/shared/mkfs-util.c
src/shared/udev-util.c
src/systemd/sd-id128.h
src/test/test-id128.c
src/veritysetup/veritysetup-generator.c

index 7200ecf6810e4799e45326c916bcf9c00ad1e79d..793010f75f4e7c6cd9ccc4de8af0eec7247054db 100644 (file)
@@ -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',
index db64bc018d1b3a2b225e097df60b33129b51af2f..e0338bae85f6926ad001aa51f6fd24a72d4e608e 100644 (file)
   <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>
 
 
       <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>
     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>
index 8063206358934a98c956e1fe44165e3c9a3a220a..b400d7307d54db7c0a20a3438ffaddbb0459f633 100644 (file)
@@ -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:
index f4578783f3aa8a91fa99463db0f2013fbbe9e126..6a892d45b5b4730b7280c795a7f4227b2b4ad28c 100644 (file)
@@ -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)),
index 2178668d11a32f827c3d50ea63e66fe2fe96905a..2773d28b4bb4bbcd8bfe2b0c9ae18f33cbf7c6a6 100644 (file)
@@ -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;
index 27c91ea724f93a453997dd96d12f6bcca2c8aa85..03fd70e572fbf9e6458dd19c7fdf72c2798ebc22 100644 (file)
@@ -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)
index 7c66d1c2dbf0387ef36d2b081f3936ab4881bce4..1068721dd47bac027cf466f5389f1b2a1c30d676 100644 (file)
 #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);
index b7327a1f0700794e7c33046ec62916ff5b20d687..17b180c10c14860c35dc477c51eea15a54b209ee 100644 (file)
@@ -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 {
index 992b19130e8cc92419058cf92762f4071fc7dba0..46269c2cc2dd734622f19d4187110f9620094372 100644 (file)
 #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;
 }
index 8f17ab8810c013505853bce6f955872fe375b519..144e58ae897ea9d0bafaf66c2e793066d61d4a71 100644 (file)
@@ -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) {
index 0862a37a8dcae24a91044f4ceded476b7c35b45d..abdf947dbff68f79000959542ba2fa30bd79f424 100644 (file)
@@ -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");
 
index b95680b36516b4ab0c003ce5a66c42984f7fc1a0..44b736d1fd6edb80edeeaff5854df718bbe9f240 100644 (file)
@@ -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))
index c01a57a5fb346de296391570fd647c52ed48772a..cd57447b8af698e8d2b593bcf3a809b60e7b64c5 100644 (file)
@@ -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) {
index 00c829ca79aaf70c3d5dd17cdf3a5e06fac5c8a7..9604d6e86b9442ccf0675e3aba1ba5043e2aa6e2 100644 (file)
 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);
index cf83eb6bcaf39ca266c80fda9807c0844c985829..acc1dc9b95194b41f7344defa46874e5fa9dd02f 100644 (file)
@@ -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;
index 061a2c2ef749465047ea650bd0cf775a8ffb7ebe..accd64f9e89f9f6e008418f4f76fdb76960b57ab 100644 (file)
@@ -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)
index 32dfcdafc47bcfbe4833040fa4c59cc96aa26149..e2574b9af39f4c2d929b5b714ce263023cae36f6 100644 (file)
@@ -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) {
index e64f3200a3b56dab29311d01ee8e7208be1e84ab..f7d3244bb381cd89e88fec9a70d6119c47f23233 100644 (file)
@@ -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);
 
index 33c4f1a5ea526618ed1c1b8f06e64ca1930275aa..5da7b0ec1a092aedfb37db525d4a58ff9dbbe9f0 100644 (file)
@@ -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);
index e38bd041595697fdff864a6dc7c2d01d7a86d49a..74d5580cbc216abb2e6fadc81ef89ed0acb6614f 100644 (file)
@@ -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();
         }