[gparted] Add resize support to nilfs2 (#642842)



commit 15bca17a46e990f4757b8b7a9a83c5c1496ba3f2
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Tue Dec 27 18:31:10 2011 +0000

    Add resize support to nilfs2 (#642842)
    
    Resizing requires nilfs-utils 2.1 or higher and Linux 3.0 or higher.
    
    Closes Bug #642842 - nilfs is not detected

 src/nilfs2.cc |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 3 deletions(-)
---
diff --git a/src/nilfs2.cc b/src/nilfs2.cc
index bad4641..bf66b85 100644
--- a/src/nilfs2.cc
+++ b/src/nilfs2.cc
@@ -38,9 +38,40 @@ FS nilfs2::get_filesystem_support()
 		fs .write_label = GParted::FS::EXTERNAL ;
 	}
 
+        //Nilfs2 resizing is an online only operation and needs:
+        //  mount, umount, nilfs-resize and linux >= 3.0 with nilfs2 support.
+        if ( ! Glib::find_program_in_path( "mount" ) .empty()        &&
+             ! Glib::find_program_in_path( "umount" ) .empty()       &&
+             ! Glib::find_program_in_path( "nilfs-resize" ) .empty() &&
+             Utils::kernel_supports_fs( "nilfs2" )                      )
+        {
+                std::ifstream input( "/proc/version" ) ;
+                std::string line ;
+                int linux_major_ver = -1 ;
+                int linux_minor_ver = -1 ;
+                int linux_patch_ver = -1 ;
+                if ( input )
+                {
+                        getline( input, line ) ;
+                        sscanf( line .c_str() , "Linux version %d.%d.%d",
+			        &linux_major_ver, &linux_minor_ver, &linux_patch_ver ) ;
+                        input .close() ;
+                }
+
+                if ( linux_major_ver >= 3 )
+                {
+                        fs .grow = GParted::FS::EXTERNAL ;
+                        if ( fs .read ) //needed to determine a minimum file system size.
+                                fs .shrink = GParted::FS::EXTERNAL ;
+                }
+        }
+
 	fs .copy = GParted::FS::GPARTED ;
 	fs .move = GParted::FS::GPARTED ;
 
+	//Minimum FS size is 128M+4K using mkfs.nilfs2 defaults
+	fs .MIN = 128 * MEBIBYTE + 4 * KIBIBYTE ;
+
 	return fs ;
 }
 
@@ -103,9 +134,32 @@ bool nilfs2::create( const Partition & new_partition, OperationDetail & operatio
 
 bool nilfs2::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
 {
-	//FIXME: Implement file system resizing.  Must be mounted like
-	//  xfs, jfs and btrfs.
-	return true ;
+	bool success = true ;
+
+	Glib::ustring mount_point = mk_temp_dir( "", operationdetail ) ;
+	if ( mount_point .empty() )
+		return false ;
+
+	success &= ! execute_command_timed( "mount -v -t nilfs2 " + partition_new .get_path() + " " + mount_point,
+	                                    operationdetail ) ;
+
+	if ( success )
+	{
+		Glib::ustring cmd = "nilfs-resize -v -y " + partition_new .get_path() ;
+		if ( ! fill_partition )
+		{
+			Glib::ustring size = Utils::num_to_str( floor( Utils::sector_to_unit(
+					partition_new .get_sector_length(), partition_new .sector_size, UNIT_KIB ) ) ) + "K" ;
+			cmd += " " + size ;
+		}
+		success &= ! execute_command_timed( cmd, operationdetail ) ;
+
+		success &= ! execute_command_timed( "umount -v " + mount_point, operationdetail ) ;
+	}
+
+	rm_temp_dir( mount_point, operationdetail ) ;
+
+	return success ;
 }
 
 bool nilfs2::move( const Partition & partition_new



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