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>
* removed legend after discussion with usability guys

View File

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

View File

@ -120,15 +120,12 @@ public:
static Glib::ustring Get_Color( FILESYSTEM filesystem ) ;
static Glib::RefPtr<Gdk::Pixbuf> 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 ) ;
};

View File

@ -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( ) ;

View File

@ -25,63 +25,20 @@ FileSystem::FileSystem()
{
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 ;
for ( unsigned int t = 0 ; t < argv .size() ; t++ )
temp += argv[ t ] + " " ;
operation_details .push_back( OperationDetails( "<b><i>" + command + "</i></b>", OperationDetails::NONE ) ) ;
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() )
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() )
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 ;
}
operation_details .back() .sub_details .push_back(
OperationDetails( "<i>" + error + "</i>", OperationDetails::NONE ) ) ;
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 ) ;
//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 ) ;

View File

@ -18,10 +18,7 @@
#include "../include/Utils.h"
#include <sstream>
#include <fstream>
#include <cerrno>
#include <iomanip>
#include <sys/mount.h>
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<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..

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::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<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...
if ( selected_partition .partition .empty() )
@ -693,7 +693,7 @@ void Win_GParted::set_valid_operations( )
return ;
else
dynamic_cast<Gtk::Label*>(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<Gtk::CheckMenuItem *>(
& 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<bool *, Glib::ustring *>(
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,
"<span weight=\"bold\" size=\"larger\">" +
String::ucompose( _("Could not unmount %1"), selected_partition .partition ) +
"</span>\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<bool *, Glib::ustring *>(
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() ;
}

View File

@ -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<OperationDetails
operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_EXT2 ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkfs.ext2" ) ;
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
if ( ! execute_command( "mkfs.ext2 " + new_partition .partition, operation_details .back() .sub_details ) )
{
operation_details .back() .status = OperationDetails::SUCCES ;
return true ;
@ -101,15 +95,13 @@ bool ext2::Resize( const Partition & partition_new,
else
operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
argv .clear() ;
argv .push_back( "resize2fs" ) ;
argv .push_back( partition_new .partition ) ;
Glib::ustring str_temp = "resize2fs " + partition_new .partition ;
if ( ! fill_partition )
argv .push_back( Utils::num_to_str( Utils::Round( Utils::sector_to_unit(
partition_new .get_length() - cylinder_size, GParted::UNIT_MIB ) ), true ) + "M" ) ;
str_temp += " " + Utils::num_to_str( Utils::Round( Utils::sector_to_unit(
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 ;
return true ;
@ -128,13 +120,8 @@ bool ext2::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 ;
@ -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") ) ) ;
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 ;
return true ;

View File

@ -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<OperationDetails
operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_EXT3 ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkfs.ext3" ) ;
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
if ( ! execute_command( "mkfs.ext3 " + new_partition .partition, operation_details .back() .sub_details ) )
{
operation_details .back() .status = OperationDetails::SUCCES ;
return true ;
@ -102,15 +96,13 @@ bool ext3::Resize( const Partition & partition_new,
else
operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
argv .clear() ;
argv .push_back( "resize2fs" ) ;
argv .push_back( partition_new .partition ) ;
Glib::ustring str_temp = "resize2fs " + partition_new .partition ;
if ( ! fill_partition )
argv .push_back( Utils::num_to_str( Utils::Round( Utils::sector_to_unit(
partition_new .get_length() - cylinder_size, GParted::UNIT_MIB ) ), true ) + "M" ) ;
str_temp += " " + Utils::num_to_str( Utils::Round( Utils::sector_to_unit(
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 ;
return true ;
@ -129,13 +121,8 @@ bool ext3::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 ;
@ -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") ) ) ;
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 ;
return true ;

View File

@ -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<OperationDetail
operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_FAT16 ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkdosfs" ) ;
argv .push_back( "-F16" ) ;
argv .push_back( "-v" ) ;
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
if ( ! execute_command( "mkdosfs -F16 -v " + new_partition .partition, operation_details .back() .sub_details ) )
{
operation_details .back() .status = OperationDetails::SUCCES ;
return true ;
@ -113,13 +104,8 @@ bool fat16::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 ;
@ -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") ) ) ;
argv .clear() ;
argv .push_back( "dosfsck" ) ;
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 )
if ( 1 >= execute_command( "dosfsck -a -w -v " + partition .partition,
operation_details .back() .sub_details ) >= 0 )
{
operation_details .back() .status = OperationDetails::SUCCES ;
return true ;

View File

@ -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<OperationDetail
operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_FAT32 ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkdosfs" ) ;
argv .push_back( "-F32" ) ;
argv .push_back( "-v" ) ;
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
if ( ! execute_command( "mkdosfs -F32 -v " + new_partition .partition, operation_details .back() .sub_details ) )
{
operation_details .back() .status = OperationDetails::SUCCES ;
return true ;
@ -112,13 +103,8 @@ bool fat32::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 ;
@ -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") ) ) ;
argv .clear() ;
argv .push_back( "dosfsck" ) ;
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 )
if ( 1 >= execute_command( "dosfsck -a -w -v " + partition .partition,
operation_details .back() .sub_details ) >= 0 )
{
operation_details .back() .status = OperationDetails::SUCCES ;
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(
_("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 ;

View File

@ -19,7 +19,6 @@
#include "../include/jfs.h"
#include <cerrno>
#include <sys/mount.h>
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<OperationDetails>
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<OperationDetail
{
operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ;
argv .clear() ;
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 )
if ( 1 >= execute_command( "jfs_fsck -f " + partition .partition, operation_details .back() .sub_details ) >= 0 )
{
operation_details .back() .status = OperationDetails::SUCCES ;
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 )
{
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 ;

View File

@ -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<OperationDetails
operation_details .push_back( OperationDetails( String::ucompose(
_("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_NTFS ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkntfs" ) ;
argv .push_back( "-Q" ) ;
argv .push_back( "-vv" ) ;
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
if ( ! execute_command( "mkntfs -Q -vv " + new_partition .partition, operation_details .back() .sub_details ) )
{
operation_details .back() .status = OperationDetails::SUCCES ;
return true ;
@ -101,7 +93,7 @@ bool ntfs::Resize( const Partition & partition_new,
operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
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 )
{
@ -113,11 +105,7 @@ bool ntfs::Resize( const Partition & partition_new,
//simulation..
operation_details .back() .sub_details .push_back( OperationDetails( _("run simulation") ) ) ;
argv .clear() ;
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 ) )
if ( ! execute_command( str_temp + " --no-action", operation_details .back() .sub_details .back() .sub_details ) )
{
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(
OperationDetails( operation_details .back() .description ) ) ;
argv .back() = str_temp ;
if ( ! execute_command( argv, operation_details .back() .sub_details .back() .sub_details ) )
if ( ! execute_command( "echo y | " + str_temp,
operation_details .back() .sub_details .back() .sub_details ) )
{
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
return_value = true ;
@ -152,13 +140,8 @@ bool ntfs::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( "ntfsclone" ) ;
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 ) )
if ( ! execute_command( "ntfsclone -f --overwrite " + dest_part_path + " " + src_part_path,
operation_details .back() .sub_details ) )
{
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") ) ) ;
argv .clear() ;
argv .push_back( "ntfsfix" ) ;
argv .push_back( partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
if ( ! execute_command( "ntfsfix " + partition .partition, operation_details .back() .sub_details ) )
{
operation_details .back() .status = OperationDetails::SUCCES ;
return true ;

View File

@ -45,10 +45,7 @@ FS reiser4::get_filesystem_support()
void reiser4::Set_Used_Sectors( Partition & partition )
{
argv .push_back( "debugfs.reiser4" ) ;
argv .push_back( partition .partition ) ;
if ( ! execute_command( argv, output ) )
if ( ! Utils::execute_command( "debugfs.reiser4 " + partition .partition, output, error, true ) )
{
index = output .find( "free blocks" ) ;
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(
_("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_REISER4 ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkfs.reiser4" ) ;
argv .push_back( "--yes" ) ;
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
if ( ! execute_command( "mkfs.reiser4 --yes " + new_partition .partition, operation_details .back() .sub_details ) )
{
operation_details .back() .status = OperationDetails::SUCCES ;
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") ) ) ;
argv .clear() ;
argv .push_back( "fsck.reiser4" ) ;
argv .push_back( "--yes" ) ;
argv .push_back( "--fix" ) ;
argv .push_back( partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
if ( ! execute_command( "fsck.reiser4 --yes --fix " + partition .partition,
operation_details .back() .sub_details ) )
{
operation_details .back() .status = OperationDetails::SUCCES ;
return true ;

View File

@ -55,10 +55,7 @@ FS reiserfs::get_filesystem_support()
void reiserfs::Set_Used_Sectors( Partition & partition )
{
argv .push_back( "debugreiserfs" ) ;
argv .push_back( partition .partition ) ;
if ( ! execute_command( argv, output ) )
if ( ! Utils::execute_command( "debugreiserfs " + partition .partition, output, error, true ) )
{
index = output .find( "Blocksize" ) ;
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(
_("create new %1 filesystem"),
Utils::Get_Filesystem_String( GParted::FS_REISERFS ) ) ) ) ;
argv .clear() ;
argv .push_back( "mkreiserfs" ) ;
argv .push_back( "-f" ) ;
argv .push_back( new_partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
if ( ! execute_command( "mkreiserfs -f " + new_partition .partition, operation_details .back() .sub_details ) )
{
operation_details .back() .status = OperationDetails::SUCCES ;
return true ;
@ -104,7 +98,7 @@ bool reiserfs::Resize( const Partition & partition_new,
operation_details .push_back( OperationDetails( _("grow filesystem to fill the partition") ) ) ;
else
operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
Glib::ustring str_temp = "echo y | resize_reiserfs " + partition_new .partition ;
if ( ! fill_partition )
@ -114,11 +108,7 @@ bool reiserfs::Resize( const Partition & partition_new,
partition_new .get_length() - cylinder_size, GParted::UNIT_BYTE ) ), true ) ;
}
argv .clear() ;
argv .push_back( "sh" ) ;
argv .push_back( "-c" ) ;
argv .push_back( str_temp ) ;
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 ;
return true ;
@ -137,13 +127,8 @@ bool reiserfs::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 ;
@ -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") ) ) ;
argv .clear() ;
argv .push_back( "reiserfsck" ) ;
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 ) ;
int exit_status = execute_command( "reiserfsck --y --fix-fixable " + partition .partition,
operation_details .back() .sub_details ) ;
if ( exit_status == 0 || exit_status == 1 || exit_status == 256 )
{
operation_details .back() .status = OperationDetails::SUCCES ;

View File

@ -19,7 +19,6 @@
#include "../include/xfs.h"
#include <cerrno>
#include <sys/mount.h>
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<OperationDetails>
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<OperationDetail
{
operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ;
argv .clear() ;
argv .push_back( "xfs_repair" ) ;
argv .push_back( "-v" ) ;
argv .push_back( partition .partition ) ;
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
if ( ! execute_command ( "xfs_repair -v " + partition .partition, operation_details .back() .sub_details ) )
{
operation_details .back() .status = OperationDetails::SUCCES ;
return true ;