]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super1.c
Central calls to ioctl BLKGETSIZE
[thirdparty/mdadm.git] / super1.c
index b7d1c996e88a824bdd3eb492aef2897b7a891bac..f1732f7b6c751e56842b255702e4bf3ad5b2f729 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -536,11 +536,23 @@ static int update_super1(struct mdinfo *info, void *sbv, char *update,
                sb->resync_offset = 0ULL;
        }
        if (strcmp(update, "uuid") == 0) {
-               memcpy(sb->set_uuid, info->uuid, 16);
+               if (super1.swapuuid) {
+                       unsigned char *ac = (unsigned char *)sb->set_uuid;
+                       unsigned char *bc = (unsigned char *)info->uuid;
+                       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(sb->set_uuid, info->uuid, 16);
+
                if (__le32_to_cpu(sb->feature_map)&MD_FEATURE_BITMAP_OFFSET) {
                        struct bitmap_super_s *bm;
                        bm = (struct bitmap_super_s*)(sbv+1024);
-                       memcpy(bm->uuid, info->uuid, 16);
+                       memcpy(bm->uuid, sb->set_uuid, 16);
                }
        }
        if (strcmp(update, "homehost") == 0 &&
@@ -684,19 +696,12 @@ static int store_super1(struct supertype *st, int fd, void *sbv)
        struct mdp_superblock_1 *sb = sbv;
        unsigned long long sb_offset;
        int sbsize;
-       unsigned long size;
        unsigned long long dsize;
 
-#ifdef BLKGETSIZE64
-       if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
-       {
-               if (ioctl(fd, BLKGETSIZE, &size))
-                       return 1;
-               else
-                       dsize = (unsigned long long)size;
-       } else
-               dsize >>= 9;
+       if (!get_dev_size(fd, NULL, &dsize))
+               return 1;
+
+       dsize >>= 9;
 
        if (dsize < 24)
                return 2;
@@ -808,17 +813,9 @@ static int write_init_super1(struct supertype *st, void *sbv,
                free(refsb);
        }
 
-#ifdef BLKGETSIZE64
-       if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
-       {
-               unsigned long size;
-               if (ioctl(fd, BLKGETSIZE, &size))
-                       return 1;
-               else
-                       dsize = size;
-       } else
-               dsize >>= 9;
+       if (!get_dev_size(fd, NULL, &dsize))
+               return 1;
+       dsize >>= 9;
 
        if (dsize < 24) {
                close(fd);
@@ -925,7 +922,6 @@ static int compare_super1(void **firstp, void *secondv)
 
 static int load_super1(struct supertype *st, int fd, void **sbp, char *devname)
 {
-       unsigned long size;
        unsigned long long dsize;
        unsigned long long sb_offset;
        struct mdp_superblock_1 *super;
@@ -966,19 +962,9 @@ static int load_super1(struct supertype *st, int fd, void **sbp, char *devname)
                st->ss = NULL;
                return 2;
        }
-#ifdef BLKGETSIZE64
-       if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
-       {
-               if (ioctl(fd, BLKGETSIZE, &size)) {
-                       if (devname)
-                               fprintf(stderr, Name ": cannot find device size for %s: %s\n",
-                                       devname, strerror(errno));
-                       return 1;
-               }
-               dsize = size;
-       } else
-               dsize >>= 9;
+       if (!get_dev_size(fd, devname, &dsize))
+               return 1;
+       dsize >>= 9;
 
        if (dsize < 24) {
                if (devname)
@@ -1164,7 +1150,7 @@ add_internal_bitmap1(struct supertype *st, void *sbv,
        unsigned long long min_chunk;
        long offset;
        int chunk = *chunkp;
-       int room;
+       int room = 0;
        struct mdp_superblock_1 *sb = sbv;
        bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + 1024);