From 7aee5aed95fd1d502722dcff556c598f619c0da1 Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Thu, 8 Dec 2005 17:03:29 +0000 Subject: [PATCH] added 'Glib::ustring mountpoint' implemented set_mountpoints() to set * include/Partition.h, src/Partition.cc: added 'Glib::ustring mountpoint' * include/GParted_Core.h, src/GParted_Core.cc: implemented set_mountpoints() to set mountpoint in partitions. * include/Dialog_Partition_Info.h, src/Dialog_Partition_Info.cc: use Partition::mountpoint instead of finding it ourselves. --- ChangeLog | 11 ++++++++ include/Dialog_Partition_Info.h | 2 -- include/GParted_Core.h | 5 ++++ include/Partition.h | 1 + src/Dialog_Partition_Info.cc | 48 ++++++--------------------------- src/GParted_Core.cc | 45 ++++++++++++++++++++++++++++++- src/Partition.cc | 2 +- 7 files changed, 70 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index ceccd2a6..2316bbbf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-12-08 Bart Hakvoort + + * include/Partition.h, + src/Partition.cc: added 'Glib::ustring mountpoint' + * include/GParted_Core.h, + src/GParted_Core.cc: implemented set_mountpoints() to set mountpoint + in partitions. + * include/Dialog_Partition_Info.h, + src/Dialog_Partition_Info.cc: use Partition::mountpoint instead of + finding it ourselves. + 2005-12-07 Bart Hakvoort * include/Partition.h, diff --git a/include/Dialog_Partition_Info.h b/include/Dialog_Partition_Info.h index 45260d4f..01504830 100644 --- a/include/Dialog_Partition_Info.h +++ b/include/Dialog_Partition_Info.h @@ -48,7 +48,6 @@ public: private: void init_drawingarea( ) ; void Display_Info( ); - Glib::ustring Find_Status( ) ; //signalhandlers void drawingarea_on_realize( ); @@ -68,7 +67,6 @@ private: Gdk::Color color_partition, color_used, color_unused, color_text ; int used,unused ; - }; } //GParted diff --git a/include/GParted_Core.h b/include/GParted_Core.h index d4a38e78..fefee425 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -67,6 +67,7 @@ public: private: GParted::FILESYSTEM Get_Filesystem( ) ; //temporary function.. asa new checks ripple through in libparted i'll remove it. void set_device_partitions( Device & device ) ; + void set_mountpoints( std::vector & partitions, bool first_time = true ) ; void Insert_Unallocated( const Glib::ustring & device_path, std::vector & partitions, Sector start, Sector end, bool inside_extended ) ; Glib::ustring get_sym_path( const Glib::ustring & real_path ) ; void Set_Used_Sectors( Partition & partition ); @@ -96,6 +97,10 @@ private: Partition partition_temp ; FS fs ; + //used in set_mountpoints() + std::map mount_info ; + std::map::iterator iter ; + PedDevice *lp_device ; PedDisk *lp_disk ; PedPartition *lp_partition ; diff --git a/include/Partition.h b/include/Partition.h index c8196717..556ffc7b 100644 --- a/include/Partition.h +++ b/include/Partition.h @@ -94,6 +94,7 @@ public: bool busy; Glib::ustring error; Glib::ustring flags; + Glib::ustring mountpoint ; std::vector logicals ; diff --git a/src/Dialog_Partition_Info.cc b/src/Dialog_Partition_Info.cc index 2b6e9c5f..db5abcc4 100644 --- a/src/Dialog_Partition_Info.cc +++ b/src/Dialog_Partition_Info.cc @@ -183,7 +183,14 @@ void Dialog_Partition_Info::Display_Info( ) Glib::ustring str_temp ; table ->attach( * mk_label( "" + (Glib::ustring) _( "Status:" ) + "" ), 0,1, top, bottom, Gtk::FILL) ; if ( partition.busy ) - str_temp = Find_Status( ) ; + { + if ( partition .type == GParted::TYPE_EXTENDED ) + str_temp = _("Busy (At least one logical partition is mounted)" ) ; + else if ( partition .filesystem == FS_LINUX_SWAP ) + str_temp = _("Active") ; + else + str_temp = String::ucompose( _("Mounted on %1"), partition .mountpoint ) ; + } else if ( partition.type == GParted::TYPE_EXTENDED ) str_temp = _("Not busy (There are no mounted logical partitions)" ) ; else if ( partition.filesystem == GParted::FS_LINUX_SWAP ) @@ -210,45 +217,6 @@ void Dialog_Partition_Info::Display_Info( ) table ->attach( * mk_label( num_to_str( partition .sector_end - partition .sector_start ) ), 1, 2, top++, bottom++, Gtk::FILL ) ; } -Glib::ustring Dialog_Partition_Info::Find_Status( ) -{ - if ( partition .type == GParted::TYPE_EXTENDED ) - return _("Busy (At least one logical partition is mounted)" ) ; - else if ( partition .filesystem == FS_LINUX_SWAP ) - return _("Active") ; - - //try to find the mountpoint in /proc/mounts - //get realpath - char real_path[ 4096 ] ; - realpath( partition .partition .c_str( ), real_path ); - Glib::ustring mountpoint, partition_real_path = real_path ; //because root partition is listed as /dev/root we need te compare against te real path.. - - std::ifstream file_mounts( "/proc/mounts" ) ; - std::string line ; - - while ( getline( file_mounts, line ) ) - { - realpath( line .substr( 0, line.find( ' ' ) ) .c_str( ), real_path ); - - if ( partition_real_path == real_path ) - { - //this is so cool =) - mountpoint = line.substr( line .find( ' ' ) +1, line .length( ) ) ; - mountpoint = mountpoint .substr( 0, mountpoint .find( ' ' ) ) ; - - break ; - } - } - - file_mounts .close( ) ; - - //sometimes rootdevices are not listed as paths. I'll take a guess and just enter / here...( we'll look into this when complaints start coming in :P ) - if ( mountpoint .empty( ) ) - mountpoint = "/" ; - - return String::ucompose( _("Mounted on %1"), mountpoint ) ; -} - Dialog_Partition_Info::~Dialog_Partition_Info( ) { this ->get_colormap( ) ->free_colors( color_used, 1 ) ; diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index ddd58793..1b6005de 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -119,9 +119,12 @@ void GParted_Core::get_devices( std::vector & devices ) temp_device .max_prims = ped_disk_get_max_primary_partition_count( lp_disk ) ; set_device_partitions( temp_device ) ; - + if ( temp_device .highest_busy ) + { + set_mountpoints( temp_device .device_partitions ) ; temp_device .readonly = ! ped_disk_commit_to_os( lp_disk ) ; + } } //harddisk without disklabel else @@ -283,6 +286,46 @@ void GParted_Core::set_device_partitions( Device & device ) Insert_Unallocated( device .path, device .device_partitions, 0, device .length -1, false ) ; } +void GParted_Core::set_mountpoints( std::vector & partitions, bool first_time ) +{ + if ( first_time ) + { + char node[255], mountpoint[255] ; + std::string line ; + std::ifstream input( "/proc/mounts" ) ; + + while ( getline( input, line ) ) + if ( line .length() > 0 && line[ 0 ] == '/' && sscanf( line .c_str(),"%s %s", node, mountpoint ) == 2 ) + mount_info[ node ] = mountpoint ; + + input .close() ; + } + + + for ( unsigned int t = 0 ; t < partitions .size() ; t++ ) + { + if ( partitions[ t ] .busy && partitions[ t ] .filesystem != GParted::FS_LINUX_SWAP ) + { + if ( partitions[ t ] .type == GParted::TYPE_PRIMARY || partitions[ t ] .type == GParted::TYPE_LOGICAL ) + { + iter = mount_info .find( partitions[ t ] .partition ); + if ( iter != mount_info .end() ) + { + partitions[ t ] .mountpoint = iter ->second ; + mount_info .erase( iter ) ; + } + else + partitions[ t ] .mountpoint = "/" ; + } + else if ( partitions[ t ] .type == GParted::TYPE_EXTENDED ) + set_mountpoints( partitions[ t ] .logicals, false ) ; + } + } + + if ( first_time ) + mount_info .clear() ; +} + void GParted_Core::Insert_Unallocated( const Glib::ustring & device_path, std::vector & partitions, Sector start, Sector end, bool inside_extended ) { partition_temp .Reset( ) ; diff --git a/src/Partition.cc b/src/Partition.cc index 27001327..c2476f24 100644 --- a/src/Partition.cc +++ b/src/Partition.cc @@ -27,7 +27,7 @@ Partition::Partition( ) void Partition::Reset( ) { - partition = error = flags = "" ; + partition = error = flags = mountpoint = "" ; status = GParted::STAT_REAL ; type = GParted::TYPE_UNALLOCATED ; filesystem = GParted::FS_UNALLOCATED ;