lots of stuff and cleanups, including fixing getting used/unused space of

* lots of stuff and cleanups, including fixing getting used/unused space of hfs/hfs+/fat16/fat32
* also fixes bug #161362
This commit is contained in:
Bart Hakvoort 2005-09-13 14:56:00 +00:00
parent ece676d4bd
commit 61cd0ce778
19 changed files with 249 additions and 95 deletions

View File

@ -1,3 +1,7 @@
2005-09-13 Bart Hakvoort <hakvoort@cvs.gnome.org>
* lots of stuff and cleanups, including fixing getting used/unused space of hfs/hfs+/fat16/fat32
* also fixes bug #161362
2005-08-31 Bart Hakvoort <hakvoort@cvs.gnome.org>
* src/Dialog_Filesystems.cc: at startup closebutton is focused (#308381)

View File

@ -179,7 +179,7 @@ namespace UStringPrivate
: arg_no(1)
{
#if __GNUC__ >= 3
//plors: i've uncommented this one since it caused a crasher at line 124 for some locales (e.g. nl_BE)
//see #157871
//os.imbue(std::locale("")); // use the user's locale for the stream
#endif
std::string::size_type b = 0, i = 0;

View File

@ -29,6 +29,7 @@
#include "../include/xfs.h"
#include "../include/jfs.h"
#include "../include/hfs.h"
#include "../include/hfsplus.h"
#include "../include/reiser4.h"
#include <glibmm/ustring.h>

View File

@ -71,11 +71,6 @@ inline long Sector_To_MB( Sector sectors )
return Round( sectors * 0.000488281250 ) ; // that's what 512/1024/1024 gives you :)
}
inline Sector Abs( Sector sectors )
{
return sectors < 0 ? sectors - 2*sectors : sectors ;
}
inline Gtk::Label * mk_label( const Glib::ustring & text, bool use_markup = true, bool align_left = true, bool wrap = false, const Glib::ustring & text_color = "black" )
{
Gtk::Label * label = manage( new Gtk::Label( text ) ) ;
@ -96,9 +91,10 @@ inline Gtk::Label * mk_label( const Glib::ustring & text, bool use_markup = true
return label ;
}
inline Glib::ustring num_to_str( Sector number )
inline Glib::ustring num_to_str( Sector number, bool use_C_locale = false )
{
std::stringstream ss;
std::stringstream ss ;
//ss.imbue( std::locale( use_C_locale ? "C" : "" ) ) ; see #157871
ss << number ;
return ss .str( ) ;
}
@ -128,6 +124,7 @@ inline Glib::ustring Get_Color( const Glib::ustring & filesystem )
else if ( filesystem == "jfs" ) return "#E0C39E" ;
else if ( filesystem == "hfs" ) return "#E0B6AF" ;
else if ( filesystem == "hfs+" ) return "#C0A39E" ;
else if ( filesystem == "ufs" ) return "#D1940C" ;

41
include/hfsplus.h Normal file
View File

@ -0,0 +1,41 @@
/* 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.
*/
#ifndef HFSPLUS
#define HFSPLUS
#include "../include/FileSystem.h"
namespace GParted
{
class hfsplus : public FileSystem
{
public:
FS get_filesystem_support( ) ;
void Set_Used_Sectors( Partition & partition ) ;
bool Create( const Partition & new_partition ) ;
bool Resize( const Partition & partition_new, bool fill_partition = false ) ;
bool Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) ;
bool Check_Repair( const Partition & partition ) ;
int get_estimated_time( long MB_to_Consider ) ;
};
} //GParted
#endif //HFSPLUS

View File

@ -43,6 +43,9 @@ void GParted_Core::find_supported_filesystems( )
hfs fs_hfs;
FILESYSTEMS .push_back( fs_hfs .get_filesystem_support( ) ) ;
hfsplus fs_hfsplus;
FILESYSTEMS .push_back( fs_hfsplus .get_filesystem_support( ) ) ;
jfs fs_jfs;
FILESYSTEMS .push_back( fs_jfs .get_filesystem_support( ) ) ;
@ -311,7 +314,7 @@ int GParted_Core::get_estimated_time( const Operation & operation )
case GParted::RESIZE_MOVE:
set_proper_filesystem( operation .partition_new .filesystem ) ;
if ( p_filesystem )
return p_filesystem ->get_estimated_time( Abs( operation .partition_original .Get_Length_MB( ) - operation .partition_new .Get_Length_MB( ) ) ) ;
return p_filesystem ->get_estimated_time( std::abs( operation .partition_original .Get_Length_MB( ) - operation .partition_new .Get_Length_MB( ) ) ) ;
break ;
@ -736,6 +739,8 @@ void GParted_Core::set_proper_filesystem( const Glib::ustring & filesystem )
p_filesystem = new fat32( ) ;
else if ( filesystem == "hfs" )
p_filesystem = new hfs( ) ;
else if ( filesystem == "hfs+" )
p_filesystem = new hfsplus( ) ;
else if ( filesystem == "jfs" )
p_filesystem = new jfs( ) ;
else if ( filesystem == "linux-swap" )

View File

@ -37,6 +37,7 @@ gparted_SOURCES = \
fat16.cc\
fat32.cc\
hfs.cc\
hfsplus.cc\
jfs.cc\
linux_swap.cc\
main.cc\

View File

@ -60,7 +60,7 @@ Glib::ustring Operation::Get_String( )
/*TO TRANSLATORS: looks like Create Logical Partition #1 (ntfs, 2345 MB) on /dev/hda */
return String::ucompose( _("Create %1 #%2 (%3, %4 MB) on %5"), temp, partition_new.partition_number, partition_new.filesystem , partition_new .Get_Length_MB( ), device .path ) ;
case RESIZE_MOVE: //if startsector has changed >= 1 MB we consider it a move
diff = Abs( partition_new .sector_start - partition_original .sector_start ) ;
diff = std::abs( partition_new .sector_start - partition_original .sector_start ) ;
if ( diff >= MEGABYTE )
{
if ( partition_new .sector_start > partition_original .sector_start )
@ -70,7 +70,7 @@ Glib::ustring Operation::Get_String( )
}
//check if size has changed ( we only consider changes >= 1 MB )
diff = Abs( (partition_original .sector_end - partition_original .sector_start) - (partition_new .sector_end - partition_new .sector_start) ) ;
diff = std::abs( (partition_original .sector_end - partition_original .sector_start) - (partition_new .sector_end - partition_new .sector_start) ) ;
if ( diff >= MEGABYTE )
{

View File

@ -85,17 +85,17 @@ bool ext2::Create( const Partition & new_partition )
bool ext2::Resize( const Partition & partition_new, bool fill_partition )
{
Glib::ustring str_temp = "LC_NUMERIC=C resize2fs " + partition_new .partition ;
Glib::ustring str_temp = "resize2fs " + partition_new .partition ;
if ( ! fill_partition )
str_temp += " " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size ) + "M" ;
str_temp += " " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size, true ) + "M" ;
return ! Execute_Command( str_temp ) ;
}
bool ext2::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path )
{
if ( ! Execute_Command( "LC_NUMERIC=C dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) )
if ( ! Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) )
{
Partition partition ;
partition .partition = dest_part_path ;

View File

@ -85,17 +85,17 @@ bool ext3::Create( const Partition & new_partition )
bool ext3::Resize( const Partition & partition_new, bool fill_partition )
{
Glib::ustring str_temp = "LC_NUMERIC=C resize2fs " + partition_new .partition ;
Glib::ustring str_temp = "resize2fs " + partition_new .partition ;
if ( ! fill_partition )
str_temp += " " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size ) + "M" ;
str_temp += " " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size, true ) + "M" ;
return ! Execute_Command( str_temp ) ;
}
bool ext3::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path )
{
if ( ! Execute_Command( "LC_NUMERIC=C dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) )
if ( ! Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) )
{
Partition partition ;
partition .partition = dest_part_path ;

View File

@ -26,14 +26,16 @@ FS fat16::get_filesystem_support( )
FS fs ;
fs .filesystem = "fat16" ;
fs .read = true ; //provided by libparted
//find out if we can create fat16 filesystems
if ( ! system( "which mkdosfs 1>/dev/null 2>/dev/null" ) )
fs .create = true ;
if ( ! system( "which dosfsck 1>/dev/null 2>/dev/null" ) )
{
fs .check = true ;
fs .read = true ;
}
//resizing of start and endpoint are provided by libparted
fs .grow = true ;
@ -43,7 +45,7 @@ FS fat16::get_filesystem_support( )
if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) )
fs .copy = true ;
fs .MIN = 32 ;
fs .MIN = 16 ;
fs .MAX = 4096 ;
return fs ;
@ -51,31 +53,33 @@ FS fat16::get_filesystem_support( )
void fat16::Set_Used_Sectors( Partition & partition )
{
PedFileSystem *fs = NULL;
PedConstraint *constraint = NULL;
PedPartition *c_part = NULL ;
char c_buf[ 512 ] ;
FILE *f ;
if ( disk )
{
c_part = ped_disk_get_partition_by_sector( disk, (partition .sector_end + partition .sector_start) / 2 ) ;
if ( c_part )
{
fs = ped_file_system_open( & c_part ->geom );
Glib::ustring output ;
Sector free_clusters = -1, bytes_per_cluster = -1 ;
if ( fs )
//get free blocks..
f = popen( ( "LC_ALL=C echo 2 | dosfsck -v " + partition .partition ) .c_str( ), "r" ) ;
while ( fgets( c_buf, 512, f ) )
{
constraint = ped_file_system_get_resize_constraint ( fs ) ;
if ( constraint )
output = Glib::locale_to_utf8( c_buf ) ;
//bytes per cluster
if ( output .find( "bytes per cluster" ) < output .length( ) )
bytes_per_cluster = atol( output .substr( 0, output .find( "b" ) ) .c_str( ) ) ;
//free clusters
if ( output .find( partition .partition ) < output .length( ) )
{
partition .Set_Unused( (partition .sector_end - partition .sector_start) - constraint ->min_size ) ;
ped_constraint_destroy ( constraint );
}
ped_file_system_close( fs ) ;
}
output = output .substr( output .find( "," ) +2, output .length( ) ) ;
free_clusters = atol( output .substr( output .find( "/" ) +1, output .find( " " ) ) .c_str( ) ) - atol( output .substr( 0, output .find( "/" ) ) .c_str( ) ) ;
}
}
pclose( f ) ;
if ( free_clusters > -1 && bytes_per_cluster > -1 )
partition .Set_Unused( free_clusters * bytes_per_cluster / 512 ) ;
}
bool fat16::Create( const Partition & new_partition )
@ -91,7 +95,7 @@ bool fat16::Resize( const Partition & partition_new, bool fill_partition )
bool fat16::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path )
{
return ! Execute_Command( "LC_NUMERIC=C dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ;
return ! Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ;
}
bool fat16::Check_Repair( const Partition & partition )

View File

@ -26,14 +26,16 @@ FS fat32::get_filesystem_support( )
FS fs ;
fs .filesystem = "fat32" ;
fs .read = true ; //provided by libparted
//find out if we can create fat32 filesystems
if ( ! system( "which mkdosfs 1>/dev/null 2>/dev/null" ) )
fs .create = true ;
if ( ! system( "which dosfsck 1>/dev/null 2>/dev/null" ) )
{
fs .check = true ;
fs .read = true ;
}
//resizing of start and endpoint are provided by libparted
fs .grow = true ;
@ -43,38 +45,40 @@ FS fat32::get_filesystem_support( )
if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) )
fs .copy = true ;
fs .MIN = 256 ;
fs .MIN = 32 ; //smaller fs'es will cause windows scandisk to fail..
return fs ;
}
void fat32::Set_Used_Sectors( Partition & partition )
{
PedFileSystem *fs = NULL;
PedConstraint *constraint = NULL;
PedPartition *c_part = NULL ;
char c_buf[ 512 ] ;
FILE *f ;
if ( disk )
{
c_part = ped_disk_get_partition_by_sector( disk, (partition .sector_end + partition .sector_start) / 2 ) ;
if ( c_part )
{
fs = ped_file_system_open( & c_part ->geom );
Glib::ustring output ;
Sector free_clusters = -1, bytes_per_cluster = -1 ;
if ( fs )
//get free blocks..
f = popen( ( "LC_ALL=C echo 2 | dosfsck -v " + partition .partition ) .c_str( ), "r" ) ;
while ( fgets( c_buf, 512, f ) )
{
constraint = ped_file_system_get_resize_constraint ( fs ) ;
if ( constraint )
output = Glib::locale_to_utf8( c_buf ) ;
//bytes per cluster
if ( output .find( "bytes per cluster" ) < output .length( ) )
bytes_per_cluster = atol( output .substr( 0, output .find( "b" ) ) .c_str( ) ) ;
//free clusters
if ( output .find( partition .partition ) < output .length( ) )
{
partition .Set_Unused( (partition .sector_end - partition .sector_start) - constraint ->min_size ) ;
ped_constraint_destroy ( constraint );
}
ped_file_system_close( fs ) ;
}
output = output .substr( output .find( "," ) +2, output .length( ) ) ;
free_clusters = atol( output .substr( output .find( "/" ) +1, output .find( " " ) ) .c_str( ) ) - atol( output .substr( 0, output .find( "/" ) ) .c_str( ) ) ;
}
}
pclose( f ) ;
if ( free_clusters > -1 && bytes_per_cluster > -1 )
partition .Set_Unused( free_clusters * bytes_per_cluster / 512 ) ;
}
bool fat32::Create( const Partition & new_partition )
@ -90,7 +94,7 @@ bool fat32::Resize( const Partition & partition_new, bool fill_partition )
bool fat32::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path )
{
return ! Execute_Command( "LC_NUMERIC=C dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ;
return ! Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ;
}
bool fat32::Check_Repair( const Partition & partition )

View File

@ -26,8 +26,8 @@ FS hfs::get_filesystem_support( )
FS fs ;
fs .filesystem = "hfs" ;
if ( ! system( "which hfs 1>/dev/null 2>/dev/null" ) )
fs .read = true ;
fs .read = true ; //provided by libparted
if ( ! system( "which hformat 1>/dev/null 2>/dev/null" ) )
fs .create = true ;
@ -42,26 +42,31 @@ FS hfs::get_filesystem_support( )
void hfs::Set_Used_Sectors( Partition & partition )
{
char c_buf[ 512 ] ;
FILE *f ;
PedFileSystem *fs = NULL;
PedConstraint *constraint = NULL;
PedPartition *c_part = NULL ;
Glib::ustring output ;
//get free bytes..
f = popen( ( "echo 'quit' | LC_ALL=C hfs " + partition .partition ) .c_str( ), "r" ) ;
while ( fgets( c_buf, 512, f ) )
if ( disk )
{
output = Glib::locale_to_utf8( c_buf ) ;
if ( output .find( "bytes free" ) < output .length( ) )
c_part = ped_disk_get_partition_by_sector( disk, (partition .sector_end + partition .sector_start) / 2 ) ;
if ( c_part )
{
output = output .substr( 0, output .find( " bytes free" ) ) ;
fs = ped_file_system_open( & c_part ->geom );
partition .Set_Unused( atol( (output .substr( output .find_last_of( ' ' ) ) ) .c_str( ) ) / 512 ) ;
break ;
if ( fs )
{
constraint = ped_file_system_get_resize_constraint ( fs ) ;
if ( constraint )
{
partition .Set_Unused( (partition .sector_end - partition .sector_start) - constraint ->min_size ) ;
ped_constraint_destroy ( constraint );
}
ped_file_system_close( fs ) ;
}
}
}
pclose( f ) ;
}
bool hfs::Create( const Partition & new_partition )
@ -76,7 +81,7 @@ bool hfs::Resize( const Partition & partition_new, bool fill_partition )
bool hfs::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path )
{
return ! Execute_Command( "LC_NUMERIC=C dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ;
return ! Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ;
}
bool hfs::Check_Repair( const Partition & partition )

92
src/hfsplus.cc Normal file
View File

@ -0,0 +1,92 @@
/* 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/hfsplus.h"
namespace GParted
{
FS hfsplus::get_filesystem_support( )
{
FS fs ;
fs .filesystem = "hfs+" ;
fs .read = true ; //provided by libparted
return fs ;
}
void hfsplus::Set_Used_Sectors( Partition & partition )
{
PedFileSystem *fs = NULL;
PedConstraint *constraint = NULL;
PedPartition *c_part = NULL ;
if ( disk )
{
c_part = ped_disk_get_partition_by_sector( disk, (partition .sector_end + partition .sector_start) / 2 ) ;
if ( c_part )
{
fs = ped_file_system_open( & c_part ->geom );
if ( fs )
{
constraint = ped_file_system_get_resize_constraint ( fs ) ;
if ( constraint )
{
partition .Set_Unused( (partition .sector_end - partition .sector_start) - constraint ->min_size ) ;
ped_constraint_destroy ( constraint );
}
ped_file_system_close( fs ) ;
}
}
}
}
bool hfsplus::Create( const Partition & new_partition )
{
return true ;
}
bool hfsplus::Resize( const Partition & partition_new, bool fill_partition )
{
return true ;
}
bool hfsplus::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path )
{
return true ;
}
bool hfsplus::Check_Repair( const Partition & partition )
{
return true ;
}
int hfsplus::get_estimated_time( long MB_to_Consider )
{
return -1 ;
}
} //GParted

View File

@ -112,7 +112,7 @@ bool jfs::Resize( const Partition & partition_new, bool fill_partition )
bool jfs::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path )
{
if ( ! Execute_Command( "LC_NUMERIC=C dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) )
if ( ! Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) )
{
Partition partition ;
partition .partition = dest_part_path ;

View File

@ -81,10 +81,10 @@ bool ntfs::Create( const Partition & new_partition )
bool ntfs::Resize( const Partition & partition_new, bool fill_partition )
{
Glib::ustring str_temp = "echo y | LC_NUMERIC=C ntfsresize -f " + partition_new .partition ;
Glib::ustring str_temp = "echo y | ntfsresize -f " + partition_new .partition ;
if ( ! fill_partition )
str_temp += " -s " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size ) + "M" ;
str_temp += " -s " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size, true ) + "M" ;
return ! Execute_Command( str_temp ) ;
}

View File

@ -84,7 +84,7 @@ void reiser4::Set_Used_Sectors( Partition & partition )
bool reiser4::Create( const Partition & new_partition )
{
return ! Execute_Command( "mkfs.reiser4 -y " + new_partition .partition ) ;
return ! Execute_Command( "mkfs.reiser4 --yes " + new_partition .partition ) ;
}
bool reiser4::Resize( const Partition & partition_new, bool fill_partition )
@ -114,7 +114,7 @@ bool reiser4::Copy( const Glib::ustring & src_part_path, const Glib::ustring & d
bool reiser4::Check_Repair( const Partition & partition )
{
return ! Execute_Command( "fsck.reiser4 -y --fix " + partition .partition ) ;
return ! Execute_Command( "fsck.reiser4 --yes --fix " + partition .partition ) ;
}
int reiser4::get_estimated_time( long MB_to_Consider )

View File

@ -89,17 +89,17 @@ bool reiserfs::Create( const Partition & new_partition )
bool reiserfs::Resize( const Partition & partition_new, bool fill_partition )
{
Glib::ustring str_temp = "echo y | LC_NUMERIC=C resize_reiserfs " + partition_new .partition ;
Glib::ustring str_temp = "echo y | resize_reiserfs " + partition_new .partition ;
if ( ! fill_partition )
str_temp += " -s " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size ) + "M" ;
str_temp += " -s " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size, true ) + "M" ;
return ! Execute_Command( str_temp ) ;
}
bool reiserfs::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path )
{
if ( ! Execute_Command( "LC_NUMERIC=C dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) )
if ( ! Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) )
{
Partition partition ;
partition .partition = dest_part_path ;