[gparted] Reorder code in Win_GParted::activate_paste() (#787204)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Reorder code in Win_GParted::activate_paste() (#787204)
- Date: Sun, 28 Jan 2018 17:15:41 +0000 (UTC)
commit f8b38b7b310a78393f14f5052a4ee27063ae733a
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Tue Jan 16 21:17:35 2018 +0000
Reorder code in Win_GParted::activate_paste() (#787204)
Background information about UDF is that when creating a file system
it's block size must match the underlying device's sector size. For
optical media like CDs and DVDs that is 2K. For hard drives that is
usually 512 bytes or 4K. However if a UDF file system has been copied
from a device with a different sector size the UDF block size won't
match the sector size. Linux will happily mount such UDF file system.
Therefore the derived udf::get_filesystem_limits() will need access to
the file system block size when determining the size limits of an
existing UDF file system being resized and use the device sector size
when a new UDF file system is being created. All this can be queried
from an appropriate Partition object passed to get_filesystem_limits().
All the calls to get_filesystem_limits() have an appropriate Partition
object available already, except in Win_GParted::activate_reformat()
when composing a format operation. Or more correctly
activate_reformat() constructs temp_ptn, a suitable Partition object,
including with fs_block_size member defaulting to -1 indicating not a
resize, but not until after the file system size limits had been checked
and get_filesystem_limits() called.
Therefore reorder the code in activate_paste() so that the file system
size limits are checked after the wanted Partition object has been
created. No functional change with this commit.
Bug 787204 - Minimum and maximum size of the UDF partition/disk
src/Win_GParted.cc | 149 ++++++++++++++++++++++++++-------------------------
1 files changed, 76 insertions(+), 73 deletions(-)
---
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index 3661b2b..dc7a974 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -2265,58 +2265,6 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
return ;
}
- // Generate minimum and maximum partition size limits for the new file system.
- const FileSystem *filesystem_object = gparted_core.get_filesystem_object( new_fs );
- FS_Limits fs_limits;
- if ( filesystem_object != NULL )
- fs_limits = filesystem_object->get_filesystem_limits();
- bool encrypted = false;
- if ( selected_partition_ptr->filesystem == FS_LUKS && selected_partition_ptr->busy )
- {
- encrypted = true;
- Byte_Value encryption_overhead = selected_partition_ptr->get_byte_length() -
- filesystem_ptn.get_byte_length();
- fs_limits.min_size += encryption_overhead;
- if ( fs_limits.max_size > 0 )
- fs_limits.max_size += encryption_overhead;
- }
-
- // Confirm partition is the right size to store the file system before continuing.
- if ( ( selected_partition_ptr->get_byte_length() < fs_limits.min_size ) ||
- ( fs_limits.max_size && selected_partition_ptr->get_byte_length() > fs_limits.max_size ) )
- {
- Gtk::MessageDialog dialog( *this,
- String::ucompose( /* TO TRANSLATORS: looks like
- * Cannot format this file system to fat16.
- */
- _("Cannot format this file system to %1"),
- Utils::get_filesystem_string( encrypted, new_fs
) ),
- false,
- Gtk::MESSAGE_ERROR,
- Gtk::BUTTONS_OK,
- true );
-
- if ( selected_partition_ptr->get_byte_length() < fs_limits.min_size )
- dialog .set_secondary_text( String::ucompose(
- /* TO TRANSLATORS: looks like
- * A fat16 file system requires a partition of at least 16.00
MiB.
- */
- _( "A %1 file system requires a partition of at least %2."),
- Utils::get_filesystem_string( encrypted, new_fs ),
- Utils::format_size( fs_limits.min_size, 1 /* Byte */ ) ) );
- else
- dialog .set_secondary_text( String::ucompose(
- /* TO TRANSLATORS: looks like
- * A partition with a hfs file system has a maximum size of
2.00 GiB.
- */
- _( "A partition with a %1 file system has a maximum size of
%2."),
- Utils::get_filesystem_string( encrypted, new_fs ),
- Utils::format_size( fs_limits.max_size, 1 /* Byte */ ) ) );
-
- dialog .run() ;
- return ;
- }
-
// Compose Partition object to represent the format operation.
Partition * temp_ptn;
if ( selected_partition_ptr->filesystem == FS_LUKS && ! selected_partition_ptr->busy )
@@ -2360,34 +2308,89 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
temp_ptn->name = selected_partition_ptr->name;
temp_ptn->status = STAT_FORMATTED;
- // When formatting a partition which already exists on the disk, all possible
- // operations could be pending so only try merging with the previous operation.
- MergeType mergetype = MERGE_LAST_WITH_PREV;
+ // Generate minimum and maximum partition size limits for the new file system.
+ const FileSystem *filesystem_object = gparted_core.get_filesystem_object( new_fs );
+ FS_Limits fs_limits;
+ if ( filesystem_object != NULL )
+ fs_limits = filesystem_object->get_filesystem_limits();
+ bool encrypted = false;
+ if ( selected_partition_ptr->filesystem == FS_LUKS && selected_partition_ptr->busy )
+ {
+ encrypted = true;
+ Byte_Value encryption_overhead = selected_partition_ptr->get_byte_length() -
+ filesystem_ptn.get_byte_length();
+ fs_limits.min_size += encryption_overhead;
+ if ( fs_limits.max_size > 0 )
+ fs_limits.max_size += encryption_overhead;
+ }
- // If selected partition is NEW we simply remove the NEW operation from the list and
- // add it again with the new file system
- if ( selected_partition_ptr->status == STAT_NEW )
+ // Confirm partition is the right size to store the file system.
+ if ( ( selected_partition_ptr->get_byte_length() < fs_limits.min_size ) ||
+ ( fs_limits.max_size && selected_partition_ptr->get_byte_length() > fs_limits.max_size ) )
{
- temp_ptn->status = STAT_NEW;
- // On a partition which is pending creation only resize/move and format
- // operations are possible. These operations are always mergeable with
- // the pending operation which will create the partition. Hence merge
- // with any earlier operations to achieve this.
- mergetype = MERGE_LAST_WITH_ANY;
+ Gtk::MessageDialog dialog( *this,
+ String::ucompose( /* TO TRANSLATORS: looks like
+ * Cannot format this file system to fat16.
+ */
+ _("Cannot format this file system to %1"),
+ Utils::get_filesystem_string( encrypted, new_fs
) ),
+ false,
+ Gtk::MESSAGE_ERROR,
+ Gtk::BUTTONS_OK,
+ true );
+
+ if ( selected_partition_ptr->get_byte_length() < fs_limits.min_size )
+ dialog.set_secondary_text( String::ucompose(
+ /* TO TRANSLATORS: looks like
+ * A fat16 file system requires a partition of at least 16.00 MiB.
+ */
+ _( "A %1 file system requires a partition of at least %2."),
+ Utils::get_filesystem_string( encrypted, new_fs ),
+ Utils::format_size( fs_limits.min_size, 1 /* Byte */ ) ) );
+ else
+ dialog.set_secondary_text( String::ucompose(
+ /* TO TRANSLATORS: looks like
+ * A partition with a hfs file system has a maximum size of 2.00 GiB.
+ */
+ _( "A partition with a %1 file system has a maximum size of %2."),
+ Utils::get_filesystem_string( encrypted, new_fs ),
+ Utils::format_size( fs_limits.max_size, 1 /* Byte */ ) ) );
+
+ dialog.run();
}
+ else
+ {
+ // When formatting a partition which already exists on the disk, all
+ // possible operations could be pending so only try merging with the
+ // previous operation.
+ MergeType mergetype = MERGE_LAST_WITH_PREV;
- Operation * operation = new OperationFormat( devices[current_device],
- *selected_partition_ptr,
- *temp_ptn );
- operation->icon = render_icon( Gtk::Stock::CONVERT, Gtk::ICON_SIZE_MENU );
+ // If selected partition is NEW we simply remove the NEW operation from
+ // the list and add it again with the new file system
+ if ( selected_partition_ptr->status == STAT_NEW )
+ {
+ temp_ptn->status = STAT_NEW;
+ // On a partition which is pending creation only resize/move and
+ // format operations are possible. These operations are always
+ // mergeable with the pending operation which will create the
+ // partition. Hence merge with any earlier operations to achieve
+ // this.
+ mergetype = MERGE_LAST_WITH_ANY;
+ }
- delete temp_ptn;
- temp_ptn = NULL;
+ Operation * operation = new OperationFormat( devices[current_device],
+ *selected_partition_ptr,
+ *temp_ptn );
+ operation->icon = render_icon( Gtk::Stock::CONVERT, Gtk::ICON_SIZE_MENU );
- Add_Operation( devices[current_device], operation );
- merge_operations( mergetype );
+ Add_Operation( devices[current_device], operation );
+ merge_operations( mergetype );
- show_operationslist() ;
+ show_operationslist();
+ }
+
+ delete temp_ptn;
+ temp_ptn = NULL;
}
bool Win_GParted::unmount_partition( const Partition & partition, Glib::ustring & error )
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]