diff options
Diffstat (limited to 'mdk-stage1')
-rw-r--r-- | mdk-stage1/NEWS | 2 | ||||
-rw-r--r-- | mdk-stage1/probing.c | 247 |
2 files changed, 13 insertions, 236 deletions
diff --git a/mdk-stage1/NEWS b/mdk-stage1/NEWS index c13134fc3..070b5747e 100644 --- a/mdk-stage1/NEWS +++ b/mdk-stage1/NEWS @@ -1,4 +1,4 @@ -- make VNME code really generic and reuse if for VirtIO and CCISS +- make VNME code really generic and reuse if for most other disks 2.45 diff --git a/mdk-stage1/probing.c b/mdk-stage1/probing.c index 251e3eb45..bce905686 100644 --- a/mdk-stage1/probing.c +++ b/mdk-stage1/probing.c @@ -568,11 +568,9 @@ static ssize_t read_attribute(char *path, char *buf) { void find_media(enum media_bus bus) { - char b[50]; char buf[5000]; struct media_info tmp[50]; int count = 0; - int fd; if (medias) free(medias); /* that does not free the strings, by the way */ @@ -581,233 +579,6 @@ void find_media(enum media_bus bus) probe_that_type(MEDIA_ADAPTERS, bus); /* ----------------------------------------------- */ - if (bus != BUS_IDE && bus != BUS_ANY) - goto find_media_after_ide; - log_message("looking for ide media"); - - strcpy(b, "/proc/ide/hd"); - for (b[12] = 'a'; b[12] <= 't'; b[12]++) { - int i; - char ide_disk[] = "disk"; - char ide_cdrom[] = "cdrom"; - char ide_tape[] = "tape"; - char ide_floppy[] = "floppy"; - - /* first, test if file exists (will tell if attached medium exists) */ - b[13] = '\0'; - if (access(b, R_OK)) - continue; - - tmp[count].name = strdup("hda"); - tmp[count].name[2] = b[12]; - - /* media type */ - strcpy(b + 13, "/media"); - 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("failed to read %s", b); - continue; - } - buf[i] = '\0'; - close(fd); - - if (ptr_begins_static_str(buf, ide_disk)) - tmp[count].type = DISK; - else if (ptr_begins_static_str(buf, ide_cdrom)) - tmp[count].type = CDROM; - else if (ptr_begins_static_str(buf, ide_tape)) - tmp[count].type = TAPE; - else if (ptr_begins_static_str(buf, ide_floppy)) - tmp[count].type = FLOPPY; - else - tmp[count].type = UNKNOWN_MEDIA; - - /* media model */ - strcpy(b + 13, "/model"); - 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 <= 0) { - log_message("failed to read %s", b); - tmp[count].model = strdup("(none)"); - } - else { - buf[i-1] = '\0'; /* eat the \n */ - tmp[count].model = strdup(buf); - } - close(fd); - - log_message("IDE/%d: %s is a %s", tmp[count].type, tmp[count].name, tmp[count].model); - count++; - } - - find_media_after_ide: - /* ----------------------------------------------- */ - if (bus != BUS_SCSI && bus != BUS_USB && bus != BUS_PCMCIA && bus != BUS_ANY) - goto find_media_after_scsi; - log_message("looking for scsi media"); - - fd = open("/proc/scsi/scsi", O_RDONLY); - if (fd != -1) { - FILE * f; - - enum { SCSI_TOP, SCSI_HOST, SCSI_VENDOR, SCSI_TYPE } state = SCSI_TOP; - char * start, * chptr, * next, * end; - char scsi_disk_count = 'a'; - char scsi_cdrom_count = '0'; - char scsi_tape_count = '0'; - - char scsi_no_devices[] = "Attached devices: none"; - char scsi_some_devices[] = "Attached devices:"; - char scsi_host[] = "Host: "; - char scsi_vendor[] = " Vendor: "; - - int i = read(fd, &buf, sizeof(buf)-1); - if (i < 1) { - close(fd); - goto end_scsi; - } - close(fd); - buf[i] = '\0'; - - if (ptr_begins_static_str(buf, scsi_no_devices)) - goto end_scsi; - - start = buf; - while (*start) { - char tmp_model[50]; - char tmp_name[10]; - - chptr = start; - while (*chptr != '\n') chptr++; - *chptr = '\0'; - next = chptr + 1; - - switch (state) { - case SCSI_TOP: - if (!ptr_begins_static_str(start, scsi_some_devices)) - goto end_scsi; - state = SCSI_HOST; - break; - - case SCSI_HOST: - if (!ptr_begins_static_str(start, scsi_host)) - goto end_scsi; - state = SCSI_VENDOR; - break; - - case SCSI_VENDOR: - if (!ptr_begins_static_str(start, scsi_vendor)) - goto end_scsi; - - /* (1) Grab Vendor info */ - start += 10; - end = chptr = strstr(start, "Model:"); - if (!chptr) - goto end_scsi; - - chptr--; - while (*chptr == ' ') - chptr--; - if (*chptr == ':') { - chptr++; - *(chptr + 1) = '\0'; - strcpy(tmp_model,"(unknown)"); - } else { - *(chptr + 1) = '\0'; - strcpy(tmp_model, start); - } - - /* (2) Grab Model info */ - start = end; - start += 7; - - chptr = strstr(start, "Rev:"); - if (!chptr) - goto end_scsi; - - chptr--; - while (*chptr == ' ') chptr--; - *(chptr + 1) = '\0'; - - strcat(tmp_model, " "); - strcat(tmp_model, start); - - tmp[count].model = strdup(tmp_model); - - state = SCSI_TYPE; - - break; - - case SCSI_TYPE: - if (strncmp(" Type:", start, 7)) - goto end_scsi; - *tmp_name = '\0'; - - if (strstr(start, "Direct-Access")) { - sprintf(tmp_name, "sd%c", scsi_disk_count++); - tmp[count].type = DISK; - } else if (strstr(start, "Sequential-Access")) { - sprintf(tmp_name, "st%c", scsi_tape_count++); - tmp[count].type = TAPE; - } else if (strstr(start, "CD-ROM")) { - sprintf(tmp_name, "sr%c", scsi_cdrom_count++); - tmp[count].type = CDROM; - } - - if (!(f = fopen("/proc/partitions", "rb")) || !fgets(buf, sizeof(buf), f) || !fgets(buf, sizeof(buf), f)) { - log_message("Couldn't open /proc/partitions"); - } else { - while (fgets(buf, sizeof(buf), f)) { - char name[100]; - int major, minor, blocks; - struct stat statbuf; - char *ptr; - memset(name, 0, sizeof(name)); - strcpy(name, "/dev/"); - sscanf(buf, " %d %d %d %s", &major, &minor, &blocks, &name[5]); - if (streq(&name[5], tmp_name) && tmp[count].type == DISK && ((blocks == 1048575) || (blocks == 1440))) - tmp[count].type = FLOPPY; - /* Try to create all devices while we have major/minor */ - if ((ptr = strchr(&name[5], '/'))) { - *ptr = '\0'; - if (stat(name, &statbuf)) - mkdir(name, 0755); - *ptr = '/'; - } - if (stat(name, &statbuf)) { - log_perror(name); - } - } - fclose(f); - } - - if (*tmp_name) { - tmp[count].name = strdup(tmp_name); - log_message("SCSI/%d: %s is a %s", tmp[count].type, tmp[count].name, tmp[count].model); - count++; - } - - state = SCSI_HOST; - } - - start = next; - } - - end_scsi:; - } - - /* ----------------------------------------------- */ log_message("looking for DAC960"); { FILE * f; @@ -844,8 +615,12 @@ void find_media(enum media_bus bus) // 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); - glob("/sys/block/cciss*", 0, NULL, &globbuf); + glob("/sys/block/vd*", GLOB_APPEND, NULL, &globbuf); + glob("/sys/block/cciss*", GLOB_APPEND, NULL, &globbuf); + glob("/sys/block/fd*", GLOB_APPEND, NULL, &globbuf); + glob("/sys/block/sd*", GLOB_APPEND, NULL, &globbuf); + glob("/sys/block/st*", GLOB_APPEND, NULL, &globbuf); + glob("/sys/block/sr*", GLOB_APPEND, NULL, &globbuf); for (int i = 0; i < globbuf.gl_pathc; i++) { char *name, *pathend; @@ -908,10 +683,13 @@ void find_media(enum media_bus bus) continue; } - if (caps & 0x0008) { + tmp[count].type = DISK; + if (caps & 0x0008 || !strncmp(name, "sr", 2)) { tmp[count].type = CDROM; - } else { - tmp[count].type = DISK; + } else if (!strncmp(name, "fd", 2)) { + tmp[count].type = FLOPPY; + } else if (!strncmp(name, "st", 2)) { + tmp[count].type = TAPE; } tmp[count].name = name; @@ -920,7 +698,6 @@ void find_media(enum media_bus bus) } globfree(&globbuf); } - find_media_after_scsi: /* ----------------------------------------------- */ tmp[count].name = NULL; |