[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#478696: [libpciaccess-dev] unable to parse vendor/device information from pci.ids.gz



Hi Ian,

our pciutils maintainer decided to only install the compressed
pci.ids.gz file, which breaks the code in libpciaccess that parses
pci.ids.  Kel was kind enough to write up a patch to make this work (see
below), would you consider something like this?  I'll try to finish up
the patch if you think this is an option.

Cheers,
Julien

On Thu, May  8, 2008 at 18:53:57 +1000, Kel Modderman wrote:

> On Wednesday 30 April 2008 22:44:42 Julien Cristau wrote:
> > > 2) Patch libpciaccess to support either situation, support gzip file streams
> > > and depend on associated libs to do that
> > > 
> > Patches welcome :)
> 
> Here is a patch. It is incomplete; there should be some associated autoconf
> changes to check for zlib.h, set some variable such as PCIIDS_COMPRESSED and
> apply the required linker flags. I am an autoconf virgin, and without any real
> desire to pop that cherry. Am hoping you guys would be able to help with that
> part.
> 
> If zlib support is not wanted, old behaviour is preserved. If zlib is wanted,
> but the pci.ids are uncompressed everything works ok too. The code is an
> adaptation of that found in pciutils-3.0.0/lib/names-parse.c.
> 
> Thanks, Kel.
> ---
> diff -Nrup libpciaccess-0.10/src/common_device_name.c libpciaccess-0.10-gz/src/common_device_name.c
> --- libpciaccess-0.10/src/common_device_name.c	2008-03-07 06:22:48.000000000 +1000
> +++ libpciaccess-0.10-gz/src/common_device_name.c	2008-05-08 18:04:40.000000000 +1000
> @@ -50,6 +50,31 @@
>  
>  #define DO_MATCH(a,b)  (((a) == PCI_MATCH_ANY) || ((a) == (b)))
>  
> +#ifdef PCIIDS_COMPRESSED
> +#include <zlib.h>
> +typedef gzFile pci_id_file;
> +
> +static pci_id_file
> +pci_id_file_open()
> +{
> +    pci_id_file result;
> +
> +    result = gzopen(PCIIDS_PATH "/pci.ids.gz", "rb");
> +    if (result)
> +        return result;
> +
> +    return gzopen(PCIIDS_PATH "/pci.ids", "rb");
> +}
> +
> +#define pci_id_file_gets(l, s, f)	gzgets(f, l, s)
> +#define pci_id_file_close(f)		gzclose(f)
> +#else
> +typedef FILE pci_id_file;
> +#define pci_id_file_open()		fopen(PCIIDS_PATH "/pci.ids", "r");
> +#define pci_id_file_gets(l, s, f)	fgets(l, s, f)
> +#define pci_id_file_close(f)		fclose(f)
> +#endif
> +
>  /**
>   * Node for sorting vendor IDs.
>   * 
> @@ -96,12 +121,6 @@ struct pci_device_leaf {
>  _pci_hidden struct pci_id_node * tree = NULL;
>  
>  /**
> - * Name of the file containing the PCI ID information.
> - */
> -static const char pci_id_file[] = PCIIDS_PATH "/pci.ids";
> -
> -
> -/**
>   * Get a pointer to the leaf node for a vendor ID.
>   * 
>   * If the vendor ID does not exist in the tree, it is added.
> @@ -170,7 +189,7 @@ insert( uint16_t vendor )
>  static void
>  populate_vendor( struct pci_id_leaf * vend, int fill_device_data )
>  {
> -    FILE * f = fopen( pci_id_file, "r" );
> +    pci_id_file * f = pci_id_file_open();
>      char buf[128];
>      unsigned vendor = PCI_MATCH_ANY;
>  
> @@ -186,12 +205,12 @@ populate_vendor( struct pci_id_leaf * ve
>       * anything.  This avoids wasted processing and potential memory leaks.
>       */
>      if (vend->num_devices != 0) {
> -	fclose(f);
> +	pci_id_file_close( f );
>  	return;
>      }
>  
>  
> -    while( fgets( buf, sizeof( buf ), f ) != NULL ) {
> +    while( pci_id_file_gets( buf, sizeof( buf ), f ) != NULL ) {
>  	unsigned num_tabs;
>  	char * new_line;
>  	size_t length;
> @@ -284,7 +303,7 @@ populate_vendor( struct pci_id_leaf * ve
>  	}
>      }
>      
> -    fclose( f );
> +    pci_id_file_close( f );
>  }
>  
>  



Reply to: