extended scan for mountpoints (see #333370)

* include/GParted_Core.h,
  src/GParted_Core.cc: extended scan for mountpoints (see #333370)
This commit is contained in:
Bart Hakvoort 2006-03-05 21:08:49 +00:00
parent 58eff60c68
commit 170eb4b4a4
3 changed files with 32 additions and 26 deletions

View File

@ -1,3 +1,8 @@
2006-03-05 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/GParted_Core.h,
src/GParted_Core.cc: extended scan for mountpoints (see #333370)
2006-03-05 Bart Hakvoort <hakvoort@cvs.gnome.org>
* src/Dialog_Partition_Info.cc,

View File

@ -73,6 +73,7 @@ private:
GParted::FILESYSTEM get_filesystem() ;
bool check_device_path( const Glib::ustring & device_path ) ;
void set_device_partitions( Device & device ) ;
void read_mountpoints_from_file( const Glib::ustring & filename ) ;
void init_maps() ;
void set_mountpoints( std::vector<Partition> & partitions ) ;
void set_short_paths( std::vector<Partition> & partitions ) ;

View File

@ -180,20 +180,16 @@ void GParted_Core::get_devices( std::vector<Device> & devices )
short_paths .clear() ;
}
void GParted_Core::init_maps()
void GParted_Core::read_mountpoints_from_file( const Glib::ustring & filename )
{
std::string line ;
short_paths .clear() ;
mount_info .clear() ;
//initialize mountpoints..
char node[255], mountpoint[255] ;
unsigned int index ;
std::ifstream proc_mounts( "/proc/mounts" ) ;
if ( proc_mounts )
std::ifstream file( filename .c_str() ) ;
if ( file )
{
while ( getline( proc_mounts, line ) )
while ( getline( file, line ) )
if ( Glib::str_has_prefix( line, "/" ) &&
sscanf( line .c_str(), "%255s %255s", node, mountpoint ) == 2 &&
static_cast<Glib::ustring>( node ) != "/dev/root" )
@ -207,26 +203,30 @@ void GParted_Core::init_maps()
mount_info[ node ] .push_back( line ) ;
}
proc_mounts .close() ;
file .close() ;
}
}
//above list lacks the root mountpoint, try to get it from /etc/mtab
std::ifstream etc_mtab( "/etc/mtab" ) ;
if ( etc_mtab )
void GParted_Core::init_maps()
{
short_paths .clear() ;
mount_info .clear() ;
read_mountpoints_from_file( "/proc/mounts" ) ;
read_mountpoints_from_file( "/etc/mtab" ) ;
//sort the mountpoints and remove duplicates..
for ( iter_mp = mount_info .begin() ; iter_mp != mount_info .end() ; ++iter_mp )
{
while ( getline( etc_mtab, line ) )
if ( Glib::str_has_prefix( line, "/" ) &&
sscanf( line .c_str(), "%255s %255s", node, mountpoint ) == 2 &&
static_cast<Glib::ustring>( mountpoint ) == "/" )
{
mount_info[ node ] .push_back( "/" ) ;
break ;
}
std::sort( iter_mp ->second .begin(), iter_mp ->second .end() ) ;
etc_mtab .close() ;
iter_mp ->second .erase(
std::unique( iter_mp ->second .begin(), iter_mp ->second .end() ),
iter_mp ->second .end() ) ;
}
//initialize shortpaths...
std::string line ;
std::ifstream proc_partitions( "/proc/partitions" ) ;
if ( proc_partitions )
{