sd_bus_message_read_strv_extend;
sd_bus_error_setfv;
+ sd_device_new_child;
+
sd_id128_string_equal;
sd_hwdb_new_from_path;
return 0;
}
+_public_ int sd_device_new_child(sd_device **ret, sd_device *device, const char *suffix) {
+ _cleanup_free_ char *path = NULL;
+ const char *s;
+ int r;
+
+ assert_return(ret, -EINVAL);
+ assert_return(device, -EINVAL);
+ assert_return(suffix, -EINVAL);
+
+ if (!path_is_normalized(suffix))
+ return -EINVAL;
+
+ r = sd_device_get_syspath(device, &s);
+ if (r < 0)
+ return r;
+
+ path = path_join(s, suffix);
+ if (!path)
+ return -ENOMEM;
+
+ return sd_device_new_from_syspath(ret, path);
+}
+
static int device_new_from_child(sd_device **ret, sd_device *child) {
_cleanup_free_ char *path = NULL;
const char *syspath;
if (!streq_ptr(s, "wlan"))
return -EOPNOTSUPP;
- r = sd_device_get_syspath(link->dev, &s);
- if (r < 0)
- return r;
-
- s = strjoina(s, "/phy80211");
- r = sd_device_new_from_syspath(&phy, s);
+ r = sd_device_new_child(&phy, link->dev, "phy80211");
if (r < 0)
return r;
int sd_device_new_from_ifname(sd_device **ret, const char *ifname);
int sd_device_new_from_ifindex(sd_device **ret, int ifindex);
+int sd_device_new_child(sd_device **ret, sd_device *device, const char *suffix);
+
int sd_device_get_parent(sd_device *child, sd_device **ret);
int sd_device_get_parent_with_subsystem_devtype(sd_device *child, const char *subsystem, const char *devtype, sd_device **ret);
#include <linux/pci_regs.h>
#include "alloc-util.h"
-#include "chase-symlinks.h"
#include "device-util.h"
#include "dirent-util.h"
#include "fd-util.h"
return r;
/* Get physical function's pci device. */
- physfn_syspath = strjoina(syspath, "/physfn");
- r = sd_device_new_from_syspath(&physfn_pcidev, physfn_syspath);
+ r = sd_device_new_child(&physfn_pcidev, pcidev, "physfn");
if (r < 0)
return r;
return -errno;
FOREACH_DIRENT_ALL(de, dir, break) {
- _cleanup_free_ char *virtfn_link_file = NULL, *virtfn_pci_syspath = NULL;
- const char *n;
+ _cleanup_(sd_device_unrefp) sd_device *virtfn_pcidev = NULL;
+ const char *n, *s;
n = startswith(de->d_name, "virtfn");
if (!n)
continue;
- virtfn_link_file = path_join(physfn_syspath, de->d_name);
- if (!virtfn_link_file)
- return -ENOMEM;
+ if (sd_device_new_child(&virtfn_pcidev, physfn_pcidev, de->d_name) < 0)
+ continue;
- if (chase_symlinks(virtfn_link_file, NULL, 0, &virtfn_pci_syspath, NULL) < 0)
+ if (sd_device_get_syspath(virtfn_pcidev, &s) < 0)
continue;
- if (streq(syspath, virtfn_pci_syspath)) {
+ if (streq(s, syspath)) {
char *suffix;
suffix = strjoin("v", n);