From 6ecc5caf36e79ecbc9ca1c14c03f459e00ef26ba Mon Sep 17 00:00:00 2001 From: Francis Pravin Date: Thu, 8 May 2025 17:48:42 +0530 Subject: [PATCH] nvme-print: print Boot Partition Write Protection Config feature field Print the fields of Boot Partition Write Protection Config feature. Signed-off-by: Francis Pravin --- nvme-print-json.c | 13 +++++++++++++ nvme-print-stdout.c | 8 ++++++++ nvme-print.c | 18 ++++++++++++++++++ nvme-print.h | 1 + 4 files changed, 40 insertions(+) diff --git a/nvme-print-json.c b/nvme-print-json.c index e073a07ee8..1b757e0ced 100644 --- a/nvme-print-json.c +++ b/nvme-print-json.c @@ -3886,6 +3886,16 @@ static void json_feature_show_fields_fdp_events(struct json_object *r, unsigned } } +static void json_feature_show_fields_bpwp(struct json_object *r, unsigned int result) +{ + __u8 field; + + field = NVME_FEAT_BPWPC_BP0WPS(result); + obj_add_str(r, "Boot Partition 0 Write Protection State", nvme_bpwps_to_string(field)); + field = NVME_FEAT_BPWPC_BP1WPS(result); + obj_add_str(r, "Boot Partition 1 Write Protection State", nvme_bpwps_to_string(field)); +} + static void json_feature_show(enum nvme_features_id fid, int sel, unsigned int result) { struct json_object *r; @@ -4022,6 +4032,9 @@ static void json_feature_show_fields(enum nvme_features_id fid, unsigned int res case NVME_FEAT_FID_FDP_EVENTS: json_feature_show_fields_fdp_events(r, result, buf); break; + case NVME_FEAT_FID_BP_WRITE_PROTECT: + json_feature_show_fields_bpwp(r, result); + break; default: break; } diff --git a/nvme-print-stdout.c b/nvme-print-stdout.c index 9e48d33019..396dd2bf10 100644 --- a/nvme-print-stdout.c +++ b/nvme-print-stdout.c @@ -5224,6 +5224,14 @@ static void stdout_feature_show_fields(enum nvme_features_id fid, d->evta & 0x1 ? "" : "Not "); } break; + case NVME_FEAT_FID_BP_WRITE_PROTECT: + field = NVME_FEAT_BPWPC_BP1WPS(result); + printf("\tBoot Partition 1 Write Protection State (BP1WPS): %s\n", + nvme_bpwps_to_string(field)); + field = NVME_FEAT_BPWPC_BP0WPS(result); + printf("\tBoot Partition 0 Write Protection State (BP0WPS): %s\n", + nvme_bpwps_to_string(field)); + break; default: break; } diff --git a/nvme-print.c b/nvme-print.c index 958106cda2..554f6ee8a0 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -1202,6 +1202,24 @@ const char *nvme_ns_wp_cfg_to_string(enum nvme_ns_write_protect_cfg state) } } +const char *nvme_bpwps_to_string(__u8 bpwps) +{ + switch (bpwps) { + case NVME_FEAT_BPWPS_CHANGE_NOT_REQUESTED: + return "Change in state not requested"; + case NVME_FEAT_BPWPS_WRITE_UNLOCKED: + return "Write Unlocked"; + case NVME_FEAT_BPWPS_WRITE_LOCKED: + return "Write Locked"; + case NVME_FEAT_BPWPS_WRITE_LOCKED_PWR_CYCLE: + return "Write Locked Until Power Cycle"; + case NVME_FEAT_BPWPS_WRITE_PROTECTION_RPMB: + return "Write Protection controlled by RPMB"; + default: + return "Reserved"; + } +} + void nvme_directive_show(__u8 type, __u8 oper, __u16 spec, __u32 nsid, __u32 result, void *buf, __u32 len, nvme_print_flags_t flags) { diff --git a/nvme-print.h b/nvme-print.h index aff633c3ae..7916b276c5 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -325,6 +325,7 @@ const char *nvme_pel_ehai_pit_to_string(enum nvme_pel_ehai_pit pit); const char *nvme_ssi_state_to_string(__u8 state); const char *nvme_time_scale_to_string(__u8 ts); const char *nvme_pls_mode_to_string(__u8 mode); +const char *nvme_bpwps_to_string(__u8 bpwps); void nvme_dev_full_path(nvme_ns_t n, char *path, size_t len); void nvme_generic_full_path(nvme_ns_t n, char *path, size_t len);