]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
imsm: sysfs support routines for determining device connectivity
authorDan Williams <dan.j.williams@intel.com>
Mon, 8 Dec 2008 23:59:18 +0000 (16:59 -0700)
committerDan Williams <dan.j.williams@intel.com>
Mon, 8 Dec 2008 23:59:18 +0000 (16:59 -0700)
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
platform-intel.c
platform-intel.h

index 6cd5830aa446802e0f996d9c93e0a62efc5c810c..03e4ba79608ba694d6e80c1733bbf1ffaba80d8b 100644 (file)
@@ -176,3 +176,64 @@ const struct imsm_orom *find_imsm_orom(void)
                return &imsm_orom;
        return NULL;
 }
+
+char *devt_to_devpath(dev_t dev)
+{
+       char device[40];
+
+       sprintf(device, "/sys/dev/block/%d:%d/device", major(dev), minor(dev));
+       return canonicalize_file_name(device);
+}
+
+static char *diskfd_to_devpath(int fd)
+{
+       /* return the device path for a disk, return NULL on error or fd
+        * refers to a partition
+        */
+       struct stat st;
+
+       if (fstat(fd, &st) != 0)
+               return NULL;
+       if (!S_ISBLK(st.st_mode))
+               return NULL;
+
+       return devt_to_devpath(st.st_rdev);
+}
+
+int path_attached_to_hba(const char *disk_path, const char *hba_path)
+{
+       int rc;
+
+       if (!disk_path || !hba_path)
+               return 0;
+
+       if (strncmp(disk_path, hba_path, strlen(hba_path)) == 0)
+               rc = 1;
+       else
+               rc = 0;
+
+       return rc;
+}
+
+int devt_attached_to_hba(dev_t dev, const char *hba_path)
+{
+       char *disk_path = devt_to_devpath(dev);
+       int rc = path_attached_to_hba(disk_path, hba_path);
+
+       if (disk_path)
+               free(disk_path);
+
+       return rc;
+}
+
+int disk_attached_to_hba(int fd, const char *hba_path)
+{
+       char *disk_path = diskfd_to_devpath(fd);
+       int rc = path_attached_to_hba(disk_path, hba_path);
+
+       if (disk_path)
+               free(disk_path);
+
+       return rc;
+}
+
index 92520027ae4548296e9db37c04ec344d2fde1f85..c1264825d930af4bd375971f5cfb33486db7be40 100644 (file)
@@ -87,3 +87,6 @@ struct sys_dev *find_driver_devices(const char *bus, const char *driver);
 __u16 devpath_to_vendor(const char *dev_path);
 void free_sys_dev(struct sys_dev **list);
 const struct imsm_orom *find_imsm_orom(void);
+int disk_attached_to_hba(int fd, const char *hba_path);
+char *devt_to_devpath(dev_t dev);
+int path_attached_to_hba(const char *disk_path, const char *hba_path);