2011-12-08 05:45:12 -07:00
|
|
|
/* Copyright (C) 2011 Mike Fleetwood
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-01-23 03:59:48 -07:00
|
|
|
* GNU General Public License for more details.
|
2011-12-08 05:45:12 -07:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-23 03:59:48 -07:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2011-12-08 05:45:12 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "../include/nilfs2.h"
|
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
|
|
|
FS nilfs2::get_filesystem_support()
|
|
|
|
{
|
|
|
|
FS fs ;
|
|
|
|
fs .filesystem = GParted::FS_NILFS2 ;
|
|
|
|
|
2014-02-14 18:26:32 -07:00
|
|
|
fs .busy = FS::GPARTED ;
|
|
|
|
|
2011-12-08 05:45:12 -07:00
|
|
|
if ( ! Glib::find_program_in_path( "mkfs.nilfs2" ) .empty() )
|
|
|
|
{
|
|
|
|
fs .create = GParted::FS::EXTERNAL ;
|
2013-06-05 15:15:47 -06:00
|
|
|
fs .create_with_label = GParted::FS::EXTERNAL ;
|
2011-12-08 05:45:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! Glib::find_program_in_path( "nilfs-tune" ) .empty() )
|
|
|
|
{
|
|
|
|
fs .read = GParted::FS::EXTERNAL ;
|
|
|
|
fs .read_label = GParted::FS::EXTERNAL ;
|
|
|
|
fs .write_label = GParted::FS::EXTERNAL ;
|
2012-01-22 13:49:52 -07:00
|
|
|
fs .read_uuid = GParted::FS::EXTERNAL ;
|
|
|
|
fs .write_uuid = GParted::FS::EXTERNAL ;
|
2011-12-08 05:45:12 -07:00
|
|
|
}
|
|
|
|
|
2012-02-05 02:06:44 -07:00
|
|
|
//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 ;
|
|
|
|
}
|
2011-12-27 11:31:10 -07:00
|
|
|
|
2011-12-08 05:45:12 -07:00
|
|
|
fs .copy = GParted::FS::GPARTED ;
|
|
|
|
fs .move = GParted::FS::GPARTED ;
|
2012-09-10 09:41:58 -06:00
|
|
|
fs .online_read = FS::GPARTED ;
|
2013-11-15 09:27:12 -07:00
|
|
|
#ifdef ENABLE_ONLINE_RESIZE
|
|
|
|
if ( Utils::kernel_version_at_least( 3, 6, 0 ) )
|
|
|
|
{
|
|
|
|
fs .online_grow = fs .grow ;
|
|
|
|
fs .online_shrink = fs .shrink ;
|
|
|
|
}
|
|
|
|
#endif
|
2011-12-08 05:45:12 -07:00
|
|
|
|
2011-12-27 11:31:10 -07:00
|
|
|
//Minimum FS size is 128M+4K using mkfs.nilfs2 defaults
|
|
|
|
fs .MIN = 128 * MEBIBYTE + 4 * KIBIBYTE ;
|
|
|
|
|
2011-12-08 05:45:12 -07:00
|
|
|
return fs ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nilfs2::set_used_sectors( Partition & partition )
|
|
|
|
{
|
|
|
|
if ( ! Utils::execute_command( "nilfs-tune -l " + partition .get_path(), output, error, true ) )
|
|
|
|
{
|
Query unallocated space for unmounted file systems (#499202)
Update file system specific implementations to set the size and free
space, thus allowing the unallocated space in the partition to be
calculated, for the following unmounted file systems:
btrfs, ext2, ext3, ext4, fat16, fat32, jfs, nilfs2, ntfs, reiserfs,
reiser4, xfs
Bug #499202 - gparted does not see the difference if partition size
differs from filesystem size
2012-01-10 08:19:01 -07:00
|
|
|
//File system size in bytes
|
|
|
|
Glib::ustring::size_type index = output .find( "Device size:" ) ;
|
|
|
|
if ( index == Glib::ustring::npos
|
|
|
|
|| sscanf( output.substr( index ) .c_str(), "Device size: %Ld", &T ) != 1
|
|
|
|
)
|
|
|
|
T = -1 ;
|
|
|
|
|
|
|
|
//Free space in blocks
|
|
|
|
index = output .find( "Free blocks count:" ) ;
|
2011-12-08 05:45:12 -07:00
|
|
|
if ( index == Glib::ustring::npos
|
|
|
|
|| sscanf( output.substr( index ) .c_str(), "Free blocks count: %Ld", &N ) != 1
|
|
|
|
)
|
|
|
|
N = -1 ;
|
|
|
|
|
|
|
|
index = output .find( "Block size:" ) ;
|
|
|
|
if ( index == Glib::ustring::npos
|
|
|
|
|| sscanf( output.substr( index ) .c_str(), "Block size: %Ld", &S ) != 1
|
|
|
|
)
|
|
|
|
S = -1 ;
|
|
|
|
|
Query unallocated space for unmounted file systems (#499202)
Update file system specific implementations to set the size and free
space, thus allowing the unallocated space in the partition to be
calculated, for the following unmounted file systems:
btrfs, ext2, ext3, ext4, fat16, fat32, jfs, nilfs2, ntfs, reiserfs,
reiser4, xfs
Bug #499202 - gparted does not see the difference if partition size
differs from filesystem size
2012-01-10 08:19:01 -07:00
|
|
|
if ( T > -1 && N > -1 && S > -1 )
|
|
|
|
{
|
|
|
|
T = Utils::round( T / double(partition .sector_size) ) ;
|
|
|
|
N = Utils::round( N * ( S / double(partition .sector_size) ) ) ;
|
|
|
|
partition .set_sector_usage( T, N ) ;
|
|
|
|
}
|
2011-12-08 05:45:12 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( ! output .empty() )
|
|
|
|
partition .messages .push_back( output ) ;
|
|
|
|
|
|
|
|
if ( ! error .empty() )
|
|
|
|
partition .messages .push_back( error ) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nilfs2::read_label( Partition & partition )
|
|
|
|
{
|
|
|
|
if ( ! Utils::execute_command( "nilfs-tune -l " + partition .get_path(), output, error, true ) )
|
|
|
|
{
|
|
|
|
Glib::ustring label = Utils::regexp_label( output, "^Filesystem volume name:[\t ]*(.*)$" ) ;
|
|
|
|
if ( label != "(none)" )
|
2014-12-16 15:04:34 -07:00
|
|
|
partition.set_filesystem_label( label );
|
2012-10-08 07:23:17 -06:00
|
|
|
else
|
2014-12-16 15:04:34 -07:00
|
|
|
partition.set_filesystem_label( "" );
|
2011-12-08 05:45:12 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( ! output .empty() )
|
|
|
|
partition .messages .push_back( output ) ;
|
|
|
|
|
|
|
|
if ( ! error .empty() )
|
|
|
|
partition .messages .push_back( error ) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nilfs2::write_label( const Partition & partition, OperationDetail & operationdetail )
|
|
|
|
{
|
2014-12-16 15:04:34 -07:00
|
|
|
return ! execute_command( "nilfs-tune -L \"" + partition.get_filesystem_label() + "\" " +
|
|
|
|
partition.get_path(),
|
|
|
|
operationdetail );
|
2011-12-08 05:45:12 -07:00
|
|
|
}
|
|
|
|
|
2012-01-22 13:49:52 -07:00
|
|
|
void nilfs2::read_uuid( Partition & partition )
|
|
|
|
{
|
|
|
|
if ( ! Utils::execute_command( "nilfs-tune -l " + partition .get_path(), output, error, true ) )
|
|
|
|
{
|
2012-09-23 08:44:40 -06:00
|
|
|
partition .uuid = Utils::regexp_label( output, "^Filesystem UUID:[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")" ) ;
|
2012-01-22 13:49:52 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( ! output .empty() )
|
|
|
|
partition .messages .push_back( output ) ;
|
|
|
|
|
|
|
|
if ( ! error .empty() )
|
|
|
|
partition .messages .push_back( error ) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nilfs2::write_uuid( const Partition & partition, OperationDetail & operationdetail )
|
|
|
|
{
|
|
|
|
return ! execute_command( "nilfs-tune -U " + Utils::generate_uuid() + " " + partition .get_path(), operationdetail ) ;
|
|
|
|
}
|
|
|
|
|
2011-12-08 05:45:12 -07:00
|
|
|
bool nilfs2::create( const Partition & new_partition, OperationDetail & operationdetail )
|
|
|
|
{
|
2014-12-16 15:04:34 -07:00
|
|
|
return ! execute_command( "mkfs.nilfs2 -L \"" + new_partition.get_filesystem_label() + "\" " +
|
|
|
|
new_partition.get_path(),
|
|
|
|
operationdetail );
|
2011-12-08 05:45:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool nilfs2::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
|
|
|
|
{
|
2011-12-27 11:31:10 -07:00
|
|
|
bool success = true ;
|
|
|
|
|
2013-11-15 09:27:12 -07:00
|
|
|
Glib::ustring mount_point ;
|
|
|
|
if ( ! partition_new .busy )
|
|
|
|
{
|
|
|
|
mount_point = mk_temp_dir( "", operationdetail ) ;
|
|
|
|
if ( mount_point .empty() )
|
|
|
|
return false ;
|
2011-12-27 11:31:10 -07:00
|
|
|
|
2013-11-15 09:27:12 -07:00
|
|
|
success &= ! execute_command( "mount -v -t nilfs2 " + partition_new .get_path() + " " + mount_point,
|
|
|
|
operationdetail, true ) ;
|
|
|
|
}
|
2011-12-27 11:31:10 -07:00
|
|
|
|
|
|
|
if ( success )
|
|
|
|
{
|
|
|
|
Glib::ustring cmd = "nilfs-resize -v -y " + partition_new .get_path() ;
|
|
|
|
if ( ! fill_partition )
|
|
|
|
{
|
|
|
|
Glib::ustring size = Utils::num_to_str( floor( Utils::sector_to_unit(
|
|
|
|
partition_new .get_sector_length(), partition_new .sector_size, UNIT_KIB ) ) ) + "K" ;
|
|
|
|
cmd += " " + size ;
|
|
|
|
}
|
2013-02-21 17:57:33 -07:00
|
|
|
success &= ! execute_command( cmd, operationdetail, true ) ;
|
2011-12-27 11:31:10 -07:00
|
|
|
|
2013-11-15 09:27:12 -07:00
|
|
|
if ( ! partition_new. busy )
|
|
|
|
success &= ! execute_command( "umount -v " + mount_point, operationdetail, true ) ;
|
2011-12-27 11:31:10 -07:00
|
|
|
}
|
|
|
|
|
2013-11-15 09:27:12 -07:00
|
|
|
if ( ! partition_new .busy )
|
|
|
|
rm_temp_dir( mount_point, operationdetail ) ;
|
2011-12-27 11:31:10 -07:00
|
|
|
|
|
|
|
return success ;
|
2011-12-08 05:45:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} //GParted
|