From a233cb6914e68252baf143c5f1d6e01e3956e33e Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Thu, 15 Aug 2024 15:10:17 -0600 Subject: [PATCH] nvmecontrol: Accept -a {1,2,3,4} for sanitize command for nvme-cli compat Linux's `nvme sanititze -a` takes a number, not a string. Accept 1-4 for compatibility so vendor's recepies are easier to implmement. Sponsored by: Netflix --- sbin/nvmecontrol/nvmecontrol.8 | 10 ++++++++++ sbin/nvmecontrol/sanitize.c | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/sbin/nvmecontrol/nvmecontrol.8 b/sbin/nvmecontrol/nvmecontrol.8 index 713fcf092d64..cb3e8aa9080f 100644 --- a/sbin/nvmecontrol/nvmecontrol.8 +++ b/sbin/nvmecontrol/nvmecontrol.8 @@ -572,6 +572,16 @@ A failed sanitize operation can only be exited if it was run in the unrestricted completion mode, as provided by the .Fl U argument. +.It 1, 2, 3, 4 +nvme-cli compatible +.Fl a +values for +.Dq exitfailure , +.Dq block , +.Dq overwrite , +and +.Dq crypto +respectively. .El .It Fl c Ar passes The number of passes when performing an diff --git a/sbin/nvmecontrol/sanitize.c b/sbin/nvmecontrol/sanitize.c index ba89e138db83..e720c6d43497 100644 --- a/sbin/nvmecontrol/sanitize.c +++ b/sbin/nvmecontrol/sanitize.c @@ -130,8 +130,11 @@ sanitize(const struct cmd *f, int argc, char *argv[]) sanact = 3; else if (strcmp(opt.sanact, "crypto") == 0) sanact = 4; + else if ((sanact = (int)strtol(opt.sanact, NULL, 10) != 0) + && (sanact >= 1 && sanact <= 4)) + ; /* compat with nvme sanitize -a number */ else { - fprintf(stderr, "Incorrect Sanitize Action value\n"); + fprintf(stderr, "Incorrect Sanitize Action value: %s\n", opt.sanact); arg_help(argc, argv, f); } }