cleanups in the core and the fs'es (resize)

* cleanups in the core and the fs'es (resize)
This commit is contained in:
Bart Hakvoort 2006-06-17 14:44:17 +00:00
parent 8b4136b84d
commit 08245cd08c
9 changed files with 108 additions and 97 deletions

View File

@ -1,3 +1,7 @@
2006-06-17 Bart Hakvoort <hakvoort@cvs.gnome.org>
* cleanups in the core and the fs'es (resize)
2006-06-17 Bart Hakvoort <hakvoort@cvs.gnome.org>
* cleanups in the core and the fs'es (check/repair)

View File

@ -65,6 +65,12 @@ private:
const Partition & partition_old,
Partition & partition_new,
std::vector<OperationDetails> & operation_detail ) ;
bool resize_filesystem( const Partition & partition_old,
const Partition & partition_new,
std::vector<OperationDetails> & operation_details,
Sector cylinder_size = 0,
bool fill_partition = false ) ;
bool copy( const Partition & partition_src,
Partition & partition_dest,
Sector min_size,
@ -105,7 +111,7 @@ private:
std::vector<OperationDetails> & operation_details,
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, Sector cylinder_size = 0 ) ;
bool set_partition_type( const Partition & partition,
std::vector<OperationDetails> & operation_details ) ;
bool wait_for_node( const Glib::ustring & node ) ;

View File

