return err;
}
+static int parse_sanact(char *str, __u8 *val)
+{
+ int len = strlen(str);
+
+ if (!strncasecmp(str, "exit-failure", len > 1 ? len : 1))
+ *val = NVME_SANITIZE_SANACT_EXIT_FAILURE;
+
+ if (!strncasecmp(str, "start-block-erase", len > 7 ? len : 7))
+ *val = NVME_SANITIZE_SANACT_START_BLOCK_ERASE;
+
+ if (!strncasecmp(str, "start-overwrite", len > 7 ? len : 7))
+ *val = NVME_SANITIZE_SANACT_START_OVERWRITE;
+
+ if (!strncasecmp(str, "start-crypto-erase", len > 7 ? len : 7))
+ *val = NVME_SANITIZE_SANACT_START_CRYPTO_ERASE;
+
+ if (*val)
+ return 0;
+
+ return argconfig_parse_byte("sanact", str, val);
+}
+
static int sanitize(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Send a sanitize command.";
const char *ovrpat_desc = "Overwrite pattern.";
struct nvme_dev *dev;
int err;
+ __u8 sanact = 0;
struct config {
bool no_dealloc;
bool oipbp;
__u8 owpass;
bool ause;
- __u8 sanact;
+ char *sanact;
__u32 ovrpat;
};
.oipbp = false,
.owpass = 0,
.ause = false,
- .sanact = 0,
+ .sanact = NULL,
.ovrpat = 0,
};
OPT_FLAG("oipbp", 'i', &cfg.oipbp, oipbp_desc),
OPT_BYTE("owpass", 'n', &cfg.owpass, owpass_desc),
OPT_FLAG("ause", 'u', &cfg.ause, ause_desc),
- OPT_BYTE("sanact", 'a', &cfg.sanact, sanact_desc),
+ OPT_STR("sanact", 'a', &cfg.sanact, sanact_desc),
OPT_UINT("ovrpat", 'p', &cfg.ovrpat, ovrpat_desc),
OPT_END()
};
if (err)
goto ret;
- switch (cfg.sanact) {
+ if (cfg.sanact) {
+ err = parse_sanact(cfg.sanact, &sanact);
+ if (err)
+ goto close_dev;
+ }
+
+ switch (sanact) {
case NVME_SANITIZE_SANACT_EXIT_FAILURE:
case NVME_SANITIZE_SANACT_START_BLOCK_ERASE:
case NVME_SANITIZE_SANACT_START_OVERWRITE:
goto close_dev;
}
- if (cfg.sanact == NVME_SANITIZE_SANACT_EXIT_FAILURE) {
- if (cfg.ause || cfg.no_dealloc) {
+ if (sanact == NVME_SANITIZE_SANACT_EXIT_FAILURE) {
+ if (cfg.ause || cfg.no_dealloc) {
fprintf(stderr, "SANACT is Exit Failure Mode\n");
err = -EINVAL;
goto close_dev;
- }
+ }
}
- if (cfg.sanact == NVME_SANITIZE_SANACT_START_OVERWRITE) {
+ if (sanact == NVME_SANITIZE_SANACT_START_OVERWRITE) {
if (cfg.owpass > 16) {
fprintf(stderr, "OWPASS out of range [0-16]\n");
err = -EINVAL;
struct nvme_sanitize_nvm_args args = {
.args_size = sizeof(args),
- .sanact = cfg.sanact,
+ .sanact = sanact,
.ause = cfg.ause,
.owpass = cfg.owpass,
.oipbp = cfg.oipbp,
show_option(s);
}
+int argconfig_parse_byte(const char *opt, const char *str, unsigned char *val)
+{
+ char *endptr;
+ unsigned long tmp = strtoul(str, &endptr, 0);
+
+ if (errno || tmp >= 1 << 8 || str == endptr) {
+ fprintf(stderr,
+ "Expected byte argument for '%s' but got '%s'!\n", opt,
+ str);
+ return -EINVAL;
+ }
+
+ *val = tmp;
+
+ return 0;
+}
+
int argconfig_parse(int argc, char *argv[], const char *program_desc,
const struct argconfig_commandline_options *options)
{
}
*((int *)value_addr) = tmp;
} else if (s->config_type == CFG_BYTE) {
- unsigned long tmp = strtoul(optarg, &endptr, 0);
- if (errno || tmp >= (1 << 8) || optarg == endptr) {
- fprintf(stderr,
- "Expected byte argument for '%s' but got '%s'!\n",
- long_opts[option_index].name, optarg);
+ if (argconfig_parse_byte(long_opts[option_index].name,
+ optarg, (uint8_t *)value_addr))
goto out;
- }
- *((uint8_t *) value_addr) = tmp;
} else if (s->config_type == CFG_SHORT) {
unsigned long tmp = strtoul(optarg, &endptr, 0);
if (errno || tmp >= (1 << 16) || optarg == endptr) {