diff --git a/ChangeLog b/ChangeLog index f348a515..0b7c9859 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2006-03-19 Bart Hakvoort + + * include/GParted_Core.h, + src/GParted_Core.cc, + src/Win_GParted.cc, + src/ext2.cc, + src/ext3.cc, + src/fat16.cc, + src/fat32.cc, + src/jfs.cc, + src/ntfs.cc, + src/reiserfs.cc: fixed issues with copying (see also #335004) + * include/Operation.h, + src/Operation.cc: cleanups + added FIXME + * include/Partition.h, + src/Partition.cc: added clear_mountpoints() + * src/DrawingAreaVisualDisk.cc: added FIXME + 2006-03-18 Bart Hakvoort * include/DrawingAreaVisualDisk.h, diff --git a/include/GParted_Core.h b/include/GParted_Core.h index 39adc22b..ecbcbc66 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -60,6 +60,7 @@ public: std::vector & operation_detail ) ; bool copy( const Glib::ustring & src_part_path, Partition & partition_dest, + Sector min_size, std::vector & operation_details ) ; bool Set_Disklabel( const Glib::ustring & device_path, const Glib::ustring & disklabel ) ; @@ -88,14 +89,14 @@ private: void set_flags( Partition & partition ) ; int create_empty_partition( Partition & new_partition, std::vector & operation_details, - bool copy = false ) ; + Sector min_size = 0 ) ; bool resize_container_partition( const Partition & partition_old, const Partition & partition_new, bool fixed_start, std::vector & operation_details ) ; bool resize_normal_using_libparted( const Partition & partition_old, const Partition & partition_new, - std::vector & operation_detail ) ; + std::vector & operation_details ) ; void set_proper_filesystem( const FILESYSTEM & filesystem ) ; bool set_partition_type( const Partition & partition, diff --git a/include/Operation.h b/include/Operation.h index a473b488..60981abb 100644 --- a/include/Operation.h +++ b/include/Operation.h @@ -19,7 +19,7 @@ #define OPERATION #include "../include/Device.h" - +//FIXME: i guess it's better to split Operation in several (sub)classes for increased efficiency/clearity namespace GParted { @@ -64,7 +64,8 @@ public: Operation() ; Operation( const Device & device, const Partition &, const Partition &, OperationType ); - //this one can be a little confusing, it *DOES NOT* change any visual representation. It only applies the operation to the list with partitions. + //this one can be a little confusing, it *DOES NOT* change any visual representation. + //It only applies the operation to the list with partitions. //this new list can be used to change the visual representation. For real writing to disk, see Apply_To_Disk() void Apply_Operation_To_Visual( std::vector & partitions ); @@ -75,7 +76,9 @@ public: Partition partition_original; //the original situation Partition partition_new; //the new situation ( can be an whole new partition or simply the old one with a new size or.... ) Glib::ustring str_operation ; - Glib::ustring copied_partition_path ; //for copy operation.. + + //for copy operation.. + Glib::ustring copied_partition_path ; OperationDetails operation_details ; @@ -89,7 +92,7 @@ private: void Apply_Resize_Move_To_Visual( std::vector & partitions ); void Apply_Resize_Move_Extended_To_Visual( std::vector & partitions ); - Glib::ustring Get_String( ); //only used in c'tor + Glib::ustring Get_String(); //only used in c'tor }; } //GParted diff --git a/include/Partition.h b/include/Partition.h index 0d2d9487..5ed72750 100644 --- a/include/Partition.h +++ b/include/Partition.h @@ -81,6 +81,7 @@ public: std::vector get_paths() const ; void add_mountpoints( const std::vector & mountpoints, bool clear_mountpoints = false ) ; Glib::ustring get_mountpoint() const ; + void clear_mountpoints() ; std::vector get_mountpoints() const ; bool operator==( const Partition & partition ) const ; diff --git a/src/DrawingAreaVisualDisk.cc b/src/DrawingAreaVisualDisk.cc index 7472bda8..82b69fc9 100644 --- a/src/DrawingAreaVisualDisk.cc +++ b/src/DrawingAreaVisualDisk.cc @@ -343,7 +343,8 @@ bool DrawingAreaVisualDisk::on_button_press_event( GdkEventButton * event ) signal_partition_selected .emit( selected_vp .partition, false ) ; - if ( event ->type == GDK_2BUTTON_PRESS ) + if ( event ->type == GDK_2BUTTON_PRESS ) //FIXME: only emit the signal if a partition was selected + //right now it's possible to 'activate' a seperator. signal_partition_activated .emit() ; else if ( event ->button == 3 ) signal_popup_menu .emit( event ->button, event ->time ) ; diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index ae4fe8d2..0277fb7e 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -562,7 +562,8 @@ bool GParted_Core::apply_operation_to_disk( Operation & operation ) case COPY: return copy( operation .copied_partition_path, operation .partition_new, - operation .operation_details .sub_details ) ; + operation .partition_new .get_length() - operation .device .cylsize, + operation .operation_details .sub_details ) ; } return false ; @@ -577,10 +578,7 @@ bool GParted_Core::create( const Device & device, { return create_empty_partition( new_partition, operation_details ) ; } - else if ( create_empty_partition( - new_partition, - operation_details, - ( new_partition .get_length() - device .cylsize ) < get_fs( new_partition .filesystem ) .MIN * MEBIBYTE ) > 0 ) + else if ( create_empty_partition( new_partition, operation_details, get_fs( new_partition .filesystem ) .MIN ) ) { set_proper_filesystem( new_partition .filesystem ) ; @@ -693,16 +691,19 @@ bool GParted_Core::resize( const Device & device, bool GParted_Core::copy( const Glib::ustring & src_part_path, Partition & partition_dest, + Sector min_size, std::vector & operation_details ) { set_proper_filesystem( partition_dest .filesystem ) ; Partition src_partition( src_part_path ) ; - +//FIXME: some filesystems (e.g. fat*) can be copied using libparted.. return ( p_filesystem && p_filesystem ->Check_Repair( src_partition, operation_details ) && - create_empty_partition( partition_dest, operation_details, true ) > 0 && + create_empty_partition( partition_dest, operation_details, min_size ) > 0 && set_partition_type( partition_dest, operation_details ) && p_filesystem ->Copy( src_part_path, partition_dest .get_path(), operation_details ) && + p_filesystem ->Check_Repair( partition_dest, operation_details ) && + p_filesystem ->Resize( partition_dest, operation_details, true ) && p_filesystem ->Check_Repair( partition_dest, operation_details ) ) ; } @@ -800,7 +801,7 @@ void GParted_Core::LP_Set_Used_Sectors( Partition & partition ) int GParted_Core::create_empty_partition( Partition & new_partition, std::vector & operation_details, - bool copy ) + Sector min_size ) { operation_details .push_back( OperationDetails( _("create empty partition") ) ) ; @@ -852,10 +853,8 @@ int GParted_Core::create_empty_partition( Partition & new_partition, if ( constraint ) { - //FIXME: i should use the length of the copied partition as min_size - //maybe we can set the used from new_partition to this size? - if ( copy ) - constraint ->min_size = new_partition .get_length() ; + if ( min_size > 0 ) + constraint ->min_size = min_size ; if ( ped_disk_add_partition( lp_disk, lp_partition, constraint ) && commit() ) { diff --git a/src/Operation.cc b/src/Operation.cc index b8c3be17..6cfacf2a 100644 --- a/src/Operation.cc +++ b/src/Operation.cc @@ -44,7 +44,7 @@ Operation::Operation( const Device & device, } } -Glib::ustring Operation::Get_String( ) +Glib::ustring Operation::Get_String() { Glib::ustring temp ; Sector diff ; @@ -161,7 +161,7 @@ void Operation::Insert_Unallocated( std::vector & partitions, Sector UNALLOCATED .Set_Unallocated( device .get_path(), 0, 0, inside_extended ) ; //if there are no partitions at all.. - if ( partitions .empty( ) ) + if ( partitions .empty() ) { UNALLOCATED .sector_start = start ; UNALLOCATED .sector_end = end ; @@ -172,28 +172,28 @@ void Operation::Insert_Unallocated( std::vector & partitions, Sector } //start <---> first partition start - if ( (partitions .front( ) .sector_start - start) >= MEBIBYTE ) + if ( (partitions .front() .sector_start - start) >= MEBIBYTE ) { UNALLOCATED .sector_start = start ; - UNALLOCATED .sector_end = partitions .front( ) .sector_start -1 ; + UNALLOCATED .sector_end = partitions .front() .sector_start -1 ; - partitions .insert( partitions .begin( ), UNALLOCATED ); + partitions .insert( partitions .begin(), UNALLOCATED ); } //look for gaps in between - for ( unsigned int t =0 ; t < partitions .size( ) -1 ; t++ ) + for ( unsigned int t =0 ; t < partitions .size() -1 ; t++ ) if ( ( partitions[ t +1 ] .sector_start - partitions[ t ] .sector_end ) >= MEBIBYTE ) { UNALLOCATED .sector_start = partitions[ t ] .sector_end +1 ; UNALLOCATED .sector_end = partitions[ t +1 ] .sector_start -1 ; - partitions .insert( partitions .begin( ) + ++t, UNALLOCATED ); + partitions .insert( partitions .begin() + ++t, UNALLOCATED ); } //last partition end <---> end - if ( (end - partitions .back( ) .sector_end ) >= MEBIBYTE ) + if ( (end - partitions .back() .sector_end ) >= MEBIBYTE ) { - UNALLOCATED .sector_start = partitions .back( ) .sector_end +1 ; + UNALLOCATED .sector_start = partitions .back() .sector_end +1 ; UNALLOCATED .sector_end = end ; partitions .push_back( UNALLOCATED ); @@ -202,16 +202,18 @@ void Operation::Insert_Unallocated( std::vector & partitions, Sector int Operation::Get_Index_Original( std::vector & partitions ) { - for ( int t = 0 ; t < static_cast( partitions .size( ) ) ; t++ ) - if ( partition_original .sector_start >= partitions[ t ] .sector_start && partition_original .sector_end <= partitions[ t ] .sector_end ) + for ( int t = 0 ; t < static_cast( partitions .size() ) ; t++ ) + if ( partition_original .sector_start >= partitions[ t ] .sector_start && + partition_original .sector_end <= partitions[ t ] .sector_end ) { //remove unallocated space preceding the original partition if ( t -1 >= 0 && partitions[ t -1 ] .type == GParted::TYPE_UNALLOCATED ) - partitions .erase( partitions .begin( ) + --t ); + partitions .erase( partitions .begin() + --t ); //remove unallocated space following the original partition - if ( t +1 < static_cast( partitions .size( ) ) && partitions[ t +1 ] .type == GParted::TYPE_UNALLOCATED ) - partitions .erase( partitions .begin( ) + t +1 ); + if ( t +1 < static_cast( partitions .size() ) && + partitions[ t +1 ] .type == GParted::TYPE_UNALLOCATED ) + partitions .erase( partitions .begin() + t +1 ); return t ; } @@ -232,14 +234,14 @@ void Operation::Apply_Delete_To_Visual( std::vector & partitions ) { if ( ! partition_original .inside_extended ) { - partitions .erase( partitions .begin( ) + Get_Index_Original( partitions ) ); + partitions .erase( partitions .begin() + Get_Index_Original( partitions ) ); Insert_Unallocated( partitions, 0, device .length -1, false ) ; } else { unsigned int ext = get_index_extended( partitions ) ; - partitions[ ext ] .logicals .erase( partitions[ ext ] .logicals .begin( ) + Get_Index_Original( partitions[ ext ] .logicals ) ); + partitions[ ext ] .logicals .erase( partitions[ ext ] .logicals .begin() + Get_Index_Original( partitions[ ext ] .logicals ) ); //if deleted partition was logical we have to decrease the partitionnumbers of the logicals //with higher numbers by one (only if its a real partition) diff --git a/src/Partition.cc b/src/Partition.cc index a1567031..b0dbbde8 100644 --- a/src/Partition.cc +++ b/src/Partition.cc @@ -193,6 +193,11 @@ std::vector Partition::get_mountpoints() const return mountpoints ; } +void Partition::clear_mountpoints() +{ + mountpoints .clear() ; +} + bool Partition::compare_paths( const Glib::ustring & A, const Glib::ustring & B ) { return A .length() < B .length() ; diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index bbbf798f..550a2ed9 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -1178,8 +1178,9 @@ void Win_GParted::activate_paste() { Dialog_Partition_Copy dialog( gparted_core .get_fs( copied_partition .filesystem ), devices[ current_device ] .cylsize ) ; - //we don't need the errors of the source partition. + //we don't need the errors/mountpoints of the source partition. copied_partition .error .clear() ; + copied_partition .clear_mountpoints() ; dialog .Set_Data( selected_partition, copied_partition ) ; dialog .set_transient_for( *this ); diff --git a/src/ext2.cc b/src/ext2.cc index 3931db8b..38478130 100644 --- a/src/ext2.cc +++ b/src/ext2.cc @@ -126,12 +126,13 @@ bool ext2::Copy( const Glib::ustring & src_part_path, operation_details .back() .sub_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; - - return Resize( Partition( dest_part_path ), operation_details, true ) ; + return true ; + } + else + { + operation_details .back() .status = OperationDetails::ERROR ; + return false ; } - - operation_details .back() .status = OperationDetails::ERROR ; - return false ; } bool ext2::Check_Repair( const Partition & partition, std::vector & operation_details ) diff --git a/src/ext3.cc b/src/ext3.cc index 5b27d538..016e182e 100644 --- a/src/ext3.cc +++ b/src/ext3.cc @@ -127,12 +127,13 @@ bool ext3::Copy( const Glib::ustring & src_part_path, operation_details .back() .sub_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; - - return Resize( Partition( dest_part_path ), operation_details, true ) ; + return true ; + } + else + { + operation_details .back() .status = OperationDetails::ERROR ; + return false ; } - - operation_details .back() .status = OperationDetails::ERROR ; - return false ; } bool ext3::Check_Repair( const Partition & partition, std::vector & operation_details ) diff --git a/src/fat16.cc b/src/fat16.cc index a1efb958..2c52ef93 100644 --- a/src/fat16.cc +++ b/src/fat16.cc @@ -96,8 +96,7 @@ bool fat16::Resize( const Partition & partition_new, std::vector & operation_details, bool fill_partition ) { - //handled in GParted_Core::resize_normal_using_libparted - return false ; + return true ; } bool fat16::Copy( const Glib::ustring & src_part_path, diff --git a/src/fat32.cc b/src/fat32.cc index e48f058e..701cee7f 100644 --- a/src/fat32.cc +++ b/src/fat32.cc @@ -95,8 +95,7 @@ bool fat32::Resize( const Partition & partition_new, std::vector & operation_details, bool fill_partition ) { - //handled in GParted_Core::Resize_Normal_Using_Libparted - return false ; + return true ; } bool fat32::Copy( const Glib::ustring & src_part_path, diff --git a/src/jfs.cc b/src/jfs.cc index 24220c71..ca97c875 100644 --- a/src/jfs.cc +++ b/src/jfs.cc @@ -210,12 +210,14 @@ bool jfs::Copy( const Glib::ustring & src_part_path, operation_details .back() .sub_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; + return true ; - return Resize( Partition( dest_part_path ), operation_details, true ) ; } - - operation_details .back() .status = OperationDetails::ERROR ; - return false ; + else + { + operation_details .back() .status = OperationDetails::ERROR ; + return false ; + } } bool jfs::Check_Repair( const Partition & partition, std::vector & operation_details ) diff --git a/src/ntfs.cc b/src/ntfs.cc index ef604e83..431c6193 100644 --- a/src/ntfs.cc +++ b/src/ntfs.cc @@ -145,12 +145,13 @@ bool ntfs::Copy( const Glib::ustring & src_part_path, operation_details .back() .sub_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; - - return Resize( Partition( dest_part_path ), operation_details, true ) ; + return true ; + } + else + { + operation_details .back() .status = OperationDetails::ERROR ; + return false ; } - - operation_details .back() .status = OperationDetails::ERROR ; - return false ; } bool ntfs::Check_Repair( const Partition & partition, std::vector & operation_details ) diff --git a/src/reiserfs.cc b/src/reiserfs.cc index efd68086..71df173d 100644 --- a/src/reiserfs.cc +++ b/src/reiserfs.cc @@ -133,12 +133,13 @@ bool reiserfs::Copy( const Glib::ustring & src_part_path, operation_details .back() .sub_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; - - return Resize( Partition( dest_part_path ), operation_details, true ) ; + return true ; + } + else + { + operation_details .back() .status = OperationDetails::ERROR ; + return false ; } - - operation_details .back() .status = OperationDetails::ERROR ; - return false ; } bool reiserfs::Check_Repair( const Partition & partition, std::vector & operation_details )