deal with the rare situation when 2 partitions are mounted on the same

* include/GParted_Core.h,
  src/GParted_Core.cc,
  src/Win_GParted.cc: deal with the rare situation when 2 partitions
  are mounted on the same mountpoint. (see also #330327)
This commit is contained in:
Bart Hakvoort 2006-02-20 14:41:05 +00:00
parent 41c619e7c2
commit d457bf3645
5 changed files with 57 additions and 22 deletions

View File

@ -1,3 +1,10 @@
2006-02-20 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/GParted_Core.h,
src/GParted_Core.cc,
src/Win_GParted.cc: deal with the rare situation when 2 partitions
are mounted on the same mountpoint. (see also #330327)
2006-02-18 Bart Hakvoort <hakvoort@cvs.gnome.org> 2006-02-18 Bart Hakvoort <hakvoort@cvs.gnome.org>
* src/GParted_Core.cc: added some checks before performing a * src/GParted_Core.cc: added some checks before performing a

View File

@ -67,6 +67,7 @@ public:
const std::vector<FS> & get_filesystems( ) const ; const std::vector<FS> & get_filesystems( ) const ;
const FS & get_fs( GParted::FILESYSTEM filesystem ) const ; const FS & get_fs( GParted::FILESYSTEM filesystem ) const ;
std::vector<Glib::ustring> get_disklabeltypes( ) ; std::vector<Glib::ustring> get_disklabeltypes( ) ;
std::vector<Glib::ustring> get_all_mountpoints() ;
private: private:
GParted::FILESYSTEM get_filesystem() ; GParted::FILESYSTEM get_filesystem() ;

View File

@ -170,7 +170,7 @@ void GParted_Core::get_devices( std::vector<Device> & devices )
} }
//clear leftover information... //clear leftover information...
mount_info .clear() ; //NOTE that we cannot clear mountinfo since it might be needed in get_all_mountpoints()
short_paths .clear() ; short_paths .clear() ;
} }
@ -178,6 +178,9 @@ void GParted_Core::init_maps()
{ {
std::string line ; std::string line ;
short_paths .clear() ;
mount_info .clear() ;
//initialize mountpoints.. //initialize mountpoints..
char node[255], mountpoint[255] ; char node[255], mountpoint[255] ;
unsigned int index ; unsigned int index ;
@ -185,9 +188,9 @@ void GParted_Core::init_maps()
if ( proc_mounts ) if ( proc_mounts )
{ {
while ( getline( proc_mounts, line ) ) while ( getline( proc_mounts, line ) )
if ( line .length() > 0 && if ( Glib::str_has_prefix( line, "/" ) &&
line[ 0 ] == '/' && sscanf( line .c_str(), "%255s %255s", node, mountpoint ) == 2 &&
sscanf( line .c_str(), "%255s %255s", node, mountpoint ) == 2 ) static_cast<Glib::ustring>( node ) != "/dev/root" )
{ {
//see if mountpoint contains spaces and deal with it //see if mountpoint contains spaces and deal with it
line = mountpoint ; line = mountpoint ;
@ -206,8 +209,7 @@ void GParted_Core::init_maps()
if ( etc_mtab ) if ( etc_mtab )
{ {
while ( getline( etc_mtab, line ) ) while ( getline( etc_mtab, line ) )
if ( line .length() > 0 && if ( Glib::str_has_prefix( line, "/" ) &&
line[ 0 ] == '/' &&
sscanf( line .c_str(), "%255s %255s", node, mountpoint ) == 2 && sscanf( line .c_str(), "%255s %255s", node, mountpoint ) == 2 &&
static_cast<Glib::ustring>( mountpoint ) == "/" ) static_cast<Glib::ustring>( mountpoint ) == "/" )
{ {
@ -330,7 +332,7 @@ void GParted_Core::set_device_partitions( Device & device )
case PED_PARTITION_EXTENDED: case PED_PARTITION_EXTENDED:
partition_temp.Set( device .path, partition_temp.Set( device .path,
device .path + Utils::num_to_str( lp_partition ->num ), ped_partition_get_path( lp_partition ),
lp_partition ->num, lp_partition ->num,
GParted::TYPE_EXTENDED, GParted::TYPE_EXTENDED,
GParted::FS_EXTENDED, GParted::FS_EXTENDED,
@ -380,10 +382,7 @@ void GParted_Core::set_mountpoints( std::vector<Partition> & partitions )
{ {
iter_mp = mount_info .find( partitions[ t ] .partition ); iter_mp = mount_info .find( partitions[ t ] .partition );
if ( iter_mp != mount_info .end() ) if ( iter_mp != mount_info .end() )
{
partitions[ t ] .mountpoints = iter_mp ->second ; partitions[ t ] .mountpoints = iter_mp ->second ;
mount_info .erase( iter_mp ) ;
}
} }
else if ( partitions[ t ] .type == GParted::TYPE_EXTENDED ) else if ( partitions[ t ] .type == GParted::TYPE_EXTENDED )
set_mountpoints( partitions[ t ] .logicals ) ; set_mountpoints( partitions[ t ] .logicals ) ;
@ -404,16 +403,11 @@ void GParted_Core::set_short_paths( std::vector<Partition> & partitions )
Glib::ustring GParted_Core::get_short_path( const Glib::ustring & real_path ) Glib::ustring GParted_Core::get_short_path( const Glib::ustring & real_path )
{ {
temp = real_path ;
iter = short_paths .find( real_path ); iter = short_paths .find( real_path );
if ( iter != short_paths .end() ) if ( iter != short_paths .end() )
{ return iter ->second ;
temp = iter ->second ;
short_paths .erase( iter ) ;
}
return temp ; return real_path ;
} }
void GParted_Core::set_used_sectors( std::vector<Partition> & partitions ) void GParted_Core::set_used_sectors( std::vector<Partition> & partitions )
@ -730,6 +724,16 @@ std::vector<Glib::ustring> GParted_Core::get_disklabeltypes( )
return disklabeltypes ; return disklabeltypes ;
} }
std::vector<Glib::ustring> GParted_Core::get_all_mountpoints()
{
std::vector<Glib::ustring> mountpoints ;
for ( iter_mp = mount_info .begin() ; iter_mp != mount_info .end() ; ++iter_mp )
mountpoints .insert( mountpoints .end(), iter_mp ->second .begin(), iter_mp ->second .end() ) ;
return mountpoints ;
}
void GParted_Core::LP_Set_Used_Sectors( Partition & partition ) void GParted_Core::LP_Set_Used_Sectors( Partition & partition )
{ {
PedFileSystem *fs = NULL; PedFileSystem *fs = NULL;

View File

@ -1337,11 +1337,34 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
void Win_GParted::thread_unmount_partition( bool * succes, Glib::ustring * error ) void Win_GParted::thread_unmount_partition( bool * succes, Glib::ustring * error )
{ {
std::vector<Glib::ustring> errors, failed_mountpoints, mountpoints = gparted_core .get_all_mountpoints() ;
Glib::ustring dummy ; Glib::ustring dummy ;
*succes = true ; *succes = true ;
for ( unsigned int t = 0 ; t < selected_partition .mountpoints .size() && *succes ; t++ ) for ( unsigned int t = 0 ; t < selected_partition .mountpoints .size() ; t++ )
*succes = ! Utils::execute_command( "umount -v " + selected_partition .mountpoints[ t ], dummy, *error ) ; if ( std::count( mountpoints .begin(), mountpoints .end(), selected_partition .mountpoints[ t ] ) <= 1 )
{
if ( Utils::execute_command( "umount -v " + selected_partition .mountpoints[ t ],
dummy,
*error ) )
{
*succes = false ;
errors .push_back( *error ) ;
}
}
else
failed_mountpoints .push_back( selected_partition .mountpoints[ t ] ) ;
if ( *succes && failed_mountpoints .size() )
{
*succes = false ;
*error = _("The partition could not be unmounted from the following mountpoints:") ;
*error += "\n\n<i>" + Glib::build_path( "\n", failed_mountpoints ) + "</i>\n\n" ;
*error += _("Most likely other partitions are also mounted on these mountpoints. You are advised to unmount them manually.") ;
}
else
*error = "<i>" + Glib::build_path( "\n", errors ) + "</i>" ;
pulse = false ; pulse = false ;
} }
@ -1366,7 +1389,7 @@ void Win_GParted::activate_unmount()
Gtk::BUTTONS_OK, Gtk::BUTTONS_OK,
true ); true );
dialog .set_secondary_text( error ) ; dialog .set_secondary_text( error, true ) ;
dialog.run() ; dialog.run() ;
} }