]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Remove spaces/tabs from ends of lines.
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index 6148ff8c8fd1506cec4fb79a822c84f8106321e7..4a751aaf1350f8db0c96d62ab5bcf69a3f6c7916 100644 (file)
--- a/util.c
+++ b/util.c
@@ -73,33 +73,32 @@ struct blkpg_partition {
  */
 int parse_uuid(char *str, int uuid[4])
 {
-    int hit = 0; /* number of Hex digIT */
-    int i;
-    char c;
-    for (i=0; i<4; i++) uuid[i]=0;
-
-    while ((c= *str++)) {
-       int n;
-       if (c>='0' && c<='9')
-           n = c-'0';
-       else if (c>='a' && c <= 'f')
-           n = 10 + c - 'a';
-       else if (c>='A' && c <= 'F')
-           n = 10 + c - 'A';
-       else if (strchr(":. -", c))
-           continue;
-       else return 0;
-
-       if (hit<32) {
-           uuid[hit/8] <<= 4;
-           uuid[hit/8] += n;
+       int hit = 0; /* number of Hex digIT */
+       int i;
+       char c;
+       for (i=0; i<4; i++) uuid[i]=0;
+
+       while ((c= *str++)) {
+               int n;
+               if (c>='0' && c<='9')
+                       n = c-'0';
+               else if (c>='a' && c <= 'f')
+                       n = 10 + c - 'a';
+               else if (c>='A' && c <= 'F')
+                       n = 10 + c - 'A';
+               else if (strchr(":. -", c))
+                       continue;
+               else return 0;
+
+               if (hit<32) {
+                       uuid[hit/8] <<= 4;
+                       uuid[hit/8] += n;
+               }
+               hit++;
        }
-       hit++;
-    }
-    if (hit == 32)
-       return 1;
-    return 0;
-    
+       if (hit == 32)
+               return 1;
+       return 0;
 }
 
 
@@ -132,7 +131,6 @@ int md_get_version(int fd)
     return -1;
 }
 
-    
 int get_linux_version()
 {
        struct utsname name;
@@ -224,7 +222,7 @@ int same_uuid(int a[4], int b[4], int swapuuid)
        if (swapuuid) {
                /* parse uuids are hostendian.
                 * uuid's from some superblocks are big-ending
-                * if there is a difference, we need to swap.. 
+                * if there is a difference, we need to swap..
                 */
                unsigned char *ac = (unsigned char *)a;
                unsigned char *bc = (unsigned char *)b;
@@ -246,6 +244,25 @@ int same_uuid(int a[4], int b[4], int swapuuid)
                return 0;
        }
 }
+void copy_uuid(void *a, int b[4], int swapuuid)
+{
+       if (swapuuid) {
+               /* parse uuids are hostendian.
+                * uuid's from some superblocks are big-ending
+                * if there is a difference, we need to swap..
+                */
+               unsigned char *ac = (unsigned char *)a;
+               unsigned char *bc = (unsigned char *)b;
+               int i;
+               for (i=0; i<16; i+= 4) {
+                       ac[i+0] = bc[i+3];
+                       ac[i+1] = bc[i+2];
+                       ac[i+2] = bc[i+1];
+                       ac[i+3] = bc[i+0];
+               }
+       } else
+               memcpy(a, b, 16);
+}
 
 #ifndef MDASSEMBLE
 int check_ext2(int fd, char *name)
@@ -299,7 +316,7 @@ int check_reiser(int fd, char *name)
        fprintf(stderr, Name ": %s appears to contain a reiserfs file system\n",name);
        size = sb[0]|(sb[1]|(sb[2]|sb[3]<<8)<<8)<<8;
        fprintf(stderr, "    size = %luK\n", size*4);
-               
+
        return 1;
 }
 
@@ -372,7 +389,7 @@ int is_standard(char *dev, int *nump)
 {
        /* tests if dev is a "standard" md dev name.
         * i.e if the last component is "/dNN" or "/mdNN",
-        * where NN is a string of digits 
+        * where NN is a string of digits
         */
        char *d = strrchr(dev, '/');
        int type=0;
@@ -449,10 +466,6 @@ int nftw(const char *path, int (*han)(const char *name, const struct stat *stb,
        return ftw(path, add_dev_1, nopenfd);
 }
 #else
-int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s)
-{
-       return 0;
-}
 int nftw(const char *path, int (*han)(const char *name, const struct stat *stb, int flag, struct FTW *s), int nopenfd, int flags)
 {
        return 0;
@@ -531,7 +544,7 @@ unsigned long calc_csum(void *super, int bytes)
                newcsum+= superc[i];
        csum = (newcsum& 0xffffffff) + (newcsum>>32);
 #ifdef __alpha__
-/* The in-kernel checksum calculation is always 16bit on 
+/* The in-kernel checksum calculation is always 16bit on
  * the alpha, though it is 32 bit on i386...
  * I wonder what it is elsewhere... (it uses and API in
  * a way that it shouldn't).
@@ -577,7 +590,6 @@ char *human_size(long long bytes)
 char *human_size_brief(long long bytes)
 {
        static char buf[30];
-       
 
        if (bytes < 5000*1024)
                snprintf(buf, sizeof(buf), "%ld.%02ldKiB",
@@ -738,7 +750,7 @@ struct supertype *guess_super(int fd)
        struct supertype *st;
        unsigned long besttime = 0;
        int bestsuper = -1;
-       
+
        void *sbp = NULL;
        int i;
 
@@ -773,7 +785,37 @@ struct supertype *guess_super(int fd)
        return NULL;
 }
 
+/* Return size of device in bytes */
+int get_dev_size(int fd, char *dname, unsigned long long *sizep)
+{
+       unsigned long long ldsize;
+#ifdef BLKGETSIZE64
+       if (ioctl(fd, BLKGETSIZE64, &ldsize) != 0)
+#endif
+       {
+               unsigned long dsize;
+               if (ioctl(fd, BLKGETSIZE, &dsize) == 0) {
+                       ldsize = dsize;
+                       ldsize <<= 9;
+               } else {
+                       if (dname)
+                               fprintf(stderr, Name ": Cannot get size of %s: %s\b",
+                                       dname, strerror(errno));
+                       return 0;
+               }
+       }
+       *sizep = ldsize;
+       return 1;
+}
 
+void get_one_disk(int mdfd, mdu_array_info_t *ainf, mdu_disk_info_t *disk)
+{
+       int d;
+       ioctl(mdfd, GET_ARRAY_INFO, ainf);
+       for (d = 0 ; d < ainf->raid_disks + ainf->nr_disks ; d++)
+               if (ioctl(mdfd, GET_DISK_INFO, disk) == 0)
+                       return;
+}
 #ifdef __TINYC__
 /* tinyc doesn't optimize this check in ioctl.h out ... */
 unsigned int __invalid_size_argument_for_IOC = 0;