shithub: lwext4

Download patch

ref: 71d088e6525e637279a46c2bb0f01e34c3a72f4a
parent: 2d9c5b5d776dcaa543b4a37f738617dfca64fff1
parent: de16b0f8bcb8b9c49811e1dcab476e0271e6cc39
author: Grzegorz Kostka <kostka.grzegorz@gmail.com>
date: Thu Mar 1 14:51:06 EST 2018

Merge pull request #34 from mmmaisel/master

Fix: ext4-mkfs and ext4-mbr-write use wrong partition size in case of multiple partitions

--- 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;
 	}
--- a/src/ext4_mkfs.c
+++ b/src/ext4_mkfs.c
@@ -709,7 +709,7 @@
 	bd->fs = fs;
 
 	if (info->len == 0)
-		info->len = bd->bdif->ph_bcnt * bd->bdif->ph_bsize;
+		info->len = bd->part_size;
 
 	if (info->block_size == 0)
 		info->block_size = 4096; /*Set block size to default value*/