Create helper functions to check for minimum kernel version
Create function Utils::kernel_version_at_least() to check that the current Linux kernel is a particular version or higher. Update nilfs2 to use this function to determine whether the kernel is new enough to support file system resizing.
This commit is contained in:
parent
88cfe40a8b
commit
5967966ff7
|
@ -156,6 +156,7 @@ public:
|
|||
static Glib::ustring get_filesystem_string( FILESYSTEM filesystem ) ;
|
||||
static Glib::ustring get_filesystem_software( FILESYSTEM filesystem ) ;
|
||||
static bool kernel_supports_fs( const Glib::ustring & fs ) ;
|
||||
static bool kernel_version_at_least( int major_ver, int minor_ver, int patch_ver ) ;
|
||||
static Glib::ustring format_size( Sector sectors, Byte_Value sector_size ) ;
|
||||
static Glib::ustring format_time( std::time_t seconds ) ;
|
||||
static double sector_to_unit( Sector sectors, Byte_Value sector_size, SIZE_UNIT size_unit ) ;
|
||||
|
@ -182,6 +183,9 @@ public:
|
|||
const Glib::ustring& delimiters ) ;
|
||||
static int convert_to_int(const Glib::ustring & src);
|
||||
static Glib::ustring generate_uuid(void);
|
||||
|
||||
private:
|
||||
static bool get_kernel_version( int & major_ver, int & minor_ver, int & patch_ver ) ;
|
||||
};
|
||||
|
||||
|
||||
|
|
45
src/Utils.cc
45
src/Utils.cc
|
@ -236,6 +236,18 @@ bool Utils::kernel_supports_fs( const Glib::ustring & fs )
|
|||
return fs_supported ;
|
||||
}
|
||||
|
||||
//Report if kernel version is >= (major, minor, patch)
|
||||
bool Utils::kernel_version_at_least( int major_ver, int minor_ver, int patch_ver )
|
||||
{
|
||||
int actual_major_ver, actual_minor_ver, actual_patch_ver ;
|
||||
if ( ! get_kernel_version( actual_major_ver, actual_minor_ver, actual_patch_ver ) )
|
||||
return false ;
|
||||
bool result = ( actual_major_ver > major_ver )
|
||||
|| ( actual_major_ver == major_ver && actual_minor_ver > minor_ver )
|
||||
|| ( actual_major_ver == major_ver && actual_minor_ver == minor_ver && actual_patch_ver >= patch_ver ) ;
|
||||
return result ;
|
||||
}
|
||||
|
||||
Glib::ustring Utils::format_size( Sector sectors, Byte_Value sector_size )
|
||||
{
|
||||
std::stringstream ss ;
|
||||
|
@ -594,5 +606,38 @@ Glib::ustring Utils::generate_uuid(void)
|
|||
return uuid_str;
|
||||
}
|
||||
|
||||
//private functions ...
|
||||
|
||||
//Read kernel version, reporting success or failure
|
||||
bool Utils::get_kernel_version( int & major_ver, int & minor_ver, int & patch_ver )
|
||||
{
|
||||
static bool read_file = false ;
|
||||
static int read_major_ver = -1 ;
|
||||
static int read_minor_ver = -1 ;
|
||||
static int read_patch_ver = -1 ;
|
||||
|
||||
bool success = false ;
|
||||
if ( ! read_file )
|
||||
{
|
||||
std::ifstream input( "/proc/version" ) ;
|
||||
std::string line ;
|
||||
if ( input )
|
||||
{
|
||||
getline( input, line ) ;
|
||||
sscanf( line .c_str(), "Linux version %d.%d.%d",
|
||||
&read_major_ver, &read_minor_ver, &read_patch_ver ) ;
|
||||
input .close() ;
|
||||
}
|
||||
read_file = true ;
|
||||
}
|
||||
if ( read_major_ver > -1 && read_minor_ver > -1 && read_patch_ver > -1 )
|
||||
{
|
||||
major_ver = read_major_ver ;
|
||||
minor_ver = read_minor_ver ;
|
||||
patch_ver = read_patch_ver ;
|
||||
success = true ;
|
||||
}
|
||||
return success ;
|
||||
}
|
||||
|
||||
} //GParted..
|
||||
|
|
|
@ -40,33 +40,18 @@ FS nilfs2::get_filesystem_support()
|
|||
fs .write_uuid = GParted::FS::EXTERNAL ;
|
||||
}
|
||||
|
||||
//Nilfs2 resizing is an online only operation and needs:
|
||||
// mount, umount, nilfs-resize and linux >= 3.0 with nilfs2 support.
|
||||
if ( ! Glib::find_program_in_path( "mount" ) .empty() &&
|
||||
! Glib::find_program_in_path( "umount" ) .empty() &&
|
||||
! Glib::find_program_in_path( "nilfs-resize" ) .empty() &&
|
||||
Utils::kernel_supports_fs( "nilfs2" ) )
|
||||
{
|
||||
std::ifstream input( "/proc/version" ) ;
|
||||
std::string line ;
|
||||
int linux_major_ver = -1 ;
|
||||
int linux_minor_ver = -1 ;
|
||||
int linux_patch_ver = -1 ;
|
||||
if ( input )
|
||||
{
|
||||
getline( input, line ) ;
|
||||
sscanf( line .c_str() , "Linux version %d.%d.%d",
|
||||
&linux_major_ver, &linux_minor_ver, &linux_patch_ver ) ;
|
||||
input .close() ;
|
||||
}
|
||||
|
||||
if ( linux_major_ver >= 3 )
|
||||
{
|
||||
fs .grow = GParted::FS::EXTERNAL ;
|
||||
if ( fs .read ) //needed to determine a minimum file system size.
|
||||
fs .shrink = GParted::FS::EXTERNAL ;
|
||||
}
|
||||
}
|
||||
//Nilfs2 resizing is an online only operation and needs:
|
||||
// mount, umount, nilfs-resize and linux >= 3.0 with nilfs2 support.
|
||||
if ( ! Glib::find_program_in_path( "mount" ) .empty() &&
|
||||
! Glib::find_program_in_path( "umount" ) .empty() &&
|
||||
! Glib::find_program_in_path( "nilfs-resize" ) .empty() &&
|
||||
Utils::kernel_supports_fs( "nilfs2" ) &&
|
||||
Utils::kernel_version_at_least( 3, 0, 0 ) )
|
||||
{
|
||||
fs .grow = GParted::FS::EXTERNAL ;
|
||||
if ( fs .read ) //needed to determine a minimum file system size.
|
||||
fs .shrink = GParted::FS::EXTERNAL ;
|
||||
}
|
||||
|
||||
fs .copy = GParted::FS::GPARTED ;
|
||||
fs .move = GParted::FS::GPARTED ;
|
||||
|
|
Loading…
Reference in New Issue