]> mj.ucw.cz Git - pciutils.git/commitdiff
proc: Work around broken /proc/bus/pci/ on some architectures.
authorMartin Mares <mj@ucw.cz>
Mon, 29 Jun 2009 17:55:24 +0000 (19:55 +0200)
committerMartin Mares <mj@ucw.cz>
Mon, 29 Jun 2009 17:55:24 +0000 (19:55 +0200)
Several architectures (e.g., sparc64) use domains in proc directory
names, which is inconsistent, because /proc/bus/pci/devices is still
unable to represent domains.

Work around it, so that the proc back-end works at least on single-domain
machines.

Suggested by Matthew Wilcox.

lib/proc.c

index e9ca24d019f40f93bcc40fd0136dd4caa921fafb..cb9d08d17768dd1379849ca505d58ebe33067fae 100644 (file)
@@ -130,6 +130,15 @@ proc_setup(struct pci_dev *d, int rw)
        a->error("File name too long");
       a->fd_rw = a->writeable || rw;
       a->fd = open(buf, a->fd_rw ? O_RDWR : O_RDONLY);
+      if (a->fd < 0)
+       {
+         e = snprintf(buf, sizeof(buf), "%s/%04x:%02x/%02x.%d",
+                      pci_get_param(a, "proc.path"),
+                      d->domain, d->bus, d->dev, d->func);
+         if (e < 0 || e >= (int) sizeof(buf))
+           a->error("File name too long");
+         a->fd = open(buf, a->fd_rw ? O_RDWR : O_RDONLY);
+       }
       if (a->fd < 0)
        a->warning("Cannot open %s", buf);
       a->cached_dev = d;