From d8b462341b5cee958671aaeb8718fc0b3c92a78f Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Wed, 21 Mar 2001 18:03:32 +0000 Subject: if subid can be useful, use them. use probe_type==-1 to ensure no subid is used --- libldetect-private.h | 2 +- lspcidrake.c | 2 +- pci.c | 22 ++++++++++------------ pciusb.c | 29 ++++++++++++++++++++++------- usb.c | 11 ++--------- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/libldetect-private.h b/libldetect-private.h index 6a27497..4e473f6 100644 --- a/libldetect-private.h +++ b/libldetect-private.h @@ -1,2 +1,2 @@ -extern void pciusb_find_modules(struct pciusb_entries entries, const char *fpciusbtable); +extern int pciusb_find_modules(struct pciusb_entries entries, const char *fpciusbtable, int no_subid); extern void pciusb_initialize(struct pciusb_entry *e); diff --git a/lspcidrake.c b/lspcidrake.c index eb312c2..4bb987f 100644 --- a/lspcidrake.c +++ b/lspcidrake.c @@ -28,7 +28,7 @@ void usb_printit(struct pciusb_entries entries) { int main(int argc, char **argv) { { - struct pciusb_entries entries = pci_probe(1); + struct pciusb_entries entries = pci_probe(0); pci_printit(entries); pciusb_free(entries); } diff --git a/pci.c b/pci.c index 0ad3960..d0027eb 100644 --- a/pci.c +++ b/pci.c @@ -5,15 +5,8 @@ #include "libldetect-private.h" #include "common.h" -static void pci_find_modules(struct pciusb_entries entries) { - char *share_path = getenv("SHARE_PATH"); - char *pcitable; - - if (!share_path || !*share_path) share_path = "/usr/share"; - pcitable = alloca(strlen(share_path) + 32); /* enough for /ldetect-lst/pcitable and EOS */ - sprintf(pcitable, "%s/ldetect-lst/pcitable", share_path); - - pciusb_find_modules(entries, pcitable); +static int pci_find_modules(struct pciusb_entries entries, int no_subid) { + return pciusb_find_modules(entries, "pcitable", no_subid); } extern struct pciusb_entries pci_probe(int probe_type) { @@ -40,7 +33,7 @@ extern struct pciusb_entries pci_probe(int probe_type) { char file[25]; FILE *f; snprintf(file, sizeof(file), "/proc/bus/pci/%02x/%02x.%d", e.pci_bus, e.pci_device, e.pci_function); - if (probe_type && (f = fopen(file, "r"))) { + if (probe_type == 1 && (f = fopen(file, "r"))) { if (fseek(f, 10, SEEK_SET) == 0) fread(&e.class, 2, 1, f); if (fseek(f, 0x2c, SEEK_SET) == 0) @@ -59,7 +52,12 @@ extern struct pciusb_entries pci_probe(int probe_type) { fclose(f); r.entries = memdup(t, sizeof(struct pciusb_entry) * r.nb); - pci_find_modules(r); - return r; + if (pci_find_modules(r, probe_type)) return r; + + /* ok, let's try again with subids */ + if (probe_type == 0) return pci_probe(1); + + /* should not happen */ + exit(1); } diff --git a/pciusb.c b/pciusb.c index 29b1d99..b023181 100644 --- a/pciusb.c +++ b/pciusb.c @@ -5,13 +5,20 @@ #include "libldetect-private.h" #include "common.h" -extern void pciusb_find_modules(struct pciusb_entries entries, const char *fpciusbtable) { +extern int pciusb_find_modules(struct pciusb_entries entries, const char *fpciusbtable, int no_subid) { FILE *f; char buf[2048]; int line; - if (!(f = fopen(fpciusbtable, "r"))) { - fprintf(stderr, "Missing pciusbtable (should be %s)\n", fpciusbtable); + char *share_path = getenv("SHARE_PATH"); + char *fname; + if (!share_path || !*share_path) share_path = "/usr/share"; + + fname = alloca(strlen(share_path) + sizeof("/ldetect-lst/") + strlen(fpciusbtable)); + sprintf(fname, "%s/ldetect-lst/%s", share_path, fpciusbtable); + + if (!(f = fopen(fname, "r"))) { + fprintf(stderr, "Missing pciusbtable (should be %s)\n", fname); exit(1); } for (line = 1; fgets(buf, sizeof(buf) - 1, f); line++) { @@ -27,8 +34,14 @@ extern void pciusb_find_modules(struct pciusb_entries entries, const char *fpciu } for (i = 0; i < entries.nb; i++) { struct pciusb_entry *e = &entries.entries[i]; - if (vendor == e->vendor && device == e->device && - (nb != 4 || (subvendor == e->subvendor && subdevice == e->subdevice)) && !e->module) { + if (vendor == e->vendor && device == e->device) { + if (nb == 4 && e->subvendor == 0xffff && e->subdevice == 0xffff && !no_subid) { + pciusb_free(entries); + fclose(f); + return 0; /* leave, let the caller call again with subids */ + } + + if ((nb != 4 || (subvendor == e->subvendor && subdevice == e->subdevice)) && !e->module) { char *p = buf + offset + 1; char *q = strchr(p, '\t'); if (q) { @@ -37,10 +50,12 @@ extern void pciusb_find_modules(struct pciusb_entries entries, const char *fpciu e->module = strcmp(p, "unknown") ? strdup(p) : NULL; e->text = strdup(q+2); } - } - } + } + } + } } fclose(f); + return 1; } extern void pciusb_initialize(struct pciusb_entry *e) { diff --git a/usb.c b/usb.c index 2f5fa3a..4c6e8d0 100644 --- a/usb.c +++ b/usb.c @@ -5,15 +5,8 @@ #include "libldetect-private.h" #include "common.h" -static void usb_find_modules(struct pciusb_entries entries) { - char *share_path = getenv("SHARE_PATH"); - char *usbtable; - - if (!share_path || !*share_path) share_path = "/usr/share"; - usbtable = alloca(strlen(share_path) + 32); /* enough for /ldetect-lst/pcitable and EOS */ - sprintf(usbtable, "%s/ldetect-lst/usbtable", share_path); - - pciusb_find_modules(entries, usbtable); +static int usb_find_modules(struct pciusb_entries entries) { + return pciusb_find_modules(entries, "usbtable", 1 /* no_subid */); } extern struct pciusb_entries usb_probe(void) { -- cgit v1.2.1