]> mj.ucw.cz Git - pciutils.git/blobdiff - lib/dump.c
lspci: Fix "Auxiliary" spelling error
[pciutils.git] / lib / dump.c
index 0915b005e503265fbd45f1d02a50b98db7e89c33..59cf7ed432d82db7d0ccb8ceded76538533f186c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     The PCI Library -- Reading of Bus Dumps
  *
- *     Copyright (c) 1997--2005 Martin Mares <mj@ucw.cz>
+ *     Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
@@ -18,10 +18,17 @@ struct dump_data {
   byte data[1];
 };
 
+static void
+dump_config(struct pci_access *a)
+{
+  pci_define_param(a, "dump.name", "", "Name of the bus dump file to read from");
+}
+
 static int
 dump_detect(struct pci_access *a)
 {
-  return !!a->method_params[PCI_ACCESS_DUMP];
+  char *name = pci_get_param(a, "dump.name");
+  return name && name[0];
 }
 
 static void
@@ -41,7 +48,7 @@ dump_validate(char *s, char *fmt)
     {
       if (*fmt == '#' ? !isxdigit(*s) : *fmt != *s)
        return 0;
-      *fmt++, *s++;
+      fmt++, s++;
     }
   return 1;
 }
@@ -49,13 +56,13 @@ dump_validate(char *s, char *fmt)
 static void
 dump_init(struct pci_access *a)
 {
-  char *name = a->method_params[PCI_ACCESS_DUMP];
+  char *name = pci_get_param(a, "dump.name");
   FILE *f;
   char buf[256];
   struct pci_dev *dev = NULL;
   int len, mn, bn, dn, fn, i, j;
 
-  if (!a)
+  if (!name)
     a->error("dump: File name not given.");
   if (!(f = fopen(name, "r")))
     a->error("dump: Cannot open %s: %s", name, strerror(errno));
@@ -63,7 +70,10 @@ dump_init(struct pci_access *a)
     {
       char *z = strchr(buf, '\n');
       if (!z)
-       a->error("dump: line too long or unterminated");
+       {
+         fclose(f);
+         a->error("dump: line too long or unterminated");
+       }
       *z-- = 0;
       if (z >= buf && *z == '\r')
        *z-- = 0;
@@ -88,7 +98,10 @@ dump_init(struct pci_access *a)
                 sscanf(z, "%x", &j) == 1 && j < 256)
            {
              if (i >= 4096)
-               a->error("dump: At most 4096 bytes of config space are supported");
+               {
+                 fclose(f);
+                 a->error("dump: At most 4096 bytes of config space are supported");
+               }
              if (i >= dd->allocated)   /* Need to re-allocate the buffer */
                {
                  dump_alloc_data(dev, 4096);
@@ -104,9 +117,13 @@ dump_init(struct pci_access *a)
                z++;
            }
          if (*z)
-           a->error("dump: Malformed line");
+           {
+             fclose(f);
+             a->error("dump: Malformed line");
+           }
        }
     }
+  fclose(f);
 }
 
 static void
@@ -157,7 +174,8 @@ dump_cleanup_dev(struct pci_dev *d)
 
 struct pci_methods pm_dump = {
   "dump",
-  NULL,                                        /* config */
+  "Reading of register dumps (set the `dump.name' parameter)",
+  dump_config,
   dump_detect,
   dump_init,
   dump_cleanup,
@@ -165,6 +183,7 @@ struct pci_methods pm_dump = {
   pci_generic_fill_info,
   dump_read,
   dump_write,
+  NULL,                                        /* read_vpd */
   NULL,                                        /* init_dev */
   dump_cleanup_dev
 };