[gparted] Enable new fs resize library available with parted-3.1 (#668281)



commit 0fda1d011d79c2e0e4d884e03947f2e4e8cec986
Author: Curtis Gedak <gedakc gmail com>
Date:   Sat Mar 3 11:47:39 2012 -0700

    Enable new fs resize library available with parted-3.1 (#668281)
    
    The parted-3.1 release brings back FAT16/FAT32 and HFS/HFS+ file
    system resize capabilities in a new libparted fs resize library.
    
    The following operations are again available when GParted is linked
    with parted-3.1:
    
       FAT16 - grow and shrink
       FAT32 - grow and shrink
       HFS   - shrink
       HFS+  - shrink
    
    Note that there is a difference in how move actions are handled for
    FAT16/FAT32 file systems based on parted version.
    
    When GParted is linked with parted >= 3.0:
    
       FAT16 - move performed internally by GParted
       FAT32 - move performed internally by GParted
    
    When GParted is linked with parted < 3.0:
    
       FAT16 - move performed by libparted
       FAT32 - move performed by libparted
    
    Thanks goes to Jim Meyering for restoring these file system resizing
    capabilities in Parted 3.1 with a new libparted fs resize library.
    
    Closes Bug #668281 - minimal file-system resize API? (FAT and HFS*
                         only)

 configure.in           |   86 +++++++++++++++++++++++++++++++++++++++++-------
 include/GParted_Core.h |    9 +++--
 include/Utils.h        |    4 +--
 src/GParted_Core.cc    |   24 ++++++++++---
 src/Makefile.am        |    4 ++
 src/fat16.cc           |   10 +++--
 src/fat32.cc           |   10 +++--
 src/hfs.cc             |    8 ++--
 src/hfsplus.cc         |    8 ++--
 9 files changed, 123 insertions(+), 40 deletions(-)
---
diff --git a/configure.in b/configure.in
index 5d58ed9..ffaf6dd 100644
--- a/configure.in
+++ b/configure.in
@@ -173,13 +173,74 @@ int main ()
 }
 ], [AC_MSG_RESULT([yes])
   AC_DEFINE([HAVE_LIBPARTED_3_0_0_PLUS], [1], [Define to 1 if libparted >= 3.0])
-  have_lp_fs_resize_api=no]
+  have_old_lp_fs_resize_api=no]
 , [AC_MSG_RESULT([no])
-  have_lp_fs_resize_api=yes]
+  have_old_lp_fs_resize_api=yes]
 )
 LIBS="$LIBS_save"
 
 
+dnl======================
+dnl check whether libparted >= 3.1 (libparted has new file system resizing LIB)
+dnl======================
+LIBPARTED_VERSION=3.1
+AC_MSG_CHECKING([if libparted >= $LIBPARTED_VERSION (libparted has new file system resizing LIB)])
+LIBS_save="$LIBS"
+LIBS="-lparted -luuid -ldl"
+need_work_around=yes
+AC_TRY_RUN([
+#include <stdio.h>
+#include <parted/parted.h>
+
+int main ()
+{
+	int min_major = 0;
+	int min_minor = 0;
+	int min_micro = 0;
+	int major = 0;
+	int minor = 0;
+	int micro = 0;
+
+	if ( ( sscanf( "$LIBPARTED_VERSION", "%d.%d.%d", &min_major, &min_minor, &min_micro ) == 3 ) ||
+	     ( sscanf( "$LIBPARTED_VERSION", "%d.%d", &min_major, &min_minor ) == 2 ) ||
+	     ( sscanf( "$LIBPARTED_VERSION", "%d", &min_major ) == 1 )
+	   )
+	{
+		if ( ( sscanf( ped_get_version(), "%d.%d.%d", &major, &minor, &micro ) == 3 ) ||
+		     ( sscanf( ped_get_version(), "%d.%d", &major, &minor ) == 2 ) ||
+		     ( sscanf( ped_get_version(), "%d", &major ) == 1 )
+		   )
+		{
+			return ! ( (major > min_major) ||
+			           ( (major == min_major) && (minor > min_minor) ) ||
+			           ( (major == min_major) && (minor == min_minor) && (micro >= min_micro) )
+			         ) ;
+		}
+	}
+
+	return 1 ;
+}
+], [ AC_MSG_RESULT([yes])
+     AC_DEFINE([HAVE_LIBPARTED_3_1_0_PLUS], [1], [Define to 1 if libparted >= 3.1])
+     have_new_lp_fs_resize_lib=yes
+   ]
+ , [ AC_MSG_RESULT([no])
+     have_new_lp_fs_resize_lib=no
+   ]
+)
+LIBS="$LIBS_save"
+
+
+dnl Check for availability of libparted fs resize library
+AM_CONDITIONAL([USE_LIBPARTED_FS_RESIZE_LIBRARY], [ test ${have_new_lp_fs_resize_lib} = yes])
+
+
+dnl Check if have libparted fs resize capability
+if test [ ${have_old_lp_fs_resize_api} = yes -o ${have_new_lp_fs_resize_lib} = yes ]; then
+	AC_DEFINE([HAVE_LIBPARTED_FS_RESIZE], [1], [Define to 1 if have libparted fs resize capability])
+fi
+
+
 dnl gthread
 PKG_CHECK_MODULES([GTHREAD], [gthread-2.0])
 AC_SUBST([GTHREAD_LIBS])
