diff --git a/include/Partition.h b/include/Partition.h index 45f64327..44661752 100644 --- a/include/Partition.h +++ b/include/Partition.h @@ -51,9 +51,6 @@ enum PartitionAlignment { // Indicator if start and end sectors must remain unchanged }; -//FIXME: we should make a difference between partition- and file system size. -//especially in the core this can make a difference when giving detailed feedback. With new cairosupport in gtkmm -//it's even possible to make stuff like this visible in the GUI in a nice and clear way class Partition { public: @@ -77,6 +74,8 @@ public: void Set_Unused( Sector sectors_unused ) ; void set_used( Sector sectors_used ) ; + void set_sector_usage( Sector sectors_fs_size, Sector sectors_fs_unused ) ; + bool significant_unallocated_space() const ; void Set_Unallocated( const Glib::ustring & device_path, Sector sector_start, @@ -117,6 +116,7 @@ public: Sector sector_end; Sector sectors_used; Sector sectors_unused; + Sector sectors_unallocated; //Difference between the size of the partition and the file system Gdk::Color color; bool inside_extended; bool busy; diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 9b9cdaf2..e7492b34 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -1486,7 +1486,15 @@ void GParted_Core::set_used_sectors( std::vector & partitions ) if ( partitions[ t ] .get_mountpoints() .size() > 0 ) { if ( statvfs( partitions[ t ] .get_mountpoint() .c_str(), &sfs ) == 0 ) - partitions[ t ] .Set_Unused( sfs .f_bfree * (sfs .f_bsize / partitions[ t ] .sector_size) ) ; + { + Sector fs_size = static_cast( sfs .f_blocks ) * + sfs .f_frsize / + partitions[ t ] .sector_size ; + Sector fs_free = static_cast( sfs .f_bfree ) * + sfs .f_bsize / + partitions[ t ] .sector_size ; + partitions[ t ] .set_sector_usage( fs_size, fs_free ) ; + } else partitions[ t ] .messages .push_back( "statvfs (" + @@ -1532,6 +1540,26 @@ void GParted_Core::set_used_sectors( std::vector & partitions ) } partitions[ t ] .messages .push_back( temp ) ; } + else if ( partitions[ t ] .significant_unallocated_space() ) + { + /* TO TRANSLATORS: looks like 1.28GiB of unallocated space within the partition. */ + temp = String::ucompose( _("%1 of unallocated space within the partition."), + Utils::format_size( partitions[ t ] .sectors_unallocated, partitions[ t ] .sector_size ) ) ; + FS fs = get_fs( partitions[ t ] .filesystem ) ; + if ( fs .check != GParted::FS::NONE + && fs .grow != GParted::FS::NONE ) + { + temp += "\n" ; + /* TO TRANSLATORS: To grow the file system to fill the partition, select the partition and choose the menu item: + * means that the user can perform a check of the partition which will + * also grow the file system to fill the partition. + */ + temp += _("To grow the file system to fill the partition, select the partition and choose the menu item:") ; + temp += "\n" ; + temp += _("Partition --> Check.") ; + } + partitions[ t ] .messages .push_back( temp ) ; + } } else if ( partitions[ t ] .type == GParted::TYPE_EXTENDED ) set_used_sectors( partitions[ t ] .logicals ) ; diff --git a/src/Partition.cc b/src/Partition.cc index 620fdeea..971a36e6 100644 --- a/src/Partition.cc +++ b/src/Partition.cc @@ -20,7 +20,9 @@ namespace GParted { - + +#define SIGNIFICANT_UNALLOCATED_PERCENTAGE 5.0 + Partition::Partition() { Reset() ; @@ -44,6 +46,7 @@ void Partition::Reset() label .clear() ; uuid .clear() ; partition_number = sector_start = sector_end = sectors_used = sectors_unused = -1; + sectors_unallocated = 0 ; free_space_before = -1 ; sector_size = 0 ; color .set( "black" ) ; @@ -80,24 +83,67 @@ void Partition::Set( const Glib::ustring & device_path, this ->color .set( Utils::get_color( filesystem ) ); } +//Deprecated method of setting file system free space, which assumes +// the file system fills the partition. void Partition::Set_Unused( Sector sectors_unused ) { if ( sectors_unused <= get_sector_length() ) { this ->sectors_unused = sectors_unused ; this ->sectors_used = ( sectors_unused == -1 ) ? -1 : get_sector_length() - sectors_unused ; + this ->sectors_unallocated = 0 ; } } - + +//Deprecated method of setting file system used space, which assumes +// the file system fills the partition. void Partition::set_used( Sector sectors_used ) { if ( sectors_used < get_sector_length() ) { this ->sectors_used = sectors_used ; this ->sectors_unused = ( sectors_used == -1 ) ? -1 : get_sector_length() - sectors_used ; + this ->sectors_unallocated = 0 ; } } +//Preferred method of setting file system size and free space, which also +// calculates unallocated space. Set sectors_fs_size = -1 for unknown. +void Partition::set_sector_usage( Sector sectors_fs_size, Sector sectors_fs_unused ) +{ + Sector length = get_sector_length() ; + if ( 0 <= sectors_fs_size && sectors_fs_size <= length + && 0 <= sectors_fs_unused && sectors_fs_unused <= sectors_fs_size + ) + { + sectors_used = sectors_fs_size - sectors_fs_unused ; + sectors_unused = sectors_fs_unused ; + sectors_unallocated = length - sectors_fs_size ; + } + else if ( sectors_fs_size == -1 ) + { + if ( 0 <= sectors_fs_unused && sectors_fs_unused <= length ) + { + sectors_used = length - sectors_fs_unused ; + sectors_unused = sectors_fs_unused ; + } + else + { + sectors_used = -1 ; + sectors_unused = -1 ; + } + sectors_unallocated = 0 ; + } +} + +bool Partition::significant_unallocated_space() const +{ + Sector length = get_sector_length() ; + if ( sectors_unallocated > 0 && length > 0 ) + return ( sectors_unallocated * 100.0 / length > SIGNIFICANT_UNALLOCATED_PERCENTAGE ) ; + return false ; +} + void Partition::Set_Unallocated( const Glib::ustring & device_path, Sector sector_start, Sector sector_end,