[gparted] Rework align to MiB adjustments to end sector of partition
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Rework align to MiB adjustments to end sector of partition
- Date: Tue, 27 Mar 2012 20:33:15 +0000 (UTC)
commit 1c47c17a476ade49ea3b8c72c7c84700b0cd08bd
Author: Curtis Gedak <gedakc gmail com>
Date: Tue Mar 27 13:42:00 2012 -0600
Rework align to MiB adjustments to end sector of partition
Ensure at least 2 sectors for Extended Boot Record (EBR) between end
of logical partition and start of next logical partition.
Ensure at least 34 sectors reserved for backup GUID Partition Table
(GPT) after the end of the last partition.
src/GParted_Core.cc | 31 +++++++++++++++++--------------
1 files changed, 17 insertions(+), 14 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 62be59e..faff717 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -513,6 +513,11 @@ bool GParted_Core::snap_to_mebibyte( const Device & device, Partition & partitio
}
}
+ //Align end sector
+ diff = (partition .sector_end + 1) % ( MEBIBYTE / partition .sector_size);
+ if ( diff )
+ partition .sector_end -= diff ;
+
//If this is a logical partition not at end of drive then check to see if space is
// required for a following logical partition Extended Boot Record
if ( partition .type == TYPE_LOGICAL )
@@ -525,8 +530,8 @@ bool GParted_Core::snap_to_mebibyte( const Device & device, Partition & partitio
index_extended = t ;
}
- //If there is a following logical partition that starts a mebibyte or less
- // from the end of this partition, then reserve a mebibyte for the EBR.
+ //If there is a following logical partition that starts less than 2 sectors from
+ // the end of this partition, then reserve at least a mebibyte for the EBR.
if ( index_extended != -1 )
{
for ( unsigned int t = 0; t < device .partitions[ index_extended ] .logicals .size(); t++ )
@@ -534,28 +539,26 @@ bool GParted_Core::snap_to_mebibyte( const Device & device, Partition & partitio
if ( ( device .partitions[ index_extended ] .logicals[ t ] .type == TYPE_LOGICAL )
&& ( device .partitions[ index_extended ] .logicals[ t ] .sector_start > partition .sector_end )
&& ( ( device .partitions[ index_extended ] .logicals[ t ] .sector_start - partition .sector_end )
- < ( MEBIBYTE / device .sector_size )
+ //Unless specifically told otherwise, the Linux kernel considers extended
+ // boot records to be two sectors long, in order to "leave room for LILO".
+ < 2
)
)
- partition .sector_end -= 1 ;
+ partition .sector_end -= ( MEBIBYTE / partition .sector_size ) ;
}
}
}
- //If this is a GPT partition table then reserve a mebibyte at the end of the device
- // for the backup partition table
- if ( device .disktype == "gpt"
- && ( ( device .length - partition .sector_end ) <= ( MEBIBYTE / device .sector_size ) )
+ //If this is a GPT partition table and the partition ends less than 34 sectors
+ // from the end of the device, then reserve at least a mebibyte for the
+ // backup partition table
+ if ( device .disktype == "gpt"
+ && ( ( device .length - partition .sector_end ) < 34 )
)
{
- partition .sector_end -= 1 ;
+ partition .sector_end -= ( MEBIBYTE / partition .sector_size ) ;
}
- //Align end sector
- diff = (partition .sector_end + 1) % ( MEBIBYTE / partition .sector_size);
- if ( diff )
- partition .sector_end -= diff ;
-
return true ;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]