[gparted] Update jfs resize to use new helper functions



commit b0d818b8f9d364d27e0d370fded158393eb771d1
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Wed Dec 28 19:42:08 2011 +0000

    Update jfs resize to use new helper functions
    
    Also update jfs file system support detection to allow growing even when
    the jfs kernel module is not already loaded.

 src/jfs.cc |  116 +++++++++++-------------------------------------------------
 1 files changed, 21 insertions(+), 95 deletions(-)
---
diff --git a/src/jfs.cc b/src/jfs.cc
index d8b7f40..5410d46 100644
--- a/src/jfs.cc
+++ b/src/jfs.cc
@@ -44,27 +44,14 @@ FS jfs::get_filesystem_support()
 		fs .check = GParted::FS::EXTERNAL ;
 	
 	//resizing of jfs requires mount, unmount, check/repair functionality and jfs support in the kernel
-	if ( ! Glib::find_program_in_path( "mount" ) .empty() &&
+	if ( ! Glib::find_program_in_path( "mount" ) .empty()  &&
 	     ! Glib::find_program_in_path( "umount" ) .empty() &&
-	     fs .check )
+	     fs .check                                         &&
+	     Utils::kernel_supports_fs( "jfs" )                   )
 	{
-		std::ifstream input( "/proc/filesystems" ) ;
-		if ( input )
-		{
-			Glib::ustring line ;
-
-			while ( input >> line )
-				if ( line == "jfs" )
-				{
-					fs .grow = GParted::FS::EXTERNAL ;
-					break ;
-				}
-	
-			input .close() ;
-		}
+		fs .grow = GParted::FS::EXTERNAL ;
 	}
 
-
 	if ( fs .check )
 	{
 		fs .move = GParted::FS::GPARTED ;
@@ -133,87 +120,26 @@ bool jfs::create( const Partition & new_partition, OperationDetail & operationde
 
 bool jfs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
 {
-	bool return_value = false ;
-	Glib::ustring error ;
-	Glib::ustring TEMP_MP = Glib::get_tmp_dir() + "/gparted_tmp_jfs_mount_point" ;
-	
-	//create mount point...
-	operationdetail .add_child( OperationDetail( String::ucompose( _("create temporary mount point (%1)"), TEMP_MP ) ) ) ;
-	if ( ! mkdir( TEMP_MP .c_str(), 0 ) )
-	{
-		operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
+	bool success = true ;
 
-		//mount partition
-		operationdetail .add_child(
-			OperationDetail( 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,
-					operationdetail .get_last_child() ) )
-		{
-			operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
-			
-			//remount the partition to resize the file system
-			operationdetail .add_child(
-				OperationDetail( 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,
-					operationdetail .get_last_child() ) )
-			{
-				operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
-				return_value = true ;
-			}
-			else
-			{
-				operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
-			}
-			
-			//and unmount it...
-			operationdetail .add_child(
-				OperationDetail( String::ucompose( _("unmount %1"), partition_new .get_path() ) ) ) ;
-		
-			if ( ! execute_command( "umount -v " + partition_new .get_path(),
-						operationdetail .get_last_child() ) )
-			{
-				operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
-			}
-			else
-			{
-				operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
-				return_value = false ;
-			}
-		}
-		else
-		{
-			operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
-		}
-		
-		//remove the mount point..
-		operationdetail .add_child(
-			OperationDetail( String::ucompose( _("remove temporary mount point (%1)"), TEMP_MP ) ) ) ;
-		if ( ! rmdir( TEMP_MP .c_str() ) )
-		{
-			operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
-		}
-		else
-		{
-			operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
-			operationdetail .get_last_child() .add_child( 
-				OperationDetail( Glib::strerror( errno ), STATUS_NONE ) ) ;
-
-			return_value = false ;
-		}
-	}
-	else
+	Glib::ustring mount_point = mk_temp_dir( "", operationdetail ) ;
+	if ( mount_point .empty() )
+		return false ;
+
+	success &= ! execute_command_timed( "mount -v -t jfs " + partition_new .get_path() + " " + mount_point,
+	                                    operationdetail ) ;
+
+	if ( success )
 	{
-		operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
-		operationdetail .get_last_child() .add_child( 
-			OperationDetail( Glib::strerror( errno ), STATUS_NONE ) ) ;
+		success &= ! execute_command_timed( "mount -v -t jfs -o remount,resize " + partition_new .get_path() + " " + mount_point,
+		                                    operationdetail ) ;
+
+		success &= ! execute_command_timed( "umount -v " + mount_point, operationdetail ) ;
 	}
-	
-	return return_value ;
+
+	rm_temp_dir( mount_point, operationdetail ) ;
+
+	return success ;
 }
 
 bool jfs::move( const Partition & partition_new



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]