From c020834508351c1e6d78320ce394d75f391b2fcb Mon Sep 17 00:00:00 2001 From: Curtis Gedak Date: Thu, 18 Dec 2008 22:07:06 +0000 Subject: [PATCH] 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 --- AUTHORS | 3 +- ChangeLog | 6 ++ include/Makefile.am | 7 ++- include/ext4.h | 45 ++++++++++++++ src/Makefile.am | 1 + src/ext4.cc | 144 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 202 insertions(+), 4 deletions(-) create mode 100644 include/ext4.h create mode 100644 src/ext4.cc diff --git a/AUTHORS b/AUTHORS index 7818e853..7897de97 100644 --- a/AUTHORS +++ b/AUTHORS @@ -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). Curtis Gedak + * Created ext4.h, ext4.cc to support ext4 file systems * Created FS_Info.h, FS_Info.cc * Rewrote read_label 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: regexp_label(), fat_compliant_label(), create_mtoolsrc_file(), delete_mtoolsrc_file, diff --git a/ChangeLog b/ChangeLog index b726fafe..7b99c217 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2008-12-18 Curtis Gedak + * 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, src/FS_Info.cc: Added get_fs_type() method diff --git a/include/Makefile.am b/include/Makefile.am index 67b0fca3..a8bfd23d 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -14,7 +14,7 @@ EXTRA_DIST = \ DialogManageFlags.h \ DrawingAreaVisualDisk.h \ FileSystem.h \ - Frame_Resizer_Base.h \ + Frame_Resizer_Base.h \ Frame_Resizer_Extended.h \ FS_Info.h \ GParted_Core.h \ @@ -28,19 +28,20 @@ EXTRA_DIST = \ OperationFormat.h \ OperationResizeMove.h \ OperationLabelPartition.h \ - Partition.h \ + Partition.h \ TreeView_Detail.h \ Utils.h \ Win_GParted.h \ ext2.h \ ext3.h \ + ext4.h \ fat16.h \ fat32.h \ hfs.h \ hfsplus.h \ i18n.h \ jfs.h \ - linux_swap.h \ + linux_swap.h \ ntfs.h \ reiser4.h \ reiserfs.h \ diff --git a/include/ext4.h b/include/ext4.h new file mode 100644 index 00000000..f82bf0ec --- /dev/null +++ b/include/ext4.h @@ -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_*/ diff --git a/src/Makefile.am b/src/Makefile.am index 93c682b8..07194e37 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -43,6 +43,7 @@ gpartedbin_SOURCES = \ Win_GParted.cc \ ext2.cc \ ext3.cc \ + ext4.cc \ fat16.cc \ fat32.cc \ hfs.cc \ diff --git a/src/ext4.cc b/src/ext4.cc new file mode 100644 index 00000000..2869db74 --- /dev/null +++ b/src/ext4.cc @@ -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