2009-11-05 11:08:32 -07:00
|
|
|
/* Copyright (C) 2004 Bart
|
2011-06-09 09:59:41 -06:00
|
|
|
* Copyright (C) 2008, 2009, 2010, 2011 Curtis Gedak
|
2004-09-19 14:24:53 -06:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-01-23 03:59:48 -07:00
|
|
|
* GNU General Public License for more details.
|
2004-09-19 14:24:53 -06:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-23 03:59:48 -07:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2004-09-19 14:24:53 -06:00
|
|
|
*/
|
|
|
|
|
2016-10-18 16:45:28 -06:00
|
|
|
#include "Dialog_Partition_New.h"
|
2018-01-18 09:26:20 -07:00
|
|
|
#include "FileSystem.h"
|
2016-10-18 16:45:28 -06:00
|
|
|
#include "GParted_Core.h"
|
|
|
|
#include "Partition.h"
|
2018-01-15 11:07:58 -07:00
|
|
|
#include "Utils.h"
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2019-03-06 07:43:36 -07:00
|
|
|
#include <glibmm/ustring.h>
|
|
|
|
|
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
2015-06-02 06:10:45 -06:00
|
|
|
Dialog_Partition_New::Dialog_Partition_New( const Device & device,
|
2015-11-02 09:31:10 -07:00
|
|
|
const Partition & selected_partition,
|
2015-06-02 06:10:45 -06:00
|
|
|
bool any_extended,
|
|
|
|
unsigned short new_count,
|
|
|
|
const std::vector<FS> & FILESYSTEMS )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
|
|
|
/*TO TRANSLATORS: dialogtitle */
|
|
|
|
this ->set_title( _("Create new Partition") ) ;
|
|
|
|
Set_Resizer( false ) ;
|
|
|
|
Set_Confirm_Button( NEW ) ;
|
|
|
|
|
2004-12-12 07:57:04 -07:00
|
|
|
//set used (in pixels)...
|
2004-09-19 14:24:53 -06:00
|
|
|
frame_resizer_base ->set_used( 0 ) ;
|
2015-06-02 06:10:45 -06:00
|
|
|
|
2015-11-02 09:31:10 -07:00
|
|
|
set_data(device, selected_partition, any_extended, new_count, FILESYSTEMS );
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2015-12-13 07:38:30 -07:00
|
|
|
Dialog_Partition_New::~Dialog_Partition_New()
|
|
|
|
{
|
|
|
|
delete new_partition;
|
|
|
|
new_partition = NULL;
|
2018-08-30 14:10:35 -06:00
|
|
|
|
|
|
|
// Work around a Gtk issue fixed in 3.24.0.
|
|
|
|
// https://gitlab.gnome.org/GNOME/gtk/issues/125
|
|
|
|
hide();
|
2015-12-13 07:38:30 -07:00
|
|
|
}
|
|
|
|
|
2015-06-02 06:10:45 -06:00
|
|
|
void Dialog_Partition_New::set_data( const Device & device,
|
2015-11-02 09:31:10 -07:00
|
|
|
const Partition & selected_partition,
|
2015-03-17 15:14:31 -06:00
|
|
|
bool any_extended,
|
|
|
|
unsigned short new_count,
|
|
|
|
const std::vector<FS> & FILESYSTEMS )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2004-10-06 09:32:40 -06:00
|
|
|
this ->new_count = new_count;
|
2015-12-05 09:26:30 -07:00
|
|
|
new_partition = selected_partition.clone();
|
2008-12-07 11:43:35 -07:00
|
|
|
|
2015-11-29 01:57:45 -07:00
|
|
|
// Copy only supported file systems, excluding LUKS, from GParted_Core FILESYSTEMS
|
|
|
|
// vector. Add FS_CLEARED, FS_UNFORMATTED and FS_EXTENDED at the end. This
|
|
|
|
// decides the order of items in the file system menu built by
|
2018-07-31 06:12:21 -06:00
|
|
|
// build_filesystems_combo().
|
2014-10-11 14:31:05 -06:00
|
|
|
this->FILESYSTEMS.clear();
|
|
|
|
for ( unsigned i = 0 ; i < FILESYSTEMS.size() ; i ++ )
|
2008-12-07 11:43:35 -07:00
|
|
|
{
|
2015-11-29 01:57:45 -07:00
|
|
|
if ( GParted_Core::supported_filesystem( FILESYSTEMS[i].filesystem ) &&
|
|
|
|
FILESYSTEMS[i].filesystem != FS_LUKS )
|
2014-10-11 14:31:05 -06:00
|
|
|
this->FILESYSTEMS.push_back( FILESYSTEMS[i] );
|
2008-12-07 11:43:35 -07:00
|
|
|
}
|
|
|
|
|
2010-10-02 18:44:41 -06:00
|
|
|
FS fs_tmp ;
|
2012-12-08 12:41:00 -07:00
|
|
|
//... add FS_CLEARED
|
|
|
|
fs_tmp .filesystem = FS_CLEARED ;
|
|
|
|
fs_tmp .create = FS::GPARTED ;
|
|
|
|
this ->FILESYSTEMS .push_back( fs_tmp ) ;
|
|
|
|
|
|
|
|
//... add FS_UNFORMATTED
|
2018-10-14 06:37:34 -06:00
|
|
|
fs_tmp.filesystem = FS_UNFORMATTED;
|
2011-06-09 09:59:41 -06:00
|
|
|
fs_tmp .create = FS::GPARTED ;
|
2010-10-02 18:44:41 -06:00
|
|
|
this ->FILESYSTEMS .push_back( fs_tmp ) ;
|
2008-12-07 11:43:35 -07:00
|
|
|
|
2014-10-11 14:31:05 -06:00
|
|
|
// ... finally add FS_EXTENDED. Needed so that when creating an extended
|
|
|
|
// partition it is identified correctly before the operation is applied.
|
2010-10-02 18:44:41 -06:00
|
|
|
fs_tmp = FS();
|
2018-10-14 06:37:34 -06:00
|
|
|
fs_tmp.filesystem = FS_EXTENDED;
|
2018-10-13 05:59:31 -06:00
|
|
|
fs_tmp.create = FS::NONE;
|
2010-10-02 18:44:41 -06:00
|
|
|
this ->FILESYSTEMS .push_back( fs_tmp ) ;
|
2019-03-06 07:43:36 -07:00
|
|
|
|
|
|
|
// Add table with selection menu's...
|
|
|
|
grid_create.set_border_width(10);
|
|
|
|
grid_create.set_row_spacing(5);
|
|
|
|
hbox_main.pack_start(grid_create, Gtk::PACK_SHRINK);
|
|
|
|
|
2018-07-31 04:51:47 -06:00
|
|
|
/* TO TRANSLATORS: used as label for a list of choices. Create as: <combo box with choices> */
|
2019-03-06 07:43:36 -07:00
|
|
|
grid_create.attach(*Utils::mk_label(Glib::ustring(_("Create as:")) + "\t"),
|
|
|
|
0, 0, 1, 1);
|
2018-07-31 04:51:47 -06:00
|
|
|
|
|
|
|
// Fill partition type combo.
|
|
|
|
combo_type.items().push_back(_("Primary Partition"));
|
|
|
|
combo_type.items().push_back(_("Logical Partition"));
|
|
|
|
combo_type.items().push_back(_("Extended Partition"));
|
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//determine which PartitionType is allowed
|
2015-03-17 15:14:31 -06:00
|
|
|
if ( device.disktype != "msdos" && device.disktype != "dvh" )
|
2010-02-24 11:39:42 -07:00
|
|
|
{
|
2018-07-31 04:51:47 -06:00
|
|
|
combo_type.items()[1].set_sensitive(false);
|
|
|
|
combo_type.items()[2].set_sensitive(false);
|
|
|
|
combo_type.set_active(0);
|
2010-02-24 11:39:42 -07:00
|
|
|
}
|
2015-11-02 09:31:10 -07:00
|
|
|
else if ( selected_partition.inside_extended )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2018-07-31 04:51:47 -06:00
|
|
|
combo_type.items()[0].set_sensitive(false);
|
|
|
|
combo_type.items()[2].set_sensitive(false);
|
|
|
|
combo_type.set_active(1);
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-31 04:51:47 -06:00
|
|
|
combo_type.items()[1].set_sensitive(false);
|
2004-10-06 09:32:40 -06:00
|
|
|
if ( any_extended )
|
2018-07-31 04:51:47 -06:00
|
|
|
combo_type.items()[2].set_sensitive(false);
|
|
|
|
combo_type.set_active(0);
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
2018-07-31 04:51:47 -06:00
|
|
|
|
2006-02-25 03:09:30 -07:00
|
|
|
//160 is the ideal width for this table column.
|
|
|
|
//(when one widget is set, the rest wil take this width as well)
|
2018-07-31 04:51:47 -06:00
|
|
|
combo_type.set_size_request(160, -1);
|
|
|
|
|
|
|
|
combo_type.signal_changed().connect(
|
2018-08-03 07:16:22 -06:00
|
|
|
sigc::bind<bool>(sigc::mem_fun(*this, &Dialog_Partition_New::combobox_changed), true));
|
2019-03-06 07:43:36 -07:00
|
|
|
grid_create.attach(combo_type, 1, 0, 1, 1);
|
2018-07-31 04:51:47 -06:00
|
|
|
|
2015-03-14 09:38:00 -06:00
|
|
|
// Partition name
|
2019-03-06 07:43:36 -07:00
|
|
|
grid_create.attach(*Utils::mk_label(Glib::ustring(_("Partition name:")) + "\t"),
|
|
|
|
0, 1, 1, 1);
|
2015-03-14 09:38:00 -06:00
|
|
|
// Initialise text entry box
|
|
|
|
partition_name_entry.set_width_chars( 20 );
|
|
|
|
partition_name_entry.set_sensitive( device.partition_naming_supported() );
|
|
|
|
partition_name_entry.set_max_length( device.get_max_partition_name_length() );
|
|
|
|
// Add entry box to table
|
2019-03-06 07:43:36 -07:00
|
|
|
grid_create.attach(partition_name_entry, 1, 1, 1, 1);
|
2015-03-14 09:38:00 -06:00
|
|
|
|
2019-03-06 07:43:36 -07:00
|
|
|
// File systems to choose from
|
|
|
|
grid_create.attach(*Utils::mk_label(Glib::ustring(_("File system:")) + "\t"),
|
|
|
|
0, 1, 2, 3);
|
2015-03-14 09:38:00 -06:00
|
|
|
|
2018-07-31 06:12:21 -06:00
|
|
|
build_filesystems_combo(device.readonly);
|
|
|
|
|
|
|
|
combo_filesystem.signal_changed().connect(
|
2018-08-03 07:16:22 -06:00
|
|
|
sigc::bind<bool>(sigc::mem_fun(*this, &Dialog_Partition_New::combobox_changed), false));
|
2019-03-06 07:43:36 -07:00
|
|
|
grid_create.attach(combo_filesystem, 1, 2, 1, 1);
|
2008-04-07 13:41:18 -06:00
|
|
|
|
2019-03-06 07:43:36 -07:00
|
|
|
// Label
|
|
|
|
grid_create.attach(*Utils::mk_label(_("Label:")), 0, 3, 1, 1);
|
2008-04-07 13:41:18 -06:00
|
|
|
//Create Text entry box
|
2015-03-14 09:10:41 -06:00
|
|
|
filesystem_label_entry.set_width_chars( 20 );
|
2019-03-06 07:43:36 -07:00
|
|
|
// Add entry box to table
|
|
|
|
grid_create.attach(filesystem_label_entry, 1, 3, 1, 1);
|
|
|
|
|
|
|
|
// Set vexpand on all grid_create child widgets
|
|
|
|
std::vector<Gtk::Widget*> children = grid_create.get_children();
|
|
|
|
for (std::vector<Gtk::Widget*>::iterator it = children.begin(); it != children.end(); ++it)
|
|
|
|
(*it)->set_vexpand();
|
2008-04-07 13:41:18 -06:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//set some widely used values...
|
2015-11-02 09:31:10 -07:00
|
|
|
MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record( selected_partition );
|
|
|
|
START = selected_partition.sector_start;
|
|
|
|
total_length = selected_partition.sector_end - selected_partition.sector_start;
|
|
|
|
TOTAL_MB = Utils::round( Utils::sector_to_unit( selected_partition.get_sector_length(),
|
|
|
|
selected_partition.sector_size, UNIT_MIB ) );
|
2005-01-19 13:01:39 -07:00
|
|
|
MB_PER_PIXEL = TOTAL_MB / 500.00 ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2008-11-18 16:58:17 -07:00
|
|
|
//set first enabled file system
|
2018-07-31 06:12:21 -06:00
|
|
|
combo_filesystem.set_active(first_creatable_fs);
|
2018-08-03 07:16:22 -06:00
|
|
|
combobox_changed(false);
|
|
|
|
|
2004-12-12 07:57:04 -07:00
|
|
|
//set spinbuttons initial values
|
|
|
|
spinbutton_after .set_value( 0 ) ;
|
2018-01-15 11:07:58 -07:00
|
|
|
spinbutton_size.set_value( ceil( fs_limits.max_size / double(MEBIBYTE) ) );
|
2010-05-20 10:00:14 -06:00
|
|
|
spinbutton_before .set_value( MIN_SPACE_BEFORE_MB ) ;
|
2004-12-12 07:57:04 -07:00
|
|
|
|
2010-05-20 15:30:04 -06:00
|
|
|
//Disable resizing when the total area is less than two mebibytes
|
|
|
|
if ( TOTAL_MB < 2 )
|
2004-12-10 13:42:23 -07:00
|
|
|
frame_resizer_base ->set_sensitive( false ) ;
|
2010-05-09 14:45:26 -06:00
|
|
|
|
2018-07-31 04:19:14 -06:00
|
|
|
// Connect signal handler for Dialog_Base_Partiton combo_alignment.
|
|
|
|
combo_alignment.signal_changed().connect(
|
2018-08-03 07:16:22 -06:00
|
|
|
sigc::bind<bool>(sigc::mem_fun(*this, &Dialog_Partition_New::combobox_changed), false));
|
2010-05-09 14:45:26 -06:00
|
|
|
|
2006-02-25 03:09:30 -07:00
|
|
|
this ->show_all_children() ;
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2015-12-16 13:15:58 -07:00
|
|
|
const Partition & Dialog_Partition_New::Get_New_Partition()
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2015-12-13 07:38:30 -07:00
|
|
|
g_assert( new_partition != NULL ); // Bug: Not initialised by constructor calling set_data()
|
|
|
|
|
2005-12-07 04:21:27 -07:00
|
|
|
PartitionType part_type ;
|
2004-09-19 14:24:53 -06:00
|
|
|
Sector new_start, new_end;
|
2018-07-31 04:51:47 -06:00
|
|
|
|
|
|
|
switch (combo_type.get_active_row_number())
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2018-10-14 06:27:58 -06:00
|
|
|
case 0: part_type = TYPE_PRIMARY; break;
|
|
|
|
case 1: part_type = TYPE_LOGICAL; break;
|
|
|
|
case 2: part_type = TYPE_EXTENDED; break;
|
2005-12-07 04:21:27 -07:00
|
|
|
|
2018-10-14 06:27:58 -06:00
|
|
|
default: part_type = TYPE_UNALLOCATED;
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
2008-04-21 11:08:43 -06:00
|
|
|
|
2008-06-15 11:18:26 -06:00
|
|
|
//FIXME: Partition size is limited to just less than 1024 TeraBytes due
|
2008-04-21 11:08:43 -06:00
|
|
|
// to the maximum value of signed 4 byte integer.
|
2015-12-16 13:15:58 -07:00
|
|
|
new_start = START + Sector(spinbutton_before.get_value_as_int()) *
|
|
|
|
(MEBIBYTE / new_partition->sector_size);
|
|
|
|
new_end = new_start + Sector(spinbutton_size.get_value_as_int()) *
|
|
|
|
(MEBIBYTE / new_partition->sector_size)
|
|
|
|
- 1;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2006-01-20 16:35:06 -07:00
|
|
|
/* due to loss of precision during calcs from Sector -> MiB and back, it is possible the new
|
2006-01-07 08:04:42 -07:00
|
|
|
* partition thinks it's bigger then it can be. Here we try to solve this.*/
|
2015-12-13 07:38:30 -07:00
|
|
|
if ( new_start < new_partition->sector_start )
|
|
|
|
new_start = new_partition->sector_start;
|
|
|
|
if ( new_end > new_partition->sector_end )
|
|
|
|
new_end = new_partition->sector_end;
|
2015-05-26 15:38:42 -06:00
|
|
|
|
2015-11-03 15:00:36 -07:00
|
|
|
// Grow new partition a bit if freespaces are < 1 MiB
|
2015-12-16 13:15:58 -07:00
|
|
|
if ( new_start - new_partition->sector_start < MEBIBYTE / new_partition->sector_size )
|
2015-12-13 07:38:30 -07:00
|
|
|
new_start = new_partition->sector_start;
|
2015-12-16 13:15:58 -07:00
|
|
|
if ( new_partition->sector_end - new_end < MEBIBYTE / new_partition->sector_size )
|
2015-12-13 07:38:30 -07:00
|
|
|
new_end = new_partition->sector_end;
|
2015-11-03 15:00:36 -07:00
|
|
|
|
Fix temporary path name of new partitions (#759488)
In the UI new partitions were being named "unallocated" instead of
"New Partition #1", etc. Also deleting a new partition not yet created
deletes all new partitions from the operation list because it matches
by name only and they were all named "unallocated". Broken by this
recent commit:
762cd1094aece03986226a39d1f6b4fecfd73ee9
Return class member from Dialog_Partition_New::Get_New_Partition() (#757671)
Prior to this commit in the create new partition dialog code did these
relevant steps:
Dialog_Partition_New::Get_New_Partition()
Partition part_temp;
...
part_temp.Set(..., "New Partition #%1", ...);
Create local Partition object using default constructor which calls
Partition::Reset() and clears the paths vector. It then calls Set()
which appends the new name making the vector:
paths = ["New Partition #%1"]
After the above commit the code did these steps:
Dialog_Partition_New::Dialog_Partition_New(..., selected_partition, ...)
set_data(..., selected_partition, ...);
new_partition = selected_partition;
Dialog_Partition_New::Get_New_Partition(...)
new_partition.Set(..., "New Partition #%1", ...);
New_partition is copied from the selected unallocated partition in which
the new partition will be created. So new_partition is now named
"unallocated". Then the Set() call appends the new name making the
vector:
paths = ["unallocated", "New Partition #%1"]
As get_path() returns the first name in the paths vector the path name
changed from "New Partition #%1" to "unallocated" causing this bug.
Fix by resetting the new_partition object to clear all vestiges of it
being a copy of the selected unallocated partition, Reset() call, before
then calling Set(). This then appends the new name to an empty vector
making it contain just the required new name:
paths = ["New Partition #%1"]
Bug 759488 - Pending create partitions are all getting named
"unallocated"
2015-12-15 05:50:09 -07:00
|
|
|
// Copy a final few values needed from the original unallocated partition before
|
|
|
|
// resetting the Partition object and populating it as the new partition.
|
2015-12-13 07:38:30 -07:00
|
|
|
Glib::ustring device_path = new_partition->device_path;
|
2015-12-16 13:15:58 -07:00
|
|
|
Sector sector_size = new_partition->sector_size;
|
2015-12-13 07:38:30 -07:00
|
|
|
bool inside_extended = new_partition->inside_extended;
|
|
|
|
new_partition->Reset();
|
|
|
|
new_partition->Set( device_path,
|
2019-03-25 14:41:08 -06:00
|
|
|
Glib::ustring::compose( _("New Partition #%1"), new_count ),
|
2016-08-19 10:19:55 -06:00
|
|
|
new_count, part_type,
|
2018-07-31 06:12:21 -06:00
|
|
|
FILESYSTEMS[combo_filesystem.get_active_row_number()].filesystem,
|
2015-12-13 07:38:30 -07:00
|
|
|
new_start, new_end,
|
|
|
|
sector_size,
|
|
|
|
inside_extended, false );
|
|
|
|
new_partition->status = STAT_NEW;
|
2008-04-07 13:41:18 -06:00
|
|
|
|
2015-03-14 09:38:00 -06:00
|
|
|
// Retrieve partition name
|
2015-12-13 07:38:30 -07:00
|
|
|
new_partition->name = Utils::trim( partition_name_entry.get_text() );
|
2015-03-14 09:38:00 -06:00
|
|
|
|
2008-04-07 13:41:18 -06:00
|
|
|
//Retrieve Label info
|
2015-12-13 07:38:30 -07:00
|
|
|
new_partition->set_filesystem_label( Utils::trim( filesystem_label_entry.get_text() ) );
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2010-05-09 14:45:26 -06:00
|
|
|
//set alignment
|
2018-07-31 04:19:14 -06:00
|
|
|
switch (combo_alignment.get_active_row_number())
|
2010-05-09 14:45:26 -06:00
|
|
|
{
|
2015-12-13 07:38:30 -07:00
|
|
|
case 0:
|
|
|
|
new_partition->alignment = ALIGN_CYLINDER;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
new_partition->alignment = ALIGN_MEBIBYTE;
|
2015-11-03 15:00:36 -07:00
|
|
|
{
|
|
|
|
// If start sector not MiB aligned and free space available
|
|
|
|
// then add ~1 MiB to partition so requested size is kept
|
2015-12-13 07:38:30 -07:00
|
|
|
Sector diff = (MEBIBYTE / new_partition->sector_size) -
|
|
|
|
(new_partition->sector_end + 1) % (MEBIBYTE / new_partition->sector_size);
|
2015-11-03 15:00:36 -07:00
|
|
|
if ( diff
|
2015-12-13 07:38:30 -07:00
|
|
|
&& new_partition->sector_start % (MEBIBYTE / new_partition->sector_size ) > 0
|
|
|
|
&& new_partition->sector_end - START + 1 + diff < total_length
|
2015-11-03 15:00:36 -07:00
|
|
|
)
|
2015-12-13 07:38:30 -07:00
|
|
|
new_partition->sector_end += diff;
|
2015-11-03 15:00:36 -07:00
|
|
|
}
|
|
|
|
break;
|
2015-12-13 07:38:30 -07:00
|
|
|
case 2:
|
|
|
|
new_partition->alignment = ALIGN_STRICT;
|
|
|
|
break;
|
2010-05-09 14:45:26 -06:00
|
|
|
|
2015-12-13 07:38:30 -07:00
|
|
|
default:
|
|
|
|
new_partition->alignment = ALIGN_MEBIBYTE;
|
|
|
|
break;
|
2010-05-09 14:45:26 -06:00
|
|
|
}
|
2006-01-07 08:04:42 -07:00
|
|
|
|
2015-12-16 13:15:58 -07:00
|
|
|
new_partition->free_space_before = Sector(spinbutton_before .get_value_as_int()) * (MEBIBYTE / new_partition->sector_size);
|
2010-05-20 10:00:14 -06:00
|
|
|
|
2015-09-22 05:13:25 -06:00
|
|
|
// Create unallocated space within this new extended partition
|
|
|
|
//
|
|
|
|
// FIXME:
|
|
|
|
// Even after moving creation of the unallocated space within this new extended
|
|
|
|
// partition to here after the above alignment adjustment, the boundaries of the
|
|
|
|
// extended partition may be further adjusted by snap_to_alignment(). However the
|
|
|
|
// UI when creating logical partitions within this extended partition will use the
|
|
|
|
// boundaries as defined now by this unallocated space. Hence boundaries of
|
|
|
|
// logical partitions may be wrong or overlapping.
|
|
|
|
//
|
|
|
|
// Test case:
|
|
|
|
// On an empty MSDOS formatted disk, create a cylinder aligned extended partition.
|
|
|
|
// Then create a default MiB aligned logical partition filling the extended
|
|
|
|
// partition. Apply the operations. Creation of logical partition fails with
|
|
|
|
// libparted message "Can't have overlapping partitions."
|
|
|
|
//
|
|
|
|
// To fix this properly all the alignment constraints need to be applied here in
|
|
|
|
// the dialogs which create and modify partition boundaries. The logic in
|
|
|
|
// snap_to_alignment() needs including in it. It will need abstracting into a set
|
|
|
|
// of methods so that it can be used in each dialog which creates and modified
|
|
|
|
// partition boundaries.
|
2015-12-13 07:38:30 -07:00
|
|
|
if ( new_partition->type == TYPE_EXTENDED )
|
2015-09-22 05:13:25 -06:00
|
|
|
{
|
2015-12-04 06:14:41 -07:00
|
|
|
Partition * unallocated = new Partition();
|
2015-12-13 07:38:30 -07:00
|
|
|
unallocated->Set_Unallocated( new_partition->device_path,
|
|
|
|
new_partition->sector_start,
|
|
|
|
new_partition->sector_end,
|
2015-12-16 13:15:58 -07:00
|
|
|
new_partition->sector_size,
|
2015-12-04 06:14:41 -07:00
|
|
|
true );
|
2015-12-13 07:38:30 -07:00
|
|
|
new_partition->logicals.push_back_adopt( unallocated );
|
2015-09-22 05:13:25 -06:00
|
|
|
}
|
|
|
|
|
2015-12-13 07:38:30 -07:00
|
|
|
return *new_partition;
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2018-08-03 07:16:22 -06:00
|
|
|
|
|
|
|
void Dialog_Partition_New::combobox_changed(bool type)
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2015-12-13 07:38:30 -07:00
|
|
|
g_assert( new_partition != NULL ); // Bug: Not initialised by constructor calling set_data()
|
|
|
|
|
2018-07-31 04:51:47 -06:00
|
|
|
// combo_type
|
2004-09-19 14:24:53 -06:00
|
|
|
if ( type )
|
|
|
|
{
|
2018-07-31 04:51:47 -06:00
|
|
|
if (combo_type.get_active_row_number() == TYPE_EXTENDED &&
|
2018-07-31 06:12:21 -06:00
|
|
|
combo_filesystem.items().size() < FILESYSTEMS.size() )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2018-07-31 06:12:21 -06:00
|
|
|
combo_filesystem.items().push_back(Utils::get_filesystem_string(FS_EXTENDED));
|
|
|
|
combo_filesystem.set_active(combo_filesystem.items().back());
|
|
|
|
combo_filesystem.set_sensitive(false);
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
2018-07-31 04:51:47 -06:00
|
|
|
else if (combo_type.get_active_row_number() != TYPE_EXTENDED &&
|
2018-07-31 06:12:21 -06:00
|
|
|
combo_filesystem.items().size() == FILESYSTEMS.size() )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2018-07-31 06:12:21 -06:00
|
|
|
combo_filesystem.items().erase(combo_filesystem.items().back());
|
|
|
|
combo_filesystem.set_sensitive(true);
|
|
|
|
combo_filesystem.set_active(first_creatable_fs);
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-31 06:12:21 -06:00
|
|
|
// combo_filesystem and combo_alignment
|
2004-09-19 14:24:53 -06:00
|
|
|
if ( ! type )
|
|
|
|
{
|
2018-07-31 06:12:21 -06:00
|
|
|
fs = FILESYSTEMS[combo_filesystem.get_active_row_number()];
|
2018-01-15 14:25:55 -07:00
|
|
|
fs_limits = GParted_Core::get_filesystem_limits( fs.filesystem, *new_partition );
|
2010-05-20 10:00:14 -06:00
|
|
|
|
2018-01-15 11:07:58 -07:00
|
|
|
if ( fs_limits.min_size < MEBIBYTE )
|
|
|
|
fs_limits.min_size = MEBIBYTE;
|
2010-05-20 10:00:14 -06:00
|
|
|
|
2018-01-15 11:07:58 -07:00
|
|
|
if ( new_partition->get_byte_length() < fs_limits.min_size )
|
|
|
|
fs_limits.min_size = new_partition->get_byte_length();
|
|
|
|
|
|
|
|
if ( ! fs_limits.max_size || ( fs_limits.max_size > ((TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE) ) )
|
|
|
|
fs_limits.max_size = (TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE;
|
2010-05-20 10:00:14 -06:00
|
|
|
|
2010-05-25 16:25:21 -06:00
|
|
|
frame_resizer_base ->set_x_min_space_before( Utils::round( MIN_SPACE_BEFORE_MB / MB_PER_PIXEL ) ) ;
|
2018-01-15 11:07:58 -07:00
|
|
|
frame_resizer_base->set_size_limits( Utils::round( fs_limits.min_size / (MB_PER_PIXEL * MEBIBYTE) ),
|
|
|
|
Utils::round( fs_limits.max_size / (MB_PER_PIXEL * MEBIBYTE) ) );
|
2010-05-20 10:00:14 -06:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//set new spinbutton ranges
|
2018-01-15 11:07:58 -07:00
|
|
|
spinbutton_before.set_range( MIN_SPACE_BEFORE_MB,
|
|
|
|
TOTAL_MB - ceil( fs_limits.min_size / double(MEBIBYTE) ) );
|
|
|
|
spinbutton_size.set_range( ceil( fs_limits.min_size / double(MEBIBYTE) ),
|
|
|
|
ceil( fs_limits.max_size / double(MEBIBYTE) ) );
|
|
|
|
spinbutton_after.set_range( 0,
|
|
|
|
TOTAL_MB - MIN_SPACE_BEFORE_MB
|
|
|
|
- ceil( fs_limits.min_size / double(MEBIBYTE) ) );
|
2010-05-20 10:00:14 -06:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//set contents of label_minmax
|
2018-01-15 11:07:58 -07:00
|
|
|
Set_MinMax_Text( ceil( fs_limits.min_size / double(MEBIBYTE) ),
|
|
|
|
ceil( fs_limits.max_size / double(MEBIBYTE) ) );
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
2010-05-20 10:00:14 -06:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//set fitting resizer colors
|
2011-06-26 06:03:37 -06:00
|
|
|
{
|
2019-02-20 04:20:20 -07:00
|
|
|
Gdk::RGBA color_temp;
|
2011-07-14 10:38:59 -06:00
|
|
|
//Background color
|
2018-07-31 04:51:47 -06:00
|
|
|
color_temp.set((combo_type.get_active_row_number() == 2) ? "darkgrey" : "white");
|
2011-06-26 06:03:37 -06:00
|
|
|
frame_resizer_base->override_default_rgb_unused_color(color_temp);
|
|
|
|
|
2011-07-14 10:38:59 -06:00
|
|
|
//Partition color
|
2011-06-26 06:03:37 -06:00
|
|
|
color_temp.set(Utils::get_color(fs.filesystem));
|
|
|
|
frame_resizer_base->set_rgb_partition_color(color_temp);
|
|
|
|
}
|
|
|
|
|
2015-03-14 09:10:41 -06:00
|
|
|
// Maximum length of the file system label varies according to the selected file system type.
|
|
|
|
filesystem_label_entry.set_max_length( Utils::get_filesystem_label_maxlength( fs.filesystem ) );
|
2012-12-16 08:41:30 -07:00
|
|
|
|
2018-08-02 10:10:11 -06:00
|
|
|
frame_resizer_base->redraw();
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2018-07-31 06:12:21 -06:00
|
|
|
|
|
|
|
void Dialog_Partition_New::build_filesystems_combo(bool only_unformatted)
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2015-12-13 07:38:30 -07:00
|
|
|
g_assert( new_partition != NULL ); // Bug: Not initialised by constructor calling set_data()
|
2018-07-31 06:12:21 -06:00
|
|
|
combo_filesystem.items().clear();
|
2015-12-13 07:38:30 -07:00
|
|
|
|
2010-10-05 02:30:55 -06:00
|
|
|
bool set_first=false;
|
2008-11-18 16:58:17 -07:00
|
|
|
//fill the file system menu with the file systems (except for extended)
|
2008-12-07 11:43:35 -07:00
|
|
|
for ( unsigned int t = 0 ; t < FILESYSTEMS .size( ) ; t++ )
|
2004-10-06 09:32:40 -06:00
|
|
|
{
|
2012-12-08 12:41:00 -07:00
|
|
|
//skip extended
|
2018-10-14 06:37:34 -06:00
|
|
|
if (FILESYSTEMS[t].filesystem == FS_EXTENDED)
|
2008-12-07 11:43:35 -07:00
|
|
|
continue ;
|
2018-07-31 06:12:21 -06:00
|
|
|
combo_filesystem.items().push_back(Utils::get_filesystem_string(FILESYSTEMS[t].filesystem));
|
|
|
|
combo_filesystem.items().back().set_sensitive(
|
2006-02-25 03:09:30 -07:00
|
|
|
! only_unformatted && FILESYSTEMS[ t ] .create &&
|
2018-01-15 11:07:58 -07:00
|
|
|
new_partition->get_byte_length() >= get_filesystem_min_limit( FILESYSTEMS[t].filesystem ) );
|
2013-10-29 20:23:51 -06:00
|
|
|
//use ext4/3/2 as first/second/third choice default file system
|
|
|
|
//(Depends on ordering in FILESYSTEMS for preference)
|
|
|
|
if ( ( FILESYSTEMS[ t ] .filesystem == FS_EXT2 ||
|
|
|
|
FILESYSTEMS[ t ] .filesystem == FS_EXT3 ||
|
|
|
|
FILESYSTEMS[ t ] .filesystem == FS_EXT4 ) &&
|
2018-07-31 06:12:21 -06:00
|
|
|
combo_filesystem.items().back().sensitive() )
|
2010-10-05 02:30:55 -06:00
|
|
|
{
|
2018-07-31 06:12:21 -06:00
|
|
|
first_creatable_fs = combo_filesystem.items().size() - 1;
|
2010-10-05 02:30:55 -06:00
|
|
|
set_first=true;
|
|
|
|
}
|
2004-10-06 09:32:40 -06:00
|
|
|
}
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-11-29 06:20:05 -07:00
|
|
|
//unformatted is always available
|
2018-07-31 06:12:21 -06:00
|
|
|
combo_filesystem.items().back().set_sensitive(true);
|
|
|
|
|
2010-10-05 02:30:55 -06:00
|
|
|
if(!set_first)
|
|
|
|
{
|
2013-10-29 20:23:51 -06:00
|
|
|
//find and set first enabled file system as last choice default
|
2018-07-31 06:12:21 -06:00
|
|
|
for (unsigned int t = 0; t < combo_filesystem.items().size(); t++)
|
|
|
|
if (combo_filesystem.items()[t].sensitive())
|
2010-10-05 02:30:55 -06:00
|
|
|
{
|
|
|
|
first_creatable_fs = t ;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2018-01-02 10:44:01 -07:00
|
|
|
Byte_Value Dialog_Partition_New::get_filesystem_min_limit( FSType fstype )
|
2018-01-15 11:07:58 -07:00
|
|
|
{
|
2018-01-15 14:25:55 -07:00
|
|
|
return GParted_Core::get_filesystem_limits( fstype, *new_partition ).min_size;
|
2018-01-15 11:07:58 -07:00
|
|
|
}
|
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
} //GParted
|