summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Terjan <pterjan@mageia.org>2020-06-11 21:25:41 +0000
committerPascal Terjan <pterjan@mageia.org>2020-06-11 21:25:41 +0000
commitcf9fb0d63dff31e5370229b2a99c95492b755ad1 (patch)
tree9e708b9068547a95b99e2aed10f76ffa1001aa45
parent7f41bb506568c9562b58b9837e20d414def3dcc6 (diff)
downloaddrakx-cf9fb0d63dff31e5370229b2a99c95492b755ad1.tar
drakx-cf9fb0d63dff31e5370229b2a99c95492b755ad1.tar.gz
drakx-cf9fb0d63dff31e5370229b2a99c95492b755ad1.tar.bz2
drakx-cf9fb0d63dff31e5370229b2a99c95492b755ad1.tar.xz
drakx-cf9fb0d63dff31e5370229b2a99c95492b755ad1.zip
Fix NVME code to work for disks with no vendor
-rw-r--r--mdk-stage1/NEWS2
-rw-r--r--mdk-stage1/probing.c58
2 files changed, 38 insertions, 22 deletions
diff --git a/mdk-stage1/NEWS b/mdk-stage1/NEWS
index e4fec4b16..0f50b7ce4 100644
--- a/mdk-stage1/NEWS
+++ b/mdk-stage1/NEWS
@@ -1,3 +1,5 @@
+- fix NVME code to work for disks with no vendor
+
2.44
- add support for NVME disks
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) {