@@ -264,17 +325,18 @@ dnl Summary
 dnl======================
 
 echo ""
-echo "===================== Final configuration ========================"
-echo "                      Installing into prefix  :  $prefix"
+echo "======================== Final configuration ==========================="
+echo "                         Installing into prefix  :  $prefix"
 echo ""
-echo "                        Build documentation?  :  $enable_doc"
+echo "                           Build documentation?  :  $enable_doc"
 echo ""
-echo "        Use native libparted dmraid support?  :  $enable_libparted_dmraid"
+echo "           Use native libparted dmraid support?  :  $enable_libparted_dmraid"
 echo ""
-echo "    --- Features Based On Libparted Version ---"
-echo "   Need partition table re-read work around?  :  $need_pt_reread_work_around"
-echo "          Supports sector sizes > 512 bytes?  :  $support_sector_size_gt_512"
-echo "    Have libparted file system resizing API?  :  $have_lp_fs_resize_api"
+echo "       --- Features Based On Libparted Version ---"
+echo "      Need partition table re-read work around?  :  $need_pt_reread_work_around"
+echo "             Supports sector sizes > 512 bytes?  :  $support_sector_size_gt_512"
+echo "   Have old libparted file system resizing API?  :  $have_old_lp_fs_resize_api"
+echo "   Have new libparted file system resizing LIB?  :  $have_new_lp_fs_resize_lib"
 echo ""
