1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-02-08 05:57:26 +03:00

repart: deal with empty partition label sensibly

libfdisk appears to return NULL when encountering an empty partition
label, let's handle this sanely, and treat NULL and "" for the current
label as the same, but for the new label as distinct: there NULL means
nothing is set, and "" means an actual empty label.

(cherry picked from commit be9ce0188ebb414319f0c003f805ea02b5eb473e)
(cherry picked from commit b3b84982d0e72d3160ff7ecb6193c6439c1fc27e)
This commit is contained in:
Lennart Poettering 2021-03-19 22:45:15 +01:00 committed by Zbigniew Jędrzejewski-Szmek
parent 434e81d174
commit 2769b27cf3

View File

@ -942,6 +942,9 @@ static int config_parse_label(
assert(rvalue);
assert(label);
/* Nota bene: the empty label is a totally valid one. Let's hence not follow our usual rule of
* assigning the empty string to reset to default here, but really accept it as label to set. */
r = specifier_printf(rvalue, specifier_table, NULL, &resolved);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
@ -1851,7 +1854,7 @@ static int context_dump_partitions(Context *context, const char *node) {
r = table_add_many(
t,
TABLE_STRING, gpt_partition_type_uuid_to_string_harder(p->type_uuid, uuid_buffer),
TABLE_STRING, label ?: "-", TABLE_SET_COLOR, label ? NULL : ansi_grey(),
TABLE_STRING, empty_to_null(label) ?: "-", TABLE_SET_COLOR, empty_to_null(label) ? NULL : ansi_grey(),
TABLE_UUID, sd_id128_is_null(p->new_uuid) ? p->current_uuid : p->new_uuid,
TABLE_STRING, p->definition_path ? basename(p->definition_path) : "-", TABLE_SET_COLOR, p->definition_path ? NULL : ansi_grey(),
TABLE_STRING, partname ?: "-", TABLE_SET_COLOR, partname ? NULL : ansi_highlight(),
@ -2424,7 +2427,7 @@ static int partition_encrypt(
volume_key,
volume_key_size,
&(struct crypt_params_luks2) {
.label = p->new_label,
.label = strempty(p->new_label),
.sector_size = 512U,
});
if (r < 0)
@ -2768,7 +2771,7 @@ static int context_mkfs(Context *context) {
if (r < 0)
return r;
r = make_filesystem(fsdev, p->format, p->new_label, fs_uuid, arg_discard);
r = make_filesystem(fsdev, p->format, strempty(p->new_label), fs_uuid, arg_discard);
if (r < 0) {
encrypted_dev_fd = safe_close(encrypted_dev_fd);
(void) deactivate_luks(cd, encrypted);
@ -2957,7 +2960,7 @@ static int context_acquire_partition_uuids_and_labels(Context *context) {
if (p->current_label) {
free(p->new_label);
p->new_label = strdup(p->current_label);
p->new_label = strdup(strempty(p->current_label));
if (!p->new_label)
return log_oom();
}
@ -3040,9 +3043,7 @@ static int context_mangle_partitions(Context *context) {
}
if (!streq_ptr(p->new_label, p->current_label)) {
assert(!isempty(p->new_label));
r = fdisk_partition_set_name(p->current_partition, p->new_label);
r = fdisk_partition_set_name(p->current_partition, strempty(p->new_label));
if (r < 0)
return log_error_errno(r, "Failed to set partition label: %m");
@ -3066,7 +3067,7 @@ static int context_mangle_partitions(Context *context) {
assert(p->offset % 512 == 0);
assert(p->new_size % 512 == 0);
assert(!sd_id128_is_null(p->new_uuid));
assert(!isempty(p->new_label));
assert(p->new_label);
t = fdisk_new_parttype();
if (!t)
@ -3104,7 +3105,7 @@ static int context_mangle_partitions(Context *context) {
if (r < 0)
return log_error_errno(r, "Failed to set partition UUID: %m");
r = fdisk_partition_set_name(q, p->new_label);
r = fdisk_partition_set_name(q, strempty(p->new_label));
if (r < 0)
return log_error_errno(r, "Failed to set partition label: %m");