2004-12-14 15:49:44 -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/jfs.h"
|
|
|
|
|
2006-01-19 14:42:38 -07:00
|
|
|
#include <cerrno>
|
|
|
|
|
2004-12-14 15:49:44 -07:00
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
|
|
|
FS jfs::get_filesystem_support( )
|
|
|
|
{
|
|
|
|
FS fs ;
|
|
|
|
|
2005-12-07 04:21:27 -07:00
|
|
|
fs .filesystem = GParted::FS_JFS ;
|
2004-12-15 03:33:12 -07:00
|
|
|
|
2004-12-29 12:22:58 -07:00
|
|
|
if ( ! system( "which jfs_debugfs 1>/dev/null 2>/dev/null" ) )
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .read = GParted::FS::EXTERNAL ;
|
2004-12-14 15:49:44 -07:00
|
|
|
|
|
|
|
if ( ! system( "which mkfs.jfs 1>/dev/null 2>/dev/null" ) )
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .create = GParted::FS::EXTERNAL ;
|
2004-12-14 15:49:44 -07:00
|
|
|
|
|
|
|
if ( ! system( "which jfs_fsck 1>/dev/null 2>/dev/null" ) )
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .check = GParted::FS::EXTERNAL ;
|
2004-12-14 15:49:44 -07:00
|
|
|
|
2005-12-14 07:47:58 -07:00
|
|
|
//resizing of jfs requires jfs support in the kernel
|
|
|
|
std::ifstream input( "/proc/filesystems" ) ;
|
|
|
|
|
|
|
|
if ( input )
|
2004-12-14 15:49:44 -07:00
|
|
|
{
|
|
|
|
Glib::ustring line ;
|
2005-12-14 07:47:58 -07:00
|
|
|
|
2004-12-14 15:49:44 -07:00
|
|
|
while ( input >> line )
|
|
|
|
if ( line == "jfs" )
|
|
|
|
{
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .grow = GParted::FS::EXTERNAL ;
|
2004-12-14 15:49:44 -07:00
|
|
|
break ;
|
|
|
|
}
|
2005-12-14 07:47:58 -07:00
|
|
|
|
2004-12-14 15:49:44 -07:00
|
|
|
input .close( ) ;
|
|
|
|
}
|
|
|
|
|
2005-11-28 10:04:13 -07:00
|
|
|
if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) && fs .grow )
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .copy = GParted::FS::EXTERNAL ;
|
2004-12-14 15:49:44 -07:00
|
|
|
|
|
|
|
fs .MIN = 16 ;
|
|
|
|
|
|
|
|
return fs ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void jfs::Set_Used_Sectors( Partition & partition )
|
|
|
|
{
|
2004-12-29 12:22:58 -07:00
|
|
|
char c_buf[ 512 ] ;
|
|
|
|
FILE *f ;
|
|
|
|
|
|
|
|
Glib::ustring output ;
|
|
|
|
|
|
|
|
//get free sectors..
|
2005-11-29 10:14:38 -07:00
|
|
|
f = popen( ( "echo dm | LC_ALL=C jfs_debugfs " + partition .partition + " | grep dn_nfree" ) .c_str( ), "r" ) ;
|
2004-12-29 12:22:58 -07:00
|
|
|
while ( fgets( c_buf, 512, f ) )
|
|
|
|
{
|
|
|
|
output = Glib::locale_to_utf8( c_buf ) ;
|
|
|
|
|
|
|
|
//free sectors
|
|
|
|
if ( output .find( "dn_nfree" ) < output .length( ) )
|
|
|
|
{
|
|
|
|
output = output .substr( output .find( ":" ) +1, output .length( ) ) ;
|
|
|
|
|
|
|
|
int dec_free_blocks ;
|
|
|
|
std::istringstream hex_free_blocks( output .substr( 0, output .find( "[" ) ) );
|
|
|
|
hex_free_blocks >> std::hex >> dec_free_blocks ;
|
|
|
|
|
|
|
|
partition .Set_Unused( dec_free_blocks * 8 ) ;//4096 / 512 (i've been told jfs blocksize is _always_ 4K)
|
|
|
|
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose( f ) ;
|
2004-12-14 15:49:44 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool jfs::Create( const Partition & new_partition, std::vector<OperationDetails> & operation_details )
|
2004-12-14 15:49:44 -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_JFS ) ) ) ) ;
|
|
|
|
argv .clear() ;
|
|
|
|
argv .push_back( "mkfs.jfs" ) ;
|
|
|
|
argv .push_back( "-q" ) ;
|
|
|
|
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-12-14 15:49:44 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool jfs::Resize( const Partition & partition_new,
|
|
|
|
std::vector<OperationDetails> & operation_details,
|
|
|
|
bool fill_partition )
|
2006-01-19 14:42:38 -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") ) ) ;
|
|
|
|
|
2004-12-14 15:49:44 -07:00
|
|
|
bool return_value = false ;
|
2005-12-14 07:47:58 -07:00
|
|
|
Glib::ustring error ;
|
|
|
|
Glib::ustring TEMP_MP = "/tmp/gparted_tmp_jfs_mountpoint" ;
|
2004-12-14 15:49:44 -07:00
|
|
|
|
2006-01-19 14:42:38 -07:00
|
|
|
//create mountpoint...
|
|
|
|
operation_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails( String::ucompose( _("create temporary mountpoint (%1)"), TEMP_MP ) ) ) ;
|
|
|
|
if ( ! mkdir( TEMP_MP .c_str(), 0 ) )
|
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
|
|
|
|
|
|
|
|
//mount partition
|
|
|
|
operation_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails( String::ucompose( _("mount %1 on %2"), partition_new .partition, TEMP_MP ) ) ) ;
|
|
|
|
if ( Utils::mount( partition_new .partition, TEMP_MP, "jfs", error ) )
|
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
|
|
|
|
|
|
|
|
//remount the partition to resize the filesystem
|
|
|
|
operation_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails( String::ucompose( _("remount %1 on %2 with the 'resize' flag enabled"),
|
|
|
|
partition_new .partition, TEMP_MP ) ) ) ;
|
|
|
|
if ( Utils::mount( partition_new .partition, TEMP_MP, "jfs", error, MS_REMOUNT, "resize" ) )
|
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
|
|
|
|
|
|
|
|
//and unmount it...
|
|
|
|
operation_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails( String::ucompose( _("umount %1"), partition_new .partition ) ) ) ;
|
|
|
|
if ( Utils::unmount( partition_new .partition, TEMP_MP, error ) )
|
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
|
|
|
|
return_value = true ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
|
|
|
|
operation_details .back() .sub_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails( error, OperationDetails::NONE ) ) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
|
|
|
|
operation_details .back() .sub_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails( error, OperationDetails::NONE ) ) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
|
|
|
|
operation_details .back() .sub_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails( error, OperationDetails::NONE ) ) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
//remove the mountpoint..
|
|
|
|
operation_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails( String::ucompose( _("remove temporary mountpoint (%1)"), TEMP_MP ) ) ) ;
|
|
|
|
if ( ! rmdir( TEMP_MP .c_str() ) )
|
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
|
|
|
|
operation_details .back() .sub_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails( Glib::strerror( errno ), OperationDetails::NONE ) ) ;
|
|
|
|
|
|
|
|
return_value = false ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-12-14 15:49:44 -07:00
|
|
|
{
|
2006-01-19 14:42:38 -07:00
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
|
|
|
|
operation_details .back() .sub_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails( Glib::strerror( errno ), OperationDetails::NONE ) ) ;
|
2004-12-14 15:49:44 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .back() .status = return_value ? OperationDetails::SUCCES : OperationDetails::ERROR ;
|
2004-12-14 15:49:44 -07:00
|
|
|
return return_value ;
|
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool jfs::Copy( const Glib::ustring & src_part_path,
|
|
|
|
const Glib::ustring & dest_part_path,
|
2006-01-19 14:42:38 -07:00
|
|
|
std::vector<OperationDetails> & operation_details )
|
2004-12-14 15:49:44 -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( "dd" ) ;
|
|
|
|
argv .push_back( "bs=8192" ) ;
|
|
|
|
argv .push_back( "if=" + src_part_path ) ;
|
|
|
|
argv .push_back( "of=" + dest_part_path ) ;
|
|
|
|
|
|
|
|
if ( ! execute_command( argv, operation_details .back() .sub_details ) )
|
2004-12-14 15:49:44 -07:00
|
|
|
{
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .back() .status = OperationDetails::SUCCES ;
|
|
|
|
|
2004-12-14 15:49:44 -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-14 15:49:44 -07:00
|
|
|
}
|
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-12-14 15:49:44 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool jfs::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details )
|
2004-12-14 15:49:44 -07:00
|
|
|
{
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .push_back( OperationDetails( _("check filesystem for errors and (if possible) fix them") ) ) ;
|
|
|
|
|
|
|
|
argv .clear() ;
|
|
|
|
argv .push_back( "jfs_fsck" ) ;
|
|
|
|
argv .push_back( "-f" ) ;
|
|
|
|
argv .push_back( partition .partition ) ;
|
2004-12-14 15:49:44 -07:00
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
if ( 1 >= execute_command( argv, operation_details .back() .sub_details ) >= 0 )
|
|
|
|
{
|
|
|
|
operation_details .back() .status = OperationDetails::SUCCES ;
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
operation_details .back() .status = OperationDetails::ERROR ;
|
|
|
|
return false ;
|
|
|
|
}
|
2004-12-14 15:49:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} //GParted
|
|
|
|
|
|
|
|
|