From 828d7a9e5b926c91b509aad67c0ed2d5b5a2e592 Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Wed, 15 Feb 2006 16:05:26 +0000 Subject: [PATCH] wrap mount/umount/swapon/swapoff instead of implementing it ourselves * wrap mount/umount/swapon/swapoff instead of implementing it ourselves (#330641) * moved execute_command() to Utils and made the filesystems use it. All in all this decreased the size of the binary with 10% and made stuff more readable. --- ChangeLog | 8 +++ include/FileSystem.h | 7 +- include/Utils.h | 11 ++- include/Win_GParted.h | 4 +- src/FileSystem.cc | 59 +++------------- src/GParted_Core.cc | 1 + src/Utils.cc | 159 ++++++++++++++---------------------------- src/Win_GParted.cc | 80 +++++++++++---------- src/ext2.cc | 41 +++-------- src/ext3.cc | 44 ++++-------- src/fat16.cc | 34 ++------- src/fat32.cc | 34 ++------- src/hfs.cc | 15 ++-- src/jfs.cc | 84 +++++++++------------- src/linux_swap.cc | 22 +++--- src/ntfs.cc | 40 +++-------- src/reiser4.cc | 21 ++---- src/reiserfs.cc | 40 +++-------- src/xfs.cc | 104 +++++++++++---------------- 19 files changed, 266 insertions(+), 542 deletions(-) diff --git a/ChangeLog b/ChangeLog index fff4673e..7ab2fbc7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-02-15 Bart Hakvoort + + * wrap mount/umount/swapon/swapoff instead of implementing it + ourselves (#330641) + * moved execute_command() to Utils and made the filesystems use it. All + in all this decreased the size of the binary with 10% and made stuff + more readable. + 2006-02-11 Bart Hakvoort * removed legend after discussion with usability guys diff --git a/include/FileSystem.h b/include/FileSystem.h index 5170500f..16fae2bd 100644 --- a/include/FileSystem.h +++ b/include/FileSystem.h @@ -47,15 +47,12 @@ public: Sector cylinder_size ; //see GParted_Core::resize() protected: - int execute_command( std::vector argv, std::vector & operation_details ) ; - int execute_command( std::vector argv, std::string & output ) ; + int execute_command( const Glib::ustring & command, std::vector & operation_details ) ; //those are used in several places.. - std::vector argv ; - std::string output, error ; + Glib::ustring output, error ; Sector N, S ; unsigned int index ; - int exit_status ; private: diff --git a/include/Utils.h b/include/Utils.h index 142c152c..8e2a3f06 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -120,15 +120,12 @@ public: static Glib::ustring Get_Color( FILESYSTEM filesystem ) ; static Glib::RefPtr get_color_as_pixbuf( FILESYSTEM filesystem, int width, int height ) ; static Glib::ustring Get_Filesystem_String( FILESYSTEM filesystem ) ; - static bool mount( const Glib::ustring & node, - const Glib::ustring & mountpoint, - const Glib::ustring & filesystem, - Glib::ustring & error, - unsigned long flags = 0, - const Glib::ustring & data = "" ) ; - static bool unmount( const Glib::ustring & node, const Glib::ustring & mountpoint, Glib::ustring & error ) ; static Glib::ustring format_size( Sector size ) ; static double sector_to_unit( Sector sectors, SIZE_UNIT size_unit ) ; + static int execute_command( const Glib::ustring & command, + Glib::ustring & output, + Glib::ustring & error, + bool use_C_locale = false ) ; }; diff --git a/include/Win_GParted.h b/include/Win_GParted.h index 49e5af73..8ac7bc5e 100644 --- a/include/Win_GParted.h +++ b/include/Win_GParted.h @@ -114,8 +114,8 @@ private: //threads.. void thread_refresh_devices() ; - void thread_unmount_partition() ; - void thread_toggle_swap() ; + void thread_unmount_partition( bool * succes, Glib::ustring * error ) ; + void thread_toggle_swap( bool * succes, Glib::ustring * error ) ; //signal handlers void open_operationslist( ) ; diff --git a/src/FileSystem.cc b/src/FileSystem.cc index 487f0542..674f758f 100644 --- a/src/FileSystem.cc +++ b/src/FileSystem.cc @@ -25,63 +25,20 @@ FileSystem::FileSystem() { cylinder_size = 0 ; } - -int FileSystem::execute_command( std::vector argv, std::vector & operation_details ) + +int FileSystem::execute_command( const Glib::ustring & command, std::vector & operation_details ) { - Glib::ustring temp ; - for ( unsigned int t = 0 ; t < argv .size() ; t++ ) - temp += argv[ t ] + " " ; + operation_details .push_back( OperationDetails( "" + command + "", OperationDetails::NONE ) ) ; - operation_details .push_back( OperationDetails( "" + temp + "", OperationDetails::NONE ) ) ; + int exit_status = Utils::execute_command( command, output, error ) ; - try - { - Glib::spawn_sync( ".", - argv, - Glib::SPAWN_SEARCH_PATH, - sigc::slot< void >(), - &output, - &error, - &exit_status ) ; - } - catch ( Glib::Exception & e ) - { - if ( ! e .what() .empty() ) - operation_details .back() .sub_details .push_back( OperationDetails( e .what(), OperationDetails::NONE ) ) ; - - return -1 ; - } - if ( ! output .empty() ) - operation_details .back() .sub_details .push_back( OperationDetails( "" + output + "", OperationDetails::NONE ) ) ; + operation_details .back() .sub_details .push_back( + OperationDetails( "" + output + "", OperationDetails::NONE ) ) ; if ( ! error .empty() ) - operation_details .back() .sub_details .push_back( OperationDetails( "" + error + "", OperationDetails::NONE ) ) ; - - return exit_status ; -} - -int FileSystem::execute_command( std::vector argv, std::string & output ) -{ - std::vector envp ; - envp .push_back( "LC_ALL=C" ) ; - envp .push_back( "PATH=" + Glib::getenv( "PATH" ) ) ; - - try - { - Glib::spawn_sync( ".", - argv, - envp, - Glib::SPAWN_SEARCH_PATH, - sigc::slot(), - &output, - &error, //dummy - &exit_status) ; - } - catch ( Glib::Exception & e ) - { - std::cout << e .what() << std::endl ; - } + operation_details .back() .sub_details .push_back( + OperationDetails( "" + error + "", OperationDetails::NONE ) ) ; return exit_status ; } diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index c157218a..625eb061 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -603,6 +603,7 @@ bool GParted_Core::resize( const Device & device, return resize_container_partition( partition_old, partition_new, false, operation_details ) ; //resize using libparted.. + //FIXME: let's add some checks before and after calling resize_normal_using_libparted() if ( get_fs( partition_old .filesystem ) .grow == GParted::FS::LIBPARTED ) return resize_normal_using_libparted( partition_old, partition_new, operation_details ) ; diff --git a/src/Utils.cc b/src/Utils.cc index 516706b3..7acbc6e7 100644 --- a/src/Utils.cc +++ b/src/Utils.cc @@ -18,10 +18,7 @@ #include "../include/Utils.h" #include -#include -#include #include -#include namespace GParted { @@ -132,109 +129,6 @@ Glib::ustring Utils::Get_Filesystem_String( FILESYSTEM filesystem ) } } -bool Utils::mount( const Glib::ustring & node, - const Glib::ustring & mountpoint, - const Glib::ustring & filesystem, - Glib::ustring & error, - unsigned long flags, - const Glib::ustring & data ) -{ - if ( ! ::mount( node .c_str(), mountpoint .c_str(), filesystem .c_str(), flags, data .c_str() ) ) - { - std::ifstream proc_mounts( "/proc/mounts" ) ; - - if ( proc_mounts ) - { - bool hit = false ; - char c_node[255] ; - std::string line ; - - //search for relevant line in /proc/mounts - while ( getline( proc_mounts, line ) ) - { - if ( line .length() > 0 && line[ 0 ] == '/' && - sscanf( line .c_str(),"%255s", c_node ) == 1 && - c_node == node ) - { - hit = true ; - break ; - } - } - - proc_mounts .close() ; - - //append 'line' to /etc/mtab - if ( hit ) - { - std::ofstream mtab( "/etc/mtab", std::ios::app ) ; - - if ( mtab ) - { - mtab << line << '\n' ; - mtab .close() ; - - return true ; - } - } - - //something went wrong while adding the line to mtab - umount( mountpoint .c_str() ) ; - } - } - else - error = Glib::strerror( errno ) ; - - - return false ; -} - -bool Utils::unmount( const Glib::ustring & node, const Glib::ustring & mountpoint, Glib::ustring & error ) -{ - //FIXME this function should only accept 'node' and unmount _all_ mounts of that node - if ( ! umount( mountpoint .c_str() ) ) - { - //search in /etc/mtab for node and delete that line - Glib::ustring mtab_minus_mount ; - bool hit = false ; - - std::ifstream mtab_in( "/etc/mtab" ) ; - if ( mtab_in ) - { - char c_node[255] ; - std::string line ; - - while ( getline( mtab_in, line ) ) - { - if ( line .length() > 0 && line[ 0 ] == '/' && - sscanf( line .c_str(),"%255s", c_node ) == 1 && - c_node == node ) - hit = true ; - else - mtab_minus_mount += line + '\n'; - } - - mtab_in .close() ; - } - - if ( hit ) - { - std::ofstream mtab_out( "/etc/mtab" ) ; - if ( mtab_out ) - { - mtab_out << mtab_minus_mount ; - mtab_out .close() ; - - return true ; - } - } - } - else - error = Glib::strerror( errno ) ; - - - return false ; -} - Glib::ustring Utils::format_size( Sector size ) { std::stringstream ss ; @@ -292,4 +186,57 @@ double Utils::sector_to_unit( Sector sectors, SIZE_UNIT size_unit ) } } +int Utils::execute_command( const Glib::ustring & command, + Glib::ustring & output, + Glib::ustring & error, + bool use_C_locale ) +{ + int exit_status = -1 ; + std::string std_out, std_error ; + + try + { + if ( use_C_locale ) + { + std::vector envp, argv; + envp .push_back( "LC_ALL=C" ) ; + envp .push_back( "PATH=" + Glib::getenv( "PATH" ) ) ; + + argv .push_back( "sh" ) ; + argv .push_back( "-c" ) ; + argv .push_back( command ) ; + + Glib::spawn_sync( ".", + argv, + envp, + Glib::SPAWN_SEARCH_PATH, + sigc::slot(), + &std_out, + &std_error, + &exit_status ) ; + } + else + { + Glib::spawn_command_line_sync( "sh -c '" + command + "'", + &std_out, + &std_error, + &exit_status ) ; + } + } + catch ( Glib::Exception & e ) + { + error = e .what() ; + + //spit exceptions to stdout.. + std::cout << error << std::endl ; + + return -1 ; + } + + output = std_out ; + error = std_error ; + + return exit_status ; +} + } //GParted.. diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index 7ba80599..d60ef0ae 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -251,11 +251,11 @@ void Win_GParted::init_partition_menu( ) menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ); menu_partition .items() .push_back( - Gtk::Menu_Helpers::MenuElem( _("Unmount"), + Gtk::Menu_Helpers::MenuElem( _("unmount"), sigc::mem_fun( *this, &Win_GParted::activate_unmount ) ) ); menu_partition .items() .push_back( - Gtk::Menu_Helpers::MenuElem( _("Deactivate"), + Gtk::Menu_Helpers::MenuElem( _("swapoff"), sigc::mem_fun( *this, &Win_GParted::activate_toggle_swap ) ) ); menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ); @@ -675,7 +675,7 @@ void Win_GParted::set_valid_operations( ) allow_paste( false ); allow_format( false ); allow_unmount( false ) ; allow_info( false ) ; allow_toggle_swap( false ) ; - dynamic_cast(menu_partition .items()[ 11 ] .get_child() ) ->set_label( _("Deactivate") ) ; + dynamic_cast(menu_partition .items()[ 11 ] .get_child() ) ->set_label( _("swapoff") ) ; //no partition selected... if ( selected_partition .partition .empty() ) @@ -693,7 +693,7 @@ void Win_GParted::set_valid_operations( ) return ; else dynamic_cast(menu_partition .items()[ 11 ] .get_child() ) - ->set_label( _("Activate") ) ; + ->set_label( _("swapon") ) ; } //only unmount is allowed @@ -773,19 +773,23 @@ void Win_GParted::open_operationslist( ) void Win_GParted::close_operationslist( ) { +//FIXME: when started like 'gparted bla' it wil crash in this function +//most likely this has something to do with the removal of the legend which rendered +//the '210' incorrect. This static numbering sucks anyway, so i should find a way to open and +//close the operationslist without these static numbers. See also open_operationslist() int x,y; this ->get_size( x, y ); y -= 210 ; //height of whole app - menubar - visualdisk - statusbar .... - for ( int t = vpaned_main .get_position( ) ; t < y ; t+=5 ) + for ( int t = vpaned_main .get_position() ; t < y ; t+=5 ) { vpaned_main .set_position( t ); - while ( Gtk::Main::events_pending( ) ) - Gtk::Main::iteration( ); + while ( Gtk::Main::events_pending() ) + Gtk::Main::iteration(); } - hbox_operations .hide( ) ; + hbox_operations .hide() ; static_cast( - & menubar_main .items( ) [ 2 ] .get_submenu( ) -> - items() [ 1 ] ) ->set_active( false ) ; + & menubar_main .items()[ 2 ] .get_submenu() -> + items()[ 1 ] ) ->set_active( false ) ; } void Win_GParted::clear_operationslist() @@ -876,7 +880,7 @@ void Win_GParted::menu_gparted_refresh_devices( ) //if no devices were detected we disable some stuff and show a message in the statusbar if ( devices .empty() ) - { + { this ->set_title( _("GParted") ); combo_devices .hide() ; @@ -902,7 +906,6 @@ void Win_GParted::menu_gparted_refresh_devices( ) statusbar .pop() ; statusbar .push( _( "No devices detected" ) ); } - else //at least one device detected { combo_devices .show() ; @@ -1341,64 +1344,67 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs ) Add_Operation( GParted::FORMAT, part_temp ) ; } -void Win_GParted::thread_unmount_partition() +void Win_GParted::thread_unmount_partition( bool * succes, Glib::ustring * error ) { - if ( Utils::unmount( selected_partition .partition, selected_partition .mountpoint, str_temp ) ) - str_temp .clear() ; - + //FIXME: umount all targets of this device.. the aim is to get it free.. + *succes = ! Utils::execute_command( "umount " + selected_partition .partition, str_temp, *error ) ; + pulse = false ; } -void Win_GParted::activate_unmount( ) +void Win_GParted::activate_unmount() { + bool succes = false ; + Glib::ustring error ; + pulse = true ; - thread = Glib::Thread::create( sigc::mem_fun( *this, &Win_GParted::thread_unmount_partition ), true ) ; + thread = Glib::Thread::create( sigc::bind( + sigc::mem_fun( *this, &Win_GParted::thread_unmount_partition ), &succes, &error ), true ) ; show_pulsebar( String::ucompose( _("Unmounting %1"), selected_partition .partition ) ) ; - - if ( ! str_temp .empty() ) + + if ( ! succes ) { Gtk::MessageDialog dialog( *this, - "" + - String::ucompose( _("Could not unmount %1"), selected_partition .partition ) + - "\n\n" + str_temp, - true, + String::ucompose( _("Could not unmount %1"), selected_partition .partition ), + false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true ); + + dialog .set_secondary_text( error ) ; + dialog.run() ; } menu_gparted_refresh_devices() ; } -void Win_GParted::thread_toggle_swap() +void Win_GParted::thread_toggle_swap( bool * succes, Glib::ustring * error ) { - bool succes = false ; - if ( selected_partition .busy ) - succes = ! swapoff( selected_partition .partition .c_str() ) ; + *succes = ! Utils::execute_command( "swapoff " + selected_partition .partition, str_temp, *error ) ; else - succes = ! swapon( selected_partition .partition .c_str(), 0 ) ; + *succes = ! Utils::execute_command( "swapon " + selected_partition .partition, str_temp, *error ) ; - if ( succes ) - str_temp .clear() ; - else - str_temp = Glib::strerror( errno ) ; - pulse = false ; } void Win_GParted::activate_toggle_swap() { + bool succes = false ; + Glib::ustring error ; + pulse = true ; - thread = Glib::Thread::create( sigc::mem_fun( *this, &Win_GParted::thread_toggle_swap ), true ) ; + + thread = Glib::Thread::create( sigc::bind( + sigc::mem_fun( *this, &Win_GParted::thread_toggle_swap ), &succes, &error ), true ) ; show_pulsebar( String::ucompose( selected_partition .busy ? _("Deactivating swap on %1") : _("Activating swap on %1"), selected_partition .partition ) ) ; - if ( ! str_temp .empty() ) + if ( ! succes ) { Gtk::MessageDialog dialog( *this, @@ -1408,7 +1414,7 @@ void Win_GParted::activate_toggle_swap() Gtk::BUTTONS_OK, true ) ; - dialog .set_secondary_text( str_temp ) ; + dialog .set_secondary_text( error ) ; dialog.run() ; } diff --git a/src/ext2.cc b/src/ext2.cc index d5d6d664..1bfe6e0f 100644 --- a/src/ext2.cc +++ b/src/ext2.cc @@ -51,11 +51,7 @@ FS ext2::get_filesystem_support( ) void ext2::Set_Used_Sectors( Partition & partition ) { - argv .push_back( "dumpe2fs" ) ; - argv .push_back( "-h" ) ; - argv .push_back( partition .partition ) ; - - if ( ! execute_command( argv, output ) ) + if ( ! Utils::execute_command( "dumpe2fs -h " + partition .partition, output, error, true ) ) { index = output .find( "Free blocks:" ) ; if ( index >= output .length() || @@ -77,10 +73,8 @@ bool ext2::Create( const Partition & new_partition, std::vector= execute_command( argv, operation_details .back() .sub_details ) >= 0 ) + if ( 1 >= execute_command( "e2fsck -f -y -v " + partition .partition, + operation_details .back() .sub_details ) >= 0 ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/ext3.cc b/src/ext3.cc index 8bd8fced..2e3a5c68 100644 --- a/src/ext3.cc +++ b/src/ext3.cc @@ -52,11 +52,7 @@ FS ext3::get_filesystem_support( ) void ext3::Set_Used_Sectors( Partition & partition ) { - argv .push_back( "dumpe2fs" ) ; - argv .push_back( "-h" ) ; - argv .push_back( partition .partition ) ; - - if ( ! execute_command( argv, output ) ) + if ( ! Utils::execute_command( "dumpe2fs -h " + partition .partition, output, error, true ) ) { index = output .find( "Free blocks:" ) ; if ( index >= output .length() || @@ -78,10 +74,8 @@ bool ext3::Create( const Partition & new_partition, std::vector= execute_command( argv, operation_details .back() .sub_details ) >= 0 ) + + if ( 1 >= execute_command( "e2fsck -f -y -v " + partition .partition, + operation_details .back() .sub_details ) >= 0 ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/fat16.cc b/src/fat16.cc index 5a305335..628c7fb7 100644 --- a/src/fat16.cc +++ b/src/fat16.cc @@ -52,12 +52,7 @@ FS fat16::get_filesystem_support( ) void fat16::Set_Used_Sectors( Partition & partition ) { - argv .push_back( "dosfsck" ) ; - argv .push_back( "-a" ) ; - argv .push_back( "-v" ) ; - argv .push_back( partition .partition ) ; - - if ( 1 >= execute_command( argv, output ) >= 0 ) + if ( 1 >= Utils::execute_command( "dosfsck -a -v " + partition .partition, output, error, true ) >= 0 ) { //free clusters index = output .find( ",", output .find( partition .partition ) + partition .partition .length() ) +1 ; @@ -81,12 +76,8 @@ bool fat16::Create( const Partition & new_partition, std::vector= execute_command( argv, operation_details .back() .sub_details ) >= 0 ) + if ( 1 >= execute_command( "dosfsck -a -w -v " + partition .partition, + operation_details .back() .sub_details ) >= 0 ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/fat32.cc b/src/fat32.cc index 96006240..2ff18edf 100644 --- a/src/fat32.cc +++ b/src/fat32.cc @@ -51,12 +51,7 @@ FS fat32::get_filesystem_support( ) void fat32::Set_Used_Sectors( Partition & partition ) { - argv .push_back( "dosfsck" ) ; - argv .push_back( "-a" ) ; - argv .push_back( "-v" ) ; - argv .push_back( partition .partition ) ; - - if ( 1 >= execute_command( argv, output ) >= 0 ) + if ( 1 >= Utils::execute_command( "dosfsck -a -v " + partition .partition, output, error, true ) >= 0 ) { //free clusters index = output .find( ",", output .find( partition .partition ) + partition .partition .length() ) +1 ; @@ -80,12 +75,8 @@ bool fat32::Create( const Partition & new_partition, std::vector= execute_command( argv, operation_details .back() .sub_details ) >= 0 ) + if ( 1 >= execute_command( "dosfsck -a -w -v " + partition .partition, + operation_details .back() .sub_details ) >= 0 ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/hfs.cc b/src/hfs.cc index 3b6fc3bf..4a851ab0 100644 --- a/src/hfs.cc +++ b/src/hfs.cc @@ -49,10 +49,8 @@ bool hfs::Create( const Partition & new_partition, std::vector operation_details .push_back( OperationDetails( String::ucompose( _("create new %1 filesystem"), Utils::Get_Filesystem_String( GParted::FS_HFS ) ) ) ) ; - argv .clear() ; - argv .push_back( "hformat" ) ; - argv .push_back( new_partition .partition ) ; - if ( ! execute_command( argv, operation_details .back() .sub_details ) ) + + if ( ! execute_command( "hformat " + new_partition .partition, operation_details .back() .sub_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; @@ -77,14 +75,9 @@ bool hfs::Copy( const Glib::ustring & src_part_path, { operation_details .push_back( OperationDetails( String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ; - - argv .clear() ; - argv .push_back( "dd" ) ; - argv .push_back( "bs=8192" ) ; - argv .push_back( "if=" + src_part_path ) ; - argv .push_back( "of=" + dest_part_path ) ; - if ( ! execute_command( argv, operation_details .back() .sub_details ) ) + if ( ! execute_command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path, + operation_details .back() .sub_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/jfs.cc b/src/jfs.cc index 9d7c5abb..603333fb 100644 --- a/src/jfs.cc +++ b/src/jfs.cc @@ -19,7 +19,6 @@ #include "../include/jfs.h" #include -#include namespace GParted { @@ -38,20 +37,25 @@ FS jfs::get_filesystem_support() if ( ! Glib::find_program_in_path( "jfs_fsck" ) .empty() ) fs .check = GParted::FS::EXTERNAL ; - //resizing of jfs requires jfs support in the kernel - std::ifstream input( "/proc/filesystems" ) ; - if ( input ) + //resizing of jfs requires mount, unmount, check/repair functionality and jfs support in the kernel + if ( ! Glib::find_program_in_path( "mount" ) .empty() && + ! Glib::find_program_in_path( "umount" ) .empty() && + fs .check ) { - Glib::ustring line ; + std::ifstream input( "/proc/filesystems" ) ; + if ( input ) + { + Glib::ustring line ; - while ( input >> line ) - if ( line == "jfs" ) - { - fs .grow = GParted::FS::EXTERNAL ; - break ; - } + while ( input >> line ) + if ( line == "jfs" ) + { + fs .grow = GParted::FS::EXTERNAL ; + break ; + } - input .close() ; + input .close() ; + } } if ( ! Glib::find_program_in_path( "dd" ) .empty() && fs .grow ) @@ -64,11 +68,7 @@ FS jfs::get_filesystem_support() void jfs::Set_Used_Sectors( Partition & partition ) { - argv .push_back( "sh" ) ; - argv .push_back( "-c" ) ; - argv .push_back( "echo dm | jfs_debugfs " + partition .partition ) ; - - if ( ! execute_command( argv, output ) ) + if ( ! Utils::execute_command( "echo dm | jfs_debugfs " + partition .partition, output, error, true ) ) { //blocksize index = output .find( "Block Size:" ) ; @@ -92,11 +92,8 @@ bool jfs::Create( const Partition & new_partition, std::vector operation_details .push_back( OperationDetails( String::ucompose( _("create new %1 filesystem"), Utils::Get_Filesystem_String( GParted::FS_JFS ) ) ) ) ; - argv .clear() ; - argv .push_back( "mkfs.jfs" ) ; - argv .push_back( "-q" ) ; - argv .push_back( new_partition .partition ) ; - if ( ! execute_command( argv, operation_details .back() .sub_details ) ) + + if ( ! execute_command( "mkfs.jfs -q " + new_partition .partition, operation_details .back() .sub_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; @@ -127,11 +124,13 @@ bool jfs::Resize( const Partition & partition_new, if ( ! mkdir( TEMP_MP .c_str(), 0 ) ) { operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; - + //mount partition operation_details .back() .sub_details .push_back( OperationDetails( String::ucompose( _("mount %1 on %2"), partition_new .partition, TEMP_MP ) ) ) ; - if ( Utils::mount( partition_new .partition, TEMP_MP, "jfs", error ) ) + + if ( ! execute_command( "mount -v -t jfs " + partition_new .partition + " " + TEMP_MP, + operation_details .back() .sub_details .back() .sub_details ) ) { operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; @@ -139,7 +138,9 @@ bool jfs::Resize( const Partition & partition_new, operation_details .back() .sub_details .push_back( OperationDetails( String::ucompose( _("remount %1 on %2 with the 'resize' flag enabled"), partition_new .partition, TEMP_MP ) ) ) ; - if ( Utils::mount( partition_new .partition, TEMP_MP, "jfs", error, MS_REMOUNT, "resize" ) ) + + if ( ! execute_command( "mount -v -t jfs -o remount,resize " + partition_new .partition + " " + TEMP_MP, + operation_details .back() .sub_details .back() .sub_details ) ) { operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; return_value = true ; @@ -147,37 +148,26 @@ bool jfs::Resize( const Partition & partition_new, else { operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; - - if ( ! error .empty() ) - operation_details .back() .sub_details .back() .sub_details .push_back( - OperationDetails( error, OperationDetails::NONE ) ) ; } //and unmount it... operation_details .back() .sub_details .push_back( OperationDetails( String::ucompose( _("unmount %1"), partition_new .partition ) ) ) ; - if ( Utils::unmount( partition_new .partition, TEMP_MP, error ) ) + + if ( ! execute_command( "umount -v " + partition_new .partition, + operation_details .back() .sub_details .back() .sub_details ) ) { operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; } else { operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; - - if ( ! error .empty() ) - operation_details .back() .sub_details .back() .sub_details .push_back( - OperationDetails( error, OperationDetails::NONE ) ) ; - return_value = false ; } } else { operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; - - if ( ! error .empty() ) - operation_details .back() .sub_details .back() .sub_details .push_back( - OperationDetails( error, OperationDetails::NONE ) ) ; } //remove the mountpoint.. @@ -214,13 +204,8 @@ bool jfs::Copy( const Glib::ustring & src_part_path, operation_details .push_back( OperationDetails( String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ; - argv .clear() ; - argv .push_back( "dd" ) ; - argv .push_back( "bs=8192" ) ; - argv .push_back( "if=" + src_part_path ) ; - argv .push_back( "of=" + dest_part_path ) ; - - if ( ! execute_command( argv, operation_details .back() .sub_details ) ) + if ( ! execute_command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path, + operation_details .back() .sub_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; @@ -237,12 +222,7 @@ bool jfs::Check_Repair( const Partition & partition, std::vector= execute_command( argv, operation_details .back() .sub_details ) >= 0 ) + if ( 1 >= execute_command( "jfs_fsck -f " + partition .partition, operation_details .back() .sub_details ) >= 0 ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/linux_swap.cc b/src/linux_swap.cc index 31551487..263fa283 100644 --- a/src/linux_swap.cc +++ b/src/linux_swap.cc @@ -46,13 +46,12 @@ void linux_swap::Set_Used_Sectors( Partition & partition ) bool linux_swap::Create( const Partition & new_partition, std::vector & operation_details ) { - operation_details .push_back( OperationDetails( String::ucompose( - _("create new %1 filesystem"), - Utils::Get_Filesystem_String( GParted::FS_LINUX_SWAP ) ) ) ) ; - argv .clear() ; - argv .push_back( "mkswap" ) ; - argv .push_back( new_partition .partition ) ; - if ( ! execute_command( argv, operation_details .back() .sub_details ) ) + operation_details .push_back( + OperationDetails( String::ucompose( + _("create new %1 filesystem"), + Utils::Get_Filesystem_String( GParted::FS_LINUX_SWAP ) ) ) ) ; + + if ( ! execute_command( "mkswap " + new_partition .partition, operation_details .back() .sub_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; @@ -78,13 +77,8 @@ bool linux_swap::Copy( const Glib::ustring & src_part_path, operation_details .push_back( OperationDetails( String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ; - argv .clear() ; - argv .push_back( "dd" ) ; - argv .push_back( "bs=8192" ) ; - argv .push_back( "if=" + src_part_path ) ; - argv .push_back( "of=" + dest_part_path ) ; - - if ( ! execute_command( argv, operation_details .back() .sub_details ) ) + if ( ! execute_command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path, + operation_details .back() .sub_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/ntfs.cc b/src/ntfs.cc index a4c23603..56a56e4f 100644 --- a/src/ntfs.cc +++ b/src/ntfs.cc @@ -53,11 +53,7 @@ FS ntfs::get_filesystem_support( ) void ntfs::Set_Used_Sectors( Partition & partition ) { - argv .push_back( "ntfscluster" ) ; - argv .push_back( "--force" ) ; - argv .push_back( partition .partition ) ; - - if ( ! execute_command( argv, output ) ) + if ( ! Utils::execute_command( "ntfscluster --force " + partition .partition, output, error, true ) ) { index = output .find( "sectors of free space" ) ; if ( index >= output .length() || @@ -74,12 +70,8 @@ bool ntfs::Create( const Partition & new_partition, std::vector= output .length() || @@ -70,11 +67,8 @@ bool reiser4::Create( const Partition & new_partition, std::vector= output .length() || @@ -80,11 +77,8 @@ bool reiserfs::Create( const Partition & new_partition, std::vector -#include namespace GParted { @@ -38,8 +37,11 @@ FS xfs::get_filesystem_support( ) if ( ! Glib::find_program_in_path( "xfs_repair" ) .empty() ) fs .check = GParted::FS::EXTERNAL ; - //resizing of xfs requires xfs_growfs, xfs_repair and xfs support in the kernel - if ( ! Glib::find_program_in_path( "xfs_growfs" ) .empty() && fs .check ) + //resizing of xfs requires xfs_growfs, xfs_repair, mount, umount and xfs support in the kernel + if ( ! Glib::find_program_in_path( "xfs_growfs" ) .empty() && + ! Glib::find_program_in_path( "mount" ) .empty() && + ! Glib::find_program_in_path( "umount" ) .empty() && + fs .check ) { Glib::ustring line ; std::ifstream input( "/proc/filesystems" ) ; @@ -55,6 +57,8 @@ FS xfs::get_filesystem_support( ) if ( ! Glib::find_program_in_path( "xfsdump" ) .empty() && ! Glib::find_program_in_path( "xfsrestore" ) .empty() && + ! Glib::find_program_in_path( "mount" ) .empty() && + ! Glib::find_program_in_path( "umount" ) .empty() && fs .check && fs .create ) fs .copy = GParted::FS::EXTERNAL ; @@ -65,15 +69,11 @@ FS xfs::get_filesystem_support( ) void xfs::Set_Used_Sectors( Partition & partition ) { - argv .push_back( "xfs_db" ) ; - argv .push_back( "-c" ) ; - argv .push_back( "sb 0" ) ; - argv .push_back( "-c print blocksize" ) ; - argv .push_back( "-c print fdblocks" ) ; - argv .push_back( "-r" ) ; - argv .push_back( partition .partition ) ; - - if ( ! execute_command( argv, output ) ) + if ( ! Utils::execute_command( + "xfs_db -c 'sb 0' -c 'print blocksize' -c 'print fdblocks' -r " + partition .partition, + output, + error, + true ) ) { //blocksize if ( sscanf( output .c_str(), "blocksize = %Ld", &S ) != 1 ) @@ -94,11 +94,8 @@ bool xfs::Create( const Partition & new_partition, std::vector operation_details .push_back( OperationDetails( String::ucompose( _("create new %1 filesystem"), Utils::Get_Filesystem_String( GParted::FS_XFS ) ) ) ) ; - argv .clear() ; - argv .push_back( "mkfs.xfs" ) ; - argv .push_back( "-f" ) ; - argv .push_back( new_partition .partition ) ; - if ( ! execute_command( argv, operation_details .back() .sub_details ) ) + + if ( ! execute_command( "mkfs.xfs -f " + new_partition .partition, operation_details .back() .sub_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; @@ -133,16 +130,17 @@ bool xfs::Resize( const Partition & partition_new, //mount partition operation_details .back() .sub_details .push_back( OperationDetails( String::ucompose( _("mount %1 on %2"), partition_new .partition, TEMP_MP ) ) ) ; - if ( Utils::mount( partition_new .partition, TEMP_MP, "xfs", error ) ) + + if ( ! execute_command( "mount -v -t xfs " + partition_new .partition + " " + TEMP_MP, + operation_details .back() .sub_details .back() .sub_details ) ) { operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; //grow the mounted filesystem.. operation_details .back() .sub_details .push_back( OperationDetails( _("grow mounted filesystem") ) ) ; - argv .clear() ; - argv .push_back( "xfs_growfs" ) ; - argv .push_back( TEMP_MP ) ; - if ( ! execute_command( argv, operation_details .back() .sub_details .back() .sub_details ) ) + + if ( ! execute_command ( "xfs_growfs " + TEMP_MP, + operation_details .back() .sub_details .back() .sub_details ) ) { operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; return_value = true ; @@ -155,28 +153,21 @@ bool xfs::Resize( const Partition & partition_new, //and unmount it... operation_details .back() .sub_details .push_back( OperationDetails( String::ucompose( _("unmount %1"), partition_new .partition ) ) ) ; - if ( Utils::unmount( partition_new .partition, TEMP_MP, error ) ) + + if ( ! execute_command( "umount -v " + partition_new .partition, + operation_details .back() .sub_details .back() .sub_details ) ) { operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; } else { operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; - - if ( ! error .empty() ) - operation_details .back() .sub_details .back() .sub_details .push_back( - OperationDetails( error, OperationDetails::NONE ) ) ; - return_value = false ; } } else { operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; - - if ( ! error .empty() ) - operation_details .back() .sub_details .back() .sub_details .push_back( - OperationDetails( error, OperationDetails::NONE ) ) ; } //remove the mountpoint.. @@ -240,25 +231,27 @@ bool xfs::Copy( const Glib::ustring & src_part_path, //mount source partition operation_details .back() .sub_details .push_back( OperationDetails( String::ucompose( _("mount %1 on %2"), src_part_path, SRC ) ) ) ; - if ( Utils::mount( src_part_path, SRC, "xfs", error, MS_NOATIME | MS_RDONLY ) ) + + if ( ! execute_command( "mount -v -t xfs -o noatime,ro " + src_part_path + " " + SRC, + operation_details .back() .sub_details .back() .sub_details ) ) { operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; //mount destination partition operation_details .back() .sub_details .push_back( OperationDetails( String::ucompose( _("mount %1 on %2"), dest_part_path, DST ) ) ) ; - if ( Utils::mount( dest_part_path, DST, "xfs", error ) ) + + if ( ! execute_command( "mount -v -t xfs " + dest_part_path + " " + DST, + operation_details .back() .sub_details .back() .sub_details ) ) { operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; //copy filesystem.. operation_details .back() .sub_details .push_back( OperationDetails( _("copy filesystem") ) ) ; - argv .clear() ; - argv .push_back( "sh" ) ; - argv .push_back( "-c" ) ; - argv .push_back( "xfsdump -J - " + SRC + " | xfsrestore -J - " + DST ) ; - if ( ! execute_command( argv, operation_details .back() .sub_details .back() .sub_details ) ) + if ( ! execute_command( + "xfsdump -J - " + SRC + " | xfsrestore -J - " + DST, + operation_details .back() .sub_details .back() .sub_details ) ) { operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; return_value = true ; @@ -271,55 +264,41 @@ bool xfs::Copy( const Glib::ustring & src_part_path, //unmount destination partition operation_details .back() .sub_details .push_back( OperationDetails( String::ucompose( _("unmount %1"), dest_part_path ) ) ) ; - if ( Utils::unmount( dest_part_path, DST, error ) ) + + if ( ! execute_command( "umount -v " + dest_part_path, + operation_details .back() .sub_details .back() .sub_details ) ) { operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; } else { operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; - - if ( ! error .empty() ) - operation_details .back() .sub_details .back() .sub_details .push_back( - OperationDetails( error, OperationDetails::NONE ) ) ; - return_value = false ; } } else { operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; - - if ( ! error .empty() ) - operation_details .back() .sub_details .back() .sub_details .push_back( - OperationDetails( error, OperationDetails::NONE ) ) ; } //unmount source partition operation_details .back() .sub_details .push_back( OperationDetails( String::ucompose( _("unmount %1"), src_part_path ) ) ) ; - if ( Utils::unmount( src_part_path, SRC, error ) ) + + if ( ! execute_command( "umount -v " + src_part_path, + operation_details .back() .sub_details .back() .sub_details ) ) { operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; } else { operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; - - if ( ! error .empty() ) - operation_details .back() .sub_details .back() .sub_details .push_back( - OperationDetails( error, OperationDetails::NONE ) ) ; - return_value = false ; } } else { operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; - - if ( ! error .empty() ) - operation_details .back() .sub_details .back() .sub_details .push_back( - OperationDetails( error, OperationDetails::NONE ) ) ; } //remove destination mountpoint.. @@ -377,12 +356,7 @@ bool xfs::Check_Repair( const Partition & partition, std::vector