[parted-devel] [PATCH] libparted/disk.c: Fix contiguous partition overlap warning

Evan Green evgreen at chromium.org
Wed May 8 17:22:53 BST 2019


When checking if a new partition overlaps, _partition_get_overlap_constraint()
goes through the existing partition table looking for the free region where
the partition could live, finding its bounds, and then ensuring that region is
non-zero in size. However if the proposed partition is exactly one sector in
size and just fits into the existing scheme, the function will fail,
complaining that the partitions overlap when in fact they do not.

The fix is to allow min_start to be equal to max_end, since they are both
inclusive.

As a repro example, attempting to "print" an image with the following
partition table fails with an overlap complaint:
Model:  (file)
Disk chromiumos_test_image.bin: 9425073s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start     End       Size      File system  Name        Flags
11      64s       64s       1s                     RWFW
 6      65s       65s       1s                     KERN-C
 7      66s       66s       1s                     ROOT-C
 9      67s       67s       1s                     reserved
10      68s       68s       1s                     reserved
 2      69s       65604s    65536s                 KERN-A
 4      65605s    131140s   65536s                 KERN-B
 8      135168s   167935s   32768s    ext4         OEM         msftdata
12      167936s   299007s   131072s   fat16        EFI-SYSTEM  boot, legacy_boot, esp
 5      299008s   303103s   4096s                  ROOT-B
 3      303104s   5218303s  4915200s  ext2         ROOT-A
 1      5218304s  9425024s  4206721s  ext4         STATE       msftdata

Below is an annotation of how that function behaves when running partition 10
through _partition_get_overlap_constraint():
Adding part 10, 68 to 68
Walk 6
Set min_start to 66, end of part 6
Walk 7
Set min_start to 67, end of part 7
Walk 9
Set min_start to 68, end of part 9
Capping max_end to part 2 start 68
Finally num 10 min_start 68 max_end 68

As you can see, min_start and max_end are equal, which is okay, since the
proposed partition 10 is exactly 1 sector in size.

Signed-off-by: Evan Green <evgreen at chromium.org>
---
 libparted/disk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libparted/disk.c b/libparted/disk.c
index fe82f44..b4a8e2f 100644
--- a/libparted/disk.c
+++ b/libparted/disk.c
@@ -1793,7 +1793,7 @@ _partition_get_overlap_constraint (PedPartition* part, PedGeometry* geom)
 	if (walk)
 		max_end = walk->geom.start - 1;
 
-	if (min_start >= max_end)
+	if (min_start > max_end)
 		return NULL;
 
 	ped_geometry_init (&free_space, part->disk->dev,
-- 
2.20.1




More information about the parted-devel mailing list