diff --git a/libnvme/src/nvme/ioctl.c b/libnvme/src/nvme/ioctl.c index ea21520f65..0ad051a359 100644 --- a/libnvme/src/nvme/ioctl.c +++ b/libnvme/src/nvme/ioctl.c @@ -38,7 +38,7 @@ static int nvme_verify_chr(struct nvme_transport_handle *hdl) return -errno; if (!S_ISCHR(nvme_stat.st_mode)) - return -ENOTBLK; + return -EINVAL; return 0; } diff --git a/nvme.c b/nvme.c index 4331db36a1..ac59f3d465 100644 --- a/nvme.c +++ b/nvme.c @@ -221,6 +221,7 @@ static const char *namespace_desired = "desired namespace"; static const char *namespace_id_desired = "identifier of desired namespace"; static const char *namespace_id_optional = "optional namespace attached to controller"; static const char *nssf = "NVMe Security Specific Field"; +static const char *only_char_dev = "Only character device is allowed"; static const char *prinfo = "PI and check field"; static const char *rae = "Retain an Asynchronous Event"; static const char *raw_directive = "show directive in binary format"; @@ -5349,6 +5350,11 @@ static int subsystem_reset(int argc, char **argv, struct command *acmd, struct p if (err) return err; + if (!nvme_transport_handle_is_chardev(hdl)) { + nvme_show_error(only_char_dev); + return -EINVAL; + } + err = nvme_subsystem_reset(hdl); if (err < 0) { if (errno == ENOTTY) @@ -5375,6 +5381,11 @@ static int reset(int argc, char **argv, struct command *acmd, struct plugin *plu if (err) return err; + if (!nvme_transport_handle_is_chardev(hdl)) { + nvme_show_error(only_char_dev); + return -EINVAL; + } + err = nvme_ctrl_reset(hdl); if (err < 0) nvme_show_error("Reset: %s", nvme_strerror(err)); @@ -5399,6 +5410,11 @@ static int ns_rescan(int argc, char **argv, struct command *acmd, struct plugin if (err) return err; + if (!nvme_transport_handle_is_chardev(hdl)) { + nvme_show_error(only_char_dev); + return -EINVAL; + } + err = validate_output_format(nvme_cfg.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); @@ -5740,7 +5756,7 @@ static int show_registers(int argc, char **argv, struct command *acmd, struct pl return err; if (nvme_transport_handle_is_blkdev(hdl)) { - nvme_show_error("Only character device is allowed"); + nvme_show_error(only_char_dev); return -EINVAL; } @@ -6017,7 +6033,7 @@ static int get_register(int argc, char **argv, struct command *acmd, struct plug return err; if (nvme_transport_handle_is_blkdev(hdl)) { - nvme_show_error("Only character device is allowed"); + nvme_show_error(only_char_dev); return -EINVAL; } @@ -6321,7 +6337,7 @@ static int set_register(int argc, char **argv, struct command *acmd, struct plug return err; if (nvme_transport_handle_is_blkdev(hdl)) { - nvme_show_error("Only character device is allowed"); + nvme_show_error(only_char_dev); return -EINVAL; }