2009-11-05 11:08:32 -07:00
|
|
|
/* Copyright (C) 2004 Bart
|
2010-04-26 13:40:38 -06:00
|
|
|
* Copyright (C) 2008, 2009, 2010 Curtis Gedak
|
2004-12-13 14:24:12 -07:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* GNU Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "../include/xfs.h"
|
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
2006-02-25 05:25:18 -07:00
|
|
|
FS xfs::get_filesystem_support()
|
2004-12-13 14:24:12 -07:00
|
|
|
{
|
|
|
|
FS fs ;
|
2005-12-07 04:21:27 -07:00
|
|
|
fs .filesystem = GParted::FS_XFS ;
|
2006-01-24 05:31:58 -07:00
|
|
|
|
|
|
|
if ( ! Glib::find_program_in_path( "xfs_db" ) .empty() )
|
2006-10-01 07:08:57 -06:00
|
|
|
{
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .read = GParted::FS::EXTERNAL ;
|
2008-11-08 16:55:17 -07:00
|
|
|
fs .read_label = FS::EXTERNAL ;
|
2006-10-01 07:08:57 -06:00
|
|
|
}
|
2008-04-07 13:41:18 -06:00
|
|
|
|
|
|
|
if ( ! Glib::find_program_in_path( "xfs_admin" ) .empty() )
|
2012-01-22 13:49:52 -07:00
|
|
|
{
|
2008-11-08 16:55:17 -07:00
|
|
|
fs .write_label = FS::EXTERNAL ;
|
2012-01-22 13:49:52 -07:00
|
|
|
fs .read_uuid = FS::EXTERNAL ;
|
|
|
|
fs .write_uuid = FS::EXTERNAL ;
|
|
|
|
}
|
2008-04-07 13:41:18 -06:00
|
|
|
|
2006-01-24 05:31:58 -07:00
|
|
|
if ( ! Glib::find_program_in_path( "mkfs.xfs" ) .empty() )
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .create = GParted::FS::EXTERNAL ;
|
2004-12-13 14:24:12 -07:00
|
|
|
|
2006-01-24 05:31:58 -07:00
|
|
|
if ( ! Glib::find_program_in_path( "xfs_repair" ) .empty() )
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .check = GParted::FS::EXTERNAL ;
|
2004-12-13 14:24:12 -07:00
|
|
|
|
2011-12-28 13:40:51 -07:00
|
|
|
//Mounted operations require mount, umount and xfs support in the kernel
|
|
|
|
if ( ! Glib::find_program_in_path( "mount" ) .empty() &&
|
2006-02-15 09:05:26 -07:00
|
|
|
! Glib::find_program_in_path( "umount" ) .empty() &&
|
2011-12-28 13:40:51 -07:00
|
|
|
fs .check &&
|
|
|
|
Utils::kernel_supports_fs( "xfs" ) )
|
2004-12-13 14:24:12 -07:00
|
|
|
{
|
2011-12-28 13:40:51 -07:00
|
|
|
//Grow
|
|
|
|
if ( ! Glib::find_program_in_path( "xfs_growfs" ) .empty() )
|
|
|
|
fs .grow = FS::EXTERNAL ;
|
|
|
|
|
|
|
|
//Copy using xfsdump, xfsrestore
|
|
|
|
if ( ! Glib::find_program_in_path( "xfsdump" ) .empty() &&
|
|
|
|
! Glib::find_program_in_path( "xfsrestore" ) .empty() &&
|
|
|
|
fs .create )
|
|
|
|
fs .copy = FS::EXTERNAL ;
|
2004-12-13 14:24:12 -07:00
|
|
|
}
|
2011-12-28 13:40:51 -07:00
|
|
|
|
2006-07-19 14:12:46 -06:00
|
|
|
if ( fs .check )
|
|
|
|
fs .move = GParted::FS::GPARTED ;
|
|
|
|
|
2012-09-10 09:41:58 -06:00
|
|
|
fs .online_read = FS::GPARTED ;
|
|
|
|
|
2010-04-26 13:40:38 -06:00
|
|
|
fs .MIN = 32 * MEBIBYTE ;//official minsize = 16MB, but the smallest xfs_repair can handle is 32MB...
|
2004-12-13 14:24:12 -07:00
|
|
|
|
|
|
|
return fs ;
|
|
|
|
}
|
|
|
|
|
2006-08-20 03:33:54 -06:00
|
|
|
void xfs::set_used_sectors( Partition & partition )
|
2004-12-13 14:24:12 -07:00
|
|
|
{
|
2006-02-15 09:05:26 -07:00
|
|
|
if ( ! Utils::execute_command(
|
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
|
|
|
"xfs_db -c 'sb 0' -c 'print blocksize' -c 'print dblocks' -c 'print fdblocks' -r " + partition .get_path(),
|
2006-02-15 09:05:26 -07:00
|
|
|
output,
|
|
|
|
error,
|
|
|
|
true ) )
|
2004-12-13 14:24:12 -07:00
|
|
|
{
|
2006-01-22 06:23:58 -07:00
|
|
|
//blocksize
|
|
|
|
if ( sscanf( output .c_str(), "blocksize = %Ld", &S ) != 1 )
|
|
|
|
S = -1 ;
|
2005-12-28 09:43:06 -07:00
|
|
|
|
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
|
|
|
//filesystem blocks
|
|
|
|
index = output .find( "\ndblocks" ) ;
|
|
|
|
if ( index > output .length() ||
|
|
|
|
sscanf( output .substr( index ) .c_str(), "\ndblocks = %Ld", &T ) != 1 )
|
|
|
|
T = -1 ;
|
|
|
|
|
2006-01-22 06:23:58 -07:00
|
|
|
//free blocks
|
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
|
|
|
index = output .find( "\nfdblocks" ) ;
|
2006-07-19 11:26:42 -06:00
|
|
|
if ( index > output .length() ||
|
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
|
|
|
sscanf( output .substr( index ) .c_str(), "\nfdblocks = %Ld", &N ) != 1 )
|
2006-01-22 06:23:58 -07:00
|
|
|
N = -1 ;
|
2005-12-28 09:43:06 -07:00
|
|
|
|
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 * ( S / double(partition .sector_size) ) ) ;
|
|
|
|
N = Utils::round( N * ( S / double(partition .sector_size) ) ) ;
|
|
|
|
partition .set_sector_usage( T, N ) ;
|
|
|
|
}
|
|
|
|
|
2006-01-22 06:23:58 -07:00
|
|
|
}
|
2006-02-25 05:25:18 -07:00
|
|
|
else
|
2006-09-08 14:51:31 -06:00
|
|
|
{
|
|
|
|
if ( ! output .empty() )
|
|
|
|
partition .messages .push_back( output ) ;
|
|
|
|
|
|
|
|
if ( ! error .empty() )
|
|
|
|
partition .messages .push_back( error ) ;
|
|
|
|
}
|
2004-12-13 14:24:12 -07:00
|
|
|
}
|
|
|
|
|
2008-11-08 16:55:17 -07:00
|
|
|
void xfs::read_label( Partition & partition )
|
2006-09-12 14:34:33 -06:00
|
|
|
{
|
2008-04-07 13:41:18 -06:00
|
|
|
if ( ! Utils::execute_command( "xfs_db -r -c 'label' " + partition .get_path(), output, error, true ) )
|
2006-10-01 07:08:57 -06:00
|
|
|
{
|
2012-10-08 07:23:17 -06:00
|
|
|
partition .set_label( Utils::regexp_label( output, "^label = \"(.*)\"" ) ) ;
|
2006-10-01 07:08:57 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( ! output .empty() )
|
|
|
|
partition .messages .push_back( output ) ;
|
|
|
|
|
|
|
|
if ( ! error .empty() )
|
|
|
|
partition .messages .push_back( error ) ;
|
|
|
|
}
|
2008-04-07 13:41:18 -06:00
|
|
|
}
|
2006-10-01 07:08:57 -06:00
|
|
|
|
2008-11-08 16:55:17 -07:00
|
|
|
bool xfs::write_label( const Partition & partition, OperationDetail & operationdetail )
|
2008-04-07 13:41:18 -06:00
|
|
|
{
|
|
|
|
Glib::ustring cmd = "" ;
|
2012-10-08 07:23:17 -06:00
|
|
|
if( partition .get_label() .empty() )
|
2008-04-07 13:41:18 -06:00
|
|
|
cmd = String::ucompose( "xfs_admin -L -- %1", partition .get_path() ) ;
|
|
|
|
else
|
2012-10-08 07:23:17 -06:00
|
|
|
cmd = String::ucompose( "xfs_admin -L \"%1\" %2", partition .get_label(), partition .get_path() ) ;
|
2008-04-07 13:41:18 -06:00
|
|
|
return ! execute_command( cmd, operationdetail ) ;
|
2006-09-12 14:34:33 -06:00
|
|
|
}
|
|
|
|
|
2012-01-22 13:49:52 -07:00
|
|
|
void xfs::read_uuid( Partition & partition )
|
|
|
|
{
|
|
|
|
if ( ! Utils::execute_command( "xfs_admin -u " + partition .get_path(), output, error, true ) )
|
|
|
|
{
|
2012-09-23 08:44:40 -06:00
|
|
|
partition .uuid = Utils::regexp_label( output, "^UUID[[:blank:]]*=[[: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 xfs::write_uuid( const Partition & partition, OperationDetail & operationdetail )
|
|
|
|
{
|
|
|
|
return ! execute_command( "xfs_admin -U generate " + partition .get_path(), operationdetail ) ;
|
|
|
|
}
|
|
|
|
|
2006-08-20 03:33:54 -06:00
|
|
|
bool xfs::create( const Partition & new_partition, OperationDetail & operationdetail )
|
2004-12-13 14:24:12 -07:00
|
|
|
{
|
2012-12-29 03:10:08 -07:00
|
|
|
return ! execute_command( "mkfs.xfs -f -L \"" + new_partition .get_label() + "\" " + new_partition .get_path(), operationdetail ) ;
|
2004-12-13 14:24:12 -07:00
|
|
|
}
|
|
|
|
|
2006-08-20 03:33:54 -06:00
|
|
|
bool xfs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
|
2006-01-19 16:30:17 -07:00
|
|
|
{
|
2011-12-28 13:40:51 -07:00
|
|
|
bool success = true ;
|
2006-01-19 16:30:17 -07:00
|
|
|
|
2011-12-28 13:40:51 -07:00
|
|
|
Glib::ustring mount_point = mk_temp_dir( "", operationdetail ) ;
|
|
|
|
if ( mount_point .empty() )
|
|
|
|
return false ;
|
2006-02-15 09:05:26 -07:00
|
|
|
|
2013-02-21 17:57:33 -07:00
|
|
|
success &= ! execute_command( "mount -v -t xfs " + partition_new .get_path() + " " + mount_point,
|
|
|
|
operationdetail, true ) ;
|
2006-01-19 16:30:17 -07:00
|
|
|
|
2011-12-28 13:40:51 -07:00
|
|
|
if ( success )
|
2004-12-13 14:24:12 -07:00
|
|
|
{
|
2013-02-21 17:57:33 -07:00
|
|
|
success &= ! execute_command( "xfs_growfs " + mount_point, operationdetail, true ) ;
|
2011-12-28 13:40:51 -07:00
|
|
|
|
2013-02-21 17:57:33 -07:00
|
|
|
success &= ! execute_command( "umount -v " + mount_point, operationdetail, true ) ;
|
2004-12-13 14:24:12 -07:00
|
|
|
}
|
2011-12-28 13:40:51 -07:00
|
|
|
|
|
|
|
rm_temp_dir( mount_point, operationdetail ) ;
|
|
|
|
|
|
|
|
return success ;
|
2004-12-13 14:24:12 -07:00
|
|
|
}
|
|
|
|
|
2010-10-19 13:35:53 -06:00
|
|
|
bool xfs::move( const Partition & partition_new
|
|
|
|
, const Partition & partition_old
|
|
|
|
, OperationDetail & operationdetail
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
2006-08-20 03:33:54 -06:00
|
|
|
bool xfs::copy( const Glib::ustring & src_part_path,
|
2006-01-19 12:15:15 -07:00
|
|
|
const Glib::ustring & dest_part_path,
|
2006-08-20 03:33:54 -06:00
|
|
|
OperationDetail & operationdetail )
|
2006-01-20 12:45:55 -07:00
|
|
|
{
|
2011-12-28 13:40:51 -07:00
|
|
|
bool success = true ;
|
|
|
|
|
2013-02-21 17:57:33 -07:00
|
|
|
success &= ! execute_command( "mkfs.xfs -f " + dest_part_path, operationdetail, true ) ;
|
2011-12-28 13:40:51 -07:00
|
|
|
if ( ! success )
|
|
|
|
return false ;
|
2006-08-20 03:33:54 -06:00
|
|
|
|
2011-12-28 13:40:51 -07:00
|
|
|
Glib::ustring src_mount_point = mk_temp_dir( "src", operationdetail ) ;
|
|
|
|
if ( src_mount_point .empty() )
|
|
|
|
return false ;
|
|
|
|
|
|
|
|
Glib::ustring dest_mount_point = mk_temp_dir( "dest", operationdetail ) ;
|
|
|
|
if ( dest_mount_point .empty() )
|
2006-01-20 12:45:55 -07:00
|
|
|
{
|
2011-12-28 13:40:51 -07:00
|
|
|
rm_temp_dir( src_mount_point, operationdetail ) ;
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
|
2013-02-21 17:57:33 -07:00
|
|
|
success &= ! execute_command( "mount -v -t xfs -o noatime,ro " + src_part_path +
|
|
|
|
" " + src_mount_point, operationdetail, true ) ;
|
2011-12-28 13:40:51 -07:00
|
|
|
|
|
|
|
if ( success )
|
|
|
|
{
|
2013-02-21 17:57:33 -07:00
|
|
|
success &= ! execute_command( "mount -v -t xfs " + dest_part_path +
|
|
|
|
" " + dest_mount_point, operationdetail, true ) ;
|
2011-12-28 13:40:51 -07:00
|
|
|
|
|
|
|
if ( success )
|
2006-01-20 12:45:55 -07:00
|
|
|
{
|
2013-02-21 17:57:33 -07:00
|
|
|
success &= ! execute_command( "sh -c 'xfsdump -J - " + src_mount_point +
|
|
|
|
" | xfsrestore -J - " + dest_mount_point + "'",
|
|
|
|
operationdetail, true );
|
2011-12-28 13:40:51 -07:00
|
|
|
|
2013-02-21 17:57:33 -07:00
|
|
|
success &= ! execute_command( "umount -v " + dest_part_path, operationdetail, true ) ;
|
2006-01-20 12:45:55 -07:00
|
|
|
}
|
2011-12-28 13:40:51 -07:00
|
|
|
|
2013-02-21 17:57:33 -07:00
|
|
|
success &= ! execute_command( "umount -v " + src_part_path, operationdetail, true ) ;
|
2006-01-20 12:45:55 -07:00
|
|
|
}
|
|
|
|
|
2011-12-28 13:40:51 -07:00
|
|
|
rm_temp_dir( dest_mount_point, operationdetail ) ;
|
|
|
|
|
|
|
|
rm_temp_dir( src_mount_point, operationdetail ) ;
|
|
|
|
|
|
|
|
return success ;
|
2004-12-13 14:24:12 -07:00
|
|
|
}
|
|
|
|
|
2006-08-20 03:33:54 -06:00
|
|
|
bool xfs::check_repair( const Partition & partition, OperationDetail & operationdetail )
|
2004-12-13 14:24:12 -07:00
|
|
|
{
|
2006-08-20 03:33:54 -06:00
|
|
|
return ! execute_command( "xfs_repair -v " + partition .get_path(), operationdetail ) ;
|
2004-12-13 14:24:12 -07:00
|
|
|
}
|
|
|
|
|
2012-07-25 14:05:33 -06:00
|
|
|
bool xfs::remove( const Partition & partition, OperationDetail & operationdetail )
|
|
|
|
{
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
2004-12-13 14:24:12 -07:00
|
|
|
} //GParted
|
|
|
|
|
|
|
|
|