]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Always return last partition end address in 512B blocks
authorMariusz Dabrowski <mariusz.dabrowski@intel.com>
Tue, 13 Dec 2016 13:31:02 +0000 (14:31 +0100)
committerJes Sorensen <Jes.Sorensen@redhat.com>
Tue, 13 Dec 2016 14:09:25 +0000 (09:09 -0500)
For 4K disks 'endofpart' is an index of the last 4K sector used by partition.
mdadm is using number of 512-byte sectors, so value returned by
get_last_partition_end must be multiplied by 8 for devices with 4K sectors.
Also, unused 'ret' variable has been removed.

Signed-off-by: Mariusz Dabrowski <mariusz.dabrowski@intel.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
util.c

diff --git a/util.c b/util.c
index 818f8392177e4ff584067d8e9ffec2c30e98cb31..f1009723ed04c0422084d1b7c97bc3ba4d2b4d7e 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1435,6 +1435,7 @@ static int get_last_partition_end(int fd, unsigned long long *endofpart)
        struct MBR boot_sect;
        unsigned long long curr_part_end;
        unsigned part_nr;
+       unsigned int sector_size;
        int retval = 0;
 
        *endofpart = 0;
@@ -1474,6 +1475,9 @@ static int get_last_partition_end(int fd, unsigned long long *endofpart)
                /* Unknown partition table */
                retval = -1;
        }
+       /* calculate number of 512-byte blocks */
+       if (get_dev_sector_size(fd, NULL, &sector_size))
+               *endofpart *= (sector_size / 512);
  abort:
        return retval;
 }
@@ -1485,9 +1489,8 @@ int check_partitions(int fd, char *dname, unsigned long long freesize,
         * Check where the last partition ends
         */
        unsigned long long endofpart;
-       int ret;
 
-       if ((ret = get_last_partition_end(fd, &endofpart)) > 0) {
+       if (get_last_partition_end(fd, &endofpart) > 0) {
                /* There appears to be a partition table here */
                if (freesize == 0) {
                        /* partitions will not be visible in new device */