From: Tokunori Ikegami Date: Wed, 17 May 2023 16:16:41 +0000 (+0900) Subject: nvme: Fix io-passthru command read metadata output X-Git-Tag: v2.5~103 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a09d5c59734f38ab36ffe4d37f5bcbd3435d6784;p=users%2Fsagi%2Fnvme-cli.git nvme: Fix io-passthru command read metadata output Signed-off-by: Tokunori Ikegami --- diff --git a/nvme.c b/nvme.c index 23737794..5d0af3e8 100644 --- a/nvme.c +++ b/nvme.c @@ -8591,18 +8591,27 @@ static int passthru(int argc, char **argv, bool admin, } else { printf("%s Command %s is Success and result: 0x%08x\n", admin ? "Admin" : "IO", strcmp(cmd_name, "Unknown") ? cmd_name : "Vendor Specific", result); - if (cfg.read && strlen(cfg.input_file)) { - if (write(dfd, (void *)data, cfg.data_len) < 0) - perror("failed to write data buffer"); + if (cfg.read) { + if (strlen(cfg.input_file)) { + if (write(dfd, (void *)data, cfg.data_len) < 0) + perror("failed to write data buffer"); + } else if (data) { + if (cfg.raw_binary) + d_raw((unsigned char *)data, cfg.data_len); + else if (!err) + d((unsigned char *)data, cfg.data_len, 16, 1); + } if (cfg.metadata_len && cfg.metadata) { - if (write(mfd, (void *)mdata, cfg.metadata_len) < 0) - perror("failed to write metadata buffer"); + if (strlen(cfg.metadata)) { + if (write(mfd, (void *)mdata, cfg.metadata_len) < 0) + perror("failed to write metadata buffer"); + } else { + if (cfg.raw_binary) + d_raw((unsigned char *)mdata, cfg.metadata_len); + else if (!err) + d((unsigned char *)mdata, cfg.metadata_len, 16, 1); + } } - } else if (!cfg.raw_binary) { - if (data && cfg.read && !err) - d((unsigned char *)data, cfg.data_len, 16, 1); - } else if (data && cfg.read) { - d_raw((unsigned char *)data, cfg.data_len); } } free_metadata: