[Pkg-pciutils-discuss] Gzipped pci.ids file

Matthew Wilcox matthew at wil.cx
Sun Jun 18 04:00:27 UTC 2006


On Sat, Jun 17, 2006 at 04:27:17PM -0600, Matthew Wilcox wrote:
> How about compressing it?
> 
> -rw-r--r-- 1 willy willy 405596 Jun  6 08:02 pci.ids
> -rw-r--r-- 1 willy willy 117665 Jun  6 08:02 pci.ids.gz
> -rw-r--r-- 1 willy willy 108116 Jun  6 08:02 pci.ids.bz2
> 
> It shouldn't be hard to bolt a gunzip decompressor into libpci.

It isn't, thanks to the design of zlib and libpci matching.  I haven't
tried to tidy this up much; consider it a proof of concept.  Since it
adds a new dependency to pciutils, I think it's something that should
have to be automatically configured.

Also, update-pciids would need updating ... and change PCI_PATH_IDS ...
but this is a start.


Index: Makefile
===================================================================
RCS file: /cvsroot/pkg-pciutils/pciutils/Makefile,v
retrieving revision 1.11
diff -u -p -r1.11 Makefile
--- Makefile	6 Jun 2006 13:24:11 -0000	1.11
+++ Makefile	18 Jun 2006 03:57:27 -0000
@@ -17,6 +17,8 @@ DIRINSTALL=install -d
 PCILIB=lib/libpci.a
 PCIINC=lib/config.h lib/header.h lib/pci.h lib/types.h lib/sysdep.h
 
+LDFLAGS += -lz
+
 ifeq ($(shell uname),NetBSD)
 PCILIB=lib/libpciutils.a
 LDFLAGS+=-lpci
Index: lib/names.c
===================================================================
RCS file: /cvsroot/pkg-pciutils/pciutils/lib/names.c,v
retrieving revision 1.6
diff -u -p -r1.6 names.c
--- lib/names.c	6 Jun 2006 11:57:57 -0000	1.6
+++ lib/names.c	18 Jun 2006 03:57:27 -0000
@@ -11,6 +11,7 @@
 #include <stdarg.h>
 #include <string.h>
 #include <errno.h>
+#include <zlib.h>
 
 #include "internal.h"
 
@@ -141,7 +142,7 @@ static inline int id_white_p(int c)
   return (c == ' ') || (c == '\t');
 }
 
-static const char *id_parse_list(struct pci_access *a, FILE *f, int *lino)
+static const char *id_parse_list(struct pci_access *a, gzFile f, int *lino)
 {
   char line[MAX_LINE];
   char *p;
@@ -151,13 +152,13 @@ static const char *id_parse_list(struct 
   static const char parse_error[] = "Parse error";
 
   *lino = 0;
-  while (fgets(line, sizeof(line), f))
+  while (gzgets(f, line, sizeof(line)))
     {
       (*lino)++;
       p = line;
       while (*p && *p != '\n' && *p != '\r')
 	p++;
-      if (!*p && !feof(f))
+      if (!*p && !gzeof(f))
 	return "Line too long";
       *p = 0;
       if (p > line && (p[-1] == ' ' || p[-1] == '\t'))
@@ -275,20 +276,25 @@ static const char *id_parse_list(struct 
 int
 pci_load_name_list(struct pci_access *a)
 {
-  FILE *f;
-  int lino;
+  gzFile f;
+  int lino, errnum;
   const char *err;
 
   pci_free_name_list(a);
   a->hash_load_failed = 1;
-  if (!(f = fopen(a->id_file_name, "r")))
+  if (!(f = gzopen(a->id_file_name, "r")))
     return 0;
   a->id_hash = pci_malloc(a, sizeof(struct id_entry *) * HASH_SIZE);
   bzero(a->id_hash, sizeof(struct id_entry *) * HASH_SIZE);
   err = id_parse_list(a, f, &lino);
-  if (!err && ferror(f))
-    err = "I/O error";
-  fclose(f);
+  if (!err) {
+    err = gzerror(f, &errnum);
+    if (errnum == Z_ERRNO)
+      err = "I/O error";
+    else if (errnum >= 0)
+      err = NULL;
+  }
+  gzclose(f);
   if (err)
     a->error("%s at %s, line %d\n", err, a->id_file_name, lino);
   a->hash_load_failed = 0;



More information about the Pkg-pciutils-discuss mailing list