]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Release mdadm-2.6.9
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index 108f3c168d2414aa1e0473d7d0042a1933935584..1b2ae6b25482ecb78b9b8c3c1e1325fe17157da6 100644 (file)
--- a/util.c
+++ b/util.c
@@ -398,7 +398,7 @@ int is_standard(char *dev, int *nump)
        if (strncmp(d, "/d",2)==0)
                d += 2, type=1; /* /dev/md/dN{pM} */
        else if (strncmp(d, "/md_d", 5)==0)
-               d += 5, type=1; /* /dev/md_dNpM */
+               d += 5, type=1; /* /dev/md_dN{pM} */
        else if (strncmp(d, "/md", 3)==0)
                d += 3, type=-1; /* /dev/mdN */
        else if (d-dev > 3 && strncmp(d-2, "md/", 3)==0)
@@ -433,8 +433,10 @@ int devlist_ready = 0;
 int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s)
 {
        struct stat st;
+
        if (S_ISLNK(stb->st_mode)) {
-               stat(name, &st);
+               if (stat(name, &st) != 0)
+                       return 0;
                stb = &st;
        }
 
@@ -606,9 +608,25 @@ char *human_size_brief(long long bytes)
                        );
        return buf;
 }
+
+void print_r10_layout(int layout)
+{
+       int near = layout & 255;
+       int far = (layout >> 8) & 255;
+       int offset = (layout&0x10000);
+       char *sep = "";
+
+       if (near != 1) {
+               printf("%s near=%d", sep, near);
+               sep = ",";
+       }
+       if (far != 1)
+               printf("%s %s=%d", sep, offset?"offset":"far", far);
+       if (near*far == 1)
+               printf("NO REDUNDANCY");
+}
 #endif
 
-#if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
 int get_mdp_major(void)
 {
 static int mdp_major = -1;
@@ -638,6 +656,7 @@ static int mdp_major = -1;
 }
 
 
+#if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
 
 char *get_md_name(int dev)
 {
@@ -692,6 +711,44 @@ void put_md_name(char *name)
        if (strncmp(name, "/dev/.tmp.md", 12)==0)
                unlink(name);
 }
+
+static int dev2major(int d)
+{
+       if (d >= 0)
+               return MD_MAJOR;
+       else
+               return get_mdp_major();
+}
+
+static int dev2minor(int d)
+{
+       if (d >= 0)
+               return d;
+       return (-1-d) << MdpMinorShift;
+}
+
+int find_free_devnum(int use_partitions)
+{
+       int devnum;
+       for (devnum = 127; devnum != 128;
+            devnum = devnum ? devnum-1 : (1<<22)-1) {
+               char *dn;
+               int _devnum;
+
+               _devnum = use_partitions ? (-1-devnum) : devnum;
+               if (mddev_busy(_devnum))
+                       continue;
+               /* make sure it is new to /dev too, at least as a
+                * non-standard */
+               dn = map_dev(dev2major(_devnum), dev2minor(_devnum), 0);
+               if (dn && ! is_standard(dn, NULL))
+                       continue;
+               break;
+       }
+       if (devnum == 128)
+               return NoMdDev;
+       return use_partitions ? (-1-devnum) : devnum;
+}
 #endif /* !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) */
 
 int dev_open(char *dev, int flags)
@@ -723,6 +780,7 @@ int dev_open(char *dev, int flags)
 
 struct superswitch *superlist[] = { &super0, &super1, NULL };
 
+#if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
 struct supertype *super_by_fd(int fd)
 {
        mdu_array_info_t array;
@@ -757,9 +815,12 @@ struct supertype *super_by_fd(int fd)
 
        if (sra)
                sysfs_free(sra);
-       st->sb = NULL;
+       if (st)
+               st->sb = NULL;
        return st;
 }
+#endif /* !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) */
+
 
 struct supertype *dup_super(struct supertype *st)
 {
@@ -780,7 +841,8 @@ struct supertype *dup_super(struct supertype *st)
        for (i = 0; stnew == NULL && superlist[i] ; i++)
                stnew = superlist[i]->match_metadata_desc(verstr);
 
-       stnew->sb = NULL;
+       if (stnew)
+               stnew->sb = NULL;
        return stnew;
 }
 
@@ -863,45 +925,6 @@ void get_one_disk(int mdfd, mdu_array_info_t *ainf, mdu_disk_info_t *disk)
                        return;
 }
 
-static int dev2major(int d)
-{
-       if (d >= 0)
-               return MD_MAJOR;
-       else
-               return get_mdp_major();
-}
-
-static int dev2minor(int d)
-{
-       if (d >= 0)
-               return d;
-       return (-1-d) << MdpMinorShift;
-}
-
-int find_free_devnum(int use_partitions)
-{
-       int devnum;
-       for (devnum = 127; devnum != 128;
-            devnum = devnum ? devnum-1 : (1<<22)-1) {
-               char *dn;
-               int _devnum;
-
-               _devnum = use_partitions ? (-1-devnum) : devnum;
-               if (mddev_busy(_devnum))
-                       continue;
-               /* make sure it is new to /dev too, at least as a
-                * non-standard */
-               dn = map_dev(dev2major(_devnum), dev2minor(_devnum), 0);
-               if (dn && ! is_standard(dn, NULL))
-                       continue;
-               break;
-       }
-       if (devnum == 128)
-               return NoMdDev;
-       return use_partitions ? (-1-devnum) : devnum;
-}
-
-
 #ifdef __TINYC__
 /* tinyc doesn't optimize this check in ioctl.h out ... */
 unsigned int __invalid_size_argument_for_IOC = 0;