Created 2 files to support ext4 operations.

Support for ext4 is planned for version 2.6.28 of the Linux kernel.

svn path=/trunk/; revision=1004
This commit is contained in:
Curtis Gedak 2008-12-18 22:07:06 +00:00
parent 5493f7ecc6
commit c020834508
6 changed files with 202 additions and 4 deletions

View file

@ -12,10 +12,11 @@ not an invitation to misrepresent who contributed to GNU GParted.
We need to keep track of copyright (see the Maintainer HOWTO on www.gnu.org). We need to keep track of copyright (see the Maintainer HOWTO on www.gnu.org).
Curtis Gedak <gedakc@users.sourceforge.net> Curtis Gedak <gedakc@users.sourceforge.net>
* Created ext4.h, ext4.cc to support ext4 file systems
* Created FS_Info.h, FS_Info.cc * Created FS_Info.h, FS_Info.cc
* Rewrote read_label functionality for hfs * Rewrote read_label functionality for hfs
* Wrote create, read_label, and check_repair functionality for hfs+ * Wrote create, read_label, and check_repair functionality for hfs+
* Wrote read_label functionality for fat16 and fat32 filesystems * Wrote read_label functionality for fat16 and fat32 file systems
* Wrote following Utils:: methods: * Wrote following Utils:: methods:
regexp_label(), fat_compliant_label(), regexp_label(), fat_compliant_label(),
create_mtoolsrc_file(), delete_mtoolsrc_file, create_mtoolsrc_file(), delete_mtoolsrc_file,

View file

@ -1,5 +1,11 @@
2008-12-18 Curtis Gedak <gedakc@gmail.com> 2008-12-18 Curtis Gedak <gedakc@gmail.com>
* include/ext4.h,
include/Makefile.am,
src/ext4.cc,
src/Makefile.am: Created 2 files to support ext4 operations.
- Support for ext4 is planned for version 2.6.28 of the Linux kernel.
* include/FS_Info.h, * include/FS_Info.h,
src/FS_Info.cc: Added get_fs_type() method src/FS_Info.cc: Added get_fs_type() method

View file

@ -14,7 +14,7 @@ EXTRA_DIST = \
DialogManageFlags.h \ DialogManageFlags.h \
DrawingAreaVisualDisk.h \ DrawingAreaVisualDisk.h \
FileSystem.h \ FileSystem.h \
Frame_Resizer_Base.h \ Frame_Resizer_Base.h \
Frame_Resizer_Extended.h \ Frame_Resizer_Extended.h \
FS_Info.h \ FS_Info.h \
GParted_Core.h \ GParted_Core.h \
@ -28,19 +28,20 @@ EXTRA_DIST = \
OperationFormat.h \ OperationFormat.h \
OperationResizeMove.h \ OperationResizeMove.h \
OperationLabelPartition.h \ OperationLabelPartition.h \
Partition.h \ Partition.h \
TreeView_Detail.h \ TreeView_Detail.h \
Utils.h \ Utils.h \
Win_GParted.h \ Win_GParted.h \
ext2.h \ ext2.h \
ext3.h \ ext3.h \
ext4.h \
fat16.h \ fat16.h \
fat32.h \ fat32.h \
hfs.h \ hfs.h \
hfsplus.h \ hfsplus.h \
i18n.h \ i18n.h \
jfs.h \ jfs.h \
linux_swap.h \ linux_swap.h \
ntfs.h \ ntfs.h \
reiser4.h \ reiser4.h \
reiserfs.h \ reiserfs.h \

45
include/ext4.h Normal file
View file

