From 296191630d477674cb49364a75fce7872ea9a368 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Fri, 28 May 2021 03:11:29 +0900 Subject: [PATCH] nvme: Fix to print get and set feature hex digits correct width Previously 2 hex digits not printed as "0x" was included the width specified. To resolve this increase 2 digits number more if the value is not zero. Signed-off-by: Tokunori Ikegami --- nvme.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/nvme.c b/nvme.c index cd7eb3df..63f71c3b 100644 --- a/nvme.c +++ b/nvme.c @@ -2818,9 +2818,11 @@ static int get_feature(int argc, char **argv, struct command *cmd, struct plugin cfg.uuid_index, cfg.data_len, buf, &result); if (!err) { if (!cfg.raw_binary || !buf) { - printf("get-feature:%#02x (%s), %s value:%#08x\n", cfg.feature_id, - nvme_feature_to_string(cfg.feature_id), - nvme_select_to_string(cfg.sel), result); + printf("get-feature:%#0*x (%s), %s value:%#0*x\n", + cfg.feature_id ? 4 : 2, cfg.feature_id, + nvme_feature_to_string(cfg.feature_id), + nvme_select_to_string(cfg.sel), result ? 10 : 8, + result); if (cfg.sel == 3) nvme_show_select_result(result); else if (cfg.human_readable) @@ -3748,9 +3750,11 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin if (err < 0) { perror("set-feature"); } else if (!err) { - printf("set-feature:%#02x (%s), value:%#08"PRIx64", cdw12:%#08"PRIx32", \ - save:%#x\n", cfg.feature_id, nvme_feature_to_string(cfg.feature_id), - (uint64_t)cfg.value, cfg.cdw12, cfg.save); + printf("set-feature:%#0*x (%s), value:%#0*"PRIx64", cdw12:%#0*x, save:%#x\n", + cfg.feature_id ? 4 : 2, cfg.feature_id, + nvme_feature_to_string(cfg.feature_id), + cfg.value ? 10 : 8, (uint64_t)cfg.value, + cfg.cdw12 ? 10 : 8, cfg.cdw12, cfg.save); if (cfg.feature_id == NVME_LBA_STATUS_INFO) { nvme_show_lba_status_info(result); } -- 2.50.1