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.
This commit is contained in:
Bart Hakvoort 2005-12-08 17:03:29 +00:00
parent 642f0a145b
commit 7aee5aed95
7 changed files with 70 additions and 44 deletions

View File

@ -1,3 +1,14 @@
2005-12-08 Bart Hakvoort <hakvoort@cvs.gnome.org>
* 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 <hakvoort@cvs.gnome.org>
* include/Partition.h,

View File

@ -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

View File

@ -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<Partition> & partitions, bool first_time = true ) ;
void Insert_Unallocated( const Glib::ustring & device_path, std::vector<Partition> & 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<Glib::ustring, Glib::ustring> mount_info ;
std::map<Glib::ustring, Glib::ustring>::iterator iter ;
PedDevice *lp_device ;
PedDisk *lp_disk ;
PedPartition *lp_partition ;

View File

@ -94,6 +94,7 @@ public:
bool busy;
Glib::ustring error;
Glib::ustring flags;
Glib::ustring mountpoint ;
std::vector<Partition> logicals ;

View File

@ -183,7 +183,14 @@ void Dialog_Partition_Info::Display_Info( )
Glib::ustring str_temp ;
table ->attach( * mk_label( "<b>" + (Glib::ustring) _( "Status:" ) + "</b>" ), 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 ) ;

View File

@ -119,9 +119,12 @@ void GParted_Core::get_devices( std::vector<Device> & 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<Partition> & 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<Partition> & partitions, Sector start, Sector end, bool inside_extended )
{
partition_temp .Reset( ) ;

View File

@ -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 ;