]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - bitmap.c
imsm: fix imsm_map.num_domains
[thirdparty/mdadm.git] / bitmap.c
index b64793924bd04c01e870e147f359af05468f5e9a..b9bbaebdf09bfdaa8981314b280db33156ff2c42 100644 (file)
--- a/bitmap.c
+++ b/bitmap.c
@@ -131,11 +131,13 @@ bitmap_info_t *bitmap_fd_read(int fd, int brief)
         */
        unsigned long long total_bits = 0, read_bits = 0, dirty_bits = 0;
        bitmap_info_t *info;
-       char *buf, *unaligned;
+       void *buf;
        int n, skip;
 
-       unaligned = malloc(8192*2);
-       buf = (char*) ((unsigned long)unaligned | 8191)+1;
+       if (posix_memalign(&buf, 512, 8192) != 0) {
+               fprintf(stderr, Name ": failed to allocate 8192 bytes\n");
+               return NULL;
+       }
        n = read(fd, buf, 8192);
 
        info = malloc(sizeof(*info));
@@ -154,7 +156,6 @@ bitmap_info_t *bitmap_fd_read(int fd, int brief)
                fprintf(stderr, Name ": failed to read superblock of bitmap "
                        "file: %s\n", strerror(errno));
                free(info);
-               free(unaligned);
                return NULL;
        }
        memcpy(&info->sb, buf, sizeof(info->sb));
@@ -162,7 +163,7 @@ bitmap_info_t *bitmap_fd_read(int fd, int brief)
 
        sb_le_to_cpu(&info->sb); /* convert superblock to CPU byte ordering */
 
-       if (brief || info->sb.sync_size == 0)
+       if (brief || info->sb.sync_size == 0 || info->sb.chunksize == 0)
                goto out;
 
        /* read the rest of the file counting total bits and dirty bits --