dc004b9
diff --git a/Makefile.am b/Makefile.am
dc004b9
index 1349e7b..068dc10 100644
dc004b9
--- a/Makefile.am
dc004b9
+++ b/Makefile.am
dc004b9
@@ -1,12 +1,12 @@
dc004b9
-AM_CFLAGS = $(HBAAPI_CFLAGS) $(PCIACCESS_CFLAGS)
dc004b9
-AM_LDFLAGS= $(PCIACCESS_LIBS)
dc004b9
+AM_CFLAGS = $(HBAAPI_CFLAGS) $(PCIACCESS_CFLAGS) $(LIBUDEV_CFLAGS)
dc004b9
+AM_LDFLAGS= $(PCIACCESS_LIBS) $(LIBUDEV_LIBS)
dc004b9
 
dc004b9
 lib_LTLIBRARIES = libhbalinux.la
dc004b9
 libhbalinux_la_SOURCES = adapt.c adapt_impl.h api_lib.h bind.c bind_impl.h \
dc004b9
 fc_scsi.h fc_types.h lib.c lport.c net_types.h pci.c rport.c scsi.c sg.c \
dc004b9
 utils.c utils.h
dc004b9
 libhbalinux_la_LDFLAGS = -version-info 2:2:0
dc004b9
-libhbalinux_la_LIBADD = $(PCIACCESS_LIBS)
dc004b9
+libhbalinux_la_LIBADD = $(PCIACCESS_LIBS) $(LIBUDEV_LIBS)
dc004b9
 
dc004b9
 pkgconfigdir = $(libdir)/pkgconfig
dc004b9
 pkgconfig_DATA = libhbalinux.pc
