added include/Utils.h replaced get_sym_path with get_short_path for

* po/POTFILES.in: added include/Utils.h
* include/GParted_Core.h,
  src/GParted_Core.cc: replaced get_sym_path with get_short_path for
  cleaner code and better performance.
This commit is contained in:
Bart Hakvoort 2005-12-11 18:46:43 +00:00
parent a6a47c7df5
commit 391f802577
4 changed files with 33 additions and 24 deletions

View File

@ -1,3 +1,10 @@
2005-12-11 Bart Hakvoort <hakvoort@cvs.gnome.org>
* po/POTFILES.in: added include/Utils.h
* include/GParted_Core.h,
src/GParted_Core.cc: replaced get_sym_path with get_short_path for
cleaner code and better performance.
2005-12-11 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/GParted_Core.h,

View File

@ -70,7 +70,7 @@ private:
void set_mountpoints( std::vector<Partition> & partitions, bool first_time = true ) ;
void set_used_sectors( std::vector<Partition> & partitions ) ;
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 ) ;
Glib::ustring get_short_path( const Glib::ustring & real_path ) ;
void LP_Set_Used_Sectors( Partition & partition );
Glib::ustring Get_Flags( ) ;
int Create_Empty_Partition( Partition & new_partition, bool copy = false ) ;

View File

@ -1,6 +1,7 @@
# List of source files containing translatable strings.
# Please keep this file sorted alphabetically.
gparted.desktop.in
include/Utils.h
src/Dialog_Base_Partition.cc
src/Dialog_Disklabel.cc
src/Dialog_Filesystems.cc

View File

@ -88,7 +88,7 @@ void GParted_Core::get_devices( std::vector<Device> & devices )
while ( lp_device && strlen( lp_device ->path ) > 6 && static_cast<Glib::ustring>( lp_device ->path ) .is_ascii( ) )
{
if ( open_device( lp_device ->path ) )
device_paths .push_back( get_sym_path( lp_device ->path ) ) ;
device_paths .push_back( get_short_path( lp_device ->path ) ) ;
lp_device = ped_device_get_next( lp_device ) ;
}
@ -625,33 +625,34 @@ std::vector<Glib::ustring> GParted_Core::get_disklabeltypes( )
return disklabeltypes ;
}
Glib::ustring GParted_Core::get_sym_path( const Glib::ustring & real_path )
Glib::ustring GParted_Core::get_short_path( const Glib::ustring & real_path )
{
int major, minor, size;
char temp[4096], device_name[4096], short_path[4096] ;
int major, minor ;
char resolved_path[255] ;
Glib::ustring short_path = real_path ;
FILE* proc_part_file = fopen ( "/proc/partitions", "r" );
if ( ! proc_part_file )
return real_path;
std::string line ;
std::ifstream input( "/proc/partitions" ) ;
//skip first 2 useless rules of /proc/partitions
fgets( temp, 256, proc_part_file ); fgets( temp, 256, proc_part_file );
while ( fgets( temp, 4096, proc_part_file ) && sscanf(temp, "%d %d %d %255s", &major, &minor, &size, device_name ) == 4 )
if ( input )
{
strcpy( short_path, "/dev/" ); strcat( short_path, device_name );
realpath( short_path, device_name );
if ( real_path == device_name ) {
fclose ( proc_part_file );
return ( Glib::ustring( short_path ) );
while ( getline( input, line ) )
{
if ( sscanf( line .c_str(), "%d %d", &major, &minor ) == 2 && minor == 0 )
{
line = "/dev/" + line .substr( line .find_last_of( ' ', line .length() ) +1 ) ;
if ( realpath( line .c_str(), resolved_path ) && real_path == resolved_path )
{
short_path = resolved_path ;
break ;
}
}
}
input .close() ;
}
//paranoia modus :)
fclose ( proc_part_file );
return real_path;
return short_path ;
}
void GParted_Core::LP_Set_Used_Sectors( Partition & partition )