diff --git a/ChangeLog b/ChangeLog index c810157f..c33e29e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-05-27 Bart Hakvoort + + * include/Dialog_Partition_Copy.h, + include/GParted_Core.h, + include/OperationCopy.h, + include/Win_GParted.h, + src/Dialog_Partition_Copy.cc, + src/GParted_Core.cc, + src/OperationCopy.cc, + src/Win_GParted.cc: made blocksize settable by the user. + 2006-05-26 Bart Hakvoort * src/GParted_Core.cc: fixed typo (#343015) diff --git a/include/Dialog_Partition_Copy.h b/include/Dialog_Partition_Copy.h index dd06e033..f0a08e0a 100644 --- a/include/Dialog_Partition_Copy.h +++ b/include/Dialog_Partition_Copy.h @@ -28,10 +28,13 @@ class Dialog_Partition_Copy : public Dialog_Base_Partition public: Dialog_Partition_Copy( const FS & fs, Sector cylinder_size ) ; void Set_Data( const Partition & selected_partition, const Partition & copied_partition ); - Partition Get_New_Partition( ) ; + + Partition Get_New_Partition() ; + Sector get_block_size() ; private: - + Gtk::HBox hbox_block_size ; + Gtk::SpinButton spinbutton_block_size ; }; }//GParted diff --git a/include/GParted_Core.h b/include/GParted_Core.h index cdc9481c..e07b6d20 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -51,6 +51,7 @@ public: bool copy( const Partition & partition_src, Partition & partition_dest, Sector min_size, + Sector block_size, std::vector & operation_details ) ; bool Set_Disklabel( const Glib::ustring & device_path, const Glib::ustring & disklabel ) ; @@ -93,7 +94,8 @@ private: bool copy_filesystem( const Partition & partition_src, const Partition & partition_dest, - std::vector & operation_details ) ; + std::vector & operation_details, + Sector block_size ) ; void set_proper_filesystem( const FILESYSTEM & filesystem ) ; bool set_partition_type( const Partition & partition, diff --git a/include/OperationCopy.h b/include/OperationCopy.h index 07e5a4a8..ab5b5b5e 100644 --- a/include/OperationCopy.h +++ b/include/OperationCopy.h @@ -29,11 +29,13 @@ public: OperationCopy( const Device & device, const Partition & partition_orig, const Partition & partition_new, - const Partition & partition_copied) ; + const Partition & partition_copied, + Sector block_size ) ; void apply_to_visual( std::vector & partitions ) ; Partition partition_copied ; + Sector block_size ; private: void create_description() ; diff --git a/include/Win_GParted.h b/include/Win_GParted.h index 782605e2..760954db 100644 --- a/include/Win_GParted.h +++ b/include/Win_GParted.h @@ -63,7 +63,10 @@ private: //Fill txtview_device_info_buffer with some information about the selected device void Fill_Label_Device_Info( bool clear = false ); - void Add_Operation( OperationType operationtype, const Partition & new_partition, int index = -1 ) ; + void Add_Operation( OperationType operationtype, + const Partition & new_partition, + Sector block_size = -1, + int index = -1 ) ; void Refresh_Visual(); bool Quit_Check_Operations(); void set_valid_operations() ; diff --git a/src/Dialog_Partition_Copy.cc b/src/Dialog_Partition_Copy.cc index bd3af19b..9f7ffc6f 100644 --- a/src/Dialog_Partition_Copy.cc +++ b/src/Dialog_Partition_Copy.cc @@ -87,13 +87,27 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons Set_MinMax_Text( Utils::round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ), Utils::round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ; - + + + //allow the user to set the size of the blocks which will be copied at once + hbox_block_size .set_spacing( 10 ) ; + this ->get_vbox() ->pack_start( hbox_block_size ) ; + hbox_block_size .pack_start( * Utils::mk_label( _("Blocksize (sectors):") ), Gtk::PACK_SHRINK ) ; + + spinbutton_block_size .set_numeric( true ) ; + spinbutton_block_size .set_increments( 1, 10 ) ; + spinbutton_block_size .set_range( 1, MEBIBYTE ) ; + spinbutton_block_size .set_value( 32 ) ; + hbox_block_size .pack_start( spinbutton_block_size, Gtk::PACK_SHRINK ) ; + //set global selected_partition (see Dialog_Base_Partition::Get_New_Partition ) this ->selected_partition = copied_partition ; this ->selected_partition .device_path = selected_partition .device_path ; this ->selected_partition .inside_extended = selected_partition .inside_extended ; this ->selected_partition .type = selected_partition .inside_extended ? GParted::TYPE_LOGICAL : GParted::TYPE_PRIMARY ; + + this ->show_all_children() ; } Partition Dialog_Partition_Copy::Get_New_Partition() @@ -106,5 +120,9 @@ Partition Dialog_Partition_Copy::Get_New_Partition() return selected_partition ; } +Sector Dialog_Partition_Copy::get_block_size() +{ + return spinbutton_block_size .get_value_as_int() ; +} } //GParted diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 8a6300b5..1b58459c 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -654,6 +654,7 @@ bool GParted_Core::apply_operation_to_disk( Operation * operation ) return copy( static_cast( operation ) ->partition_copied, operation ->partition_new, static_cast( operation ) ->partition_copied .get_length(), + static_cast( operation ) ->block_size, operation ->operation_details .sub_details ) ; } @@ -785,6 +786,7 @@ bool GParted_Core::resize( const Device & device, bool GParted_Core::copy( const Partition & partition_src, Partition & partition_dest, Sector min_size, + Sector block_size, std::vector & operation_details ) { set_proper_filesystem( partition_dest .filesystem ) ; @@ -806,7 +808,8 @@ bool GParted_Core::copy( const Partition & partition_src, case GParted::FS::GPARTED : succes = copy_filesystem( partition_src, partition_dest, - operation_details ) ; + operation_details, + block_size ) ; break ; case GParted::FS::LIBPARTED : @@ -1258,11 +1261,17 @@ bool GParted_Core::resize_normal_using_libparted( const Partition & partition_ol bool GParted_Core::copy_filesystem( const Partition & partition_src, const Partition & partition_dest, - std::vector & operation_details ) -{//FIXME: try to increase speed by copying more sectors at once, this should probably become a userspace setting + std::vector & operation_details, + Sector block_size ) +{ + operation_details .back() .sub_details .push_back( OperationDetails( + "" + String::ucompose( _("Use a blocksize of %1 (%2 sectors)"), + Utils::format_size( block_size ), + block_size ) + "", + OperationDetails::NONE ) ) ; + bool succes = false ; - - char buf[1024] ; + char buf[block_size * 512] ; PedDevice *lp_device_src, *lp_device_dest ; //FIXME: adapt open_device() so we don't have to call ped_device_get() here //(same goes for close_device() and ped_device_destroy() @@ -1283,25 +1292,25 @@ bool GParted_Core::copy_filesystem( const Partition & partition_src, Glib::ustring error_message ; Sector t = 0 ; - for ( ; t < partition_src .get_length() ; t++ ) + for ( ; t < partition_src .get_length() - block_size ; t+=block_size ) { - if ( ! ped_device_read( lp_device_src, buf, partition_src .sector_start + t, 1 ) ) + if ( ! ped_device_read( lp_device_src, buf, partition_src .sector_start + t, block_size ) ) { - error_message = "" + String::ucompose( _("Error while reading sector %1"), + error_message = "" + String::ucompose( _("Error while reading block at sector %1"), partition_src .sector_start + t ) + "" ; break ; } - if ( ! ped_device_write( lp_device_dest, buf, partition_dest .sector_start + t, 1 ) ) + if ( ! ped_device_write( lp_device_dest, buf, partition_dest .sector_start + t, block_size ) ) { - error_message = "" + String::ucompose( _("Error while writing sector %1"), + error_message = "" + String::ucompose( _("Error while writing block at sector %1"), partition_src .sector_start + t ) + "" ; break ; } - if ( t % MEBIBYTE == 0 ) + if ( t % ( block_size * 100 ) == 0 ) { operation_details .back() .sub_details .back() .progress_text = String::ucompose( _("%1 of %2 copied"), @@ -1316,13 +1325,27 @@ bool GParted_Core::copy_filesystem( const Partition & partition_src, } } + //copy the last couple of sectors.. + Sector last_sectors = partition_src .get_length() - t ; + if ( ped_device_read( lp_device_src, buf, partition_src .sector_start + t, last_sectors ) ) + { + if ( ped_device_write( lp_device_dest, buf, partition_dest .sector_start + t , last_sectors ) ) + t += last_sectors ; + else + error_message = "" + String::ucompose( _("Error while writing block at sector %1"), + partition_src .sector_start + t ) + "" ; + } + else + error_message = "" + String::ucompose( _("Error while reading block at sector %1"), + partition_src .sector_start + t ) + "" ; + //final description operation_details .back() .sub_details .back() .description = "" + String::ucompose( _("%1 of %2 copied"), Utils::format_size( t +1 ), Utils::format_size( partition_src .get_length() ) ) + - "" ; + "" ; //reset fraction to -1 to make room for a new one (or a pulsebar) operation_details .back() .sub_details .back() .fraction = -1 ; diff --git a/src/OperationCopy.cc b/src/OperationCopy.cc index c97d9c2a..2be7b7aa 100644 --- a/src/OperationCopy.cc +++ b/src/OperationCopy.cc @@ -23,7 +23,8 @@ namespace GParted OperationCopy::OperationCopy( const Device & device, const Partition & partition_orig, const Partition & partition_new, - const Partition & partition_copied ) + const Partition & partition_copied, + Sector block_size ) { type = GParted::COPY ; @@ -31,6 +32,7 @@ OperationCopy::OperationCopy( const Device & device, this ->partition_original = partition_orig ; this ->partition_new = partition_new ; this ->partition_copied = partition_copied ; + this ->block_size = block_size ; create_description() ; @@ -89,7 +91,6 @@ void OperationCopy::create_description() partition_copied .get_path(), partition_original .get_path() ) ; } - } } //GParted diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index f7c87638..4474d18b 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -573,7 +573,13 @@ bool Win_GParted::on_delete_event( GdkEventAny *event ) return ! Quit_Check_Operations(); } -void Win_GParted::Add_Operation( OperationType operationtype, const Partition & new_partition, int index ) +//FIXME: i guess it's better if we just create the operations in the activate_* functions instead +//of doing it here. now we're adding more and more functionality (e.g. blocksize) to the operations +//the current approach doesn't suffice anymore. +void Win_GParted::Add_Operation( OperationType operationtype, + const Partition & new_partition, + Sector block_size, + int index ) { Operation * operation ; switch ( operationtype ) @@ -604,7 +610,8 @@ void Win_GParted::Add_Operation( OperationType operationtype, const Partition & operation = new OperationCopy( devices[ current_device ], selected_partition, new_partition, - copied_partition ) ; + copied_partition, + block_size ) ; operation ->icon = render_icon( Gtk::Stock::COPY, Gtk::ICON_SIZE_MENU ); break; } @@ -1269,7 +1276,7 @@ void Win_GParted::activate_paste() if ( dialog .run() == Gtk::RESPONSE_OK ) { dialog .hide() ; - Add_Operation( GParted::COPY, dialog .Get_New_Partition() ); + Add_Operation( GParted::COPY, dialog .Get_New_Partition(), dialog .get_block_size() ); } } } @@ -1281,8 +1288,11 @@ void Win_GParted::activate_paste() partition_new .set_used( copied_partition .sectors_used ) ; partition_new .error .clear() ; partition_new .status = GParted::STAT_COPY ; - - Add_Operation( GParted::COPY, partition_new ) ; + + //FIXME: in this case there's no window presented to the user, so he cannot choose the blocksize + //i guess this means we have to present a window with the choice (maybe the copydialog, with everything + //except the blocksize disabled? + Add_Operation( GParted::COPY, partition_new, 32 ) ; } } @@ -1469,7 +1479,7 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs ) //(NOTE: in this case we set status to STAT_NEW) part_temp .status = STAT_NEW ; - Add_Operation( GParted::CREATE, part_temp, t ); + Add_Operation( GParted::CREATE, part_temp, -1, t ); break; }