shithub: lwext4

Download patch

ref: b0ddedb220094550e28184c1473db69d38421430
parent: 2d9c5b5d776dcaa543b4a37f738617dfca64fff1
author: Max Maisel <max.maisel@posteo.de>
date: Thu Mar 1 12:16:18 EST 2018

ext4-mbr-write: Fixed partition size calculation

--- a/src/ext4_mbr.c
+++ b/src/ext4_mbr.c
@@ -129,7 +129,7 @@
 int ext4_mbr_write(struct ext4_blockdev *parent, struct ext4_mbr_parts *parts)
 {
 	int r;
-	uint64_t disk_size = parent->part_size;
+	uint64_t disk_size;
 	uint32_t division_sum = parts->division[0] + parts->division[1] +
 				parts->division[2] + parts->division[3];
 
@@ -141,6 +141,8 @@
 	if (r != EOK)
 		return r;
 
+	disk_size = parent->part_size;
+
 	/*Calculate CHS*/
 	uint32_t k = 16;
 	while ((k < 256) && ((disk_size / k / 63) > 1024))
@@ -167,7 +169,7 @@
 
 		if (i == 0) {
 			part_start += 63;
-			part_size -= 63;
+			part_size -= 63 * parent->bdif->ph_bsize;
 		}
 
 		uint32_t cyl_end = cyl_part + cyl_it - 1;
@@ -182,7 +184,7 @@
 		mbr->part_entry[i].chs2[2] = cyl_end;
 
 		mbr->part_entry[i].first_lba = part_start;
-		mbr->part_entry[i].sectors = part_size;
+		mbr->part_entry[i].sectors = part_size / parent->bdif->ph_bsize;
 
 		cyl_it += cyl_part;
 	}