]> git.openfabrics.org - ~adrianc/mstflint.git/commitdiff
Actual format for device softlink looks like this: /sys/class/infiniband/mthca0/device ->
authorMichael S. Tsirkin <mst@mellanox.co.il>
Thu, 14 Dec 2006 11:58:34 +0000 (13:58 +0200)
committerMichael S. Tsirkin <mst@mellanox.co.il>
Thu, 14 Dec 2006 12:08:23 +0000 (14:08 +0200)
../../../devices/pci0000:00/0000:00:04.0/0000:03:00.2/0000:05:01.0/0000:06:00.0
directory hierarchy mirros the bus hierarchy.
So we should only parse the basename when looking for the device location.

mtcr.h

diff --git a/mtcr.h b/mtcr.h
index d751dd6f3a3fddccc5e9b1cb742fe2cfeac21d3a..9a9a0f78c118ebd43b9844308295df48d090ee62 100644 (file)
--- a/mtcr.h
+++ b/mtcr.h
@@ -69,6 +69,7 @@
 #include <fcntl.h>
 #include <string.h>
 #include <stdlib.h>
+#include <libgen.h>
 
 
 #if CONFIG_ENABLE_MMAP
@@ -175,6 +176,7 @@ int mfind(const char* name, off_t* offset_p,
   if (scnt == 1) {
          char mbuf[4048];
          char pbuf[4048];
+         char *base;
 
          tmp = snprintf(mbuf, sizeof mbuf, "/sys/class/infiniband/%s/device", name);
          if (tmp <= 0 || tmp >= (int)sizeof mbuf) {
@@ -188,10 +190,11 @@ int mfind(const char* name, off_t* offset_p,
                  return 1;
          }
 
-         scnt = sscanf(pbuf, "../../../devices/pci%x:%x/%x:%x:%x.%x/%x:%x:%x.%x",
-                       &tmp, &tmp, &tmp, &tmp, &tmp, &tmp,
+         base = basename(pbuf);
+         if (!base) goto name_parsed;
+         scnt = sscanf(base, "%x:%x:%x.%x",
                        & my_domain, & my_bus, & my_dev, & my_func);    
-         if (scnt == 10) goto name_parsed;
+         if (scnt == 4) goto name_parsed;
   }
 
   scnt=sscanf(name,"%x:%x.%x", & my_bus, & my_dev, & my_func);