]> mj.ucw.cz Git - pciutils.git/blobdiff - lib/sysfs.c
pciutils: Decode available DVSEC details
[pciutils.git] / lib / sysfs.c
index 577982480fbc87f3c2d51f76307e7fe8123c58e2..42c88c69f7c2326eb2ada9b9deaa86c8c857c286 100644 (file)
@@ -119,6 +119,24 @@ sysfs_get_string(struct pci_dev *d, char *object, char *buf, int mandatory)
   return 1;
 }
 
+static char *
+sysfs_deref_link(struct pci_dev *d, char *link_name)
+{
+  char path[2*OBJNAMELEN], rel_path[OBJNAMELEN];
+
+  sysfs_obj_name(d, link_name, path);
+  memset(rel_path, 0, sizeof(rel_path));
+
+  if (readlink(path, rel_path, sizeof(rel_path)) < 0)
+    return NULL;
+
+  sysfs_obj_name(d, "", path);
+  strcat(path, rel_path);
+
+  // Returns a pointer to malloc'ed memory
+  return realpath(path, NULL);
+}
+
 static int
 sysfs_get_value(struct pci_dev *d, char *object, int mandatory)
 {
@@ -276,7 +294,7 @@ sysfs_fill_slots(struct pci_access *a)
        {
          for (d = a->devices; d; d = d->next)
            if (dom == (unsigned)d->domain && bus == d->bus && dev == d->dev && !d->phy_slot)
-             d->phy_slot = pci_strdup(a, entry->d_name);
+             d->phy_slot = pci_set_property(d, PCI_FILL_PHYS_SLOT, entry->d_name);
        }
       fclose(file);
     }
@@ -298,19 +316,29 @@ sysfs_fill_info(struct pci_dev *d, int flags)
     {
       char buf[OBJBUFSIZE];
       if (sysfs_get_string(d, "modalias", buf, 0))
-       d->module_alias = pci_strdup(d->access, buf);
+       d->module_alias = pci_set_property(d, PCI_FILL_MODULE_ALIAS, buf);
     }
 
   if ((flags & PCI_FILL_LABEL) && !(d->known_fields & PCI_FILL_LABEL))
     {
       char buf[OBJBUFSIZE];
       if (sysfs_get_string(d, "label", buf, 0))
-       d->label = pci_strdup(d->access, buf);
+       d->label = pci_set_property(d, PCI_FILL_LABEL, buf);
     }
 
   if ((flags & PCI_FILL_NUMA_NODE) && !(d->known_fields & PCI_FILL_NUMA_NODE))
     d->numa_node = sysfs_get_value(d, "numa_node", 0);
 
+  if ((flags & PCI_FILL_DT_NODE) && !(d->known_fields & PCI_FILL_DT_NODE))
+    {
+      char *node = sysfs_deref_link(d, "of_node");
+      if (node)
+       {
+         pci_set_property(d, PCI_FILL_DT_NODE, node);
+         free(node);
+       }
+    }
+
   return pci_generic_fill_info(d, flags);
 }