From 682283ce89cc838d6ffbf5da9ed5ecf38b13c213 Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Sat, 17 Jun 2006 08:56:24 +0000 Subject: [PATCH] cleanups in the core and the fs'es (create) * cleanups in the core and the fs'es (create) --- ChangeLog | 4 ++++ include/GParted_Core.h | 7 +++--- src/GParted_Core.cc | 48 ++++++++++++++++++++++++++++-------------- src/ext2.cc | 6 +----- src/ext3.cc | 6 +----- src/fat16.cc | 6 +----- src/fat32.cc | 6 +----- src/hfs.cc | 6 +----- src/jfs.cc | 6 +----- src/linux_swap.cc | 7 +----- src/ntfs.cc | 6 +----- src/reiser4.cc | 6 +----- src/reiserfs.cc | 6 +----- src/xfs.cc | 6 +----- 14 files changed, 51 insertions(+), 75 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4e77aee7..a52c3b86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-06-17 Bart Hakvoort + + * cleanups in the core and the fs'es (create) + 2006-06-04 Bart Hakvoort * src/GParted_Core.cc: removed 'EXPERIMENTAL' from move-message to diff --git a/include/GParted_Core.h b/include/GParted_Core.h index 88af9872..36dc2305 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -88,9 +88,10 @@ private: std::vector get_alternate_paths( const Glib::ustring & path ) ; void LP_Set_Used_Sectors( Partition & partition ); void set_flags( Partition & partition ) ; - bool create_empty_partition( Partition & new_partition, - std::vector & operation_details, - Sector min_size = 0 ) ; + bool create_partition( Partition & new_partition, + std::vector & operation_details, + Sector min_size = 0 ) ; + bool create_filesystem( const Partition & partition, std::vector & operation_details ) ; bool resize_container_partition( const Partition & partition_old, Partition & partition_new, bool fixed_start, diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index c3edf4b0..5b0436da 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -661,7 +661,7 @@ bool GParted_Core::apply_operation_to_disk( Operation * operation ) static_cast( operation ) ->block_size, operation ->operation_details .sub_details ) ; } - + return false ; } @@ -672,19 +672,15 @@ bool GParted_Core::create( const Device & device, if ( new_partition .type == GParted::TYPE_EXTENDED ) { - return create_empty_partition( new_partition, operation_details ) ; + return create_partition( new_partition, operation_details ) ; } - else if ( create_empty_partition( new_partition, operation_details, get_fs( new_partition .filesystem ) .MIN ) ) + else if ( create_partition( new_partition, operation_details, get_fs( new_partition .filesystem ) .MIN ) ) { - set_proper_filesystem( new_partition .filesystem ) ; - - //most likely this means the user created an unformatted partition, - //however in theory, it could also screw some errorhandling. - if ( ! p_filesystem ) + if ( new_partition .filesystem == GParted::FS_UNFORMATTED ) return true ; - - return set_partition_type( new_partition, operation_details ) && - p_filesystem ->Create( new_partition, operation_details ) ; + else + return set_partition_type( new_partition, operation_details ) && + create_filesystem( new_partition, operation_details ) ; } return false ; @@ -852,7 +848,7 @@ bool GParted_Core::move_partition( const Partition & partition_old, ped_device_close( lp_device ); - //FIXME: errorhandling moet stukken beter voordat we committen! + //FIXME: errorhandling needs to be improved! succes = resize_container_partition( partition_old, partition_new, false, @@ -941,7 +937,7 @@ bool GParted_Core::copy( const Partition & partition_src, { bool succes = true ; if ( partition_dest .status == GParted::STAT_NEW ) - succes = create_empty_partition( partition_dest, operation_details, min_size ) ; + succes = create_partition( partition_dest, operation_details, min_size ) ; if ( succes && set_partition_type( partition_dest, operation_details ) ) { @@ -1135,9 +1131,9 @@ void GParted_Core::LP_Set_Used_Sectors( Partition & partition ) partition .error = ped_error ; } -bool GParted_Core::create_empty_partition( Partition & new_partition, - std::vector & operation_details, - Sector min_size ) +bool GParted_Core::create_partition( Partition & new_partition, + std::vector & operation_details, + Sector min_size ) { operation_details .push_back( OperationDetails( _("create empty partition") ) ) ; @@ -1250,6 +1246,26 @@ bool GParted_Core::create_empty_partition( Partition & new_partition, return false ; } } + +bool GParted_Core::create_filesystem( const Partition & partition, std::vector & operation_details ) +{ + operation_details .push_back( OperationDetails( String::ucompose( + _("create new %1 filesystem"), + Utils::get_filesystem_string( partition .filesystem ) ) ) ) ; + + set_proper_filesystem( partition .filesystem ) ; + + if ( p_filesystem && p_filesystem ->Create( partition, operation_details .back() .sub_details ) ) + { + operation_details .back() .status = OperationDetails::SUCCES ; + return true ; + } + else + { + operation_details .back() .status = OperationDetails::ERROR ; + return false ; + } +} bool GParted_Core::resize_container_partition( const Partition & partition_old, Partition & partition_new, diff --git a/src/ext2.cc b/src/ext2.cc index 5e1b0669..6c143cb8 100644 --- a/src/ext2.cc +++ b/src/ext2.cc @@ -75,11 +75,7 @@ void ext2::Set_Used_Sectors( Partition & partition ) bool ext2::Create( const Partition & new_partition, std::vector & operation_details ) { - operation_details .push_back( OperationDetails( String::ucompose( - _("create new %1 filesystem"), - Utils::get_filesystem_string( GParted::FS_EXT2 ) ) ) ) ; - - if ( ! execute_command( "mkfs.ext2 " + new_partition .get_path(), operation_details .back() .sub_details ) ) + if ( ! execute_command( "mkfs.ext2 " + new_partition .get_path(), operation_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/ext3.cc b/src/ext3.cc index 599c426a..3af5ecc2 100644 --- a/src/ext3.cc +++ b/src/ext3.cc @@ -70,11 +70,7 @@ void ext3::Set_Used_Sectors( Partition & partition ) bool ext3::Create( const Partition & new_partition, std::vector & operation_details ) { - operation_details .push_back( OperationDetails( String::ucompose( - _("create new %1 filesystem"), - Utils::get_filesystem_string( GParted::FS_EXT3 ) ) ) ) ; - - if ( ! execute_command( "mkfs.ext3 " + new_partition .get_path(), operation_details .back() .sub_details ) ) + if ( ! execute_command( "mkfs.ext3 " + new_partition .get_path(), operation_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/fat16.cc b/src/fat16.cc index 92ee29d8..ab7506d4 100644 --- a/src/fat16.cc +++ b/src/fat16.cc @@ -75,11 +75,7 @@ void fat16::Set_Used_Sectors( Partition & partition ) bool fat16::Create( const Partition & new_partition, std::vector & operation_details ) { - operation_details .push_back( OperationDetails( String::ucompose( - _("create new %1 filesystem"), - Utils::get_filesystem_string( GParted::FS_FAT16 ) ) ) ) ; - - if ( ! execute_command( "mkdosfs -F16 -v " + new_partition .get_path(), operation_details .back() .sub_details ) ) + if ( ! execute_command( "mkdosfs -F16 -v " + new_partition .get_path(), operation_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/fat32.cc b/src/fat32.cc index f8e16e7d..36e969b3 100644 --- a/src/fat32.cc +++ b/src/fat32.cc @@ -76,11 +76,7 @@ void fat32::Set_Used_Sectors( Partition & partition ) bool fat32::Create( const Partition & new_partition, std::vector & operation_details ) { - operation_details .push_back( OperationDetails( String::ucompose( - _("create new %1 filesystem"), - Utils::get_filesystem_string( GParted::FS_FAT32 ) ) ) ) ; - - if ( ! execute_command( "mkdosfs -F32 -v " + new_partition .get_path(), operation_details .back() .sub_details ) ) + if ( ! execute_command( "mkdosfs -F32 -v " + new_partition .get_path(), operation_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/hfs.cc b/src/hfs.cc index 0784b445..8024c1fd 100644 --- a/src/hfs.cc +++ b/src/hfs.cc @@ -46,11 +46,7 @@ void hfs::Set_Used_Sectors( Partition & partition ) bool hfs::Create( const Partition & new_partition, std::vector & operation_details ) { - operation_details .push_back( OperationDetails( String::ucompose( - _("create new %1 filesystem"), - Utils::get_filesystem_string( GParted::FS_HFS ) ) ) ) ; - - if ( ! execute_command( "hformat " + new_partition .get_path(), operation_details .back() .sub_details ) ) + if ( ! execute_command( "hformat " + new_partition .get_path(), operation_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/jfs.cc b/src/jfs.cc index 1f437d11..8639b878 100644 --- a/src/jfs.cc +++ b/src/jfs.cc @@ -91,11 +91,7 @@ void jfs::Set_Used_Sectors( Partition & partition ) bool jfs::Create( const Partition & new_partition, std::vector & operation_details ) { - operation_details .push_back( OperationDetails( String::ucompose( - _("create new %1 filesystem"), - Utils::get_filesystem_string( GParted::FS_JFS ) ) ) ) ; - - if ( ! execute_command( "mkfs.jfs -q " + new_partition .get_path(), operation_details .back() .sub_details ) ) + if ( ! execute_command( "mkfs.jfs -q " + new_partition .get_path(), operation_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/linux_swap.cc b/src/linux_swap.cc index f7730899..7dad99aa 100644 --- a/src/linux_swap.cc +++ b/src/linux_swap.cc @@ -45,12 +45,7 @@ void linux_swap::Set_Used_Sectors( Partition & partition ) bool linux_swap::Create( const Partition & new_partition, std::vector & operation_details ) { - operation_details .push_back( - OperationDetails( String::ucompose( - _("create new %1 filesystem"), - Utils::get_filesystem_string( GParted::FS_LINUX_SWAP ) ) ) ) ; - - if ( ! execute_command( "mkswap " + new_partition .get_path(), operation_details .back() .sub_details ) ) + if ( ! execute_command( "mkswap " + new_partition .get_path(), operation_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/ntfs.cc b/src/ntfs.cc index e52b68d6..071ce7f0 100644 --- a/src/ntfs.cc +++ b/src/ntfs.cc @@ -69,11 +69,7 @@ void ntfs::Set_Used_Sectors( Partition & partition ) bool ntfs::Create( const Partition & new_partition, std::vector & operation_details ) { - operation_details .push_back( OperationDetails( String::ucompose( - _("create new %1 filesystem"), - Utils::get_filesystem_string( GParted::FS_NTFS ) ) ) ) ; - - if ( ! execute_command( "mkntfs -Q -vv " + new_partition .get_path(), operation_details .back() .sub_details ) ) + if ( ! execute_command( "mkntfs -Q -vv " + new_partition .get_path(), operation_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/reiser4.cc b/src/reiser4.cc index f7f1da27..d1e1a641 100644 --- a/src/reiser4.cc +++ b/src/reiser4.cc @@ -68,11 +68,7 @@ void reiser4::Set_Used_Sectors( Partition & partition ) bool reiser4::Create( const Partition & new_partition, std::vector & operation_details ) { - operation_details .push_back( OperationDetails( String::ucompose( - _("create new %1 filesystem"), - Utils::get_filesystem_string( GParted::FS_REISER4 ) ) ) ) ; - - if ( ! execute_command( "mkfs.reiser4 --yes " + new_partition .get_path(), operation_details .back() .sub_details ) ) + if ( ! execute_command( "mkfs.reiser4 --yes " + new_partition .get_path(), operation_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/reiserfs.cc b/src/reiserfs.cc index 64b5bc72..5405d4a3 100644 --- a/src/reiserfs.cc +++ b/src/reiserfs.cc @@ -73,11 +73,7 @@ void reiserfs::Set_Used_Sectors( Partition & partition ) bool reiserfs::Create( const Partition & new_partition, std::vector & operation_details ) { - operation_details .push_back( OperationDetails( String::ucompose( - _("create new %1 filesystem"), - Utils::get_filesystem_string( GParted::FS_REISERFS ) ) ) ) ; - - if ( ! execute_command( "mkreiserfs -f " + new_partition .get_path(), operation_details .back() .sub_details ) ) + if ( ! execute_command( "mkreiserfs -f " + new_partition .get_path(), operation_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ; diff --git a/src/xfs.cc b/src/xfs.cc index 9ee1635d..f346cf8e 100644 --- a/src/xfs.cc +++ b/src/xfs.cc @@ -93,11 +93,7 @@ void xfs::Set_Used_Sectors( Partition & partition ) bool xfs::Create( const Partition & new_partition, std::vector & operation_details ) { - operation_details .push_back( OperationDetails( String::ucompose( - _("create new %1 filesystem"), - Utils::get_filesystem_string( GParted::FS_XFS ) ) ) ) ; - - if ( ! execute_command( "mkfs.xfs -f " + new_partition .get_path(), operation_details .back() .sub_details ) ) + if ( ! execute_command( "mkfs.xfs -f " + new_partition .get_path(), operation_details ) ) { operation_details .back() .status = OperationDetails::SUCCES ; return true ;