Blame SOURCES/pciutils-dir-d.patch

eb2128
diff -up pciutils-3.0.0/lib/names-parse.c.dird pciutils-3.0.0/lib/names-parse.c
eb2128
--- pciutils-3.0.0/lib/names-parse.c.dird	2008-04-10 21:15:47.000000000 +0200
eb2128
+++ pciutils-3.0.0/lib/names-parse.c	2008-09-01 15:17:23.000000000 +0200
eb2128
@@ -6,10 +6,13 @@
eb2128
  *	Can be freely distributed and used under the terms of the GNU GPL.
eb2128
  */
eb2128
 
eb2128
+#define _GNU_SOURCE
eb2128
 #include <stdio.h>
eb2128
 #include <stdlib.h>
eb2128
 #include <string.h>
eb2128
 #include <errno.h>
eb2128
+#include <dirent.h>
eb2128
+#include <libgen.h>
eb2128
 
eb2128
 #include "internal.h"
eb2128
 #include "names.h"
eb2128
@@ -82,7 +85,7 @@ static inline int id_white_p(int c)
eb2128
 }
eb2128
 
eb2128
 
eb2128
-static const char *id_parse_list(struct pci_access *a, pci_file f, int *lino)
eb2128
+static const char *id_parse_list(struct pci_access *a, pci_file f, int *lino, int flags)
eb2128
 {
eb2128
   char line[MAX_LINE];
eb2128
   char *p;
eb2128
@@ -207,7 +210,7 @@ static const char *id_parse_list(struct 
eb2128
 	p++;
eb2128
       if (!*p)
eb2128
 	return parse_error;
eb2128
-      if (pci_id_insert(a, cat, id1, id2, id3, id4, p, SRC_LOCAL))
eb2128
+      if (pci_id_insert(a, cat, id1, id2, id3, id4, p, SRC_LOCAL) && flags)
eb2128
 	return "Duplicate entry";
eb2128
     }
eb2128
   return NULL;
eb2128
@@ -223,13 +226,14 @@ pci_load_name_list(struct pci_access *a)
eb2128
   pci_free_name_list(a);
eb2128
   a->id_load_failed = 1;
eb2128
   if (!(f = pci_open(a)))
eb2128
-    return 0;
eb2128
-  err = id_parse_list(a, f, &lino);
eb2128
+    return pci_new_load_name_list(a);
eb2128
+  err = id_parse_list(a, f, &lino, 0);
eb2128
   PCI_ERROR(f, err);
eb2128
   pci_close(f);
eb2128
   if (err)
eb2128
     a->error("%s at %s, line %d\n", err, a->id_file_name, lino);
eb2128
   a->id_load_failed = 0;
eb2128
+  pci_new_load_name_list(a);
eb2128
   return 1;
eb2128
 }
eb2128
 
eb2128
@@ -249,3 +253,49 @@ pci_set_name_list_path(struct pci_access
eb2128
   a->id_file_name = name;
eb2128
   a->free_id_name = to_be_freed;
eb2128
 }
eb2128
+int pci_new_load_name_list(struct pci_access *a)
eb2128
+{
eb2128
+  pci_file f;
eb2128
+  int lino, tempsize;
eb2128
+  const char *err;
eb2128
+  char *temp;
eb2128
+  char new_id_path[PATH_MAX+1] = {0,};
eb2128
+  DIR *pci_ids_dir;
eb2128
+  struct dirent *dp;
eb2128
+  
eb2128
+  strncpy(new_id_path, a->id_file_name, PATH_MAX);
eb2128
+  new_id_path[PATH_MAX] = 0;
eb2128
+  strncat(new_id_path, ".d/", PATH_MAX - strnlen(new_id_path, PATH_MAX));
eb2128
+  /* printf("new_id_path is %s\n", new_id_path); */
eb2128
+  pci_ids_dir = opendir(new_id_path); 
eb2128
+  if (pci_ids_dir == NULL)
eb2128
+    return 0;
eb2128
+
eb2128
+  do
eb2128
+    {
eb2128
+     if ((dp = readdir(pci_ids_dir)) != NULL)
eb2128
+       {
eb2128
+          if (! strcmp(dp->d_name, "..") || ! strcmp(dp->d_name, "."))
eb2128
+            continue;
eb2128
+          if (strstr(dp->d_name, ".ids")) 
eb2128
+            {
eb2128
+             tempsize = strnlen(new_id_path, PATH_MAX) + dp->d_reclen + 1;
eb2128
+             temp = malloc(tempsize);      /* This malloced memory is freed in the function pci_set_name_list_path() */ 
eb2128
+             memset(temp, 0, tempsize);
eb2128
+             strncpy(temp, new_id_path, (strnlen(new_id_path, PATH_MAX))+1);
eb2128
+             strncat(temp, dp->d_name, PATH_MAX - strnlen(temp, PATH_MAX));
eb2128
+             /* printf("Found file %s, processing it\n", temp); */
eb2128
+             pci_set_name_list_path(a, temp, 1);
eb2128
+             if (!(f = pci_open(a)))
eb2128
+               continue;
eb2128
+             err = id_parse_list(a, f, &lino, 0);
eb2128
+             PCI_ERROR(f, err);
eb2128
+             pci_close(f);
eb2128
+             if (err)
eb2128
+               a->error("%s at %s, line %d\n", err, a->id_file_name, lino);
eb2128
+            }
eb2128
+       }
eb2128
+    }while (dp != NULL);
eb2128
+  closedir(pci_ids_dir);
eb2128
+  return 1;
eb2128
+}   
eb2128
diff -up pciutils-3.0.0/lib/pci.h.dird pciutils-3.0.0/lib/pci.h
eb2128
--- pciutils-3.0.0/lib/pci.h.dird	2008-04-10 21:23:05.000000000 +0200
eb2128
+++ pciutils-3.0.0/lib/pci.h	2008-09-01 15:17:23.000000000 +0200
eb2128
@@ -194,6 +194,7 @@ int pci_load_name_list(struct pci_access
eb2128
 void pci_free_name_list(struct pci_access *a) PCI_ABI;	/* Called automatically by pci_cleanup() */
eb2128
 void pci_set_name_list_path(struct pci_access *a, char *name, int to_be_freed) PCI_ABI;
eb2128
 void pci_id_cache_flush(struct pci_access *a) PCI_ABI;
eb2128
+int pci_new_load_name_list(struct pci_access *a);
eb2128
 
eb2128
 enum pci_lookup_mode {
eb2128
   PCI_LOOKUP_VENDOR = 1,		/* Vendor name (args: vendorID) */