From: Michael S. Tsirkin Date: Thu, 14 Dec 2006 11:58:34 +0000 (+0200) Subject: Actual format for device softlink looks like this: /sys/class/infiniband/mthca0/device -> X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=d8e486a4495a0298cd19e9236fdfd89960eea846;p=~adrianc%2Fmstflint.git Actual format for device softlink looks like this: /sys/class/infiniband/mthca0/device -> ../../../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. --- diff --git a/mtcr.h b/mtcr.h index d751dd6..9a9a0f7 100644 --- a/mtcr.h +++ b/mtcr.h @@ -69,6 +69,7 @@ #include #include #include +#include #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);