Bug#630130: kpartx creates wrong partition mappings for gpt with sector size != 512bytes

Philipp Schmidt philipp at ppc.in-berlin.de
Sat Jun 11 10:25:17 UTC 2011


Package: kpartx
Version: 0.4.8+git0.761c66f
Severity: important
Tags: upstream

Hello,

kpartx creates wrong partiton mappings for gpt partition tables when the
sector size ist not 512 bytes (e.g. 4k exported by an fcal array). This
may lead to data corruption when trying to write to the created devices.

I have attached a patch fixing the problem.

--- gpt.c.orig	2009-08-04 23:34:22.000000000 +0200
+++ gpt.c	2011-06-11 12:09:29.000000000 +0200
@@ -619,6 +619,7 @@
 	uint32_t i;
 	int n = 0;
 	int last_used_index=-1;
+	int sector_size_mul = get_sector_size(fd)/512;
 
 	if (!find_valid_gpt (fd, &gpt, &ptes) || !gpt || !ptes) {
 		if (gpt)
@@ -634,9 +635,9 @@
 			sp[n].size = 0;
 			n++;
 		} else {
-			sp[n].start = __le64_to_cpu(ptes[i].starting_lba);
-			sp[n].size  = __le64_to_cpu(ptes[i].ending_lba) -
-				__le64_to_cpu(ptes[i].starting_lba) + 1;
+			sp[n].start = __le64_to_cpu(ptes[i].starting_lba)*sector_size_mul;
+			sp[n].size  = (__le64_to_cpu(ptes[i].ending_lba) -
+				__le64_to_cpu(ptes[i].starting_lba) + 1)*sector_size_mul;
                         last_used_index=n;
 			n++;
 		}





More information about the pkg-lvm-maintainers mailing list