]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super-intel.c
mdadm/util: unify stat checking blkdev into function
[thirdparty/mdadm.git] / super-intel.c
index 36f77d3cc5b9fdb2ca667eff3761f42d1606120f..e13c9402a562d621489e8a19ef9a3b3dc629cb47 100644 (file)
@@ -6562,7 +6562,7 @@ count_volumes_list(struct md_list *devlist, char *homehost,
 
        for (tmpdev = devlist; tmpdev; tmpdev = tmpdev->next) {
                char *devname = tmpdev->devname;
-               struct stat stb;
+               dev_t rdev;
                struct supertype *tst;
                int dfd;
                if (tmpdev->used > 1)
@@ -6578,14 +6578,7 @@ count_volumes_list(struct md_list *devlist, char *homehost,
                        dprintf("cannot open device %s: %s\n",
                                devname, strerror(errno));
                        tmpdev->used = 2;
-               } else if (fstat(dfd, &stb)< 0) {
-                       /* Impossible! */
-                       dprintf("fstat failed for %s: %s\n",
-                               devname, strerror(errno));
-                       tmpdev->used = 2;
-               } else if ((stb.st_mode & S_IFMT) != S_IFBLK) {
-                       dprintf("%s is not a block device.\n",
-                               devname);
+               } else if (!fstat_is_blkdev(dfd, devname, &rdev)) {
                        tmpdev->used = 2;
                } else if (must_be_container(dfd)) {
                        struct supertype *cst;
@@ -6607,7 +6600,7 @@ count_volumes_list(struct md_list *devlist, char *homehost,
                        if (cst)
                                cst->ss->free_super(cst);
                } else {
-                       tmpdev->st_rdev = stb.st_rdev;
+                       tmpdev->st_rdev = rdev;
                        if (tst->ss->load_super(tst,dfd, NULL)) {
                                dprintf("no RAID superblock on %s\n",
                                        devname);
@@ -6862,7 +6855,7 @@ static int validate_geometry_imsm_volume(struct supertype *st, int level,
                                         unsigned long long *freesize,
                                         int verbose)
 {
-       struct stat stb;
+       dev_t rdev;
        struct intel_super *super = st->sb;
        struct imsm_super *mpb;
        struct dl *dl;
@@ -6927,13 +6920,11 @@ static int validate_geometry_imsm_volume(struct supertype *st, int level,
        }
 
        /* This device must be a member of the set */
-       if (stat(dev, &stb) < 0)
-               return 0;
-       if ((S_IFMT & stb.st_mode) != S_IFBLK)
+       if (!stat_is_blkdev(dev, &rdev))
                return 0;
        for (dl = super->disks ; dl ; dl = dl->next) {
-               if (dl->major == (int)major(stb.st_rdev) &&
-                   dl->minor == (int)minor(stb.st_rdev))
+               if (dl->major == (int)major(rdev) &&
+                   dl->minor == (int)minor(rdev))
                        break;
        }
        if (!dl) {