]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - libblkid/src/superblocks/drbd.c
Merge branch 'libblkid/drbd/padding' of https://github.com/t-8ch/util-linux
[thirdparty/util-linux.git] / libblkid / src / superblocks / drbd.c
index 7f72eb13f3d0cb68eb674ff0a0fc4ffcd69dbeb0..811098a5d2d23d409259eafb2c4eac7ebcfd9b60 100644 (file)
@@ -70,9 +70,8 @@ struct md_on_disk_08 {
        uint32_t bm_bytes_per_bit;
        uint32_t reserved_u32[4];
 
-       /* Unnecessary for libblkid **
-        * char reserved[8 * 512 - (8*(UI_SIZE+3)+4*11)];
-        */
+       unsigned char padding_start[0];
+       unsigned char padding_end[0] __attribute__((aligned(4096)));
 };
 
 /*
@@ -118,12 +117,21 @@ struct meta_data_on_disk_9 {
        struct peer_dev_md_on_disk_9 peers[DRBD_PEERS_MAX];
        uint64_t history_uuids[HISTORY_UUIDS];
 
-       /* Unnecessary for libblkid **
-        * char padding[0] __attribute__((aligned(4096)));
-        */
+       unsigned char padding_start[0];
+       unsigned char padding_end[0] __attribute__((aligned(4096)));
 } __attribute__((packed));
 
 
+static int is_zero_padded(const unsigned char *padding_start,
+                         const unsigned char *padding_end)
+{
+       for (; padding_start < padding_end; padding_start++) {
+               if (*padding_start != 0)
+                       return 0;
+       }
+       return 1;
+}
+
 static int probe_drbd_84(blkid_probe pr, const struct blkid_idmag *mag)
 {
        const struct md_on_disk_08 *md;
@@ -132,6 +140,10 @@ static int probe_drbd_84(blkid_probe pr, const struct blkid_idmag *mag)
        if (!md)
                return errno ? -errno : 1;
 
+       if (!is_zero_padded(member_ptr(md, padding_start),
+                           member_ptr(md, padding_end)))
+               return 1;
+
        /*
         * DRBD does not have "real" uuids; the following resembles DRBD's
         * notion of uuids (64 bit, see struct above)
@@ -153,6 +165,10 @@ static int probe_drbd_90(blkid_probe pr, const struct blkid_idmag *mag)
        if (!md)
                return errno ? -errno : 1;
 
+       if (!is_zero_padded(member_ptr(md, padding_start),
+                           member_ptr(md, padding_end)))
+               return 1;
+
        /*
         * DRBD does not have "real" uuids; the following resembles DRBD's
         * notion of uuids (64 bit, see struct above)