From cf9fb0d63dff31e5370229b2a99c95492b755ad1 Mon Sep 17 00:00:00 2001 From: Pascal Terjan Date: Thu, 11 Jun 2020 21:25:41 +0000 Subject: Fix NVME code to work for disks with no vendor --- mdk-stage1/probing.c | 58 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 22 deletions(-) (limited to 'mdk-stage1/probing.c') diff --git a/mdk-stage1/probing.c b/mdk-stage1/probing.c index e9cc60af0..5850f95c5 100644 --- a/mdk-stage1/probing.c +++ b/mdk-stage1/probing.c @@ -883,47 +883,61 @@ void find_media(enum media_bus bus) * */ log_message("looking for NVME"); { + int missing_vendor = 0; glob_t globbuf; glob("/sys/block/nvme*/device/vendor", 0, NULL, &globbuf); + if (globbuf.gl_pathc == 0) { + glob("/sys/block/nvme*/device/model", 0, NULL, &globbuf); + if (globbuf.gl_pathc != 0) { + missing_vendor = 1; + } + } + for (int i = 0; i < globbuf.gl_pathc; i++) { char *path = globbuf.gl_pathv[i]; char *model = "Unknown NVME Disk"; + int vendor_length = 0; + int fd; // Get device name by skipping /sys/block/ char *name_end = strchr(path + 11, '/'); if (!name_end) { - log_message("Strange path: %s", path); + log_message("Strange path from glob: %s", path); continue; } // Read vendor name - int fd = open(path, O_RDONLY); - int vendor_length = 0; - buf[0] = '\0'; - if (fd == -1) { - log_message("Failed to open %s for reading", path); - } else { - int n = read(fd, buf, sizeof(buf)); - if (n == -1) { - log_message("Couldn't read vendor file (%s)", path); - } else { - // Strip whitespaces and newline - for (int j = n-1; j >= 0; j--) { - if (buf[j] == '\n' || buf[j] == ' ') - continue; - vendor_length = j+1; - break; + if (!missing_vendor) { + fd = open(path, O_RDONLY); + buf[0] = '\0'; + if (fd == -1) { + log_message("Failed to open %s for reading", path); + } else { + int n = read(fd, buf, sizeof(buf)); + if (n == -1) { + log_message("Couldn't read vendor file (%s)", path); + } else { + // Strip whitespaces and newline + for (int j = n-1; j >= 0; j--) { + if (buf[j] == '\n' || buf[j] == ' ') + continue; + vendor_length = j+1; + break; + } + buf[vendor_length] = ' '; + buf[vendor_length+1] = '\0'; + vendor_length++; } - buf[vendor_length] = ' '; - buf[vendor_length+1] = '\0'; - vendor_length++; + close(fd); } - close(fd); } // Read model name - char *dirpath = strrchr(path, '/'); + + // Filename can be model or vendor, simpler to use same code in both cases + strcpy(buf, path); + char *dirpath = strrchr(buf, '/'); strcpy(dirpath+1, "model"); fd = open(path, O_RDONLY); if (fd == -1) { -- cgit v1.2.1