Make calibrate work with whole disk devices (#743181)

This enables the Check, Label and New UUID operations to succeed on
whole disk device file systems even when libparted doesn't recognise the
file system.

This benefits reiser4 and lvm2 pv file systems with all versions of
libparted, current version is 3.2, and for nilfs2 with libparted < 2.4.

Bug 743181 - Add unpartitioned drive read-write support
This commit is contained in:
Mike Fleetwood 2015-01-20 17:33:51 +00:00 committed by Curtis Gedak
parent 51ac4d5648
commit c4229c99f8
1 changed files with 58 additions and 41 deletions

View File

@ -3154,13 +3154,21 @@ bool GParted_Core::calibrate_partition( Partition & partition, OperationDetail &
{
operationdetail .add_child( OperationDetail( String::ucompose( _("calibrate %1"), partition .get_path() ) ) ) ;
bool succes = false ;
bool success = false;
PedDevice* lp_device = NULL ;
PedDisk* lp_disk = NULL ;
if ( get_device_and_disk( partition .device_path, lp_device, lp_disk ) )
if ( get_device( partition.device_path, lp_device ) )
{
if ( partition.whole_device )
{
// Virtual partition spanning whole disk device
success = true;
}
else if ( get_disk( lp_device, lp_disk ) )
{
// Partitioned device
PedPartition *lp_partition = NULL;
if ( partition .type == GParted::TYPE_EXTENDED )
if ( partition.type == TYPE_EXTENDED )
lp_partition = ped_disk_extended_partition( lp_disk );
else
lp_partition = ped_disk_get_partition_by_sector( lp_disk, partition.get_sector() );
@ -3169,35 +3177,45 @@ bool GParted_Core::calibrate_partition( Partition & partition, OperationDetail &
{
// Re-add the real partition path from libparted.
//
// When creating a copy operation the list of paths for
// the partition object was set to ["copy of /dev/SRC"] to
// display in the UI before the operations are applied.
// When pasting into an existing partition, this re-adds
// the real path to the start of the list making it
// ["/dev/DST", "copy of /dev/SRC"]. This provides the
// real path for any file system specific tools needed
// during the copy operation. Such as file system check
// and grow steps added when the source and destination
// aren't identical sizes or when file system specific
// tools are used to perform the copy as for XFS or recent
// EXT2/3/4 tools.
// When creating a copy operation the list of
// paths for the partition object was set to
// ["copy of /dev/SRC"] to display in the UI
// before the operations are applied. When
// pasting into an existing partition, this
// re-adds the real path to the start of the list
// making it ["/dev/DST", "copy of /dev/SRC"].
// This provides the real path for any file system
// specific tools needed during the copy
// operation. Such as file system check and grow
// steps added when the source and destination
// aren't identical sizes or when file system
// specific tools are used to perform the copy as
// for XFS or recent EXT2/3/4 tools.
//
// FIXME: Having this work just because "/dev/DST" happens
// to sort before "copy of /dev/SRC" is ugly! Probably
// have a separate display path which can be changed at
// will without affecting the list of real paths for the
// partition.
// FIXME: Having this work just because "/dev/DST"
// happens to sort before "copy of /dev/SRC" is
// ugly! Probably have a separate display path
// which can be changed at will without affecting
// the list of real paths for the partition.
partition.add_path( get_partition_path( lp_partition ) );
// Reload the partition boundaries from libparted to
// ensure that GParted knows what the actual partition
// boundaries are before applying the next operation.
// Necessary when the previous operation in the sequence
// was a resize/move operation where GParted may have only
// estimated where libparted would move the boundaries to.
// Reload the partition boundaries from libparted
// to ensure that GParted knows what the actual
// partition boundaries are before applying the
// next operation. Necessary when the previous
// operation in the sequence was a resize/move
// operation where GParted may have only estimated
// where libparted would move the boundaries to.
partition.sector_start = lp_partition->geom.start;
partition.sector_end = lp_partition->geom.end;
success = true;
}
}
// else error from get_disk() reading partition table
if ( success )
{
operationdetail .get_last_child() .add_child(
OperationDetail(
String::ucompose( _("path: %1"), partition .get_path() ) + "\n" +
@ -3208,14 +3226,13 @@ bool GParted_Core::calibrate_partition( Partition & partition, OperationDetail &
Utils::format_size( partition .get_sector_length(), partition .sector_size ) ),
STATUS_NONE,
FONT_ITALIC ) ) ;
succes = true ;
}
destroy_device_and_disk( lp_device, lp_disk ) ;
}
operationdetail .get_last_child() .set_status( succes ? STATUS_SUCCES : STATUS_ERROR ) ;
return succes ;
operationdetail.get_last_child().set_status( success ? STATUS_SUCCES : STATUS_ERROR );
return success;
}
else //nothing to calibrate...
return true ;