]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-print: print namespace write protect states in get feature
authorGollu Appalanaidu <anaidu.gollu@samsung.com>
Thu, 29 Apr 2021 16:38:04 +0000 (22:08 +0530)
committerKeith Busch <kbusch@kernel.org>
Mon, 10 May 2021 18:08:22 +0000 (12:08 -0600)
Print the Namespace write protect states for the get feature
with FID 0x84, Namespace write protect config.

Signed-off-by: Gollu Appalanaidu <anaidu.gollu@samsung.com>
nvme-print.c

index 921bcca8f74118290fe086fe5a0da26dd17073aa..4662ae8c84682c683d30aed15ae439a8197d823b 100755 (executable)
@@ -5517,6 +5517,22 @@ static void nvme_show_host_mem_buffer(struct nvme_host_mem_buffer *hmb)
                le32_to_cpu(hmb->hsize));
 }
 
+static const char *nvme_show_ns_write_protect_config(__u8 state)
+{
+       switch (state) {
+       case NVME_NS_NO_WRITE_PROTECT:
+               return "No Write Protect";
+       case NVME_NS_WRITE_PROTECT:
+               return "Write Protect";
+       case NVME_NS_WRITE_PROTECT_POWER_CYCLE:
+               return "Write Protect Until Power Cycle";
+       case NVME_NS_WRITE_PROTECT_PERMANENT:
+               return "Permanent Write Protect";
+       default:
+               return "Reserved";
+       }
+}
+
 static void nvme_directive_show_fields(__u8 dtype, __u8 doper,
                                       unsigned int result, unsigned char *buf)
 {
@@ -5743,7 +5759,7 @@ void nvme_feature_show_fields(enum nvme_feat fid, unsigned int result,
                printf("\tPersist Through Power Loss (PTPL): %s\n", (result & 0x00000001) ? "True":"False");
                break;
        case NVME_FEAT_WRITE_PROTECT:
-               printf("\tNamespace Write Protect: %s\n", result != NVME_NS_NO_WRITE_PROTECT ? "True" :  "False");
+               printf("\tNamespace Write Protect state: %s\n", nvme_show_ns_write_protect_config(result & 0x7));
                break;
        case NVME_FEAT_TIMESTAMP:
                nvme_show_timestamp((struct nvme_timestamp *)buf);