summaryrefslogtreecommitdiffstats
path: root/src/id128
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-16 18:20:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-16 18:20:20 +0000
commit8612d3d858fa108e5732a586d4e2d0227ae34422 (patch)
tree33e7f8b3d5caa6c44b4d6759cb25d3eff4b2d975 /src/id128
parentAdding debian version 256.2-1. (diff)
downloadsystemd-8612d3d858fa108e5732a586d4e2d0227ae34422.tar.xz
systemd-8612d3d858fa108e5732a586d4e2d0227ae34422.zip
Merging upstream version 256.4.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/id128')
-rw-r--r--src/id128/id128.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/id128/id128.c b/src/id128/id128.c
index fa86cf6..875d22d 100644
--- a/src/id128/id128.c
+++ b/src/id128/id128.c
@@ -16,7 +16,7 @@
#include "verbs.h"
static Id128PrettyPrintMode arg_mode = ID128_PRINT_ID128;
-static sd_id128_t arg_app = {};
+static sd_id128_t arg_app = SD_ID128_NULL;
static bool arg_value = false;
static PagerFlags arg_pager_flags = 0;
static bool arg_legend = true;
@@ -72,15 +72,12 @@ static int verb_invocation_id(int argc, char **argv, void *userdata) {
}
static int show_one(Table **table, const char *name, sd_id128_t uuid, bool first) {
- sd_id128_t u;
int r;
assert(table);
- if (sd_id128_is_null(arg_app))
- u = uuid;
- else
- assert_se(sd_id128_get_app_specific(uuid, arg_app, &u) == 0);
+ if (!name)
+ name = "XYZ";
if (arg_mode == ID128_PRINT_PRETTY) {
_cleanup_free_ char *id = NULL;
@@ -91,7 +88,7 @@ static int show_one(Table **table, const char *name, sd_id128_t uuid, bool first
ascii_strupper(id);
- r = id128_pretty_print_sample(id, u);
+ r = id128_pretty_print_sample(id, uuid);
if (r < 0)
return r;
if (!first)
@@ -100,19 +97,19 @@ static int show_one(Table **table, const char *name, sd_id128_t uuid, bool first
}
if (arg_value)
- return id128_pretty_print(u, arg_mode);
+ return id128_pretty_print(uuid, arg_mode);
if (!*table) {
*table = table_new("name", "id");
if (!*table)
return log_oom();
+
table_set_width(*table, 0);
}
return table_add_many(*table,
TABLE_STRING, name,
- arg_mode == ID128_PRINT_ID128 ? TABLE_ID128 : TABLE_UUID,
- u);
+ arg_mode == ID128_PRINT_ID128 ? TABLE_ID128 : TABLE_UUID, uuid);
}
static int verb_show(int argc, char **argv, void *userdata) {
@@ -120,23 +117,26 @@ static int verb_show(int argc, char **argv, void *userdata) {
int r;
argv = strv_skip(argv, 1);
- if (strv_isempty(argv))
+ if (strv_isempty(argv)) {
+ if (!sd_id128_is_null(arg_app))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "'show --app-specific=' can only be used with explicit UUID input.");
+
for (const GptPartitionType *e = gpt_partition_type_table; e->name; e++) {
r = show_one(&table, e->name, e->uuid, e == gpt_partition_type_table);
if (r < 0)
return r;
}
- else
+ } else
STRV_FOREACH(p, argv) {
sd_id128_t uuid;
- bool have_uuid;
- const char *id;
+ const char *id = NULL;
/* Check if the argument is an actual UUID first */
- have_uuid = sd_id128_from_string(*p, &uuid) >= 0;
+ bool is_uuid = sd_id128_from_string(*p, &uuid) >= 0;
- if (have_uuid)
- id = gpt_partition_type_uuid_to_string(uuid) ?: "XYZ";
+ if (is_uuid)
+ id = gpt_partition_type_uuid_to_string(uuid);
else {
GptPartitionType type;
@@ -148,6 +148,9 @@ static int verb_show(int argc, char **argv, void *userdata) {
id = *p;
}
+ if (!sd_id128_is_null(arg_app))
+ assert_se(sd_id128_get_app_specific(uuid, arg_app, &uuid) >= 0);
+
r = show_one(&table, id, uuid, p == argv);
if (r < 0)
return r;