added support for reading volumelabels. Atm we only read ext2/3, but the

* added support for reading volumelabels. Atm we only read ext2/3, but
  the infrastructure for adding the other filesystems is in place.
  It's simply a matter of finding the right commands and parsing the
  output. (see #338528 for more info)
This commit is contained in:
Bart Hakvoort 2006-09-12 20:34:33 +00:00
parent 5c704583bc
commit e3b4a7316b
35 changed files with 157 additions and 15 deletions

View File

@ -1,3 +1,10 @@
2006-09-12 Bart Hakvoort <hakvoort@cvs.gnome.org>
* added support for reading volumelabels. Atm we only read ext2/3, but
the infrastructure for adding the other filesystems is in place.
It's simply a matter of finding the right commands and parsing the
output. (see #338528 for more info)
2006-09-11 Bart Hakvoort <hakvoort@cvs.gnome.org>
* configure.in: bumped to gparted-0.3.1

View File

@ -35,6 +35,7 @@ public:
virtual FS get_filesystem_support() = 0 ;
virtual void set_used_sectors( Partition & partition ) = 0 ;
virtual void get_label( Partition & partition ) = 0 ;
virtual bool create( const Partition & new_partition, OperationDetail & operationdetail ) = 0 ;
virtual bool resize( const Partition & partition_new,
OperationDetail & operationdetail,

View File

@ -59,6 +59,7 @@ private:
std::vector<Glib::ustring> get_alternate_paths( const Glib::ustring & path ) ;
void set_device_partitions( Device & device ) ;
GParted::FILESYSTEM get_filesystem() ;
void get_label( Partition & partition ) ;
void insert_unallocated( const Glib::ustring & device_path,
std::vector<Partition> & partitions,
Sector start,

View File

@ -98,6 +98,7 @@ public:
PartitionType type;// UNALLOCATED, PRIMARY, LOGICAL, etc...
PartitionStatus status; //STAT_REAL, STAT_NEW, etc..
FILESYSTEM filesystem ;
Glib::ustring label ;
Sector sector_start;
Sector sector_end;
Sector sectors_used;

View File

@ -67,6 +67,7 @@ private:
Gtk::TreeModelColumn<Glib::ustring> path;
Gtk::TreeModelColumn<Glib::ustring> filesystem;
Gtk::TreeModelColumn<Glib::ustring> mountpoint;
Gtk::TreeModelColumn<Glib::ustring> label ;
Gtk::TreeModelColumn<Glib::ustring> size;
Gtk::TreeModelColumn<Glib::ustring> used;
Gtk::TreeModelColumn<Glib::ustring> unused;
@ -80,7 +81,7 @@ private:
treeview_detail_Columns()
{
add( path ); add( filesystem ); add( mountpoint ) ;
add( path ); add( filesystem ); add( mountpoint ) ; add( label ) ;
add( size ); add( used ); add( unused ); add( color );
add( text_color ); add( mount_text_color ); add( icon1 );
add( icon2 ) ; add( flags ); add( partition );

View File

@ -91,6 +91,7 @@ struct FS
FILESYSTEM filesystem ;
Support read ; //can we get the amount of used sectors?
Support get_label ;
Support create ;
Support grow ;
Support shrink ;
@ -103,7 +104,7 @@ struct FS
FS()
{
read = create = grow = shrink = move = check = copy = NONE;
read = get_label = create = grow = shrink = move = check = copy = NONE;
MIN = MAX = 0 ;
}
} ;

View File

@ -29,6 +29,7 @@ class ext2 : public FileSystem
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void get_label( Partition & partition ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool copy( const Glib::ustring & src_part_path,

View File

@ -29,6 +29,7 @@ class ext3 : public FileSystem
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void get_label( Partition & partition ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool copy( const Glib::ustring & src_part_path,

View File

@ -29,6 +29,7 @@ class fat16 : public FileSystem
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void get_label( Partition & partition ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool copy( const Glib::ustring & src_part_path,

View File

@ -29,6 +29,7 @@ class fat32 : public FileSystem
public:
FS get_filesystem_support();
void set_used_sectors( Partition & partition ) ;
void get_label( Partition & partition ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool copy( const Glib::ustring & src_part_path,

View File

@ -29,6 +29,7 @@ class hfs : public FileSystem
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void get_label( Partition & partition ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool copy( const Glib::ustring & src_part_path,

View File

@ -29,6 +29,7 @@ class hfsplus : public FileSystem
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void get_label( Partition & partition ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool copy( const Glib::ustring & src_part_path,

View File

@ -29,6 +29,7 @@ class jfs : public FileSystem
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void get_label( Partition & partition ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool copy( const Glib::ustring & src_part_path,

View File

@ -29,6 +29,7 @@ class linux_swap : public FileSystem
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void get_label( Partition & partition ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool copy( const Glib::ustring & src_part_path,

View File

@ -29,6 +29,7 @@ class ntfs : public FileSystem
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void get_label( Partition & partition ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool copy( const Glib::ustring & src_part_path,

View File

@ -29,6 +29,7 @@ class reiser4 : public FileSystem
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void get_label( Partition & partition ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool copy( const Glib::ustring & src_part_path,

View File

@ -29,6 +29,7 @@ class reiserfs : public FileSystem
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void get_label( Partition & partition ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool copy( const Glib::ustring & src_part_path,

View File

@ -29,6 +29,7 @@ class ufs : public FileSystem
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void get_label( Partition & partition ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool copy( const Glib::ustring & src_part_path,

View File

@ -29,6 +29,7 @@ class xfs : public FileSystem
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void get_label( Partition & partition ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool copy( const Glib::ustring & src_part_path,

View File

@ -593,6 +593,8 @@ void GParted_Core::set_device_partitions( Device & device )
break;
}
get_label( partition_temp ) ;
partition_temp .messages .insert( partition_temp .messages .end(),
libparted_messages. begin(),
libparted_messages .end() ) ;
@ -679,6 +681,25 @@ GParted::FILESYSTEM GParted_Core::get_filesystem()
return GParted::FS_UNKNOWN ;
}
void GParted_Core::get_label( Partition & partition )
{
if ( partition .type != TYPE_EXTENDED )
{
switch( get_fs( partition .filesystem ) .get_label )
{
case FS::EXTERNAL:
if ( set_proper_filesystem( partition .filesystem ) )
p_filesystem ->get_label( partition ) ;
break ;
case FS::LIBPARTED:
break ;
default:
break ;
}
}
}
void GParted_Core::insert_unallocated( const Glib::ustring & device_path,
std::vector<Partition> & partitions,

View File

@ -39,6 +39,7 @@ void Partition::Reset()
status = GParted::STAT_REAL ;
type = GParted::TYPE_UNALLOCATED ;
filesystem = GParted::FS_UNALLOCATED ;
label .clear() ;
partition_number = sector_start = sector_end = sectors_used = sectors_unused = -1;
color .set( "black" ) ;
inside_extended = busy = strict = false ;

View File

@ -34,6 +34,7 @@ TreeView_Detail::TreeView_Detail()
append_column( _("Partition"), treeview_detail_columns .path );
append_column( _("Filesystem"), treeview_detail_columns .color );
append_column( _("Mountpoint"), treeview_detail_columns .mountpoint );
append_column( _("Label"), treeview_detail_columns .label );
append_column( _("Size"), treeview_detail_columns .size );
append_column( _("Used"), treeview_detail_columns .used );
append_column( _("Unused"), treeview_detail_columns .unused );
@ -71,11 +72,11 @@ TreeView_Detail::TreeView_Detail()
treeview_detail_columns .mount_text_color );
//set alignment of numeric columns to right
for( short t = 3 ; t < 6 ; t++ )
for( short t = 4 ; t < 7 ; t++ )
get_column_cell_renderer( t ) ->property_xalign() = 1 ;
//expand columns and centeralign the headertext
for( short t = 3 ; t < 7 ; t++ )
for( short t = 4 ; t < 8 ; t++ )
{
get_column( t ) ->set_expand( true ) ;
get_column( t ) ->set_alignment( 0.5 ) ;
@ -83,8 +84,8 @@ TreeView_Detail::TreeView_Detail()
}
void TreeView_Detail::load_partitions( const std::vector<Partition> & partitions )
{
bool mount_info = false ;
{//FIXME:rewrite this one to make use of recursivity instead of duplicating stuff
bool mount_info = false, label = false ;
treestore_detail ->clear() ;
for ( unsigned int i = 0 ; i < partitions .size() ; i++ )
@ -101,14 +102,21 @@ void TreeView_Detail::load_partitions( const std::vector<Partition> & partitions
if ( partitions[ i ] .logicals[ t ] .get_mountpoints() .size() )
mount_info = true ;
if ( ! partitions[ i ] .label .empty() )
label = true ;
}
}
if ( partitions[ i ] .get_mountpoints() .size() )
mount_info = true ;
if ( ! partitions[ i ] .label .empty() )
label = true ;
}
get_column( 2 ) ->set_visible( mount_info ) ;
get_column( 3 ) ->set_visible( label ) ;
columns_autosize();
expand_all() ;
@ -180,6 +188,8 @@ void TreeView_Detail::create_row( const Gtk::TreeRow & treerow, const Partition
//mountpoint
treerow[ treeview_detail_columns .mount_text_color ] = partition .busy ? "black" : "darkgrey" ;
treerow[ treeview_detail_columns .mountpoint ] = Glib::build_path( ", ", partition .get_mountpoints() ) ;
treerow[ treeview_detail_columns .label ] = partition .label ;
//size
treerow[ treeview_detail_columns .size ] = Utils::format_size( partition .get_length() ) ;

View File

@ -23,29 +23,32 @@ namespace GParted
FS ext2::get_filesystem_support()
{
FS fs ;
fs .filesystem = GParted::FS_EXT2 ;
fs .filesystem = FS_EXT2 ;
if ( ! Glib::find_program_in_path( "dumpe2fs" ) .empty() )
fs .read = GParted::FS::EXTERNAL ;
fs .read = FS::EXTERNAL ;
if ( ! Glib::find_program_in_path( "e2label" ) .empty() )
fs .get_label = FS::EXTERNAL ;
if ( ! Glib::find_program_in_path( "mkfs.ext2" ) .empty() )
fs .create = GParted::FS::EXTERNAL ;
fs .create = FS::EXTERNAL ;
if ( ! Glib::find_program_in_path( "e2fsck" ) .empty() )
fs .check = GParted::FS::EXTERNAL ;
fs .check = FS::EXTERNAL ;
if ( ! Glib::find_program_in_path( "resize2fs" ) .empty() && fs .check )
{
fs .grow = GParted::FS::EXTERNAL ;
fs .grow = FS::EXTERNAL ;
if ( fs .read ) //needed to determine a min filesystemsize..
fs .shrink = GParted::FS::EXTERNAL ;
fs .shrink = FS::EXTERNAL ;
}
if ( fs .check )
{
fs .copy = GParted::FS::GPARTED ;
fs .move = GParted::FS::GPARTED ;
fs .copy = FS::GPARTED ;
fs .move = FS::GPARTED ;
}
return fs ;
@ -77,6 +80,25 @@ void ext2::set_used_sectors( Partition & partition )
partition .messages .push_back( error ) ;
}
}
void ext2::get_label( Partition & partition )
{
if ( ! Utils::execute_command( "e2label " + partition .get_path(), output, error, true ) )
{
if ( output .size() > 0 && output[ output .size() -1 ] == '\n' )
partition .label = output .substr( 0, output .size() -1 ) ;
else
partition .label + output ;
}
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
if ( ! error .empty() )
partition .messages .push_back( error ) ;
}
}
bool ext2::create( const Partition & new_partition, OperationDetail & operationdetail )
{
@ -89,7 +111,7 @@ bool ext2::resize( const Partition & partition_new, OperationDetail & operationd
if ( ! fill_partition )
str_temp += " " + Utils::num_to_str( Utils::round( Utils::sector_to_unit(
partition_new .get_length(), GParted::UNIT_KIB ) ) -1, true ) + "K" ;
partition_new .get_length(), UNIT_KIB ) ) -1, true ) + "K" ;
return ! execute_command( str_temp, operationdetail ) ;
}

View File

@ -79,6 +79,25 @@ void ext3::set_used_sectors( Partition & partition )
}
}
void ext3::get_label( Partition & partition )
{
if ( ! Utils::execute_command( "e2label " + partition .get_path(), output, error, true ) )
{
if ( output .size() > 0 && output[ output .size() -1 ] == '\n' )
partition .label = output .substr( 0, output .size() -1 ) ;
else
partition .label + output ;
}
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
if ( ! error .empty() )
partition .messages .push_back( error ) ;
}
}
bool ext3::create( const Partition & new_partition, OperationDetail & operationdetail )
{
return ! execute_command( "mkfs.ext3 " + new_partition .get_path(), operationdetail ) ;

View File

@ -78,6 +78,10 @@ void fat16::set_used_sectors( Partition & partition )
partition .messages .push_back( error ) ;
}
}
void fat16::get_label( Partition & partition )
{
}
bool fat16::create( const Partition & new_partition, OperationDetail & operationdetail )
{

View File

@ -79,6 +79,10 @@ void fat32::set_used_sectors( Partition & partition )
}
}
void fat32::get_label( Partition & partition )
{
}
bool fat32::create( const Partition & new_partition, OperationDetail & operationdetail )
{
return ! execute_command( "mkdosfs -F32 -v " + new_partition .get_path(), operationdetail ) ;

View File

@ -45,6 +45,10 @@ void hfs::set_used_sectors( Partition & partition )
{
}
void hfs::get_label( Partition & partition )
{
}
bool hfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{
return ! execute_command( "hformat " + new_partition .get_path(), operationdetail ) ;

View File

@ -40,6 +40,10 @@ void hfsplus::set_used_sectors( Partition & partition )
{
}
void hfsplus::get_label( Partition & partition )
{
}
bool hfsplus::create( const Partition & new_partition, OperationDetail & operationdetail )
{
return true ;

View File

@ -99,6 +99,10 @@ void jfs::set_used_sectors( Partition & partition )
}
}
void jfs::get_label( Partition & partition )
{
}
bool jfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{
return ! execute_command( "mkfs.jfs -q " + new_partition .get_path(), operationdetail ) ;

View File

@ -43,6 +43,10 @@ void linux_swap::set_used_sectors( Partition & partition )
{
}
void linux_swap::get_label( Partition & partition )
{
}
bool linux_swap::create( const Partition & new_partition, OperationDetail & operationdetail )
{
return ! execute_command( "mkswap " + new_partition .get_path(), operationdetail ) ;

View File

@ -77,6 +77,10 @@ void ntfs::set_used_sectors( Partition & partition )
}
}
void ntfs::get_label( Partition & partition )
{
}
bool ntfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{
return ! execute_command( "mkntfs -Q -vv " + new_partition .get_path(), operationdetail ) ;

View File

@ -77,6 +77,10 @@ void reiser4::set_used_sectors( Partition & partition )
}
}
void reiser4::get_label( Partition & partition )
{
}
bool reiser4::create( const Partition & new_partition, OperationDetail & operationdetail )
{
return ! execute_command( "mkfs.reiser4 --yes " + new_partition .get_path(), operationdetail ) ;

View File

@ -81,6 +81,10 @@ void reiserfs::set_used_sectors( Partition & partition )
partition .messages .push_back( error ) ;
}
}
void reiserfs::get_label( Partition & partition )
{
}
bool reiserfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{

View File

@ -37,6 +37,10 @@ void ufs::set_used_sectors( Partition & partition )
{
}
void ufs::get_label( Partition & partition )
{
}
bool ufs::create( const Partition & new_partition, OperationDetail & operationdetail )
{
return true ;

View File

@ -101,6 +101,10 @@ void xfs::set_used_sectors( Partition & partition )
}
}
void xfs::get_label( Partition & partition )
{
}
bool xfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{
return ! execute_command( "mkfs.xfs -f " + new_partition .get_path(), operationdetail ) ;