From bd02bca6131883f1aab455a9f7c7192ab1e761c0 Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Sun, 21 Nov 2004 21:49:38 +0000 Subject: [PATCH] P ). Resizing of ext2/3 works perfect now. I've even tested it on the * Again way too many chances to create a detailed entry (i'm glad i'm the only dev atm :P ). Resizing of ext2/3 works perfect now. I've even tested it on the partition holding my SG seasons =) Implemented checking of filesystems (only internally used atm). Done some overall tweaking, finetuning etc.. release 0.0.7 is getting shape. --- ChangeLog | 7 + include/Dialog_Partition_Copy.h | 6 +- include/Dialog_Partition_Resize_Move.h | 2 +- include/FileSystem.h | 11 +- include/GParted_Core.h | 8 +- include/Operation.h | 2 - include/Partition.h | 8 +- include/TreeView_Detail.h | 12 +- include/Utils.h | 6 +- include/VBox_VisualDisk.h | 4 +- include/ext2.h | 4 +- include/ext3.h | 4 +- include/fat16.h | 4 +- include/fat32.h | 4 +- include/linux_swap.h | 4 +- include/reiserfs.h | 4 +- src/Dialog_Partition_Copy.cc | 24 +-- src/Dialog_Partition_Info.cc | 4 +- src/Dialog_Partition_New.cc | 5 +- src/Dialog_Partition_Resize_Move.cc | 4 +- src/FileSystem.cc | 11 +- src/GParted_Core.cc | 246 +++++++++++++++---------- src/Partition.cc | 21 +-- src/TreeView_Detail.cc | 87 ++++----- src/VBox_VisualDisk.cc | 134 +++++++------- src/Win_GParted.cc | 14 +- src/ext2.cc | 113 ++++++------ src/ext3.cc | 125 ++++++------- src/fat16.cc | 76 ++++---- src/fat32.cc | 76 ++++---- src/linux_swap.cc | 49 ++--- src/reiserfs.cc | 73 ++++---- 32 files changed, 613 insertions(+), 539 deletions(-) diff --git a/ChangeLog b/ChangeLog index aeb875f1..baf57243 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-11-21 Bart Hakvoort + + * Again way too many chances to create a detailed entry (i'm glad i'm the only dev atm :P ). + Resizing of ext2/3 works perfect now. I've even tested it on the partition holding my SG seasons =) + Implemented checking of filesystems (only internally used atm). + Done some overall tweaking, finetuning etc.. release 0.0.7 is getting shape. + 2004-11-19 Bart Hakvoort * include/Device.h, diff --git a/include/Dialog_Partition_Copy.h b/include/Dialog_Partition_Copy.h index 078b6207..e5da00bc 100644 --- a/include/Dialog_Partition_Copy.h +++ b/include/Dialog_Partition_Copy.h @@ -26,9 +26,9 @@ namespace GParted class Dialog_Partition_Copy : public Dialog_Base_Partition { public: - Dialog_Partition_Copy() ; - void Set_Data( Partition & selected_partition, Partition & copied_partition ); - Partition Get_New_Partition() ; + Dialog_Partition_Copy( ) ; + void Set_Data( const Partition & selected_partition, const Partition & copied_partition ); + Partition Get_New_Partition( ) ; private: diff --git a/include/Dialog_Partition_Resize_Move.h b/include/Dialog_Partition_Resize_Move.h index 7a065327..34b2136a 100644 --- a/include/Dialog_Partition_Resize_Move.h +++ b/include/Dialog_Partition_Resize_Move.h @@ -26,7 +26,7 @@ namespace GParted class Dialog_Partition_Resize_Move : public Dialog_Base_Partition { public: - Dialog_Partition_Resize_Move( std::vector FILESYSTEMS ) ; + Dialog_Partition_Resize_Move( std::vector FILESYSTEMS, Sector cylinder_size ) ; void Set_Data( const Partition & selected_partition, const std::vector & partitions ) ; private: diff --git a/include/FileSystem.h b/include/FileSystem.h index 99077e12..bc2ff5b7 100644 --- a/include/FileSystem.h +++ b/include/FileSystem.h @@ -78,21 +78,26 @@ namespace GParted class FileSystem { public: + FileSystem( ) ; virtual ~FileSystem( ) { } virtual FS get_filesystem_support( ) = 0 ; + virtual void Set_Used_Sectors( Partition & partition ) = 0 ; virtual bool Create( const Glib::ustring device_path, const Partition & new_partition ) = 0 ; - virtual bool Resize( const Glib::ustring device_path, const Partition & partition_old, const Partition & partition_new ) = 0 ; + virtual bool Resize( const Partition & partition_new, bool fill_partition = false ) = 0 ; virtual bool Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) = 0 ; + virtual bool Check_Repair( const Partition & partition ) = 0 ; virtual int get_estimated_time( long MB_to_Consider ) = 0 ; - + Glib::RefPtr textbuffer ; + PedDisk *disk ; //see GParted_Core::Set_Used_Sectors() ... + long cylinder_size ; //see GParted_Core::Resize() + protected: bool Execute_Command( Glib::ustring command ) ; PedDevice *device ; - PedDisk *disk ; private: void Update_Textview( ) ; diff --git a/include/GParted_Core.h b/include/GParted_Core.h index b7ed8ad4..43e0a915 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -41,7 +41,7 @@ public: void find_supported_filesystems( ) ; void get_devices( std::vector & devices, bool deep_scan ) ; - int get_estimated_time( Operation & operation ) ; + int get_estimated_time( const Operation & operation ) ; void Apply_Operation_To_Disk( Operation & operation ); @@ -57,13 +57,15 @@ public: private: void set_device_partitions( Device & device, bool deep_scan = true ) ; Glib::ustring get_sym_path( const Glib::ustring & real_path ) ; - Sector Get_Used_Sectors( PedPartition *c_partition, const Glib::ustring & sym_path ); + void Set_Used_Sectors( Partition & partition ); Glib::ustring Get_Flags( PedPartition *c_partition ) ; int Create_Empty_Partition( const Glib::ustring & device_path, Partition & new_partition, bool copy = false ) ; - bool Resize_Extended( const Glib::ustring & device_path, const Partition & extended ) ; + bool Resize_Container_Partition( const Glib::ustring & device_path, const Partition & partition_old, const Partition & partition_new ) ; + bool Resize_Normal_Using_Libparted( const Glib::ustring & device_path, const Partition & partition_old, const Partition & partition_new ) ; void Show_Error( Glib::ustring message ) ; void set_proper_filesystem( const Glib::ustring & filesystem ) ; + long Get_Cylinder_Size( const Glib::ustring & device_path ) ; Glib::RefPtr textbuffer; diff --git a/include/Operation.h b/include/Operation.h index ebfa3ec9..068bd074 100644 --- a/include/Operation.h +++ b/include/Operation.h @@ -54,8 +54,6 @@ public: Glib::ustring str_operation ; Glib::ustring copied_partition_path ; //for copy operation.. - - private: void Insert_Unallocated( std::vector & partitions, Sector start, Sector end ); int Get_Index_Original( std::vector & partitions ) ; diff --git a/include/Partition.h b/include/Partition.h index b010ad02..7455e8b0 100644 --- a/include/Partition.h +++ b/include/Partition.h @@ -66,16 +66,16 @@ public: const bool inside_extended, const bool busy ) ; - void Set_Used( Sector used ) ; + void Set_Unused( Sector sectors_unused ) ; void Set_Unallocated( Sector sector_start, Sector sector_end, bool inside_extended ); //update partition number (used when a logical partition is deleted) void Update_Number( int new_number ); - long Get_Length_MB( ); - long Get_Used_MB( ); - long Get_Unused_MB( ); + const long Get_Length_MB( ) const ; + const long Get_Used_MB( ) const ; + const long Get_Unused_MB( ) const ; //some public members Glib::ustring partition;//the symbolic path (e.g. /dev/hda1 ) diff --git a/include/TreeView_Detail.h b/include/TreeView_Detail.h index ce44719a..f4d819b6 100644 --- a/include/TreeView_Detail.h +++ b/include/TreeView_Detail.h @@ -36,20 +36,20 @@ class TreeView_Detail : public Gtk::TreeView { public: TreeView_Detail( ); - void Load_Partitions( std::vector & partitions ) ; + void Load_Partitions( const std::vector & partitions ) ; void Set_Selected( const Partition & partition ); //signals for interclass communication - sigc::signal signal_mouse_click; + sigc::signal signal_mouse_click; private: - void Create_Row( const Gtk::TreeRow &, Partition &); + void Create_Row( const Gtk::TreeRow & treerow, const Partition & partition ); //overridden signal virtual bool on_button_press_event(GdkEventButton *); - Gtk::TreeRow row,childrow; - Gtk::TreeIter iter,iter_child; + Gtk::TreeRow row, childrow; + Gtk::TreeIter iter, iter_child; Glib::RefPtr treestore_detail; Glib::RefPtr treeselection; @@ -69,7 +69,7 @@ private: Gtk::TreeModelColumn flags; Gtk::TreeModelColumn< Partition > partition_struct; //hidden column ( see also on_button_press_event ) - treeview_detail_Columns() { + treeview_detail_Columns( ) { add( partition ); add( type ); add( type_square ); add( size ); add( used ); add( unused ); add( color ); add( text_color ); add( status_icon ); add( flags ); add(partition_struct); } }; diff --git a/include/Utils.h b/include/Utils.h index c72786ed..844f45ab 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -43,12 +43,14 @@ typedef long long Sector; struct FS { Glib::ustring filesystem ; + bool read ; //can we get the amount of used sectors? bool create ; bool resize ; //only endpoint bool move ; //startpoint and endpoint - bool check ; + bool check ; //some checktool available? + bool copy ; - FS( ) {create = resize = move = check = false ;} + FS( ) {read = create = resize = move = check = copy = false ;} }; diff --git a/include/VBox_VisualDisk.h b/include/VBox_VisualDisk.h index f579971c..c0ab9487 100644 --- a/include/VBox_VisualDisk.h +++ b/include/VBox_VisualDisk.h @@ -54,7 +54,7 @@ class VBox_VisualDisk : public Gtk::VBox public: VBox_VisualDisk( const std::vector & partitions, const Sector device_length ); - ~VBox_VisualDisk(); + ~VBox_VisualDisk( ); void Set_Selected( const Partition & ); @@ -64,7 +64,7 @@ public: private: void Build_Visual_Disk( ) ; //i still dream of some fully resizeable visualdisk.... - void Create_Visual_Partition( Partition & partition ) ; + void Create_Visual_Partition( const Partition & partition ) ; void Prepare_Legend( std::vector & legend, const std::vector & partitions ) ; void Build_Legend( ) ; diff --git a/include/ext2.h b/include/ext2.h index e630213d..a8b96cf3 100644 --- a/include/ext2.h +++ b/include/ext2.h @@ -28,9 +28,11 @@ class ext2 : public FileSystem { public: FS get_filesystem_support( ) ; + void Set_Used_Sectors( Partition & partition ) ; bool Create( const Glib::ustring device_path, const Partition & new_partition ) ; - bool Resize( const Glib::ustring device_path, const Partition & partition_old, const Partition & partition_new ) ; + bool Resize( const Partition & partition_new, bool fill_partition = false ) ; bool Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) ; + bool Check_Repair( const Partition & partition ) ; int get_estimated_time( long MB_to_Consider ) ; }; diff --git a/include/ext3.h b/include/ext3.h index ba3c1aec..4c29c42c 100644 --- a/include/ext3.h +++ b/include/ext3.h @@ -28,9 +28,11 @@ class ext3 : public FileSystem { public: FS get_filesystem_support( ) ; + void Set_Used_Sectors( Partition & partition ) ; bool Create( const Glib::ustring device_path, const Partition & new_partition ) ; - bool Resize( const Glib::ustring device_path, const Partition & partition_old, const Partition & partition_new ) ; + bool Resize( const Partition & partition_new, bool fill_partition = false ) ; bool Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) ; + bool Check_Repair( const Partition & partition ) ; int get_estimated_time( long MB_to_Consider ) ; }; diff --git a/include/fat16.h b/include/fat16.h index eb2d45f3..d1e1a6e8 100644 --- a/include/fat16.h +++ b/include/fat16.h @@ -28,9 +28,11 @@ class fat16 : public FileSystem { public: FS get_filesystem_support( ) ; + void Set_Used_Sectors( Partition & partition ) ; bool Create( const Glib::ustring device_path, const Partition & new_partition ) ; - bool Resize( const Glib::ustring device_path, const Partition & partition_old, const Partition & partition_new ) ; + bool Resize( const Partition & partition_new, bool fill_partition = false ) ; bool Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) ; + bool Check_Repair( const Partition & partition ) ; int get_estimated_time( long MB_to_Consider ) ; }; diff --git a/include/fat32.h b/include/fat32.h index 5e5ff400..52282919 100644 --- a/include/fat32.h +++ b/include/fat32.h @@ -28,9 +28,11 @@ class fat32 : public FileSystem { public: FS get_filesystem_support( ); + void Set_Used_Sectors( Partition & partition ) ; bool Create( const Glib::ustring device_path, const Partition & new_partition ) ; - bool Resize( const Glib::ustring device_path, const Partition & partition_old, const Partition & partition_new ) ; + bool Resize( const Partition & partition_new, bool fill_partition = false ) ; bool Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) ; + bool Check_Repair( const Partition & partition ) ; int get_estimated_time( long MB_to_Consider ) ; }; diff --git a/include/linux_swap.h b/include/linux_swap.h index a54f0200..6052ab1d 100644 --- a/include/linux_swap.h +++ b/include/linux_swap.h @@ -28,9 +28,11 @@ class linux_swap : public FileSystem { public: FS get_filesystem_support( ) ; + void Set_Used_Sectors( Partition & partition ) ; bool Create( const Glib::ustring device_path, const Partition & new_partition ) ; - bool Resize( const Glib::ustring device_path, const Partition & partition_old, const Partition & partition_new ) ; + bool Resize( const Partition & partition_new, bool fill_partition = false ) ; bool Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) ; + bool Check_Repair( const Partition & partition ) ; int get_estimated_time( long MB_to_Consider ) ; }; diff --git a/include/reiserfs.h b/include/reiserfs.h index 28cd0384..80f7e253 100644 --- a/include/reiserfs.h +++ b/include/reiserfs.h @@ -30,9 +30,11 @@ class reiserfs : public FileSystem { public: FS get_filesystem_support( ) ; + void Set_Used_Sectors( Partition & partition ) ; bool Create( const Glib::ustring device_path, const Partition & new_partition ) ; - bool Resize( const Glib::ustring device_path, const Partition & partition_old, const Partition & partition_new ) ; + bool Resize( const Partition & partition_new, bool fill_partition = false ) ; bool Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) ; + bool Check_Repair( const Partition & partition ) ; int get_estimated_time( long MB_to_Consider ) ; }; diff --git a/src/Dialog_Partition_Copy.cc b/src/Dialog_Partition_Copy.cc index cd7fdc88..0605c4d8 100644 --- a/src/Dialog_Partition_Copy.cc +++ b/src/Dialog_Partition_Copy.cc @@ -26,7 +26,7 @@ Dialog_Partition_Copy::Dialog_Partition_Copy() Set_Confirm_Button( PASTE ) ; } -void Dialog_Partition_Copy::Set_Data( Partition & selected_partition, Partition & copied_partition ) +void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, const Partition & copied_partition ) { GRIP = true ; //prevents on spinbutton_changed from getting activated prematurely @@ -36,40 +36,40 @@ void Dialog_Partition_Copy::Set_Data( Partition & selected_partition, Partition frame_resizer_base ->set_rgb_partition_color( copied_partition .color ) ; //set some widely used values... - START = selected_partition.sector_start ; - total_length = selected_partition.sector_end - selected_partition.sector_start ; + START = selected_partition .sector_start ; + total_length = selected_partition .sector_end - selected_partition .sector_start ; TOTAL_MB = selected_partition .Get_Length_MB() ; MB_PER_PIXEL = (double) TOTAL_MB / 500 ; //now calculate proportional length of partition frame_resizer_base ->set_x_start( 0 ) ; - frame_resizer_base ->set_x_end( ( Round( (double) (copied_partition.sector_end - copied_partition.sector_start) / ( (double)total_length/500) )) ) ; - frame_resizer_base ->set_used( frame_resizer_base ->get_x_end() ) ; + frame_resizer_base ->set_x_end( ( Round( (double) (copied_partition .sector_end - copied_partition .sector_start) / ( (double)total_length/500) )) ) ; + frame_resizer_base ->set_used( frame_resizer_base ->get_x_end( ) ) ; //used to store current positions (see Dialog_Base_Partition::on_signal_resize) this ->x_start = frame_resizer_base ->get_x_start( ) ; this ->x_end = frame_resizer_base ->get_x_end( ) ; //set values of spinbutton_before - spinbutton_before .set_range( 0, TOTAL_MB - copied_partition .Get_Length_MB() -1 ) ;//mind the -1 !! + spinbutton_before .set_range( 0, TOTAL_MB - copied_partition .Get_Length_MB( ) -1 ) ;//mind the -1 !! spinbutton_before .set_value( 0 ) ; //set values of spinbutton_size (check for fat16 maxsize of 1023 MB) long UPPER; - if ( copied_partition.filesystem == "fat16" && Sector_To_MB( total_length ) > 1023 ) + if ( copied_partition .filesystem == "fat16" && Sector_To_MB( total_length ) > 1023 ) UPPER = 1023 ; else UPPER = TOTAL_MB ; - spinbutton_size .set_range( copied_partition .Get_Length_MB() +1, UPPER ) ; - spinbutton_size .set_value( copied_partition .Get_Length_MB() ) ; + spinbutton_size .set_range( copied_partition .Get_Length_MB( ) +1, UPPER ) ; + spinbutton_size .set_value( copied_partition .Get_Length_MB( ) ) ; //set values of spinbutton_after - spinbutton_after .set_range( 0, TOTAL_MB - copied_partition .Get_Length_MB() -1 ) ; - spinbutton_after .set_value( TOTAL_MB - copied_partition .Get_Length_MB() ) ; + spinbutton_after .set_range( 0, TOTAL_MB - copied_partition .Get_Length_MB( ) -1 ) ; + spinbutton_after .set_value( TOTAL_MB - copied_partition .Get_Length_MB( ) ) ; //set contents of label_minmax - Set_MinMax_Text( copied_partition .Get_Length_MB() +1, UPPER ) ; + Set_MinMax_Text( copied_partition .Get_Length_MB( ) +1, UPPER ) ; //set global selected_partition (see Dialog_Base_Partition::Get_New_Partition ) this ->selected_partition = copied_partition ; diff --git a/src/Dialog_Partition_Info.cc b/src/Dialog_Partition_Info.cc index 35ac631a..eb5c7616 100644 --- a/src/Dialog_Partition_Info.cc +++ b/src/Dialog_Partition_Info.cc @@ -27,7 +27,7 @@ Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition ) this ->set_resizable( false ); /*TO TRANSLATORS: dialogtitle, looks like Information about /dev/hda3 */ - this->set_title( String::ucompose( _( "Information about %1"), partition.partition ) ); + this ->set_title( String::ucompose( _( "Information about %1"), partition .partition ) ); init_drawingarea( ) ; @@ -44,7 +44,7 @@ Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition ) hbox = manage( new Gtk::HBox( ) ); hbox ->pack_start( *image, Gtk::PACK_SHRINK ) ; - hbox ->pack_start( * mk_label( " " + (Glib::ustring) _( "Libparted message:" ) + " " ), Gtk::PACK_SHRINK ) ; + hbox ->pack_start( * mk_label( " " + (Glib::ustring) _( "Warning:" ) + " " ), Gtk::PACK_SHRINK ) ; frame ->set_label_widget( *hbox ) ; frame ->add( * mk_label( "" + partition.error + "", true, true, true ) ) ; diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc index 7bffce23..b1bd4924 100644 --- a/src/Dialog_Partition_New.cc +++ b/src/Dialog_Partition_New.cc @@ -42,6 +42,7 @@ void Dialog_Partition_New::Set_Data( const Partition & partition, bool any_exten this ->new_count = new_count; this ->selected_partition = partition; this ->FILESYSTEMS = FILESYSTEMS ; + this ->FILESYSTEMS .erase( this ->FILESYSTEMS .end( ) ) ;//remove dummy "unknown" FS fs ; fs.filesystem = "extended" ; this ->FILESYSTEMS .push_back( fs ) ; @@ -169,14 +170,14 @@ void Dialog_Partition_New::optionmenu_changed( bool type ) if (optionmenu_type.get_history() == GParted::EXTENDED ) { menu_filesystem.items().push_back(Gtk::Menu_Helpers::MenuElem( "extended") ) ; - optionmenu_filesystem.set_history( 6 ) ; + optionmenu_filesystem.set_history( 6 ) ; optionmenu_filesystem.set_sensitive( false ); } else if ( menu_filesystem.items() .size() > 6 ) { menu_filesystem.items() .remove( menu_filesystem.items() .back() ); optionmenu_filesystem.set_sensitive( true ); - optionmenu_filesystem.set_history( 0 ) ; + optionmenu_filesystem.set_history( 0 ) ; } } diff --git a/src/Dialog_Partition_Resize_Move.cc b/src/Dialog_Partition_Resize_Move.cc index 004b2e56..cf61f258 100644 --- a/src/Dialog_Partition_Resize_Move.cc +++ b/src/Dialog_Partition_Resize_Move.cc @@ -20,10 +20,10 @@ namespace GParted { -Dialog_Partition_Resize_Move::Dialog_Partition_Resize_Move( std::vector FILESYSTEMS ) +Dialog_Partition_Resize_Move::Dialog_Partition_Resize_Move( std::vector FILESYSTEMS, Sector cylinder_size ) { this ->FILESYSTEMS = FILESYSTEMS ; - BUF = 5 ; + BUF = Sector_To_MB( cylinder_size ) *2 ; } void Dialog_Partition_Resize_Move::Set_Data( const Partition & selected_partition, const std::vector & partitions ) diff --git a/src/FileSystem.cc b/src/FileSystem.cc index 219e120e..534c808d 100644 --- a/src/FileSystem.cc +++ b/src/FileSystem.cc @@ -21,14 +21,20 @@ namespace GParted { +FileSystem::FileSystem( ) +{ + disk = NULL; + cylinder_size = 0 ; +} + bool FileSystem::Execute_Command( Glib::ustring command ) { Glib::Dispatcher dispatcher; sigc::connection conn = dispatcher .connect( sigc::mem_fun(*this, &FileSystem::Update_Textview) ); //stderr to stdout - command += " 2>&1" ; - + //command += " 2>&1" ; + std::cout << command << std::endl ; output = command + "\n\n" ; dispatcher ( ) ; @@ -47,6 +53,7 @@ bool FileSystem::Execute_Command( Glib::ustring command ) output = "" ; dispatcher ( ) ; + return true ; } diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index c43e00f7..fefce72e 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -3,26 +3,12 @@ namespace GParted { -//AFAIK it's not possible to use a C++ memberfunction as a callback for a C libary function (if you know otherwise, PLEASE contact me) -Glib::ustring error_message; -PedExceptionOption PedException_Handler (PedException* ex) -{ - error_message = Glib::locale_to_utf8( ex ->message ) ; - - std::cout << "\nLIBPARTED MESSAGE ----------------------\n" << error_message << "\n---------------------------\n"; - - return PED_EXCEPTION_UNHANDLED ; -} - - - GParted_Core::GParted_Core( ) { device = NULL ; disk = NULL ; c_partition = NULL ; - ped_exception_set_handler( PedException_Handler ) ; - + p_filesystem = NULL ; textbuffer = Gtk::TextBuffer::create( ) ; @@ -52,6 +38,10 @@ void GParted_Core::find_supported_filesystems( ) reiserfs fs_reiserfs; FILESYSTEMS .push_back( fs_reiserfs .get_filesystem_support( ) ) ; + + //unknown filesystem (default when no match is found) + FS fs ; fs .filesystem = "unknown" ; + FILESYSTEMS .push_back( fs ) ; } void GParted_Core::get_devices( std::vector & devices, bool deep_scan ) @@ -110,7 +100,7 @@ void GParted_Core::get_devices( std::vector & devices, bool deep_scan ) void GParted_Core::set_device_partitions( Device & device, bool deep_scan ) { Partition partition_temp ; - Glib::ustring part_path, error ; + Glib::ustring part_path ; int EXT_INDEX = -1 ; //clear partitions @@ -131,13 +121,13 @@ void GParted_Core::set_device_partitions( Device & device, bool deep_scan ) else { temp = "unknown" ; - error = _( "Unable to detect filesystem! Possible reasons are:" ) ; - error += "\n-"; - error += _( "The filesystem is damaged" ) ; - error += "\n-" ; - error += _( "The filesystem is unknown to libparted" ) ; - error += "\n-"; - error += _( "There is no filesystem available (unformatted)" ) ; + partition_temp .error = _( "Unable to detect filesystem! Possible reasons are:" ) ; + partition_temp .error += "\n-"; + partition_temp .error += _( "The filesystem is damaged" ) ; + partition_temp .error += "\n-" ; + partition_temp .error += _( "The filesystem is unknown to libparted" ) ; + partition_temp .error += "\n-"; + partition_temp .error += _( "There is no filesystem available (unformatted)" ) ; } partition_temp .Set( part_path, @@ -148,11 +138,21 @@ void GParted_Core::set_device_partitions( Device & device, bool deep_scan ) c_partition ->type, ped_partition_is_busy( c_partition ) ); - if ( deep_scan ) - partition_temp .Set_Used( Get_Used_Sectors( c_partition, part_path ) ) ; + if ( deep_scan && partition_temp .filesystem != "linux-swap" ) + { + Set_Used_Sectors( partition_temp ) ; + + //the 'Unknow' filesystem warning overrules this one + if ( partition_temp .sectors_used == -1 && partition_temp .error .empty( ) ) + { + partition_temp .error = _("Unable to read the contents of this filesystem!") ; + partition_temp .error += "\n" ; + partition_temp .error += ("As a result you won't be able to resize this partition.") ; + } + } partition_temp .flags = Get_Flags( c_partition ) ; - partition_temp .error = error .empty( ) ? error_message : error ; + if ( partition_temp .busy ) device .busy = true ; @@ -203,16 +203,13 @@ void GParted_Core::set_device_partitions( Device & device, bool deep_scan ) device .device_partitions[ EXT_INDEX ] .logicals .push_back( partition_temp ) ; } - //reset stuff.. - error = error_message = "" ; - //next partition (if any) c_partition = ped_disk_next_partition ( disk, c_partition ) ; } } -int GParted_Core::get_estimated_time( Operation & operation ) +int GParted_Core::get_estimated_time( const Operation & operation ) { switch ( operation .operationtype ) { @@ -269,13 +266,9 @@ void GParted_Core::Apply_Operation_To_Disk( Operation & operation ) case COPY: if ( ! Copy( operation .device_path, operation .copied_partition_path, operation .partition_new ) ) Show_Error( String::ucompose( _("Error while copying %1"), operation .partition_new .partition ) ) ; - } - - } - bool GParted_Core::Create( const Glib::ustring & device_path, Partition & new_partition ) { if ( new_partition .type == GParted::EXTENDED ) @@ -316,16 +309,45 @@ bool GParted_Core::Delete( const Glib::ustring & device_path, const Partition & return return_value ; } -bool GParted_Core::Resize(const Glib::ustring & device_path, const Partition & partition_old, const Partition & partition_new ) +bool GParted_Core::Resize( const Glib::ustring & device_path, const Partition & partition_old, const Partition & partition_new ) { if ( partition_old .type == GParted::EXTENDED ) - return Resize_Extended( device_path, partition_new ) ; + return Resize_Container_Partition( device_path, partition_old, partition_new ) ; + //these 3 still use libparted's resizer. + else if ( partition_old .filesystem == "linux-swap" || + partition_old .filesystem == "fat16" || + partition_old .filesystem == "fat32" + ) + return Resize_Normal_Using_Libparted( device_path, partition_old, partition_new ) ; + + //use custom resize tools..(afaik only resize, no moves) else { set_proper_filesystem( partition_new .filesystem ) ; - - return p_filesystem ->Resize( device_path, partition_old, partition_new ) ; + + if ( p_filesystem ->Check_Repair( partition_new ) ) + { + //shrinking + if ( partition_new .sector_end < partition_old .sector_end ) + { + p_filesystem ->cylinder_size = Get_Cylinder_Size( device_path ) ; + + if ( p_filesystem ->Resize( partition_new ) ) + Resize_Container_Partition( device_path, partition_old, partition_new ) ; + } + + //growing + if ( partition_new .sector_end > partition_old .sector_end ) + Resize_Container_Partition( device_path, partition_old, partition_new ) ; + + + p_filesystem ->Check_Repair( partition_new ) ; + + p_filesystem ->Resize( partition_new, true ) ; //expand filesystem to fit exactly in partition + + return p_filesystem ->Check_Repair( partition_new ) ; + } } return false ; @@ -383,64 +405,32 @@ Glib::ustring GParted_Core::get_sym_path( const Glib::ustring & real_path ) } -Sector GParted_Core::Get_Used_Sectors( PedPartition *c_partition, const Glib::ustring & sym_path) +void GParted_Core::Set_Used_Sectors( Partition & partition ) { - /* This is quite an unreliable process, atm i try two different methods, but since both are far from perfect the results are - * questionable. - * - first i try geometry.get_used() in libpartedpp, i implemented this function to check the minimal size when resizing a partition. Disadvantage - * of this method is the fact it won't work on mounted filesystems. Besides that, its SLOW - * - if the former method fails ( result is -1 ) i'll try to read the output from the df command ( df -k --sync ) - * - if this fails the filesystem on the partition is ( more or less ) unknown to the operating system and therefore the unused sectors cannot be calcualted - * - as soon as i have my internetconnection back i should ask people with more experience on this stuff for advice ! - */ + if ( partition .filesystem == "unknown" || partition .filesystem == "linux-swap" ) + partition .Set_Unused( -1 ) ; - //check if there is a (known) filesystem - if ( ! c_partition ->fs_type ) - return -1; - - //used sectors are not relevant for swapspace - if ( (Glib::ustring) c_partition ->fs_type ->name == "linux-swap" ) - return -1; - - //METHOD #1 - //the getused method doesn't work on mounted partitions and for some filesystems ( i *guess* this is called check by andrew ) - if ( ! ped_partition_is_busy( c_partition ) && Get_FS( c_partition ->fs_type ->name, FILESYSTEMS ) .create ) - { - PedFileSystem *fs = NULL; - PedConstraint *constraint = NULL; - - fs = ped_file_system_open( & c_partition ->geom ); - - if ( fs ) - { - constraint = ped_file_system_get_resize_constraint (fs); - ped_file_system_close (fs); - if ( constraint && constraint->min_size != -1 ) - return constraint->min_size ; - } - } - - //METHOD #2 - //this ony works for mounted ( and therefore known to the OS ) filesystems. My method is quite crude, keep in mind it's only temporary ;-) - if ( ped_partition_is_busy( c_partition ) ) + else if ( partition .busy ) { - Glib::ustring buf; - system( ("df -k --sync " + sym_path + " | grep " + sym_path + " > /tmp/.tmp_gparted") .c_str( ) ); + system( ("df -k --sync " + partition .partition + " | grep " + partition .partition + " > /tmp/.tmp_gparted") .c_str( ) ); std::ifstream file_input( "/tmp/.tmp_gparted" ); - file_input >> buf; //skip first value - file_input >> buf; - if ( buf != "0" && ! buf .empty( ) ) - { - file_input >> buf; - file_input .close( ); system( "rm -f /tmp/.tmp_gparted" ); - return atoi( buf .c_str( ) ) * 1024/512 ; - } - file_input .close( ); system( "rm -f /tmp/.tmp_gparted" ); + //we need the 4th value + file_input >> temp; file_input >> temp; file_input >> temp;file_input >> temp; + if ( ! temp .empty( ) ) + partition .Set_Unused( atoi( temp .c_str( ) ) * 1024/512 ) ; + + file_input .close( ); + system( "rm -f /tmp/.tmp_gparted" ); } - - return -1 ; //all methods were unsuccesfull + else if ( Get_FS( partition .filesystem, FILESYSTEMS ) .read ) + { + set_proper_filesystem( partition .filesystem ) ; + + p_filesystem ->disk = disk ; + p_filesystem ->Set_Used_Sectors( partition ) ; + } } int GParted_Core::Create_Empty_Partition( const Glib::ustring & device_path, Partition & new_partition, bool copy ) @@ -491,28 +481,70 @@ int GParted_Core::Create_Empty_Partition( const Glib::ustring & device_path, Par return new_partition .partition_number ; } -bool GParted_Core::Resize_Extended( const Glib::ustring & device_path, const Partition & extended ) +bool GParted_Core::Resize_Container_Partition( const Glib::ustring & device_path, const Partition & partition_old, const Partition & partition_new ) { bool return_value = false ; + PedConstraint *constraint = NULL ; + c_partition = NULL ; + if ( open_device_and_disk( device_path, device, disk ) ) { - PedPartition *c_part = NULL ; - PedConstraint *constraint = NULL ; + if ( partition_old .type == GParted::EXTENDED ) + c_partition = ped_disk_extended_partition( disk ) ; + else + c_partition = ped_disk_get_partition_by_sector( disk, (partition_old .sector_end + partition_old .sector_start) / 2 ) ; - c_part = ped_disk_extended_partition( disk ) ; - if ( c_part ) + if ( c_partition ) { - constraint = ped_constraint_any ( device ); + constraint = ped_constraint_any( device ); if ( constraint ) { - if ( ped_disk_set_partition_geom ( disk, c_part, constraint, extended .sector_start, extended .sector_end ) ) - { - ped_partition_set_system ( c_part, NULL ); + if ( ped_disk_set_partition_geom ( disk, c_partition, constraint, partition_new .sector_start, partition_new .sector_end ) ) return_value = Commit( disk ) ; - } + + ped_constraint_destroy ( constraint ); + } - ped_constraint_destroy (constraint); + + } + + close_device_and_disk( device, disk ) ; + } + + sleep( 1 ) ; //the OS needs time to re-add the devicenode.. + + return return_value ; +} + +bool GParted_Core::Resize_Normal_Using_Libparted( const Glib::ustring & device_path, const Partition & partition_old, const Partition & partition_new ) +{ + bool return_value = false ; + + PedFileSystem *fs = NULL ; + PedConstraint *constraint = NULL ; + c_partition = NULL ; + + if ( open_device_and_disk( device_path, device, disk ) ) + { + c_partition = ped_disk_get_partition_by_sector( disk, (partition_old .sector_end + partition_old .sector_start) / 2 ) ; + if ( c_partition ) + { + fs = ped_file_system_open ( & c_partition ->geom ); + if ( fs ) + { + constraint = ped_file_system_get_resize_constraint ( fs ); + if ( constraint ) + { + if ( ped_disk_set_partition_geom ( disk, c_partition, constraint, partition_new .sector_start, partition_new .sector_end ) && + ped_file_system_resize ( fs, & c_partition ->geom, NULL ) + ) + return_value = Commit( disk ) ; + + ped_constraint_destroy ( constraint ); + } + + ped_file_system_close ( fs ); } } @@ -570,4 +602,18 @@ void GParted_Core::set_proper_filesystem( const Glib::ustring & filesystem ) p_filesystem ->textbuffer = textbuffer ; } +long GParted_Core::Get_Cylinder_Size( const Glib::ustring & device_path ) +{ + long cylinder_size = 0 ; + + if ( open_device( device_path, device ) ) + { + cylinder_size = Sector_To_MB( device ->bios_geom .heads * device ->bios_geom .sectors ) ; + + close_device_and_disk( device, disk ) ; + } + + return cylinder_size ; +} + } //GParted diff --git a/src/Partition.cc b/src/Partition.cc index 1c8ebb3d..bffb2cf1 100644 --- a/src/Partition.cc +++ b/src/Partition.cc @@ -56,38 +56,37 @@ void Partition::Set( const Glib::ustring & partition, this ->busy = busy; } -void Partition::Set_Used( Sector used ) +void Partition::Set_Unused( Sector sectors_unused ) { - this ->sectors_used = used; - this ->sectors_unused = ( used == -1 ) ? -1 : ( sector_end - sector_start) - used ; + this ->sectors_unused = sectors_unused ; + this ->sectors_used = ( sectors_unused == -1 ) ? -1 : ( sector_end - sector_start) - sectors_unused ; } void Partition::Set_Unallocated( Sector sector_start, Sector sector_end, bool inside_extended ) { - this ->Set( _("Unallocated"), -1, GParted::UNALLOCATED, "unallocated", sector_start, sector_end , inside_extended, false); + this ->Set( _("Unallocated"), -1, GParted::UNALLOCATED, "unallocated", sector_start, sector_end , inside_extended, false ); this ->error = this ->flags = "" ; this ->status = GParted::STAT_REAL ; } void Partition::Update_Number( int new_number ) { //of course this fails when we have devicenames with numbers over 99 - partition_number >= 10 ? partition = partition.substr( 0, partition.length() -2 ) : partition = partition.substr( 0, partition.length() -1 ) ; - + partition = partition .substr( 0, partition .length( ) - ( partition_number >= 10 ? 2 : 1 ) ) ; this ->partition_number = new_number; this ->partition += num_to_str( partition_number ) ; } -long Partition::Get_Length_MB( ) +const long Partition::Get_Length_MB( ) const { - return Sector_To_MB( this ->sector_end - this ->sector_start) ; + return Sector_To_MB( sector_end - sector_start ) ; } -long Partition::Get_Used_MB( ) +const long Partition::Get_Used_MB( ) const { - return Sector_To_MB( this ->sectors_used) ; + return Sector_To_MB( this ->sectors_used ) ; } -long Partition::Get_Unused_MB( ) +const long Partition::Get_Unused_MB( ) const { return Get_Length_MB( ) - Get_Used_MB( ) ; } diff --git a/src/TreeView_Detail.cc b/src/TreeView_Detail.cc index b227b21c..9afe88d6 100644 --- a/src/TreeView_Detail.cc +++ b/src/TreeView_Detail.cc @@ -70,53 +70,58 @@ TreeView_Detail::TreeView_Detail( ) } -void TreeView_Detail::Load_Partitions( std::vector & partitions ) +void TreeView_Detail::Load_Partitions( const std::vector & partitions ) { - treestore_detail ->clear() ; + treestore_detail ->clear( ) ; - for ( unsigned int i=0;iappend()); - Create_Row( row, partitions[i] ); + row = *( treestore_detail ->append( ) ); + Create_Row( row, partitions[ i ] ); - if ( partitions[i] .type == GParted::EXTENDED ) + if ( partitions[ i ] .type == GParted::EXTENDED ) { - for ( unsigned int t=0;tappend( row.children() )); - Create_Row( childrow, partitions[i] .logicals[ t ] ); + childrow = *( treestore_detail ->append( row.children( ) ) ); + Create_Row( childrow, partitions[ i ] .logicals[ t ] ); } } } //show logical partitions ( if any ) - this->expand_all(); + this ->expand_all( ); } void TreeView_Detail::Set_Selected( const Partition & partition ) { //look for appropiate row - for(iter = treestore_detail->children().begin();iter!=treestore_detail->children().end();iter++ ) + for( iter = treestore_detail ->children( ) .begin( ) ; iter != treestore_detail ->children( ) .end( ) ; iter++ ) { row = *iter; - partition_temp = row[treeview_detail_columns.partition_struct] ; + partition_temp = row[ treeview_detail_columns.partition_struct ] ; //primary's - if ( partition .sector_start >= partition_temp .sector_start && partition .sector_end <=partition_temp .sector_end && partition.inside_extended == partition_temp.inside_extended ) - { this->set_cursor( (Gtk::TreePath) row); return; } + if ( partition .sector_start >= partition_temp .sector_start && + partition .sector_end <=partition_temp .sector_end && + partition.inside_extended == partition_temp.inside_extended ) + { + this ->set_cursor( (Gtk::TreePath) row ); + return; + } //logicals - if ( row.children().size() > 0 ) //this is the row with the extended partition, search it's childrows... + if ( row .children( ) .size( ) > 0 ) //this is the row with the extended partition, search it's childrows... { - for(iter_child = row.children().begin();iter_child != row.children().end();iter_child++ ) + for( iter_child = row .children( ) .begin( ) ; iter_child != row.children( ) .end( ) ; iter_child++ ) { childrow = *iter_child; - partition_temp = childrow[treeview_detail_columns.partition_struct] ; + partition_temp = childrow[ treeview_detail_columns.partition_struct ] ; - if ( partition .sector_start >= partition_temp .sector_start && partition .sector_end <= partition_temp.sector_end ) + if ( partition .sector_start >= partition_temp .sector_start && partition .sector_end <= partition_temp .sector_end ) { - this->expand_all(); - this->set_cursor( (Gtk::TreePath) childrow); + this ->expand_all( ); + this ->set_cursor( (Gtk::TreePath) childrow ); return; } } @@ -127,54 +132,54 @@ void TreeView_Detail::Set_Selected( const Partition & partition ) } -void TreeView_Detail::Create_Row( const Gtk::TreeRow & treerow, Partition & partition ) +void TreeView_Detail::Create_Row( const Gtk::TreeRow & treerow, const Partition & partition ) { //hereby i assume these 2 are mutual exclusive. is this wise?? Time (and bugreports) will tell :) - if ( partition.busy ) - treerow[treeview_detail_columns.status_icon] = render_icon(Gtk::Stock::DIALOG_AUTHENTICATION, Gtk::ICON_SIZE_BUTTON); - else if ( partition.filesystem == "unknown" || partition .error != "" ) - treerow[treeview_detail_columns.status_icon] = render_icon(Gtk::Stock::DIALOG_WARNING, Gtk::ICON_SIZE_BUTTON); + if ( partition .busy ) + treerow[ treeview_detail_columns .status_icon ] = render_icon( Gtk::Stock::DIALOG_AUTHENTICATION, Gtk::ICON_SIZE_BUTTON ); + else if ( partition .filesystem == "unknown" || partition .error != "" ) + treerow[ treeview_detail_columns .status_icon ] = render_icon( Gtk::Stock::DIALOG_WARNING, Gtk::ICON_SIZE_BUTTON ); - treerow[treeview_detail_columns.partition] = partition.partition; - treerow[treeview_detail_columns.color] = Get_Color( partition .filesystem ) ; + treerow[ treeview_detail_columns .partition ] = partition .partition; + treerow[ treeview_detail_columns .color ] = Get_Color( partition .filesystem ) ; - partition .type == GParted::UNALLOCATED ? treerow[treeview_detail_columns.text_color] = "darkgrey" : treerow[treeview_detail_columns.text_color] = "black" ; - treerow[treeview_detail_columns.type] = partition.filesystem ; + treerow[ treeview_detail_columns .text_color ] = ( partition .type == GParted::UNALLOCATED ) ? "darkgrey" : "black" ; + treerow[ treeview_detail_columns .type ] = partition .filesystem ; treerow[ treeview_detail_columns .type_square ] = "██" ; //size - treerow[treeview_detail_columns.size] = num_to_str( partition .Get_Length_MB() ) ; + treerow[ treeview_detail_columns .size ] = num_to_str( partition .Get_Length_MB( ) ) ; //used - if ( partition.sectors_used != -1 ) - treerow[treeview_detail_columns.used] = num_to_str( partition .Get_Used_MB() ) ; + if ( partition .sectors_used != -1 ) + treerow[ treeview_detail_columns .used ] = num_to_str( partition .Get_Used_MB( ) ) ; else - treerow[treeview_detail_columns.used] = "---" ; + treerow[ treeview_detail_columns .used ] = "---" ; //unused if ( partition .sectors_unused != -1 ) - treerow[treeview_detail_columns.unused] = num_to_str(partition .Get_Unused_MB() ) ; + treerow[ treeview_detail_columns .unused ] = num_to_str( partition .Get_Unused_MB( ) ) ; else - treerow[treeview_detail_columns.unused] = "---" ; + treerow[ treeview_detail_columns .unused ] = "---" ; //flags - treerow[treeview_detail_columns.flags] = " " + partition .flags ; + treerow[ treeview_detail_columns .flags ] = " " + partition .flags ; //hidden column (partition object) - treerow[treeview_detail_columns.partition_struct] = partition; + treerow[ treeview_detail_columns .partition_struct ] = partition; } -bool TreeView_Detail::on_button_press_event(GdkEventButton* event) +bool TreeView_Detail::on_button_press_event( GdkEventButton* event ) { //Call base class, to allow normal handling, - bool return_value = TreeView::on_button_press_event(event); + bool return_value = TreeView::on_button_press_event( event ); - iter = treeselection->get_selected(); + iter = treeselection ->get_selected( ); if ( *iter != 0 ) { row = *iter; - signal_mouse_click.emit( event, row[treeview_detail_columns.partition_struct] ); + signal_mouse_click .emit( event, row[ treeview_detail_columns .partition_struct ] ); } return return_value; diff --git a/src/VBox_VisualDisk.cc b/src/VBox_VisualDisk.cc index b0711484..21989f17 100644 --- a/src/VBox_VisualDisk.cc +++ b/src/VBox_VisualDisk.cc @@ -20,7 +20,7 @@ namespace GParted { -VBox_VisualDisk::VBox_VisualDisk( const std::vector & partitions, const Sector device_length) +VBox_VisualDisk::VBox_VisualDisk( const std::vector & partitions, const Sector device_length ) { this ->partitions = partitions ; this ->device_length = device_length ; @@ -28,8 +28,8 @@ VBox_VisualDisk::VBox_VisualDisk( const std::vector & partitions, con selected_partition = -1; //create frame which contains the visual disk - frame_disk_legend = manage( new Gtk::Frame() ) ; - frame_disk_legend ->set_shadow_type(Gtk::SHADOW_ETCHED_OUT); + frame_disk_legend = manage( new Gtk::Frame( ) ) ; + frame_disk_legend ->set_shadow_type( Gtk::SHADOW_ETCHED_OUT ); frame_disk_legend ->set_border_width( 5 ); hbox_disk_main.pack_start( *frame_disk_legend, Gtk::PACK_EXPAND_PADDING ); @@ -41,9 +41,9 @@ VBox_VisualDisk::VBox_VisualDisk( const std::vector & partitions, con this->pack_start( hbox_disk_main, Gtk::PACK_SHRINK ); //set and allocated some standard colors - color_used.set( "#F8F8BA" ); this ->get_colormap() ->alloc_color( color_used ) ;//bleach yellow ;) - color_unused.set( "white" ); this ->get_colormap() ->alloc_color( color_unused ) ; - color_text.set( "black" ); this ->get_colormap() ->alloc_color( color_text ) ; + color_used.set( "#F8F8BA" ); this ->get_colormap( ) ->alloc_color( color_used ) ;//bleach yellow ;) + color_unused.set( "white" ); this ->get_colormap( ) ->alloc_color( color_unused ) ; + color_text.set( "black" ); this ->get_colormap( ) ->alloc_color( color_text ) ; //since disksegments have minimal sizes ( unallocated 15 and partitions 20 pixels ) i do some checking to prevent the visual disk from growing to much @@ -51,7 +51,7 @@ VBox_VisualDisk::VBox_VisualDisk( const std::vector & partitions, con double width, extra_pixels = 0 ; - for ( unsigned int t=0; tSCREEN_WIDTH -= ( (partitions .size() -1) *5 ) ; + this ->SCREEN_WIDTH -= ( (partitions .size( ) -1) *5 ) ; //create hbox_disk and add to frame - hbox_disk = manage( new Gtk::HBox() ) ; + hbox_disk = manage( new Gtk::HBox( ) ) ; hbox_disk ->set_spacing( 5 ); frame_disk_legend ->add( *hbox_disk ); //walk through all partitions.... - for ( unsigned int i=0;ipack_start( *( visual_partitions.back() ->drawingarea), Gtk::PACK_SHRINK ) ; + if ( partitions[ i ].type != GParted::EXTENDED ) + hbox_disk ->pack_start( *( visual_partitions .back( ) ->drawingarea ), Gtk::PACK_SHRINK ) ; } - this ->show_all_children() ; + this ->show_all_children( ) ; } -void VBox_VisualDisk::Create_Visual_Partition( Partition & partition ) +void VBox_VisualDisk::Create_Visual_Partition( const Partition & partition ) { int x,y;//for pango_layout check - visual_partition = new Visual_Partition() ; - visual_partitions.push_back( visual_partition ) ; - visual_partitions.back() ->index = visual_partitions .size() -1 ; // <---- BELACHELIJK!! DOE DAAR IETS AAN!!! - visual_partitions.back() ->sector_start = partition .sector_start ; + visual_partition = new Visual_Partition( ) ; + visual_partitions .push_back( visual_partition ) ; + visual_partitions .back( ) ->index = visual_partitions .size( ) -1 ; // <---- BELACHELIJK!! DOE DAAR IETS AAN!!! + visual_partitions .back( ) ->sector_start = partition .sector_start ; if ( partition .type == GParted::EXTENDED ) { - visual_partitions.back() ->drawingarea = NULL ;//it's just a dummy ;-) ( see Set_Selected() ) - visual_partitions.back() ->length = 0 ; //keeps total_length clean + visual_partitions.back( ) ->drawingarea = NULL ;//it's just a dummy ;-) ( see Set_Selected() ) + visual_partitions.back( ) ->length = 0 ; //keeps total_length clean - eventbox_extended = manage( new Gtk::EventBox() ) ; + eventbox_extended = manage( new Gtk::EventBox( ) ) ; eventbox_extended ->set_size_request( -1, 60 ); - eventbox_extended ->modify_bg( eventbox_extended ->get_state(), partition .color ); + eventbox_extended ->modify_bg( eventbox_extended ->get_state( ), partition .color ); hbox_disk ->pack_start( *eventbox_extended, Gtk::PACK_SHRINK ) ; - hbox_extended = manage( new Gtk::HBox() ) ; + hbox_extended = manage( new Gtk::HBox( ) ) ; hbox_extended ->set_border_width( 5 ); hbox_extended ->set_spacing( 5 ); eventbox_extended ->add( *hbox_extended ) ; - for ( unsigned int t=0;tpack_start( *( visual_partitions.back() ->drawingarea), Gtk::PACK_SHRINK ) ; + hbox_extended ->pack_start( *( visual_partitions .back( ) ->drawingarea ), Gtk::PACK_SHRINK ) ; } return ; } - visual_partitions.back() ->length = (int) (SCREEN_WIDTH / (double) ( device_length / (double) ( partition .sector_end - partition .sector_start) ) ); - if ( visual_partitions.back() ->length < 20 )//we need a min. size. Otherwise some small partitions wouldn't be visible - partition .type == GParted::UNALLOCATED ? visual_partitions.back() ->length = 15 : visual_partitions.back() ->length = 20 ; + visual_partitions .back( ) ->length = (int) (SCREEN_WIDTH / (double) ( device_length / (double) ( partition .sector_end - partition .sector_start) ) ); + if ( visual_partitions .back( ) ->length < 20 )//we need a min. size. Otherwise some small partitions wouldn't be visible + visual_partitions .back( ) ->length = ( partition .type == GParted::UNALLOCATED ) ? 15 : 20 ; if ( partition .inside_extended ) - { visual_partitions.back() ->height = 34 ; visual_partitions.back() ->text_y = 9 ; } + { + visual_partitions .back( ) ->height = 34 ; + visual_partitions .back( ) ->text_y = 9 ; + } else - { visual_partitions.back() ->height = 44 ;visual_partitions.back() ->text_y = 15 ; } + { + visual_partitions .back( ) ->height = 44 ; + visual_partitions .back( ) ->text_y = 15 ; + } if ( partition .type == GParted::UNALLOCATED ) - visual_partitions.back() ->used = -1; + visual_partitions .back( ) ->used = -1; else - visual_partitions.back() ->used = (int) ( (visual_partitions.back() ->length - (BORDER *2)) / (double) ( ( partition .sector_end - partition .sector_start) / (double)partition .sectors_used ) ) ; + visual_partitions .back( ) ->used = (int) ( (visual_partitions .back( ) ->length - (BORDER *2)) / (double) ( ( partition .sector_end - partition .sector_start) / (double)partition .sectors_used ) ) ; - visual_partitions.back() ->color_fs = partition .color; - this ->get_colormap() ->alloc_color(visual_partitions.back() ->color_fs); + visual_partitions.back( ) ->color_fs = partition .color; + this ->get_colormap( ) ->alloc_color( visual_partitions .back( ) ->color_fs ); - visual_partitions.back() ->drawingarea = manage( new Gtk::DrawingArea() ) ; - visual_partitions.back() ->drawingarea ->set_size_request( visual_partitions.back() ->length +1, 60 ); - visual_partitions.back() ->drawingarea ->set_events(Gdk::BUTTON_PRESS_MASK); + visual_partitions .back( ) ->drawingarea = manage( new Gtk::DrawingArea( ) ) ; + visual_partitions .back( ) ->drawingarea ->set_size_request( visual_partitions .back( ) ->length +1, 60 ); + visual_partitions .back( ) ->drawingarea ->set_events( Gdk::BUTTON_PRESS_MASK ); //connect signal handlers - visual_partitions.back() ->drawingarea ->signal_button_press_event().connect( sigc::bind(sigc::mem_fun(*this, &VBox_VisualDisk::on_drawingarea_button_press), partition ) ); - visual_partitions.back() ->drawingarea ->signal_realize().connect( sigc::bind(sigc::mem_fun(*this, &VBox_VisualDisk::drawingarea_on_realize), visual_partitions.back() ) ); - visual_partitions.back() ->drawingarea ->signal_expose_event().connect( sigc::bind(sigc::mem_fun(*this, &VBox_VisualDisk::drawingarea_on_expose), visual_partitions.back() )); + visual_partitions .back( ) ->drawingarea ->signal_button_press_event( ) .connect( sigc::bind(sigc::mem_fun(*this, &VBox_VisualDisk::on_drawingarea_button_press), partition ) ); + visual_partitions .back( ) ->drawingarea ->signal_realize( ) .connect( sigc::bind(sigc::mem_fun(*this, &VBox_VisualDisk::drawingarea_on_realize), visual_partitions .back( ) ) ); + visual_partitions .back( ) ->drawingarea ->signal_expose_event( ) .connect( sigc::bind(sigc::mem_fun(*this, &VBox_VisualDisk::drawingarea_on_expose), visual_partitions .back( ) )); //create pangolayout and see if it fits in the visual partition - str_temp = partition .partition + "\n" + String::ucompose( _("%1 MB"), partition .Get_Length_MB() ) ; - visual_partitions.back() ->pango_layout = visual_partitions.back() ->drawingarea ->create_pango_layout ( str_temp ) ; + str_temp = partition .partition + "\n" + String::ucompose( _("%1 MB"), partition .Get_Length_MB( ) ) ; + visual_partitions .back( ) ->pango_layout = visual_partitions .back( ) ->drawingarea ->create_pango_layout ( str_temp ) ; - visual_partitions.back() ->pango_layout ->get_pixel_size( x, y ) ; - if ( visual_partitions.back() ->length - BORDER * 2 -2 < x ) - visual_partitions.back() ->pango_layout ->set_text( "" ) ; + visual_partitions .back( ) ->pango_layout ->get_pixel_size( x, y ) ; + if ( visual_partitions .back( ) ->length - BORDER * 2 -2 < x ) + visual_partitions .back( ) ->pango_layout ->set_text( "" ) ; //tooltip str_temp = "" ; if ( partition .type != GParted::UNALLOCATED ) str_temp = partition .filesystem + "\n" ; - str_temp += partition .partition + "\n" + String::ucompose( _("%1 MB"), partition .Get_Length_MB() ) ; - tooltips.set_tip( *(visual_partitions.back() ->drawingarea), str_temp ) ; + str_temp += partition .partition + "\n" + String::ucompose( _("%1 MB"), partition .Get_Length_MB( ) ) ; + tooltips .set_tip( *( visual_partitions.back( ) ->drawingarea ), str_temp ) ; } void VBox_VisualDisk::Prepare_Legend( std::vector & legend, const std::vector & partitions ) @@ -256,9 +262,9 @@ void VBox_VisualDisk::Set_Selected( const Partition & partition ) void VBox_VisualDisk::drawingarea_on_realize( Visual_Partition* vp ) { - vp ->gc = Gdk::GC::create( vp ->drawingarea ->get_window() ); + vp ->gc = Gdk::GC::create( vp ->drawingarea ->get_window( ) ); - vp ->drawingarea ->get_window() ->set_background( vp ->color_fs ); + vp ->drawingarea ->get_window( ) ->set_background( vp ->color_fs ); //eventmasks necessary for tooltips vp ->drawingarea ->add_events( Gdk::ENTER_NOTIFY_MASK ); vp ->drawingarea ->add_events( Gdk::LEAVE_NOTIFY_MASK ); @@ -267,25 +273,25 @@ void VBox_VisualDisk::drawingarea_on_realize( Visual_Partition* vp ) bool VBox_VisualDisk::drawingarea_on_expose( GdkEventExpose * ev, Visual_Partition* vp ) { - vp ->drawingarea ->get_window() ->clear() ; + vp ->drawingarea ->get_window( ) ->clear( ) ; if ( vp ->used != -1 ) //if not unknown or unallocated { vp ->gc ->set_foreground( color_used ); - vp ->drawingarea ->get_window() ->draw_rectangle( vp ->gc, true, BORDER,BORDER, vp ->used, vp ->height ); + vp ->drawingarea ->get_window( ) ->draw_rectangle( vp ->gc, true, BORDER, BORDER, vp ->used, vp ->height ); vp ->gc ->set_foreground( color_unused ); - vp ->drawingarea ->get_window() ->draw_rectangle( vp ->gc, true, BORDER + vp ->used, BORDER, vp ->length - vp ->used - BORDER *2 , vp ->height ); + vp ->drawingarea ->get_window( ) ->draw_rectangle( vp ->gc, true, BORDER + vp ->used, BORDER, vp ->length - vp ->used - BORDER *2 , vp ->height ); } vp ->gc ->set_foreground( color_text ); - vp ->drawingarea ->get_window() ->draw_layout( vp ->gc, BORDER +2, vp ->text_y, vp ->pango_layout ) ; + vp ->drawingarea ->get_window( ) ->draw_layout( vp ->gc, BORDER +2, vp ->text_y, vp ->pango_layout ) ; //if partition is selected one.. if ( vp ->index == selected_partition ) { vp ->gc ->set_foreground( color_used ); - vp ->drawingarea ->get_window() ->draw_rectangle( vp ->gc, false, 4,4,vp ->length-8, vp ->height +8 ); + vp ->drawingarea ->get_window( ) ->draw_rectangle( vp ->gc, false, 4, 4, vp ->length -8, vp ->height +8 ); } return true; @@ -293,24 +299,24 @@ bool VBox_VisualDisk::drawingarea_on_expose( GdkEventExpose * ev, Visual_Partiti bool VBox_VisualDisk::on_drawingarea_button_press( GdkEventButton *event, const Partition & partition ) { - signal_mouse_click.emit( event, partition ); + signal_mouse_click .emit( event, partition ); return true; } -VBox_VisualDisk::~VBox_VisualDisk() +VBox_VisualDisk::~VBox_VisualDisk( ) { - for ( unsigned int t=0;t< visual_partitions.size() ; t++ ) + for ( unsigned int t = 0 ; t < visual_partitions .size( ) ; t++ ) { - this ->get_colormap() ->free_colors( visual_partitions[t] ->color_fs, 1 ) ; - delete visual_partitions[t] ; + this ->get_colormap( ) ->free_colors( visual_partitions[ t ] ->color_fs, 1 ) ; + delete visual_partitions[ t ] ; } - visual_partitions.clear() ; + visual_partitions .clear( ) ; //free the allocated colors - this ->get_colormap() ->free_colors( color_used, 1 ) ; - this ->get_colormap() ->free_colors( color_unused, 1 ) ; - this ->get_colormap() ->free_colors( color_text, 1 ) ; + this ->get_colormap( ) ->free_colors( color_used, 1 ) ; + this ->get_colormap( ) ->free_colors( color_unused, 1 ) ; + this ->get_colormap( ) ->free_colors( color_text, 1 ) ; } diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index edb9d4f1..43fe7dc5 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -585,7 +585,7 @@ void Win_GParted::Set_Valid_Operations() allow_new( true ); //find out if there is a copied partition and if it fits inside this unallocated space - if ( copied_partition .partition != "NONE" && copied_partition .Get_Length_MB() < selected_partition .Get_Length_MB() ) + if ( copied_partition .partition != "NONE" && copied_partition .Get_Length_MB( ) < selected_partition .Get_Length_MB( ) ) allow_paste( true ) ; return ; @@ -611,7 +611,9 @@ void Win_GParted::Set_Valid_Operations() allow_resize( true ) ; //only allow copying of real partitions - if ( selected_partition .status != GParted::STAT_NEW && selected_partition .status != GParted::STAT_COPY ) + if ( selected_partition .status != GParted::STAT_NEW && + selected_partition .status != GParted::STAT_COPY && + Get_FS( selected_partition .filesystem, gparted_core .get_fs( ) ) .copy ) allow_copy( true ) ; } @@ -833,13 +835,13 @@ void Win_GParted::activate_resize() std::vector partitions = devices[ current_device ] .device_partitions ; - if ( operations.size() ) - for (unsigned int t=0;t/dev/null 2>/dev/null" ) ) + fs .read = true ; + + if ( ! system( "which mkfs.ext2 1>/dev/null 2>/dev/null" ) ) + fs .create = true ; + + if ( ! system( "which e2fsck 1>/dev/null 2>/dev/null" ) ) + fs .check = true ; + + //resizing is a delicate process which requires 3 commands.. + if ( ! system( "which resize2fs 1>/dev/null 2>/dev/null" ) && fs .read && fs .check ) + fs .resize = true ; + + if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) + fs .copy = true ; return fs ; } -bool ext2::Create( const Glib::ustring device_path, const Partition & new_partition ) +void ext2::Set_Used_Sectors( Partition & partition ) { - bool return_value = false ; + char c_buf[ 512 ] ; + FILE *f ; - if ( open_device_and_disk( device_path, device, disk ) ) - { - PedPartition *c_part = NULL ; - PedFileSystemType *fs_type = NULL ; - PedFileSystem *fs = NULL ; + Glib::ustring output ; + Sector free_blocks = -1, blocksize = -1 ; + + //get free blocks.. + f = popen( ( "dumpe2fs -h " + partition .partition ) .c_str( ), "r" ) ; + while ( fgets( c_buf, 512, f ) ) + { + output = Glib::locale_to_utf8( c_buf ) ; - c_part = ped_disk_get_partition_by_sector( disk, (new_partition .sector_end + new_partition .sector_start) / 2 ) ; - if ( c_part ) - { - fs_type = ped_file_system_type_get( "ext2" ) ; - if ( fs_type ) - { - fs = ped_file_system_create( & c_part ->geom, fs_type, NULL ); - if ( fs ) - { - if ( ped_partition_set_system( c_part, fs_type ) ) - return_value = Commit( disk ) ; - - ped_file_system_close( fs ); - } - } - } + //free blocks + if ( output .find( "Free blocks" ) < output .length( ) ) + free_blocks = atoi( (output .substr( output .find( ":" ) +1, output .length( ) ) ) .c_str( ) ) ; + + //blocksize + if ( output .find( "Block size:" ) < output .length( ) ) + blocksize = atoi( (output .substr( output .find( ":" ) +1, output .length( ) ) ) .c_str( ) ) ; - close_device_and_disk( device, disk ) ; } - - return return_value ; + pclose( f ) ; + + if ( free_blocks > -1 && blocksize > -1 ) + partition .Set_Unused( free_blocks * blocksize / 512 ) ; } -bool ext2::Resize( const Glib::ustring device_path, const Partition & partition_old, const Partition & partition_new ) +bool ext2::Create( const Glib::ustring device_path, const Partition & new_partition ) { - bool return_value = false ; + return Execute_Command( "mkfs.ext2 " + new_partition .partition ) ; +} + +bool ext2::Resize( const Partition & partition_new, bool fill_partition ) +{ + Glib::ustring str_temp = "resize2fs " + partition_new .partition ; - PedPartition *c_part = NULL ; - PedFileSystem *fs = NULL ; - PedConstraint *constraint = NULL ; + if ( ! fill_partition ) + str_temp += " " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size ) + "M" ; - if ( open_device_and_disk( device_path, device, disk ) ) - { - c_part = ped_disk_get_partition_by_sector( disk, (partition_old .sector_end + partition_old .sector_start) / 2 ) ; - if ( c_part ) - { - fs = ped_file_system_open ( & c_part->geom ); - if ( fs ) - { - constraint = ped_file_system_get_resize_constraint ( fs ); - if ( constraint ) - { - if ( ped_disk_set_partition_geom ( disk, c_part, constraint, partition_new .sector_start, partition_new .sector_end ) && - ped_file_system_resize ( fs, & c_part->geom, NULL ) ) - return_value = Commit( disk ) ; - - ped_constraint_destroy ( constraint ); - } - - ped_file_system_close ( fs ); - } - } - - close_device_and_disk( device, disk ) ; - } - - return return_value ; + return Execute_Command( str_temp ) ; } bool ext2::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) @@ -106,9 +94,14 @@ bool ext2::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest return Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; } +bool ext2::Check_Repair( const Partition & partition ) +{ + return Execute_Command( "e2fsck -fy " + partition .partition ) ; +} + int ext2::get_estimated_time( long MB_to_Consider ) { - return 1 + MB_to_Consider / 500 ; + return -1 ; } diff --git a/src/ext3.cc b/src/ext3.cc index 51af6b45..d5c0651f 100644 --- a/src/ext3.cc +++ b/src/ext3.cc @@ -26,89 +26,67 @@ FS ext3::get_filesystem_support( ) FS fs ; fs .filesystem = "ext3" ; + if ( ! system( "which dumpe2fs 1>/dev/null 2>/dev/null" ) ) + fs .read = true ; - if ( ! system( "which tune2fs 1>/dev/null 2>/dev/null" ) ) + if ( ! system( "which mkfs.ext3 1>/dev/null 2>/dev/null" ) ) fs .create = true ; - fs .resize = true ; - + if ( ! system( "which e2fsck 1>/dev/null 2>/dev/null" ) ) + fs .check = true ; + + //resizing is a delicate process which requires 3 commands.. + if ( ! system( "which resize2fs 1>/dev/null 2>/dev/null" ) && fs .read && fs .check ) + fs .resize = true ; + + if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) + fs .copy = true ; + return fs ; } + +void ext3::Set_Used_Sectors( Partition & partition ) +{ + char c_buf[ 512 ] ; + FILE *f ; + + Glib::ustring output ; + Sector free_blocks = -1, blocksize = -1 ; + + //get free blocks.. + f = popen( ( "dumpe2fs -h " + partition .partition ) .c_str( ), "r" ) ; + while ( fgets( c_buf, 512, f ) ) + { + output = Glib::locale_to_utf8( c_buf ) ; + + //free blocks + if ( output .find( "Free blocks" ) < output .length( ) ) + free_blocks = atoi( (output .substr( output .find( ":" ) +1, output .length( ) ) ) .c_str( ) ) ; + + //blocksize + if ( output .find( "Block size:" ) < output .length( ) ) + blocksize = atoi( (output .substr( output .find( ":" ) +1, output .length( ) ) ) .c_str( ) ) ; + + } + pclose( f ) ; + + if ( free_blocks > -1 && blocksize > -1 ) + partition .Set_Unused( free_blocks * blocksize / 512 ) ; +} bool ext3::Create( const Glib::ustring device_path, const Partition & new_partition ) { - bool return_value = false ; - - if ( open_device_and_disk( device_path, device, disk ) ) - { - PedPartition *c_part = NULL ; - PedFileSystemType *fs_type = NULL ; - PedFileSystem *fs = NULL ; - - c_part = ped_disk_get_partition_by_sector( disk, (new_partition .sector_end + new_partition .sector_start) / 2 ) ; - if ( c_part ) - { - fs_type = ped_file_system_type_get( "ext2" ) ; - if ( fs_type ) - { - fs = ped_file_system_create( & c_part ->geom, fs_type, NULL ); - if ( fs ) - { - if ( ped_partition_set_system(c_part, fs_type ) ) - { - return_value = Commit( disk ) ; - - sleep( 1 ) ; - //system( ("tune2fs -j " + new_partition .partition) .c_str( ) ) ; - Execute_Command( "tune2fs -j " + new_partition .partition ) ; - - } - - ped_file_system_close( fs ); - } - } - } - - close_device_and_disk( device, disk) ; - } - - return return_value ; + return Execute_Command( "mkfs.ext3 " + new_partition .partition ) ; } -bool ext3::Resize( const Glib::ustring device_path, const Partition & partition_old, const Partition & partition_new ) +bool ext3::Resize( const Partition & partition_new, bool fill_partition ) { - bool return_value = false ; + Glib::ustring str_temp = "resize2fs " + partition_new .partition ; - PedPartition *c_part = NULL ; - PedFileSystem *fs = NULL ; - PedConstraint *constraint = NULL ; + if ( ! fill_partition ) + str_temp += " " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size ) + "M" ; - if ( open_device_and_disk( device_path, device, disk ) ) - { - c_part = ped_disk_get_partition_by_sector( disk, (partition_old .sector_end + partition_old .sector_start) / 2 ) ; - if ( c_part ) - { - fs = ped_file_system_open ( & c_part->geom ); - if ( fs ) - { - constraint = ped_file_system_get_resize_constraint ( fs ); - if ( constraint ) - { - if ( ped_disk_set_partition_geom ( disk, c_part, constraint, partition_new .sector_start, partition_new .sector_end ) && - ped_file_system_resize ( fs, & c_part->geom, NULL ) ) - return_value = Commit( disk ) ; - - ped_constraint_destroy ( constraint ); - } - - ped_file_system_close ( fs ); - } - } - - close_device_and_disk( device, disk ) ; - } - - return return_value ; + return Execute_Command( str_temp ) ; } bool ext3::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) @@ -116,9 +94,14 @@ bool ext3::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest return Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; } +bool ext3::Check_Repair( const Partition & partition ) +{ + return Execute_Command( "e2fsck -fy " + partition .partition ) ; +} + int ext3::get_estimated_time( long MB_to_Consider ) { - return 1 + MB_to_Consider / 400 ; + return -1 ; } } //GParted diff --git a/src/fat16.cc b/src/fat16.cc index e0e9659b..047301e5 100644 --- a/src/fat16.cc +++ b/src/fat16.cc @@ -26,12 +26,45 @@ FS fat16::get_filesystem_support( ) FS fs ; fs .filesystem = "fat16" ; + fs .read = true ; //provided by libparted fs .create = true ; fs .resize = true ; fs .move = true ; + if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) + fs .copy = true ; + return fs ; } + +void fat16::Set_Used_Sectors( Partition & partition ) +{ + PedFileSystem *fs = NULL; + PedConstraint *constraint = NULL; + PedPartition *c_part = NULL ; + + if ( disk ) + { + c_part = ped_disk_get_partition_by_sector( disk, (partition .sector_end + partition .sector_start) / 2 ) ; + if ( c_part ) + { + fs = ped_file_system_open( & c_part ->geom ); + + if ( fs ) + { + constraint = ped_file_system_get_resize_constraint ( fs ) ; + if ( constraint ) + { + partition .Set_Unused( (partition .sector_end - partition .sector_start) - constraint ->min_size ) ; + + ped_constraint_destroy ( constraint ); + } + + ped_file_system_close( fs ) ; + } + } + } +} bool fat16::Create( const Glib::ustring device_path, const Partition & new_partition ) { @@ -66,40 +99,10 @@ bool fat16::Create( const Glib::ustring device_path, const Partition & new_parti return return_value ; } -bool fat16::Resize( const Glib::ustring device_path, const Partition & partition_old, const Partition & partition_new ) +bool fat16::Resize( const Partition & partition_new, bool fill_partition ) { - bool return_value = false ; - - PedPartition *c_part = NULL ; - PedFileSystem *fs = NULL ; - PedConstraint *constraint = NULL ; - - if ( open_device_and_disk( device_path, device, disk ) ) - { - c_part = ped_disk_get_partition_by_sector( disk, (partition_old .sector_end + partition_old .sector_start) / 2 ) ; - if ( c_part ) - { - fs = ped_file_system_open ( & c_part->geom ); - if ( fs ) - { - constraint = ped_file_system_get_resize_constraint ( fs ); - if ( constraint ) - { - if ( ped_disk_set_partition_geom ( disk, c_part, constraint, partition_new .sector_start, partition_new .sector_end ) && - ped_file_system_resize ( fs, & c_part->geom, NULL ) ) - return_value = Commit( disk ) ; - - ped_constraint_destroy ( constraint ); - } - - ped_file_system_close ( fs ); - } - } - - close_device_and_disk( device, disk) ; - } - - return return_value ; + //handled in GParted_Core::Resize_Normal_Using_Libparted + return false ; } bool fat16::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) @@ -107,9 +110,14 @@ bool fat16::Copy( const Glib::ustring & src_part_path, const Glib::ustring & des return Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; } +bool fat16::Check_Repair( const Partition & partition ) +{ + return false ; +} + int fat16::get_estimated_time( long MB_to_Consider ) { - return 1 ; + return -1 ; } } //GParted diff --git a/src/fat32.cc b/src/fat32.cc index e7123d3e..68b95c05 100644 --- a/src/fat32.cc +++ b/src/fat32.cc @@ -26,6 +26,7 @@ FS fat32::get_filesystem_support( ) FS fs ; fs .filesystem = "fat32" ; + fs .read = true ; //provided by libparted //find out if we can create fat32 filesystems if ( ! system( "which mkdosfs 1>/dev/null 2>/dev/null" ) ) @@ -35,48 +36,50 @@ FS fat32::get_filesystem_support( ) fs .resize = true ; fs .move = true ; + if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) + fs .copy = true ; + return fs ; } +void fat32::Set_Used_Sectors( Partition & partition ) +{ + PedFileSystem *fs = NULL; + PedConstraint *constraint = NULL; + PedPartition *c_part = NULL ; + + if ( disk ) + { + c_part = ped_disk_get_partition_by_sector( disk, (partition .sector_end + partition .sector_start) / 2 ) ; + if ( c_part ) + { + fs = ped_file_system_open( & c_part ->geom ); + + if ( fs ) + { + constraint = ped_file_system_get_resize_constraint ( fs ) ; + if ( constraint ) + { + partition .Set_Unused( (partition .sector_end - partition .sector_start) - constraint ->min_size ) ; + + ped_constraint_destroy ( constraint ); + } + + ped_file_system_close( fs ) ; + } + } + } +} + bool fat32::Create( const Glib::ustring device_path, const Partition & new_partition ) { return Execute_Command( "mkdosfs -F32 " + new_partition .partition ) ; } -bool fat32::Resize( const Glib::ustring device_path, const Partition & partition_old, const Partition & partition_new ) +bool fat32::Resize( const Partition & partition_new, bool fill_partition ) { - bool return_value = false ; - - PedPartition *c_part = NULL ; - PedFileSystem *fs = NULL ; - PedConstraint *constraint = NULL ; - - if ( open_device_and_disk( device_path, device, disk ) ) - { - c_part = ped_disk_get_partition_by_sector( disk, (partition_old .sector_end + partition_old .sector_start) / 2 ) ; - if ( c_part ) - { - fs = ped_file_system_open ( & c_part->geom ); - if ( fs ) - { - constraint = ped_file_system_get_resize_constraint ( fs ); - if ( constraint ) - { - if ( ped_disk_set_partition_geom ( disk, c_part, constraint, partition_new .sector_start, partition_new .sector_end ) && - ped_file_system_resize ( fs, & c_part->geom, NULL ) ) - return_value = Commit( disk ) ; - - ped_constraint_destroy ( constraint ); - } - - ped_file_system_close ( fs ); - } - } - - close_device_and_disk( device, disk) ; - } - - return return_value ; + //handled in GParted_Core::Resize_Normal_Using_Libparted + return false ; } bool fat32::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) @@ -84,9 +87,14 @@ bool fat32::Copy( const Glib::ustring & src_part_path, const Glib::ustring & des return Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; } +bool fat32::Check_Repair( const Partition & partition ) +{ + return false ; +} + int fat32::get_estimated_time( long MB_to_Consider ) { - return 1 + MB_to_Consider / 5000 ; + return -1 ; } diff --git a/src/linux_swap.cc b/src/linux_swap.cc index 4856b330..1dca860b 100644 --- a/src/linux_swap.cc +++ b/src/linux_swap.cc @@ -26,13 +26,21 @@ FS linux_swap::get_filesystem_support( ) FS fs ; fs .filesystem = "linux-swap" ; + fs .read = false ; //used/unused isn't relevant for swapspace fs .create = true ; fs .resize = true ; fs .move = true ; + if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) + fs .copy = true ; + return fs ; } +void linux_swap::Set_Used_Sectors( Partition & partition ) +{ +} + bool linux_swap::Create( const Glib::ustring device_path, const Partition & new_partition ) { bool return_value = false ; @@ -66,40 +74,10 @@ bool linux_swap::Create( const Glib::ustring device_path, const Partition & new_ return return_value ; } -bool linux_swap::Resize( const Glib::ustring device_path, const Partition & partition_old, const Partition & partition_new ) +bool linux_swap::Resize( const Partition & partition_new, bool fill_partition ) { - bool return_value = false ; - - PedPartition *c_part = NULL ; - PedFileSystem *fs = NULL ; - PedConstraint *constraint = NULL ; - - if ( open_device_and_disk( device_path, device, disk ) ) - { - c_part = ped_disk_get_partition_by_sector( disk, (partition_old .sector_end + partition_old .sector_start) / 2 ) ; - if ( c_part ) - { - fs = ped_file_system_open ( & c_part->geom ); - if ( fs ) - { - constraint = ped_file_system_get_resize_constraint ( fs ); - if ( constraint ) - { - if ( ped_disk_set_partition_geom ( disk, c_part, constraint, partition_new .sector_start, partition_new .sector_end ) && - ped_file_system_resize ( fs, & c_part->geom, NULL ) ) - return_value = Commit( disk ) ; - - ped_constraint_destroy ( constraint ); - } - - ped_file_system_close ( fs ); - } - } - - close_device_and_disk( device, disk ) ; - } - - return return_value ; + //handled in GParted_Core::Resize_Normal_Using_Libparted + return false ; } bool linux_swap::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) @@ -107,6 +85,11 @@ bool linux_swap::Copy( const Glib::ustring & src_part_path, const Glib::ustring return Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; } +bool linux_swap::Check_Repair( const Partition & partition ) +{ + return false ; +} + int linux_swap::get_estimated_time( long MB_to_Consider ) { return 1 + MB_to_Consider / 5000 ; diff --git a/src/reiserfs.cc b/src/reiserfs.cc index 75c38985..62b6138c 100644 --- a/src/reiserfs.cc +++ b/src/reiserfs.cc @@ -30,6 +30,7 @@ FS reiserfs::get_filesystem_support( ) static void * test_handle = NULL ; if ( (test_handle = dlopen("libreiserfs.so", RTLD_NOW)) ) { + fs .read = true ; fs .create = true ; fs .resize = true ; @@ -37,8 +38,40 @@ FS reiserfs::get_filesystem_support( ) test_handle = NULL ; } + if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) + fs .copy = true ; + return fs ; } + +void reiserfs::Set_Used_Sectors( Partition & partition ) +{ + PedFileSystem *fs = NULL; + PedConstraint *constraint = NULL; + PedPartition *c_part = NULL ; + + if ( disk ) + { + c_part = ped_disk_get_partition_by_sector( disk, (partition .sector_end + partition .sector_start) / 2 ) ; + if ( c_part ) + { + fs = ped_file_system_open( & c_part ->geom ); + + if ( fs ) + { + constraint = ped_file_system_get_resize_constraint ( fs ) ; + if ( constraint ) + { + partition .Set_Unused( (partition .sector_end - partition .sector_start) - constraint ->min_size ) ; + + ped_constraint_destroy ( constraint ); + } + + ped_file_system_close( fs ) ; + } + } + } +} bool reiserfs::Create( const Glib::ustring device_path, const Partition & new_partition ) { @@ -73,40 +106,9 @@ bool reiserfs::Create( const Glib::ustring device_path, const Partition & new_pa return return_value ; } -bool reiserfs::Resize( const Glib::ustring device_path, const Partition & partition_old, const Partition & partition_new ) +bool reiserfs::Resize( const Partition & partition_new, bool fill_partition ) { - bool return_value = false ; - - PedPartition *c_part = NULL ; - PedFileSystem *fs = NULL ; - PedConstraint *constraint = NULL ; - - if ( open_device_and_disk( device_path, device, disk ) ) - { - c_part = ped_disk_get_partition_by_sector( disk, (partition_old .sector_end + partition_old .sector_start) / 2 ) ; - if ( c_part ) - { - fs = ped_file_system_open ( & c_part->geom ); - if ( fs ) - { - constraint = ped_file_system_get_resize_constraint ( fs ); - if ( constraint ) - { - if ( ped_disk_set_partition_geom ( disk, c_part, constraint, partition_new .sector_start, partition_new .sector_end ) && - ped_file_system_resize ( fs, & c_part->geom, NULL ) ) - return_value = Commit( disk ) ; - - ped_constraint_destroy ( constraint ); - } - - ped_file_system_close ( fs ); - } - } - - close_device_and_disk( device, disk ) ; - } - - return return_value ; + return false ; } bool reiserfs::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) @@ -114,6 +116,11 @@ bool reiserfs::Copy( const Glib::ustring & src_part_path, const Glib::ustring & return Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; } +bool reiserfs::Check_Repair( const Partition & partition ) +{ + return false ; +} + int reiserfs::get_estimated_time( long MB_to_Consider ) { return 1 + MB_to_Consider / 1000 ;