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)
This commit is contained in:
Curtis Gedak 2012-03-03 11:47:39 -07:00
parent 284956a6da
commit 0fda1d011d
9 changed files with 123 additions and 40 deletions

View file

@ -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 "========================================================================"

View file

@ -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 ) ;

View file

@ -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
};

View file

@ -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 ) ;

View file

@ -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)

View file

@ -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 ;

View file

@ -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 ;

View file

@ -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() )

View file

@ -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() )