From 3a918a337b483e9e78bc31885f6c6315f61b8917 Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Sun, 2 Apr 2006 21:26:27 +0000 Subject: [PATCH] improved disabling of automounting. It's still somewhat crude, but right * include/GParted_Core.h, src/GParted_Core.cc: improved disabling of automounting. It's still somewhat crude, but right now it's ok for some semi-public testing. I'll do some cleanups tomorrow morning. * src/Dialog_Progress.cc: added FIXME --- ChangeLog | 8 ++++++ include/GParted_Core.h | 3 ++- src/Dialog_Progress.cc | 4 +-- src/GParted_Core.cc | 59 ++++++++++++++++++++++++++++++------------ 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index b16c78c0..554b26a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-04-02 Bart Hakvoort + + * include/GParted_Core.h, + src/GParted_Core.cc: improved disabling of automounting. It's still + somewhat crude, but right now it's ok for some semi-public testing. + I'll do some cleanups tomorrow morning. + * src/Dialog_Progress.cc: added FIXME + 2006-04-02 Bart Hakvoort * include/GParted_Core.h, diff --git a/include/GParted_Core.h b/include/GParted_Core.h index b51ad520..b35b6f95 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -94,7 +94,7 @@ private: void set_proper_filesystem( const FILESYSTEM & filesystem ) ; bool set_partition_type( const Partition & partition, std::vector & operation_details ) ; - bool wait_for_node( const Glib::ustring & node ) ; + bool wait_for_node( const Glib::ustring & node, bool disable_automount = false ) ; bool erase_filesystem_signatures( const Partition & partition ) ; bool open_device( const Glib::ustring & device_path ) ; @@ -120,6 +120,7 @@ private: std::map< Glib::ustring, std::vector >::iterator iter_mp ; std::vector pmount_locked_partitions ; + Glib::ustring PID ; PedDevice *lp_device ; PedDisk *lp_disk ; diff --git a/src/Dialog_Progress.cc b/src/Dialog_Progress.cc index 93ecb2f9..35907c16 100644 --- a/src/Dialog_Progress.cc +++ b/src/Dialog_Progress.cc @@ -249,9 +249,9 @@ void Dialog_Progress::on_expander_changed() } void Dialog_Progress::on_cell_data_description( Gtk::CellRenderer * renderer, const Gtk::TreeModel::iterator & iter ) -{ +{//FIXME: markup tags in the text should be escaped (e.g. will interfere with the real tags) dynamic_cast( renderer ) ->property_markup() = - static_cast( * iter )[ treeview_operations_columns .operation_description ] ; + static_cast( *iter )[ treeview_operations_columns .operation_description ] ; } void * Dialog_Progress::static_pthread_apply_operation( void * p_dialog_progress ) diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 3e840945..8bc74827 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -51,6 +51,8 @@ GParted_Core::GParted_Core() lp_disk = NULL ; lp_partition = NULL ; p_filesystem = NULL ; + + PID = Utils::num_to_str( getpid() ) ; ped_exception_set_handler( ped_exception_handler ) ; @@ -444,11 +446,12 @@ void GParted_Core::disable_automount( const std::vector & partitions if ( partitions[ t ] .type == GParted::TYPE_EXTENDED ) disable_automount( partitions[ t ] .logicals ) ; - if ( std::find( pmount_locked_partitions .begin(), + if ( partitions[ t ] .type != GParted::TYPE_UNALLOCATED && + std::find( pmount_locked_partitions .begin(), pmount_locked_partitions .end(), partitions[ t ] .get_path() ) == pmount_locked_partitions .end() ) { - Utils::execute_command( "pmount --lock " + partitions[ t ] .get_path() + " " + Utils::num_to_str( getpid() ) ) ; + Utils::execute_command( "pmount --lock " + partitions[ t ] .get_path() + " " + PID ) ; pmount_locked_partitions .push_back( partitions[ t ] .get_path() ) ; } @@ -683,6 +686,10 @@ bool GParted_Core::Delete( const Partition & partition, std::vector 0 && ( new_partition .type == GParted::TYPE_EXTENDED || ( - wait_for_node( new_partition .get_path() ) && + wait_for_node( new_partition .get_path(), ! Glib::find_program_in_path( "pmount" ) .empty() ) && erase_filesystem_signatures( new_partition ) ) ) @@ -1027,7 +1034,7 @@ bool GParted_Core::create_empty_partition( Partition & new_partition, { operation_details .back() .status = OperationDetails::SUCCES ; - return new_partition .partition_number > 0 ; + return true ; } else { @@ -1038,7 +1045,7 @@ bool GParted_Core::create_empty_partition( Partition & new_partition, operation_details .back() .status = OperationDetails::ERROR ; return false ; - } + } } bool GParted_Core::resize_container_partition( const Partition & partition_old, @@ -1262,20 +1269,38 @@ bool GParted_Core::set_partition_type( const Partition & partition, return return_value ; } -bool GParted_Core::wait_for_node( const Glib::ustring & node ) +bool GParted_Core::wait_for_node( const Glib::ustring & node, bool disable_automount ) { //we'll loop for 10 seconds or till 'node' appeares... - for( short t = 0 ; t < 50 ; t++ ) + if ( disable_automount ) { - //FIXME: find a better way to check if a file exists - //the current way is suboptimal (at best) - if ( Glib::file_test( node, Glib::FILE_TEST_EXISTS ) ) - { - sleep( 2 ) ; //apperantly the node isn't available immediatly after file_test returns succesfully :/ - return true ; + for( short t = 0 ; t < 50 ; t++ ) + { + if ( ! Utils::execute_command( "pmount --lock " + node + " " + PID ) ) + { + //apperantly the node isn't available immediatly after file_test returns succesfully :/ + sleep( 2 ) ; + return true ; + } + else + usleep( 200000 ) ; + } + } + else + { + for( short t = 0 ; t < 50 ; t++ ) + { + //FIXME: find a better way to check if a file exists + //the current way is suboptimal (at best) + if ( Glib::file_test( node, Glib::FILE_TEST_EXISTS ) ) + { + //same issue + sleep( 2 ) ; + return true ; + } + else + usleep( 200000 ) ; //200 milliseconds } - else - usleep( 200000 ) ; //200 milliseconds } return false ; @@ -1371,7 +1396,7 @@ GParted_Core::~GParted_Core() delete p_filesystem ; for ( unsigned int t = 0 ; t < pmount_locked_partitions .size() ; t++ ) - Utils::execute_command( "pmount --unlock " + pmount_locked_partitions[ t ] + " " + Utils::num_to_str( getpid() ) ) ; + Utils::execute_command( "pmount --unlock " + pmount_locked_partitions[ t ] + " " + PID ) ; } } //GParted