@ -0,0 +1,45 @@
/* Copyright (C) 2008 Curtis Gedak
*
* 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.
*/
#ifndef EXT4_H_
#define EXT4_H_
#include "../include/FileSystem.h"
namespace GParted
{
class ext4 : public FileSystem
{
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void read_label( Partition & partition ) ;
bool write_label( const Partition & partition, OperationDetail & operationdetail ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool copy( const Glib::ustring & src_part_path,
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
};
} //GParted
#endif /*EXT4_H_*/

View file

@ -43,6 +43,7 @@ gpartedbin_SOURCES = \
Win_GParted.cc \ Win_GParted.cc \
ext2.cc \ ext2.cc \
ext3.cc \ ext3.cc \
ext4.cc \
fat16.cc \ fat16.cc \
fat32.cc \ fat32.cc \
hfs.cc \ hfs.cc \

144
src/ext4.cc Normal file
View file

@ -0,0 +1,144 @@
/* Copyright (C) 2008 Curtis Gedak
*
* 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/ext4.h"
namespace GParted
{
FS ext4::get_filesystem_support()
{
FS fs ;
fs .filesystem = GParted::FS_EXT4 ;
//To be on the safe side, only enable all the function if mkfs.ext4 is
// found indicating that there is a recent copy of e2fsprogs available.
if ( ! Glib::find_program_in_path( "mkfs.ext4" ) .empty() )
{
fs .create = GParted::FS::EXTERNAL ;
if ( ! Glib::find_program_in_path( "dumpe2fs" ) .empty() )
fs .read = GParted::FS::EXTERNAL ;
if ( ! Glib::find_program_in_path( "e2label" ) .empty() ) {
fs .read_label = FS::EXTERNAL ;
fs .write_label = FS::EXTERNAL ;
}
if ( ! Glib::find_program_in_path( "e2fsck" ) .empty() )
fs .check = GParted::FS::EXTERNAL ;
if ( ! Glib::find_program_in_path( "resize2fs" ) .empty() && fs .check )
{
fs .grow = GParted::FS::EXTERNAL ;
if ( fs .read ) //needed to determine a min file system size..
fs .shrink = GParted::FS::EXTERNAL ;
}
if ( fs .check )
{
fs .copy = GParted::FS::GPARTED ;
fs .move = GParted::FS::GPARTED ;
}
}
return fs ;
}
void ext4::set_used_sectors( Partition & partition )
{
if ( ! Utils::execute_command( "dumpe2fs -h " + partition .get_path(), output, error, true ) )
{
index = output .find( "Free blocks:" ) ;
if ( index >= output .length() ||
sscanf( output.substr( index ) .c_str(), "Free blocks: %Ld", &N ) != 1 )
N = -1 ;
index = output .find( "Block size:" ) ;
if ( index >= output.length() ||
sscanf( output.substr( index ) .c_str(), "Block size: %Ld", &S ) != 1 )
S = -1 ;
if ( N > -1 && S > -1 )
partition .Set_Unused( Utils::round( N * ( S / 512.0 ) ) ) ;
}
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
if ( ! error .empty() )
partition .messages .push_back( error ) ;
}
}
void ext4::read_label( Partition & partition )
{
if ( ! Utils::execute_command( "e2label " + partition .get_path(), output, error, true ) )
{
partition .label = Utils::regexp_label( output, "^(.*)" ) ;
}
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
if ( ! error .empty() )
partition .messages .push_back( error ) ;
}
}
bool ext4::write_label( const Partition & partition, OperationDetail & operationdetail )
{
return ! execute_command( "e2label " + partition .get_path() + " \"" + partition .label + "\"", operationdetail ) ;
}
bool ext4::create( const Partition & new_partition, OperationDetail & operationdetail )
{
return ! execute_command( "mkfs.ext4 -L \"" + new_partition .label + "\" " + new_partition .get_path(), operationdetail ) ;
}
bool ext4::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
{
Glib::ustring str_temp = "resize2fs " + partition_new .get_path() ;
if ( ! fill_partition )
str_temp += " " + Utils::num_to_str( Utils::round( Utils::sector_to_unit(
partition_new .get_length(), GParted::UNIT_KIB ) ) -1, true ) + "K" ;
return ! execute_command( str_temp, operationdetail ) ;
}
bool ext4::copy( const Glib::ustring & src_part_path,
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail )
{
return true ;
}
bool ext4::check_repair( const Partition & partition, OperationDetail & operationdetail )
{
exit_status = execute_command( "e2fsck -f -y -v " + partition .get_path(), operationdetail ) ;
//exitstatus 256 isn't documented, but it's returned when the 'FILE SYSTEM IS MODIFIED'
//this is quite normal (especially after a copy) so we let the function return true...
return ( exit_status == 0 || exit_status == 1 || exit_status == 2 || exit_status == 256 ) ;
}
} //GParted