added column 'check' use halproperty 'storage.automount_enabled_hint'

* include/Dialog_Filesystems.h,
  src/Dialog_Filesystems.cc: added column 'check'
* include/GParted_Core.h,
  src/GParted_Core.cc: use halproperty
  'storage.automount_enabled_hint' instead of pmount to disable
  automounting.
This commit is contained in:
Bart Hakvoort 2006-04-03 18:48:53 +00:00
parent 3a918a337b
commit 7f187d644c
6 changed files with 69 additions and 59 deletions

View File

@ -1,3 +1,12 @@
2006-04-03 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/Dialog_Filesystems.h,
src/Dialog_Filesystems.cc: added column 'check'
* include/GParted_Core.h,
src/GParted_Core.cc: use halproperty
'storage.automount_enabled_hint' instead of pmount to disable
automounting.
2006-04-02 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/GParted_Core.h,

View File

@ -51,6 +51,7 @@ private:
Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > shrink ;
Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > move ;
Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > copy ;
Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > check ;
treeview_filesystems_Columns()
{
@ -62,6 +63,7 @@ private:
add( shrink ) ;
add( move ) ;
add( copy ) ;
add( check ) ;
}
};

View File

@ -66,7 +66,7 @@ private:
GParted::FILESYSTEM get_filesystem() ;
bool check_device_path( const Glib::ustring & device_path ) ;
void set_device_partitions( Device & device ) ;
void disable_automount( const std::vector<Partition> & partitions ) ;
void disable_automount( const Device & device ) ;
void read_mountpoints_from_file( const Glib::ustring & filename,
std::map< Glib::ustring, std::vector<Glib::ustring> > & map ) ;
void init_maps() ;
@ -94,7 +94,7 @@ private:
void set_proper_filesystem( const FILESYSTEM & filesystem ) ;
bool set_partition_type( const Partition & partition,
std::vector<OperationDetails> & operation_details ) ;
bool wait_for_node( const Glib::ustring & node, bool disable_automount = false ) ;
bool wait_for_node( const Glib::ustring & node ) ;
bool erase_filesystem_signatures( const Partition & partition ) ;
bool open_device( const Glib::ustring & device_path ) ;
@ -119,8 +119,9 @@ private:
std::map< Glib::ustring, Glib::ustring >::iterator iter ;
std::map< Glib::ustring, std::vector<Glib::ustring> >::iterator iter_mp ;
std::vector<Glib::ustring> pmount_locked_partitions ;
Glib::ustring PID ;
//disabling automount stuff
bool DISABLE_AUTOMOUNT ;
std::map<Glib::ustring, Glib::ustring> disabled_automount_devices ;
PedDevice *lp_device ;
PedDisk *lp_disk ;

View File

@ -38,6 +38,7 @@ Dialog_Filesystems::Dialog_Filesystems()
treeview_filesystems .append_column( _("Shrink"), treeview_filesystems_columns .shrink );
treeview_filesystems .append_column( _("Move"), treeview_filesystems_columns .move );
treeview_filesystems .append_column( _("Copy"), treeview_filesystems_columns .copy );
treeview_filesystems .append_column( _("Check"), treeview_filesystems_columns .check );
treeview_filesystems .get_selection() ->set_mode( Gtk::SELECTION_NONE );
get_vbox() ->pack_start( treeview_filesystems ) ;
@ -46,7 +47,7 @@ Dialog_Filesystems::Dialog_Filesystems()
icon_yes = render_icon( Gtk::Stock::APPLY, Gtk::ICON_SIZE_LARGE_TOOLBAR ) ;
icon_no = render_icon( Gtk::Stock::CANCEL, Gtk::ICON_SIZE_LARGE_TOOLBAR ) ;
add_button( Gtk::Stock::REFRESH, Gtk::RESPONSE_OK );
add_button( Gtk::Stock::REFRESH, Gtk::RESPONSE_OK ) ;
add_button( Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE ) ->grab_focus() ;
show_all_children() ;
}
@ -71,6 +72,7 @@ void Dialog_Filesystems::Show_Filesystem( const FS & fs )
treerow[ treeview_filesystems_columns .shrink ] = fs .shrink ? icon_yes : icon_no ;
treerow[ treeview_filesystems_columns .move ] = fs .move ? icon_yes : icon_no ;
treerow[ treeview_filesystems_columns .copy ] = fs .copy ? icon_yes : icon_no ;
treerow[ treeview_filesystems_columns .check ] = fs .check ? icon_yes : icon_no ;
}
Dialog_Filesystems::~Dialog_Filesystems()

View File

