2004-11-23 09:20:59 -07:00
|
|
|
/* Copyright (C) 2004 Bart
|
|
|
|
*
|
|
|
|
* 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/ntfs.h"
|
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
|
|
|
FS ntfs::get_filesystem_support( )
|
|
|
|
{
|
|
|
|
FS fs ;
|
2005-12-07 04:21:27 -07:00
|
|
|
fs .filesystem = GParted::FS_NTFS ;
|
2006-01-24 05:31:58 -07:00
|
|
|
|
|
|
|
if ( ! Glib::find_program_in_path( "ntfscluster" ) .empty() )
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .read = GParted::FS::EXTERNAL ;
|
2004-11-23 09:20:59 -07:00
|
|
|
|
2006-01-24 05:31:58 -07:00
|
|
|
if ( ! Glib::find_program_in_path( "mkntfs" ) .empty() )
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .create = GParted::FS::EXTERNAL ;
|
2004-11-23 09:20:59 -07:00
|
|
|
|
2006-01-24 05:31:58 -07:00
|
|
|
if ( ! Glib::find_program_in_path( "ntfsfix" ) .empty() )
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .check = GParted::FS::EXTERNAL ;
|
2004-11-23 09:20:59 -07:00
|
|
|
|
2004-12-15 03:33:12 -07:00
|
|
|
//resizing is a delicate process ...
|
2006-01-24 05:31:58 -07:00
|
|
|
if ( ! Glib::find_program_in_path( "ntfsresize" ) .empty() && fs .check )
|
2004-12-15 03:33:12 -07:00
|
|
|
{
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .grow = GParted::FS::EXTERNAL ;
|
2004-12-15 03:33:12 -07:00
|
|
|
|
2005-11-28 10:04:13 -07:00
|
|
|
if ( fs .read ) //needed to determine a min filesystemsize..
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .shrink = GParted::FS::EXTERNAL ;
|
2004-12-15 03:33:12 -07:00
|
|
|
}
|
2004-11-23 09:20:59 -07:00
|
|
|
|
2004-12-13 06:58:51 -07:00
|
|
|
//we need ntfsresize to set correct used/unused after cloning
|
2006-01-24 05:31:58 -07:00
|
|
|
if ( ! Glib::find_program_in_path( "ntfsclone" ) .empty() && fs .grow )
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .copy = GParted::FS::EXTERNAL ;
|
2004-11-23 09:20:59 -07:00
|
|
|
|
|
|
|
return fs ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ntfs::Set_Used_Sectors( Partition & partition )
|
|
|
|
{
|
2005-12-28 09:43:06 -07:00
|
|
|
argv .push_back( "ntfscluster" ) ;
|
|
|
|
argv .push_back( "--force" ) ;
|
|
|
|
argv .push_back( partition .partition ) ;
|
2004-11-23 09:20:59 -07:00
|
|
|
|
2006-01-22 06:23:58 -07:00
|
|
|
if ( ! execute_command( argv, output ) )
|
2004-11-23 09:20:59 -07:00
|
|
|
{
|
2006-01-22 06:23:58 -07:00
|
|
|
index = output .find( "sectors of free space" ) ;
|
|
|
|
if ( index >= output .length() ||
|
|
|
|
sscanf( output .substr( index ) .c_str(), "sectors of free space : %Ld", &N ) != 1 )
|
|
|
|
N = -1 ;
|
2005-12-28 09:43:06 -07:00
|
|
|
|
2006-01-22 06:23:58 -07:00
|
|
|
if ( N > -1 )
|
|
|
|
partition .Set_Unused( N ) ;
|
|
|
|
}
|
2004-11-23 09:20:59 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool ntfs::Create( const Partition & new_partition, std::vector<OperationDetails> & operation_details )
|
2004-11-23 09:20:59 -07:00
|
|
|
{
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .push_back( OperationDetails( String::ucompose(
|
|
|
|
_("create new %1 filesystem"),
|
|
|
|
Utils::Get_Filesystem_String( GParted::FS_NTFS ) ) ) ) ;
|
|
|
|
argv .clear() ;
|
|
|
|
argv .push_back( "mkntfs" ) ;
|
|
|
|
argv .push_back( "-Q" ) ;
|
|
|
|
argv .push_back( "-vv" ) ;
|
|
|
|
argv .push_back( new_partition .partition ) ;
|
|
|
|
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
|
|
|
|
{
|
|
|
|
operation_details .back() .status = OperationDetails::SUCCES ;
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
operation_details .back() .status = OperationDetails::ERROR ;
|
|
|
|
return false ;
|
|
|
|
}
|
2004-11-23 09:20:59 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool ntfs::Resize( const Partition & partition_new,
|
|
|
|
std::vector<OperationDetails> & operation_details,
|
|
|
|
bool fill_partition )
|
2006-01-20 16:20:31 -07:00
|
|
|
{
|
2006-01-19 12:15:15 -07:00
|
|
|
if ( fill_partition )
|
|
|
|
operation_details .push_back( OperationDetails( _("grow filesystem to fill the partition") ) ) ;
|
|
|
|
else
|
|
|
|
operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
|
|
|
|
|
2006-01-20 16:20:31 -07:00
|
|
|
bool return_value = false ;
|
|
|
|
Glib::ustring str_temp = "echo y | ntfsresize -P --force " + partition_new .partition ;
|
2004-11-23 09:20:59 -07:00
|
|
|
|
|
|
|
if ( ! fill_partition )
|
2006-01-21 17:07:27 -07:00
|
|
|
{
|
|
|
|
str_temp += " -s " ;
|
2006-01-22 14:16:36 -07:00
|
|
|
str_temp += Utils::num_to_str( Utils::Round( Utils::sector_to_unit(
|
|
|
|
partition_new .get_length() - cylinder_size, GParted::UNIT_BYTE ) ), true ) ;
|
2006-01-21 17:07:27 -07:00
|
|
|
}
|
2004-11-23 09:20:59 -07:00
|
|
|
|
2006-01-20 16:20:31 -07:00
|
|
|
//simulation..
|
|
|
|
operation_details .back() .sub_details .push_back( OperationDetails( _("run simulation") ) ) ;
|
|
|
|
|
|
|
|
argv .clear() ;
|
|
|
|
argv .push_back( "sh" ) ;
|
|
|
|
argv .push_back( "-c" ) ;
|
|
|
|
argv .push_back( str_temp + " --no-action" ) ;
|
|
|
|
if ( ! execute_command( argv, operation_details .back() .sub_details .back() .sub_details ) )
|
2006-01-19 12:15:15 -07:00
|
|
|
{
|
2006-01-20 16:20:31 -07:00
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
|
|
|
|
|
|
|
|
//real resize (use description from 'main' operation)
|
|
|
|
operation_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails( operation_details .back() .description ) ) ;
|
|
|
|
|
2006-01-21 17:07:27 -07:00
|
|
|
argv .back() = str_temp ;
|
2006-01-20 16:20:31 -07:00
|
|
|
if ( ! execute_command( argv, operation_details .back() .sub_details .back() .sub_details ) )
|
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
|
|
|
|
return_value = true ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
|
|
|
|
}
|
2006-01-19 12:15:15 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-20 16:20:31 -07:00
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
|
2006-01-19 12:15:15 -07:00
|
|
|
}
|
2006-01-20 16:20:31 -07:00
|
|
|
|
|
|
|
operation_details .back() .status = return_value ? OperationDetails::SUCCES : OperationDetails::ERROR ;
|
|
|
|
return return_value ;
|
2004-11-23 09:20:59 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool ntfs::Copy( const Glib::ustring & src_part_path,
|
|
|
|
const Glib::ustring & dest_part_path,
|
|
|
|
std::vector<OperationDetails> & operation_details )
|
2004-11-23 09:20:59 -07:00
|
|
|
{
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .push_back( OperationDetails(
|
|
|
|
String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ;
|
|
|
|
|
|
|
|
argv .clear() ;
|
|
|
|
argv .push_back( "ntfsclone" ) ;
|
|
|
|
argv .push_back( "-f" ) ;
|
|
|
|
argv .push_back( "--overwrite" ) ;
|
|
|
|
argv .push_back( dest_part_path ) ;
|
|
|
|
argv .push_back( src_part_path ) ;
|
|
|
|
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
|
2004-12-15 12:39:18 -07:00
|
|
|
{
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .back() .status = OperationDetails::SUCCES ;
|
|
|
|
|
2004-12-15 12:39:18 -07:00
|
|
|
Partition partition ;
|
|
|
|
partition .partition = dest_part_path ;
|
2006-01-19 12:15:15 -07:00
|
|
|
return Resize( partition, operation_details, true ) ;
|
2004-12-15 12:39:18 -07:00
|
|
|
}
|
2006-01-19 12:15:15 -07:00
|
|
|
|
|
|
|
operation_details .back() .status = OperationDetails::ERROR ;
|
2004-12-15 12:39:18 -07:00
|
|
|
return false ;
|
2004-11-23 09:20:59 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool ntfs::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details )
|
2004-11-23 09:20:59 -07:00
|
|
|
{
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ;
|
2006-01-20 16:20:31 -07:00
|
|
|
|
|
|
|
argv .clear() ;
|
|
|
|
argv .push_back( "ntfsfix" ) ;
|
|
|
|
argv .push_back( partition .partition ) ;
|
|
|
|
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
|
2006-01-19 12:15:15 -07:00
|
|
|
{
|
|
|
|
operation_details .back() .status = OperationDetails::SUCCES ;
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
operation_details .back() .status = OperationDetails::ERROR ;
|
|
|
|
return false ;
|
|
|
|
}
|
2004-11-23 09:20:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} //GParted
|
|
|
|
|
|
|
|
|