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.
This commit is contained in:
Bart Hakvoort 2006-02-15 16:05:26 +00:00
parent 62bf833847
commit 828d7a9e5b
19 changed files with 266 additions and 542 deletions

View File

@ -1,3 +1,11 @@
2006-02-15 Bart Hakvoort <hakvoort@cvs.gnome.org>
* 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 <hakvoort@cvs.gnome.org> 2006-02-11 Bart Hakvoort <hakvoort@cvs.gnome.org>
* removed legend after discussion with usability guys * removed legend after discussion with usability guys

View File

@ -47,15 +47,12 @@ public:
Sector cylinder_size ; //see GParted_Core::resize() Sector cylinder_size ; //see GParted_Core::resize()
protected: protected:
int execute_command( std::vector<std::string> argv, std::vector<OperationDetails> & operation_details ) ; int execute_command( const Glib::ustring & command, std::vector<OperationDetails> & operation_details ) ;
int execute_command( std::vector<std::string> argv, std::string & output ) ;
//those are used in several places.. //those are used in several places..
std::vector<std::string> argv ; Glib::ustring output, error ;
std::string output, error ;
Sector N, S ; Sector N, S ;
unsigned int index ; unsigned int index ;
int exit_status ;
private: private:

View File

@ -120,15 +120,12 @@ public:
static Glib::ustring Get_Color( FILESYSTEM filesystem ) ; static Glib::ustring Get_Color( FILESYSTEM filesystem ) ;
static Glib::RefPtr<Gdk::Pixbuf> get_color_as_pixbuf( FILESYSTEM filesystem, int width, int height ) ; static Glib::RefPtr<Gdk::Pixbuf> get_color_as_pixbuf( FILESYSTEM filesystem, int width, int height ) ;
static Glib::ustring Get_Filesystem_String( FILESYSTEM filesystem ) ; 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 Glib::ustring format_size( Sector size ) ;
static double sector_to_unit( Sector sectors, SIZE_UNIT size_unit ) ; 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 ) ;
}; };

View File

@ -114,8 +114,8 @@ private:
//threads.. //threads..
void thread_refresh_devices() ; void thread_refresh_devices() ;
void thread_unmount_partition() ; void thread_unmount_partition( bool * succes, Glib::ustring * error ) ;
void thread_toggle_swap() ; void thread_toggle_swap( bool * succes, Glib::ustring * error ) ;
//signal handlers //signal handlers
void open_operationslist( ) ; void open_operationslist( ) ;

View File

@ -26,62 +26,19 @@ FileSystem::FileSystem()
cylinder_size = 0 ; cylinder_size = 0 ;
} }
int FileSystem::execute_command( std::vector<std::string> argv, std::vector<OperationDetails> & operation_details ) int FileSystem::execute_command( const Glib::ustring & command, std::vector<OperationDetails> & operation_details )
{ {
Glib::ustring temp ; operation_details .push_back( OperationDetails( "<b><i>" + command + "</i></b>", OperationDetails::NONE ) ) ;
for ( unsigned int t = 0 ; t < argv .size() ; t++ )
temp += argv[ t ] + " " ;
operation_details .push_back( OperationDetails( "<b><i>" + temp + "</i></b>", 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() ) if ( ! output .empty() )
operation_details .back() .sub_details .push_back( OperationDetails( "<i>" + output + "</i>", OperationDetails::NONE ) ) ; operation_details .back() .sub_details .push_back(
OperationDetails( "<i>" + output + "</i>", OperationDetails::NONE ) ) ;
if ( ! error .empty() ) if ( ! error .empty() )
operation_details .back() .sub_details .push_back( OperationDetails( "<i>" + error + "</i>", OperationDetails::NONE ) ) ; operation_details .back() .sub_details .push_back(
OperationDetails( "<i>" + error + "</i>", OperationDetails::NONE ) ) ;
return exit_status ;
}
int FileSystem::execute_command( std::vector<std::string> argv, std::string & output )
{
std::vector<std::string> 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<void>(),
&output,
&error, //dummy
&exit_status) ;
}
catch ( Glib::Exception & e )
{
std::cout << e .what() << std::endl ;
}
return exit_status ; return exit_status ;
} }

View File