@ -892,13 +892,9 @@ bool GParted_Core::resize( const Device & device,
if ( check_repair( partition_new, operation_details ) )
{
succes = true ;
set_proper_filesystem( partition_new .filesystem ) ;
//FIXME, find another way to resolve this cylsize problem...
if ( partition_new .get_length() < partition_old .get_length() )
{
p_filesystem ->cylinder_size = device .cylsize ;
succes = p_filesystem ->Resize( partition_new, operation_details ) ;
}
succes = resize_filesystem( partition_old, partition_new, operation_details, device .cylsize ) ;
if ( succes )
succes = resize_partition(
@ -912,7 +908,7 @@ bool GParted_Core::resize( const Device & device,
succes = false ;
//expand filesystem to fit exactly in partition
if ( ! p_filesystem ->Resize( partition_new, operation_details, true ) )
if ( ! resize_filesystem( partition_old, partition_new, operation_details, device .cylsize, true ) )
succes = false ;
if ( ! check_repair( partition_new, operation_details ) )
@ -923,6 +919,35 @@ bool GParted_Core::resize( const Device & device,
return false ;
}
bool GParted_Core::resize_filesystem( const Partition & partition_old,
const Partition & partition_new,
std::vector<OperationDetails> & operation_details,
Sector cylinder_size,
bool fill_partition )
{
if ( fill_partition )
operation_details .push_back( OperationDetails( _("grow filesystem to fill the partition") ) ) ;
else if ( partition_new .get_length() < partition_old .get_length() )
operation_details .push_back( OperationDetails( _("shrink filesystem") ) ) ;
else if ( partition_new .get_length() > partition_old .get_length() )
operation_details .push_back( OperationDetails( _("grow filesystem") ) ) ;
else
operation_details .push_back(
OperationDetails( _("new and old partition have the same size. continuing anyway") ) ) ;
set_proper_filesystem( partition_new .filesystem, cylinder_size ) ;
if ( p_filesystem && p_filesystem ->Resize( partition_new, operation_details .back() .sub_details, fill_partition ) )
{
operation_details .back() .status = OperationDetails::SUCCES ;
return true ;
}
else
{
operation_details .back() .status = OperationDetails::ERROR ;
return false ;
}
}
bool GParted_Core::copy( const Partition & partition_src,
Partition & partition_dest,
@ -1272,7 +1297,13 @@ bool GParted_Core::resize_partition( const Partition & partition_old,
std::vector<OperationDetails> & operation_details,
Sector min_size )
{
operation_details .push_back( OperationDetails( _("resize partition") ) ) ;
if ( partition_new .get_length() < partition_old .get_length() )
operation_details .push_back( OperationDetails( _("shrink partition") ) ) ;
else if ( partition_new .get_length() > partition_old .get_length() )
operation_details .push_back( OperationDetails( _("grow partition") ) ) ;
else
operation_details .push_back(
OperationDetails( _("new and old partition have the same size. continuing anyway") ) ) ;
operation_details .back() .sub_details .push_back(
OperationDetails(
@ -1585,7 +1616,7 @@ void GParted_Core::set_flags( Partition & partition )
partition .flags .push_back( ped_partition_flag_get_name( flags[ t ] ) ) ;
}
void GParted_Core::set_proper_filesystem( const FILESYSTEM & filesystem )
void GParted_Core::set_proper_filesystem( const FILESYSTEM & filesystem, Sector cylinder_size )
{
if ( p_filesystem )
delete p_filesystem ;
@ -1608,6 +1639,9 @@ void GParted_Core::set_proper_filesystem( const FILESYSTEM & filesystem )
default : p_filesystem = NULL ;
}
if ( p_filesystem )
p_filesystem ->cylinder_size = cylinder_size ;
}
bool GParted_Core::set_partition_type( const Partition & partition,

View File

@ -91,18 +91,13 @@ bool ext2::Resize( const Partition & partition_new,
std::vector<OperationDetails> & operation_details,
bool fill_partition )
{
if ( fill_partition )
operation_details .push_back( OperationDetails( _("grow filesystem to fill the partition") ) ) ;
else
operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
Glib::ustring str_temp = "resize2fs " + partition_new .get_path() ;
if ( ! fill_partition )
str_temp += " " + Utils::num_to_str( Utils::round( Utils::sector_to_unit(
partition_new .get_length() - cylinder_size, GParted::UNIT_MIB ) ), true ) + "M" ;
if ( ! execute_command( str_temp, operation_details .back() .sub_details ) )
if ( ! execute_command( str_temp, operation_details ) )
{
operation_details .back() .status = OperationDetails::SUCCES ;
return true ;

View File

@ -86,18 +86,13 @@ bool ext3::Resize( const Partition & partition_new,
std::vector<OperationDetails> & operation_details,
bool fill_partition )
{
if ( fill_partition )
operation_details .push_back( OperationDetails( _("grow filesystem to fill the partition") ) ) ;
else
operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
Glib::ustring str_temp = "resize2fs " + partition_new .get_path() ;
if ( ! fill_partition )
str_temp += " " + Utils::num_to_str( Utils::round( Utils::sector_to_unit(
partition_new .get_length() - cylinder_size, GParted::UNIT_MIB ) ), true ) + "M" ;
if ( ! execute_command( str_temp, operation_details .back() .sub_details ) )
if ( ! execute_command( str_temp, operation_details ) )
{
operation_details .back() .status = OperationDetails::SUCCES ;
return true ;

View File

@ -107,78 +107,74 @@ bool jfs::Resize( const Partition & partition_new,
std::vector<OperationDetails> & operation_details,
bool fill_partition )
{
if ( fill_partition )
operation_details .push_back( OperationDetails( _("grow filesystem to fill the partition") ) ) ;
else
operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
bool return_value = false ;
Glib::ustring error ;
Glib::ustring TEMP_MP = Glib::get_tmp_dir() + "/gparted_tmp_jfs_mountpoint" ;
//create mountpoint...
operation_details .back() .sub_details .push_back(
operation_details .push_back(
OperationDetails( String::ucompose( _("create temporary mountpoint (%1)"), TEMP_MP ) ) ) ;
if ( ! mkdir( TEMP_MP .c_str(), 0 ) )
{
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
operation_details .back() .status = OperationDetails::SUCCES ;
//mount partition
operation_details .back() .sub_details .push_back(
operation_details .push_back(
OperationDetails( String::ucompose( _("mount %1 on %2"), partition_new .get_path(), TEMP_MP ) ) ) ;
if ( ! execute_command( "mount -v -t jfs " + partition_new .get_path() + " " + TEMP_MP,
operation_details .back() .sub_details .back() .sub_details ) )
operation_details .back() .sub_details ) )
{
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
operation_details .back() .status = OperationDetails::SUCCES ;
//remount the partition to resize the filesystem
operation_details .back() .sub_details .push_back(
operation_details .push_back(
OperationDetails( String::ucompose( _("remount %1 on %2 with the 'resize' flag enabled"),
partition_new .get_path(), TEMP_MP ) ) ) ;
if ( ! execute_command( "mount -v -t jfs -o remount,resize " + partition_new .get_path() + " " + TEMP_MP,
operation_details .back() .sub_details .back() .sub_details ) )
if ( ! execute_command(
"mount -v -t jfs -o remount,resize " + partition_new .get_path() + " " + TEMP_MP,
operation_details .back() .sub_details ) )
{
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
operation_details .back() .status = OperationDetails::SUCCES ;
return_value = true ;
}
else
{
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .status = OperationDetails::ERROR ;
}
//and unmount it...
operation_details .back() .sub_details .push_back(
operation_details .push_back(
OperationDetails( String::ucompose( _("unmount %1"), partition_new .get_path() ) ) ) ;
if ( ! execute_command( "umount -v " + partition_new .get_path(),
operation_details .back() .sub_details .back() .sub_details ) )
operation_details .back() .sub_details ) )
{
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
operation_details .back() .status = OperationDetails::SUCCES ;
}
else
{
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .status = OperationDetails::ERROR ;
return_value = false ;
}
}
else
{
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .status = OperationDetails::ERROR ;
}
//remove the mountpoint..
operation_details .back() .sub_details .push_back(
operation_details .push_back(
OperationDetails( String::ucompose( _("remove temporary mountpoint (%1)"), TEMP_MP ) ) ) ;
if ( ! rmdir( TEMP_MP .c_str() ) )
{
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
operation_details .back() .status = OperationDetails::SUCCES ;
}
else
{
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .sub_details .back() .sub_details .push_back(
operation_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .sub_details .push_back(
OperationDetails( Glib::strerror( errno ), OperationDetails::NONE ) ) ;
return_value = false ;
@ -186,12 +182,11 @@ bool jfs::Resize( const Partition & partition_new,
}
else
{
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .sub_details .back() .sub_details .push_back(
operation_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .sub_details .push_back(
OperationDetails( Glib::strerror( errno ), OperationDetails::NONE ) ) ;
}
operation_details .back() .status = return_value ? OperationDetails::SUCCES : OperationDetails::ERROR ;
return return_value ;
}

View File

@ -85,11 +85,6 @@ bool ntfs::Resize( const Partition & partition_new,
std::vector<OperationDetails> & operation_details,
bool fill_partition )
{
if ( fill_partition )
operation_details .push_back( OperationDetails( _("grow filesystem to fill the partition") ) ) ;
else
operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
bool return_value = false ;
Glib::ustring str_temp = "ntfsresize -P --force --force " + partition_new .get_path() ;
@ -101,32 +96,30 @@ bool ntfs::Resize( const Partition & partition_new,
}
//simulation..
operation_details .back() .sub_details .push_back( OperationDetails( _("run simulation") ) ) ;
operation_details .push_back( OperationDetails( _("run simulation") ) ) ;
if ( ! execute_command( str_temp + " --no-action", operation_details .back() .sub_details .back() .sub_details ) )
if ( ! execute_command( str_temp + " --no-action", operation_details .back() .sub_details ) )
{
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
operation_details .back() .status = OperationDetails::SUCCES ;
//real resize (use description from 'main' operation)
operation_details .back() .sub_details .push_back(
OperationDetails( operation_details .back() .description ) ) ;
//real resize
operation_details .push_back( OperationDetails( _("real resize") ) ) ;
if ( ! execute_command( str_temp, operation_details .back() .sub_details .back() .sub_details ) )
if ( ! execute_command( str_temp, operation_details .back() .sub_details ) )
{
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
operation_details .back() .status = OperationDetails::SUCCES ;
return_value = true ;
}
else
{
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .status = OperationDetails::ERROR ;
}
}
else
{
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .status = OperationDetails::ERROR ;
}
operation_details .back() .status = return_value ? OperationDetails::SUCCES : OperationDetails::ERROR ;
return return_value ;
}

View File

@ -89,11 +89,6 @@ bool reiserfs::Resize( const Partition & partition_new,
std::vector<OperationDetails> & operation_details,
bool fill_partition )
{
if ( fill_partition )
operation_details .push_back( OperationDetails( _("grow filesystem to fill the partition") ) ) ;
else
operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
Glib::ustring str_temp = "echo y | resize_reiserfs " + partition_new .get_path() ;
if ( ! fill_partition )
@ -103,7 +98,7 @@ bool reiserfs::Resize( const Partition & partition_new,
partition_new .get_length() - cylinder_size, GParted::UNIT_BYTE ) ), true ) ;
}
exit_status = execute_command( str_temp, operation_details .back() .sub_details ) ;
exit_status = execute_command( str_temp, operation_details ) ;
if ( exit_status == 0 || exit_status == 256 )
{
operation_details .back() .status = OperationDetails::SUCCES ;

View File

@ -109,76 +109,71 @@ bool xfs::Resize( const Partition & partition_new,
std::vector<OperationDetails> & operation_details,
bool fill_partition )
{
if ( fill_partition )
operation_details .push_back( OperationDetails( _("grow filesystem to fill the partition") ) ) ;
else
operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
bool return_value = false ;
Glib::ustring error ;
Glib::ustring TEMP_MP = Glib::get_tmp_dir() + "/gparted_tmp_xfs_mountpoint" ;
//create mountpoint...
operation_details .back() .sub_details .push_back(
operation_details .push_back(
OperationDetails( String::ucompose( _("create temporary mountpoint (%1)"), TEMP_MP ) ) ) ;
if ( ! mkdir( TEMP_MP .c_str(), 0 ) )
{
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
operation_details .back() .status = OperationDetails::SUCCES ;
//mount partition
operation_details .back() .sub_details .push_back(
operation_details .push_back(
OperationDetails( String::ucompose( _("mount %1 on %2"), partition_new .get_path(), TEMP_MP ) ) ) ;
if ( ! execute_command( "mount -v -t xfs " + partition_new .get_path() + " " + TEMP_MP,
operation_details .back() .sub_details .back() .sub_details ) )
operation_details .back() .sub_details ) )
{
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
operation_details .back() .status = OperationDetails::SUCCES ;
//grow the mounted filesystem..
operation_details .back() .sub_details .push_back( OperationDetails( _("grow mounted filesystem") ) ) ;
operation_details .push_back( OperationDetails( _("grow mounted filesystem") ) ) ;
if ( ! execute_command ( "xfs_growfs " + TEMP_MP,
operation_details .back() .sub_details .back() .sub_details ) )
operation_details .back() .sub_details ) )
{
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
operation_details .back() .status = OperationDetails::SUCCES ;
return_value = true ;
}
else
{
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .status = OperationDetails::ERROR ;
}
//and unmount it...
operation_details .back() .sub_details .push_back(
operation_details .push_back(
OperationDetails( String::ucompose( _("unmount %1"), partition_new .get_path() ) ) ) ;
if ( ! execute_command( "umount -v " + partition_new .get_path(),
operation_details .back() .sub_details .back() .sub_details ) )
operation_details .back() .sub_details ) )
{
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
operation_details .back() .status = OperationDetails::SUCCES ;
}
else
{
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .status = OperationDetails::ERROR ;
return_value = false ;
}
}
else
{
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .status = OperationDetails::ERROR ;
}
//remove the mountpoint..
operation_details .back() .sub_details .push_back(
operation_details .push_back(
OperationDetails( String::ucompose( _("remove temporary mountpoint (%1)"), TEMP_MP ) ) ) ;
if ( ! rmdir( TEMP_MP .c_str() ) )
{
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
operation_details .back() .status = OperationDetails::SUCCES ;
}
else
{
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .sub_details .back() .sub_details .push_back(
operation_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .sub_details .push_back(
OperationDetails( Glib::strerror( errno ), OperationDetails::NONE ) ) ;
return_value = false ;
@ -186,12 +181,11 @@ bool xfs::Resize( const Partition & partition_new,
}
else
{
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .sub_details .back() .sub_details .push_back(
operation_details .back() .status = OperationDetails::ERROR ;
operation_details .back() .sub_details .push_back(
OperationDetails( Glib::strerror( errno ), OperationDetails::NONE ) ) ;
}
operation_details .back() .status = return_value ? OperationDetails::SUCCES : OperationDetails::ERROR ;
return return_value ;
}