Add whole_device flag to the partition object (#743181)

Need to be able to take different actions in the GParted_Core partition
manipulation methods and in Win_GParted UI methods to deal with
libparted supported partitions or whole disk devices without a partition
table.  Add boolean whole_device to the partition object and set
appropriately to allow for this.

Bug 743181 - Add unpartitioned drive read-write support
This commit is contained in:
Mike Fleetwood 2015-01-04 11:29:01 +00:00 committed by Curtis Gedak
parent e33bb8d688
commit 5098744f9a
7 changed files with 97 additions and 82 deletions

View File

@ -60,16 +60,17 @@ public:
void Reset() ;
//simple Set-functions. only for convenience, since most members are public
void Set( const Glib::ustring & device_path,
const Glib::ustring & partition,
int partition_number,
PartitionType type,
FILESYSTEM filesystem,
Sector sector_start,
Sector sector_end,
Byte_Value sector_size,
bool inside_extended,
bool busy ) ;
void Set( const Glib::ustring & device_path,
const Glib::ustring & partition,
int partition_number,
PartitionType type,
bool whole_device,
FILESYSTEM filesystem,
Sector sector_start,
Sector sector_end,
Byte_Value sector_size,
bool inside_extended,
bool busy );
void set_sector_usage( Sector sectors_fs_size, Sector sectors_fs_unused ) ;
bool sector_usage_known() const ;
@ -79,11 +80,12 @@ public:
Sector get_sectors_unallocated() const ;
void get_usage_triple( int imax, int & i1, int & i2, int & i3 ) const ;
void Set_Unallocated( const Glib::ustring & device_path,
Sector sector_start,
Sector sector_end,
Byte_Value sector_size,
bool inside_extended );
void Set_Unallocated( const Glib::ustring & device_path,
bool whole_device,
Sector sector_start,
Sector sector_end,
Byte_Value sector_size,
bool inside_extended );
//update partition number (used when a logical partition is deleted)
void Update_Number( int new_number );
@ -112,6 +114,7 @@ public:
Glib::ustring device_path ;
int partition_number;
PartitionType type;// UNALLOCATED, PRIMARY, LOGICAL, etc...
bool whole_device; // Is this a virtual partition spanning a whole unpartitioned disk device?
PartitionStatus status; //STAT_REAL, STAT_NEW, etc..
PartitionAlignment alignment; //ALIGN_CYLINDER, ALIGN_STRICT, etc
FILESYSTEM filesystem ;

View File

@ -193,13 +193,13 @@ Partition Dialog_Partition_New::Get_New_Partition( Byte_Value sector_size )
new_end = selected_partition.sector_end ;
part_temp .status = GParted::STAT_NEW ;
part_temp .Set( selected_partition .device_path,
String::ucompose( _("New Partition #%1"), new_count ),
new_count, part_type,
FILESYSTEMS[ optionmenu_filesystem .get_history() ] .filesystem,
new_start, new_end,
sector_size,
selected_partition .inside_extended, false ) ;
part_temp.Set( selected_partition.device_path,
String::ucompose( _("New Partition #%1"), new_count ),
new_count, part_type, selected_partition.whole_device,
FILESYSTEMS[optionmenu_filesystem.get_history()].filesystem,
new_start, new_end,
sector_size,
selected_partition.inside_extended, false );
//Retrieve Label info
part_temp.set_filesystem_label( Utils::trim( entry.get_text() ) );
@ -214,11 +214,12 @@ Partition Dialog_Partition_New::Get_New_Partition( Byte_Value sector_size )
if ( part_temp .type == GParted::TYPE_EXTENDED )
{
Partition UNALLOCATED ;
UNALLOCATED .Set_Unallocated( part_temp .device_path,
part_temp .sector_start,
part_temp .sector_end,
sector_size,
true ) ;
UNALLOCATED.Set_Unallocated( part_temp.device_path,
part_temp.whole_device,
part_temp.sector_start,
part_temp.sector_end,
sector_size,
true );
part_temp .logicals .push_back( UNALLOCATED ) ;
}

View File

@ -429,7 +429,7 @@ void Dialog_Rescue_Data::read_partitions_from_buffer()
}
part.Set(dev_path, part_path, part_num,
type, fs, sec_start, sec_end, sec_size, false, false);
type, false, fs, sec_start, sec_end, sec_size, false, false);
this->partitions.push_back(part);
}

View File