@ -51,8 +51,7 @@ GParted_Core::GParted_Core()
lp_disk = NULL ;
lp_partition = NULL ;
p_filesystem = NULL ;
PID = Utils::num_to_str( getpid() ) ;
DISABLE_AUTOMOUNT = false ;
ped_exception_set_handler( ped_exception_handler ) ;
@ -65,6 +64,15 @@ GParted_Core::GParted_Core()
//throw libpartedversion to the stdout to see which version is actually used.
std::cout << "======================" << std::endl ;
std::cout << "libparted : " << ped_get_version() << std::endl ;
//see if we can disable automounting
if ( ! Glib::find_program_in_path( "hal-find-by-property" ) .empty() &&
! Glib::find_program_in_path( "hal-set-property" ) .empty() )
{
DISABLE_AUTOMOUNT = true ;
std::cout << "automounting disabled" << std::endl ;
}
std::cout << "======================" << std::endl ;
//initialize filesystemlist
@ -156,7 +164,9 @@ void GParted_Core::get_devices( std::vector<Device> & devices )
std::sort( device_paths .begin(), device_paths .end() ) ;
}
//FIXME: i guess this is the correct place to remove devices from disabled_automount_devices..
//this is necessary for people who remove and replug their usbdevice without restarting gparted
//all devices not in device_paths yet availabl in disable_automount_devices should be removed..
for ( unsigned int t = 0 ; t < device_paths .size() ; t++ )
{
if ( check_device_path( device_paths[ t ] ) &&
@ -186,11 +196,8 @@ void GParted_Core::get_devices( std::vector<Device> & devices )
temp_device .disktype = lp_disk ->type ->name ;
temp_device .max_prims = ped_disk_get_max_primary_partition_count( lp_disk ) ;
disable_automount( temp_device ) ;
set_device_partitions( temp_device ) ;
if ( ! Glib::find_program_in_path( "pmount" ) .empty() )
disable_automount( temp_device .partitions ) ;
set_mountpoints( temp_device .partitions ) ;
set_used_sectors( temp_device .partitions ) ;
@ -439,21 +446,34 @@ void GParted_Core::set_device_partitions( Device & device )
insert_unallocated( device .get_path(), device .partitions, 0, device .length -1, false ) ;
}
void GParted_Core::disable_automount( const std::vector<Partition> & partitions )
void GParted_Core::disable_automount( const Device & device )
{
for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
if ( DISABLE_AUTOMOUNT )
{
if ( partitions[ t ] .type == GParted::TYPE_EXTENDED )
disable_automount( partitions[ t ] .logicals ) ;
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() )
if ( disabled_automount_devices .find( device .get_path() ) == disabled_automount_devices .end() )
{
Utils::execute_command( "pmount --lock " + partitions[ t ] .get_path() + " " + PID ) ;
//get HAL device-id
Glib::ustring hal_id, error ;
bool found = false ;
pmount_locked_partitions .push_back( partitions[ t ] .get_path() ) ;
for ( unsigned int t = 0 ; t < device .get_paths() .size() && ! found ; t++ )
found = ! Utils::execute_command(
"hal-find-by-property --key 'block.device' --string '" +
device .get_paths()[ t ] + "'",
hal_id,
error ) ;
if ( found )
{
if ( ! hal_id .empty() && hal_id[ hal_id .length() -1 ] == '\n' )
hal_id .erase( hal_id .length() -1, 1 ) ;
Utils::execute_command( "hal-set-property --udi '" + hal_id +
"' --key 'storage.automount_enabled_hint' --bool false" ) ;
}
//found or not found.. we're done with this device..
disabled_automount_devices[ device. get_path() ] = hal_id ;
}
}
}
@ -686,10 +706,6 @@ bool GParted_Core::Delete( const Partition & partition, std::vector<OperationDet
lp_disk,
(partition .sector_end + partition .sector_start) / 2 ) ;
//remove the lock (if it exists)
if ( ! Glib::find_program_in_path( "pmount" ) .empty() )
Utils::execute_command( "pmount --unlock " + partition .get_path() + " " + PID ) ;
return_value = ped_disk_delete_partition( lp_disk, lp_partition ) && commit() ;
sleep( 1 ) ; //give the kernel some time to reread the partitiontable
@ -1026,7 +1042,7 @@ bool GParted_Core::create_empty_partition( Partition & new_partition,
(
new_partition .type == GParted::TYPE_EXTENDED ||
(
wait_for_node( new_partition .get_path(), ! Glib::find_program_in_path( "pmount" ) .empty() ) &&
wait_for_node( new_partition .get_path() ) &&
erase_filesystem_signatures( new_partition )
)
)
@ -1269,38 +1285,21 @@ bool GParted_Core::set_partition_type( const Partition & partition,
return return_value ;
}
bool GParted_Core::wait_for_node( const Glib::ustring & node, bool disable_automount )
bool GParted_Core::wait_for_node( const Glib::ustring & node )
{
//we'll loop for 10 seconds or till 'node' appeares...
if ( disable_automount )
for( short t = 0 ; t < 50 ; t++ )
{
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 ) )
{
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
//same issue
sleep( 2 ) ;
return true ;
}
else
usleep( 200000 ) ; //200 milliseconds
}
return false ;
@ -1394,9 +1393,6 @@ GParted_Core::~GParted_Core()
{
if ( p_filesystem )
delete p_filesystem ;
for ( unsigned int t = 0 ; t < pmount_locked_partitions .size() ; t++ )
Utils::execute_command( "pmount --unlock " + pmount_locked_partitions[ t ] + " " + PID ) ;
}
} //GParted

View File

@ -240,7 +240,7 @@ int Utils::execute_command( const Glib::ustring & command,
output = std_out ;
error = std_error ;
return exit_status ;
}