From: Zbigniew Jędrzejewski-Szmek Date: Mon, 13 Jun 2022 08:22:46 +0000 (+0200) Subject: sd-id128: rename and export sd_id128_string_equal() X-Git-Tag: v252-rc1~751^2~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e16144844b9963f8ff72b325e281fa91aef3bc34;p=thirdparty%2Fsystemd.git sd-id128: rename and export sd_id128_string_equal() 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.) --- diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index 12e0ff516ca..d114236cf78 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -10,6 +10,8 @@ #include #include +#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; } diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index bffd75bdd03..97269db80dc 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -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)) diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index c18ac527660..87a2897eea9 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -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; diff --git a/src/libsystemd/sd-id128/id128-util.c b/src/libsystemd/sd-id128/id128-util.c index e4a3bbd3ebe..1068721dd47 100644 --- a/src/libsystemd/sd-id128/id128-util.c +++ b/src/libsystemd/sd-id128/id128-util.c @@ -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); -} diff --git a/src/libsystemd/sd-id128/id128-util.h b/src/libsystemd/sd-id128/id128-util.h index 65a278c8ee0..17b180c10c1 100644 --- a/src/libsystemd/sd-id128/id128-util.h +++ b/src/libsystemd/sd-id128/id128-util.h @@ -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); diff --git a/src/libsystemd/sd-id128/sd-id128.c b/src/libsystemd/sd-id128/sd-id128.c index 183d34054dc..709c8ffb575 100644 --- a/src/libsystemd/sd-id128/sd-id128.c +++ b/src/libsystemd/sd-id128/sd-id128.c @@ -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; diff --git a/src/shared/find-esp.c b/src/shared/find-esp.c index 41eb644aa54..ea27d7911a7 100644 --- a/src/shared/find-esp.c +++ b/src/shared/find-esp.c @@ -4,6 +4,7 @@ #include #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) diff --git a/src/systemd/sd-id128.h b/src/systemd/sd-id128.h index cf87e8820fd..92682166d76 100644 --- a/src/systemd/sd-id128.h +++ b/src/systemd/sd-id128.h @@ -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; }