cleanups in the core and the fs'es (check/repair)

* cleanups in the core and the fs'es (check/repair)
This commit is contained in:
Bart Hakvoort 2006-06-17 09:55:32 +00:00
parent 3094aeaabe
commit 20d5650188
12 changed files with 62 additions and 79 deletions

View File

@ -1,3 +1,7 @@
2006-06-17 Bart Hakvoort <hakvoort@cvs.gnome.org>
* cleanups in the core and the fs'es (check/repair)
2006-06-17 Bart Hakvoort <hakvoort@cvs.gnome.org> 2006-06-17 Bart Hakvoort <hakvoort@cvs.gnome.org>
* src/GParted_Core.cc: use new create_filesystem() in format() * src/GParted_Core.cc: use new create_filesystem() in format()

View File

@ -92,11 +92,11 @@ private:
std::vector<OperationDetails> & operation_details, std::vector<OperationDetails> & operation_details,
Sector min_size = 0 ) ; Sector min_size = 0 ) ;
bool create_filesystem( const Partition & partition, std::vector<OperationDetails> & operation_details ) ; bool create_filesystem( const Partition & partition, std::vector<OperationDetails> & operation_details ) ;
bool resize_container_partition( const Partition & partition_old, bool resize_partition( const Partition & partition_old,
Partition & partition_new, Partition & partition_new,
bool fixed_start, bool fixed_start,
std::vector<OperationDetails> & operation_details, std::vector<OperationDetails> & operation_details,
Sector min_size = 0 ) ; Sector min_size = 0 ) ;
bool resize_normal_using_libparted( const Partition & partition_old, bool resize_normal_using_libparted( const Partition & partition_old,
Partition & partition_new, Partition & partition_new,
std::vector<OperationDetails> & operation_details ) ; std::vector<OperationDetails> & operation_details ) ;
@ -104,6 +104,7 @@ private:
const Partition & partition_dest, const Partition & partition_dest,
std::vector<OperationDetails> & operation_details, std::vector<OperationDetails> & operation_details,
Sector block_size ) ; Sector block_size ) ;
bool check_repair( const Partition & partition, std::vector<OperationDetails> & operation_details ) ;
void set_proper_filesystem( const FILESYSTEM & filesystem ) ; void set_proper_filesystem( const FILESYSTEM & filesystem ) ;
bool set_partition_type( const Partition & partition, bool set_partition_type( const Partition & partition,
std::vector<OperationDetails> & operation_details ) ; std::vector<OperationDetails> & operation_details ) ;

View File

