Correctly quote and escape arguments passed to external commands (#787203)

Trying to set a file system label to (including the double quotes):
    " --help "
fails.  For example labelling an ext4 file system would try to run this
command:
    # e2label /dev/sdb1 "" --help ""
    Usage: e2label device [newlabel]
    # echo $?
    1

Alternatively trying to create a file system with a label of just a
double quote also fails.  The Applying Pending Operations dialog waits
forever and won't cancel or force cancel.  Have to use the window
manager close window button to close the dialog.  Also GParted reports
this error to the console:
    (gpartedbin:9648): glibmm-CRITICAL **:
    unhandled exception (type Glib::Error) in signal handler:
    domain: g-shell-error-quark
    code  : 0
    what  : Text ended before matching quote was found for ". (The text was 'mkfs.xfs -f -L """ /dev/sdb2')

Command strings are parsed and split into argv array by function
Glib::shell_parse_argv() which calls internal glib function
tokenize_command_line() for shell tokenization.  It expects the command
string to be properly quoted and escaped and after tokenization, calls
g_shell_unquote() on every parsed argument.  So to prevent constructing
incorrect commands, every non-static string needs to be properly quoted.

GParted only puts labels and mount points into double quotes, but has
not escaped special characters in those values itself.  This patch
fixes all these problems by using Glib::shell_quote() on all variable
values.  Labels, mount points, paths and all others too.

Probably a better solution would be to use a new function which takes
argv array instead of one string with all the, correctly quoted and
escaped, arguments concatenated together.

Bug 787203 - Correctly quote and escape arguments of external programs
             passed to execute_command()
This commit is contained in:
Pali Rohár 2017-09-03 09:52:54 +02:00 committed by Mike Fleetwood
parent f422052356
commit 8fdc2c21a6
22 changed files with 223 additions and 169 deletions

View File

@ -246,9 +246,11 @@ Glib::ustring DMRaid::get_udev_dm_name( const Glib::ustring & dev_path )
Glib::ustring dm_name = "" ; Glib::ustring dm_name = "" ;
if ( udevinfo_found ) if ( udevinfo_found )
Utils::execute_command( "udevinfo --query=all --name=" + dev_path, output, error, true ) ; Utils::execute_command( "udevinfo --query=all --name=" + Glib::shell_quote( dev_path ),
output, error, true );
else if ( udevadm_found ) else if ( udevadm_found )
Utils::execute_command( "udevadm info --query=all --name=" + dev_path, output, error, true ) ; Utils::execute_command( "udevadm info --query=all --name=" + Glib::shell_quote( dev_path ),
output, error, true );
if ( ! output .empty() ) if ( ! output .empty() )
{ {
@ -430,7 +432,7 @@ bool DMRaid::delete_affected_dev_map_entries( const Partition & partition, Opera
for ( unsigned int k=0; k < affected_entries .size(); k++ ) for ( unsigned int k=0; k < affected_entries .size(); k++ )
{ {
command = "dmsetup remove " + DEV_MAPPER_PATH + affected_entries[k]; command = "dmsetup remove " + Glib::shell_quote( DEV_MAPPER_PATH + affected_entries[k] );
if ( execute_command( command, operationdetail .get_last_child() ) ) if ( execute_command( command, operationdetail .get_last_child() ) )
exit_status = false ; //command failed exit_status = false ; //command failed
} }
@ -454,7 +456,7 @@ bool DMRaid::delete_dev_map_entry( const Partition & partition, OperationDetail
for ( unsigned int k = 0; k < partition_entries .size(); k++ ) for ( unsigned int k = 0; k < partition_entries .size(); k++ )
{ {
Glib::ustring command = "dmsetup remove " + partition_entries[k] ; Glib::ustring command = "dmsetup remove " + Glib::shell_quote( partition_entries[k] );
if ( execute_command( command, operationdetail .get_last_child() ) ) if ( execute_command( command, operationdetail .get_last_child() ) )
exit_status = false ; //command failed exit_status = false ; //command failed
} }
@ -477,7 +479,7 @@ bool DMRaid::purge_dev_map_entries( const Glib::ustring & dev_path )
for ( unsigned int k=0; k < dir_list .size(); k++ ) for ( unsigned int k=0; k < dir_list .size(); k++ )
{ {
command = "dmsetup remove " + DEV_MAPPER_PATH + dir_list[k]; command = "dmsetup remove " + Glib::shell_quote( DEV_MAPPER_PATH + dir_list[k] );
if ( Utils::execute_command( command, output, error, true ) ) if ( Utils::execute_command( command, output, error, true ) )
exit_status = false ; //command failed exit_status = false ; //command failed
} }

View File

@ -182,9 +182,10 @@ void Dialog_Rescue_Data::on_view_clicked(int nPart)
Glib::ustring mountPoint=tmpDir; Glib::ustring mountPoint=tmpDir;
Glib::ustring commandLine= "mount -o ro,loop,offset="+Utils::num_to_str(initOffset) Glib::ustring commandLine = "mount -o ro,loop,offset=" + Utils::num_to_str(initOffset) +
+",sizelimit="+Utils::num_to_str(totalSize)+" "+this->device_path+" \""+mountPoint+"\""; ",sizelimit=" + Utils::num_to_str(totalSize) +
" " + Glib::shell_quote(this->device_path) +
" " + Glib::shell_quote(mountPoint);
int mountResult=Utils::execute_command(commandLine); int mountResult=Utils::execute_command(commandLine);
if(mountResult!=0) if(mountResult!=0)
@ -279,7 +280,7 @@ void Dialog_Rescue_Data::check_overlaps(int nPart)
{ {
Glib::ustring mountP=this->device->partitions[i].get_mountpoint(); Glib::ustring mountP=this->device->partitions[i].get_mountpoint();
Glib::ustring commandUmount = "umount \"" + mountP + "\""; Glib::ustring commandUmount = "umount " + Glib::shell_quote(mountP);
Utils::execute_command(commandUmount); Utils::execute_command(commandUmount);
} }
} }

View File

@ -88,7 +88,8 @@ Glib::ustring FS_Info::get_fs_type( const Glib::ustring & path )
// bypassing the the cache to get the correct results. // bypassing the the cache to get the correct results.
Glib::ustring output; Glib::ustring output;
Glib::ustring error; Glib::ustring error;
if ( ! Utils::execute_command( "blkid -c /dev/null " + path, output, error, true ) ) if ( ! Utils::execute_command( "blkid -c /dev/null " + Glib::shell_quote( path ),
output, error, true ) )
fs_sec_type = Utils::regexp_label( output, " SEC_TYPE=\"([^\"]*)\"" ); fs_sec_type = Utils::regexp_label( output, " SEC_TYPE=\"([^\"]*)\"" );
} }
if ( fs_sec_type == "msdos" ) if ( fs_sec_type == "msdos" )
@ -254,7 +255,7 @@ bool FS_Info::run_blkid_load_cache( const Glib::ustring & path )
// /dev/sdb3: PARTUUID="bb8438e1-d9f1-45d3-9888-e990b598900d" // /dev/sdb3: PARTUUID="bb8438e1-d9f1-45d3-9888-e990b598900d"
Glib::ustring cmd = "blkid"; Glib::ustring cmd = "blkid";
if ( path.size() ) if ( path.size() )
cmd = cmd + " " + path; cmd = cmd + " " + Glib::shell_quote( path );
Glib::ustring output; Glib::ustring output;
Glib::ustring error; Glib::ustring error;
bool loaded_entries = false; bool loaded_entries = false;
@ -303,7 +304,7 @@ bool FS_Info::run_blkid_update_cache_one_label( FS_Entry & fs_entry )
// label without blkid's default non-reversible encoding. // label without blkid's default non-reversible encoding.
Glib::ustring output; Glib::ustring output;
Glib::ustring error; Glib::ustring error;
bool success = ! Utils::execute_command( "blkid -o value -s LABEL " + fs_entry.path.m_name, bool success = ! Utils::execute_command( "blkid -o value -s LABEL " + Glib::shell_quote( fs_entry.path.m_name ),
output, error, true ); output, error, true );
if ( ! success ) if ( ! success )
return false; return false;

View File

@ -279,7 +279,8 @@ void GParted_Core::set_devices_thread( std::vector<Device> * pdevices )
void GParted_Core::guess_partition_table(const Device & device, Glib::ustring &buff) void GParted_Core::guess_partition_table(const Device & device, Glib::ustring &buff)
{ {
Glib::ustring error; Glib::ustring error;
Glib::ustring cmd = "gpart -s " + Utils::num_to_str( device.sector_size ) + " " + device.get_path(); Glib::ustring cmd = "gpart -s " + Utils::num_to_str( device.sector_size ) +
" " + Glib::shell_quote( device.get_path() );
Utils::execute_command( cmd, buff, error, true ); Utils::execute_command( cmd, buff, error, true );
} }
@ -1004,7 +1005,7 @@ void GParted_Core::set_device_serial_number( Device & device )
Glib::ustring output; Glib::ustring output;
Glib::ustring error; Glib::ustring error;
Utils::execute_command( "hdparm -I " + device.get_path(), output, error, true ); Utils::execute_command( "hdparm -I " + Glib::shell_quote( device.get_path() ), output, error, true );
if ( ! error.empty() ) if ( ! error.empty() )
{ {
// hdparm reported an error message to stderr. Assume it's a device // hdparm reported an error message to stderr. Assume it's a device

View File

@ -402,7 +402,7 @@ bool Utils::kernel_supports_fs( const Glib::ustring & fs )
return true ; return true ;
Glib::ustring output, error ; Glib::ustring output, error ;
execute_command( "modprobe " + fs, output, error, true ); execute_command( "modprobe " + Glib::shell_quote( fs ), output, error, true );
input .open( "/proc/filesystems" ) ; input .open( "/proc/filesystems" ) ;
if ( input ) if ( input )

View File

@ -2391,7 +2391,7 @@ bool Win_GParted::unmount_partition( const Partition & partition, Glib::ustring
} }
else else
{ {
Glib::ustring cmd = "umount -v \"" + fs_mountpoints[i] + "\""; Glib::ustring cmd = "umount -v " + Glib::shell_quote( fs_mountpoints[i] );
Glib::ustring dummy; Glib::ustring dummy;
Glib::ustring umount_error; Glib::ustring umount_error;
if ( Utils::execute_command( cmd, dummy, umount_error ) ) if ( Utils::execute_command( cmd, dummy, umount_error ) )
@ -2536,22 +2536,22 @@ void Win_GParted::toggle_busy_state()
switch ( action ) switch ( action )
{ {
case SWAPOFF: case SWAPOFF:
cmd = "swapoff -v " + filesystem_ptn.get_path(); cmd = "swapoff -v " + Glib::shell_quote( filesystem_ptn.get_path() );
success = ! Utils::execute_command( cmd, output, error ); success = ! Utils::execute_command( cmd, output, error );
error_msg = "<i># " + cmd + "\n" + error + "</i>"; error_msg = "<i># " + cmd + "\n" + error + "</i>";
break; break;
case SWAPON: case SWAPON:
cmd = "swapon -v " + filesystem_ptn.get_path(); cmd = "swapon -v " + Glib::shell_quote( filesystem_ptn.get_path() );
success = ! Utils::execute_command( cmd, output, error ); success = ! Utils::execute_command( cmd, output, error );
error_msg = "<i># " + cmd + "\n" + error + "</i>"; error_msg = "<i># " + cmd + "\n" + error + "</i>";
break; break;
case DEACTIVATE_VG: case DEACTIVATE_VG:
cmd = "lvm vgchange -a n " + filesystem_ptn.get_mountpoint(); cmd = "lvm vgchange -a n " + Glib::shell_quote( filesystem_ptn.get_mountpoint() );
success = ! Utils::execute_command( cmd, output, error ); success = ! Utils::execute_command( cmd, output, error );
error_msg = "<i># " + cmd + "\n" + error + "</i>"; error_msg = "<i># " + cmd + "\n" + error + "</i>";
break; break;
case ACTIVATE_VG: case ACTIVATE_VG:
cmd = "lvm vgchange -a y " + filesystem_ptn.get_mountpoint(); cmd = "lvm vgchange -a y " + Glib::shell_quote( filesystem_ptn.get_mountpoint() );
success = ! Utils::execute_command( cmd, output, error ); success = ! Utils::execute_command( cmd, output, error );
error_msg = "<i># " + cmd + "\n" + error + "</i>"; error_msg = "<i># " + cmd + "\n" + error + "</i>";
break; break;
@ -2593,8 +2593,8 @@ void Win_GParted::activate_mount_partition( unsigned int index )
filesystem_ptn.get_mountpoints()[index] ) ); filesystem_ptn.get_mountpoints()[index] ) );
// First try mounting letting mount (libblkid) determine the file system type. // First try mounting letting mount (libblkid) determine the file system type.
cmd = "mount -v " + filesystem_ptn.get_path() + cmd = "mount -v " + Glib::shell_quote( filesystem_ptn.get_path() ) +
" \"" + filesystem_ptn.get_mountpoints()[index] + "\""; " " + Glib::shell_quote( filesystem_ptn.get_mountpoints()[index] );
success = ! Utils::execute_command( cmd, output, error ); success = ! Utils::execute_command( cmd, output, error );
if ( ! success ) if ( ! success )
{ {
@ -2605,8 +2605,9 @@ void Win_GParted::activate_mount_partition( unsigned int index )
{ {
// Second try mounting specifying the GParted determined file // Second try mounting specifying the GParted determined file
// system type. // system type.
cmd = "mount -v -t " + type + " " + filesystem_ptn.get_path() + cmd = "mount -v -t " + Glib::shell_quote( type ) +
" \"" + filesystem_ptn.get_mountpoints()[index] + "\""; " " + Glib::shell_quote( filesystem_ptn.get_path() ) +
" " + Glib::shell_quote( filesystem_ptn.get_mountpoints()[index] );
success = ! Utils::execute_command( cmd, output, error ); success = ! Utils::execute_command( cmd, output, error );
if ( ! success ) if ( ! success )
error_msg += "\n<i># " + cmd + "\n" + error + "</i>"; error_msg += "\n<i># " + cmd + "\n" + error + "</i>";

View File

@ -154,14 +154,15 @@ bool btrfs::is_busy( const Glib::ustring & path )
bool btrfs::create( const Partition & new_partition, OperationDetail & operationdetail ) bool btrfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "mkfs.btrfs -L \"" + new_partition.get_filesystem_label() + "\" " + return ! execute_command( "mkfs.btrfs -L " + Glib::shell_quote( new_partition.get_filesystem_label() ) +
new_partition.get_path(), " " + Glib::shell_quote( new_partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
bool btrfs::check_repair( const Partition & partition, OperationDetail & operationdetail ) bool btrfs::check_repair( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "btrfsck " + partition .get_path(), operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( "btrfsck " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS );
} }
void btrfs::set_used_sectors( Partition & partition ) void btrfs::set_used_sectors( Partition & partition )
@ -217,9 +218,11 @@ void btrfs::set_used_sectors( Partition & partition )
// 4) Extents can be and are relocated to other devices within the file system // 4) Extents can be and are relocated to other devices within the file system
// when shrinking a device. // when shrinking a device.
if ( btrfs_found ) if ( btrfs_found )
Utils::execute_command( "btrfs filesystem show " + partition .get_path(), output, error, true ) ; Utils::execute_command( "btrfs filesystem show " + Glib::shell_quote( partition.get_path() ),
output, error, true );
else else
Utils::execute_command( "btrfs-show " + partition .get_path(), output, error, true ) ; Utils::execute_command( "btrfs-show " + Glib::shell_quote( partition.get_path() ),
output, error, true );
//In many cases the exit status doesn't reflect valid output or an error condition //In many cases the exit status doesn't reflect valid output or an error condition
// so rely on parsing the output to determine success. // so rely on parsing the output to determine success.
@ -295,8 +298,8 @@ void btrfs::set_used_sectors( Partition & partition )
bool btrfs::write_label( const Partition & partition, OperationDetail & operationdetail ) bool btrfs::write_label( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "btrfs filesystem label " + partition.get_path() + return ! execute_command( "btrfs filesystem label " + Glib::shell_quote( partition.get_path() ) +
" \"" + partition.get_filesystem_label() + "\"", " " + Glib::shell_quote( partition.get_filesystem_label() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
@ -320,7 +323,8 @@ bool btrfs::resize( const Partition & partition_new, OperationDetail & operation
mount_point = mk_temp_dir( "", operationdetail ) ; mount_point = mk_temp_dir( "", operationdetail ) ;
if ( mount_point .empty() ) if ( mount_point .empty() )
return false ; return false ;
success &= ! execute_command( "mount -v -t btrfs " + path + " \"" + mount_point + "\"", success &= ! execute_command( "mount -v -t btrfs " + Glib::shell_quote( path ) +
" " + Glib::shell_quote( mount_point ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
else else
@ -336,9 +340,9 @@ bool btrfs::resize( const Partition & partition_new, OperationDetail & operation
size = "max" ; size = "max" ;
Glib::ustring cmd ; Glib::ustring cmd ;
if ( btrfs_found ) if ( btrfs_found )
cmd = "btrfs filesystem resize " + devid_str + ":" + size + " \"" + mount_point + "\""; cmd = "btrfs filesystem resize " + devid_str + ":" + size + " " + Glib::shell_quote( mount_point );
else else
cmd = "btrfsctl -r " + devid_str + ":" + size + " \"" + mount_point + "\""; cmd = "btrfsctl -r " + devid_str + ":" + size + " " + Glib::shell_quote( mount_point );
exit_status = execute_command( cmd, operationdetail ); exit_status = execute_command( cmd, operationdetail );
bool resize_succeeded = ( exit_status == 0 ) ; bool resize_succeeded = ( exit_status == 0 ) ;
if ( resize_to_same_size_fails ) if ( resize_to_same_size_fails )
@ -365,7 +369,7 @@ bool btrfs::resize( const Partition & partition_new, OperationDetail & operation
success &= resize_succeeded ; success &= resize_succeeded ;
if ( ! partition_new .busy ) if ( ! partition_new .busy )
success &= ! execute_command( "umount -v \"" + mount_point + "\"", success &= ! execute_command( "umount -v " + Glib::shell_quote( mount_point ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
@ -378,9 +382,11 @@ bool btrfs::resize( const Partition & partition_new, OperationDetail & operation
void btrfs::read_label( Partition & partition ) void btrfs::read_label( Partition & partition )
{ {
if ( btrfs_found ) if ( btrfs_found )
Utils::execute_command( "btrfs filesystem show " + partition .get_path(), output, error, true ) ; Utils::execute_command( "btrfs filesystem show " + Glib::shell_quote( partition.get_path() ),
output, error, true );
else else
Utils::execute_command( "btrfs-show " + partition .get_path(), output, error, true ) ; Utils::execute_command( "btrfs-show " + Glib::shell_quote( partition.get_path() ),
output, error, true );
//In many cases the exit status doesn't reflect valid output or an error condition //In many cases the exit status doesn't reflect valid output or an error condition
// so rely on parsing the output to determine success. // so rely on parsing the output to determine success.
@ -414,9 +420,11 @@ void btrfs::read_label( Partition & partition )
void btrfs::read_uuid( Partition & partition ) void btrfs::read_uuid( Partition & partition )
{ {
if ( btrfs_found ) if ( btrfs_found )
Utils::execute_command( "btrfs filesystem show " + partition .get_path(), output, error, true ) ; Utils::execute_command( "btrfs filesystem show " + Glib::shell_quote( partition.get_path() ),
output, error, true );
else else
Utils::execute_command( "btrfs-show " + partition .get_path(), output, error, true ) ; Utils::execute_command( "btrfs-show " + Glib::shell_quote( partition.get_path() ),
output, error, true );
//In many cases the exit status doesn't reflect valid output or an error condition //In many cases the exit status doesn't reflect valid output or an error condition
// so rely on parsing the output to determine success. // so rely on parsing the output to determine success.
@ -435,7 +443,8 @@ void btrfs::read_uuid( Partition & partition )
bool btrfs::write_uuid( const Partition & partition, OperationDetail & operationdetail ) bool btrfs::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "btrfstune -f -u " + partition.get_path(), operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( "btrfstune -f -u " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS );
} }
void btrfs::clear_cache() void btrfs::clear_cache()
@ -488,9 +497,9 @@ const BTRFS_Device & btrfs::get_cache_entry( const Glib::ustring & path )
std::vector<int> devid_list ; std::vector<int> devid_list ;
std::vector<Glib::ustring> path_list ; std::vector<Glib::ustring> path_list ;
if ( btrfs_found ) if ( btrfs_found )
Utils::execute_command( "btrfs filesystem show " + path, output, error, true ) ; Utils::execute_command( "btrfs filesystem show " + Glib::shell_quote( path ), output, error, true );
else else
Utils::execute_command( "btrfs-show " + path, output, error, true ) ; Utils::execute_command( "btrfs-show " + Glib::shell_quote( path ), output, error, true );
//In many cases the exit status doesn't reflect valid output or an error condition //In many cases the exit status doesn't reflect valid output or an error condition
// so rely on parsing the output to determine success. // so rely on parsing the output to determine success.

View File

@ -175,7 +175,8 @@ void ext2::set_used_sectors( Partition & partition )
// avoid overhead subtraction. Read the free space from the kernel via // avoid overhead subtraction. Read the free space from the kernel via
// the statvfs() system call when mounted and from the superblock when // the statvfs() system call when mounted and from the superblock when
// unmounted. // unmounted.
if ( ! Utils::execute_command( dump_cmd + " -h " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( dump_cmd + " -h " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
Glib::ustring::size_type index = output.find( "Block count:" ); Glib::ustring::size_type index = output.find( "Block count:" );
if ( index >= output .length() || if ( index >= output .length() ||
@ -232,7 +233,8 @@ void ext2::set_used_sectors( Partition & partition )
void ext2::read_label( Partition & partition ) void ext2::read_label( Partition & partition )
{ {
if ( ! Utils::execute_command( label_cmd + " " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( label_cmd + " " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
partition.set_filesystem_label( Utils::trim( output ) ); partition.set_filesystem_label( Utils::trim( output ) );
} }
@ -248,14 +250,15 @@ void ext2::read_label( Partition & partition )
bool ext2::write_label( const Partition & partition, OperationDetail & operationdetail ) bool ext2::write_label( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( label_cmd + " " + partition.get_path() + return ! execute_command( label_cmd + " " + Glib::shell_quote( partition.get_path() ) +
" \"" + partition.get_filesystem_label() + "\"", " " + Glib::shell_quote( partition.get_filesystem_label() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
void ext2::read_uuid( Partition & partition ) void ext2::read_uuid( Partition & partition )
{ {
if ( ! Utils::execute_command( tune_cmd + " -l " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( tune_cmd + " -l " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
partition .uuid = Utils::regexp_label( output, "^Filesystem UUID:[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ; partition .uuid = Utils::regexp_label( output, "^Filesystem UUID:[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ;
} }
@ -271,7 +274,7 @@ void ext2::read_uuid( Partition & partition )
bool ext2::write_uuid( const Partition & partition, OperationDetail & operationdetail ) bool ext2::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( tune_cmd + " -U random " + partition .get_path(), return ! execute_command( tune_cmd + " -U random " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
@ -289,14 +292,15 @@ bool ext2::create( const Partition & new_partition, OperationDetail & operationd
features = " -O ^64bit"; features = " -O ^64bit";
} }
return ! execute_command( mkfs_cmd + " -F" + features + return ! execute_command( mkfs_cmd + " -F" + features +
" -L \"" + new_partition.get_filesystem_label() + "\" " + new_partition.get_path(), " -L " + Glib::shell_quote( new_partition.get_filesystem_label() ) +
" " + Glib::shell_quote( new_partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE|EXEC_PROGRESS_STDOUT, operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE|EXEC_PROGRESS_STDOUT,
static_cast<StreamSlot>( sigc::mem_fun( *this, &ext2::create_progress ) ) ); static_cast<StreamSlot>( sigc::mem_fun( *this, &ext2::create_progress ) ) );
} }
bool ext2::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition ) bool ext2::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
{ {
Glib::ustring str_temp = resize_cmd + " -p " + partition_new .get_path() ; Glib::ustring str_temp = resize_cmd + " -p " + Glib::shell_quote( partition_new.get_path() );
if ( ! fill_partition ) if ( ! fill_partition )
str_temp += " " + Utils::num_to_str( floor( Utils::sector_to_unit( str_temp += " " + Utils::num_to_str( floor( Utils::sector_to_unit(
@ -308,8 +312,8 @@ bool ext2::resize( const Partition & partition_new, OperationDetail & operationd
bool ext2::check_repair( const Partition & partition, OperationDetail & operationdetail ) bool ext2::check_repair( const Partition & partition, OperationDetail & operationdetail )
{ {
exit_status = execute_command( fsck_cmd + " -f -y -v -C 0 " + partition.get_path(), operationdetail, exit_status = execute_command( fsck_cmd + " -f -y -v -C 0 " + Glib::shell_quote( partition.get_path() ),
EXEC_CANCEL_SAFE|EXEC_PROGRESS_STDOUT, operationdetail, EXEC_CANCEL_SAFE|EXEC_PROGRESS_STDOUT,
static_cast<StreamSlot>( sigc::mem_fun( *this, &ext2::check_repair_progress ) ) ); static_cast<StreamSlot>( sigc::mem_fun( *this, &ext2::check_repair_progress ) ) );
bool success = ( exit_status == 0 || exit_status == 1 || exit_status == 2 ); bool success = ( exit_status == 0 || exit_status == 1 || exit_status == 2 );
set_status( operationdetail, success ); set_status( operationdetail, success );
@ -324,9 +328,9 @@ bool ext2::move( const Partition & partition_new,
Glib::ustring offset = Utils::num_to_str( llabs(distance) * partition_new.sector_size ); Glib::ustring offset = Utils::num_to_str( llabs(distance) * partition_new.sector_size );
Glib::ustring cmd; Glib::ustring cmd;
if ( distance < 0 ) if ( distance < 0 )
cmd = image_cmd + " -ra -p -o " + offset + " " + partition_new.get_path(); cmd = image_cmd + " -ra -p -o " + offset + " " + Glib::shell_quote( partition_new.get_path() );
else else
cmd = image_cmd + " -ra -p -O " + offset + " " + partition_new.get_path(); cmd = image_cmd + " -ra -p -O " + offset + " " + Glib::shell_quote( partition_new.get_path() );
fs_block_size = partition_old.fs_block_size; fs_block_size = partition_old.fs_block_size;
return ! execute_command( cmd, operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE|EXEC_PROGRESS_STDERR, return ! execute_command( cmd, operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE|EXEC_PROGRESS_STDERR,
@ -338,7 +342,8 @@ bool ext2::copy( const Partition & src_part,
OperationDetail & operationdetail ) OperationDetail & operationdetail )
{ {
fs_block_size = src_part.fs_block_size; fs_block_size = src_part.fs_block_size;
return ! execute_command( image_cmd + " -ra -p " + src_part.get_path() + " " + dest_part.get_path(), return ! execute_command( image_cmd + " -ra -p " + Glib::shell_quote( src_part.get_path() ) +
" " + Glib::shell_quote( dest_part.get_path() ),
operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE|EXEC_PROGRESS_STDERR, operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE|EXEC_PROGRESS_STDERR,
static_cast<StreamSlot>( sigc::mem_fun( *this, &ext2::copy_progress ) ) ); static_cast<StreamSlot>( sigc::mem_fun( *this, &ext2::copy_progress ) ) );
} }

View File

@ -41,8 +41,8 @@ FS f2fs::get_filesystem_support()
bool f2fs::create( const Partition & new_partition, OperationDetail & operationdetail ) bool f2fs::create( const Partition & new_partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "mkfs.f2fs -l \"" + new_partition.get_filesystem_label() + "\" " + return ! execute_command( "mkfs.f2fs -l " + Glib::shell_quote( new_partition.get_filesystem_label() ) +
new_partition.get_path(), " " + Glib::shell_quote( new_partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }

View File

@ -131,7 +131,8 @@ FS fat16::get_filesystem_support()
void fat16::set_used_sectors( Partition & partition ) void fat16::set_used_sectors( Partition & partition )
{ {
exit_status = Utils::execute_command( check_cmd + " -n -v " + partition .get_path(), output, error, true ) ; exit_status = Utils::execute_command( check_cmd + " -n -v " + Glib::shell_quote( partition.get_path() ),
output, error, true );
if ( exit_status == 0 || exit_status == 1 ) if ( exit_status == 0 || exit_status == 1 )
{ {
//total file system size in logical sectors //total file system size in logical sectors
@ -180,7 +181,8 @@ void fat16::set_used_sectors( Partition & partition )
void fat16::read_label( Partition & partition ) void fat16::read_label( Partition & partition )
{ {
if ( ! Utils::execute_command( "mlabel -s :: -i " + partition.get_path(), output, error, true ) ) if ( ! Utils::execute_command( "mlabel -s :: -i " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
partition.set_filesystem_label( Utils::trim( Utils::regexp_label( output, "Volume label is ([^(]*)" ) ) ); partition.set_filesystem_label( Utils::trim( Utils::regexp_label( output, "Volume label is ([^(]*)" ) ) );
} }
@ -198,17 +200,17 @@ bool fat16::write_label( const Partition & partition, OperationDetail & operatio
{ {
Glib::ustring cmd = "" ; Glib::ustring cmd = "" ;
if ( partition.get_filesystem_label().empty() ) if ( partition.get_filesystem_label().empty() )
cmd = "mlabel -c :: -i " + partition.get_path(); cmd = "mlabel -c :: -i " + Glib::shell_quote( partition.get_path() );
else else
cmd = "mlabel ::\"" + sanitize_label( partition.get_filesystem_label() ) + "\" -i " cmd = "mlabel ::" + Glib::shell_quote( sanitize_label( partition.get_filesystem_label() ) ) +
+ partition.get_path(); " -i " + Glib::shell_quote( partition.get_path() );
return ! execute_command( cmd, operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( cmd, operationdetail, EXEC_CHECK_STATUS );
} }
void fat16::read_uuid( Partition & partition ) void fat16::read_uuid( Partition & partition )
{ {
Glib::ustring cmd = "mdir -f :: -i " + partition.get_path(); Glib::ustring cmd = "mdir -f :: -i " + Glib::shell_quote( partition.get_path() );
if ( ! Utils::execute_command( cmd, output, error, true ) ) if ( ! Utils::execute_command( cmd, output, error, true ) )
{ {
@ -228,7 +230,7 @@ void fat16::read_uuid( Partition & partition )
bool fat16::write_uuid( const Partition & partition, OperationDetail & operationdetail ) bool fat16::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{ {
Glib::ustring cmd = "mlabel -s -n :: -i " + partition.get_path(); Glib::ustring cmd = "mlabel -s -n :: -i " + Glib::shell_quote( partition.get_path() );
return ! execute_command( cmd, operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( cmd, operationdetail, EXEC_CHECK_STATUS );
} }
@ -237,16 +239,17 @@ bool fat16::create( const Partition & new_partition, OperationDetail & operation
{ {
Glib::ustring fat_size = specific_type == FS_FAT16 ? "16" : "32" ; Glib::ustring fat_size = specific_type == FS_FAT16 ? "16" : "32" ;
Glib::ustring label_args = new_partition.get_filesystem_label().empty() ? "" : Glib::ustring label_args = new_partition.get_filesystem_label().empty() ? "" :
"-n \"" + sanitize_label( new_partition.get_filesystem_label() ) + "\" "; "-n " + Glib::shell_quote( sanitize_label( new_partition.get_filesystem_label() ) ) + " ";
return ! execute_command( create_cmd + " -F" + fat_size + " -v -I " + label_args + return ! execute_command( create_cmd + " -F" + fat_size + " -v -I " + label_args +
new_partition.get_path(), Glib::shell_quote( new_partition.get_path() ),
operationdetail, operationdetail,
EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE ); EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE );
} }
bool fat16::check_repair( const Partition & partition, OperationDetail & operationdetail ) bool fat16::check_repair( const Partition & partition, OperationDetail & operationdetail )
{ {
exit_status = execute_command( check_cmd + " -a -w -v " + partition .get_path(), operationdetail, exit_status = execute_command( check_cmd + " -a -w -v " + Glib::shell_quote( partition .get_path() ),
operationdetail,
EXEC_CANCEL_SAFE ); EXEC_CANCEL_SAFE );
bool success = ( exit_status == 0 || exit_status == 1 ); bool success = ( exit_status == 0 || exit_status == 1 );
set_status( operationdetail, success ); set_status( operationdetail, success );

View File

@ -54,16 +54,18 @@ bool hfs::create( const Partition & new_partition, OperationDetail & operationde
{ {
Glib::ustring cmd = ""; Glib::ustring cmd = "";
if( new_partition.get_filesystem_label().empty() ) if( new_partition.get_filesystem_label().empty() )
cmd = "hformat " + new_partition .get_path() ; cmd = "hformat " + Glib::shell_quote( new_partition.get_path() );
else else
cmd = "hformat -l \"" + new_partition.get_filesystem_label() + "\" " + new_partition.get_path(); cmd = "hformat -l " + Glib::shell_quote( new_partition.get_filesystem_label() ) +
" " + Glib::shell_quote( new_partition.get_path() );
return ! execute_command( cmd , operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( cmd , operationdetail, EXEC_CHECK_STATUS );
} }
bool hfs::check_repair( const Partition & partition, OperationDetail & operationdetail ) bool hfs::check_repair( const Partition & partition, OperationDetail & operationdetail )
{ {
//FIXME: find out what the returnvalue is in case of modified.. also check what the -a flag does.. (there is no manpage) //FIXME: find out what the returnvalue is in case of modified.. also check what the -a flag does.. (there is no manpage)
return ! execute_command( "hfsck -v " + partition.get_path(), operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( "hfsck -v " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS );
} }
} //GParted } //GParted

View File

@ -52,15 +52,17 @@ bool hfsplus::create( const Partition & new_partition, OperationDetail & operati
{ {
Glib::ustring cmd = ""; Glib::ustring cmd = "";
if( new_partition.get_filesystem_label().empty() ) if( new_partition.get_filesystem_label().empty() )
cmd = "mkfs.hfsplus " + new_partition .get_path() ; cmd = "mkfs.hfsplus " + Glib::shell_quote( new_partition.get_path() );
else else
cmd = "mkfs.hfsplus -v \"" + new_partition.get_filesystem_label() + "\" " + new_partition.get_path(); cmd = "mkfs.hfsplus -v " + Glib::shell_quote( new_partition.get_filesystem_label() ) +
" " + Glib::shell_quote( new_partition.get_path() );
return ! execute_command( cmd , operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( cmd , operationdetail, EXEC_CHECK_STATUS );
} }
bool hfsplus::check_repair( const Partition & partition, OperationDetail & operationdetail ) bool hfsplus::check_repair( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "fsck.hfsplus -f -y " + partition.get_path(), operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( "fsck.hfsplus -f -y " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS );
} }
} //GParted } //GParted

View File

@ -116,7 +116,8 @@ void jfs::set_used_sectors( Partition & partition )
void jfs::read_label( Partition & partition ) void jfs::read_label( Partition & partition )
{ {
if ( ! Utils::execute_command( "jfs_tune -l " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "jfs_tune -l " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
partition.set_filesystem_label( Utils::regexp_label( output, "^Volume label:[\t ]*'(.*)'" ) ); partition.set_filesystem_label( Utils::regexp_label( output, "^Volume label:[\t ]*'(.*)'" ) );
} }
@ -132,13 +133,15 @@ void jfs::read_label( Partition & partition )
bool jfs::write_label( const Partition & partition, OperationDetail & operationdetail ) bool jfs::write_label( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "jfs_tune -L \"" + partition.get_filesystem_label() + "\" " + partition.get_path(), return ! execute_command( "jfs_tune -L " + Glib::shell_quote( partition.get_filesystem_label() ) +
" " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
void jfs::read_uuid( Partition & partition ) void jfs::read_uuid( Partition & partition )
{ {
if ( ! Utils::execute_command( "jfs_tune -l " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "jfs_tune -l " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
partition .uuid = Utils::regexp_label( output, "^File system UUID:[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ; partition .uuid = Utils::regexp_label( output, "^File system UUID:[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ;
} }
@ -154,13 +157,14 @@ void jfs::read_uuid( Partition & partition )
bool jfs::write_uuid( const Partition & partition, OperationDetail & operationdetail ) bool jfs::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "jfs_tune -U random " + partition .get_path(), operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( "jfs_tune -U random " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS );
} }
bool jfs::create( const Partition & new_partition, OperationDetail & operationdetail ) bool jfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "mkfs.jfs -q -L \"" + new_partition.get_filesystem_label() + "\" " + return ! execute_command( "mkfs.jfs -q -L " + Glib::shell_quote( new_partition.get_filesystem_label() ) +
new_partition.get_path(), " " + Glib::shell_quote( new_partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE ); operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE );
} }
@ -174,8 +178,8 @@ bool jfs::resize( const Partition & partition_new, OperationDetail & operationde
mount_point = mk_temp_dir( "", operationdetail ) ; mount_point = mk_temp_dir( "", operationdetail ) ;
if ( mount_point .empty() ) if ( mount_point .empty() )
return false ; return false ;
success &= ! execute_command( "mount -v -t jfs " + partition_new .get_path() + success &= ! execute_command( "mount -v -t jfs " + Glib::shell_quote( partition_new.get_path() ) +
" \"" + mount_point + "\"", " " + Glib::shell_quote( mount_point ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
else else
@ -183,12 +187,13 @@ bool jfs::resize( const Partition & partition_new, OperationDetail & operationde
if ( success ) if ( success )
{ {
success &= ! execute_command( "mount -v -t jfs -o remount,resize " + partition_new .get_path() + success &= ! execute_command( "mount -v -t jfs -o remount,resize " +
" \"" + mount_point + "\"", Glib::shell_quote( partition_new.get_path() ) +
" " + Glib::shell_quote( mount_point ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
if ( ! partition_new .busy ) if ( ! partition_new .busy )
success &= ! execute_command( "umount -v \"" + mount_point + "\"", success &= ! execute_command( "umount -v " + Glib::shell_quote( mount_point ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
@ -200,8 +205,8 @@ bool jfs::resize( const Partition & partition_new, OperationDetail & operationde
bool jfs::check_repair( const Partition & partition, OperationDetail & operationdetail ) bool jfs::check_repair( const Partition & partition, OperationDetail & operationdetail )
{ {
exit_status = execute_command( "jfs_fsck -f " + partition.get_path(), operationdetail, exit_status = execute_command( "jfs_fsck -f " + Glib::shell_quote( partition.get_path() ),
EXEC_CANCEL_SAFE ); operationdetail, EXEC_CANCEL_SAFE );
bool success = ( exit_status == 0 || exit_status == 1 ); bool success = ( exit_status == 0 || exit_status == 1 );
set_status( operationdetail, success ); set_status( operationdetail, success );
return success; return success;

View File

@ -115,7 +115,7 @@ void linux_swap::set_used_sectors( Partition & partition )
void linux_swap::read_label( Partition & partition ) void linux_swap::read_label( Partition & partition )
{ {
if ( ! Utils::execute_command( "swaplabel " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "swaplabel " + Glib::shell_quote( partition.get_path() ), output, error, true ) )
{ {
partition.set_filesystem_label( Utils::regexp_label( output, "^LABEL:[[:blank:]]*(.*)$" ) ); partition.set_filesystem_label( Utils::regexp_label( output, "^LABEL:[[:blank:]]*(.*)$" ) );
} }
@ -131,13 +131,14 @@ void linux_swap::read_label( Partition & partition )
bool linux_swap::write_label( const Partition & partition, OperationDetail & operationdetail ) bool linux_swap::write_label( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "swaplabel -L \"" + partition.get_filesystem_label() + "\" " + partition.get_path(), return ! execute_command( "swaplabel -L " + Glib::shell_quote( partition.get_filesystem_label() ) +
" " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
void linux_swap::read_uuid( Partition & partition ) void linux_swap::read_uuid( Partition & partition )
{ {
if ( ! Utils::execute_command( "swaplabel " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "swaplabel " + Glib::shell_quote( partition.get_path() ), output, error, true ) )
{ {
partition .uuid = Utils::regexp_label( output, "^UUID:[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ; partition .uuid = Utils::regexp_label( output, "^UUID:[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ;
} }
@ -154,24 +155,25 @@ void linux_swap::read_uuid( Partition & partition )
bool linux_swap::write_uuid( const Partition & partition, OperationDetail & operationdetail ) bool linux_swap::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "swaplabel -U \"" + Utils::generate_uuid() + "\" " + partition .get_path(), return ! execute_command( "swaplabel -U " + Glib::shell_quote( Utils::generate_uuid() ) +
" " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
bool linux_swap::create( const Partition & new_partition, OperationDetail & operationdetail ) bool linux_swap::create( const Partition & new_partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "mkswap -L \"" + new_partition.get_filesystem_label() + "\" " + return ! execute_command( "mkswap -L " + Glib::shell_quote( new_partition.get_filesystem_label() ) +
new_partition.get_path(), " " + Glib::shell_quote( new_partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
bool linux_swap::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition ) bool linux_swap::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
{ {
//Maintain label and uuid when recreating swap //Maintain label and uuid when recreating swap
Glib::ustring command = "mkswap -L \"" + partition_new.get_filesystem_label() + "\" "; Glib::ustring command = "mkswap -L " + Glib::shell_quote( partition_new.get_filesystem_label() ) + " ";
if ( ! partition_new .uuid .empty() ) if ( ! partition_new .uuid .empty() )
command += " -U \"" + partition_new .uuid + "\" " ; command += " -U " + Glib::shell_quote( partition_new.uuid ) + " ";
command += partition_new .get_path() ; command += Glib::shell_quote( partition_new.get_path() );
return ! execute_command( command, operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( command, operationdetail, EXEC_CHECK_STATUS );
} }

View File

@ -136,7 +136,7 @@ bool luks::resize( const Partition & partition_new, OperationDetail & operationd
// device sector size. // device sector size.
size = "--size " + Utils::num_to_str( ( partition_new.get_byte_length() - mapping.offset ) / 512LL ) + " "; size = "--size " + Utils::num_to_str( ( partition_new.get_byte_length() - mapping.offset ) / 512LL ) + " ";
return ! execute_command( "cryptsetup -v " + size + "resize " + mapping.name, return ! execute_command( "cryptsetup -v " + size + "resize " + Glib::shell_quote( mapping.name ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }

View File

@ -93,7 +93,8 @@ void lvm2_pv::set_used_sectors( Partition & partition )
bool lvm2_pv::create( const Partition & new_partition, OperationDetail & operationdetail ) bool lvm2_pv::create( const Partition & new_partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "lvm pvcreate -M 2 " + new_partition.get_path(), operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( "lvm pvcreate -M 2 " + Glib::shell_quote( new_partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS );
} }
bool lvm2_pv::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition ) bool lvm2_pv::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
@ -103,13 +104,14 @@ bool lvm2_pv::resize( const Partition & partition_new, OperationDetail & operati
size = " --setphysicalvolumesize " + size = " --setphysicalvolumesize " +
Utils::num_to_str( floor( Utils::sector_to_unit( Utils::num_to_str( floor( Utils::sector_to_unit(
partition_new .get_sector_length(), partition_new .sector_size, UNIT_KIB ) ) ) + "K " ; partition_new .get_sector_length(), partition_new .sector_size, UNIT_KIB ) ) ) + "K " ;
return ! execute_command( "lvm pvresize -v " + size + partition_new.get_path(), return ! execute_command( "lvm pvresize -v " + size + Glib::shell_quote( partition_new.get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
bool lvm2_pv::check_repair( const Partition & partition, OperationDetail & operationdetail ) bool lvm2_pv::check_repair( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "lvm pvck -v " + partition.get_path(), operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( "lvm pvck -v " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS );
} }
bool lvm2_pv::remove( const Partition & partition, OperationDetail & operationdetail ) bool lvm2_pv::remove( const Partition & partition, OperationDetail & operationdetail )
@ -117,10 +119,10 @@ bool lvm2_pv::remove( const Partition & partition, OperationDetail & operationde
Glib::ustring vgname = LVM2_PV_Info::get_vg_name( partition.get_path() ); Glib::ustring vgname = LVM2_PV_Info::get_vg_name( partition.get_path() );
Glib::ustring cmd ; Glib::ustring cmd ;
if ( vgname .empty() ) if ( vgname .empty() )
cmd = "lvm pvremove " + partition .get_path() ; cmd = "lvm pvremove " + Glib::shell_quote( partition.get_path() );
else else
//Must force the removal of a PV which is a member of a VG //Must force the removal of a PV which is a member of a VG
cmd = "lvm pvremove --force --force --yes " + partition .get_path() ; cmd = "lvm pvremove --force --force --yes " + Glib::shell_quote( partition.get_path() );
return ! execute_command( cmd, operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( cmd, operationdetail, EXEC_CHECK_STATUS );
} }

View File

@ -73,7 +73,8 @@ FS nilfs2::get_filesystem_support()
void nilfs2::set_used_sectors( Partition & partition ) void nilfs2::set_used_sectors( Partition & partition )
{ {
if ( ! Utils::execute_command( "nilfs-tune -l " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "nilfs-tune -l " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
//File system size in bytes //File system size in bytes
Glib::ustring::size_type index = output .find( "Device size:" ) ; Glib::ustring::size_type index = output .find( "Device size:" ) ;
@ -115,7 +116,8 @@ void nilfs2::set_used_sectors( Partition & partition )
void nilfs2::read_label( Partition & partition ) void nilfs2::read_label( Partition & partition )
{ {
if ( ! Utils::execute_command( "nilfs-tune -l " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "nilfs-tune -l " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
Glib::ustring label = Utils::regexp_label( output, "^Filesystem volume name:[\t ]*(.*)$" ) ; Glib::ustring label = Utils::regexp_label( output, "^Filesystem volume name:[\t ]*(.*)$" ) ;
if ( label != "(none)" ) if ( label != "(none)" )
@ -135,14 +137,15 @@ void nilfs2::read_label( Partition & partition )
bool nilfs2::write_label( const Partition & partition, OperationDetail & operationdetail ) bool nilfs2::write_label( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "nilfs-tune -L \"" + partition.get_filesystem_label() + "\" " + return ! execute_command( "nilfs-tune -L " + Glib::shell_quote( partition.get_filesystem_label() ) +
partition.get_path(), " " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
void nilfs2::read_uuid( Partition & partition ) void nilfs2::read_uuid( Partition & partition )
{ {
if ( ! Utils::execute_command( "nilfs-tune -l " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "nilfs-tune -l " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
partition .uuid = Utils::regexp_label( output, "^Filesystem UUID:[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ; partition .uuid = Utils::regexp_label( output, "^Filesystem UUID:[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ;
} }
@ -158,14 +161,15 @@ void nilfs2::read_uuid( Partition & partition )
bool nilfs2::write_uuid( const Partition & partition, OperationDetail & operationdetail ) bool nilfs2::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "nilfs-tune -U " + Utils::generate_uuid() + " " + partition .get_path(), return ! execute_command( "nilfs-tune -U " + Glib::shell_quote( Utils::generate_uuid() ) +
" " + Glib::shell_quote( partition .get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
bool nilfs2::create( const Partition & new_partition, OperationDetail & operationdetail ) bool nilfs2::create( const Partition & new_partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "mkfs.nilfs2 -L \"" + new_partition.get_filesystem_label() + "\" " + return ! execute_command( "mkfs.nilfs2 -L " + Glib::shell_quote( new_partition.get_filesystem_label() ) +
new_partition.get_path(), " " + Glib::shell_quote( new_partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
@ -180,14 +184,14 @@ bool nilfs2::resize( const Partition & partition_new, OperationDetail & operatio
if ( mount_point .empty() ) if ( mount_point .empty() )
return false ; return false ;
success &= ! execute_command( "mount -v -t nilfs2 " + partition_new .get_path() + success &= ! execute_command( "mount -v -t nilfs2 " + Glib::shell_quote( partition_new.get_path() ) +
" \"" + mount_point + "\"", " " + Glib::shell_quote( mount_point ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
if ( success ) if ( success )
{ {
Glib::ustring cmd = "nilfs-resize -v -y " + partition_new .get_path() ; Glib::ustring cmd = "nilfs-resize -v -y " + Glib::shell_quote( partition_new.get_path() );
if ( ! fill_partition ) if ( ! fill_partition )
{ {
Glib::ustring size = Utils::num_to_str( floor( Utils::sector_to_unit( Glib::ustring size = Utils::num_to_str( floor( Utils::sector_to_unit(
@ -197,7 +201,7 @@ bool nilfs2::resize( const Partition & partition_new, OperationDetail & operatio
success &= ! execute_command( cmd, operationdetail, EXEC_CHECK_STATUS ); success &= ! execute_command( cmd, operationdetail, EXEC_CHECK_STATUS );
if ( ! partition_new. busy ) if ( ! partition_new. busy )
success &= ! execute_command( "umount -v \"" + mount_point + "\"", success &= ! execute_command( "umount -v " + Glib::shell_quote( mount_point ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }

View File

@ -122,8 +122,9 @@ FS ntfs::get_filesystem_support()
void ntfs::set_used_sectors( Partition & partition ) void ntfs::set_used_sectors( Partition & partition )
{ {
exit_status = Utils::execute_command( exit_status = Utils::execute_command( "ntfsresize --info --force --no-progress-bar " +
"ntfsresize --info --force --no-progress-bar " + partition .get_path(), output, error, true ) ; Glib::shell_quote( partition.get_path() ),
output, error, true );
if ( exit_status == 0 || exit_status == 1 ) if ( exit_status == 0 || exit_status == 1 )
{ {
Glib::ustring::size_type index = output.find( "Current volume size:" ); Glib::ustring::size_type index = output.find( "Current volume size:" );
@ -167,7 +168,8 @@ void ntfs::set_used_sectors( Partition & partition )
void ntfs::read_label( Partition & partition ) void ntfs::read_label( Partition & partition )
{ {
if ( ! Utils::execute_command( "ntfslabel --force " + partition .get_path(), output, error, false ) ) if ( ! Utils::execute_command( "ntfslabel --force " + Glib::shell_quote( partition.get_path() ),
output, error, false ) )
{ {
partition.set_filesystem_label( Utils::trim( output ) ); partition.set_filesystem_label( Utils::trim( output ) );
} }
@ -183,8 +185,8 @@ void ntfs::read_label( Partition & partition )
bool ntfs::write_label( const Partition & partition, OperationDetail & operationdetail ) bool ntfs::write_label( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "ntfslabel --force " + partition.get_path() + return ! execute_command( "ntfslabel --force " + Glib::shell_quote( partition.get_path() ) +
" \"" + partition.get_filesystem_label() + "\"", " " + Glib::shell_quote( partition.get_filesystem_label() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
@ -195,10 +197,10 @@ void ntfs::read_uuid( Partition & partition )
bool ntfs::write_uuid( const Partition & partition, OperationDetail & operationdetail ) bool ntfs::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{ {
if ( partition .uuid == UUID_RANDOM_NTFS_HALF ) if ( partition .uuid == UUID_RANDOM_NTFS_HALF )
return ! execute_command( "ntfslabel --new-half-serial " + partition.get_path(), return ! execute_command( "ntfslabel --new-half-serial " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
else else
return ! execute_command( "ntfslabel --new-serial " + partition.get_path(), return ! execute_command( "ntfslabel --new-serial " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
return true ; return true ;
@ -206,8 +208,8 @@ bool ntfs::write_uuid( const Partition & partition, OperationDetail & operationd
bool ntfs::create( const Partition & new_partition, OperationDetail & operationdetail ) bool ntfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "mkntfs -Q -v -F -L \"" + new_partition.get_filesystem_label() + "\" " + return ! execute_command( "mkntfs -Q -v -F -L " + Glib::shell_quote( new_partition.get_filesystem_label() ) +
new_partition.get_path(), " " + Glib::shell_quote( new_partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE ); operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE );
} }
@ -225,7 +227,7 @@ bool ntfs::resize( const Partition & partition_new, OperationDetail & operationd
//simulation.. //simulation..
operationdetail .add_child( OperationDetail( _("run simulation") ) ) ; operationdetail .add_child( OperationDetail( _("run simulation") ) ) ;
if ( ! execute_command( cmd + " --no-action " + partition_new.get_path(), if ( ! execute_command( cmd + " --no-action " + Glib::shell_quote( partition_new.get_path() ),
operationdetail.get_last_child(), EXEC_CHECK_STATUS ) ) operationdetail.get_last_child(), EXEC_CHECK_STATUS ) )
{ {
operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ; operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
@ -233,7 +235,7 @@ bool ntfs::resize( const Partition & partition_new, OperationDetail & operationd
//real resize //real resize
operationdetail .add_child( OperationDetail( _("real resize") ) ) ; operationdetail .add_child( OperationDetail( _("real resize") ) ) ;
if ( ! execute_command( cmd + " " + partition_new.get_path(), if ( ! execute_command( cmd + " " + Glib::shell_quote( partition_new.get_path() ),
operationdetail.get_last_child(), EXEC_CHECK_STATUS|EXEC_PROGRESS_STDOUT, operationdetail.get_last_child(), EXEC_CHECK_STATUS|EXEC_PROGRESS_STDOUT,
static_cast<StreamSlot>( sigc::mem_fun( *this, &ntfs::resize_progress ) ) ) ) static_cast<StreamSlot>( sigc::mem_fun( *this, &ntfs::resize_progress ) ) ) )
{ {
@ -257,7 +259,8 @@ bool ntfs::copy( const Partition & src_part,
Partition & dest_part, Partition & dest_part,
OperationDetail & operationdetail ) OperationDetail & operationdetail )
{ {
return ! execute_command( "ntfsclone -f --overwrite " + dest_part.get_path() + " " + src_part.get_path(), return ! execute_command( "ntfsclone -f --overwrite " + Glib::shell_quote( dest_part.get_path() ) +
" " + Glib::shell_quote( src_part.get_path() ),
operationdetail, operationdetail,
EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE|EXEC_PROGRESS_STDOUT, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE|EXEC_PROGRESS_STDOUT,
static_cast<StreamSlot>( sigc::mem_fun( *this, &ntfs::clone_progress ) ) ); static_cast<StreamSlot>( sigc::mem_fun( *this, &ntfs::clone_progress ) ) );
@ -265,7 +268,8 @@ bool ntfs::copy( const Partition & src_part,
bool ntfs::check_repair( const Partition & partition, OperationDetail & operationdetail ) bool ntfs::check_repair( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "ntfsresize -i -f -v " + partition.get_path(), operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( "ntfsresize -i -f -v " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS );
} }
//Private methods //Private methods

View File

@ -61,7 +61,8 @@ FS reiser4::get_filesystem_support()
void reiser4::set_used_sectors( Partition & partition ) void reiser4::set_used_sectors( Partition & partition )
{ {
if ( ! Utils::execute_command( "debugfs.reiser4 " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "debugfs.reiser4 " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
Glib::ustring::size_type index = output.find( "\nblocks:" ); Glib::ustring::size_type index = output.find( "\nblocks:" );
if ( index >= output .length() || if ( index >= output .length() ||
@ -98,7 +99,8 @@ void reiser4::set_used_sectors( Partition & partition )
void reiser4::read_label( Partition & partition ) void reiser4::read_label( Partition & partition )
{ {
if ( ! Utils::execute_command( "debugfs.reiser4 " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "debugfs.reiser4 " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
Glib::ustring::size_type maxlen = Utils::get_filesystem_label_maxlength( FS_REISER4 ) ; Glib::ustring::size_type maxlen = Utils::get_filesystem_label_maxlength( FS_REISER4 ) ;
Glib::ustring label = Utils::regexp_label( output, "^label:[[:blank:]]*(.*)$" ) ; Glib::ustring label = Utils::regexp_label( output, "^label:[[:blank:]]*(.*)$" ) ;
@ -122,7 +124,8 @@ void reiser4::read_label( Partition & partition )
void reiser4::read_uuid( Partition & partition ) void reiser4::read_uuid( Partition & partition )
{ {
if ( ! Utils::execute_command( "debugfs.reiser4 " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "debugfs.reiser4 " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
partition .uuid = Utils::regexp_label( output, "uuid:[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ; partition .uuid = Utils::regexp_label( output, "uuid:[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ;
} }
@ -138,14 +141,15 @@ void reiser4::read_uuid( Partition & partition )
bool reiser4::create( const Partition & new_partition, OperationDetail & operationdetail ) bool reiser4::create( const Partition & new_partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "mkfs.reiser4 --force --yes --label \"" + new_partition.get_filesystem_label() + "\" " + return ! execute_command( "mkfs.reiser4 --force --yes --label " +
new_partition.get_path(), Glib::shell_quote( new_partition.get_filesystem_label() ) +
" " + Glib::shell_quote( new_partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE ); operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE );
} }
bool reiser4::check_repair( const Partition & partition, OperationDetail & operationdetail ) bool reiser4::check_repair( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "fsck.reiser4 --yes --fix --quiet " + partition.get_path(), return ! execute_command( "fsck.reiser4 --yes --fix --quiet " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE ); operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE );
} }

View File

@ -78,7 +78,8 @@ FS reiserfs::get_filesystem_support()
void reiserfs::set_used_sectors( Partition & partition ) void reiserfs::set_used_sectors( Partition & partition )
{ {
if ( ! Utils::execute_command( "debugreiserfs " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "debugreiserfs " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
Glib::ustring::size_type index = output.find( "Count of blocks on the device:" ); Glib::ustring::size_type index = output.find( "Count of blocks on the device:" );
if ( index >= output .length() || if ( index >= output .length() ||
@ -115,7 +116,8 @@ void reiserfs::set_used_sectors( Partition & partition )
void reiserfs::read_label( Partition & partition ) void reiserfs::read_label( Partition & partition )
{ {
if ( ! Utils::execute_command( "debugreiserfs " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "debugreiserfs " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
partition.set_filesystem_label( Utils::regexp_label( output, "^label:[\t ]*(.*)$" ) ); partition.set_filesystem_label( Utils::regexp_label( output, "^label:[\t ]*(.*)$" ) );
} }
@ -131,14 +133,14 @@ void reiserfs::read_label( Partition & partition )
bool reiserfs::write_label( const Partition & partition, OperationDetail & operationdetail ) bool reiserfs::write_label( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "reiserfstune --label \"" + partition.get_filesystem_label() + "\" " + return ! execute_command( "reiserfstune --label " + Glib::shell_quote( partition.get_filesystem_label() ) +
partition.get_path(), " " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
void reiserfs::read_uuid( Partition & partition ) void reiserfs::read_uuid( Partition & partition )
{ {
if ( ! Utils::execute_command( "debugreiserfs " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "debugreiserfs " + Glib::shell_quote( partition .get_path() ), output, error, true ) )
{ {
partition .uuid = Utils::regexp_label( output, "^UUID:[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ; partition .uuid = Utils::regexp_label( output, "^UUID:[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ;
} }
@ -154,14 +156,15 @@ void reiserfs::read_uuid( Partition & partition )
bool reiserfs::write_uuid( const Partition & partition, OperationDetail & operationdetail ) bool reiserfs::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "reiserfstune -u random " + partition.get_path(), return ! execute_command( "reiserfstune -u random " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
bool reiserfs::create( const Partition & new_partition, OperationDetail & operationdetail ) bool reiserfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "mkreiserfs -f -f --label \"" + new_partition.get_filesystem_label() + "\" " + return ! execute_command( "mkreiserfs -f -f --label " +
new_partition.get_path(), Glib::shell_quote( new_partition.get_filesystem_label() ) +
" " + Glib::shell_quote( new_partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE ); operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE );
} }
@ -188,7 +191,8 @@ bool reiserfs::resize( const Partition & partition_new, OperationDetail & operat
bool reiserfs::check_repair( const Partition & partition, OperationDetail & operationdetail ) bool reiserfs::check_repair( const Partition & partition, OperationDetail & operationdetail )
{ {
exit_status = execute_command( "reiserfsck --yes --fix-fixable --quiet " + partition.get_path(), exit_status = execute_command( "reiserfsck --yes --fix-fixable --quiet " +
Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CANCEL_SAFE ); operationdetail, EXEC_CANCEL_SAFE );
bool success = ( exit_status == 0 || exit_status == 1 ); bool success = ( exit_status == 0 || exit_status == 1 );
set_status( operationdetail, success ); set_status( operationdetail, success );

View File

@ -120,7 +120,7 @@ bool udf::create( const Partition & new_partition, OperationDetail & operationde
// (from util-linux) prior to version v2.26 reads the Volume Identifier // (from util-linux) prior to version v2.26 reads the Volume Identifier
// (--vid). Therefore for compatibility reasons store the label in both // (--vid). Therefore for compatibility reasons store the label in both
// locations. // locations.
label_args = "--lvid=\"" + label + "\" " + "--vid=\"" + vid + "\" "; label_args = "--lvid=" + Glib::shell_quote( label ) + " --vid=" + Glib::shell_quote( vid ) + " ";
} }
// NOTE: UDF block size must match logical sector size of underlying media. // NOTE: UDF block size must match logical sector size of underlying media.
@ -129,7 +129,7 @@ bool udf::create( const Partition & new_partition, OperationDetail & operationde
// TODO: Add GUI option for choosing different optical disks and UDF revision. // TODO: Add GUI option for choosing different optical disks and UDF revision.
// For now format as UDF revision 2.01 for hard disk media type. // For now format as UDF revision 2.01 for hard disk media type.
return ! execute_command( "mkudffs --utf8 --media-type=hd --udfrev=0x201 " + return ! execute_command( "mkudffs --utf8 --media-type=hd --udfrev=0x201 " +
blocksize_args + label_args + new_partition.get_path(), blocksize_args + label_args + Glib::shell_quote( new_partition.get_path() ),
operationdetail, operationdetail,
EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE ); EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE );
} }

View File

@ -87,11 +87,9 @@ FS xfs::get_filesystem_support()
void xfs::set_used_sectors( Partition & partition ) void xfs::set_used_sectors( Partition & partition )
{ {
if ( ! Utils::execute_command( if ( ! Utils::execute_command( "xfs_db -c 'sb 0' -c 'print blocksize' -c 'print dblocks'"
"xfs_db -c 'sb 0' -c 'print blocksize' -c 'print dblocks' -c 'print fdblocks' -r " + partition .get_path(), " -c 'print fdblocks' -r " + Glib::shell_quote( partition.get_path() ),
output, output, error, true ) )
error,
true ) )
{ {
//blocksize //blocksize
if ( sscanf( output.c_str(), "blocksize = %lld", &S ) != 1 ) if ( sscanf( output.c_str(), "blocksize = %lld", &S ) != 1 )
@ -130,7 +128,8 @@ void xfs::set_used_sectors( Partition & partition )
void xfs::read_label( Partition & partition ) void xfs::read_label( Partition & partition )
{ {
if ( ! Utils::execute_command( "xfs_db -r -c 'label' " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "xfs_db -r -c 'label' " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
partition.set_filesystem_label( Utils::regexp_label( output, "^label = \"(.*)\"" ) ); partition.set_filesystem_label( Utils::regexp_label( output, "^label = \"(.*)\"" ) );
} }
@ -148,15 +147,17 @@ bool xfs::write_label( const Partition & partition, OperationDetail & operationd
{ {
Glib::ustring cmd = "" ; Glib::ustring cmd = "" ;
if( partition.get_filesystem_label().empty() ) if( partition.get_filesystem_label().empty() )
cmd = "xfs_admin -L -- " + partition .get_path() ; cmd = "xfs_admin -L -- " + Glib::shell_quote( partition.get_path() );
else else
cmd = "xfs_admin -L \"" + partition.get_filesystem_label() + "\" " + partition.get_path(); cmd = "xfs_admin -L " + Glib::shell_quote( partition.get_filesystem_label() ) +
" " + partition.get_path();
return ! execute_command( cmd, operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( cmd, operationdetail, EXEC_CHECK_STATUS );
} }
void xfs::read_uuid( Partition & partition ) void xfs::read_uuid( Partition & partition )
{ {
if ( ! Utils::execute_command( "xfs_admin -u " + partition .get_path(), output, error, true ) ) if ( ! Utils::execute_command( "xfs_admin -u " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
{ {
partition .uuid = Utils::regexp_label( output, "^UUID[[:blank:]]*=[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ; partition .uuid = Utils::regexp_label( output, "^UUID[[:blank:]]*=[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ;
} }
@ -172,13 +173,14 @@ void xfs::read_uuid( Partition & partition )
bool xfs::write_uuid( const Partition & partition, OperationDetail & operationdetail ) bool xfs::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "xfs_admin -U generate " + partition.get_path(), operationdetail, EXEC_CHECK_STATUS ); return ! execute_command( "xfs_admin -U generate " + Glib::shell_quote( partition.get_path() ),
operationdetail, EXEC_CHECK_STATUS );
} }
bool xfs::create( const Partition & new_partition, OperationDetail & operationdetail ) bool xfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "mkfs.xfs -f -L \"" + new_partition.get_filesystem_label() + "\" " + return ! execute_command( "mkfs.xfs -f -L " + Glib::shell_quote( new_partition.get_filesystem_label() ) +
new_partition.get_path(), " " + Glib::shell_quote( new_partition.get_path() ),
operationdetail, operationdetail,
EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE ); EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE );
} }
@ -193,8 +195,8 @@ bool xfs::resize( const Partition & partition_new, OperationDetail & operationde
mount_point = mk_temp_dir( "", operationdetail ) ; mount_point = mk_temp_dir( "", operationdetail ) ;
if ( mount_point.empty() ) if ( mount_point.empty() )
return false ; return false ;
success &= ! execute_command( "mount -v -t xfs " + partition_new .get_path() + success &= ! execute_command( "mount -v -t xfs " + Glib::shell_quote( partition_new.get_path() ) +
" \"" + mount_point + "\"", " " + Glib::shell_quote( mount_point ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
else else
@ -202,11 +204,11 @@ bool xfs::resize( const Partition & partition_new, OperationDetail & operationde
if ( success ) if ( success )
{ {
success &= ! execute_command( "xfs_growfs \"" + mount_point + "\"", success &= ! execute_command( "xfs_growfs " + Glib::shell_quote( mount_point ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
if ( ! partition_new .busy ) if ( ! partition_new .busy )
success &= ! execute_command( "umount -v \"" + mount_point + "\"", success &= ! execute_command( "umount -v " + Glib::shell_quote( mount_point ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
@ -222,8 +224,8 @@ bool xfs::copy( const Partition & src_part,
{ {
bool success = true ; bool success = true ;
success &= ! execute_command( "mkfs.xfs -f " + dest_part.get_path(), operationdetail, success &= ! execute_command( "mkfs.xfs -f " + Glib::shell_quote( dest_part.get_path() ),
EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE ); operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE );
if ( ! success ) if ( ! success )
return false ; return false ;
@ -238,8 +240,8 @@ bool xfs::copy( const Partition & src_part,
return false ; return false ;
} }
success &= ! execute_command( "mount -v -t xfs -o noatime,ro " + src_part.get_path() + success &= ! execute_command( "mount -v -t xfs -o noatime,ro " + Glib::shell_quote( src_part.get_path() ) +
" \"" + src_mount_point + "\"", " " + Glib::shell_quote( src_mount_point ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
// Get source FS used bytes, needed in progress update calculation // Get source FS used bytes, needed in progress update calculation
@ -252,8 +254,8 @@ bool xfs::copy( const Partition & src_part,
if ( success ) if ( success )
{ {
success &= ! execute_command( "mount -v -t xfs " + dest_part.get_path() + success &= ! execute_command( "mount -v -t xfs " + Glib::shell_quote( dest_part.get_path() ) +
" \"" + dest_mount_point + "\"", " " + Glib::shell_quote( dest_mount_point ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
if ( success ) if ( success )
@ -265,11 +267,11 @@ bool xfs::copy( const Partition & src_part,
EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE|EXEC_PROGRESS_TIMED, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE|EXEC_PROGRESS_TIMED,
static_cast<TimedSlot>( sigc::mem_fun( *this, &xfs::copy_progress ) ) ); static_cast<TimedSlot>( sigc::mem_fun( *this, &xfs::copy_progress ) ) );
success &= ! execute_command( "umount -v \"" + dest_mount_point + "\"", success &= ! execute_command( "umount -v " + Glib::shell_quote( dest_mount_point ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
success &= ! execute_command( "umount -v \"" + src_mount_point + "\"", success &= ! execute_command( "umount -v " + Glib::shell_quote( src_mount_point ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
@ -282,8 +284,8 @@ bool xfs::copy( const Partition & src_part,
bool xfs::check_repair( const Partition & partition, OperationDetail & operationdetail ) bool xfs::check_repair( const Partition & partition, OperationDetail & operationdetail )
{ {
return ! execute_command( "xfs_repair -v " + partition .get_path(), operationdetail, return ! execute_command( "xfs_repair -v " + Glib::shell_quote( partition.get_path() ),
EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE ); operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE );
} }
//Private methods //Private methods