mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-19 10:03:39 +03:00
Merge pull request #22507 from poettering/id128-compare-tweaks
sd-id128: comparison tweaks
This commit is contained in:
commit
d1e7fa02ca
@ -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',
|
||||
|
@ -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,13 +32,22 @@
|
||||
|
||||
<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>
|
||||
@ -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>
|
||||
|
@ -1239,10 +1239,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");
|
||||
r = sd_id128_from_string(parttype, &id);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to parse ID_PART_ENTRY_TYPE field '%s', ignoring: %m", parttype);
|
||||
if (!sd_id128_equal(id, GPT_USER_HOME)) {
|
||||
if (id128_equal_string(parttype, GPT_USER_HOME) <= 0) {
|
||||
log_debug("Found partition (%s) we don't care about, ignoring.", sysfs);
|
||||
return 0;
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "filesystems.h"
|
||||
#include "fs-util.h"
|
||||
#include "fsck-util.h"
|
||||
#include "gpt.h"
|
||||
#include "home-util.h"
|
||||
#include "homework-luks.h"
|
||||
#include "homework-mount.h"
|
||||
@ -703,7 +704,7 @@ static int luks_validate(
|
||||
if (!pp)
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
|
||||
if (!streq_ptr(blkid_partition_get_type_string(pp), "773f91ef-66d4-49b5-bd83-d683bf40ad16"))
|
||||
if (id128_equal_string(blkid_partition_get_type_string(pp), GPT_USER_HOME) <= 0)
|
||||
continue;
|
||||
|
||||
if (!streq_ptr(blkid_partition_get_name(pp), label))
|
||||
@ -1762,7 +1763,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) {
|
||||
@ -1858,7 +1859,7 @@ static int make_partition_table(
|
||||
if (!t)
|
||||
return log_oom();
|
||||
|
||||
r = fdisk_parttype_set_typestr(t, "773f91ef-66d4-49b5-bd83-d683bf40ad16");
|
||||
r = fdisk_parttype_set_typestr(t, SD_ID128_TO_UUID_STRING(GPT_USER_HOME));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to initialize partition type: %m");
|
||||
|
||||
@ -1917,7 +1918,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 +2746,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:
|
||||
|
@ -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)),
|
||||
|
@ -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;
|
||||
|
@ -2198,7 +2198,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)
|
||||
|
@ -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);
|
||||
@ -229,3 +206,19 @@ 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);
|
||||
}
|
||||
|
@ -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 {
|
||||
@ -40,3 +34,5 @@ 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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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");
|
||||
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include "errno-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "gpt.h"
|
||||
#include "id128-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
#include "pe-header.h"
|
||||
@ -889,7 +891,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 (!streq(v, "c12a7328-f81f-11d2-ba4b-00a0c93ec93b"))
|
||||
if (id128_equal_string(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);
|
||||
@ -982,7 +984,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 (!streq(v, "c12a7328-f81f-11d2-ba4b-00a0c93ec93b"))
|
||||
if (id128_equal_string(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);
|
||||
@ -1280,7 +1282,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), "Failed to probe partition type UUID of \"%s\": %m", node);
|
||||
if (!streq(v, "bc13c2ff-59e6-4262-a352-b275fd6f7172"))
|
||||
if (id128_equal_string(v, GPT_XBOOTLDR) <= 0)
|
||||
return log_full_errno(searching ? LOG_DEBUG : LOG_ERR,
|
||||
searching ? SYNTHETIC_ERRNO(EADDRNOTAVAIL) : SYNTHETIC_ERRNO(ENODEV),
|
||||
"File system \"%s\" has wrong type for extended boot loader partition.", node);
|
||||
@ -1344,7 +1346,7 @@ static int verify_xbootldr_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 (!streq(v, "bc13c2ff-59e6-4262-a352-b275fd6f7172"))
|
||||
if (id128_equal_string(v, GPT_XBOOTLDR))
|
||||
return log_full_errno(searching ? LOG_DEBUG : LOG_ERR,
|
||||
searching ? SYNTHETIC_ERRNO(EADDRNOTAVAIL) : SYNTHETIC_ERRNO(ENODEV),
|
||||
"File system \"%s\" has wrong type for extended boot loader partition.", node);
|
||||
|
@ -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))
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -213,7 +213,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
|
||||
return log_oom();
|
||||
|
||||
} else if (proc_cmdline_key_streq(key, "usrhash")) {
|
||||
|
||||
|
||||
if (proc_cmdline_value_missing(key, value))
|
||||
return 0;
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user