]> mj.ucw.cz Git - pciutils.git/blobdiff - lib/filter.c
Let filters accept vendor and device 0xffff.
[pciutils.git] / lib / filter.c
index 299af2994998338e3034cebc113c8d24ed845c5a..2bedc95e050a4f168b356747211129e31a3fe4da 100644 (file)
@@ -1,9 +1,7 @@
 /*
- *     $Id: filter.c,v 1.1 1999/01/22 21:05:22 mj Exp $
+ *     The PCI Library -- Device Filtering
  *
- *     Linux PCI Library -- Device Filtering
- *
- *     Copyright (c) 1998--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
+ *     Copyright (c) 1998--2003 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
 #include "internal.h"
 
 void
-pci_filter_init(struct pci_access * UNUSED a, struct pci_filter *f)
+pci_filter_init(struct pci_access *a UNUSED, struct pci_filter *f)
 {
-  f->bus = f->slot = f->func = -1;
+  f->domain = f->bus = f->slot = f->func = -1;
   f->vendor = f->device = -1;
 }
 
-/* Slot filter syntax: [[bus]:][slot][.[func]] */
+/* Slot filter syntax: [[[domain]:][bus]:][slot][.[func]] */
 
 char *
 pci_filter_parse_slot(struct pci_filter *f, char *str)
 {
-  char *colon = strchr(str, ':');
+  char *colon = strrchr(str, ':');
   char *dot = strchr((colon ? colon + 1 : str), '.');
   char *mid = str;
-  char *e;
+  char *e, *bus, *colon2;
 
   if (colon)
     {
       *colon++ = 0;
       mid = colon;
-      if (str[0] && strcmp(str, "*"))
+      colon2 = strchr(str, ':');
+      if (colon2)
+       {
+         *colon2++ = 0;
+         bus = colon2;
+         if (str[0] && strcmp(str, "*"))
+           {
+             long int x = strtol(str, &e, 16);
+             if ((e && *e) || (x < 0 || x > 0xffff))
+               return "Invalid domain number";
+             f->domain = x;
+           }
+       }
+      else
+       bus = str;
+      if (bus[0] && strcmp(bus, "*"))
        {
-         long int x = strtol(str, &e, 16);
-         if ((e && *e) || (x < 0 || x >= 0xff))
+         long int x = strtol(bus, &e, 16);
+         if ((e && *e) || (x < 0 || x > 0xff))
            return "Invalid bus number";
          f->bus = x;
        }
@@ -47,14 +60,14 @@ pci_filter_parse_slot(struct pci_filter *f, char *str)
   if (mid[0] && strcmp(mid, "*"))
     {
       long int x = strtol(mid, &e, 16);
-      if ((e && *e) || (x < 0 || x >= 0x1f))
+      if ((e && *e) || (x < 0 || x > 0x1f))
        return "Invalid slot number";
       f->slot = x;
     }
   if (dot && dot[0] && strcmp(dot, "*"))
     {
       long int x = strtol(dot, &e, 16);
-      if ((e && *e) || (x < 0 || x >= 7))
+      if ((e && *e) || (x < 0 || x > 7))
        return "Invalid function number";
       f->func = x;
     }
@@ -77,14 +90,14 @@ pci_filter_parse_id(struct pci_filter *f, char *str)
   if (str[0] && strcmp(str, "*"))
     {
       long int x = strtol(str, &e, 16);
-      if ((e && *e) || (x < 0 || x >= 0xffff))
+      if ((e && *e) || (x < 0 || x > 0xffff))
        return "Invalid vendor ID";
       f->vendor = x;
     }
   if (s[0] && strcmp(s, "*"))
     {
       long int x = strtol(s, &e, 16);
-      if ((e && *e) || (x < 0 || x >= 0xffff))
+      if ((e && *e) || (x < 0 || x > 0xffff))
        return "Invalid device ID";
       f->device = x;
     }
@@ -94,7 +107,8 @@ pci_filter_parse_id(struct pci_filter *f, char *str)
 int
 pci_filter_match(struct pci_filter *f, struct pci_dev *d)
 {
-  if ((f->bus >= 0 && f->bus != d->bus) ||
+  if ((f->domain >= 0 && f->domain != d->domain) ||
+      (f->bus >= 0 && f->bus != d->bus) ||
       (f->slot >= 0 && f->slot != d->dev) ||
       (f->func >= 0 && f->func != d->func))
     return 0;