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
|
|
|
|
{
|
|
|
|
|
2006-01-24 05:31:58 -07:00
|
|
|
FS jfs::get_filesystem_support()
|
2004-12-14 15:49:44 -07:00
|
|
|
{
|
|
|
|
FS fs ;
|
2005-12-07 04:21:27 -07:00
|
|
|
fs .filesystem = GParted::FS_JFS ;
|
2004-12-15 03:33:12 -07:00
|
|
|
|
2006-01-24 05:31:58 -07:00
|
|
|
if ( ! Glib::find_program_in_path( "jfs_debugfs" ) .empty() )
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .read = GParted::FS::EXTERNAL ;
|
2004-12-14 15:49:44 -07:00
|
|
|
|
2006-01-24 05:31:58 -07:00
|
|
|
if ( ! Glib::find_program_in_path( "mkfs.jfs" ) .empty() )
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .create = GParted::FS::EXTERNAL ;
|
2004-12-14 15:49:44 -07:00
|
|
|
|
2006-01-24 05:31:58 -07:00
|
|
|
if ( ! Glib::find_program_in_path( "jfs_fsck" ) .empty() )
|
2005-11-26 17:57:11 -07:00
|
|
|
fs .check = GParted::FS::EXTERNAL ;
|
2004-12-14 15:49:44 -07:00
|
|
|
|
2006-02-15 09:05:26 -07:00
|
|
|
//resizing of jfs requires mount, unmount, check/repair functionality and jfs support in the kernel
|
|
|
|
if ( ! Glib::find_program_in_path( "mount" ) .empty() &&
|
|
|
|
! Glib::find_program_in_path( "umount" ) .empty() &&
|
|
|
|
fs .check )
|
2004-12-14 15:49:44 -07:00
|
|
|
{
|
2006-02-15 09:05:26 -07:00
|
|
|
std::ifstream input( "/proc/filesystems" ) ;
|
|
|
|
if ( input )
|
|
|
|
{
|
|
|
|
Glib::ustring line ;
|
|
|
|
|
|
|
|
while ( input >> line )
|
|
|
|
if ( line == "jfs" )
|
|
|
|
{
|
|
|
|
fs .grow = GParted::FS::EXTERNAL ;
|
|
|
|
break ;
|
|
|
|
}
|
2005-12-14 07:47:58 -07:00
|
|
|
|
2006-02-15 09:05:26 -07:00
|
|
|
input .close() ;
|
|
|
|
}
|
2004-12-14 15:49:44 -07:00
|
|
|
}
|
2006-05-23 15:17:34 -06:00
|
|
|
|
|
|
|
if ( fs .grow )
|
|
|
|
fs .copy = GParted::FS::GPARTED ;
|
2004-12-14 15:49:44 -07:00
|
|
|
|
2006-02-25 03:09:30 -07:00
|
|
|
fs .MIN = 16 * MEBIBYTE ;
|
2004-12-14 15:49:44 -07:00
|
|
|
|
|
|
|
return fs ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void jfs::Set_Used_Sectors( Partition & partition )
|
|
|
|
{
|
2006-03-14 14:37:47 -07:00
|
|
|
if ( ! Utils::execute_command( "echo dm | jfs_debugfs " + partition .get_path(), output, error, true ) )
|
2004-12-29 12:22:58 -07:00
|
|
|
{
|
2006-01-22 06:23:58 -07:00
|
|
|
//blocksize
|
|
|
|
index = output .find( "Block Size:" ) ;
|
|
|
|
if ( index >= output .length() ||
|
|
|
|
sscanf( output .substr( index ) .c_str(), "Block Size: %Ld", &S ) != 1 )
|
|
|
|
S = -1 ;
|
2004-12-29 12:22:58 -07:00
|
|
|
|
2006-01-22 06:23:58 -07:00
|
|
|
//free blocks
|
|
|
|
index = output .find( "dn_nfree:" ) ;
|
|
|
|
if ( index >= output .length() ||
|
|
|
|
sscanf( output .substr( index ) .c_str(), "dn_nfree: %Lx", &N ) != 1 )
|
|
|
|
N = -1 ;
|
|
|
|
|
|
|
|
if ( S > -1 && N > -1 )
|
2006-03-28 05:40:29 -07:00
|
|
|
partition .Set_Unused( Utils::round( N * ( S / 512.0 ) ) ) ;
|
2004-12-29 12:22:58 -07:00
|
|
|
}
|
2006-02-25 05:25:18 -07:00
|
|
|
else
|
|
|
|
partition .error = error ;
|
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"),
|
2006-03-28 05:40:29 -07:00
|
|
|
Utils::get_filesystem_string( GParted::FS_JFS ) ) ) ) ;
|
2006-02-15 09:05:26 -07:00
|
|
|
|
2006-03-14 14:37:47 -07:00
|
|
|
if ( ! execute_command( "mkfs.jfs -q " + new_partition .get_path(), 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-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 ;
|
2006-01-24 05:31:58 -07:00
|
|
|
Glib::ustring TEMP_MP = Glib::get_tmp_dir() + "/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 ;
|
2006-02-15 09:05:26 -07:00
|
|
|
|
2006-01-19 14:42:38 -07:00
|
|
|
//mount partition
|
|
|
|
operation_details .back() .sub_details .push_back(
|
2006-03-14 14:37:47 -07:00
|
|
|
OperationDetails( String::ucompose( _("mount %1 on %2"), partition_new .get_path(), TEMP_MP ) ) ) ;
|
2006-02-15 09:05:26 -07:00
|
|
|
|
2006-03-14 14:37:47 -07:00
|
|
|
if ( ! execute_command( "mount -v -t jfs " + partition_new .get_path() + " " + TEMP_MP,
|
2006-02-15 09:05:26 -07:00
|
|
|
operation_details .back() .sub_details .back() .sub_details ) )
|
2006-01-19 14:42:38 -07:00
|
|
|
{
|
|
|
|
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"),
|
2006-03-14 14:37:47 -07:00
|
|
|
partition_new .get_path(), TEMP_MP ) ) ) ;
|
2006-02-15 09:05:26 -07:00
|
|
|
|
2006-03-14 14:37:47 -07:00
|
|
|
if ( ! execute_command( "mount -v -t jfs -o remount,resize " + partition_new .get_path() + " " + TEMP_MP,
|
2006-02-15 09:05:26 -07:00
|
|
|
operation_details .back() .sub_details .back() .sub_details ) )
|
2006-01-19 14:42:38 -07:00
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
|
2006-01-19 16:30:17 -07:00
|
|
|
return_value = true ;
|
2006-01-19 14:42:38 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
|
|
|
|
}
|
2006-01-19 16:30:17 -07:00
|
|
|
|
|
|
|
//and unmount it...
|
|
|
|
operation_details .back() .sub_details .push_back(
|
2006-03-14 14:37:47 -07:00
|
|
|
OperationDetails( String::ucompose( _("unmount %1"), partition_new .get_path() ) ) ) ;
|
2006-02-15 09:05:26 -07:00
|
|
|
|
2006-03-14 14:37:47 -07:00
|
|
|
if ( ! execute_command( "umount -v " + partition_new .get_path(),
|
2006-02-15 09:05:26 -07:00
|
|
|
operation_details .back() .sub_details .back() .sub_details ) )
|
2006-01-19 16:30:17 -07:00
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
|
|
|
|
return_value = false ;
|
|
|
|
}
|
2006-01-19 14:42:38 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
|
|
|
|
}
|
2006-01-19 16:30:17 -07:00
|
|
|
|
2006-01-19 14:42:38 -07:00
|
|
|
//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-05-23 15:17:34 -06:00
|
|
|
return true ;
|
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
|
|
|
{
|
changed statusmessage, fixed issue with exit_status and tested/confirmed
* src/ext2.cc,
src/ext3.cc,
src/fat16.cc,
src/fat32.cc,
src/jfs.cc,
src/ntfs.cc,
src/reiser4.cc,
src/reiserfs.cc,
src/xfs.cc: changed statusmessage, fixed issue with exit_status and
tested/confirmed succesfull usage of Partition::get_path() in
Set_Used_Sectors() of all filesystems.
2006-03-16 06:12:01 -07:00
|
|
|
operation_details .push_back( OperationDetails(
|
|
|
|
String::ucompose( _("check filesystem on %1 for errors and (if possible) fix them"),
|
|
|
|
partition .get_path() ) ) ) ;
|
2006-02-25 05:25:18 -07:00
|
|
|
|
2006-03-14 14:37:47 -07:00
|
|
|
exit_status = execute_command( "jfs_fsck -f " + partition .get_path(), operation_details .back() .sub_details ) ;
|
2006-02-25 05:25:18 -07:00
|
|
|
if ( exit_status == 0 || exit_status == 1 )
|
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-12-14 15:49:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} //GParted
|
|
|
|
|
|
|
|
|