From b450bae44d70bb2710bd00ea06a34fe431f42402 Mon Sep 17 00:00:00 2001 From: Guillaume Cottenceau Date: Thu, 22 Mar 2001 23:25:56 +0000 Subject: - fix detection of more than 3 scsi attached devices - cleaner code for cmp of ptr against static strings --- mdk-stage1/probing.c | 29 +++++++++++++++++++---------- mdk-stage1/tools.h | 2 ++ 2 files changed, 21 insertions(+), 10 deletions(-) (limited to 'mdk-stage1') diff --git a/mdk-stage1/probing.c b/mdk-stage1/probing.c index 46bc79acc..93c1614ba 100644 --- a/mdk-stage1/probing.c +++ b/mdk-stage1/probing.c @@ -195,7 +195,7 @@ static struct media_info * medias = NULL; static void find_media(void) { char b[50]; - char buf[500]; + char buf[5000]; struct media_info tmp[50]; int count; int fd; @@ -212,6 +212,10 @@ static void find_media(void) strcpy(b, "/proc/ide/hd"); for (b[12] = 'a'; b[12] <= 'h'; 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'; @@ -237,13 +241,13 @@ static void find_media(void) buf[i] = '\0'; close(fd); - if (!strncmp(buf, "disk", strlen("disk"))) + if (ptr_begins_static_str(buf, ide_disk)) tmp[count].type = DISK; - else if (!strncmp(buf, "cdrom", strlen("cdrom"))) + else if (ptr_begins_static_str(buf, ide_cdrom)) tmp[count].type = CDROM; - else if (!strncmp(buf, "tape", strlen("tape"))) + else if (ptr_begins_static_str(buf, ide_tape)) tmp[count].type = TAPE; - else if (!strncmp(buf, "floppy", strlen("floppy"))) + else if (ptr_begins_static_str(buf, ide_floppy)) tmp[count].type = FLOPPY; else tmp[count].type = UNKNOWN_MEDIA; @@ -285,7 +289,12 @@ static void find_media(void) char scsi_cdrom_count = '0'; char scsi_tape_count = '0'; - int i = read(fd, &buf, sizeof(buf)); + 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; @@ -293,7 +302,7 @@ static void find_media(void) close(fd); buf[i] = '\0'; - if (!strncmp(buf, "Attached devices: none", strlen("Attached devices: none"))) + if (ptr_begins_static_str(buf, scsi_no_devices)) goto end_scsi; start = buf; @@ -308,19 +317,19 @@ static void find_media(void) switch (state) { case SCSI_TOP: - if (strncmp(start, "Attached devices: ", strlen("Attached devices: "))) + if (!ptr_begins_static_str(start, scsi_some_devices)) goto end_scsi; state = SCSI_HOST; break; case SCSI_HOST: - if (strncmp(start, "Host: ", strlen("Host: "))) + if (!ptr_begins_static_str(start, scsi_host)) goto end_scsi; state = SCSI_VENDOR; break; case SCSI_VENDOR: - if (strncmp(start, " Vendor: ", strlen(" Vendor: "))) + if (!ptr_begins_static_str(start, scsi_vendor)) goto end_scsi; /* (1) Grab Vendor info */ diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h index 8ec084451..85295492b 100644 --- a/mdk-stage1/tools.h +++ b/mdk-stage1/tools.h @@ -46,5 +46,7 @@ struct param_elem char * value; }; +#define ptr_begins_static_str(pointer,static_str) (!strncmp(pointer,static_str,sizeof(static_str)-1)) + #endif -- cgit v1.2.1