Always return last partition end address in 512B blocks
PATCH v2 1/1 Always return last partition end address in 512B blocks
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 <[email protected]>
--- util.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
util.c +5 -2
@@ -1430,6 +1430,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 ;
@@ -1469,6 +1470,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 , §or_size)) + *endofpart *= (sector_size /512 ); abort:return retval; }
@@ -1480,9 +1484,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 */
Signature · 1 line
1.8.3.1
Jes Sorensen
AppliedQuoted 9 lines · Mariusz Dabrowski
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_endmust be multiplied by 8 for devices with 4K sectors. Also, unused 'ret' variable has been removed.Signed-off-by Mariusz Dabrowski <[email protected]>--- util.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Applied!
Thanks,
Jes