"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Dialog_Base_Partition.cc" between
gparted-1.0.0.tar.gz and gparted-1.1.0.tar.gz

About: GParted is a graphical partition editor for creating, reorganizing, and deleting disk partitions (using GNU libparted).

Dialog_Base_Partition.cc  (gparted-1.0.0):Dialog_Base_Partition.cc  (gparted-1.1.0)
skipping to change at line 18 skipping to change at line 18
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>. * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Device.h"
#include "Dialog_Base_Partition.h" #include "Dialog_Base_Partition.h"
#include "Partition.h" #include "Partition.h"
#include "Utils.h" #include "Utils.h"
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
namespace GParted namespace GParted
{ {
Dialog_Base_Partition::Dialog_Base_Partition() Dialog_Base_Partition::Dialog_Base_Partition(const Device& device)
: m_device(device)
{ {
frame_resizer_base = NULL; frame_resizer_base = NULL;
GRIP = false ; GRIP = false ;
this ->fixed_start = false ; this ->fixed_start = false ;
this ->set_resizable( false ); this ->set_resizable( false );
ORIG_BEFORE = ORIG_SIZE = ORIG_AFTER = -1 ; ORIG_BEFORE = ORIG_SIZE = ORIG_AFTER = -1 ;
MIN_SPACE_BEFORE_MB = -1 ; MIN_SPACE_BEFORE_MB = -1 ;
// Pack resizer hbox // Pack resizer hbox
hbox_resizer.set_orientation(Gtk::ORIENTATION_HORIZONTAL); hbox_resizer.set_orientation(Gtk::ORIENTATION_HORIZONTAL);
skipping to change at line 200 skipping to change at line 202
{ {
case 0: case 0:
new_partition->alignment = ALIGN_CYLINDER; new_partition->alignment = ALIGN_CYLINDER;
break; break;
case 1: case 1:
new_partition->alignment = ALIGN_MEBIBYTE; new_partition->alignment = ALIGN_MEBIBYTE;
{ {
// If partition size is not an integer multiple o f MiB or // If partition size is not an integer multiple o f MiB or
// the start or end sectors are not MiB aligned, and space // the start or end sectors are not MiB aligned, and space
// is available, then add 1 MiB to partition so r equested // is available, then add 1 MiB to partition so r equested
// size is kept after GParted_Core::snap_to_mebib // size is kept after snap_to_mebibyte() method r
yte ounding.
// method rounding.
Sector partition_size = new_partition->sector_end - new_partition->sector_start + 1; Sector partition_size = new_partition->sector_end - new_partition->sector_start + 1;
Sector sectors_in_mib = MEBIBYTE / new_partition- >sector_size; Sector sectors_in_mib = MEBIBYTE / new_partition- >sector_size;
if ( ( ( partition_size % sectors_in_mib > 0 ) if ( ( ( partition_size % sectors_in_mib > 0 )
|| ( new_partition->sector_start % sect ors_in_mib > 0 ) || ( new_partition->sector_start % sect ors_in_mib > 0 )
|| ( ( new_partition->sector_end + 1 ) % sectors_in_mib > 0 ) || ( ( new_partition->sector_end + 1 ) % sectors_in_mib > 0 )
) )
&& ( partition_size + sectors_in_mib < total _length ) && ( partition_size + sectors_in_mib < total _length )
) )
new_partition->sector_end += sectors_in_m ib; new_partition->sector_end += sectors_in_m ib;
} }
break; break;
case 2: case 2:
new_partition->alignment = ALIGN_STRICT; new_partition->alignment = ALIGN_STRICT;
break; break;
default: default:
new_partition->alignment = ALIGN_MEBIBYTE; new_partition->alignment = ALIGN_MEBIBYTE;
break; break;
} }
new_partition->free_space_before = Sector(spinbutton_before.get_value_as_
int()) * (MEBIBYTE / new_partition->sector_size);
// If the original before value has not changed, then set indicator to ke
ep start sector unchanged.
if ( ORIG_BEFORE == spinbutton_before .get_value_as_int() )
new_partition->strict_start = TRUE;
snap_to_alignment(m_device, *new_partition);
//update partition usage //update partition usage
if ( new_partition->sector_usage_known() ) if ( new_partition->sector_usage_known() )
{ {
Sector new_size = new_partition->get_sector_length(); Sector new_size = new_partition->get_sector_length();
if ( old_size == new_size ) if ( old_size == new_size )
{ {
//Pasting into new same sized partition or moving partiti on keeping the same size, //Pasting into new same sized partition or moving partiti on keeping the same size,
// therefore only block copy operation will be performed maintaining file system size. // therefore only block copy operation will be performed maintaining file system size.
new_partition->set_sector_usage( new_partition->set_sector_usage(
new_partition->sectors_used + new_partiti on->sectors_unused, new_partition->sectors_used + new_partiti on->sectors_unused,
new_partition->sectors_unused ); new_partition->sectors_unused );
} }
else else
{ {
//Pasting into new larger partition or (moving and) resiz ing partition larger or smaller, //Pasting into new larger partition or (moving and) resiz ing partition larger or smaller,
// therefore block copy followed by file system grow or shrink operations will be // therefore block copy followed by file system grow or shrink operations will be
// performed making the file system fill the partition. // performed making the file system fill the partition.
new_partition->set_sector_usage( new_size, new_size - new _partition->sectors_used ); new_partition->set_sector_usage( new_size, new_size - new _partition->sectors_used );
} }
} }
}
new_partition->free_space_before = Sector(spinbutton_before.get_value_as_ void Dialog_Base_Partition::snap_to_alignment(const Device& device, Partition& p
int()) * (MEBIBYTE / new_partition->sector_size); artition)
{
if (partition.alignment == ALIGN_CYLINDER)
snap_to_cylinder(device, partition);
else if (partition.alignment == ALIGN_MEBIBYTE)
snap_to_mebibyte(device, partition);
}
//if the original before value has not changed, then set indicator to kee void Dialog_Base_Partition::snap_to_cylinder(const Device& device, Partition& pa
p start sector unchanged rtition)
if ( ORIG_BEFORE == spinbutton_before .get_value_as_int() ) {
new_partition->strict_start = TRUE; Sector diff = 0;
// Determine if partition size is less than half a disk cylinder.
bool less_than_half_cylinder = false;
if (partition.sector_end - partition.sector_start < device.cylsize / 2)
less_than_half_cylinder = true;
if (partition.type == TYPE_LOGICAL ||
partition.sector_start == device.sectors )
{
// Must account the relative offset between:
// (A) the Extended Boot Record sector and the next track of the
// logical partition (usually 63 sectors), and
// (B) the Master Boot Record sector and the next track of the fi
rst
// primary partition.
diff = (partition.sector_start - device.sectors) % device.cylsize
;
}
else if (partition.sector_start == 34)
{
// (C) the GUID Partition Table (GPT) and the start of the data
// partition at sector 34.
diff = (partition.sector_start - 34) % device.cylsize;
}
else
{
diff = partition.sector_start % device.cylsize;
}
if (diff && ! partition.strict_start)
{
if (diff < device.cylsize / 2 || less_than_half_cylinder)
partition.sector_start -= diff;
else
partition.sector_start += device.cylsize - diff;
}
diff = (partition.sector_end + 1) % device.cylsize;
if (diff)
{
if (diff < device.cylsize / 2 && ! less_than_half_cylinder)
partition.sector_end -= diff;
else
partition.sector_end += device.cylsize - diff;
}
}
void Dialog_Base_Partition::snap_to_mebibyte(const Device& device, Partition& pa
rtition)
{
Sector diff = 0;
if (partition.sector_start < 2 || partition.type == TYPE_LOGICAL)
{
// Must account the relative offset between:
// (A) the Master Boot Record sector and the first primary/extend
ed partition, and
// (B) the Extended Boot Record sector and the logical partition.
// If strict_start is set then do not adjust sector start.
// If this partition is not simply queued for a reformat then
// add space minimum to force alignment to next mebibyte.
if (! partition.strict_start &&
partition.free_space_before == 0 &&
partition.status != STAT_FORMATTED )
{
// Unless specifically told otherwise, the Linux kernel c
onsiders extended
// boot records to be two sectors long, in order to "leav
e room for LILO".
partition.sector_start += 2;
}
}
// Calculate difference offset from Mebibyte boundary.
diff = Sector(partition.sector_start % (MEBIBYTE / partition.sector_size)
);
// Align start sector only if permitted to change start sector.
if (diff && (! partition.strict_start
||
(partition.strict_start && (partition.status == STAT_NEW ||
partition.status == STAT_COPY )
) ))
{
partition.sector_start += MEBIBYTE / partition.sector_size - diff
;
// If this is an extended partition then check to see if sufficie
nt space is
// available for any following logical partition Extended Boot Re
cord.
if (partition.type == TYPE_EXTENDED)
{
// If there is logical partition that starts less than 2
sectors from
// the start of this partition, then reserve a mebibyte f
or the EBR.
int index_extended = find_extended_partition(device.parti
tions);
if (index_extended >= 0)
{
for (unsigned int i = 0; i < device.partitions[in
dex_extended].logicals.size(); i++)
{
if (device.partitions[index_extended].log
icals[i].type == TYPE_LOGICAL &&
// Unless specifically told otherwise
, the Linux kernel considers extended
// boot records to be two sectors lon
g, in order to "leave room for LILO".
device.partitions[index_extended].log
icals[i].sector_start
- partition.sector_start < 2 )
{
partition.sector_start -= MEBIBYT
E / partition.sector_size;
}
}
}
}
}
// 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 i
f space
// is required for a following logical partition Extended Boot Record.
if (partition.type == TYPE_LOGICAL)
{
// If there is a following logical partition that starts less tha
n 2 sectors
// from the end of this partition, then reserve at least a mebiby
te for the EBR.
int index_extended = find_extended_partition(device.partitions);
if (index_extended >= 0)
{
for (unsigned int i = 0; i < device.partitions[index_exte
nded].logicals.size(); i++)
{
if (device.partitions[index_extended].logicals[i]
.type == TYPE_LOGICAL &&
device.partitions[index_extended].logicals[i]
.sector_start > partition.sector_end &&
// Unless specifically told otherwise, the Li
nux kernel considers extended
// boot records to be two sectors long, in or
der to "leave room for LILO".
device.partitions[index_extended].logicals[i]
.sector_start
- partition.sector_end < 2 )
{
partition.sector_end -= MEBIBYTE / partit
ion.sector_size;
}
}
}
// If the logical partition end is beyond the end of the extended
partition
// then reduce logical partition end by a mebibyte to address the
overlap.
if (index_extended != -1
&&
partition.sector_end > device.partitions[index_extended].se
ctor_end )
{
partition.sector_end -= MEBIBYTE / partition.sector_size;
}
}
// If this is a primary or an extended partition and the partition overla
ps
// the start of the next primary or extended partition then subtract a
// mebibyte from the end of the partition to address the overlap.
if (partition.type == TYPE_PRIMARY || partition.type == TYPE_EXTENDED)
{
for (unsigned int i = 0; i < device.partitions.size(); i++)
{
if ((device.partitions[i].type == TYPE_PRIMARY ||
device.partitions[i].type == TYPE_EXTENDED )
&&
// For a change to an existing partition, (e.g., mov
e or resize)
// skip comparing to original partition and only com
pare to
// other existing partitions.
partition.status == STAT_REAL
&&
partition.partition_number != device.partitions[i].pa
rtition_number &&
device.partitions[i].sector_start > partition.sector
_start &&
device.partitions[i].sector_start <= partition.sector
_end )
{
partition.sector_end -= MEBIBYTE / partition.sect
or_size;
}
}
}
// If this is an extended partition then check to see if the end of the
// extended partition encompasses the end of the last logical partition.
if (partition.type == TYPE_EXTENDED)
{
// If there is logical partition that has an end sector beyond th
e
// end of the extended partition, then set the extended partition
// end sector to be the same as the end of the logical partition.
for (unsigned int i = 0; i < partition.logicals.size(); i++)
{
if (partition.logicals[i].type == TYPE_LOGICAL
&&
partition.logicals[i].sector_end > partition.sector_
end )
{
partition.sector_end = partition.logicals[i].sect
or_end;
}
}
}
// If this is a GPT partition table and the partition ends less than 34 s
ectors
// from the end of the device, then reserve at least a mebibyte for the b
ackup
// partition table.
if (device.disktype == "gpt" && device.length - partition.sector_end < 34
)
partition.sector_end -= MEBIBYTE / partition.sector_size;
} }
void Dialog_Base_Partition::Set_Confirm_Button( CONFIRMBUTTON button_type ) void Dialog_Base_Partition::Set_Confirm_Button( CONFIRMBUTTON button_type )
{ {
switch( button_type ) switch( button_type )
{ {
case NEW : case NEW :
this ->add_button( Gtk::Stock::ADD, Gtk::RESPONSE_OK ); this ->add_button( Gtk::Stock::ADD, Gtk::RESPONSE_OK );
break ; break ;
 End of changes. 7 change blocks. 
10 lines changed or deleted 262 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)