summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mdk-stage1/probing.c60
1 files changed, 24 insertions, 36 deletions
diff --git a/mdk-stage1/probing.c b/mdk-stage1/probing.c
index d97ecce69..c23ab517b 100644
--- a/mdk-stage1/probing.c
+++ b/mdk-stage1/probing.c
@@ -870,47 +870,13 @@ void find_media(enum media_bus bus)
}
}
/* ----------------------------------------------- */
- log_message("looking for VirtIO");
- {
- int fd, i;
- char b[50];
- char *name = b+11;
- strcpy(b, "/sys/block/vd");
- for (b[13] = 'a'; b[13] <= 'c'; b[13]++) {
- /* first, test if file exists (will tell if attached medium exists) */
- b[14] = '\0';
- if (access(b, R_OK))
- continue;
-
- tmp[count].name = strdup(name);
- tmp[count].type = DISK; //UNKNOWN_MEDIA;
- tmp[count].model = strdup("VirtIO disk");
-
- /* media type */
- strcpy(b + 14, "/capability");
- fd = open(b, O_RDONLY);
- if (fd == -1) {
- log_message("failed to open %s for reading", b);
- //continue;
- }
- i = read(fd, buf, sizeof(buf));
- if (i == -1) {
- log_message("Couldn't read capabilities file (%s)", b);
- } else {
- if (!strcmp(buf, "10"))
- tmp[count].type = DISK;
- }
-
- count++;
- }
- }
- /* ----------------------------------------------- */
log_message("looking for other disks");
{
glob_t globbuf;
// TODO: We should switch everything to here, and later switch to ignoring
// some types of disks (ram, loop, ...) rather than a list to accept.
glob("/sys/block/nvme*", 0, NULL, &globbuf);
+ glob("/sys/block/vd*", 0, NULL, &globbuf);
for (int i = 0; i < globbuf.gl_pathc; i++) {
char *name, *pathend;
@@ -948,8 +914,30 @@ void find_media(enum media_bus bus)
strcpy(pathend, "/device/model");
read_attribute(path, model+vendor_length);
+ strcpy(pathend, "/device/capability");
+ strcpy(buf, "0x0");
+ read_attribute(path, buf+3);
+ int caps = atoi(buf);
+
+ if (!(caps & 0x0010)) {
+ log_message("Ignoring device %s (not up)", name);
+ free(name);
+ continue;
+ }
+
+ if (caps & 0x0400) {
+ log_message("Ignoring device %s (hidden)", name);
+ free(name);
+ continue;
+ }
+
+ if (caps & 0x0008) {
+ tmp[count].type = CDROM;
+ } else {
+ tmp[count].type = DISK;
+ }
+
tmp[count].name = name;
- tmp[count].type = DISK;
tmp[count].model = strdup(model);
count++;
}