From cc1542fa8480fb15775cac82c2bdc47981aa5eee Mon Sep 17 00:00:00 2001 From: Volker Lanz Date: Thu, 15 Apr 2010 10:20:36 +0000 Subject: [PATCH] change the way the number of free sectors before and after a partition is calculated: In case of the free sectors after a partition, we used to just add the length of the following unallocated partition to the last sector. This does not work for extended partitions where unallocated partitions have number_of_sectors_per_track free space before AND after them. This is because if a new partition is created in place of the unallocated space and this partition is followed by another logical, we need two times number_of_sectors_per_track for two extended boot records. If, however, the partition in question is simply resized to fill up all space following it (and is still followed by a logical), we only need ONE EBR. To solve this, we now use the difference between the following partition's last sector and the partition's last sector instead. The same is true for free sectors preceding a partition, of course. svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1115127 --- src/core/partitiontable.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/partitiontable.cpp b/src/core/partitiontable.cpp index 2a98044..c8e8e56 100644 --- a/src/core/partitiontable.cpp +++ b/src/core/partitiontable.cpp @@ -67,8 +67,10 @@ qint64 PartitionTable::freeSectorsBefore(const Partition& p) const { const Partition* pred = predecessor(p); + // due to the space required for extended boot records the + // below is NOT the same as pred->length() if (pred && pred->roles().has(PartitionRole::Unallocated)) - return pred->length(); + return p.firstSector() - pred->firstSector(); return 0; } @@ -82,8 +84,10 @@ qint64 PartitionTable::freeSectorsAfter(const Partition& p) const { const Partition* succ = successor(p); + // due to the space required for extended boot records the + // below is NOT the same as succ->length() if (succ && succ->roles().has(PartitionRole::Unallocated)) - return succ->length(); + return succ->lastSector() - p.lastSector(); return 0; }