]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-id128: rename and export sd_id128_string_equal()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 13 Jun 2022 08:22:46 +0000 (10:22 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 30 Jun 2022 08:35:27 +0000 (10:35 +0200)
We find this function useful in our code, so no reason not to export it.
I changed the order of last two words in the name to match the arguments.
(With "equal_string" I expected sd_id128_t first, string second, but in
actual use, the second argument is usually a long constant so it's nice
to keep this order of arguments.)

src/home/homed-manager.c
src/home/homework-luks.c
src/libsystemd/libsystemd.sym
src/libsystemd/sd-id128/id128-util.c
src/libsystemd/sd-id128/id128-util.h
src/libsystemd/sd-id128/sd-id128.c
src/shared/find-esp.c
src/systemd/sd-id128.h

index 12e0ff516cacf9553e81e3b18ef607d4bc4966bb..d114236cf78712e2091672b56de93d379c2b5c05 100644 (file)
@@ -10,6 +10,8 @@
 #include <sys/quota.h>
 #include <sys/stat.h>
 
+#include "sd-id128.h"
+
 #include "btrfs-util.h"
 #include "bus-common-errors.h"
 #include "bus-error.h"
@@ -1239,7 +1241,7 @@ static int manager_add_device(Manager *m, sd_device *d) {
                 return 0;
         if (r < 0)
                 return log_error_errno(r, "Failed to acquire ID_PART_ENTRY_TYPE device property, ignoring: %m");
-        if (id128_equal_string(parttype, GPT_USER_HOME) <= 0) {
+        if (sd_id128_string_equal(parttype, GPT_USER_HOME) <= 0) {
                 log_debug("Found partition (%s) we don't care about, ignoring.", sysfs);
                 return 0;
         }
index bffd75bdd0395761f105ea3d3c7d10433e779952..97269db80dc74b49e75d30b518eb1c3e7ad6c285 100644 (file)
@@ -14,6 +14,7 @@
 #include "sd-daemon.h"
 #include "sd-device.h"
 #include "sd-event.h"
+#include "sd-id128.h"
 
 #include "blkid-util.h"
 #include "blockdev-util.h"
@@ -34,7 +35,6 @@
 #include "home-util.h"
 #include "homework-luks.h"
 #include "homework-mount.h"
-#include "id128-util.h"
 #include "io-util.h"
 #include "keyring-util.h"
 #include "memory-util.h"
@@ -704,7 +704,7 @@ static int luks_validate(
                 if (!pp)
                         return errno > 0 ? -errno : -EIO;
 
-                if (id128_equal_string(blkid_partition_get_type_string(pp), GPT_USER_HOME) <= 0)
+                if (sd_id128_string_equal(blkid_partition_get_type_string(pp), GPT_USER_HOME) <= 0)
                         continue;
 
                 if (!streq_ptr(blkid_partition_get_name(pp), label))
index c18ac527660c64b834c3cec277a2083ca0d18b64..87a2897eea9dc201bdbfa27e6d7ea4e9e0f6bfae 100644 (file)
@@ -783,6 +783,8 @@ LIBSYSTEMD_252 {
 global:
         sd_bus_error_setfv;
 
+        sd_id128_string_equal;
+
         sd_hwdb_new_from_path;
 
         sd_netlink_new_from_fd;
index e4a3bbd3ebe5b73085ea3c34b1f91da058a309da..1068721dd47bac027cf466f5389f1b2a1c30d676 100644 (file)
@@ -206,19 +206,3 @@ int id128_get_product(sd_id128_t *ret) {
         *ret = uuid;
         return 0;
 }
-
-int id128_equal_string(const char *s, sd_id128_t id) {
-        sd_id128_t parsed;
-        int r;
-
-        if (!s)
-                return false;
-
-        /* Checks if the specified string matches a valid string representation of the specified 128 bit ID/uuid */
-
-        r = sd_id128_from_string(s, &parsed);
-        if (r < 0)
-                return r;
-
-        return sd_id128_equal(parsed, id);
-}
index 65a278c8ee02ffbb6f419e5a686ae253564f5573..17b180c10c14860c35dc477c51eea15a54b209ee 100644 (file)
@@ -34,5 +34,3 @@ extern const struct hash_ops id128_hash_ops;
 sd_id128_t id128_make_v4_uuid(sd_id128_t id);
 
 int id128_get_product(sd_id128_t *ret);
-
-int id128_equal_string(const char *s, sd_id128_t id);
index 183d34054dc5a8073ef5c40dc3a30b5ede94f586..709c8ffb5750e62f93646cb2216cf0d7d4c4fe29 100644 (file)
@@ -101,6 +101,22 @@ _public_ int sd_id128_from_string(const char s[], sd_id128_t *ret) {
         return 0;
 }
 
+_public_ int sd_id128_string_equal(const char *s, sd_id128_t id) {
+        sd_id128_t parsed;
+        int r;
+
+        if (!s)
+                return false;
+
+        /* Checks if the specified string matches a valid string representation of the specified 128 bit ID/uuid */
+
+        r = sd_id128_from_string(s, &parsed);
+        if (r < 0)
+                return r;
+
+        return sd_id128_equal(parsed, id);
+}
+
 _public_ int sd_id128_get_machine(sd_id128_t *ret) {
         static thread_local sd_id128_t saved_machine_id = {};
         int r;
index 41eb644aa5423e8a7867a4cdbc54b5bc1e3c9968..ea27d7911a7880da40152e8714ba3d12e71abc7c 100644 (file)
@@ -4,6 +4,7 @@
 #include <sys/vfs.h>
 
 #include "sd-device.h"
+#include "sd-id128.h"
 
 #include "alloc-util.h"
 #include "blkid-util.h"
@@ -13,7 +14,6 @@
 #include "errno-util.h"
 #include "find-esp.h"
 #include "gpt.h"
-#include "id128-util.h"
 #include "parse-util.h"
 #include "path-util.h"
 #include "stat-util.h"
@@ -85,7 +85,7 @@ static int verify_esp_blkid(
         r = blkid_probe_lookup_value(b, "PART_ENTRY_TYPE", &v, NULL);
         if (r != 0)
                 return log_error_errno(errno ?: EIO, "Failed to probe partition type UUID of \"%s\": %m", node);
-        if (id128_equal_string(v, GPT_ESP) <= 0)
+        if (sd_id128_string_equal(v, GPT_ESP) <= 0)
                 return log_full_errno(searching ? LOG_DEBUG : LOG_ERR,
                                        SYNTHETIC_ERRNO(searching ? EADDRNOTAVAIL : ENODEV),
                                        "File system \"%s\" has wrong type for an EFI System Partition (ESP).", node);
@@ -178,7 +178,7 @@ static int verify_esp_udev(
         r = sd_device_get_property_value(d, "ID_PART_ENTRY_TYPE", &v);
         if (r < 0)
                 return log_error_errno(r, "Failed to get device property: %m");
-        if (id128_equal_string(v, GPT_ESP) <= 0)
+        if (sd_id128_string_equal(v, GPT_ESP) <= 0)
                 return log_full_errno(searching ? LOG_DEBUG : LOG_ERR,
                                        SYNTHETIC_ERRNO(searching ? EADDRNOTAVAIL : ENODEV),
                                        "File system \"%s\" has wrong type for an EFI System Partition (ESP).", node);
@@ -510,7 +510,7 @@ static int verify_xbootldr_blkid(
                 r = blkid_probe_lookup_value(b, "PART_ENTRY_TYPE", &v, NULL);
                 if (r != 0)
                         return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "%s: Failed to probe PART_ENTRY_TYPE: %m", node);
-                if (id128_equal_string(v, GPT_XBOOTLDR) <= 0)
+                if (sd_id128_string_equal(v, GPT_XBOOTLDR) <= 0)
                         return log_full_errno(searching ? LOG_DEBUG : LOG_ERR,
                                               searching ? SYNTHETIC_ERRNO(EADDRNOTAVAIL) : SYNTHETIC_ERRNO(ENODEV),
                                               "%s: Partitition has wrong PART_ENTRY_TYPE=%s for XBOOTLDR partition.", node, v);
@@ -576,7 +576,7 @@ static int verify_xbootldr_udev(
                 if (r < 0)
                         return log_device_error_errno(d, r, "Failed to query ID_PART_ENTRY_TYPE: %m");
 
-                r = id128_equal_string(v, GPT_XBOOTLDR);
+                r = sd_id128_string_equal(v, GPT_XBOOTLDR);
                 if (r < 0)
                         return log_device_error_errno(d, r, "Failed to parse ID_PART_ENTRY_TYPE=%s: %m", v);
                 if (r == 0)
index cf87e8820fd40fdc49cc6653fbf600a3b828cf09..92682166d76b04504bdf0a1a8fffbe55e609ed77 100644 (file)
@@ -119,6 +119,8 @@ _sd_pure_ static __inline__ int sd_id128_equal(sd_id128_t a, sd_id128_t b) {
         return memcmp(&a, &b, 16) == 0;
 }
 
+int sd_id128_string_equal(const char *s, sd_id128_t id);
+
 _sd_pure_ static __inline__ int sd_id128_is_null(sd_id128_t a) {
         return a.qwords[0] == 0 && a.qwords[1] == 0;
 }