@ -363,6 +363,7 @@ void GParted_Core::set_devices_thread( std::vector<Device> * pdevices )
Partition partition_temp;
partition_temp.Set_Unallocated( temp_device .get_path(),
true,
0LL,
temp_device .length - 1LL,
temp_device .sector_size,
@ -1152,16 +1153,17 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
partition_is_busy = is_busy( filesystem, partition_path ) ;
}
partition_temp .Set( device .get_path(),
partition_path,
lp_partition ->num,
lp_partition ->type == 0 ? GParted::TYPE_PRIMARY : GParted::TYPE_LOGICAL,
filesystem,
lp_partition ->geom .start,
lp_partition ->geom .end,
device .sector_size,
lp_partition ->type,
partition_is_busy ) ;
partition_temp.Set( device .get_path(),
partition_path,
lp_partition->num,
( lp_partition->type == 0 ) ? TYPE_PRIMARY : TYPE_LOGICAL,
false,
filesystem,
lp_partition->geom.start,
lp_partition->geom.end,
device.sector_size,
lp_partition->type,
partition_is_busy );
partition_temp .add_paths( pp_info .get_alternate_paths( partition_temp .get_path() ) ) ;
set_flags( partition_temp, lp_partition ) ;
@ -1172,16 +1174,17 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
break ;
case PED_PARTITION_EXTENDED:
partition_temp .Set( device .get_path(),
partition_path,
lp_partition ->num,
GParted::TYPE_EXTENDED,
GParted::FS_EXTENDED,
lp_partition ->geom .start,
lp_partition ->geom .end,
device .sector_size,
false,
false ) ;
partition_temp.Set( device.get_path(),
partition_path,
lp_partition->num,
TYPE_EXTENDED,
false,
FS_EXTENDED,
lp_partition->geom.start,
lp_partition->geom.end,
device.sector_size,
false,
false );
partition_temp .add_paths( pp_info .get_alternate_paths( partition_temp .get_path() ) ) ;
set_flags( partition_temp, lp_partition ) ;
@ -1261,6 +1264,7 @@ void GParted_Core::set_device_one_partition( Device & device, PedDevice * lp_dev
path,
1,
TYPE_PRIMARY,
true,
fstype,
0LL,
device.length - 1LL,
@ -1556,7 +1560,7 @@ void GParted_Core::insert_unallocated( const Glib::ustring & device_path,
bool inside_extended )
{
Partition partition_temp ;
partition_temp .Set_Unallocated( device_path, 0, 0, sector_size, inside_extended ) ;
partition_temp.Set_Unallocated( device_path, false, 0LL, 0LL, sector_size, inside_extended );
//if there are no partitions at all..
if ( partitions .empty() )

View File

@ -45,7 +45,7 @@ int Operation::find_index_extended( const std::vector<Partition> & partitions )
void Operation::insert_unallocated( std::vector<Partition> & partitions, Sector start, Sector end, Byte_Value sector_size, bool inside_extended )
{
Partition UNALLOCATED ;
UNALLOCATED .Set_Unallocated( device .get_path(), 0, 0, sector_size, inside_extended ) ;
UNALLOCATED.Set_Unallocated( device.get_path(), false, 0LL, 0LL, sector_size, inside_extended );
//if there are no partitions at all..
if ( partitions .empty() )

View File

@ -38,6 +38,7 @@ void Partition::Reset()
messages .clear() ;
status = GParted::STAT_REAL ;
type = GParted::TYPE_UNALLOCATED ;
whole_device = false;
alignment = ALIGN_STRICT ;
filesystem = GParted::FS_UNALLOCATED ;
have_filesystem_label = false;
@ -55,16 +56,17 @@ void Partition::Reset()
mountpoints .clear() ;
}
void Partition::Set( const Glib::ustring & device_path,
const Glib::ustring & partition,
int partition_number,
PartitionType type,
FILESYSTEM filesystem,
Sector sector_start,
Sector sector_end,
Byte_Value sector_size,
bool inside_extended,
bool busy )
void Partition::Set( const Glib::ustring & device_path,
const Glib::ustring & partition,
int partition_number,
PartitionType type,
bool whole_device,
FILESYSTEM filesystem,
Sector sector_start,
Sector sector_end,
Byte_Value sector_size,
bool inside_extended,
bool busy )
{
this ->device_path = device_path ;
@ -72,6 +74,7 @@ void Partition::Set( const Glib::ustring & device_path,
this ->partition_number = partition_number;
this ->type = type;
this->whole_device = whole_device;
this ->filesystem = filesystem;
this ->sector_start = sector_start;
this ->sector_end = sector_end;
@ -163,18 +166,20 @@ Sector Partition::get_sectors_unallocated() const
}
void Partition::Set_Unallocated( const Glib::ustring & device_path,
Sector sector_start,
Sector sector_end,
Byte_Value sector_size,
bool inside_extended )
bool whole_device,
Sector sector_start,
Sector sector_end,
Byte_Value sector_size,
bool inside_extended )
{
Reset() ;
Set( device_path,
Utils::get_filesystem_string( GParted::FS_UNALLOCATED ),
Utils::get_filesystem_string( FS_UNALLOCATED ),
-1,
GParted::TYPE_UNALLOCATED,
GParted::FS_UNALLOCATED,
TYPE_UNALLOCATED,
whole_device,
FS_UNALLOCATED,
sector_start,
sector_end,
sector_size,

View File

@ -1644,11 +1644,12 @@ void Win_GParted::activate_resize()
//And add the new partition to the end of the operations list
//change 'selected_partition' into a suitable 'partition_original')
selected_partition .Set_Unallocated( devices[ current_device ] .get_path(),
selected_partition .sector_start,
selected_partition .sector_end,
devices[current_device] .sector_size,
selected_partition .inside_extended ) ;
selected_partition.Set_Unallocated( devices[current_device].get_path(),
selected_partition.whole_device,
selected_partition.sector_start,
selected_partition.sector_end,
devices[current_device].sector_size,
selected_partition.inside_extended );
Operation * operation = new OperationCreate( devices[ current_device ],
selected_partition,
@ -2020,16 +2021,17 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
//ok we made it. lets create an fitting partition object
Partition part_temp ;
part_temp .Set( devices[ current_device ] .get_path(),
selected_partition .get_path(),
selected_partition .partition_number,
selected_partition .type,
new_fs,
selected_partition .sector_start,
selected_partition .sector_end,
devices[ current_device ] .sector_size,
selected_partition .inside_extended,
false ) ;
part_temp.Set( devices[current_device].get_path(),
selected_partition.get_path(),
selected_partition.partition_number,
selected_partition.type,
selected_partition.whole_device,
new_fs,
selected_partition.sector_start,
selected_partition.sector_end,
devices[current_device].sector_size,
selected_partition.inside_extended,
false );
//Leave sector usage figures to new Partition object defaults of
// -1, -1, 0 (_used, _unused, _unallocated) representing unknown.