diff --git a/include/Makefile.am b/include/Makefile.am index d711674e..661b4b8f 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -42,7 +42,6 @@ EXTRA_DIST = \ ext2.h \ f2fs.h \ fat16.h \ - fat32.h \ hfs.h \ hfsplus.h \ i18n.h \ diff --git a/include/fat16.h b/include/fat16.h index bfc4be44..5dc28af3 100644 --- a/include/fat16.h +++ b/include/fat16.h @@ -27,7 +27,9 @@ namespace GParted class fat16 : public FileSystem { + const enum FILESYSTEM specific_type ; public: + fat16( enum FILESYSTEM type ) : specific_type( type ) {} ; const Glib::ustring get_custom_text( CUSTOM_TEXT ttype, int index = 0 ) ; FS get_filesystem_support() ; void set_used_sectors( Partition & partition ) ; @@ -38,6 +40,7 @@ public: bool create( const Partition & new_partition, OperationDetail & operationdetail ) ; bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ; +private: static const Glib::ustring Change_UUID_Warning [] ; }; diff --git a/include/fat32.h b/include/fat32.h deleted file mode 100644 index 514f7aeb..00000000 --- a/include/fat32.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (C) 2004 Bart - * Copyright (C) 2008, 2009, 2010 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 DEFINE_FAT32 -#define DEFINE_FAT32 - -#include "../include/FileSystem.h" - -namespace GParted -{ - -class fat32 : public FileSystem -{ -public: - const Glib::ustring get_custom_text( CUSTOM_TEXT ttype, int index = 0 ) ; - FS get_filesystem_support(); - void set_used_sectors( Partition & partition ) ; - void read_label( Partition & partition ) ; - bool write_label( const Partition & partition, OperationDetail & operationdetail ) ; - void read_uuid( Partition & partition ) ; - bool write_uuid( const Partition & partition, OperationDetail & operationdetail ) ; - bool create( const Partition & new_partition, OperationDetail & operationdetail ) ; - bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ; - - const static Glib::ustring ( & Change_UUID_Warning ) [] ; -}; - -} //GParted - -#endif //FAT32 diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 327a9bde..0d1aed3f 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -35,7 +35,6 @@ #include "../include/ext2.h" #include "../include/f2fs.h" #include "../include/fat16.h" -#include "../include/fat32.h" #include "../include/linux_swap.h" #include "../include/lvm2_pv.h" #include "../include/reiserfs.h" @@ -105,8 +104,8 @@ void GParted_Core::find_supported_filesystems() FILESYSTEM_MAP[ FS_EXT3 ] = new ext2( FS_EXT3 ) ; FILESYSTEM_MAP[ FS_EXT4 ] = new ext2( FS_EXT4 ) ; FILESYSTEM_MAP[ FS_F2FS ] = new f2fs() ; - FILESYSTEM_MAP[ FS_FAT16 ] = new fat16() ; - FILESYSTEM_MAP[ FS_FAT32 ] = new fat32() ; + FILESYSTEM_MAP[ FS_FAT16 ] = new fat16( FS_FAT16 ) ; + FILESYSTEM_MAP[ FS_FAT32 ] = new fat16( FS_FAT32 ) ; FILESYSTEM_MAP[ FS_HFS ] = new hfs() ; FILESYSTEM_MAP[ FS_HFSPLUS ] = new hfsplus() ; FILESYSTEM_MAP[ FS_JFS ] = new jfs() ; diff --git a/src/Makefile.am b/src/Makefile.am index 313f8956..138ccb79 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -53,7 +53,6 @@ gpartedbin_SOURCES = \ ext2.cc \ f2fs.cc \ fat16.cc \ - fat32.cc \ hfs.cc \ hfsplus.cc \ jfs.cc \ diff --git a/src/fat16.cc b/src/fat16.cc index 18f7d832..a194a15a 100644 --- a/src/fat16.cc +++ b/src/fat16.cc @@ -61,12 +61,12 @@ const Glib::ustring fat16::get_custom_text( CUSTOM_TEXT ttype, int index ) FS fat16::get_filesystem_support() { FS fs ; - fs .filesystem = GParted::FS_FAT16 ; + fs .filesystem = specific_type ; // hack to disable silly mtools warnings setenv( "MTOOLS_SKIP_CHECK", "1", 0 ); - //find out if we can create fat16 file systems + //find out if we can create fat file systems if ( ! Glib::find_program_in_path( "mkdosfs" ) .empty() ) fs .create = GParted::FS::EXTERNAL ; @@ -99,9 +99,16 @@ FS fat16::get_filesystem_support() fs .copy = GParted::FS::GPARTED ; fs .online_read = FS::GPARTED ; - fs .MIN = 16 * MEBIBYTE ; - fs .MAX = (4096 - 1) * MEBIBYTE ; //Maximum seems to be just less than 4096 MiB - + if ( fs .filesystem == FS_FAT16 ) + { + fs .MIN = 16 * MEBIBYTE ; + fs .MAX = (4096 - 1) * MEBIBYTE ; //Maximum seems to be just less than 4096 MiB + } + else //FS_FAT32 + { + fs .MIN = 33 * MEBIBYTE ; //Smaller file systems will cause windows scandisk to fail. + } + return fs ; } @@ -227,7 +234,8 @@ bool fat16::write_uuid( const Partition & partition, OperationDetail & operation bool fat16::create( const Partition & new_partition, OperationDetail & operationdetail ) { - return ! execute_command( "mkdosfs -F16 -v -I -n \"" + new_partition .get_label() + + Glib::ustring fat_size = specific_type == FS_FAT16 ? "16" : "32" ; + return ! execute_command( "mkdosfs -F" + fat_size + " -v -I -n \"" + new_partition .get_label() + "\" " + new_partition .get_path(), operationdetail, false, diff --git a/src/fat32.cc b/src/fat32.cc deleted file mode 100644 index 4576bf9a..00000000 --- a/src/fat32.cc +++ /dev/null @@ -1,234 +0,0 @@ -/* Copyright (C) 2004 Bart - * Copyright (C) 2008, 2009, 2010, 2011, 2012 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/fat16.h" -#include "../include/fat32.h" - -/***** -//For some reason unknown, this works without these include statements. -#include // 'C' library for mkstemp() -#include // 'C' library for write(), close() -#include // 'C' library for remove() -*****/ - -namespace GParted -{ - -const Glib::ustring ( & fat32::Change_UUID_Warning ) [] = fat16::Change_UUID_Warning ; - -const Glib::ustring fat32::get_custom_text( CUSTOM_TEXT ttype, int index ) -{ - int i ; - switch ( ttype ) { - case CTEXT_CHANGE_UUID_WARNING : - for ( i = 0 ; i < index && Change_UUID_Warning[ i ] != "" ; i++ ) { - // Just iterate... - } - return Change_UUID_Warning [ i ] ; - default : - return FileSystem::get_custom_text( ttype, index ) ; - } -} - -FS fat32::get_filesystem_support() -{ - FS fs ; - fs .filesystem = GParted::FS_FAT32 ; - - // hack to disable silly mtools warnings - setenv( "MTOOLS_SKIP_CHECK", "1", 0 ); - - //find out if we can create fat32 file systems - if ( ! Glib::find_program_in_path( "mkdosfs" ) .empty() ) - fs .create = GParted::FS::EXTERNAL ; - - if ( ! Glib::find_program_in_path( "dosfsck" ) .empty() ) - { - fs .check = GParted::FS::EXTERNAL ; - fs .read = GParted::FS::EXTERNAL ; - } - - if ( ! Glib::find_program_in_path( "mdir" ) .empty() ) - fs .read_uuid = FS::EXTERNAL ; - - if ( ! Glib::find_program_in_path( "mlabel" ) .empty() ) { - fs .read_label = FS::EXTERNAL ; - fs .write_label = FS::EXTERNAL ; - fs .write_uuid = FS::EXTERNAL ; - } - -#ifdef HAVE_LIBPARTED_FS_RESIZE - //resizing of start and endpoint are provided by libparted - fs .grow = GParted::FS::LIBPARTED ; - fs .shrink = GParted::FS::LIBPARTED ; -#endif -#ifdef HAVE_LIBPARTED_3_0_0_PLUS - fs .move = FS::GPARTED ; -#else - fs .move = GParted::FS::LIBPARTED ; -#endif - - fs .copy = GParted::FS::GPARTED ; - fs .online_read = FS::GPARTED ; - - fs .MIN = 33 * MEBIBYTE ; //Smaller file systems will cause windows scandisk to fail. - - return fs ; -} - -void fat32::set_used_sectors( Partition & partition ) -{ - //FIXME: i've encoutered a readonly fat32 file system.. this won't work with the -a ... best check also without the -a - exit_status = Utils::execute_command( "dosfsck -n -v " + partition .get_path(), output, error, true ) ; - if ( exit_status == 0 || exit_status == 1 || exit_status == 256 ) - { - //total file system size in logical sectors - index = output .rfind( "\n", output .find( "sectors total" ) ) +1 ; - if ( index >= output .length() || sscanf( output .substr( index ) .c_str(), "%Ld", &T ) != 1 ) - T = -1 ; - - //bytes per logical sector - index = output .rfind( "\n", output .find( "bytes per logical sector" ) ) +1 ; - if ( index >= output .length() || sscanf( output .substr( index ) .c_str(), "%Ld", &S ) != 1 ) - S = -1 ; - - if ( T > -1 && S > -1 ) - T = Utils::round( T * ( S / double(partition .sector_size) ) ) ; - - //free clusters - index = output .find( ",", output .find( partition .get_path() ) + partition .get_path() .length() ) +1 ; - if ( index < output .length() && sscanf( output .substr( index ) .c_str(), "%Ld/%Ld", &S, &N ) == 2 ) - N -= S ; - else - N = -1 ; - - //bytes per cluster - index = output .rfind( "\n", output .find( "bytes per cluster" ) ) +1 ; - if ( index >= output .length() || sscanf( output .substr( index ) .c_str(), "%Ld", &S ) != 1 ) - S = -1 ; - - if ( N > -1 && S > -1 ) - N = Utils::round( N * ( S / double(partition .sector_size) ) ) ; - - if ( T > -1 && N > -1 ) - partition .set_sector_usage( T, N ) ; - } - else - { - if ( ! output .empty() ) - partition .messages .push_back( output ) ; - - if ( ! error .empty() ) - partition .messages .push_back( error ) ; - } -} - -void fat32::read_label( Partition & partition ) -{ - Glib::ustring cmd = "mlabel -s :: -i " + partition.get_path(); - - if ( ! Utils::execute_command( cmd, output, error, true ) ) - { - partition .set_label( Utils::trim( Utils::regexp_label( output, "Volume label is ([^(]*)" ) ) ) ; - } - else - { - if ( ! output .empty() ) - partition .messages .push_back( output ) ; - - if ( ! error .empty() ) - partition .messages .push_back( error ) ; - } -} - -bool fat32::write_label( const Partition & partition, OperationDetail & operationdetail ) -{ - Glib::ustring cmd = "" ; - if ( partition .get_label() .empty() ) - cmd = "mlabel -c :: -i " + partition.get_path(); - else - cmd = "mlabel ::\"" + partition.get_label() + "\" -i " + partition.get_path(); - - operationdetail .add_child( OperationDetail( cmd, STATUS_NONE, FONT_BOLD_ITALIC ) ) ; - - int exit_status = Utils::execute_command( cmd, output, error ) ; - - if ( ! output .empty() ) - operationdetail .get_last_child() .add_child( OperationDetail( output, STATUS_NONE, FONT_ITALIC ) ) ; - - if ( ! error .empty() ) - operationdetail .get_last_child() .add_child( OperationDetail( error, STATUS_NONE, FONT_ITALIC ) ) ; - - return ( exit_status == 0 ); -} - -void fat32::read_uuid( Partition & partition ) -{ - Glib::ustring cmd = "mdir -f :: -i " + partition.get_path(); - - if ( ! Utils::execute_command( cmd, output, error, true ) ) - { - partition .uuid = Utils::regexp_label( output, "Volume Serial Number is[[:blank:]]([^[:space:]]+)" ) ; - if ( partition .uuid == "0000-0000" ) - partition .uuid .clear() ; - } - else - { - if ( ! output .empty() ) - partition .messages .push_back( output ) ; - - if ( ! error .empty() ) - partition .messages .push_back( error ) ; - } -} - - -bool fat32::write_uuid( const Partition & partition, OperationDetail & operationdetail ) -{ - Glib::ustring cmd = "mlabel -s -n :: -i " + partition.get_path(); - - operationdetail .add_child( OperationDetail( cmd, STATUS_NONE, FONT_BOLD_ITALIC ) ) ; - - int exit_status = Utils::execute_command( cmd, output, error ) ; - - if ( ! output .empty() ) - operationdetail .get_last_child() .add_child( OperationDetail( output, STATUS_NONE, FONT_ITALIC ) ) ; - - if ( ! error .empty() ) - operationdetail .get_last_child() .add_child( OperationDetail( error, STATUS_NONE, FONT_ITALIC ) ) ; - - return ( exit_status == 0 ); -} - -bool fat32::create( const Partition & new_partition, OperationDetail & operationdetail ) -{ - return ! execute_command( "mkdosfs -F32 -v -I -n \"" + new_partition.get_label() + - "\" " + new_partition.get_path(), operationdetail, - false, true ); -} - -bool fat32::check_repair( const Partition & partition, OperationDetail & operationdetail ) -{ - exit_status = execute_command( "dosfsck -a -w -v " + partition.get_path(), operationdetail, - false, true ); - - return ( exit_status == 0 || exit_status == 1 || exit_status == 256 ) ; -} - -} //GParted