]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - bitmap.c
Assemble: wait for device to appear via udev
[thirdparty/mdadm.git] / bitmap.c
index 86176696f957edef9d88955e869612ba6c47de85..18101664fa1728e997bdb27826141d5a1f40cca7 100644 (file)
--- a/bitmap.c
+++ b/bitmap.c
@@ -115,6 +115,15 @@ unsigned long long bitmap_bits(unsigned long long array_size,
        return (array_size * 512 + chunksize - 1) / chunksize;
 }
 
+unsigned long bitmap_sectors(struct bitmap_super_s *bsb)
+{
+       unsigned long long bits = bitmap_bits(__le64_to_cpu(bsb->sync_size),
+                                             __le32_to_cpu(bsb->chunksize));
+       int bits_per_sector = 8*512;
+       return (bits + bits_per_sector - 1) / bits_per_sector;
+}
+
+
 bitmap_info_t *bitmap_fd_read(int fd, int brief)
 {
        /* Note: fd might be open O_DIRECT, so we must be
@@ -125,7 +134,10 @@ bitmap_info_t *bitmap_fd_read(int fd, int brief)
        void *buf;
        int n, skip;
 
-       posix_memalign(&buf, 512, 8192);
+       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));