@ -847,11 +847,11 @@ bool GParted_Core::move_partition( const Partition & partition_old,
ped_device_close( lp_device ); ped_device_close( lp_device );
//FIXME: errorhandling needs to be improved! //FIXME: errorhandling needs to be improved!
succes = resize_container_partition( partition_old, succes = resize_partition( partition_old,
partition_new, partition_new,
false, false,
operation_details, operation_details,
partition_old .get_length() ) ; partition_old .get_length() ) ;
} }
close_device_and_disk() ; close_device_and_disk() ;
@ -867,22 +867,21 @@ bool GParted_Core::resize( const Device & device,
{ {
//extended partition //extended partition
if ( partition_old .type == GParted::TYPE_EXTENDED ) if ( partition_old .type == GParted::TYPE_EXTENDED )
return resize_container_partition( partition_old, partition_new, false, operation_details ) ; return resize_partition( partition_old, partition_new, false, operation_details ) ;
bool succes = false ; bool succes = false ;
set_proper_filesystem( partition_new .filesystem ) ;
//resize using libparted.. //resize using libparted..
if ( get_fs( partition_old .filesystem ) .grow == GParted::FS::LIBPARTED || if ( get_fs( partition_old .filesystem ) .grow == GParted::FS::LIBPARTED ||
get_fs( partition_old .filesystem ) .shrink == GParted::FS::LIBPARTED || get_fs( partition_old .filesystem ) .shrink == GParted::FS::LIBPARTED ||
get_fs( partition_old .filesystem ) .move == GParted::FS::LIBPARTED ) get_fs( partition_old .filesystem ) .move == GParted::FS::LIBPARTED )
{ {
if ( p_filesystem && p_filesystem ->Check_Repair( partition_new, operation_details ) ) if ( check_repair( partition_new, operation_details ) )
{ {
succes = resize_normal_using_libparted( partition_old, partition_new, operation_details ) ; succes = resize_normal_using_libparted( partition_old, partition_new, operation_details ) ;
//always check after a resize, but if it failes the whole operation failes //always check after a resize, but if it failes the whole operation failes
if ( ! p_filesystem ->Check_Repair( partition_new, operation_details ) ) if ( ! check_repair( partition_new, operation_details ) )
succes = false ; succes = false ;
} }
@ -890,9 +889,10 @@ bool GParted_Core::resize( const Device & device,
} }
//use custom resize tools.. //use custom resize tools..
if ( p_filesystem && p_filesystem ->Check_Repair( partition_new, operation_details ) ) if ( check_repair( partition_new, operation_details ) )
{ {
succes = true ; succes = true ;
set_proper_filesystem( partition_new .filesystem ) ;
if ( partition_new .get_length() < partition_old .get_length() ) if ( partition_new .get_length() < partition_old .get_length() )
{ {
@ -901,21 +901,21 @@ bool GParted_Core::resize( const Device & device,
} }
if ( succes ) if ( succes )
succes = resize_container_partition( succes = resize_partition(
partition_old, partition_old,
partition_new, partition_new,
! get_fs( partition_new .filesystem ) .move, ! get_fs( partition_new .filesystem ) .move,
operation_details ) ; operation_details ) ;
//these 3 are always executed, however, if 1 of them fails the whole operation fails //these 3 are always executed, however, if 1 of them fails the whole operation fails
if ( ! p_filesystem ->Check_Repair( partition_new, operation_details ) ) if ( ! check_repair( partition_new, operation_details ) )
succes = false ; succes = false ;
//expand filesystem to fit exactly in partition //expand filesystem to fit exactly in partition
if ( ! p_filesystem ->Resize( partition_new, operation_details, true ) ) if ( ! p_filesystem ->Resize( partition_new, operation_details, true ) )
succes = false ; succes = false ;
if ( ! p_filesystem ->Check_Repair( partition_new, operation_details ) ) if ( ! check_repair( partition_new, operation_details ) )
succes = false ; succes = false ;
return succes ; return succes ;
@ -930,8 +930,7 @@ bool GParted_Core::copy( const Partition & partition_src,
Sector block_size, Sector block_size,
std::vector<OperationDetails> & operation_details ) std::vector<OperationDetails> & operation_details )
{ {
set_proper_filesystem( partition_dest .filesystem ) ; if ( check_repair( partition_src, operation_details ) )
if ( p_filesystem && p_filesystem ->Check_Repair( partition_src, operation_details ) )
{ {
bool succes = true ; bool succes = true ;
if ( partition_dest .status == GParted::STAT_NEW ) if ( partition_dest .status == GParted::STAT_NEW )
@ -943,6 +942,8 @@ bool GParted_Core::copy( const Partition & partition_src,
String::ucompose( _("copy filesystem of %1 to %2"), String::ucompose( _("copy filesystem of %1 to %2"),
partition_src .get_path(), partition_src .get_path(),
partition_dest .get_path() ) ) ) ; partition_dest .get_path() ) ) ) ;
set_proper_filesystem( partition_dest .filesystem ) ;
switch ( get_fs( partition_dest .filesystem ) .copy ) switch ( get_fs( partition_dest .filesystem ) .copy )
{ {
@ -969,9 +970,9 @@ bool GParted_Core::copy( const Partition & partition_src,
} }
return ( succes && return ( succes &&
p_filesystem ->Check_Repair( partition_dest, operation_details ) && check_repair( partition_dest, operation_details ) &&
p_filesystem ->Resize( partition_dest, operation_details, true ) && p_filesystem ->Resize( partition_dest, operation_details, true ) &&
p_filesystem ->Check_Repair( partition_dest, operation_details ) ) ; check_repair( partition_dest, operation_details ) ) ;
} }
} }
@ -1265,11 +1266,11 @@ bool GParted_Core::create_filesystem( const Partition & partition, std::vector<O
} }
} }
bool GParted_Core::resize_container_partition( const Partition & partition_old, bool GParted_Core::resize_partition( const Partition & partition_old,
Partition & partition_new, Partition & partition_new,
bool fixed_start, bool fixed_start,
std::vector<OperationDetails> & operation_details, std::vector<OperationDetails> & operation_details,
Sector min_size ) Sector min_size )
{ {
operation_details .push_back( OperationDetails( _("resize partition") ) ) ; operation_details .push_back( OperationDetails( _("resize partition") ) ) ;
@ -1555,6 +1556,26 @@ bool GParted_Core::copy_filesystem( const Partition & partition_src,
operation_details .back() .status = succes ? OperationDetails::SUCCES : OperationDetails::ERROR ; operation_details .back() .status = succes ? OperationDetails::SUCCES : OperationDetails::ERROR ;
return succes ; return succes ;
} }
bool GParted_Core::check_repair( const Partition & partition, std::vector<OperationDetails> & operation_details )
{
operation_details .push_back( OperationDetails(
String::ucompose( _("check filesystem on %1 for errors and (if possible) fix them"),
partition .get_path() ) ) ) ;
set_proper_filesystem( partition .filesystem ) ;
if ( p_filesystem && p_filesystem ->Check_Repair( partition, operation_details .back() .sub_details ) )
{
operation_details .back() .status = OperationDetails::SUCCES ;
return true ;
}
else
{
operation_details .back() .status = OperationDetails::ERROR ;
return false ;
}
}
void GParted_Core::set_flags( Partition & partition ) void GParted_Core::set_flags( Partition & partition )
{ {

View File

@ -123,12 +123,7 @@ bool ext2::Copy( const Glib::ustring & src_part_path,
bool ext2::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details ) bool ext2::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details )
{ {
operation_details .push_back( OperationDetails( exit_status = execute_command( "e2fsck -f -y -v " + partition .get_path(), operation_details ) ;
String::ucompose( _("check filesystem on %1 for errors and (if possible) fix them"),
partition .get_path() ) ) ) ;
exit_status = execute_command( "e2fsck -f -y -v " + partition .get_path(),
operation_details .back() .sub_details ) ;
//exitstatus 256 isn't documented, but it's returned when the 'FILESYSTEM IS MODIFIED' //exitstatus 256 isn't documented, but it's returned when the 'FILESYSTEM IS MODIFIED'
//this is quite normal (especially after a copy) so we let the function return true... //this is quite normal (especially after a copy) so we let the function return true...

View File

@ -118,12 +118,7 @@ bool ext3::Copy( const Glib::ustring & src_part_path,
bool ext3::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details ) bool ext3::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details )
{ {
operation_details .push_back( OperationDetails( exit_status = execute_command( "e2fsck -f -y -v " + partition .get_path(), operation_details ) ;
String::ucompose( _("check filesystem on %1 for errors and (if possible) fix them"),
partition .get_path() ) ) ) ;
exit_status = execute_command( "e2fsck -f -y -v " + partition .get_path(),
operation_details .back() .sub_details ) ;
//exitstatus 256 isn't documented, but it's returned when the 'FILESYSTEM IS MODIFIED' //exitstatus 256 isn't documented, but it's returned when the 'FILESYSTEM IS MODIFIED'
//this is quite normal (especially after a copy) so we let the function return true... //this is quite normal (especially after a copy) so we let the function return true...

View File

@ -103,12 +103,7 @@ bool fat16::Copy( const Glib::ustring & src_part_path,
bool fat16::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details ) bool fat16::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details )
{ {
operation_details .push_back( OperationDetails( exit_status = execute_command( "dosfsck -a -w -v " + partition .get_path(), operation_details ) ;
String::ucompose( _("check filesystem on %1 for errors and (if possible) fix them"),
partition .get_path() ) ) ) ;
exit_status = execute_command( "dosfsck -a -w -v " + partition .get_path(),
operation_details .back() .sub_details ) ;
if ( exit_status == 0 || exit_status == 1 ) if ( exit_status == 0 || exit_status == 1 )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;

View File

@ -104,12 +104,7 @@ bool fat32::Copy( const Glib::ustring & src_part_path,
bool fat32::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details ) bool fat32::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details )
{ {
operation_details .push_back( OperationDetails( exit_status = execute_command( "dosfsck -a -w -v " + partition .get_path(), operation_details ) ;
String::ucompose( _("check filesystem on %1 for errors and (if possible) fix them"),
partition .get_path() ) ) ) ;
exit_status = execute_command( "dosfsck -a -w -v " + partition .get_path(),
operation_details .back() .sub_details ) ;
if ( exit_status == 0 || exit_status == 1 ) if ( exit_status == 0 || exit_status == 1 )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;

View File

@ -204,11 +204,7 @@ bool jfs::Copy( const Glib::ustring & src_part_path,
bool jfs::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details ) bool jfs::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details )
{ {
operation_details .push_back( OperationDetails( exit_status = execute_command( "jfs_fsck -f " + partition .get_path(), operation_details ) ;
String::ucompose( _("check filesystem on %1 for errors and (if possible) fix them"),
partition .get_path() ) ) ) ;
exit_status = execute_command( "jfs_fsck -f " + partition .get_path(), operation_details .back() .sub_details ) ;
if ( exit_status == 0 || exit_status == 1 ) if ( exit_status == 0 || exit_status == 1 )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;

View File

@ -149,12 +149,7 @@ bool ntfs::Copy( const Glib::ustring & src_part_path,
bool ntfs::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details ) bool ntfs::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details )
{ {
operation_details .push_back( OperationDetails( if ( ! execute_command( "ntfsresize -P -i -f -v " + partition .get_path(), operation_details ) )
String::ucompose( _("check filesystem on %1 for errors and (if possible) fix them"),
partition .get_path() ) ) ) ;
if ( ! execute_command( "ntfsresize -P -i -f -v " + partition .get_path(),
operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;

View File

@ -96,12 +96,7 @@ bool reiser4::Copy( const Glib::ustring & src_part_path,
bool reiser4::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details ) bool reiser4::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details )
{ {
operation_details .push_back( OperationDetails( if ( ! execute_command( "fsck.reiser4 --yes --fix " + partition .get_path(), operation_details ) )
String::ucompose( _("check filesystem on %1 for errors and (if possible) fix them"),
partition .get_path() ) ) ) ;
if ( ! execute_command( "fsck.reiser4 --yes --fix " + partition .get_path(),
operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;

View File

@ -125,12 +125,7 @@ bool reiserfs::Copy( const Glib::ustring & src_part_path,
bool reiserfs::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details ) bool reiserfs::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details )
{ {
operation_details .push_back( OperationDetails( exit_status = execute_command( "reiserfsck --y --fix-fixable " + partition .get_path(), operation_details ) ;
String::ucompose( _("check filesystem on %1 for errors and (if possible) fix them"),
partition .get_path() ) ) ) ;
exit_status = execute_command( "reiserfsck --y --fix-fixable " + partition .get_path(),
operation_details .back() .sub_details ) ;
if ( exit_status == 0 || exit_status == 1 || exit_status == 256 ) if ( exit_status == 0 || exit_status == 1 || exit_status == 256 )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;

View File

@ -348,11 +348,7 @@ bool xfs::Copy( const Glib::ustring & src_part_path,
bool xfs::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details ) bool xfs::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details )
{ {
operation_details .push_back( OperationDetails( if ( ! execute_command( "xfs_repair -v " + partition .get_path(), operation_details ) )
String::ucompose( _("check filesystem on %1 for errors and (if possible) fix them"),
partition .get_path() ) ) ) ;
if ( ! execute_command( "xfs_repair -v " + partition .get_path(), operation_details .back() .sub_details ) )
{ {
operation_details .back() .status = OperationDetails::SUCCES ; operation_details .back() .status = OperationDetails::SUCCES ;
return true ; return true ;