-echo " If all settings are OK, type make and make install "
-echo "=================================================================="
+echo " If all settings are OK, type make and then (as root) make install"
+echo "========================================================================"
diff --git a/include/GParted_Core.h b/include/GParted_Core.h
index fe30e26..4317da0 100644
--- a/include/GParted_Core.h
+++ b/include/GParted_Core.h
@@ -1,5 +1,5 @@
 /* Copyright (C) 2004 Bart
- * Copyright (C) 2008, 2009, 2010, 2011 Curtis Gedak
+ * Copyright (C) 2008, 2009, 2010, 2011, 2012 Curtis Gedak
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -23,6 +23,9 @@
 #include "../include/Operation.h"
 
 #include <parted/parted.h>
+#ifdef HAVE_LIBPARTED_3_1_0_PLUS
+#include <parted/filesys.h>
+#endif
 #include <vector>
 #include <fstream>
 
@@ -81,7 +84,7 @@ private:
 				 bool inside_extended ) ;
 	void set_mountpoints( std::vector<Partition> & partitions ) ;
 	void set_used_sectors( std::vector<Partition> & partitions ) ;
-#ifndef HAVE_LIBPARTED_3_0_0_PLUS
+#ifdef HAVE_LIBPARTED_FS_RESIZE
 	void LP_set_used_sectors( Partition & partition );
 #endif
 	void set_flags( Partition & partition ) ;
@@ -110,7 +113,7 @@ private:
 	bool move_filesystem( const Partition & partition_old,
 			      const Partition & partition_new,
 			      OperationDetail & operationdetail ) ;
-#ifndef HAVE_LIBPARTED_3_0_0_PLUS
+#ifdef HAVE_LIBPARTED_FS_RESIZE
 	bool resize_move_filesystem_using_libparted( const Partition & partition_old,
 				      		     const Partition & partition_new,
 					      	     OperationDetail & operationdetail ) ;
diff --git a/include/Utils.h b/include/Utils.h
index fee138b..e56fb11 100644
--- a/include/Utils.h
+++ b/include/Utils.h
@@ -1,5 +1,5 @@
 /* Copyright (C) 2004 Bart
- * Copyright (C) 2008, 2009, 2010, 2011 Curtis Gedak
+ * Copyright (C) 2008, 2009, 2010, 2011, 2012 Curtis Gedak
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -109,9 +109,7 @@ struct FS
 	{
 		NONE		= 0,
 		GPARTED		= 1,
-#ifndef HAVE_LIBPARTED_3_0_0_PLUS
 		LIBPARTED	= 2,
-#endif
 		EXTERNAL	= 3
 	};
 
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index fa72231..cefd084 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -1442,7 +1442,7 @@ void GParted_Core::set_used_sectors( std::vector<Partition> & partitions )
 							if ( set_proper_filesystem( partitions[ t ] .filesystem ) )
 								p_filesystem ->set_used_sectors( partitions[ t ] ) ;
 							break ;
-#ifndef HAVE_LIBPARTED_3_0_0_PLUS
+#ifdef HAVE_LIBPARTED_FS_RESIZE
 						case GParted::FS::LIBPARTED	:
 							LP_set_used_sectors( partitions[ t ] ) ;
 							break ;
@@ -1478,7 +1478,7 @@ void GParted_Core::set_used_sectors( std::vector<Partition> & partitions )
 	}
 }
 
-#ifndef HAVE_LIBPARTED_3_0_0_PLUS
+#ifdef HAVE_LIBPARTED_FS_RESIZE
 void GParted_Core::LP_set_used_sectors( Partition & partition )
 {
 	PedFileSystem *fs = NULL;
@@ -1656,7 +1656,7 @@ bool GParted_Core::create_filesystem( const Partition & partition, OperationDeta
 			break ;
 		case GParted::FS::GPARTED:
 			break ;
-#ifndef HAVE_LIBPARTED_3_0_0_PLUS
+#ifndef HAVE_LIBPARTED_3_0_PLUS
 		case GParted::FS::LIBPARTED:
 			break ;
 #endif
@@ -1665,6 +1665,9 @@ bool GParted_Core::create_filesystem( const Partition & partition, OperationDeta
 				 p_filesystem ->create( partition, operationdetail .get_last_child() ) ;
 
 			break ;
+
+		default:
+			break ;
 	}
 
 	operationdetail .get_last_child() .set_status(  succes ? STATUS_SUCCES : STATUS_ERROR ) ;
@@ -1971,7 +1974,7 @@ bool GParted_Core::move_filesystem( const Partition & partition_old,
 				succes = copy_filesystem( partition_old, partition_new, operationdetail .get_last_child() ) ;
 
 			break ;
-#ifndef HAVE_LIBPARTED_3_0_0_PLUS
+#ifdef HAVE_LIBPARTED_FS_RESIZE
 		case GParted::FS::LIBPARTED:
 			succes = resize_move_filesystem_using_libparted( partition_old,
 									 partition_new,
@@ -1985,13 +1988,16 @@ bool GParted_Core::move_filesystem( const Partition & partition_old,
 			                            , operationdetail .get_last_child()
 			                            ) ;
 			break ;
+
+		default:
+			break ;
 	}
 
 	operationdetail .get_last_child() .set_status( succes ? STATUS_SUCCES : STATUS_ERROR ) ;
 	return succes ;
 }
 
-#ifndef HAVE_LIBPARTED_3_0_0_PLUS
+#ifdef HAVE_LIBPARTED_FS_RESIZE
 bool GParted_Core::resize_move_filesystem_using_libparted( const Partition & partition_old,
 		  	      		            	   const Partition & partition_new,
 						    	   OperationDetail & operationdetail ) 
@@ -2285,7 +2291,7 @@ bool GParted_Core::resize_filesystem( const Partition & partition_old,
 			break ;
 		case GParted::FS::GPARTED:
 			break ;
-#ifndef HAVE_LIBPARTED_3_0_0_PLUS
+#ifdef HAVE_LIBPARTED_FS_RESIZE
 		case GParted::FS::LIBPARTED:
 			succes = resize_move_filesystem_using_libparted( partition_old,
 									 partition_new,
@@ -2298,6 +2304,9 @@ bool GParted_Core::resize_filesystem( const Partition & partition_old,
 							operationdetail .get_last_child(), 
 							fill_partition ) ;
 			break ;
+
+		default:
+			break ;
 	}
 
 	operationdetail .get_last_child() .set_status( succes ? STATUS_SUCCES : STATUS_ERROR ) ;
@@ -2613,6 +2622,9 @@ bool GParted_Core::check_repair_filesystem( const Partition & partition, Operati
 				 p_filesystem ->check_repair( partition, operationdetail .get_last_child() ) ;
 
 			break ;
+
+		default:
+			break ;
 	}
 
 	operationdetail .get_last_child() .set_status( succes ? STATUS_SUCCES : STATUS_ERROR ) ;
diff --git a/src/Makefile.am b/src/Makefile.am
index 5fe75fb..7c65fb2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -70,5 +70,9 @@ gpartedbin_SOURCES = \
 
 gpartedbin_LDFLAGS = -lparted
 
+if USE_LIBPARTED_FS_RESIZE_LIBRARY
+gpartedbin_LDFLAGS += -lparted-fs-resize
+endif
+
 gpartedbin_LDADD = $(GTHREAD_LIBS) $(GTKMM_LIBS)
 
diff --git a/src/fat16.cc b/src/fat16.cc
index e4ad513..bd0485b 100644
--- a/src/fat16.cc
+++ b/src/fat16.cc
@@ -1,5 +1,5 @@
 /* Copyright (C) 2004 Bart
- * Copyright (C) 2008, 2009, 2010, 2011 Curtis Gedak
+ * Copyright (C) 2008, 2009, 2010, 2011, 2012 Curtis Gedak
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -82,13 +82,15 @@ FS fat16::get_filesystem_support()
 		fs .write_uuid = FS::EXTERNAL ;
 	}
 
-#ifndef HAVE_LIBPARTED_3_0_0_PLUS
+#ifdef HAVE_LIBPARTED_FS_RESIZE
 	//resizing of start and endpoint are provided by libparted
 	fs .grow = GParted::FS::LIBPARTED ;
 	fs .shrink = GParted::FS::LIBPARTED ;
-	fs .move = GParted::FS::LIBPARTED ;
+#endif
+#ifdef HAVE_LIBPARTED_3_0_0_PLUS
+	fs .move = FS::GPARTED ;
 #else
-	fs.move = FS::GPARTED ;
+	fs .move = GParted::FS::LIBPARTED ;
 #endif
 
 	fs .copy = GParted::FS::GPARTED ;
diff --git a/src/fat32.cc b/src/fat32.cc
index aa77cd1..c49ed50 100644
--- a/src/fat32.cc
+++ b/src/fat32.cc
@@ -1,5 +1,5 @@
 /* Copyright (C) 2004 Bart
- * Copyright (C) 2008, 2009, 2010, 2011 Curtis Gedak
+ * Copyright (C) 2008, 2009, 2010, 2011, 2012 Curtis Gedak
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -70,13 +70,15 @@ FS fat32::get_filesystem_support()
 		fs .write_uuid = FS::EXTERNAL ;
 	}
 
-#ifndef HAVE_LIBPARTED_3_0_0_PLUS
+#ifdef HAVE_LIBPARTED_FS_RESIZE
 	//resizing of start and endpoint are provided by libparted
 	fs .grow = GParted::FS::LIBPARTED ;
 	fs .shrink = GParted::FS::LIBPARTED ;
-	fs .move = GParted::FS::LIBPARTED ;
-#else
+#endif
+#ifdef HAVE_LIBPARTED_3_0_0_PLUS
 	fs .move = FS::GPARTED ;
+#else
+	fs .move = GParted::FS::LIBPARTED ;
 #endif
 
 	fs .copy = GParted::FS::GPARTED ;
diff --git a/src/hfs.cc b/src/hfs.cc
index 525ea14..84e1b60 100644
--- a/src/hfs.cc
+++ b/src/hfs.cc
@@ -1,5 +1,5 @@
 /* Copyright (C) 2004 Bart
- * Copyright (C) 2008, 2009, 2010, 2011 Curtis Gedak
+ * Copyright (C) 2008, 2009, 2010, 2011, 2012 Curtis Gedak
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -28,9 +28,9 @@ FS hfs::get_filesystem_support()
 		
 	fs .filesystem = GParted::FS_HFS ;
 
-#ifndef HAVE_LIBPARTED_3_0_0_PLUS
-	fs .read = GParted::FS::LIBPARTED ; 
-	fs .shrink = GParted::FS::LIBPARTED ; 
+#ifdef HAVE_LIBPARTED_FS_RESIZE
+	fs .read = GParted::FS::LIBPARTED ;
+	fs .shrink = GParted::FS::LIBPARTED ;
 #endif
 
 	if ( ! Glib::find_program_in_path( "hformat" ) .empty() )
diff --git a/src/hfsplus.cc b/src/hfsplus.cc
index f6c08e2..66c868b 100644
--- a/src/hfsplus.cc
+++ b/src/hfsplus.cc
@@ -1,5 +1,5 @@
 /* Copyright (C) 2004 Bart
- * Copyright (C) 2008, 2009, 2010, 2011 Curtis Gedak
+ * Copyright (C) 2008, 2009, 2010, 2011, 2012 Curtis Gedak
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -28,9 +28,9 @@ FS hfsplus::get_filesystem_support()
 	
 	fs .filesystem = GParted::FS_HFSPLUS ;
 
-#ifndef HAVE_LIBPARTED_3_0_0_PLUS
-	fs .read = GParted::FS::LIBPARTED ; 
-	fs .shrink = GParted::FS::LIBPARTED ; 
+#ifdef HAVE_LIBPARTED_FS_RESIZE
+	fs .read = GParted::FS::LIBPARTED ;
+	fs .shrink = GParted::FS::LIBPARTED ;
 #endif
 
 	if ( ! Glib::find_program_in_path( "mkfs.hfsplus" ) .empty() )



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