From 1382c7bc17e61bb840a8f0a317c2e4101899f8ff Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Thu, 24 Nov 2005 15:59:31 +0000 Subject: [PATCH] cleanups correct partitiontype is now set after creation or conversion. * include/FileSystem.h: cleanups * include/GParted_Core.h, src/GParted_Core.cc: correct partitiontype is now set after creation or conversion. (#322281) --- ChangeLog | 6 ++++++ include/FileSystem.h | 3 ++- include/GParted_Core.h | 1 + src/GParted_Core.cc | 30 +++++++++++++++++++++++++++++- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0d68926c..340baabf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-11-24 Bart Hakvoort + * include/FileSystem.h: cleanups + * include/GParted_Core.h, + src/GParted_Core.cc: correct partitiontype is now set after creation + or conversion. (#322281) + 2005-11-18 Bart Hakvoort * configure.in: added mk to ALL_LINGUAS on request of Arangel diff --git a/include/FileSystem.h b/include/FileSystem.h index cb16f460..896d065b 100644 --- a/include/FileSystem.h +++ b/include/FileSystem.h @@ -39,7 +39,8 @@ inline bool open_device_and_disk( const Glib::ustring & device_path, PedDevice * if ( open_device( device_path, device ) ) disk = ped_disk_new( device ); - //if ! disk and writeable it's probably a HD without disklabel. We return true here and deal with them in GParted_Core::get_devices + //if ! disk and writeable it's probably a HD without disklabel. + //We return true here and deal with them in GParted_Core::get_devices if ( ! disk && ( strict || device ->read_only ) ) { ped_device_destroy( device ) ; diff --git a/include/GParted_Core.h b/include/GParted_Core.h index d553eba9..714b9716 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -77,6 +77,7 @@ private: void Show_Error( Glib::ustring message ) ; void set_proper_filesystem( const Glib::ustring & filesystem ) ; + void set_partition_type( const Glib::ustring & device_path, const Partition & partition ) ; Glib::RefPtr textbuffer; diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 1bfd7380..358151a3 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -365,9 +365,12 @@ bool GParted_Core::Create( const Device & device, Partition & new_partition ) { set_proper_filesystem( new_partition .filesystem ) ; - //most likely this means the user created an unformatted partition, however in theory, it could also screw some errorhandling. + //most likely this means the user created an unformatted partition, + //however in theory, it could also screw some errorhandling. if ( ! p_filesystem ) return true ; + + set_partition_type( device .path, new_partition ) ; return p_filesystem ->Create( new_partition ) ; } @@ -387,6 +390,8 @@ bool GParted_Core::Convert_FS( const Glib::ustring & device_path, const Partitio close_device_and_disk( device, disk ) ; } + + set_partition_type( device_path, partition ) ; set_proper_filesystem( partition .filesystem ) ; @@ -775,4 +780,27 @@ void GParted_Core::set_proper_filesystem( const Glib::ustring & filesystem ) p_filesystem ->textbuffer = textbuffer ; } + +void GParted_Core::set_partition_type( const Glib::ustring & device_path, const Partition & partition ) +{ + if ( open_device_and_disk( device_path, device, disk ) ) + { + PedFileSystemType * fs_type = ped_file_system_type_get( partition .filesystem .c_str() ) ; + + //default is Linux (83) + if ( ! fs_type ) + fs_type = ped_file_system_type_get( "ext2" ) ; + + if ( fs_type ) + { + c_partition = ped_disk_get_partition_by_sector( disk, (partition .sector_end + partition .sector_start) / 2 ) ; + + if ( c_partition && ped_partition_set_system( c_partition, fs_type ) && Commit( disk ) ) + sleep( 1 ) ; //paranoia: give the OS some time to update nodes in /dev + } + + close_device_and_disk( device, disk ) ; + } +} + } //GParted