[gparted] Allow creation of partition at sector 2048 when following another (#172)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Allow creation of partition at sector 2048 when following another (#172)
- Date: Wed, 27 Oct 2021 15:35:14 +0000 (UTC)
commit 0bfbac4f65f0ba082e8a8abf30599ea2bcc33f34
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Tue Oct 19 19:06:20 2021 +0100
Allow creation of partition at sector 2048 when following another (#172)
[This commit message and test case is written assuming a drive with a
(logical) sector size of 512 bytes. GParted equally well works with
other sector sizes because the limit is expressed as 1 MiB / sector
size. Adjust the test case sector counts as needed when testing with
different sector sized drives.]
Prepare an MSDOS or GPT partitioned disk with the first partition within
the first 1 MiB.
For MSDOS use:
dd if=/dev/zero bs=1M of=/dev/sdb
echo 1,2047 | sfdisk -uS --force /dev/sdb
For GPT use:
sgdisk --zap-all /dev/sdb
sgdisk --set-alignment=1 --new 1:34:2047 /dev/sdb
In GParted create a new partition on /dev/sdb as near to the start of
the drive as possible. GParted insists on added an extra 1 MiB of space
before the new partition, making it start at sector 4096, even though
sector 2048 is free and aligns to whole megabytes.
Delete the preceding partition. Now GParted allows the new partition
to be created starting at sector 2048.
GParted only needs to add padding of 1 MiB to account for the partition
table at the start of the drive when the possible start is within the
first MiB, not already at the first MiB. Fix this off by one error in
the sector comparison.
The reason this has bug has never occurred before is because it is very
unusual to have the first partition entirely within the first 1 MiB.
Normally either the (start of) the drive is free so GParted creates an
unallocated partition object starting at sector 0, so adding 1 MiB of
padding to preserve the partition table is correct; or the first
partition starts at 1 MiB so the possible start for a second partition
is much later in the drive.
Closes #172 - GParted doesn't allow creation of a partition starting at
sector 2048 if there is a partition before it
src/Dialog_Base_Partition.cc | 2 +-
src/Win_GParted.cc | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/src/Dialog_Base_Partition.cc b/src/Dialog_Base_Partition.cc
index 943ef816..a025ac49 100644
--- a/src/Dialog_Base_Partition.cc
+++ b/src/Dialog_Base_Partition.cc
@@ -510,7 +510,7 @@ int Dialog_Base_Partition::MB_Needed_for_Boot_Record( const Partition & partitio
)
|| ( partition .type == TYPE_LOGICAL )
/* Beginning of disk device */
- || ( partition .sector_start <= (MEBIBYTE / partition .sector_size) )
+ || (partition.sector_start < (MEBIBYTE / partition.sector_size))
)
return 1 ;
else
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index 9e07a801..3bf5054d 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -1363,7 +1363,7 @@ void Win_GParted::set_valid_operations()
)
|| ( selected_partition_ptr->type == TYPE_LOGICAL )
/* Beginning of disk device */
- || ( selected_partition_ptr->sector_start <= (MEBIBYTE /
selected_partition_ptr->sector_size) )
+ || (selected_partition_ptr->sector_start < (MEBIBYTE /
selected_partition_ptr->sector_size))
)
required_size += MEBIBYTE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]