1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-23 10:50:16 +03:00

id128: refuse --app-specific= if we're listing GPT types

Prompted by 

The intention of b37e8184a5a376749fbf68674ed6d7a4fc9901aa
is to expose sd_id128_get_app_specific() on command line.
But combining that with GPT type list makes little sense.

(cherry picked from commit fa96c55b7b0d19a7f72908ee7d3f8a1ef630be96)
This commit is contained in:
Mike Yuan 2024-07-16 21:10:46 +02:00 committed by Luca Boccassi
parent b60d5bc1b7
commit 86ec58a55c

@ -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;