From d9020321e66ab0760b44332b3947a4f80afe265c Mon Sep 17 00:00:00 2001 From: Keith Busch Date: Mon, 6 Apr 2015 14:31:09 -0600 Subject: [PATCH] Register read fix for kernel 4.0 The nvme sysfs path was moved in kernel 4.0 to a new class type, so just opening that one first before falling back to the previous location. This also is printing an error if the user requested an invalid command. Signed-off-by: Keith Busch --- nvme.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nvme.c b/nvme.c index 7210a1a7..87e87bec 100644 --- a/nvme.c +++ b/nvme.c @@ -778,8 +778,13 @@ static void get_registers(struct nvme_bar *bar, unsigned char_only) } base = nvme_char_from_block(basename(devicename)); - sprintf(path, "/sys/class/misc/%s/device/resource0", base); + + sprintf(path, "/sys/class/nvme/%s/device/resource0", base); pci_fd = open(path, O_RDONLY); + if (pci_fd < 0) { + sprintf(path, "/sys/class/misc/%s/device/resource0", base); + pci_fd = open(path, O_RDONLY); + } if (pci_fd < 0) { fprintf(stderr, "%s did not find a pci resource\n", devicename); exit(ENODEV); @@ -2382,6 +2387,9 @@ static void handle_internal_command(int argc, char **argv) continue; exit(cmd->fn(argc, argv)); } + fprintf(stderr, "unknown command '%s'\n", argv[0]); + help(1, NULL); + exit(1); } int main(int argc, char **argv) -- 2.50.1