mirror of
https://gitlab.gnome.org/GNOME/gparted
synced 2024-11-05 20:46:55 +00:00
Add reporting of linux-swap usage (#708107)
For active swap space read the usage from /proc/swaps. (Linux kernel uses units of 1 KiB). By definition inactive swap space is 100% free. $ cat /proc/swaps Filename Type Size Used Priority /dev/sda2 partition 5242876 430552 -1 Always set fs.read = FS::EXTERNAL even if /proc/swaps doesn't exist so that an attempt is made to open the file generating a specific error, in addition to the generic error. open("/proc/swaps", O_RDONLY): No such file or directory Unable to read the contents of this file system! Because of this some operations may be unavailable. The cause might be a missing software package. The following list of software packages is required for linux- swap file system support: util-linux. Closes Bug #708107 - Usage of swap space is not reported
This commit is contained in:
parent
f41bb75495
commit
387b391d6d
3 changed files with 47 additions and 2 deletions
|
@ -31,6 +31,7 @@ public:
|
||||||
virtual const Glib::ustring get_custom_text( CUSTOM_TEXT ttype, int index = 0 ) ;
|
virtual const Glib::ustring get_custom_text( CUSTOM_TEXT ttype, int index = 0 ) ;
|
||||||
|
|
||||||
FS get_filesystem_support() ;
|
FS get_filesystem_support() ;
|
||||||
|
void set_used_sectors( Partition & partition ) ;
|
||||||
void read_label( Partition & partition ) ;
|
void read_label( Partition & partition ) ;
|
||||||
bool write_label( const Partition & partition, OperationDetail & operationdetail ) ;
|
bool write_label( const Partition & partition, OperationDetail & operationdetail ) ;
|
||||||
void read_uuid( Partition & partition ) ;
|
void read_uuid( Partition & partition ) ;
|
||||||
|
|
|
@ -1539,8 +1539,7 @@ void GParted_Core::set_used_sectors( std::vector<Partition> & partitions, PedDis
|
||||||
{
|
{
|
||||||
for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
|
for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
|
||||||
{
|
{
|
||||||
if ( partitions[ t ] .filesystem != GParted::FS_LINUX_SWAP &&
|
if ( partitions[ t ] .filesystem != GParted::FS_LUKS &&
|
||||||
partitions[ t ] .filesystem != GParted::FS_LUKS &&
|
|
||||||
partitions[ t ] .filesystem != GParted::FS_UNKNOWN
|
partitions[ t ] .filesystem != GParted::FS_UNKNOWN
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include "../include/linux_swap.h"
|
#include "../include/linux_swap.h"
|
||||||
|
|
||||||
|
#include <cerrno>
|
||||||
|
|
||||||
namespace GParted
|
namespace GParted
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -43,6 +45,9 @@ FS linux_swap::get_filesystem_support()
|
||||||
FS fs ;
|
FS fs ;
|
||||||
fs .filesystem = GParted::FS_LINUX_SWAP ;
|
fs .filesystem = GParted::FS_LINUX_SWAP ;
|
||||||
|
|
||||||
|
fs .read = FS::EXTERNAL ;
|
||||||
|
fs .online_read = FS::EXTERNAL ;
|
||||||
|
|
||||||
if ( ! Glib::find_program_in_path( "mkswap" ) .empty() )
|
if ( ! Glib::find_program_in_path( "mkswap" ) .empty() )
|
||||||
{
|
{
|
||||||
fs .create = GParted::FS::EXTERNAL ;
|
fs .create = GParted::FS::EXTERNAL ;
|
||||||
|
@ -65,6 +70,46 @@ FS linux_swap::get_filesystem_support()
|
||||||
return fs ;
|
return fs ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void linux_swap::set_used_sectors( Partition & partition )
|
||||||
|
{
|
||||||
|
if ( partition .busy )
|
||||||
|
{
|
||||||
|
T = -1 ; N = -1 ;
|
||||||
|
std::string line ;
|
||||||
|
std::ifstream input( "/proc/swaps" ) ;
|
||||||
|
if ( input )
|
||||||
|
{
|
||||||
|
Glib::ustring path = partition .get_path() ;
|
||||||
|
Glib::ustring::size_type path_len = path.length() ;
|
||||||
|
while ( getline( input, line ) )
|
||||||
|
{
|
||||||
|
if ( line .substr( 0, path_len ) == path )
|
||||||
|
{
|
||||||
|
sscanf( line .substr( path_len ) .c_str(), " %*s %Ld %Ld", &T, &N ) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
input .close() ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
partition .messages .push_back( "open(\"/proc/swaps\", O_RDONLY): " + Glib::strerror( errno ) ) ;
|
||||||
|
}
|
||||||
|
if ( T > -1 && N > -1 )
|
||||||
|
{
|
||||||
|
T = Utils::round( T * ( KIBIBYTE / double(partition .sector_size) ) ) ;
|
||||||
|
N = Utils::round( N * ( KIBIBYTE / double(partition .sector_size) ) ) ;
|
||||||
|
partition .set_sector_usage( T, T - N ) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//By definition inactive swap space is 100% free
|
||||||
|
Sector size = partition .get_sector_length() ;
|
||||||
|
partition .set_sector_usage( size, size ) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void linux_swap::read_label( Partition & partition )
|
void linux_swap::read_label( Partition & partition )
|
||||||
{
|
{
|
||||||
if ( ! Utils::execute_command( "swaplabel " + partition .get_path(), output, error, true ) )
|
if ( ! Utils::execute_command( "swaplabel " + partition .get_path(), output, error, true ) )
|
||||||
|
|
Loading…
Reference in a new issue