fd = open("/proc/scsi/scsi", O_RDONLY);
if (fd < 0) {
logMessage("failed to open /proc/scsi/scsi: %s", strerror(errno));
return 1;
}
i = read(fd, buf, sizeof(buf) - 1);
if (i < 1) {
logMessage("failed to read /proc/scsi/scsi: %s", strerror(errno));
return 1;
}
close(fd);
buf[i] = '\0';
start = buf;
while (*start) {
chptr = start;
while (*chptr != '\n') chptr++;
*chptr = '\0';
next = chptr + 1;
switch (state) {
case SCSISCSI_TOP:
if (strcmp("Attached devices: ", start)) {
logMessage("unexpected line in /proc/scsi/scsi: %s", start);
free(sdi);
return INST_ERROR;
}
state = SCSISCSI_HOST;
break;
case SCSISCSI_HOST:
if (strncmp("Host: ", start, 6)) {
logMessage("unexpected line in /proc/scsi/scsi: %s", start);
free(sdi);
return INST_ERROR;
}
start = strstr(start, "Id: ");
if (!start) {
logMessage("Id: missing in /proc/scsi/scsi");
return INST_ERROR;
}
start += 4;
id = strtol(start, NULL, 10);
state = SCSISCSI_VENDOR;
break;
case SCSISCSI_VENDOR:
if (strncmp(" Vendor: ", start, 10)) {
logMessage("unexpected line in /proc/scsi/scsi: %s", start);
free(sdi);
return INST_ERROR;
}
start += 10;
chptr = strstr(start, "Model:");
if (!chptr) {
logMessage("Model missing in /proc/scsi/scsi");
free(sdi);
return INST_ERROR;
}