dc004b9
diff --git a/adapt_impl.h b/adapt_impl.h
dc004b9
index d86c2f8..9d9a347 100644
dc004b9
--- a/adapt_impl.h
dc004b9
+++ b/adapt_impl.h
dc004b9
@@ -151,7 +151,7 @@ HBA_STATUS scsi_report_luns_v2(HBA_HANDLE, HBA_WWN, HBA_WWN,
dc004b9
 HBA_STATUS sg_issue_inquiry(const char *, HBA_UINT8, HBA_UINT8,
dc004b9
 		void *, HBA_UINT32 *, HBA_UINT8 *, void *, HBA_UINT32 *);
dc004b9
 
dc004b9
-void adapter_init(void);
dc004b9
+int adapter_init(void);
dc004b9
 void adapter_shutdown(void);
dc004b9
 
dc004b9
 /* struct port_stats; */
dc004b9
diff --git a/configure.ac b/configure.ac
dc004b9
index 8dadf29..758cadb 100644
dc004b9
--- a/configure.ac
dc004b9
+++ b/configure.ac
dc004b9
@@ -13,6 +13,10 @@ AC_SUBST(PCIACCESS_LIBS)
dc004b9
 PKG_CHECK_MODULES(HBAAPI, HBAAPI)
dc004b9
 AC_SUBST(HBAAPI_CFLAGS)
dc004b9
 
dc004b9
+PKG_CHECK_MODULES(LIBUDEV, libudev)
dc004b9
+AC_SUBST(LIBUDEV_CFLAGS)
dc004b9
+AC_SUBST(LIBUDEV_LIBS)
dc004b9
+
dc004b9
 AC_CONFIG_FILES([Makefile libhbalinux.spec libhbalinux.pc])
dc004b9
 AC_OUTPUT
dc004b9
 
dc004b9
diff --git a/libhbalinux.spec.in b/libhbalinux.spec.in
dc004b9
index 344c166..4690da9 100644
dc004b9
--- a/libhbalinux.spec.in
dc004b9
+++ b/libhbalinux.spec.in
dc004b9
@@ -9,7 +9,7 @@ URL:            http://www.open-fcoe.org
dc004b9
 Source0:        http://www.open-fcoe.org/openfc/%{name}-%{version}.tar.gz
dc004b9
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
dc004b9
 
dc004b9
-BuildRequires:  libHBAAPI-devel libpciaccess-devel
dc004b9
+BuildRequires:  libHBAAPI-devel libpciaccess-devel systemd-devel
dc004b9
 Requires:       libHBAAPI
dc004b9
 
dc004b9
 %description
dc004b9
diff --git a/lport.c b/lport.c
dc004b9
index bc34078..695bdc6 100644
dc004b9
--- a/lport.c
dc004b9
+++ b/lport.c
dc004b9
@@ -20,6 +20,8 @@
dc004b9
 #include "api_lib.h"
dc004b9
 #include "adapt_impl.h"
dc004b9
 
dc004b9
+#include <libudev.h>
dc004b9
+
dc004b9
 #ifndef HBA_STATUS_ERROR_ILLEGAL_FCID
dc004b9
 #define HBA_STATUS_ERROR_ILLEGAL_FCID 33	/* defined after HBA-API 2.2 */
dc004b9
 #endif
dc004b9
@@ -88,18 +90,16 @@ struct sa_nameval port_speeds_table[] = {
dc004b9
  * and convert them to bitmasks for the HBA_PORTSPEED supported
dc004b9
  * Format expected: "1 Gbit[, 10 Gbit]", etc.
dc004b9
  */
dc004b9
-static int sys_read_speed(const char *dir, const char *file, char *buf,
dc004b9
-			  size_t buflen, HBA_PORTSPEED *speeds)
dc004b9
+static int sys_read_speed(const char *speedstr, HBA_PORTSPEED *speeds)
dc004b9
 {
dc004b9
 	int rc = 0;
dc004b9
 	u_int32_t val = 0;
dc004b9
 	int len = 0;
dc004b9
-	char *cp;
dc004b9
+	const char *cp;
dc004b9
 	struct sa_nameval *tp = port_speeds_table;
dc004b9
 
dc004b9
-	rc = sa_sys_read_line(dir, file, buf, buflen);
dc004b9
-	if (rc == 0 && strstr(buf, "Unknown") == NULL) {
dc004b9
-		for (cp = buf; *cp != '\0';) {
dc004b9
+	if (rc == 0 && strstr(speedstr, "Unknown") == NULL) {
dc004b9
+		for (cp = speedstr; *cp != '\0';) {
dc004b9
 			for (; tp->nv_name != NULL; tp++) {
dc004b9
 				len = strlen(tp->nv_name);
dc004b9
 				if (strncasecmp(tp->nv_name, cp, len) == 0) {
dc004b9
@@ -140,69 +140,189 @@ counting_rports(struct dirent *dp, void *arg)
dc004b9
 	return HBA_STATUS_OK;
dc004b9
 }
dc004b9
 
dc004b9
-static int
dc004b9
-check_ifindex(struct dirent *dp, void *arg)
dc004b9
+static void 
dc004b9
+sysfs_scan_pci(struct udev_device *pci,
dc004b9
+	struct hba_info *hba_info,
dc004b9
+	HBA_ADAPTERATTRIBUTES *atp
dc004b9
+	)
dc004b9
 {
dc004b9
-	char *ifindex = (char *)arg;
dc004b9
-	char hba_dir[256];
dc004b9
+	const char *attr;
dc004b9
+	const char *hba_dir;
dc004b9
 	char buf[256];
dc004b9
-	int rc;
dc004b9
-
dc004b9
-	snprintf(hba_dir, sizeof(hba_dir),
dc004b9
-		 SYSFS_HBA_DIR "/%s", dp->d_name);
dc004b9
-	memset(buf, 0, sizeof(buf));
dc004b9
-	rc = sa_sys_read_line(hba_dir, "ifindex", buf, sizeof(buf) - 1);
dc004b9
-	if (rc)
dc004b9
-		return 0;
dc004b9
-	if (!strncmp(ifindex, buf, sizeof(buf))) {
dc004b9
-		strcpy(arg, dp->d_name);
dc004b9
-		return 1;
dc004b9
+	char *saveptr;	/* for strtok_r */
dc004b9
+
dc004b9
+	/* Get vendor_id */
dc004b9
+	attr = udev_device_get_sysattr_value(pci, "vendor");
dc004b9
+	hba_info->vendor_id = strtoul(attr, NULL, 0);
dc004b9
+
dc004b9
+	/* Get device_id */
dc004b9
+	attr = udev_device_get_sysattr_value(pci, "device");
dc004b9
+	hba_info->device_id = strtoul(attr, NULL, 0);
dc004b9
+
dc004b9
+	/* Get subsystem_vendor_id */
dc004b9
+	attr = udev_device_get_sysattr_value(pci, "subsystem_vendor");
dc004b9
+	hba_info->subsystem_vendor_id = strtoul(attr, NULL, 0);
dc004b9
+
dc004b9
+	/* Get subsystem_device_id */
dc004b9
+	attr = udev_device_get_sysattr_value(pci, "subsystem_device");
dc004b9
+	hba_info->subsystem_device_id = strtoul(attr, NULL, 0);
dc004b9
+
dc004b9
+	/* Get device_class */
dc004b9
+	attr = udev_device_get_sysattr_value(pci, "class");
dc004b9
+	hba_info->device_class = strtoul(attr, NULL, 0);
dc004b9
+	hba_info->device_class = hba_info->device_class>>8;
dc004b9
+
dc004b9
+	/*
dc004b9
+	 * Get Hardware Information via PCI Library
dc004b9
+	 */
dc004b9
+
dc004b9
+	sscanf(udev_device_get_sysname(pci), "%x:%x:%x:%x",
dc004b9
+			&hba_info->domain, &hba_info->bus,
dc004b9
+			&hba_info->dev, &hba_info->func);
dc004b9
+	(void) find_pci_device(hba_info);
dc004b9
+
dc004b9
+	/* Get Number of Ports */
dc004b9
+	atp->NumberOfPorts = hba_info->NumberOfPorts;
dc004b9
+
dc004b9
+	/* Get Manufacturer */
dc004b9
+	sa_strncpy_safe(atp->Manufacturer, sizeof(atp->Manufacturer),
dc004b9
+			hba_info->Manufacturer, sizeof(hba_info->Manufacturer));
dc004b9
+
dc004b9
+	/* Get SerialNumber */
dc004b9
+	sa_strncpy_safe(atp->SerialNumber, sizeof(atp->SerialNumber),
dc004b9
+			hba_info->SerialNumber, sizeof(hba_info->SerialNumber));
dc004b9
+
dc004b9
+
dc004b9
+	/* Get ModelDescription */
dc004b9
+	sa_strncpy_safe(atp->ModelDescription, sizeof(atp->ModelDescription),
dc004b9
+			hba_info->ModelDescription,
dc004b9
+			sizeof(hba_info->ModelDescription));
dc004b9
+	if (!strncmp(hba_info->ModelDescription, "Unknown",
dc004b9
+		 sizeof(hba_info->ModelDescription))) {
dc004b9
+		snprintf(atp->ModelDescription, sizeof(atp->ModelDescription),
dc004b9
+			"[%04x:%04x]-[%04x:%04x]-(%04x)",
dc004b9
+			hba_info->vendor_id, hba_info->device_id,
dc004b9
+			hba_info->subsystem_vendor_id,
dc004b9
+			hba_info->subsystem_device_id,
dc004b9
+			hba_info->device_class);
dc004b9
+		/*
dc004b9
+		 * Get Model
dc004b9
+		 *
dc004b9
+		 * If the device is a newly developed product, and
dc004b9
+		 * the model description is not in pci.ids yet, use
dc004b9
+		 * the model description constructed above as the
dc004b9
+		 * model string.
dc004b9
+		 */
dc004b9
+		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
dc004b9
+				atp->ModelDescription,
dc004b9
+				sizeof(atp->ModelDescription));
dc004b9
 	}
dc004b9
-	return 0;
dc004b9
+
dc004b9
+	/*
dc004b9
+	 * Get Model
dc004b9
+	 *
dc004b9
+	 * If the device name has already been added into
dc004b9
+	 * the pci.ids file, use the first word of the model
dc004b9
+	 * description as the model. If the space after the
dc004b9
+	 * first word is not found (new product), use the
dc004b9
+	 * model description as the model.
dc004b9
+	 */
dc004b9
+	sa_strncpy_safe(buf, sizeof(buf), atp->ModelDescription,
dc004b9
+			sizeof(atp->ModelDescription));
dc004b9
+	if (strtok_r(buf, " ", &saveptr))
dc004b9
+		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
dc004b9
+				buf, strnlen(buf, sizeof(buf)));
dc004b9
+	else
dc004b9
+		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
dc004b9
+				atp->ModelDescription,
dc004b9
+				sizeof(atp->ModelDescription));
dc004b9
+
dc004b9
+	/* Get HardwareVersion */
dc004b9
+	sa_strncpy_safe(atp->HardwareVersion, sizeof(atp->HardwareVersion),
dc004b9
+			hba_info->HardwareVersion,
dc004b9
+			sizeof(hba_info->HardwareVersion));
dc004b9
+
dc004b9
+	/* Get OptionROMVersion (TODO) */
dc004b9
+	sa_strncpy_safe(atp->OptionROMVersion, sizeof(atp->OptionROMVersion),
dc004b9
+			HBA_ROM_VERSION, sizeof(HBA_ROM_VERSION));
dc004b9
+
dc004b9
+	/* Get FirmwareVersion (TODO) */
dc004b9
+	sa_strncpy_safe(atp->FirmwareVersion, sizeof(atp->FirmwareVersion),
dc004b9
+			HBA_FW_VERSION, sizeof(HBA_FW_VERSION));
dc004b9
+
dc004b9
+	/* Get VendorSpecificID (TODO) */
dc004b9
+	atp->VendorSpecificID = HBA_VENDOR_SPECIFIC_ID;
dc004b9
+
dc004b9
+	/* Get DriverVersion */
dc004b9
+	hba_dir = udev_device_get_syspath(pci);
dc004b9
+	sa_sys_read_line(hba_dir, SYSFS_MODULE_VER,
dc004b9
+			atp->DriverVersion, sizeof(atp->DriverVersion));
dc004b9
 }
dc004b9
 
dc004b9
-/*
dc004b9
- * find_phys_if - find the regular network interface name that
dc004b9
- *                has the ifindex that matches the specified iflink.
dc004b9
- *                This ifname will be used to find the PCI info
dc004b9
- *                of a VLAN interface.
dc004b9
- * hba_dir: hba_dir of VLAN interface.
dc004b9
- * buf: returns ifname of regular network interface.
dc004b9
- */
dc004b9
-static int
dc004b9
-find_phys_if(char *hba_dir, char *buf, size_t len)
dc004b9
+struct udev_device *
dc004b9
+find_netdev_by_ifindex(struct udev *udev, const char *ifindex)
dc004b9
 {
dc004b9
-	int rc;
dc004b9
+	struct udev_enumerate *ue;
dc004b9
+	struct udev_list_entry *head;
dc004b9
+	struct udev_device *newnet = NULL;
dc004b9
 
dc004b9
-	rc = sa_sys_read_line(hba_dir, "iflink", buf, len);
dc004b9
-	if (rc)
dc004b9
-		return 1;
dc004b9
-	/*
dc004b9
-	 * Search for the regular network interface and
dc004b9
-	 * return the interface name in the buf.
dc004b9
-	 */
dc004b9
-	sa_dir_read(SYSFS_HBA_DIR, check_ifindex, buf);
dc004b9
-	return 0;
dc004b9
+	ue = udev_enumerate_new(udev);
dc004b9
+	udev_enumerate_add_match_subsystem(ue, "net");
dc004b9
+	udev_enumerate_add_match_sysattr(ue, "ifindex", ifindex); 
dc004b9
+	udev_enumerate_scan_devices(ue);
dc004b9
+	/* enumerate returns a list, but there should only ever be one device
dc004b9
+	 * with a given ifindex */
dc004b9
+	head = udev_enumerate_get_list_entry(ue);
dc004b9
+	if (head)
dc004b9
+		newnet = udev_device_new_from_syspath(udev, udev_list_entry_get_name(head));
dc004b9
+	udev_enumerate_unref(ue);
dc004b9
+	return newnet;
dc004b9
+}
dc004b9
+
dc004b9
+struct udev_device *
dc004b9
+find_phys_if(struct udev_device *net)
dc004b9
+{
dc004b9
+	const char *ifindex;
dc004b9
+	const char *iflink;
dc004b9
+	struct udev *udev;
dc004b9
+	struct udev_device *lower = NULL;
dc004b9
+
dc004b9
+	ifindex = udev_device_get_sysattr_value(net, "ifindex");
dc004b9
+	iflink = udev_device_get_sysattr_value(net, "iflink");
dc004b9
+	if (strcmp(ifindex, iflink)) {
dc004b9
+		udev = udev_device_get_udev(net);
dc004b9
+		lower = find_netdev_by_ifindex(udev, iflink);
dc004b9
+	}
dc004b9
+	if (lower) {
dc004b9
+		return lower;
dc004b9
+	} else {
dc004b9
+		udev_device_ref(net);
dc004b9
+		return net;
dc004b9
+	}
dc004b9
 }
dc004b9
 
dc004b9
 static int
dc004b9
-sysfs_scan(struct dirent *dp, void *arg)
dc004b9
+sysfs_scan(struct udev_device *fc_host)
dc004b9
 {
dc004b9
 	HBA_ADAPTERATTRIBUTES *atp;
dc004b9
 	HBA_PORTATTRIBUTES *pap;
dc004b9
-	HBA_WWN wwnn;
dc004b9
+	uint64_t wwnn;
dc004b9
 	struct hba_info hba_info;
dc004b9
 	struct adapter_info *ap;
dc004b9
 	struct port_info *pp;
dc004b9
-	char host_dir[80], hba_dir[80], drv_dir[80];
dc004b9
-	char dev_dir[128];
dc004b9
+	const char *hba_dir;
dc004b9
+	char drv_dir[80];
dc004b9
 	char ifname[20], buf[256];
dc004b9
 	char *driverName;
dc004b9
 	int data[32], rc, i;
dc004b9
 	char *cp;
dc004b9
-	char *saveptr;	/* for strtok_r */
dc004b9
-	unsigned int ifindex;
dc004b9
-	unsigned int iflink;
dc004b9
+
dc004b9
+	const char *sysname = udev_device_get_sysname(fc_host);
dc004b9
+	const char *syspath = udev_device_get_syspath(fc_host);
dc004b9
+	struct udev_device *pci;
dc004b9
+	struct udev_device *net;
dc004b9
+	const char *ptr = NULL;
dc004b9
+	const char *attr;
dc004b9
 
dc004b9
 	memset(&hba_info, 0, sizeof(hba_info));
dc004b9
 
dc004b9
@@ -217,7 +337,7 @@ sysfs_scan(struct dirent *dp, void *arg)
dc004b9
 		return HBA_STATUS_ERROR;
dc004b9
 	}
dc004b9
 	memset(ap, 0, sizeof(*ap));
dc004b9
-	ap->ad_kern_index = atoi(dp->d_name + sizeof("host") - 1);
dc004b9
+	ap->ad_kern_index = atoi(sysname + sizeof("host") - 1);
dc004b9
 	ap->ad_port_count = 1;
dc004b9
 
dc004b9
 	/* atp points to the HBA attributes structure */
dc004b9
@@ -239,137 +359,76 @@ sysfs_scan(struct dirent *dp, void *arg)
dc004b9
 	memset(pp, 0, sizeof(*pp));
dc004b9
 	pp->ap_adapt = ap;
dc004b9
 	pp->ap_index = ap->ad_port_count - 1;
dc004b9
-	pp->ap_kern_hba = atoi(dp->d_name + sizeof("host") - 1);
dc004b9
+	pp->ap_kern_hba = atoi(sysname + sizeof("host") - 1);
dc004b9
 
dc004b9
 	/* pap points to the local port attributes structure */
dc004b9
 	pap = &pp->ap_attr;
dc004b9
 
dc004b9
-	/* Construct the host directory name from the input name */
dc004b9
-	snprintf(host_dir, sizeof(host_dir),
dc004b9
-		SYSFS_HOST_DIR "/%s", dp->d_name);
dc004b9
-
dc004b9
-	rc = sa_sys_read_line(host_dir, "symbolic_name", buf, sizeof(buf));
dc004b9
-
dc004b9
 	/* Get PortSymbolicName */
dc004b9
+	ptr = udev_device_get_sysattr_value(fc_host, "symbolic_name");
dc004b9
 	sa_strncpy_safe(pap->PortSymbolicName, sizeof(pap->PortSymbolicName),
dc004b9
-			buf, sizeof(buf));
dc004b9
+			ptr, strlen(ptr));
dc004b9
 
dc004b9
 	/* Skip the HBA if it isn't OpenFC */
dc004b9
 	cp = strstr(pap->PortSymbolicName, " over ");
dc004b9
 	if (!cp)
dc004b9
 		goto skip;
dc004b9
 
dc004b9
-	/*
dc004b9
-	 * See if <host_dir>/device is a PCI symlink.
dc004b9
-	 * If not, try it as a net device.
dc004b9
-	 */
dc004b9
-	snprintf(dev_dir, sizeof(dev_dir), "%s/device", host_dir);
dc004b9
-	i = readlink(dev_dir, buf, sizeof(buf) - 1);
dc004b9
-	if (i < 0)
dc004b9
-		i = 0;
dc004b9
-	buf[i] = '\0';
dc004b9
-
dc004b9
-	if (strstr(buf, "devices/pci") && !strstr(buf, "/net/")) {
dc004b9
-		snprintf(hba_dir, sizeof(hba_dir), "%s/device/..", host_dir);
dc004b9
-	} else {
dc004b9
-		/* assume a net device */
dc004b9
-		cp += 6;
dc004b9
-		sa_strncpy_safe(ifname, sizeof(ifname), cp, strlen(cp));
dc004b9
-		snprintf(hba_dir, sizeof(hba_dir),
dc004b9
-			 SYSFS_HBA_DIR "/%s", ifname);
dc004b9
-		/*
dc004b9
-		 * Try as VLAN device or other virtual net device.
dc004b9
-		 * If this is the case, ifindex and iflink will be different.
dc004b9
-		 * iflink is the ifindex of the physical device.
dc004b9
-		 */
dc004b9
-		rc = sa_sys_read_u32(hba_dir, "ifindex", &ifindex);
dc004b9
-		if (rc < 0)
dc004b9
-			goto skip;
dc004b9
-		rc = sa_sys_read_u32(hba_dir, "iflink", &iflink);
dc004b9
-		if (rc < 0)
dc004b9
-			goto skip;
dc004b9
-		if (ifindex != iflink) {
dc004b9
-			rc = find_phys_if(hba_dir, buf, sizeof(buf));
dc004b9
-			if (rc)
dc004b9
-				goto skip;
dc004b9
-			strncpy(ifname, buf, sizeof(ifname));
dc004b9
-		}
dc004b9
-
dc004b9
-		snprintf(hba_dir, sizeof(hba_dir),
dc004b9
-			 SYSFS_HBA_DIR "/%s/device", ifname);
dc004b9
-		i = readlink(hba_dir, buf, sizeof(buf) - 1);
dc004b9
-		if (i < 0)
dc004b9
-			goto skip;
dc004b9
-		buf[i] = '\0';
dc004b9
+	pci = udev_device_get_parent_with_subsystem_devtype(fc_host, "pci", NULL);
dc004b9
+	net = udev_device_get_parent_with_subsystem_devtype(fc_host, "net", NULL);
dc004b9
+	if (!pci && net) {
dc004b9
+		/* check for a vlan device, stacked on a real PCI network device */
dc004b9
+		net = find_phys_if(net);
dc004b9
+		pci = udev_device_get_parent_with_subsystem_devtype(net, "pci", NULL);
dc004b9
 	}
dc004b9
 
dc004b9
 	/*
dc004b9
-	 * Assume a PCI symlink value is in buf.
dc004b9
-	 * Back up to the last path component that looks like a PCI element.
dc004b9
-	 * A sample link value is like:
dc004b9
-	 *	../../devices/pci*.../0000:03:00.0
dc004b9
-	 */
dc004b9
-	rc = 0;
dc004b9
-	do {
dc004b9
-		cp = strrchr(buf, '/');
dc004b9
-		if (!cp)
dc004b9
-			break;
dc004b9
-		rc = sscanf(cp + 1, "%x:%x:%x.%x",
dc004b9
-			    &hba_info.domain, &hba_info.bus,
dc004b9
-			    &hba_info.dev, &hba_info.func);
dc004b9
-		if (rc == 4)
dc004b9
-			break;
dc004b9
-		*cp = '\0';
dc004b9
-	} while (cp && cp > buf);
dc004b9
-
dc004b9
-	if (rc != 4)
dc004b9
-		goto skip;
dc004b9
-
dc004b9
-	/*
dc004b9
 	 * Save the host directory and the hba directory
dc004b9
 	 * in local port structure
dc004b9
 	 */
dc004b9
 	sa_strncpy_safe(pp->host_dir, sizeof(pp->host_dir),
dc004b9
-			host_dir, sizeof(host_dir));
dc004b9
+			syspath, strlen(syspath));
dc004b9
 
dc004b9
 	/* Get NodeWWN */
dc004b9
-	rc = sys_read_wwn(pp->host_dir, "node_name", &wwnn);
dc004b9
-	memcpy(&pap->NodeWWN, &wwnn, sizeof(wwnn));
dc004b9
+	attr = udev_device_get_sysattr_value(fc_host, "node_name");
dc004b9
+	wwnn = strtoull(attr, NULL, 16);
dc004b9
+	copy_wwn(&pap->NodeWWN, wwnn);
dc004b9
 
dc004b9
 	/* Get PortWWN */
dc004b9
-	rc = sys_read_wwn(pp->host_dir, "port_name", &pap->PortWWN);
dc004b9
+	attr = udev_device_get_sysattr_value(fc_host, "port_name");
dc004b9
+	wwnn = strtoull(attr, NULL, 16);
dc004b9
+	copy_wwn(&pap->PortWWN, wwnn);
dc004b9
 
dc004b9
 	/* Get PortFcId */
dc004b9
-	rc = sa_sys_read_u32(pp->host_dir, "port_id", &pap->PortFcId);
dc004b9
+	attr = udev_device_get_sysattr_value(fc_host, "port_id");
dc004b9
+	pap->PortFcId = strtoul(attr, NULL, 0);
dc004b9
 
dc004b9
 	/* Get PortType */
dc004b9
-	rc = sa_sys_read_line(pp->host_dir, "port_type", buf, sizeof(buf));
dc004b9
-	rc = sa_enum_encode(port_types_table, buf, &pap->PortType);
dc004b9
+	attr = udev_device_get_sysattr_value(fc_host, "port_type");
dc004b9
+	rc = sa_enum_encode(port_types_table, attr, &pap->PortType);
dc004b9
 
dc004b9
 	/* Get PortState */
dc004b9
-	rc = sa_sys_read_line(pp->host_dir, "port_state", buf, sizeof(buf));
dc004b9
-	rc = sa_enum_encode(port_states_table, buf, &pap->PortState);
dc004b9
+	attr = udev_device_get_sysattr_value(fc_host, "port_state");
dc004b9
+	rc = sa_enum_encode(port_states_table, attr, &pap->PortState);
dc004b9
 
dc004b9
 	/* Get PortSpeed */
dc004b9
-	rc = sys_read_speed(pp->host_dir, "speed",
dc004b9
-				buf, sizeof(buf),
dc004b9
-				&pap->PortSpeed);
dc004b9
+	attr = udev_device_get_sysattr_value(fc_host, "speed");
dc004b9
+	rc = sys_read_speed(attr, &pap->PortSpeed);
dc004b9
 
dc004b9
 	/* Get PortSupportedSpeed */
dc004b9
-	rc = sys_read_speed(pp->host_dir, "supported_speeds",
dc004b9
-				buf, sizeof(buf),
dc004b9
-				&pap->PortSupportedSpeed);
dc004b9
+	attr = udev_device_get_sysattr_value(fc_host, "supported_speeds");
dc004b9
+	rc = sys_read_speed(attr, &pap->PortSupportedSpeed);
dc004b9
 
dc004b9
 	/* Get PortMaxFrameSize */
dc004b9
-	rc = sa_sys_read_line(pp->host_dir, "maxframe_size", buf, sizeof(buf));
dc004b9
-	sscanf(buf, "%d", &pap->PortMaxFrameSize);
dc004b9
+	attr = udev_device_get_sysattr_value(fc_host, "maxframe_size");
dc004b9
+	sscanf(attr, "%d", &pap->PortMaxFrameSize);
dc004b9
 
dc004b9
 	/* Get PortSupportedFc4Types */
dc004b9
-	rc = sa_sys_read_line(pp->host_dir, "supported_fc4s", buf, sizeof(buf));
dc004b9
-	sscanf(buf, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
dc004b9
-		    "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
dc004b9
-		    "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
dc004b9
-		    "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
dc004b9
+	attr = udev_device_get_sysattr_value(fc_host, "supported_fc4s");
dc004b9
+	sscanf(attr, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
dc004b9
+		     "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
dc004b9
+		     "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
dc004b9
+		     "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
dc004b9
 		&data[0], &data[1], &data[2], &data[3], &data[4], &data[5],
dc004b9
 		&data[6], &data[7], &data[8], &data[9], &data[10], &data[11],
dc004b9
 		&data[12], &data[13], &data[14], &data[15], &data[16],
dc004b9
@@ -380,11 +439,11 @@ sysfs_scan(struct dirent *dp, void *arg)
dc004b9
 		pap->PortSupportedFc4Types.bits[i] = data[i];
dc004b9
 
dc004b9
 	/* Get PortActiveFc4Types */
dc004b9
-	rc = sa_sys_read_line(pp->host_dir, "active_fc4s", buf, sizeof(buf));
dc004b9
-	sscanf(buf, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
dc004b9
-		    "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
dc004b9
-		    "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
dc004b9
-		    "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
dc004b9
+	attr = udev_device_get_sysattr_value(fc_host, "active_fc4s");
dc004b9
+	sscanf(attr, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
dc004b9
+		     "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
dc004b9
+		     "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
dc004b9
+		     "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
dc004b9
 		&data[0], &data[1], &data[2], &data[3], &data[4], &data[5],
dc004b9
 		&data[6], &data[7], &data[8], &data[9], &data[10], &data[11],
dc004b9
 		&data[12], &data[13], &data[14], &data[15], &data[16],
dc004b9
@@ -395,19 +454,19 @@ sysfs_scan(struct dirent *dp, void *arg)
dc004b9
 		pap->PortActiveFc4Types.bits[i] = data[i];
dc004b9
 
dc004b9
 	/* Get FabricName */
dc004b9
-	rc = sys_read_wwn(pp->host_dir, "fabric_name", &pap->FabricName);
dc004b9
+	attr = udev_device_get_sysattr_value(fc_host, "fabric_name");
dc004b9
+	wwnn = strtoull(attr, NULL, 16);
dc004b9
+	copy_wwn(&pap->FabricName, wwnn);
dc004b9
 
dc004b9
 	/* Get PortSupportedClassofService */
dc004b9
-	rc = sa_sys_read_line(pp->host_dir, "supported_classes",
dc004b9
-				buf, sizeof(buf));
dc004b9
-
dc004b9
-	cp = strstr(buf, "Class");
dc004b9
+	attr = udev_device_get_sysattr_value(fc_host, "supported_classes");
dc004b9
+	cp = strstr(attr, "Class");
dc004b9
 	if (cp)
dc004b9
 		pap->PortSupportedClassofService = *(cp + 6) - '0';
dc004b9
 
dc004b9
 	/* Get OSDeviceName */
dc004b9
 	sa_strncpy_safe(pap->OSDeviceName, sizeof(pap->OSDeviceName),
dc004b9
-			dp->d_name, sizeof(dp->d_name));
dc004b9
+			sysname, sizeof(sysname));
dc004b9
 
dc004b9
 	/* Get NumberofDiscoveredPorts */
dc004b9
 	snprintf(buf, sizeof(buf), "%s/device", pp->host_dir);
dc004b9
@@ -428,104 +487,8 @@ sysfs_scan(struct dirent *dp, void *arg)
dc004b9
 	snprintf(buf, sizeof(buf), "fcoe:%s", ifname);
dc004b9
 	ap->ad_name = strdup(buf);
dc004b9
 
dc004b9
-	/* Get vendor_id */
dc004b9
-	rc = sa_sys_read_u32(hba_dir, "vendor", &hba_info.vendor_id);
dc004b9
-
dc004b9
-	/* Get device_id */
dc004b9
-	rc = sa_sys_read_u32(hba_dir, "device", &hba_info.device_id);
dc004b9
-
dc004b9
-	/* Get subsystem_vendor_id */
dc004b9
-	rc = sa_sys_read_u32(hba_dir, "subsystem_vendor",
dc004b9
-				&hba_info.subsystem_vendor_id);
dc004b9
-
dc004b9
-	/* Get subsystem_device_id */
dc004b9
-	rc = sa_sys_read_u32(hba_dir, "subsystem_device",
dc004b9
-				&hba_info.subsystem_device_id);
dc004b9
-
dc004b9
-	/* Get device_class */
dc004b9
-	rc = sa_sys_read_u32(hba_dir, "class", &hba_info.device_class);
dc004b9
-	hba_info.device_class = hba_info.device_class>>8;
dc004b9
-
dc004b9
-	/*
dc004b9
-	 * Get Hardware Information via PCI Library
dc004b9
-	 */
dc004b9
-	(void) find_pci_device(&hba_info);
dc004b9
-
dc004b9
-	/* Get Number of Ports */
dc004b9
-	atp->NumberOfPorts = hba_info.NumberOfPorts;
dc004b9
-
dc004b9
-	/* Get Manufacturer */
dc004b9
-	sa_strncpy_safe(atp->Manufacturer, sizeof(atp->Manufacturer),
dc004b9
-			hba_info.Manufacturer, sizeof(hba_info.Manufacturer));
dc004b9
-
dc004b9
-	/* Get SerialNumber */
dc004b9
-	sa_strncpy_safe(atp->SerialNumber, sizeof(atp->SerialNumber),
dc004b9
-			hba_info.SerialNumber, sizeof(hba_info.SerialNumber));
dc004b9
-
dc004b9
-
dc004b9
-	/* Get ModelDescription */
dc004b9
-	sa_strncpy_safe(atp->ModelDescription, sizeof(atp->ModelDescription),
dc004b9
-			hba_info.ModelDescription,
dc004b9
-			sizeof(hba_info.ModelDescription));
dc004b9
-	if (!strncmp(hba_info.ModelDescription, "Unknown",
dc004b9
-		 sizeof(hba_info.ModelDescription))) {
dc004b9
-		snprintf(atp->ModelDescription, sizeof(atp->ModelDescription),
dc004b9
-			"[%04x:%04x]-[%04x:%04x]-(%04x)",
dc004b9
-			hba_info.vendor_id, hba_info.device_id,
dc004b9
-			hba_info.subsystem_vendor_id,
dc004b9
-			hba_info.subsystem_device_id,
dc004b9
-			hba_info.device_class);
dc004b9
-		/*
dc004b9
-		 * Get Model
dc004b9
-		 *
dc004b9
-		 * If the device is a newly developed product, and
dc004b9
-		 * the model description is not in pci.ids yet, use
dc004b9
-		 * the model description constructed above as the
dc004b9
-		 * model string.
dc004b9
-		 */
dc004b9
-		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
dc004b9
-				atp->ModelDescription,
dc004b9
-				sizeof(atp->ModelDescription));
dc004b9
-	}
dc004b9
-
dc004b9
-	/*
dc004b9
-	 * Get Model
dc004b9
-	 *
dc004b9
-	 * If the device name has already been added into
dc004b9
-	 * the pci.ids file, use the first word of the model
dc004b9
-	 * description as the model. If the space after the
dc004b9
-	 * first word is not found (new product), use the
dc004b9
-	 * model description as the model.
dc004b9
-	 */
dc004b9
-	sa_strncpy_safe(buf, sizeof(buf), atp->ModelDescription,
dc004b9
-			sizeof(atp->ModelDescription));
dc004b9
-	if (strtok_r(buf, " ", &saveptr))
dc004b9
-		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
dc004b9
-				buf, strnlen(buf, sizeof(buf)));
dc004b9
-	else
dc004b9
-		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
dc004b9
-				atp->ModelDescription,
dc004b9
-				sizeof(atp->ModelDescription));
dc004b9
-
dc004b9
-	/* Get HardwareVersion */
dc004b9
-	sa_strncpy_safe(atp->HardwareVersion, sizeof(atp->HardwareVersion),
dc004b9
-			hba_info.HardwareVersion,
dc004b9
-			sizeof(hba_info.HardwareVersion));
dc004b9
-
dc004b9
-	/* Get OptionROMVersion (TODO) */
dc004b9
-	sa_strncpy_safe(atp->OptionROMVersion, sizeof(atp->OptionROMVersion),
dc004b9
-			HBA_ROM_VERSION, sizeof(HBA_ROM_VERSION));
dc004b9
-
dc004b9
-	/* Get FirmwareVersion (TODO) */
dc004b9
-	sa_strncpy_safe(atp->FirmwareVersion, sizeof(atp->FirmwareVersion),
dc004b9
-			HBA_FW_VERSION, sizeof(HBA_FW_VERSION));
dc004b9
-
dc004b9
-	/* Get VendorSpecificID (TODO) */
dc004b9
-	atp->VendorSpecificID = HBA_VENDOR_SPECIFIC_ID;
dc004b9
-
dc004b9
-	/* Get DriverVersion */
dc004b9
-	rc = sa_sys_read_line(hba_dir, SYSFS_MODULE_VER,
dc004b9
-			atp->DriverVersion, sizeof(atp->DriverVersion));
dc004b9
+	if (pci)
dc004b9
+		sysfs_scan_pci(pci, &hba_info, atp);
dc004b9
 
dc004b9
 	/* Get NodeSymbolicName */
dc004b9
 	sa_strncpy_safe(atp->NodeSymbolicName, sizeof(atp->NodeSymbolicName),
dc004b9
@@ -538,6 +501,7 @@ sysfs_scan(struct dirent *dp, void *arg)
dc004b9
 		sizeof(pap->NodeWWN));
dc004b9
 
dc004b9
 	/* Get DriverName */
dc004b9
+	hba_dir = udev_device_get_syspath(pci);
dc004b9
 	snprintf(drv_dir, sizeof(drv_dir), "%s" SYSFS_MODULE , hba_dir);
dc004b9
 	i = readlink(drv_dir, buf, sizeof(buf));
dc004b9
 	if (i < 0)
dc004b9
@@ -662,10 +626,48 @@ sysfs_get_port_fc4stats(char *dir, HBA_FC4STATISTICS *fc4sp)
dc004b9
 /*
dc004b9
  * Open device and read adapter info if available.
dc004b9
  */
dc004b9
-void
dc004b9
+int
dc004b9
 adapter_init(void)
dc004b9
 {
dc004b9
-	sa_dir_read(SYSFS_HOST_DIR, sysfs_scan, NULL);
dc004b9
+	struct udev *udev;
dc004b9
+	struct udev_enumerate *ue;
dc004b9
+	struct udev_list_entry *head, *ul;
dc004b9
+	struct udev_device *fc_host;
dc004b9
+	const char *syspath;
dc004b9
+	int re = 0;
dc004b9
+
dc004b9
+	udev = udev_new();
dc004b9
+	if (!udev) {
dc004b9
+		return -ENOMEM;
dc004b9
+	}
dc004b9
+	ue = udev_enumerate_new(udev);
dc004b9
+	if (!ue) {
dc004b9
+		re = -ENOMEM;
dc004b9
+		goto err_enum_new;
dc004b9
+	}
dc004b9
+	re = udev_enumerate_add_match_subsystem(ue, "fc_host");
dc004b9
+	if (re) {
dc004b9
+		goto err_add_match;
dc004b9
+	}
dc004b9
+	re = udev_enumerate_scan_devices(ue);
dc004b9
+	if (re) {
dc004b9
+		goto err_scan_devs;
dc004b9
+	}
dc004b9
+	head = udev_enumerate_get_list_entry(ue);
dc004b9
+	udev_list_entry_foreach(ul, head) {
dc004b9
+		syspath = udev_list_entry_get_name(ul);
dc004b9
+		fc_host = udev_device_new_from_syspath(udev, syspath);
dc004b9
+		if (!fc_host)
dc004b9
+			continue;
dc004b9
+		sysfs_scan(fc_host);
dc004b9
+		udev_device_unref(fc_host);
dc004b9
+	}
dc004b9
+err_scan_devs:
dc004b9
+err_add_match:
dc004b9
+	udev_enumerate_unref(ue);
dc004b9
+err_enum_new:
dc004b9
+	udev_unref(udev);
dc004b9
+	return re;
dc004b9
 }
dc004b9
 
dc004b9
 void