Blame SOURCES/pciutils-dir-d.patch

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