@ -603,6 +603,7 @@ bool GParted_Core::resize( const Device & device,
return resize_container_partition( partition_old, partition_new, false, operation_details ) ; return resize_container_partition( partition_old, partition_new, false, operation_details ) ;
//resize using libparted.. //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 ) if ( get_fs( partition_old .filesystem ) .grow == GParted::FS::LIBPARTED )
return resize_normal_using_libparted( partition_old, partition_new, operation_details ) ; return resize_normal_using_libparted( partition_old, partition_new, operation_details ) ;

View File

@ -18,10 +18,7 @@
#include "../include/Utils.h" #include "../include/Utils.h"
#include <sstream> #include <sstream>
#include <fstream>
#include <cerrno>
#include <iomanip> #include <iomanip>
#include <sys/mount.h>
namespace GParted 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 ) Glib::ustring Utils::format_size( Sector size )
{ {
std::stringstream ss ; 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<std::string> 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<void>(),
&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.. } //GParted..

View File

@ -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::SeparatorElem() );
menu_partition .items() .push_back( menu_partition .items() .push_back(
Gtk::Menu_Helpers::MenuElem( _("Unmount"), Gtk::Menu_Helpers::MenuElem( _("unmount"),
sigc::mem_fun( *this, &Win_GParted::activate_unmount ) ) ); sigc::mem_fun( *this, &Win_GParted::activate_unmount ) ) );
menu_partition .items() .push_back( menu_partition .items() .push_back(
Gtk::Menu_Helpers::MenuElem( _("Deactivate"), Gtk::Menu_Helpers::MenuElem( _("swapoff"),
sigc::mem_fun( *this, &Win_GParted::activate_toggle_swap ) ) ); sigc::mem_fun( *this, &Win_GParted::activate_toggle_swap ) ) );
menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ); 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_paste( false ); allow_format( false ); allow_unmount( false ) ; allow_info( false ) ;
allow_toggle_swap( false ) ; allow_toggle_swap( false ) ;
dynamic_cast<Gtk::Label*>(menu_partition .items()[ 11 ] .get_child() ) ->set_label( _("Deactivate") ) ; dynamic_cast<Gtk::Label*>(menu_partition .items()[ 11 ] .get_child() ) ->set_label( _("swapoff") ) ;
//no partition selected... //no partition selected...
if ( selected_partition .partition .empty() ) if ( selected_partition .partition .empty() )
@ -693,7 +693,7 @@ void Win_GParted::set_valid_operations( )
return ; return ;
else else
dynamic_cast<Gtk::Label*>(menu_partition .items()[ 11 ] .get_child() ) dynamic_cast<Gtk::Label*>(menu_partition .items()[ 11 ] .get_child() )
->set_label( _("Activate") ) ; ->set_label( _("swapon") ) ;
} }
//only unmount is allowed //only unmount is allowed
@ -773,19 +773,23 @@ void Win_GParted::open_operationslist( )
void Win_GParted::close_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 ); int x,y; this ->get_size( x, y );
y -= 210 ; //height of whole app - menubar - visualdisk - statusbar .... 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 ); vpaned_main .set_position( t );
while ( Gtk::Main::events_pending( ) ) while ( Gtk::Main::events_pending() )
Gtk::Main::iteration( ); Gtk::Main::iteration();
} }
hbox_operations .hide( ) ; hbox_operations .hide() ;
static_cast<Gtk::CheckMenuItem *>( static_cast<Gtk::CheckMenuItem *>(
& menubar_main .items( ) [ 2 ] .get_submenu( ) -> & menubar_main .items()[ 2 ] .get_submenu() ->
items() [ 1 ] ) ->set_active( false ) ; items()[ 1 ] ) ->set_active( false ) ;
} }
void Win_GParted::clear_operationslist() void Win_GParted::clear_operationslist()
@ -902,7 +906,6 @@ void Win_GParted::menu_gparted_refresh_devices( )
statusbar .pop() ; statusbar .pop() ;
statusbar .push( _( "No devices detected" ) ); statusbar .push( _( "No devices detected" ) );
} }
else //at least one device detected else //at least one device detected
{ {
combo_devices .show() ; combo_devices .show() ;
@ -1341,64 +1344,67 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
Add_Operation( GParted::FORMAT, part_temp ) ; 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 ) ) //FIXME: umount all targets of this device.. the aim is to get it free..
str_temp .clear() ; *succes = ! Utils::execute_command( "umount " + selected_partition .partition, str_temp, *error ) ;
pulse = false ; pulse = false ;
} }
void Win_GParted::activate_unmount( ) void Win_GParted::activate_unmount()
{ {
bool succes = false ;
Glib::ustring error ;
pulse = true ; pulse = true ;
thread = Glib::Thread::create( sigc::mem_fun( *this, &Win_GParted::thread_unmount_partition ), true ) ; thread = Glib::Thread::create( sigc::bind<bool *, Glib::ustring *>(
sigc::mem_fun( *this, &Win_GParted::thread_unmount_partition ), &succes, &error ), true ) ;
show_pulsebar( String::ucompose( _("Unmounting %1"), selected_partition .partition ) ) ; show_pulsebar( String::ucompose( _("Unmounting %1"), selected_partition .partition ) ) ;
if ( ! str_temp .empty() ) if ( ! succes )
{ {
Gtk::MessageDialog dialog( *this, Gtk::MessageDialog dialog( *this,
"<span weight=\"bold\" size=\"larger\">" + String::ucompose( _("Could not unmount %1"), selected_partition .partition ),
String::ucompose( _("Could not unmount %1"), selected_partition .partition ) + false,
"</span>\n\n" + str_temp,
true,
Gtk::MESSAGE_ERROR, Gtk::MESSAGE_ERROR,
Gtk::BUTTONS_OK, Gtk::BUTTONS_OK,
true ); true );
dialog .set_secondary_text( error ) ;
dialog.run() ; dialog.run() ;
} }
menu_gparted_refresh_devices() ; 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 ) if ( selected_partition .busy )
succes = ! swapoff( selected_partition .partition .c_str() ) ; *succes = ! Utils::execute_command( "swapoff " + selected_partition .partition, str_temp, *error ) ;
else 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 ; pulse = false ;
} }
void Win_GParted::activate_toggle_swap() void Win_GParted::activate_toggle_swap()
{ {
bool succes = false ;
Glib::ustring error ;
pulse = true ; pulse = true ;
thread = Glib::Thread::create( sigc::mem_fun( *this, &Win_GParted::thread_toggle_swap ), true ) ;
thread = Glib::Thread::create( sigc::bind<bool *, Glib::ustring *>(
sigc::mem_fun( *this, &Win_GParted::thread_toggle_swap ), &succes, &error ), true ) ;
show_pulsebar( show_pulsebar(
String::ucompose( selected_partition .busy ? _("Deactivating swap on %1") : _("Activating swap on %1"), String::ucompose( selected_partition .busy ? _("Deactivating swap on %1") : _("Activating swap on %1"),
selected_partition .partition ) ) ; selected_partition .partition ) ) ;
if ( ! str_temp .empty() ) if ( ! succes )
{ {
Gtk::MessageDialog dialog( Gtk::MessageDialog dialog(
*this, *this,
@ -1408,7 +1414,7 @@ void Win_GParted::activate_toggle_swap()
Gtk::BUTTONS_OK, Gtk::BUTTONS_OK,
true ) ; true ) ;
dialog .set_secondary_text( str_temp ) ; dialog .set_secondary_text( error ) ;
dialog.run() ; dialog.run() ;
} }

View File

@ -51,11 +51,7 @@ FS ext2::get_filesystem_support( )
void ext2::Set_Used_Sectors( Partition & partition ) void ext2::Set_Used_Sectors( Partition & partition )
{ {
argv .push_back( "dumpe2fs" ) ; if ( ! Utils::execute_command( "dumpe2fs -h " + partition .partition, output, error, true ) )
argv .push_back( "-h" ) ;
argv .push_back( partition .partition ) ;
if ( ! execute_command( argv, output ) )
{ {
index = output .find( "Free blocks:" ) ; index = output .find( "Free blocks:" ) ;
if ( index >= output .length() || if ( index >= output .length() ||
@ -77,10 +73,8 @@ bool ext2::Create( const Partition & new_partition, std::vector<OperationDetails
operation_details .push_back( OperationDetails( String::ucompose( operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"), _("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_EXT2 ) ) ) ) ; Utils::Get_Filesystem_String( GParted::FS_EXT2 ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkfs.ext2" ) ; if ( ! execute_command( "mkfs.ext2 " + new_partition .partition, operation_details .back() .sub_details ) )
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -101,15 +95,13 @@ bool ext2::Resize( const Partition & partition_new,
else else
operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ; operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
argv .clear() ; Glib::ustring str_temp = "resize2fs " + partition_new .partition ;
argv .push_back( "resize2fs" ) ;
argv .push_back( partition_new .partition ) ;
if ( ! fill_partition ) if ( ! fill_partition )
argv .push_back( Utils::num_to_str( Utils::Round( Utils::sector_to_unit( str_temp += " " + Utils::num_to_str( Utils::Round( Utils::sector_to_unit(
partition_new .get_length() - cylinder_size, GParted::UNIT_MIB ) ), true ) + "M" ) ; partition_new .get_length() - cylinder_size, GParted::UNIT_MIB ) ), true ) + "M" ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) ) if ( ! execute_command( str_temp, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -128,13 +120,8 @@ bool ext2::Copy( const Glib::ustring & src_part_path,
operation_details .push_back( OperationDetails( operation_details .push_back( OperationDetails(
String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ; String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ;
argv .clear() ; if ( ! execute_command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path,
argv .push_back( "dd" ) ; operation_details .back() .sub_details ) )
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 ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
@ -151,14 +138,8 @@ bool ext2::Check_Repair( const Partition & partition, std::vector<OperationDetai
{ {
operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ; operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ;
argv .clear() ; if ( 1 >= execute_command( "e2fsck -f -y -v " + partition .partition,
argv .push_back( "e2fsck" ) ; operation_details .back() .sub_details ) >= 0 )
argv .push_back( "-f" ) ;
argv .push_back( "-y" ) ;
argv .push_back( "-v" ) ;
argv .push_back( partition .partition ) ;
if ( 1 >= execute_command( argv, operation_details .back() .sub_details ) >= 0 )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;

View File

@ -52,11 +52,7 @@ FS ext3::get_filesystem_support( )
void ext3::Set_Used_Sectors( Partition & partition ) void ext3::Set_Used_Sectors( Partition & partition )
{ {
argv .push_back( "dumpe2fs" ) ; if ( ! Utils::execute_command( "dumpe2fs -h " + partition .partition, output, error, true ) )
argv .push_back( "-h" ) ;
argv .push_back( partition .partition ) ;
if ( ! execute_command( argv, output ) )
{ {
index = output .find( "Free blocks:" ) ; index = output .find( "Free blocks:" ) ;
if ( index >= output .length() || if ( index >= output .length() ||
@ -78,10 +74,8 @@ bool ext3::Create( const Partition & new_partition, std::vector<OperationDetails
operation_details .push_back( OperationDetails( String::ucompose( operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"), _("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_EXT3 ) ) ) ) ; Utils::Get_Filesystem_String( GParted::FS_EXT3 ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkfs.ext3" ) ; if ( ! execute_command( "mkfs.ext3 " + new_partition .partition, operation_details .back() .sub_details ) )
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -102,15 +96,13 @@ bool ext3::Resize( const Partition & partition_new,
else else
operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ; operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
argv .clear() ; Glib::ustring str_temp = "resize2fs " + partition_new .partition ;
argv .push_back( "resize2fs" ) ;
argv .push_back( partition_new .partition ) ;
if ( ! fill_partition ) if ( ! fill_partition )
argv .push_back( Utils::num_to_str( Utils::Round( Utils::sector_to_unit( str_temp += " " + Utils::num_to_str( Utils::Round( Utils::sector_to_unit(
partition_new .get_length() - cylinder_size, GParted::UNIT_MIB ) ), true ) + "M" ) ; partition_new .get_length() - cylinder_size, GParted::UNIT_MIB ) ), true ) + "M" ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) ) if ( ! execute_command( str_temp, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -129,13 +121,8 @@ bool ext3::Copy( const Glib::ustring & src_part_path,
operation_details .push_back( OperationDetails( operation_details .push_back( OperationDetails(
String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ; String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ;
argv .clear() ; if ( ! execute_command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path,
argv .push_back( "dd" ) ; operation_details .back() .sub_details ) )
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 ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
@ -152,14 +139,9 @@ bool ext3::Check_Repair( const Partition & partition, std::vector<OperationDetai
{ {
operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ; operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ;
argv .clear() ;
argv .push_back( "e2fsck" ) ;
argv .push_back( "-f" ) ;
argv .push_back( "-y" ) ;
argv .push_back( "-v" ) ;
argv .push_back( partition .partition ) ;
if ( 1 >= 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 ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;

View File

@ -52,12 +52,7 @@ FS fat16::get_filesystem_support( )
void fat16::Set_Used_Sectors( Partition & partition ) void fat16::Set_Used_Sectors( Partition & partition )
{ {
argv .push_back( "dosfsck" ) ; if ( 1 >= Utils::execute_command( "dosfsck -a -v " + partition .partition, output, error, true ) >= 0 )
argv .push_back( "-a" ) ;
argv .push_back( "-v" ) ;
argv .push_back( partition .partition ) ;
if ( 1 >= execute_command( argv, output ) >= 0 )
{ {
//free clusters //free clusters
index = output .find( ",", output .find( partition .partition ) + partition .partition .length() ) +1 ; index = output .find( ",", output .find( partition .partition ) + partition .partition .length() ) +1 ;
@ -81,12 +76,8 @@ bool fat16::Create( const Partition & new_partition, std::vector<OperationDetail
operation_details .push_back( OperationDetails( String::ucompose( operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"), _("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_FAT16 ) ) ) ) ; Utils::Get_Filesystem_String( GParted::FS_FAT16 ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkdosfs" ) ; if ( ! execute_command( "mkdosfs -F16 -v " + new_partition .partition, operation_details .back() .sub_details ) )
argv .push_back( "-F16" ) ;
argv .push_back( "-v" ) ;
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -113,13 +104,8 @@ bool fat16::Copy( const Glib::ustring & src_part_path,
operation_details .push_back( OperationDetails( operation_details .push_back( OperationDetails(
String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ; String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ;
argv .clear() ; if ( ! execute_command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path,
argv .push_back( "dd" ) ; operation_details .back() .sub_details ) )
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 ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -135,14 +121,8 @@ bool fat16::Check_Repair( const Partition & partition, std::vector<OperationDeta
{ {
operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ; operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ;
argv .clear() ; if ( 1 >= execute_command( "dosfsck -a -w -v " + partition .partition,
argv .push_back( "dosfsck" ) ; operation_details .back() .sub_details ) >= 0 )
argv .push_back( "-a" ) ;
argv .push_back( "-w" ) ;
argv .push_back( "-v" ) ;
argv .push_back( partition .partition ) ;
if ( 1 >= execute_command( argv, operation_details .back() .sub_details ) >= 0 )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;

View File

@ -51,12 +51,7 @@ FS fat32::get_filesystem_support( )
void fat32::Set_Used_Sectors( Partition & partition ) void fat32::Set_Used_Sectors( Partition & partition )
{ {
argv .push_back( "dosfsck" ) ; if ( 1 >= Utils::execute_command( "dosfsck -a -v " + partition .partition, output, error, true ) >= 0 )
argv .push_back( "-a" ) ;
argv .push_back( "-v" ) ;
argv .push_back( partition .partition ) ;
if ( 1 >= execute_command( argv, output ) >= 0 )
{ {
//free clusters //free clusters
index = output .find( ",", output .find( partition .partition ) + partition .partition .length() ) +1 ; index = output .find( ",", output .find( partition .partition ) + partition .partition .length() ) +1 ;
@ -80,12 +75,8 @@ bool fat32::Create( const Partition & new_partition, std::vector<OperationDetail
operation_details .push_back( OperationDetails( String::ucompose( operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"), _("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_FAT32 ) ) ) ) ; Utils::Get_Filesystem_String( GParted::FS_FAT32 ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkdosfs" ) ; if ( ! execute_command( "mkdosfs -F32 -v " + new_partition .partition, operation_details .back() .sub_details ) )
argv .push_back( "-F32" ) ;
argv .push_back( "-v" ) ;
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -112,13 +103,8 @@ bool fat32::Copy( const Glib::ustring & src_part_path,
operation_details .push_back( OperationDetails( operation_details .push_back( OperationDetails(
String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ; String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ;
argv .clear() ; if ( ! execute_command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path,
argv .push_back( "dd" ) ; operation_details .back() .sub_details ) )
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 ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -134,14 +120,8 @@ bool fat32::Check_Repair( const Partition & partition, std::vector<OperationDeta
{ {
operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ; operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ;
argv .clear() ; if ( 1 >= execute_command( "dosfsck -a -w -v " + partition .partition,
argv .push_back( "dosfsck" ) ; operation_details .back() .sub_details ) >= 0 )
argv .push_back( "-a" ) ;
argv .push_back( "-w" ) ;
argv .push_back( "-v" ) ;
argv .push_back( partition .partition ) ;
if ( 1 >= execute_command( argv, operation_details .back() .sub_details ) >= 0 )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;

View File

@ -49,10 +49,8 @@ bool hfs::Create( const Partition & new_partition, std::vector<OperationDetails>
operation_details .push_back( OperationDetails( String::ucompose( operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"), _("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_HFS ) ) ) ) ; Utils::Get_Filesystem_String( GParted::FS_HFS ) ) ) ) ;
argv .clear() ;
argv .push_back( "hformat" ) ; if ( ! execute_command( "hformat " + new_partition .partition, operation_details .back() .sub_details ) )
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -78,13 +76,8 @@ bool hfs::Copy( const Glib::ustring & src_part_path,
operation_details .push_back( OperationDetails( operation_details .push_back( OperationDetails(
String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ; String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ;
argv .clear() ; if ( ! execute_command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path,
argv .push_back( "dd" ) ; operation_details .back() .sub_details ) )
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 ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;

View File

@ -19,7 +19,6 @@
#include "../include/jfs.h" #include "../include/jfs.h"
#include <cerrno> #include <cerrno>
#include <sys/mount.h>
namespace GParted namespace GParted
{ {
@ -38,7 +37,11 @@ FS jfs::get_filesystem_support()
if ( ! Glib::find_program_in_path( "jfs_fsck" ) .empty() ) if ( ! Glib::find_program_in_path( "jfs_fsck" ) .empty() )
fs .check = GParted::FS::EXTERNAL ; fs .check = GParted::FS::EXTERNAL ;
//resizing of jfs requires jfs support in the kernel //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 )
{
std::ifstream input( "/proc/filesystems" ) ; std::ifstream input( "/proc/filesystems" ) ;
if ( input ) if ( input )
{ {
@ -53,6 +56,7 @@ FS jfs::get_filesystem_support()
input .close() ; input .close() ;
} }
}
if ( ! Glib::find_program_in_path( "dd" ) .empty() && fs .grow ) if ( ! Glib::find_program_in_path( "dd" ) .empty() && fs .grow )
fs .copy = GParted::FS::EXTERNAL ; fs .copy = GParted::FS::EXTERNAL ;
@ -64,11 +68,7 @@ FS jfs::get_filesystem_support()
void jfs::Set_Used_Sectors( Partition & partition ) void jfs::Set_Used_Sectors( Partition & partition )
{ {
argv .push_back( "sh" ) ; if ( ! Utils::execute_command( "echo dm | jfs_debugfs " + partition .partition, output, error, true ) )
argv .push_back( "-c" ) ;
argv .push_back( "echo dm | jfs_debugfs " + partition .partition ) ;
if ( ! execute_command( argv, output ) )
{ {
//blocksize //blocksize
index = output .find( "Block Size:" ) ; index = output .find( "Block Size:" ) ;
@ -92,11 +92,8 @@ bool jfs::Create( const Partition & new_partition, std::vector<OperationDetails>
operation_details .push_back( OperationDetails( String::ucompose( operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"), _("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_JFS ) ) ) ) ; Utils::Get_Filesystem_String( GParted::FS_JFS ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkfs.jfs" ) ; if ( ! execute_command( "mkfs.jfs -q " + new_partition .partition, operation_details .back() .sub_details ) )
argv .push_back( "-q" ) ;
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -131,7 +128,9 @@ bool jfs::Resize( const Partition & partition_new,
//mount partition //mount partition
operation_details .back() .sub_details .push_back( operation_details .back() .sub_details .push_back(
OperationDetails( String::ucompose( _("mount %1 on %2"), partition_new .partition, TEMP_MP ) ) ) ; 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 ; 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( operation_details .back() .sub_details .push_back(
OperationDetails( String::ucompose( _("remount %1 on %2 with the 'resize' flag enabled"), OperationDetails( String::ucompose( _("remount %1 on %2 with the 'resize' flag enabled"),
partition_new .partition, TEMP_MP ) ) ) ; 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 ; operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
return_value = true ; return_value = true ;
@ -147,37 +148,26 @@ bool jfs::Resize( const Partition & partition_new,
else else
{ {
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; 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... //and unmount it...
operation_details .back() .sub_details .push_back( operation_details .back() .sub_details .push_back(
OperationDetails( String::ucompose( _("unmount %1"), partition_new .partition ) ) ) ; 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 ; operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
} }
else else
{ {
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; 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 ; return_value = false ;
} }
} }
else else
{ {
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; 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.. //remove the mountpoint..
@ -214,13 +204,8 @@ bool jfs::Copy( const Glib::ustring & src_part_path,
operation_details .push_back( OperationDetails( operation_details .push_back( OperationDetails(
String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ; String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ;
argv .clear() ; if ( ! execute_command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path,
argv .push_back( "dd" ) ; operation_details .back() .sub_details ) )
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 ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
@ -237,12 +222,7 @@ bool jfs::Check_Repair( const Partition & partition, std::vector<OperationDetail
{ {
operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ; operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ;
argv .clear() ; if ( 1 >= execute_command( "jfs_fsck -f " + partition .partition, operation_details .back() .sub_details ) >= 0 )
argv .push_back( "jfs_fsck" ) ;
argv .push_back( "-f" ) ;
argv .push_back( partition .partition ) ;
if ( 1 >= execute_command( argv, operation_details .back() .sub_details ) >= 0 )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;

View File

@ -46,13 +46,12 @@ void linux_swap::Set_Used_Sectors( Partition & partition )
bool linux_swap::Create( const Partition & new_partition, std::vector<OperationDetails> & operation_details ) bool linux_swap::Create( const Partition & new_partition, std::vector<OperationDetails> & operation_details )
{ {
operation_details .push_back( OperationDetails( String::ucompose( operation_details .push_back(
OperationDetails( String::ucompose(
_("create new %1 filesystem"), _("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_LINUX_SWAP ) ) ) ) ; Utils::Get_Filesystem_String( GParted::FS_LINUX_SWAP ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkswap" ) ; if ( ! execute_command( "mkswap " + new_partition .partition, operation_details .back() .sub_details ) )
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -78,13 +77,8 @@ bool linux_swap::Copy( const Glib::ustring & src_part_path,
operation_details .push_back( OperationDetails( operation_details .push_back( OperationDetails(
String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ; String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ;
argv .clear() ; if ( ! execute_command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path,
argv .push_back( "dd" ) ; operation_details .back() .sub_details ) )
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 ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;

View File

@ -53,11 +53,7 @@ FS ntfs::get_filesystem_support( )
void ntfs::Set_Used_Sectors( Partition & partition ) void ntfs::Set_Used_Sectors( Partition & partition )
{ {
argv .push_back( "ntfscluster" ) ; if ( ! Utils::execute_command( "ntfscluster --force " + partition .partition, output, error, true ) )
argv .push_back( "--force" ) ;
argv .push_back( partition .partition ) ;
if ( ! execute_command( argv, output ) )
{ {
index = output .find( "sectors of free space" ) ; index = output .find( "sectors of free space" ) ;
if ( index >= output .length() || if ( index >= output .length() ||
@ -74,12 +70,8 @@ bool ntfs::Create( const Partition & new_partition, std::vector<OperationDetails
operation_details .push_back( OperationDetails( String::ucompose( operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"), _("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_NTFS ) ) ) ) ; Utils::Get_Filesystem_String( GParted::FS_NTFS ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkntfs" ) ; if ( ! execute_command( "mkntfs -Q -vv " + new_partition .partition, operation_details .back() .sub_details ) )
argv .push_back( "-Q" ) ;
argv .push_back( "-vv" ) ;
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -101,7 +93,7 @@ bool ntfs::Resize( const Partition & partition_new,
operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ; operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
bool return_value = false ; bool return_value = false ;
Glib::ustring str_temp = "echo y | ntfsresize -P --force " + partition_new .partition ; Glib::ustring str_temp = "ntfsresize -P --force " + partition_new .partition ;
if ( ! fill_partition ) if ( ! fill_partition )
{ {
@ -113,11 +105,7 @@ bool ntfs::Resize( const Partition & partition_new,
//simulation.. //simulation..
operation_details .back() .sub_details .push_back( OperationDetails( _("run simulation") ) ) ; operation_details .back() .sub_details .push_back( OperationDetails( _("run simulation") ) ) ;
argv .clear() ; if ( ! execute_command( str_temp + " --no-action", operation_details .back() .sub_details .back() .sub_details ) )
argv .push_back( "sh" ) ;
argv .push_back( "-c" ) ;
argv .push_back( str_temp + " --no-action" ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details .back() .sub_details ) )
{ {
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
@ -125,8 +113,8 @@ bool ntfs::Resize( const Partition & partition_new,
operation_details .back() .sub_details .push_back( operation_details .back() .sub_details .push_back(
OperationDetails( operation_details .back() .description ) ) ; OperationDetails( operation_details .back() .description ) ) ;
argv .back() = str_temp ; if ( ! execute_command( "echo y | " + str_temp,
if ( ! execute_command( argv, operation_details .back() .sub_details .back() .sub_details ) ) operation_details .back() .sub_details .back() .sub_details ) )
{ {
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
return_value = true ; return_value = true ;
@ -152,13 +140,8 @@ bool ntfs::Copy( const Glib::ustring & src_part_path,
operation_details .push_back( OperationDetails( operation_details .push_back( OperationDetails(
String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ; String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ;
argv .clear() ; if ( ! execute_command( "ntfsclone -f --overwrite " + dest_part_path + " " + src_part_path,
argv .push_back( "ntfsclone" ) ; operation_details .back() .sub_details ) )
argv .push_back( "-f" ) ;
argv .push_back( "--overwrite" ) ;
argv .push_back( dest_part_path ) ;
argv .push_back( src_part_path ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
@ -175,10 +158,7 @@ bool ntfs::Check_Repair( const Partition & partition, std::vector<OperationDetai
{ {
operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ; operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ;
argv .clear() ; if ( ! execute_command( "ntfsfix " + partition .partition, operation_details .back() .sub_details ) )
argv .push_back( "ntfsfix" ) ;
argv .push_back( partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;

View File

@ -45,10 +45,7 @@ FS reiser4::get_filesystem_support()
void reiser4::Set_Used_Sectors( Partition & partition ) void reiser4::Set_Used_Sectors( Partition & partition )
{ {
argv .push_back( "debugfs.reiser4" ) ; if ( ! Utils::execute_command( "debugfs.reiser4 " + partition .partition, output, error, true ) )
argv .push_back( partition .partition ) ;
if ( ! execute_command( argv, output ) )
{ {
index = output .find( "free blocks" ) ; index = output .find( "free blocks" ) ;
if ( index >= output .length() || if ( index >= output .length() ||
@ -70,11 +67,8 @@ bool reiser4::Create( const Partition & new_partition, std::vector<OperationDeta
operation_details .push_back( OperationDetails( String::ucompose( operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"), _("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_REISER4 ) ) ) ) ; Utils::Get_Filesystem_String( GParted::FS_REISER4 ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkfs.reiser4" ) ; if ( ! execute_command( "mkfs.reiser4 --yes " + new_partition .partition, operation_details .back() .sub_details ) )
argv .push_back( "--yes" ) ;
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -104,13 +98,8 @@ bool reiser4::Check_Repair( const Partition & partition, std::vector<OperationDe
{ {
operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ; operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ;
argv .clear() ; if ( ! execute_command( "fsck.reiser4 --yes --fix " + partition .partition,
argv .push_back( "fsck.reiser4" ) ; operation_details .back() .sub_details ) )
argv .push_back( "--yes" ) ;
argv .push_back( "--fix" ) ;
argv .push_back( partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;

View File

@ -55,10 +55,7 @@ FS reiserfs::get_filesystem_support()
void reiserfs::Set_Used_Sectors( Partition & partition ) void reiserfs::Set_Used_Sectors( Partition & partition )
{ {
argv .push_back( "debugreiserfs" ) ; if ( ! Utils::execute_command( "debugreiserfs " + partition .partition, output, error, true ) )
argv .push_back( partition .partition ) ;
if ( ! execute_command( argv, output ) )
{ {
index = output .find( "Blocksize" ) ; index = output .find( "Blocksize" ) ;
if ( index >= output .length() || if ( index >= output .length() ||
@ -80,11 +77,8 @@ bool reiserfs::Create( const Partition & new_partition, std::vector<OperationDet
operation_details .push_back( OperationDetails( String::ucompose( operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"), _("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_REISERFS ) ) ) ) ; Utils::Get_Filesystem_String( GParted::FS_REISERFS ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkreiserfs" ) ; if ( ! execute_command( "mkreiserfs -f " + new_partition .partition, operation_details .back() .sub_details ) )
argv .push_back( "-f" ) ;
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -114,11 +108,7 @@ bool reiserfs::Resize( const Partition & partition_new,
partition_new .get_length() - cylinder_size, GParted::UNIT_BYTE ) ), true ) ; partition_new .get_length() - cylinder_size, GParted::UNIT_BYTE ) ), true ) ;
} }
argv .clear() ; if ( ! execute_command( str_temp, operation_details .back() .sub_details ) )
argv .push_back( "sh" ) ;
argv .push_back( "-c" ) ;
argv .push_back( str_temp ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -137,13 +127,8 @@ bool reiserfs::Copy( const Glib::ustring & src_part_path,
operation_details .push_back( OperationDetails( operation_details .push_back( OperationDetails(
String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ; String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ;
argv .clear() ; if ( ! execute_command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path,
argv .push_back( "dd" ) ; operation_details .back() .sub_details ) )
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 ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
@ -160,15 +145,8 @@ bool reiserfs::Check_Repair( const Partition & partition, std::vector<OperationD
{ {
operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ; operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ;
argv .clear() ; int exit_status = execute_command( "reiserfsck --y --fix-fixable " + partition .partition,
argv .push_back( "reiserfsck" ) ; operation_details .back() .sub_details ) ;
argv .push_back( "--y" ) ;
argv .push_back( "--fix-fixable" ) ;
argv .push_back( partition .partition ) ;
//according to the manpage it should return 0 or 1 on succes, instead it returns 256 on succes..
//blah, don't have time for this. Just check for both options
exit_status = execute_command( argv, operation_details .back() .sub_details ) ;
if ( exit_status == 0 || exit_status == 1 || exit_status == 256 ) if ( exit_status == 0 || exit_status == 1 || exit_status == 256 )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;

View File

@ -19,7 +19,6 @@
#include "../include/xfs.h" #include "../include/xfs.h"
#include <cerrno> #include <cerrno>
#include <sys/mount.h>
namespace GParted namespace GParted
{ {
@ -38,8 +37,11 @@ FS xfs::get_filesystem_support( )
if ( ! Glib::find_program_in_path( "xfs_repair" ) .empty() ) if ( ! Glib::find_program_in_path( "xfs_repair" ) .empty() )
fs .check = GParted::FS::EXTERNAL ; fs .check = GParted::FS::EXTERNAL ;
//resizing of xfs requires xfs_growfs, xfs_repair and xfs support in the kernel //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() && fs .check ) 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 ; Glib::ustring line ;
std::ifstream input( "/proc/filesystems" ) ; std::ifstream input( "/proc/filesystems" ) ;
@ -55,6 +57,8 @@ FS xfs::get_filesystem_support( )
if ( ! Glib::find_program_in_path( "xfsdump" ) .empty() && if ( ! Glib::find_program_in_path( "xfsdump" ) .empty() &&
! Glib::find_program_in_path( "xfsrestore" ) .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 .check && fs .create )
fs .copy = GParted::FS::EXTERNAL ; fs .copy = GParted::FS::EXTERNAL ;
@ -65,15 +69,11 @@ FS xfs::get_filesystem_support( )
void xfs::Set_Used_Sectors( Partition & partition ) void xfs::Set_Used_Sectors( Partition & partition )
{ {
argv .push_back( "xfs_db" ) ; if ( ! Utils::execute_command(
argv .push_back( "-c" ) ; "xfs_db -c 'sb 0' -c 'print blocksize' -c 'print fdblocks' -r " + partition .partition,
argv .push_back( "sb 0" ) ; output,
argv .push_back( "-c print blocksize" ) ; error,
argv .push_back( "-c print fdblocks" ) ; true ) )
argv .push_back( "-r" ) ;
argv .push_back( partition .partition ) ;
if ( ! execute_command( argv, output ) )
{ {
//blocksize //blocksize
if ( sscanf( output .c_str(), "blocksize = %Ld", &S ) != 1 ) if ( sscanf( output .c_str(), "blocksize = %Ld", &S ) != 1 )
@ -94,11 +94,8 @@ bool xfs::Create( const Partition & new_partition, std::vector<OperationDetails>
operation_details .push_back( OperationDetails( String::ucompose( operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"), _("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_XFS ) ) ) ) ; Utils::Get_Filesystem_String( GParted::FS_XFS ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkfs.xfs" ) ; if ( ! execute_command( "mkfs.xfs -f " + new_partition .partition, operation_details .back() .sub_details ) )
argv .push_back( "-f" ) ;
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;
@ -133,16 +130,17 @@ bool xfs::Resize( const Partition & partition_new,
//mount partition //mount partition
operation_details .back() .sub_details .push_back( operation_details .back() .sub_details .push_back(
OperationDetails( String::ucompose( _("mount %1 on %2"), partition_new .partition, TEMP_MP ) ) ) ; 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 ; operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
//grow the mounted filesystem.. //grow the mounted filesystem..
operation_details .back() .sub_details .push_back( OperationDetails( _("grow mounted filesystem") ) ) ; operation_details .back() .sub_details .push_back( OperationDetails( _("grow mounted filesystem") ) ) ;
argv .clear() ;
argv .push_back( "xfs_growfs" ) ; if ( ! execute_command ( "xfs_growfs " + TEMP_MP,
argv .push_back( TEMP_MP ) ; operation_details .back() .sub_details .back() .sub_details ) )
if ( ! execute_command( argv, operation_details .back() .sub_details .back() .sub_details ) )
{ {
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
return_value = true ; return_value = true ;
@ -155,28 +153,21 @@ bool xfs::Resize( const Partition & partition_new,
//and unmount it... //and unmount it...
operation_details .back() .sub_details .push_back( operation_details .back() .sub_details .push_back(
OperationDetails( String::ucompose( _("unmount %1"), partition_new .partition ) ) ) ; 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 ; operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
} }
else else
{ {
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; 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 ; return_value = false ;
} }
} }
else else
{ {
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; 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.. //remove the mountpoint..
@ -240,25 +231,27 @@ bool xfs::Copy( const Glib::ustring & src_part_path,
//mount source partition //mount source partition
operation_details .back() .sub_details .push_back( operation_details .back() .sub_details .push_back(
OperationDetails( String::ucompose( _("mount %1 on %2"), src_part_path, SRC ) ) ) ; 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 ; operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
//mount destination partition //mount destination partition
operation_details .back() .sub_details .push_back( operation_details .back() .sub_details .push_back(
OperationDetails( String::ucompose( _("mount %1 on %2"), dest_part_path, DST ) ) ) ; 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 ; operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
//copy filesystem.. //copy filesystem..
operation_details .back() .sub_details .push_back( OperationDetails( _("copy filesystem") ) ) ; operation_details .back() .sub_details .push_back( OperationDetails( _("copy filesystem") ) ) ;
argv .clear() ; if ( ! execute_command(
argv .push_back( "sh" ) ; "xfsdump -J - " + SRC + " | xfsrestore -J - " + DST,
argv .push_back( "-c" ) ; operation_details .back() .sub_details .back() .sub_details ) )
argv .push_back( "xfsdump -J - " + SRC + " | xfsrestore -J - " + DST ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details .back() .sub_details ) )
{ {
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
return_value = true ; return_value = true ;
@ -271,55 +264,41 @@ bool xfs::Copy( const Glib::ustring & src_part_path,
//unmount destination partition //unmount destination partition
operation_details .back() .sub_details .push_back( operation_details .back() .sub_details .push_back(
OperationDetails( String::ucompose( _("unmount %1"), dest_part_path ) ) ) ; 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 ; operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
} }
else else
{ {
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; 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 ; return_value = false ;
} }
} }
else else
{ {
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; 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 //unmount source partition
operation_details .back() .sub_details .push_back( operation_details .back() .sub_details .push_back(
OperationDetails( String::ucompose( _("unmount %1"), src_part_path ) ) ) ; 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 ; operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
} }
else else
{ {
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; 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 ; return_value = false ;
} }
} }
else else
{ {
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ; 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.. //remove destination mountpoint..
@ -377,12 +356,7 @@ bool xfs::Check_Repair( const Partition & partition, std::vector<OperationDetail
{ {
operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ; operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ;
argv .clear() ; if ( ! execute_command ( "xfs_repair -v " + partition .partition, operation_details .back() .sub_details ) )
argv .push_back( "xfs_repair" ) ;
argv .push_back( "-v" ) ;
argv .push_back( partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;