diff --git a/configure.ac b/configure.ac index 1e999873..7f98a3c2 100644 --- a/configure.ac +++ b/configure.ac @@ -99,6 +99,27 @@ int main() ) +dnl Check for libparted 2.0 to 3.0 inclusive for a bug where loop table +dnl creation doesn't delete old partitions. +LIBPARTED_MIN_WANTED_VERSION='2.0' +LIBPARTED_MAX_WANTED_VERSION='3.0' +AC_MSG_CHECKING([for $LIBPARTED_MIN_WANTED_VERSION <= libparted <= $LIBPARTED_MAX_WANTED_VERSION (loop table creation doesn't delete old partitions)]) +LIBPARTED_MIN_WANTED_INT=`echo "$LIBPARTED_MIN_WANTED_VERSION" | + $AWK -F. '{print $1 * 10000 + $2 * 100 + $3}'` +LIBPARTED_MAX_WANTED_INT=`echo "$LIBPARTED_MAX_WANTED_VERSION" | + $AWK -F. '{print $1 * 10000 + $2 * 100 + $3}'` +if test "$LIBPARTED_MIN_WANTED_INT" -le "$LIBPARTED_FOUND_INT" -a \ + "$LIBPARTED_FOUND_INT" -le "$LIBPARTED_MAX_WANTED_INT"; then + need_loop_delete_old_ptns_workaround=yes + AC_DEFINE([ENABLE_LOOP_DELETE_OLD_PTNS_WORKAROUND], 1, + [Define to 1 to enable deletion of old partitions before creating a loop table workaround]) + AC_MSG_RESULT([(cached) yes]) +else + need_loop_delete_old_ptns_workaround=no + AC_MSG_RESULT([(cached) no]) +fi + + dnl Check for libparted >= 2.2 for improved informing the kernel to dnl re-read the partition table code and support of larger sector sizes dnl (> 512 bytes). @@ -353,6 +374,8 @@ echo "" echo " Use native libparted dmraid support? : $enable_libparted_dmraid" echo "" echo " --- Features Based On Libparted Version ---" +echo " Need delete old partitions before" +echo " creating a loop table workaround? : $need_loop_delete_old_ptns_workaround" echo " Need partition table re-read workaround? : $need_pt_reread_workaround" echo " Supports large sector sizes (> 512 bytes)? : $support_large_sector_sizes" echo " Have old libparted file system resizing API? : $have_old_lp_fs_resize_api" diff --git a/include/GParted_Core.h b/include/GParted_Core.h index 1c85ca1f..29eca5f3 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -48,7 +48,8 @@ public: bool apply_operation_to_disk( Operation * operation ); bool set_disklabel( const Device & device, const Glib::ustring & disklabel ); - bool new_disklabel( const Glib::ustring & device_path, const Glib::ustring & disklabel ); + bool new_disklabel( const Glib::ustring & device_path, const Glib::ustring & disklabel, + bool recreate_dmraid_devs = true ); bool toggle_flag( const Partition & partition, const Glib::ustring & flag, bool state ) ; diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 9b425451..52df5e48 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -810,6 +810,21 @@ bool GParted_Core::set_disklabel( const Device & device, const Glib::ustring & d { Glib::ustring device_path = device.get_path(); + // FIXME: Should call file system specific removal actions + // (to remove LVM2 PVs before deleting the partitions). + +#ifdef ENABLE_LOOP_DELETE_OLD_PTNS_WORKAROUND + // When creating a "loop" table with libparted 2.0 to 3.0 inclusive, it doesn't + // inform the kernel to delete old partitions so as a consequence blkid's cache + // becomes stale and it won't report a file system subsequently created on the + // whole disk device. Create a GPT first to use that code in libparted to delete + // any old partitions. Fixed in parted 3.1 by commit: + // f5c909c0cd50ed52a48dae6d35907dc08b137e88 + // libparted: remove has_partitions check to allow loopback partitions + if ( disklabel == "loop" ) + new_disklabel( device_path, "gpt", false ); +#endif + // Ensure that any previous whole disk device file system can't be recognised by // libparted in preference to the "loop" partition table signature, or by blkid in // preference to any partition table about to be written. @@ -826,7 +841,8 @@ bool GParted_Core::set_disklabel( const Device & device, const Glib::ustring & d return new_disklabel( device_path, disklabel ); } -bool GParted_Core::new_disklabel( const Glib::ustring & device_path, const Glib::ustring & disklabel ) +bool GParted_Core::new_disklabel( const Glib::ustring & device_path, const Glib::ustring & disklabel, + bool recreate_dmraid_devs ) { bool return_value = false ; @@ -850,7 +866,7 @@ bool GParted_Core::new_disklabel( const Glib::ustring & device_path, const Glib: #ifndef USE_LIBPARTED_DMRAID //delete and recreate disk entries if dmraid DMRaid dmraid ; - if ( return_value && dmraid .is_dmraid_device( device_path ) ) + if ( recreate_dmraid_devs && return_value && dmraid.is_dmraid_device( device_path ) ) { dmraid .purge_dev_map_entries( device_path ) ; dmraid .create_dev_map_entries( device_path ) ; @@ -859,7 +875,7 @@ bool GParted_Core::new_disklabel( const Glib::ustring & device_path, const Glib: return return_value ; } - + bool GParted_Core::toggle_flag( const Partition & partition, const Glib::ustring & flag, bool state ) { bool succes = false ;