]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - sysfs.c
util: make env checking more generic
[thirdparty/mdadm.git] / sysfs.c
diff --git a/sysfs.c b/sysfs.c
index 58c84e26339e8014027bcea6d722bf87b73b4030..00f42ea65722704c14b32e3e888b2a950ea09e83 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -82,26 +82,21 @@ int sysfs_open(int devnum, char *devname, char *attr)
 void sysfs_init(struct mdinfo *mdi, int fd, int devnum)
 {
        if (fd >= 0) {
-               struct stat stb;
                mdu_version_t vers;
-               if (fstat(fd, &stb))
-                       return;
                if (ioctl(fd, RAID_VERSION, &vers) != 0)
                        return;
-               if (major(stb.st_rdev)==9)
-                       sprintf(mdi->sys_name, "md%d", (int)minor(stb.st_rdev));
-               else
-                       sprintf(mdi->sys_name, "md_d%d",
-                               (int)minor(stb.st_rdev)>>MdpMinorShift);
-       } else {
-               if (devnum >= 0)
-                       sprintf(mdi->sys_name, "md%d", devnum);
-               else
-                       sprintf(mdi->sys_name, "md_d%d",
-                               -1-devnum);
+               devnum = fd2devnum(fd);
        }
+       if (devnum == NoMdDev)
+               return;
+       if (devnum >= 0)
+               sprintf(mdi->sys_name, "md%d", devnum);
+       else
+               sprintf(mdi->sys_name, "md_d%d",
+                       -1-devnum);
 }
 
+
 struct mdinfo *sysfs_read(int fd, int devnum, unsigned long options)
 {
        /* Longest possible name in sysfs, mounted at /sys, is
@@ -363,7 +358,7 @@ unsigned long long get_component_size(int fd)
        char fname[50];
        int n;
        if (fstat(fd, &stb)) return 0;
-       if (major(stb.st_rdev) == 9)
+       if (major(stb.st_rdev) != get_mdp_major())
                sprintf(fname, "/sys/block/md%d/md/component_size",
                        (int)minor(stb.st_rdev));
        else