]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super0.c
Central calls to ioctl BLKGETSIZE
[thirdparty/mdadm.git] / super0.c
index 600aae028cafc047d2dfde724e3c050d1ed7b2b4..770d96e990ec492ea6b71154d2a19d219644bcea 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -116,7 +116,8 @@ static void examine_super0(void *sbv, char *homehost)
        printf("     Raid Level : %s\n", c?c:"-unknown-");
        if ((int)sb->level >= 0) {
                int ddsks=0;
-               printf("    Device Size : %d%s\n", sb->size, human_size((long long)sb->size<<10));
+               printf("  Used Dev Size : %d%s\n", sb->size,
+                      human_size((long long)sb->size<<10));
                switch(sb->level) {
                case 1: ddsks=1;break;
                case 4:
@@ -320,6 +321,7 @@ static void getinfo_super0(struct mdinfo *info, void *sbv)
        info->array.ctime = sb->ctime;
        info->array.utime = sb->utime;
        info->array.chunk_size = sb->chunk_size;
+       info->array.state = sb->state;
        info->component_size = sb->size*2;
 
        info->disk.state = sb->this_disk.state;
@@ -586,20 +588,12 @@ static void add_to_super0(void *sbv, mdu_disk_info_t *dinfo)
 
 static int store_super0(struct supertype *st, int fd, void *sbv)
 {
-       unsigned long size;
        unsigned long long dsize;
        unsigned long long offset;
        mdp_super_t *super = sbv;
-    
-#ifdef BLKGETSIZE64
-       if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
-       {
-               if (ioctl(fd, BLKGETSIZE, &size))
-                       return 1;
-               else
-                       dsize = ((unsigned long long)size)<<9;
-       }
+
+       if (!get_dev_size(fd, NULL, &dsize))
+               return 1;
 
        if (dsize < MD_RESERVED_SECTORS*2*512)
                return 2;
@@ -706,20 +700,10 @@ static int load_super0(struct supertype *st, int fd, void **sbp, char *devname)
        int uuid[4];
        struct bitmap_super_s *bsb;
     
-#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;
-               } else
-                       dsize = size << 9;
-       }
+       if (!get_dev_size(fd, devname, &dsize))
+               return 1;
 
-       if (dsize < MD_RESERVED_SECTORS*2) {
+       if (dsize < MD_RESERVED_SECTORS*512 * 2) {
                if (devname)
                        fprintf(stderr, Name ": %s is too small for md: size is %ld sectors.\n",
                                devname, size);
@@ -827,7 +811,10 @@ static __u64 avail_size0(struct supertype *st, __u64 devsize)
        return MD_NEW_SIZE_SECTORS(devsize);
 }
 
-static int add_internal_bitmap0(struct supertype *st, void *sbv, int chunk, int delay, int write_behind, unsigned long long size, int may_change, int major)
+static int add_internal_bitmap0(struct supertype *st, void *sbv, int *chunkp,
+                               int delay, int write_behind,
+                               unsigned long long size, int may_change,
+                               int major)
 {
        /*
         * The bitmap comes immediately after the superblock and must be 60K in size
@@ -838,6 +825,7 @@ static int add_internal_bitmap0(struct supertype *st, void *sbv, int chunk, int
        unsigned long long bits;
        unsigned long long max_bits = 60*1024*8;
        unsigned long long min_chunk;
+       int chunk = *chunkp;
        mdp_super_t *sb = sbv;
        bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + MD_SB_BYTES);
 
@@ -863,7 +851,7 @@ static int add_internal_bitmap0(struct supertype *st, void *sbv, int chunk, int
        bms->daemon_sleep = __cpu_to_le32(delay);
        bms->sync_size = __cpu_to_le64(size);
        bms->write_behind = __cpu_to_le32(write_behind);
-
+       *chunkp = chunk;
        return 1;
 }
 
@@ -871,19 +859,12 @@ static int add_internal_bitmap0(struct supertype *st, void *sbv, int chunk, int
 void locate_bitmap0(struct supertype *st, int fd, void *sbv)
 {
        unsigned long long dsize;
-       unsigned long size;
        unsigned long long offset;
-#ifdef BLKGETSIZE64
-       if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
-       {
-               if (ioctl(fd, BLKGETSIZE, &size))
-                       return;
-               else
-                       dsize = ((unsigned long long)size)<<9;
-       }
 
-       if (dsize < MD_RESERVED_SECTORS*2)
+       if (!get_dev_size(fd, NULL, &dsize))
+               return;
+
+       if (dsize < MD_RESERVED_SECTORS*512 * 2)
                return;
 
        offset = MD_NEW_SIZE_SECTORS(dsize>>9);
@@ -897,7 +878,6 @@ void locate_bitmap0(struct supertype *st, int fd, void *sbv)
 
 int write_bitmap0(struct supertype *st, int fd, void *sbv)
 {
-       unsigned long size;
        unsigned long long dsize;
        unsigned long long offset;
        mdp_super_t *sb = sbv;
@@ -907,17 +887,11 @@ int write_bitmap0(struct supertype *st, int fd, void *sbv)
        int towrite, n;
        char buf[4096];
 
-#ifdef BLKGETSIZE64
-       if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
-       {
-               if (ioctl(fd, BLKGETSIZE, &size))
-                       return 1;
-               else
-                       dsize = ((unsigned long long)size)<<9;
-       }
+       if (!get_dev_size(fd, NULL, &dsize))
+               return 1;
+
 
-       if (dsize < MD_RESERVED_SECTORS*2)
+       if (dsize < MD_RESERVED_SECTORS*512 * 2)
        return -1;
 
        offset = MD_NEW_SIZE_SECTORS(dsize>>9);