massaged for gcc3.4
unconditional usb support usb probing fixed again
This commit is contained in:
parent
29f901523e
commit
a4108d4897
4
Makefile
4
Makefile
@ -54,7 +54,7 @@ include Makefile.common
|
||||
STAGE1BINS = $(METHODS:%=stage1-%)
|
||||
BINS = init $(STAGE1BINS)
|
||||
|
||||
DEFS = -DENABLE_USB
|
||||
DEFS =
|
||||
ifneq ($(WITH_SHELL),)
|
||||
DEFS += -DSPAWN_SHELL
|
||||
endif
|
||||
@ -112,7 +112,7 @@ ALLSRC = $(INITSRC) $(STAGE1SRC) $(MEDIASRC) $(NETWORKSRC)
|
||||
###############################################################################
|
||||
|
||||
STAGE1OBJS-MEDIA = $(subst .c,-MEDIA.o,$(STAGE1SRC) $(MEDIASRC))
|
||||
MEDIA_DEFS = -DDISABLE_NETWORK ##-DAUTO_METHOD=\""cdrom"\" -DAUTO_METHOD=\""disk"\"
|
||||
MEDIA_DEFS = -DDISABLE_NETWORK
|
||||
|
||||
STAGE1OBJS-NETWORK = $(subst .c,-NETWORK.o,$(STAGE1SRC) $(NETWORKSRC))
|
||||
NETWORK_DEFS = -DDISABLE_CDROM -DDISABLE_DISK
|
||||
|
691
probing.c
691
probing.c
@ -60,8 +60,6 @@ struct pci_module_map {
|
||||
struct pci_module_map * next;
|
||||
};
|
||||
|
||||
#ifndef DISABLE_USB
|
||||
|
||||
struct usb_module_map {
|
||||
unsigned short vendor; /* PCI vendor id */
|
||||
unsigned short device; /* PCI device id */
|
||||
@ -76,7 +74,6 @@ char *usb_hcd[] = {
|
||||
};
|
||||
|
||||
#define HCD_NUM (sizeof(usb_hcd) / sizeof(char *))
|
||||
#endif
|
||||
|
||||
static void warning_insmod_failed(enum insmod_return r)
|
||||
{
|
||||
@ -174,6 +171,229 @@ static struct pci_module_map * get_pci_ids()
|
||||
return pcidb;
|
||||
}
|
||||
|
||||
/* forward */
|
||||
static void probe_that_type(enum driver_type type);
|
||||
|
||||
/* ---- PCI probe ---------------------------------------------- */
|
||||
static void pci_probe(enum driver_type type)
|
||||
{
|
||||
FILE * f;
|
||||
int n;
|
||||
char buf[200];
|
||||
char devname[22];
|
||||
u_int8_t devdata[48];
|
||||
static int need_usb_hcd[HCD_NUM];
|
||||
struct pci_module_map * pci_ids = NULL;
|
||||
int that_class;
|
||||
|
||||
switch (type) {
|
||||
#ifndef DISABLE_MEDIAS
|
||||
case SCSI_ADAPTERS:
|
||||
that_class = PCI_CLASS_STORAGE_SCSI << 8;
|
||||
break;
|
||||
#endif
|
||||
#ifndef DISABLE_NETWORK
|
||||
#ifndef DISABLE_PCINET
|
||||
case NETWORK_DEVICES:
|
||||
that_class = PCI_CLASS_NETWORK_ETHERNET << 8;
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
case USB_CONTROLLERS:
|
||||
that_class = PCI_CLASS_SERIAL_USB << 8;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (NULL == (pci_ids = get_pci_ids())) {
|
||||
log_message("PCI: could not get pci ids");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(f = fopen("/proc/bus/pci/devices", "rb"))) {
|
||||
log_message("PCI: could not open proc file");
|
||||
return;
|
||||
}
|
||||
|
||||
while (NULL != fgets(buf, sizeof(buf), f)) {
|
||||
int i, dfn, vendor, device, class, subv, subid;
|
||||
struct pci_module_map * pcidb;
|
||||
|
||||
sscanf(buf, "%x %x", &dfn, &vendor);
|
||||
device = vendor & 0xFFFF; /* because scanf from dietlibc does not support %4f */
|
||||
vendor = (vendor >> 16) & 0xFFFF;
|
||||
|
||||
snprintf(devname, sizeof(devname), "/proc/bus/pci/%02x/%02x.%x",
|
||||
dfn >> 8, PCI_SLOT(dfn & 0xff), PCI_FUNC(dfn & 0xff));
|
||||
|
||||
log_message("gathering info for %s", devname);
|
||||
|
||||
if ((i = open(devname, O_RDONLY)) != -1) {
|
||||
read(i, devdata, sizeof(devdata));
|
||||
close(i);
|
||||
} else continue;
|
||||
|
||||
class = devdata[9] | (devdata[10] << 8) | (devdata[11] << 16);
|
||||
subv = devdata[0x2c] | (devdata[0x2d] << 8);
|
||||
subid = devdata[0x2e] | (devdata[0x2f] << 8);
|
||||
|
||||
log_message("found pci device: %04x %04x %06x %04x %04x",
|
||||
vendor, device, class, subv, subid);
|
||||
|
||||
for (pcidb = pci_ids; pcidb; pcidb = pcidb->next) {
|
||||
if (that_class == (class & 0xffff00) &&
|
||||
pcidb->vendor == vendor && pcidb->device == device) {
|
||||
log_message("module is \"%s\"", pcidb->module);
|
||||
#ifndef DISABLE_MEDIAS
|
||||
if (type == SCSI_ADAPTERS) {
|
||||
int wait_msg = 0;
|
||||
enum insmod_return failed;
|
||||
if (IS_AUTOMATIC) {
|
||||
wait_message("Loading driver for SCSI adapter:\n \n%s", pcidb->module);
|
||||
wait_msg = 1;
|
||||
} else
|
||||
stg1_info_message("About to load driver for SCSI adapter:\n \n%s", pcidb->module);
|
||||
failed = my_insmod(pcidb->module, SCSI_ADAPTERS, NULL);
|
||||
if (wait_msg)
|
||||
remove_wait_message();
|
||||
warning_insmod_failed(failed);
|
||||
}
|
||||
#endif /* DISABLE_MEDIAS */
|
||||
#ifndef DISABLE_NETWORK
|
||||
if (type == NETWORK_DEVICES) {
|
||||
stg1_info_message("About to load driver for network device:\n \n%s", pcidb->module);
|
||||
prepare_intf_descr(pcidb->module);
|
||||
warning_insmod_failed(my_insmod(pcidb->module, NETWORK_DEVICES, NULL));
|
||||
if (intf_descr_for_discover) /* for modules providing more than one net intf */
|
||||
net_discovered_interface(NULL);
|
||||
}
|
||||
#endif /* DISABLE_NETWORK */
|
||||
if (type == USB_CONTROLLERS) {
|
||||
/* found explicitly declared module */
|
||||
for (i=0; i < HCD_NUM; i++) {
|
||||
if(ptr_begins_static_str(pcidb->module, usb_hcd[i])) {
|
||||
log_message("found explicit %s", usb_hcd[i]);
|
||||
need_usb_hcd[i] = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* vendor & device matched */
|
||||
else {
|
||||
/* no module found, trying to identify one by class:
|
||||
HCD: PCI Class:
|
||||
uhci-hcd 0x000c0300
|
||||
ohci-hcd 0x000c0310
|
||||
ehci-hcd 0x000c0320
|
||||
*/
|
||||
if (type == USB_CONTROLLERS && (class & 0xffff0f) == 0x0c0300) {
|
||||
log_message("found by class %s", usb_hcd[(class & 0xf0)>>4]);
|
||||
need_usb_hcd[(class & 0xf0)>>4] = 1;
|
||||
}
|
||||
}
|
||||
} /* end of this vendor & device */
|
||||
} /* end of pci device list */
|
||||
|
||||
fclose(f);
|
||||
|
||||
/* load all usb controller modules now, starting from possible ehci-hcd */
|
||||
/* to prevent case when old-timed module sitting on newer host controller */
|
||||
if (type == USB_CONTROLLERS) {
|
||||
for (n=HCD_NUM-1; n; n--) {
|
||||
if (need_usb_hcd[n]) {
|
||||
stg1_info_message("About to load driver for usb controller: %s", usb_hcd[n]);
|
||||
my_insmod(usb_hcd[n], USB_CONTROLLERS, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- USB probe ---------------------------------------------- */
|
||||
static void usb_probe(enum driver_type type)
|
||||
{
|
||||
static int already_probed_usb_controllers = 0;
|
||||
static int already_mounted_usbdev = 0;
|
||||
|
||||
FILE * f;
|
||||
char buf[200];
|
||||
static struct usb_module_map * usb_ids = NULL;
|
||||
|
||||
switch (type) {
|
||||
#ifdef ENABLE_USBNET
|
||||
case NETWORK_DEVICES:
|
||||
/*
|
||||
usbdb = usbnet_usb_ids;
|
||||
*/
|
||||
break;
|
||||
#endif
|
||||
case SCSI_ADAPTERS:
|
||||
/*
|
||||
usbdb = usbstorage_usb_ids;
|
||||
*/
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (!already_probed_usb_controllers) {
|
||||
already_probed_usb_controllers = 1;
|
||||
probe_that_type(USB_CONTROLLERS);
|
||||
}
|
||||
|
||||
if (!already_mounted_usbdev) {
|
||||
already_mounted_usbdev = 1;
|
||||
if (mount("/proc/bus/usb", "/proc/bus/usb", "usbfs", 0, NULL)) {
|
||||
log_message("USB: couldn't mount /proc/bus/usb");
|
||||
return;
|
||||
}
|
||||
wait_message("Waiting for USB stuff to show up.");
|
||||
sleep(2); /* sucking background work */
|
||||
remove_wait_message();
|
||||
}
|
||||
|
||||
/* dirty hack */
|
||||
if (type == SCSI_ADAPTERS) {
|
||||
stg1_info_message("About to load driver for usb storage device: usb-storage");
|
||||
my_insmod("usb-storage", ANY_DRIVER_TYPE, NULL);
|
||||
}
|
||||
|
||||
if (!(f = fopen("/proc/bus/usb/devices", "rb"))) {
|
||||
log_message("USB: could not open proc file");
|
||||
return;
|
||||
}
|
||||
|
||||
while (NULL != fgets(buf, sizeof(buf), f)) {
|
||||
int vendor, device;
|
||||
struct usb_module_map * usbdb;
|
||||
|
||||
if (strstr(buf, "Keyboard")) {
|
||||
my_insmod("usbkbd", ANY_DRIVER_TYPE, NULL);
|
||||
my_insmod("keybdev", ANY_DRIVER_TYPE, NULL);
|
||||
}
|
||||
|
||||
if (sscanf(buf, "P: Vendor=%x ProdID=%x", &vendor, &device) != 2)
|
||||
continue;
|
||||
|
||||
for (usbdb = usb_ids; usbdb; usbdb = usbdb->next) {
|
||||
if (usbdb->vendor == vendor && usbdb->device == device) {
|
||||
log_message("USB: device %04x %04x is \"%s\"", vendor, device, usbdb->module);
|
||||
#ifdef ENABLE_USBNET
|
||||
if (type == NETWORK_DEVICES) {
|
||||
stg1_info_message("About to load driver for usb network device:\n \n%s", usbdb->module);
|
||||
prepare_intf_descr(usbdb->module);
|
||||
warning_insmod_failed(my_insmod(usbdb->module, NETWORK_DEVICES, NULL));
|
||||
if (intf_descr_for_discover) /* for modules providing more than one net intf */
|
||||
net_discovered_interface(NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void probe_that_type(enum driver_type type)
|
||||
{
|
||||
if (IS_EXPERT) {
|
||||
@ -181,246 +401,119 @@ static void probe_that_type(enum driver_type type)
|
||||
return;
|
||||
}
|
||||
|
||||
/* ---- PCI probe ---------------------------------------------- */
|
||||
{
|
||||
FILE * f;
|
||||
int n;
|
||||
char buf[200];
|
||||
char devname[22];
|
||||
u_int8_t devdata[48];
|
||||
struct pci_module_map * pci_ids = NULL;
|
||||
int that_class;
|
||||
|
||||
#ifdef ENABLE_USB
|
||||
static int need_usb_hcd[HCD_NUM];
|
||||
#endif
|
||||
|
||||
switch (type) {
|
||||
#ifndef DISABLE_MEDIAS
|
||||
case SCSI_ADAPTERS:
|
||||
that_class = PCI_CLASS_STORAGE_SCSI << 8;
|
||||
break;
|
||||
#endif
|
||||
#ifndef DISABLE_NETWORK
|
||||
#ifndef DISABLE_PCINET
|
||||
case NETWORK_DEVICES:
|
||||
that_class = PCI_CLASS_NETWORK_ETHERNET << 8;
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef ENABLE_USB
|
||||
case USB_CONTROLLERS:
|
||||
that_class = PCI_CLASS_SERIAL_USB << 8;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
goto end_pci_probe;
|
||||
}
|
||||
|
||||
if (NULL == (pci_ids = get_pci_ids())) {
|
||||
log_message("PCI: could not get pci ids");
|
||||
goto end_pci_probe;
|
||||
}
|
||||
|
||||
if (!(f = fopen("/proc/bus/pci/devices", "rb"))) {
|
||||
log_message("PCI: could not open proc file");
|
||||
goto end_pci_probe;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
int i, dfn, vendor, device, class, subv, subid;
|
||||
struct pci_module_map * pcidb;
|
||||
|
||||
if (!fgets(buf, sizeof(buf), f)) break;
|
||||
|
||||
sscanf(buf, "%x %x", &dfn, &vendor);
|
||||
device = vendor & 0xFFFF; /* because scanf from dietlibc does not support %4f */
|
||||
vendor = (vendor >> 16) & 0xFFFF;
|
||||
|
||||
snprintf(devname, sizeof(devname), "/proc/bus/pci/%02x/%02x.%x",
|
||||
dfn >> 8, PCI_SLOT(dfn & 0xff), PCI_FUNC(dfn & 0xff));
|
||||
|
||||
log_message("gathering info for %s", devname);
|
||||
|
||||
if ((i = open(devname, O_RDONLY)) != -1) {
|
||||
read(i, devdata, sizeof(devdata));
|
||||
close(i);
|
||||
} else continue;
|
||||
|
||||
class = devdata[9] | (devdata[10] << 8) | (devdata[11] << 16);
|
||||
subv = devdata[0x2c] | (devdata[0x2d] << 8);
|
||||
subid = devdata[0x2e] | (devdata[0x2f] << 8);
|
||||
|
||||
log_message("found pci device: %04x %04x %06x %04x %04x",
|
||||
vendor, device, class, subv, subid);
|
||||
|
||||
for (pcidb = pci_ids; pcidb; pcidb = pcidb->next) {
|
||||
if (that_class == (class & 0xffff00) &&
|
||||
pcidb->vendor == vendor && pcidb->device == device) {
|
||||
log_message("module is \"%s\"", pcidb->module);
|
||||
#ifndef DISABLE_MEDIAS
|
||||
if (type == SCSI_ADAPTERS) {
|
||||
int wait_msg = 0;
|
||||
enum insmod_return failed;
|
||||
if (IS_AUTOMATIC) {
|
||||
wait_message("Loading driver for SCSI adapter:\n \n%s", pcidb->module);
|
||||
wait_msg = 1;
|
||||
} else
|
||||
stg1_info_message("About to load driver for SCSI adapter:\n \n%s", pcidb->module);
|
||||
failed = my_insmod(pcidb->module, SCSI_ADAPTERS, NULL);
|
||||
if (wait_msg)
|
||||
remove_wait_message();
|
||||
warning_insmod_failed(failed);
|
||||
}
|
||||
#endif /* DISABLE_MEDIAS */
|
||||
#ifndef DISABLE_NETWORK
|
||||
if (type == NETWORK_DEVICES) {
|
||||
stg1_info_message("About to load driver for network device:\n \n%s", pcidb->module);
|
||||
prepare_intf_descr(pcidb->module);
|
||||
warning_insmod_failed(my_insmod(pcidb->module, NETWORK_DEVICES, NULL));
|
||||
if (intf_descr_for_discover) /* for modules providing more than one net intf */
|
||||
net_discovered_interface(NULL);
|
||||
}
|
||||
#endif /* DISABLE_NETWORK */
|
||||
#ifdef ENABLE_USB
|
||||
if (type == USB_CONTROLLERS) {
|
||||
/* found explicitly declared module */
|
||||
for (i=0; i < HCD_NUM; i++) {
|
||||
if(ptr_begins_static_str(pcidb->module, usb_hcd[i])) {
|
||||
log_message("found explicit %s", usb_hcd[i]);
|
||||
need_usb_hcd[i] = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_USB */
|
||||
} /* vendor & device matched */
|
||||
#ifdef ENABLE_USB
|
||||
else {
|
||||
/* no module found, trying to identify one by class:
|
||||
HCD: PCI Class:
|
||||
uhci-hcd 0x000c0300
|
||||
ohci-hcd 0x000c0310
|
||||
ehci-hcd 0x000c0320
|
||||
*/
|
||||
if (type == USB_CONTROLLERS && (class & 0xffff0f) == 0x0c0300) {
|
||||
log_message("found by class %s", usb_hcd[(class & 0xf0)>>4]);
|
||||
need_usb_hcd[(class & 0xf0)>>4] = 1;
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_USB */
|
||||
} /* end of this vendor & device */
|
||||
} /* end of pci device list */
|
||||
fclose(f);
|
||||
|
||||
#ifdef ENABLE_USB
|
||||
/* load all usb controller modules now, starting from possible ehci-hcd */
|
||||
/* to prevent case when old-timed module sitting on newer host controller */
|
||||
if (type == USB_CONTROLLERS) {
|
||||
for (n=HCD_NUM-1; n; n--) {
|
||||
if (need_usb_hcd[n]) {
|
||||
stg1_info_message("About to load driver for usb controller: %s", usb_hcd[n]);
|
||||
my_insmod(usb_hcd[n], USB_CONTROLLERS, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
end_pci_probe:
|
||||
}
|
||||
|
||||
#ifdef ENABLE_USB
|
||||
/* ---- USB probe ---------------------------------------------- */
|
||||
{
|
||||
static int already_probed_usb_controllers = 0;
|
||||
static int already_mounted_usbdev = 0;
|
||||
|
||||
FILE * f;
|
||||
char buf[200];
|
||||
static struct usb_module_map * usb_ids = NULL;
|
||||
|
||||
switch (type) {
|
||||
#ifdef ENABLE_USBNET
|
||||
case NETWORK_DEVICES:
|
||||
/*
|
||||
usbdb = usbnet_usb_ids;
|
||||
*/
|
||||
break;
|
||||
#endif
|
||||
case SCSI_ADAPTERS:
|
||||
/*
|
||||
usbdb = usbstorage_usb_ids;
|
||||
*/
|
||||
break;
|
||||
default:
|
||||
goto end_usb_probe;
|
||||
}
|
||||
|
||||
if (!already_probed_usb_controllers) {
|
||||
already_probed_usb_controllers = 1;
|
||||
probe_that_type(USB_CONTROLLERS);
|
||||
}
|
||||
|
||||
if (!already_mounted_usbdev) {
|
||||
already_mounted_usbdev = 1;
|
||||
if (mount("/proc/bus/usb", "/proc/bus/usb", "usbdevfs", 0, NULL)) {
|
||||
log_message("USB: couldn't mount /proc/bus/usb");
|
||||
goto end_usb_probe;
|
||||
}
|
||||
wait_message("Waiting for USB stuff to show up.");
|
||||
sleep(2); /* sucking background work */
|
||||
remove_wait_message();
|
||||
}
|
||||
|
||||
/* dirty hack */
|
||||
if (type == SCSI_ADAPTERS) {
|
||||
stg1_info_message("About to load driver for usb storage device: usb-storage");
|
||||
my_insmod("usb-storage", ANY_DRIVER_TYPE, NULL);
|
||||
}
|
||||
|
||||
if (!(f = fopen("/proc/bus/usb/devices", "rb"))) {
|
||||
log_message("USB: could not open proc file");
|
||||
goto end_usb_probe;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
int vendor, device;
|
||||
struct usb_module_map * usbdb;
|
||||
|
||||
if (!fgets(buf, sizeof(buf), f)) break;
|
||||
|
||||
if (strstr(buf, "Keyboard")) {
|
||||
my_insmod("usbkbd", ANY_DRIVER_TYPE, NULL);
|
||||
my_insmod("keybdev", ANY_DRIVER_TYPE, NULL);
|
||||
}
|
||||
|
||||
if (sscanf(buf, "P: Vendor=%x ProdID=%x", &vendor, &device) != 2)
|
||||
continue;
|
||||
|
||||
for (usbdb = usb_ids; usbdb; usbdb = usbdb->next) {
|
||||
if (usbdb->vendor == vendor && usbdb->device == device) {
|
||||
log_message("USB: device %04x %04x is \"%s\" (%s)", vendor, device, usbdb->module);
|
||||
#ifdef ENABLE_USBNET
|
||||
if (type == NETWORK_DEVICES) {
|
||||
stg1_info_message("About to load driver for usb network device:\n \n%s", usbdb->module);
|
||||
prepare_intf_descr(usbdb->module);
|
||||
warning_insmod_failed(my_insmod(usbdb->module, NETWORK_DEVICES, NULL));
|
||||
if (intf_descr_for_discover) /* for modules providing more than one net intf */
|
||||
net_discovered_interface(NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
end_usb_probe:
|
||||
}
|
||||
#endif
|
||||
pci_probe(type);
|
||||
usb_probe(type);
|
||||
}
|
||||
|
||||
|
||||
#ifndef DISABLE_MEDIAS
|
||||
static struct media_info * medias = NULL;
|
||||
|
||||
int find_scsi_media(char *buf, struct media_info *media)
|
||||
{
|
||||
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 count = 0;
|
||||
|
||||
if (ptr_begins_static_str(buf, scsi_no_devices)) return 0;
|
||||
|
||||
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)) return count;
|
||||
state = SCSI_HOST;
|
||||
break;
|
||||
|
||||
case SCSI_HOST:
|
||||
if (!ptr_begins_static_str(start, scsi_host)) return count;
|
||||
state = SCSI_VENDOR;
|
||||
break;
|
||||
|
||||
case SCSI_VENDOR:
|
||||
if (!ptr_begins_static_str(start, scsi_vendor)) return count;
|
||||
|
||||
/* (1) Grab Vendor info */
|
||||
start += 10;
|
||||
end = chptr = strstr(start, "Model:");
|
||||
if (!chptr) return count;
|
||||
|
||||
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) return count;
|
||||
|
||||
chptr--;
|
||||
while (*chptr == ' ') chptr--;
|
||||
*(chptr + 1) = '\0';
|
||||
|
||||
strcat(tmp_model, " ");
|
||||
strcat(tmp_model, start);
|
||||
|
||||
media->model = strdup(tmp_model);
|
||||
state = SCSI_TYPE;
|
||||
|
||||
break;
|
||||
|
||||
case SCSI_TYPE:
|
||||
if (strncmp(" Type:", start, 7)) return count;
|
||||
*tmp_name = '\0';
|
||||
|
||||
if (strstr(start, "Direct-Access")) {
|
||||
sprintf(tmp_name, "sd%c", scsi_disk_count++);
|
||||
media->type = DISK;
|
||||
} else if (strstr(start, "Sequential-Access")) {
|
||||
sprintf(tmp_name, "st%c", scsi_tape_count++);
|
||||
media->type = TAPE;
|
||||
} else if (strstr(start, "CD-ROM")) {
|
||||
sprintf(tmp_name, "sr%c", scsi_cdrom_count++);
|
||||
media->type = CDROM;
|
||||
}
|
||||
|
||||
if (*tmp_name) {
|
||||
media->name = strdup(tmp_name);
|
||||
log_message("SCSI/%d: %s is a %s", media->type, media->name, media->model);
|
||||
count++;
|
||||
media++;
|
||||
}
|
||||
|
||||
state = SCSI_HOST;
|
||||
}
|
||||
|
||||
start = next;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static void find_media(void)
|
||||
{
|
||||
char b[50];
|
||||
@ -505,132 +598,18 @@ static void find_media(void)
|
||||
count++;
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------- */
|
||||
log_message("looking for scsi media");
|
||||
|
||||
fd = open("/proc/scsi/scsi", O_RDONLY);
|
||||
if (fd != -1) {
|
||||
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";
|
||||
/* seems in 2.6 no trailing space exists */
|
||||
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;
|
||||
if (i > 1) {
|
||||
buf[i] = '\0';
|
||||
count += find_scsi_media(buf, &tmp[count]);
|
||||
}
|
||||
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 (*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 Compaq Smart Array media");
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user