2006-03-24 12:08:41 -07:00
|
|
|
/* Copyright (C) 2004 Bart 'plors' Hakvoort
|
|
|
|
*
|
|
|
|
* 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/Win_GParted.h"
|
2004-11-17 06:00:25 -07:00
|
|
|
#include "../include/GParted_Core.h"
|
2006-03-24 12:08:41 -07:00
|
|
|
#include "../include/OperationCopy.h"
|
|
|
|
#include "../include/OperationCreate.h"
|
|
|
|
#include "../include/OperationDelete.h"
|
|
|
|
#include "../include/OperationFormat.h"
|
|
|
|
#include "../include/OperationResizeMove.h"
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2006-04-02 08:35:21 -06:00
|
|
|
#include "../include/ext2.h"
|
|
|
|
#include "../include/ext3.h"
|
|
|
|
#include "../include/fat16.h"
|
|
|
|
#include "../include/fat32.h"
|
|
|
|
#include "../include/linux_swap.h"
|
|
|
|
#include "../include/reiserfs.h"
|
|
|
|
#include "../include/ntfs.h"
|
|
|
|
#include "../include/xfs.h"
|
|
|
|
#include "../include/jfs.h"
|
|
|
|
#include "../include/hfs.h"
|
|
|
|
#include "../include/hfsplus.h"
|
|
|
|
#include "../include/reiser4.h"
|
|
|
|
#include "../include/ufs.h"
|
|
|
|
|
2006-03-02 14:55:04 -07:00
|
|
|
#include <cerrno>
|
2005-12-10 17:05:28 -07:00
|
|
|
#include <sys/statvfs.h>
|
|
|
|
|
2006-02-25 09:30:43 -07:00
|
|
|
Glib::ustring ped_error ; //see e.g. ped_exception_handler()
|
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
namespace GParted
|
|
|
|
{
|
2006-03-14 14:37:47 -07:00
|
|
|
|
2006-02-25 09:30:43 -07:00
|
|
|
GParted_Core::GParted_Core()
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2005-11-26 17:57:11 -07:00
|
|
|
lp_device = NULL ;
|
|
|
|
lp_disk = NULL ;
|
|
|
|
lp_partition = NULL ;
|
2004-11-17 06:00:25 -07:00
|
|
|
p_filesystem = NULL ;
|
|
|
|
|
2006-02-25 09:30:43 -07:00
|
|
|
ped_exception_set_handler( ped_exception_handler ) ;
|
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
//get valid flags ...
|
2006-02-25 09:30:43 -07:00
|
|
|
for ( PedPartitionFlag flag = ped_partition_flag_next( static_cast<PedPartitionFlag>( NULL ) ) ;
|
|
|
|
flag ;
|
|
|
|
flag = ped_partition_flag_next( flag ) )
|
2006-03-31 03:49:27 -07:00
|
|
|
flags .push_back( flag ) ;
|
2005-01-08 16:45:45 -07:00
|
|
|
|
2005-01-23 07:05:21 -07:00
|
|
|
//throw libpartedversion to the stdout to see which version is actually used.
|
|
|
|
std::cout << "======================" << std::endl ;
|
2006-02-25 09:30:43 -07:00
|
|
|
std::cout << "libparted : " << ped_get_version() << std::endl ;
|
2005-01-23 07:05:21 -07:00
|
|
|
std::cout << "======================" << std::endl ;
|
|
|
|
|
|
|
|
//initialize filesystemlist
|
2006-02-25 09:30:43 -07:00
|
|
|
find_supported_filesystems() ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2006-02-25 09:30:43 -07:00
|
|
|
void GParted_Core::find_supported_filesystems()
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2006-02-25 09:30:43 -07:00
|
|
|
FILESYSTEMS .clear() ;
|
2004-11-17 06:00:25 -07:00
|
|
|
|
|
|
|
ext2 fs_ext2;
|
2006-02-25 09:30:43 -07:00
|
|
|
FILESYSTEMS .push_back( fs_ext2 .get_filesystem_support() ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
|
|
|
|
ext3 fs_ext3;
|
2006-02-25 09:30:43 -07:00
|
|
|
FILESYSTEMS .push_back( fs_ext3 .get_filesystem_support() ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
|
|
|
|
fat16 fs_fat16;
|
2006-02-25 09:30:43 -07:00
|
|
|
FILESYSTEMS .push_back( fs_fat16 .get_filesystem_support() ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
|
|
|
|
fat32 fs_fat32;
|
2006-02-25 09:30:43 -07:00
|
|
|
FILESYSTEMS .push_back( fs_fat32 .get_filesystem_support() ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2004-12-14 15:49:44 -07:00
|
|
|
hfs fs_hfs;
|
2006-02-25 09:30:43 -07:00
|
|
|
FILESYSTEMS .push_back( fs_hfs .get_filesystem_support() ) ;
|
2004-12-14 15:49:44 -07:00
|
|
|
|
2005-09-13 08:56:00 -06:00
|
|
|
hfsplus fs_hfsplus;
|
2006-02-25 09:30:43 -07:00
|
|
|
FILESYSTEMS .push_back( fs_hfsplus .get_filesystem_support() ) ;
|
2005-09-13 08:56:00 -06:00
|
|
|
|
2004-12-14 15:49:44 -07:00
|
|
|
jfs fs_jfs;
|
2006-02-25 09:30:43 -07:00
|
|
|
FILESYSTEMS .push_back( fs_jfs .get_filesystem_support() ) ;
|
2004-12-14 15:49:44 -07:00
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
linux_swap fs_linux_swap;
|
2006-02-25 09:30:43 -07:00
|
|
|
FILESYSTEMS .push_back( fs_linux_swap .get_filesystem_support() ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2006-02-17 14:18:07 -07:00
|
|
|
ntfs fs_ntfs;
|
2006-02-25 09:30:43 -07:00
|
|
|
FILESYSTEMS .push_back( fs_ntfs .get_filesystem_support() ) ;
|
2006-02-17 14:18:07 -07:00
|
|
|
|
2004-12-28 17:09:58 -07:00
|
|
|
reiser4 fs_reiser4;
|
2006-02-25 09:30:43 -07:00
|
|
|
FILESYSTEMS .push_back( fs_reiser4 .get_filesystem_support() ) ;
|
2004-12-28 17:09:58 -07:00
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
reiserfs fs_reiserfs;
|
2006-02-25 09:30:43 -07:00
|
|
|
FILESYSTEMS .push_back( fs_reiserfs .get_filesystem_support() ) ;
|
2004-11-21 14:49:38 -07:00
|
|
|
|
2006-04-02 08:35:21 -06:00
|
|
|
ufs fs_ufs;
|
|
|
|
FILESYSTEMS .push_back( fs_ufs .get_filesystem_support() ) ;
|
|
|
|
|
2004-12-13 14:24:12 -07:00
|
|
|
xfs fs_xfs;
|
2006-02-25 09:30:43 -07:00
|
|
|
FILESYSTEMS .push_back( fs_xfs .get_filesystem_support() ) ;
|
2004-12-13 14:24:12 -07:00
|
|
|
|
2004-11-21 14:49:38 -07:00
|
|
|
//unknown filesystem (default when no match is found)
|
2005-12-07 04:21:27 -07:00
|
|
|
FS fs ; fs .filesystem = GParted::FS_UNKNOWN ;
|
2004-11-21 14:49:38 -07:00
|
|
|
FILESYSTEMS .push_back( fs ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
2006-02-02 06:50:37 -07:00
|
|
|
|
|
|
|
void GParted_Core::set_user_devices( const std::vector<Glib::ustring> & user_devices )
|
|
|
|
{
|
|
|
|
this ->device_paths = user_devices ;
|
|
|
|
this ->probe_devices = ! user_devices .size() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GParted_Core::check_device_path( const Glib::ustring & device_path )
|
|
|
|
{
|
2006-03-26 12:45:23 -07:00
|
|
|
return ( device_path .length() > 6 && device_path .is_ascii() ) ;
|
2006-02-02 06:50:37 -07:00
|
|
|
}
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2004-12-17 12:45:04 -07:00
|
|
|
void GParted_Core::get_devices( std::vector<Device> & devices )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2005-12-29 07:21:45 -07:00
|
|
|
devices .clear() ;
|
2004-11-17 06:00:25 -07:00
|
|
|
Device temp_device ;
|
|
|
|
|
2006-01-05 13:01:34 -07:00
|
|
|
init_maps() ;
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2006-02-02 06:50:37 -07:00
|
|
|
//only probe if no devices were specified as arguments..
|
|
|
|
if ( probe_devices )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2006-02-02 06:50:37 -07:00
|
|
|
device_paths .clear() ;
|
|
|
|
|
|
|
|
//try to find all available devices
|
|
|
|
ped_device_probe_all();
|
|
|
|
|
|
|
|
lp_device = ped_device_get_next( NULL );
|
|
|
|
while ( lp_device )
|
|
|
|
{
|
|
|
|
device_paths .push_back( lp_device ->path ) ;
|
|
|
|
|
|
|
|
lp_device = ped_device_get_next( lp_device ) ;
|
|
|
|
}
|
|
|
|
close_device_and_disk() ;
|
2005-12-30 11:11:03 -07:00
|
|
|
|
2006-03-26 02:16:13 -07:00
|
|
|
std::sort( device_paths .begin(), device_paths .end() ) ;
|
|
|
|
}
|
2006-01-05 13:01:34 -07:00
|
|
|
|
2005-12-29 07:21:45 -07:00
|
|
|
for ( unsigned int t = 0 ; t < device_paths .size() ; t++ )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2006-03-26 12:45:23 -07:00
|
|
|
if ( check_device_path( device_paths[ t ] ) &&
|
|
|
|
open_device_and_disk( device_paths[ t ], false ) &&
|
|
|
|
lp_device )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2005-12-29 07:21:45 -07:00
|
|
|
temp_device .Reset() ;
|
2004-11-19 04:55:38 -07:00
|
|
|
|
2004-11-27 16:31:19 -07:00
|
|
|
//device info..
|
2006-03-14 14:37:47 -07:00
|
|
|
temp_device .add_path( device_paths[ t ] ) ;
|
|
|
|
temp_device .add_paths( get_alternate_paths( temp_device .get_path() ) ) ;
|
|
|
|
|
2005-11-26 17:57:11 -07:00
|
|
|
temp_device .model = lp_device ->model ;
|
|
|
|
temp_device .heads = lp_device ->bios_geom .heads ;
|
|
|
|
temp_device .sectors = lp_device ->bios_geom .sectors ;
|
|
|
|
temp_device .cylinders = lp_device ->bios_geom .cylinders ;
|
2004-11-17 06:00:25 -07:00
|
|
|
temp_device .length = temp_device .heads * temp_device .sectors * temp_device .cylinders ;
|
2006-02-25 03:09:30 -07:00
|
|
|
temp_device .cylsize = temp_device .heads * temp_device .sectors ;
|
2004-12-27 05:08:01 -07:00
|
|
|
|
2006-01-20 16:35:06 -07:00
|
|
|
//make sure cylsize is at least 1 MiB
|
2006-02-25 03:09:30 -07:00
|
|
|
if ( temp_device .cylsize < MEBIBYTE )
|
|
|
|
temp_device .cylsize = MEBIBYTE ;
|
2005-08-30 20:30:25 -06:00
|
|
|
|
2004-12-27 05:08:01 -07:00
|
|
|
//normal harddisk
|
2005-11-26 17:57:11 -07:00
|
|
|
if ( lp_disk )
|
2004-11-27 16:31:19 -07:00
|
|
|
{
|
2005-11-26 17:57:11 -07:00
|
|
|
temp_device .disktype = lp_disk ->type ->name ;
|
|
|
|
temp_device .max_prims = ped_disk_get_max_primary_partition_count( lp_disk ) ;
|
2004-11-29 08:27:33 -07:00
|
|
|
|
2004-12-17 12:45:04 -07:00
|
|
|
set_device_partitions( temp_device ) ;
|
2006-03-07 04:55:27 -07:00
|
|
|
set_mountpoints( temp_device .partitions ) ;
|
2006-01-05 13:01:34 -07:00
|
|
|
set_used_sectors( temp_device .partitions ) ;
|
2005-12-10 17:05:28 -07:00
|
|
|
|
|
|
|
if ( temp_device .highest_busy )
|
2005-11-26 17:57:11 -07:00
|
|
|
temp_device .readonly = ! ped_disk_commit_to_os( lp_disk ) ;
|
2004-11-27 16:31:19 -07:00
|
|
|
}
|
|
|
|
//harddisk without disklabel
|
|
|
|
else
|
|
|
|
{
|
2004-11-28 05:09:04 -07:00
|
|
|
temp_device .disktype = _("unrecognized") ;
|
2004-11-27 16:31:19 -07:00
|
|
|
temp_device .max_prims = -1 ;
|
|
|
|
|
|
|
|
Partition partition_temp ;
|
2006-03-14 14:37:47 -07:00
|
|
|
partition_temp .Set_Unallocated( temp_device .get_path(),
|
|
|
|
0,
|
|
|
|
temp_device .length,
|
|
|
|
false );
|
2006-01-05 13:01:34 -07:00
|
|
|
temp_device .partitions .push_back( partition_temp );
|
2004-11-27 16:31:19 -07:00
|
|
|
}
|
2005-08-30 20:30:25 -06:00
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
devices .push_back( temp_device ) ;
|
|
|
|
|
2006-01-05 13:01:34 -07:00
|
|
|
close_device_and_disk() ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
}
|
2006-01-05 13:01:34 -07:00
|
|
|
|
|
|
|
//clear leftover information...
|
2006-02-20 07:41:05 -07:00
|
|
|
//NOTE that we cannot clear mountinfo since it might be needed in get_all_mountpoints()
|
2006-03-14 14:37:47 -07:00
|
|
|
alternate_paths .clear() ;
|
2006-03-07 04:55:27 -07:00
|
|
|
fstab_info .clear() ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2006-03-07 04:55:27 -07:00
|
|
|
void GParted_Core::read_mountpoints_from_file( const Glib::ustring & filename,
|
|
|
|
std::map< Glib::ustring, std::vector<Glib::ustring> > & map )
|
2006-01-05 13:01:34 -07:00
|
|
|
{
|
2006-01-24 16:37:59 -07:00
|
|
|
std::string line ;
|
|
|
|
char node[255], mountpoint[255] ;
|
2006-01-30 12:45:50 -07:00
|
|
|
unsigned int index ;
|
2006-03-05 14:08:49 -07:00
|
|
|
|
|
|
|
std::ifstream file( filename .c_str() ) ;
|
|
|
|
if ( file )
|
2006-01-05 13:01:34 -07:00
|
|
|
{
|
2006-03-05 14:08:49 -07:00
|
|
|
while ( getline( file, line ) )
|
2006-02-20 07:41:05 -07:00
|
|
|
if ( Glib::str_has_prefix( line, "/" ) &&
|
|
|
|
sscanf( line .c_str(), "%255s %255s", node, mountpoint ) == 2 &&
|
|
|
|
static_cast<Glib::ustring>( node ) != "/dev/root" )
|
2006-01-30 12:45:50 -07:00
|
|
|
{
|
|
|
|
line = mountpoint ;
|
2006-03-17 03:07:49 -07:00
|
|
|
|
|
|
|
//see if mountpoint contains spaces and deal with it
|
2006-01-30 12:45:50 -07:00
|
|
|
index = line .find( "\\040" ) ;
|
|
|
|
if ( index < line .length() )
|
|
|
|
line .replace( index, 4, " " ) ;
|
|
|
|
|
2006-03-07 04:55:27 -07:00
|
|
|
map[ node ] .push_back( line ) ;
|
2006-01-30 12:45:50 -07:00
|
|
|
}
|
2006-03-05 14:08:49 -07:00
|
|
|
|
|
|
|
file .close() ;
|
2006-01-24 16:37:59 -07:00
|
|
|
}
|
2006-03-05 14:08:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void GParted_Core::init_maps()
|
|
|
|
{
|
2006-03-14 14:37:47 -07:00
|
|
|
alternate_paths .clear() ;
|
2006-03-05 14:08:49 -07:00
|
|
|
mount_info .clear() ;
|
2006-03-07 04:55:27 -07:00
|
|
|
fstab_info .clear() ;
|
2006-03-05 14:08:49 -07:00
|
|
|
|
2006-03-07 04:55:27 -07:00
|
|
|
read_mountpoints_from_file( "/proc/mounts", mount_info ) ;
|
|
|
|
read_mountpoints_from_file( "/etc/mtab", mount_info ) ;
|
|
|
|
read_mountpoints_from_file( "/etc/fstab", fstab_info ) ;
|
2006-01-24 16:37:59 -07:00
|
|
|
|
2006-03-07 04:55:27 -07:00
|
|
|
//sort the mountpoints and remove duplicates.. (no need to do this for fstab_info)
|
2006-03-05 14:08:49 -07:00
|
|
|
for ( iter_mp = mount_info .begin() ; iter_mp != mount_info .end() ; ++iter_mp )
|
2006-01-24 16:37:59 -07:00
|
|
|
{
|
2006-03-05 14:08:49 -07:00
|
|
|
std::sort( iter_mp ->second .begin(), iter_mp ->second .end() ) ;
|
|
|
|
|
|
|
|
iter_mp ->second .erase(
|
|
|
|
std::unique( iter_mp ->second .begin(), iter_mp ->second .end() ),
|
|
|
|
iter_mp ->second .end() ) ;
|
2006-01-05 13:01:34 -07:00
|
|
|
}
|
|
|
|
|
2006-03-14 14:37:47 -07:00
|
|
|
//initialize alternate_paths...
|
2006-03-05 14:08:49 -07:00
|
|
|
std::string line ;
|
2006-01-05 13:01:34 -07:00
|
|
|
std::ifstream proc_partitions( "/proc/partitions" ) ;
|
|
|
|
if ( proc_partitions )
|
|
|
|
{
|
|
|
|
char c_str[255] ;
|
|
|
|
|
|
|
|
while ( getline( proc_partitions, line ) )
|
|
|
|
if ( sscanf( line .c_str(), "%*d %*d %*d %255s", c_str ) == 1 )
|
|
|
|
{
|
|
|
|
line = "/dev/" ;
|
|
|
|
line += c_str ;
|
2006-03-14 14:37:47 -07:00
|
|
|
|
|
|
|
if ( realpath( line .c_str(), c_str ) && line != c_str )
|
|
|
|
{
|
|
|
|
//because we can make no assumption about which path libparted will detect
|
|
|
|
//we add all combinations.
|
|
|
|
alternate_paths[ c_str ] = line ;
|
|
|
|
alternate_paths[ line ] = c_str ;
|
|
|
|
}
|
2006-01-05 13:01:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
proc_partitions .close() ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GParted::FILESYSTEM GParted_Core::get_filesystem()
|
2004-12-29 09:38:45 -07:00
|
|
|
{
|
|
|
|
//standard libparted filesystems..
|
2005-12-07 04:21:27 -07:00
|
|
|
if ( lp_partition && lp_partition ->fs_type )
|
|
|
|
{
|
|
|
|
if ( static_cast<Glib::ustring>( lp_partition ->fs_type ->name ) == "extended" )
|
|
|
|
return GParted::FS_EXTENDED ;
|
|
|
|
else if ( static_cast<Glib::ustring>( lp_partition ->fs_type ->name ) == "ext2" )
|
|
|
|
return GParted::FS_EXT2 ;
|
|
|
|
else if ( static_cast<Glib::ustring>( lp_partition ->fs_type ->name ) == "ext3" )
|
|
|
|
return GParted::FS_EXT3 ;
|
|
|
|
else if ( static_cast<Glib::ustring>( lp_partition ->fs_type ->name ) == "linux-swap" )
|
|
|
|
return GParted::FS_LINUX_SWAP ;
|
|
|
|
else if ( static_cast<Glib::ustring>( lp_partition ->fs_type ->name ) == "fat16" )
|
|
|
|
return GParted::FS_FAT16 ;
|
|
|
|
else if ( static_cast<Glib::ustring>( lp_partition ->fs_type ->name ) == "fat32" )
|
|
|
|
return GParted::FS_FAT32 ;
|
|
|
|
else if ( static_cast<Glib::ustring>( lp_partition ->fs_type ->name ) == "ntfs" )
|
|
|
|
return GParted::FS_NTFS ;
|
|
|
|
else if ( static_cast<Glib::ustring>( lp_partition ->fs_type ->name ) == "reiserfs" )
|
|
|
|
return GParted::FS_REISERFS ;
|
|
|
|
else if ( static_cast<Glib::ustring>( lp_partition ->fs_type ->name ) == "xfs" )
|
|
|
|
return GParted::FS_XFS ;
|
|
|
|
else if ( static_cast<Glib::ustring>( lp_partition ->fs_type ->name ) == "jfs" )
|
|
|
|
return GParted::FS_JFS ;
|
|
|
|
else if ( static_cast<Glib::ustring>( lp_partition ->fs_type ->name ) == "hfs" )
|
|
|
|
return GParted::FS_HFS ;
|
|
|
|
else if ( static_cast<Glib::ustring>( lp_partition ->fs_type ->name ) == "hfs+" )
|
|
|
|
return GParted::FS_HFSPLUS ;
|
|
|
|
else if ( static_cast<Glib::ustring>( lp_partition ->fs_type ->name ) == "ufs" )
|
|
|
|
return GParted::FS_UFS ;
|
|
|
|
}
|
|
|
|
|
2004-12-29 09:38:45 -07:00
|
|
|
|
|
|
|
//other filesystems libparted couldn't detect (i've send patches for these filesystems to the parted guys)
|
|
|
|
char buf[512] ;
|
2005-11-26 17:57:11 -07:00
|
|
|
ped_device_open( lp_device );
|
2004-12-29 09:38:45 -07:00
|
|
|
|
|
|
|
//reiser4
|
2005-12-07 04:21:27 -07:00
|
|
|
ped_geometry_read( & lp_partition ->geom, buf, 128, 1 ) ;
|
2005-11-26 17:57:11 -07:00
|
|
|
ped_device_close( lp_device );
|
2005-12-07 04:21:27 -07:00
|
|
|
|
|
|
|
if ( static_cast<Glib::ustring>( buf ) == "ReIsEr4" )
|
|
|
|
return GParted::FS_REISER4 ;
|
2004-12-29 09:38:45 -07:00
|
|
|
|
|
|
|
//no filesystem found....
|
|
|
|
partition_temp .error = _( "Unable to detect filesystem! Possible reasons are:" ) ;
|
|
|
|
partition_temp .error += "\n-";
|
|
|
|
partition_temp .error += _( "The filesystem is damaged" ) ;
|
|
|
|
partition_temp .error += "\n-" ;
|
|
|
|
partition_temp .error += _( "The filesystem is unknown to libparted" ) ;
|
|
|
|
partition_temp .error += "\n-";
|
|
|
|
partition_temp .error += _( "There is no filesystem available (unformatted)" ) ;
|
2005-12-07 04:21:27 -07:00
|
|
|
|
|
|
|
return GParted::FS_UNKNOWN ;
|
2004-12-29 09:38:45 -07:00
|
|
|
}
|
|
|
|
|
2004-12-17 12:45:04 -07:00
|
|
|
void GParted_Core::set_device_partitions( Device & device )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
|
|
|
int EXT_INDEX = -1 ;
|
2006-03-28 11:46:08 -07:00
|
|
|
char * lp_path ;//we have to free the result of ped_partition_get_path()..
|
2004-11-17 06:00:25 -07:00
|
|
|
|
|
|
|
//clear partitions
|
2006-01-05 13:01:34 -07:00
|
|
|
device .partitions .clear() ;
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2005-11-26 17:57:11 -07:00
|
|
|
lp_partition = ped_disk_next_partition( lp_disk, NULL ) ;
|
|
|
|
while ( lp_partition )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2006-01-05 13:01:34 -07:00
|
|
|
partition_temp .Reset() ;
|
|
|
|
|
2005-11-26 17:57:11 -07:00
|
|
|
switch ( lp_partition ->type )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
|
|
|
case PED_PARTITION_NORMAL:
|
2006-03-28 11:46:08 -07:00
|
|
|
case PED_PARTITION_LOGICAL:
|
|
|
|
lp_path = ped_partition_get_path( lp_partition ) ;
|
2006-03-14 14:37:47 -07:00
|
|
|
partition_temp .Set( device .get_path(),
|
2006-03-28 11:46:08 -07:00
|
|
|
lp_path,
|
2006-01-05 13:01:34 -07:00
|
|
|
lp_partition ->num,
|
2006-03-14 14:37:47 -07:00
|
|
|
lp_partition ->type == 0 ?
|
|
|
|
GParted::TYPE_PRIMARY : GParted::TYPE_LOGICAL,
|
2006-01-05 13:01:34 -07:00
|
|
|
get_filesystem(),
|
|
|
|
lp_partition ->geom .start,
|
|
|
|
lp_partition ->geom .end,
|
|
|
|
lp_partition ->type,
|
2006-03-28 11:46:08 -07:00
|
|
|
ped_partition_is_busy( lp_partition ) ) ;
|
|
|
|
free( lp_path ) ;
|
2005-08-30 20:30:25 -06:00
|
|
|
|
2006-03-14 14:37:47 -07:00
|
|
|
partition_temp .add_paths( get_alternate_paths( partition_temp .get_path() ) ) ;
|
2006-02-17 16:20:28 -07:00
|
|
|
set_flags( partition_temp ) ;
|
|
|
|
|
2004-12-27 11:56:57 -07:00
|
|
|
if ( partition_temp .busy && partition_temp .partition_number > device .highest_busy )
|
|
|
|
device .highest_busy = partition_temp .partition_number ;
|
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
break ;
|
2006-03-14 14:37:47 -07:00
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
case PED_PARTITION_EXTENDED:
|
2006-03-28 11:46:08 -07:00
|
|
|
lp_path = ped_partition_get_path( lp_partition ) ;
|
2006-03-14 14:37:47 -07:00
|
|
|
partition_temp .Set( device .get_path(),
|
2006-03-28 11:46:08 -07:00
|
|
|
lp_path,
|
2006-03-14 14:37:47 -07:00
|
|
|
lp_partition ->num,
|
|
|
|
GParted::TYPE_EXTENDED,
|
|
|
|
GParted::FS_EXTENDED,
|
|
|
|
lp_partition ->geom .start,
|
|
|
|
lp_partition ->geom .end,
|
|
|
|
false,
|
2006-03-28 11:46:08 -07:00
|
|
|
ped_partition_is_busy( lp_partition ) ) ;
|
|
|
|
free( lp_path ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2006-03-14 14:37:47 -07:00
|
|
|
partition_temp .add_paths( get_alternate_paths( partition_temp .get_path() ) ) ;
|
2006-02-17 16:20:28 -07:00
|
|
|
set_flags( partition_temp ) ;
|
2006-03-14 14:37:47 -07:00
|
|
|
|
2006-01-05 13:01:34 -07:00
|
|
|
EXT_INDEX = device .partitions .size() ;
|
2004-11-17 06:00:25 -07:00
|
|
|
break ;
|
|
|
|
|
2005-12-07 04:21:27 -07:00
|
|
|
default:
|
|
|
|
break;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2004-12-12 13:36:00 -07:00
|
|
|
//if there's an end, there's a partition ;)
|
|
|
|
if ( partition_temp .sector_end > -1 )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
|
|
|
if ( ! partition_temp .inside_extended )
|
2006-01-05 13:01:34 -07:00
|
|
|
device .partitions .push_back( partition_temp );
|
2004-11-17 06:00:25 -07:00
|
|
|
else
|
2006-01-05 13:01:34 -07:00
|
|
|
device .partitions[ EXT_INDEX ] .logicals .push_back( partition_temp ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//next partition (if any)
|
2005-12-07 04:21:27 -07:00
|
|
|
lp_partition = ped_disk_next_partition( lp_disk, lp_partition ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
2004-12-12 13:36:00 -07:00
|
|
|
|
|
|
|
if ( EXT_INDEX > -1 )
|
2006-03-14 14:37:47 -07:00
|
|
|
insert_unallocated( device .get_path(),
|
2006-01-05 13:01:34 -07:00
|
|
|
device .partitions[ EXT_INDEX ] .logicals,
|
|
|
|
device .partitions[ EXT_INDEX ] .sector_start,
|
|
|
|
device .partitions[ EXT_INDEX ] .sector_end,
|
2005-12-13 18:58:15 -07:00
|
|
|
true ) ;
|
2004-12-12 13:36:00 -07:00
|
|
|
|
2006-03-14 14:37:47 -07:00
|
|
|
insert_unallocated( device .get_path(), device .partitions, 0, device .length -1, false ) ;
|
2004-12-12 13:36:00 -07:00
|
|
|
}
|
|
|
|
|
2006-01-05 13:01:34 -07:00
|
|
|
void GParted_Core::set_mountpoints( std::vector<Partition> & partitions )
|
2005-12-08 10:03:29 -07:00
|
|
|
{
|
|
|
|
for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
|
|
|
|
{
|
2006-03-07 04:55:27 -07:00
|
|
|
if ( ( partitions[ t ] .type == GParted::TYPE_PRIMARY ||
|
|
|
|
partitions[ t ] .type == GParted::TYPE_LOGICAL ) &&
|
|
|
|
partitions[ t ] .filesystem != GParted::FS_LINUX_SWAP )
|
2005-12-08 10:03:29 -07:00
|
|
|
{
|
2006-03-07 04:55:27 -07:00
|
|
|
if ( partitions[ t ] .busy )
|
2005-12-08 10:03:29 -07:00
|
|
|
{
|
2006-03-14 14:37:47 -07:00
|
|
|
for ( unsigned int i = 0 ; i < partitions[ t ] .get_paths() .size() ; i++ )
|
|
|
|
{
|
|
|
|
iter_mp = mount_info .find( partitions[ t ] .get_paths()[ i ] ) ;
|
|
|
|
if ( iter_mp != mount_info .end() )
|
|
|
|
{
|
2006-03-15 09:12:11 -07:00
|
|
|
partitions[ t ] .add_mountpoints( iter_mp ->second ) ;
|
2006-03-14 14:37:47 -07:00
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-15 09:12:11 -07:00
|
|
|
if ( partitions[ t ] .get_mountpoints() .empty() )
|
2006-03-05 08:11:47 -07:00
|
|
|
partitions[ t ] .error = _("Unable to find mountpoint") ;
|
2005-12-08 10:03:29 -07:00
|
|
|
}
|
2006-03-07 04:55:27 -07:00
|
|
|
else
|
|
|
|
{
|
2006-03-14 14:37:47 -07:00
|
|
|
iter_mp = fstab_info .find( partitions[ t ] .get_path() );
|
2006-03-07 04:55:27 -07:00
|
|
|
if ( iter_mp != fstab_info .end() )
|
2006-03-15 09:12:11 -07:00
|
|
|
partitions[ t ] .add_mountpoints( iter_mp ->second ) ;
|
2006-03-07 04:55:27 -07:00
|
|
|
}
|
2005-12-08 10:03:29 -07:00
|
|
|
}
|
2006-03-07 04:55:27 -07:00
|
|
|
else if ( partitions[ t ] .type == GParted::TYPE_EXTENDED )
|
|
|
|
set_mountpoints( partitions[ t ] .logicals ) ;
|
2005-12-08 10:03:29 -07:00
|
|
|
}
|
2006-01-05 13:01:34 -07:00
|
|
|
}
|
2006-03-14 14:37:47 -07:00
|
|
|
|
|
|
|
std::vector<Glib::ustring> GParted_Core::get_alternate_paths( const Glib::ustring & path )
|
2006-01-05 13:01:34 -07:00
|
|
|
{
|
2006-03-14 14:37:47 -07:00
|
|
|
std::vector<Glib::ustring> paths ;
|
|
|
|
|
|
|
|
iter = alternate_paths .find( path ) ;
|
|
|
|
if ( iter != alternate_paths .end() )
|
|
|
|
paths .push_back( iter ->second ) ;
|
2006-01-05 13:01:34 -07:00
|
|
|
|
2006-03-14 14:37:47 -07:00
|
|
|
return paths ;
|
2005-12-08 10:03:29 -07:00
|
|
|
}
|
2005-12-10 17:05:28 -07:00
|
|
|
|
|
|
|
void GParted_Core::set_used_sectors( std::vector<Partition> & partitions )
|
|
|
|
{
|
|
|
|
struct statvfs sfs ;
|
|
|
|
|
|
|
|
temp = _("Unable to read the contents of this filesystem!") ;
|
|
|
|
temp += "\n" ;
|
|
|
|
temp += _("Because of this some operations may be unavailable.") ;
|
|
|
|
temp += "\n\n" ;
|
|
|
|
temp += _("Did you install the correct plugin for this filesystem?") ;
|
|
|
|
|
|
|
|
for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
|
|
|
|
{
|
2006-02-25 05:25:18 -07:00
|
|
|
if ( partitions[ t ] .filesystem != GParted::FS_LINUX_SWAP &&
|
|
|
|
partitions[ t ] .filesystem != GParted::FS_UNKNOWN )
|
2005-12-10 17:05:28 -07:00
|
|
|
{
|
2006-02-25 05:25:18 -07:00
|
|
|
if ( partitions[ t ] .type == GParted::TYPE_PRIMARY ||
|
|
|
|
partitions[ t ] .type == GParted::TYPE_LOGICAL )
|
2005-12-10 17:05:28 -07:00
|
|
|
{
|
|
|
|
if ( partitions[ t ] .busy )
|
|
|
|
{
|
2006-03-15 09:12:11 -07:00
|
|
|
if ( partitions[ t ] .get_mountpoints() .size() > 0 )
|
2006-03-06 06:39:21 -07:00
|
|
|
{
|
2006-03-15 09:12:11 -07:00
|
|
|
if ( statvfs( partitions[ t ] .get_mountpoint() .c_str(), &sfs ) == 0 )
|
2006-03-05 08:11:47 -07:00
|
|
|
partitions[ t ] .Set_Unused( sfs .f_bfree * (sfs .f_bsize / 512) ) ;
|
|
|
|
else
|
|
|
|
partitions[ t ] .error =
|
2006-03-15 09:12:11 -07:00
|
|
|
"statvfs (" + partitions[ t ] .get_mountpoint() + "): " + Glib::strerror( errno );
|
2006-03-05 08:11:47 -07:00
|
|
|
}
|
2005-12-10 17:05:28 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch( get_fs( partitions[ t ] .filesystem ) .read )
|
|
|
|
{
|
|
|
|
case GParted::FS::EXTERNAL :
|
|
|
|
set_proper_filesystem( partitions[ t ] .filesystem ) ;
|
|
|
|
p_filesystem ->Set_Used_Sectors( partitions[ t ] ) ;
|
|
|
|
break ;
|
|
|
|
case GParted::FS::LIBPARTED :
|
|
|
|
LP_Set_Used_Sectors( partitions[ t ] ) ;
|
|
|
|
break ;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-25 05:25:18 -07:00
|
|
|
if ( partitions[ t ] .sectors_used == -1 && partitions[ t ] .error .empty() )
|
2005-12-10 17:05:28 -07:00
|
|
|
partitions[ t ] .error = temp ;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if ( partitions[ t ] .type == GParted::TYPE_EXTENDED )
|
|
|
|
set_used_sectors( partitions[ t ] .logicals ) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-12-08 10:03:29 -07:00
|
|
|
|
2006-02-17 16:20:28 -07:00
|
|
|
void GParted_Core::insert_unallocated( const Glib::ustring & device_path,
|
|
|
|
std::vector<Partition> & partitions,
|
|
|
|
Sector start,
|
|
|
|
Sector end,
|
|
|
|
bool inside_extended )
|
2004-12-12 13:36:00 -07:00
|
|
|
{
|
2006-02-17 16:20:28 -07:00
|
|
|
partition_temp .Reset() ;
|
2005-12-07 15:44:40 -07:00
|
|
|
partition_temp .Set_Unallocated( device_path, 0, 0, inside_extended ) ;
|
2004-12-12 13:36:00 -07:00
|
|
|
|
|
|
|
//if there are no partitions at all..
|
2006-02-17 16:20:28 -07:00
|
|
|
if ( partitions .empty() )
|
2004-12-12 13:36:00 -07:00
|
|
|
{
|
2004-12-13 04:17:40 -07:00
|
|
|
partition_temp .sector_start = start ;
|
|
|
|
partition_temp .sector_end = end ;
|
2004-12-12 13:36:00 -07:00
|
|
|
|
2004-12-13 04:17:40 -07:00
|
|
|
partitions .push_back( partition_temp );
|
2004-12-12 13:36:00 -07:00
|
|
|
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
//start <---> first partition start
|
2006-03-31 11:58:58 -07:00
|
|
|
if ( (partitions .front() .sector_start - start) >= MEBIBYTE )
|
2004-12-12 13:36:00 -07:00
|
|
|
{
|
2004-12-13 04:17:40 -07:00
|
|
|
partition_temp .sector_start = start ;
|
2006-03-31 11:58:58 -07:00
|
|
|
partition_temp .sector_end = partitions .front() .sector_start -1 ;
|
2004-12-12 13:36:00 -07:00
|
|
|
|
2006-03-31 11:58:58 -07:00
|
|
|
partitions .insert( partitions .begin(), partition_temp );
|
2004-12-12 13:36:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//look for gaps in between
|
2006-03-31 11:58:58 -07:00
|
|
|
for ( unsigned int t =0 ; t < partitions .size() -1 ; t++ )
|
2006-01-21 17:07:27 -07:00
|
|
|
if ( ( partitions[ t +1 ] .sector_start - partitions[ t ] .sector_end ) >= MEBIBYTE )
|
2004-12-12 13:36:00 -07:00
|
|
|
{
|
2004-12-13 04:17:40 -07:00
|
|
|
partition_temp .sector_start = partitions[ t ] .sector_end +1 ;
|
|
|
|
partition_temp .sector_end = partitions[ t +1 ] .sector_start -1 ;
|
2004-12-12 13:36:00 -07:00
|
|
|
|
2006-03-31 11:58:58 -07:00
|
|
|
partitions .insert( partitions .begin() + ++t, partition_temp );
|
2004-12-12 13:36:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//last partition end <---> end
|
2006-03-31 11:58:58 -07:00
|
|
|
if ( (end - partitions .back() .sector_end ) >= MEBIBYTE )
|
2004-12-12 13:36:00 -07:00
|
|
|
{
|
2006-03-31 11:58:58 -07:00
|
|
|
partition_temp .sector_start = partitions .back() .sector_end +1 ;
|
2004-12-13 04:17:40 -07:00
|
|
|
partition_temp .sector_end = end ;
|
2004-12-12 13:36:00 -07:00
|
|
|
|
2004-12-13 04:17:40 -07:00
|
|
|
partitions .push_back( partition_temp );
|
2004-12-12 13:36:00 -07:00
|
|
|
}
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2006-03-24 12:08:41 -07:00
|
|
|
bool GParted_Core::apply_operation_to_disk( Operation * operation )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2006-03-24 12:08:41 -07:00
|
|
|
switch ( operation ->type )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
|
|
|
case DELETE:
|
2006-03-24 12:08:41 -07:00
|
|
|
return Delete( operation ->partition_original, operation ->operation_details .sub_details ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
case CREATE:
|
2006-03-24 12:08:41 -07:00
|
|
|
return create( operation ->device,
|
|
|
|
operation ->partition_new,
|
|
|
|
operation ->operation_details .sub_details ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
case RESIZE_MOVE:
|
2006-03-24 12:08:41 -07:00
|
|
|
return resize( operation ->device,
|
|
|
|
operation ->partition_original,
|
|
|
|
operation ->partition_new,
|
|
|
|
operation ->operation_details .sub_details ) ;
|
2006-01-02 08:18:29 -07:00
|
|
|
case FORMAT:
|
2006-03-24 12:08:41 -07:00
|
|
|
return format( operation ->partition_new, operation ->operation_details .sub_details ) ;
|
2006-01-19 12:15:15 -07:00
|
|
|
case COPY:
|
2006-03-29 12:21:42 -07:00
|
|
|
operation ->partition_new .add_path( operation ->partition_original .get_path(), true ) ;
|
2006-03-24 12:08:41 -07:00
|
|
|
return copy( static_cast<OperationCopy*>( operation ) ->partition_copied .get_path(),
|
|
|
|
operation ->partition_new,
|
|
|
|
static_cast<OperationCopy*>( operation ) ->partition_copied .get_length(),
|
|
|
|
operation ->operation_details .sub_details ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
2006-01-19 12:15:15 -07:00
|
|
|
|
|
|
|
return false ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool GParted_Core::create( const Device & device,
|
|
|
|
Partition & new_partition,
|
|
|
|
std::vector<OperationDetails> & operation_details )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
if ( new_partition .type == GParted::TYPE_EXTENDED )
|
|
|
|
{
|
|
|
|
return create_empty_partition( new_partition, operation_details ) ;
|
|
|
|
}
|
fixed issues with copying (see also #335004) cleanups + added FIXME added
* include/GParted_Core.h,
src/GParted_Core.cc,
src/Win_GParted.cc,
src/ext2.cc,
src/ext3.cc,
src/fat16.cc,
src/fat32.cc,
src/jfs.cc,
src/ntfs.cc,
src/reiserfs.cc: fixed issues with copying (see also #335004)
* include/Operation.h,
src/Operation.cc: cleanups + added FIXME
* include/Partition.h,
src/Partition.cc: added clear_mountpoints()
* src/DrawingAreaVisualDisk.cc: added FIXME
2006-03-19 08:30:20 -07:00
|
|
|
else if ( create_empty_partition( new_partition, operation_details, get_fs( new_partition .filesystem ) .MIN ) )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
|
|
|
set_proper_filesystem( new_partition .filesystem ) ;
|
|
|
|
|
2005-11-24 08:59:31 -07:00
|
|
|
//most likely this means the user created an unformatted partition,
|
|
|
|
//however in theory, it could also screw some errorhandling.
|
2004-11-28 07:30:15 -07:00
|
|
|
if ( ! p_filesystem )
|
|
|
|
return true ;
|
2006-01-19 12:15:15 -07:00
|
|
|
|
|
|
|
return set_partition_type( new_partition, operation_details ) &&
|
|
|
|
p_filesystem ->Create( new_partition, operation_details ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool GParted_Core::format( const Partition & partition, std::vector<OperationDetails> & operation_details )
|
2004-11-25 12:21:42 -07:00
|
|
|
{
|
|
|
|
//remove all filesystem signatures...
|
2005-12-07 15:44:40 -07:00
|
|
|
erase_filesystem_signatures( partition ) ;
|
|
|
|
|
2004-11-25 12:21:42 -07:00
|
|
|
set_proper_filesystem( partition .filesystem ) ;
|
2005-11-29 07:50:20 -07:00
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
return set_partition_type( partition, operation_details ) &&
|
|
|
|
p_filesystem ->Create( partition, operation_details ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool GParted_Core::Delete( const Partition & partition, std::vector<OperationDetails> & operation_details )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
|
|
|
bool return_value = false ;
|
|
|
|
|
2005-12-07 15:44:40 -07:00
|
|
|
if ( open_device_and_disk( partition .device_path ) )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2005-12-07 04:21:27 -07:00
|
|
|
if ( partition .type == GParted::TYPE_EXTENDED )
|
2005-11-26 17:57:11 -07:00
|
|
|
lp_partition = ped_disk_extended_partition( lp_disk ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
else
|
2006-02-17 16:20:28 -07:00
|
|
|
lp_partition = ped_disk_get_partition_by_sector(
|
|
|
|
lp_disk,
|
|
|
|
(partition .sector_end + partition .sector_start) / 2 ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2006-02-17 16:20:28 -07:00
|
|
|
return_value = ped_disk_delete_partition( lp_disk, lp_partition ) && commit() ;
|
2006-01-07 14:23:09 -07:00
|
|
|
sleep( 1 ) ; //give the kernel some time to reread the partitiontable
|
2005-12-07 15:44:40 -07:00
|
|
|
|
2006-01-07 14:23:09 -07:00
|
|
|
close_device_and_disk() ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return return_value ;
|
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool GParted_Core::resize( const Device & device,
|
|
|
|
const Partition & partition_old,
|
|
|
|
const Partition & partition_new,
|
|
|
|
std::vector<OperationDetails> & operation_details )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2006-01-22 14:16:36 -07:00
|
|
|
//extended partition
|
2005-12-07 04:21:27 -07:00
|
|
|
if ( partition_old .type == GParted::TYPE_EXTENDED )
|
2006-01-19 12:15:15 -07:00
|
|
|
return resize_container_partition( partition_old, partition_new, false, operation_details ) ;
|
2004-11-21 14:49:38 -07:00
|
|
|
|
2006-02-18 09:03:29 -07:00
|
|
|
bool succes = false ;
|
|
|
|
set_proper_filesystem( partition_new .filesystem ) ;
|
|
|
|
|
2006-01-22 14:16:36 -07:00
|
|
|
//resize using libparted..
|
2005-11-26 17:57:11 -07:00
|
|
|
if ( get_fs( partition_old .filesystem ) .grow == GParted::FS::LIBPARTED )
|
2006-02-18 09:03:29 -07:00
|
|
|
{
|
|
|
|
if ( p_filesystem && p_filesystem ->Check_Repair( partition_new, operation_details ) )
|
|
|
|
{
|
|
|
|
succes = resize_normal_using_libparted( partition_old, partition_new, operation_details ) ;
|
2006-01-22 14:16:36 -07:00
|
|
|
|
2006-02-18 09:03:29 -07:00
|
|
|
//always check after a resize, but if it failes the whole operation failes
|
|
|
|
if ( ! p_filesystem ->Check_Repair( partition_new, operation_details ) )
|
|
|
|
succes = false ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return succes ;
|
|
|
|
}
|
2006-01-22 14:16:36 -07:00
|
|
|
|
2006-02-18 09:03:29 -07:00
|
|
|
//use custom resize tools..
|
2006-01-22 14:16:36 -07:00
|
|
|
if ( p_filesystem && p_filesystem ->Check_Repair( partition_new, operation_details ) )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2006-01-22 14:16:36 -07:00
|
|
|
succes = true ;
|
2004-11-21 14:49:38 -07:00
|
|
|
|
2006-01-22 14:16:36 -07:00
|
|
|
if ( partition_new .get_length() < partition_old .get_length() )
|
|
|
|
{
|
2006-02-25 03:09:30 -07:00
|
|
|
p_filesystem ->cylinder_size = device .cylsize ;
|
2006-01-22 14:16:36 -07:00
|
|
|
succes = p_filesystem ->Resize( partition_new, operation_details ) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( succes )
|
|
|
|
succes = resize_container_partition(
|
|
|
|
partition_old,
|
|
|
|
partition_new,
|
|
|
|
! get_fs( partition_new .filesystem ) .move,
|
|
|
|
operation_details ) ;
|
2004-11-21 14:49:38 -07:00
|
|
|
|
2006-01-22 14:16:36 -07:00
|
|
|
//these 3 are always executed, however, if 1 of them fails the whole operation fails
|
|
|
|
if ( ! p_filesystem ->Check_Repair( partition_new, operation_details ) )
|
|
|
|
succes = false ;
|
|
|
|
|
|
|
|
//expand filesystem to fit exactly in partition
|
|
|
|
if ( ! p_filesystem ->Resize( partition_new, operation_details, true ) )
|
|
|
|
succes = false ;
|
2004-11-21 14:49:38 -07:00
|
|
|
|
2006-01-22 14:16:36 -07:00
|
|
|
if ( ! p_filesystem ->Check_Repair( partition_new, operation_details ) )
|
|
|
|
succes = false ;
|
2006-02-18 09:03:29 -07:00
|
|
|
|
|
|
|
return succes ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
2006-01-22 14:16:36 -07:00
|
|
|
|
2006-02-18 09:03:29 -07:00
|
|
|
return false ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool GParted_Core::copy( const Glib::ustring & src_part_path,
|
|
|
|
Partition & partition_dest,
|
fixed issues with copying (see also #335004) cleanups + added FIXME added
* include/GParted_Core.h,
src/GParted_Core.cc,
src/Win_GParted.cc,
src/ext2.cc,
src/ext3.cc,
src/fat16.cc,
src/fat32.cc,
src/jfs.cc,
src/ntfs.cc,
src/reiserfs.cc: fixed issues with copying (see also #335004)
* include/Operation.h,
src/Operation.cc: cleanups + added FIXME
* include/Partition.h,
src/Partition.cc: added clear_mountpoints()
* src/DrawingAreaVisualDisk.cc: added FIXME
2006-03-19 08:30:20 -07:00
|
|
|
Sector min_size,
|
2006-01-19 12:15:15 -07:00
|
|
|
std::vector<OperationDetails> & operation_details )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
fixed issues with copying (see also #335004) cleanups + added FIXME added
* include/GParted_Core.h,
src/GParted_Core.cc,
src/Win_GParted.cc,
src/ext2.cc,
src/ext3.cc,
src/fat16.cc,
src/fat32.cc,
src/jfs.cc,
src/ntfs.cc,
src/reiserfs.cc: fixed issues with copying (see also #335004)
* include/Operation.h,
src/Operation.cc: cleanups + added FIXME
* include/Partition.h,
src/Partition.cc: added clear_mountpoints()
* src/DrawingAreaVisualDisk.cc: added FIXME
2006-03-19 08:30:20 -07:00
|
|
|
//FIXME: some filesystems (e.g. fat*) can be copied using libparted..
|
2006-03-29 12:21:42 -07:00
|
|
|
|
|
|
|
set_proper_filesystem( partition_dest .filesystem ) ;
|
|
|
|
if ( p_filesystem && p_filesystem ->Check_Repair( Partition( src_part_path ), operation_details ) )
|
|
|
|
{
|
|
|
|
bool succes = true ;
|
|
|
|
if ( partition_dest .status == GParted::STAT_NEW )
|
|
|
|
succes = create_empty_partition( partition_dest, operation_details, min_size ) ;
|
|
|
|
|
|
|
|
return ( succes &&
|
|
|
|
set_partition_type( partition_dest, operation_details ) &&
|
|
|
|
p_filesystem ->Copy( src_part_path, partition_dest .get_path(), operation_details ) &&
|
|
|
|
p_filesystem ->Check_Repair( partition_dest, operation_details ) &&
|
|
|
|
p_filesystem ->Resize( partition_dest, operation_details, true ) &&
|
|
|
|
p_filesystem ->Check_Repair( partition_dest, operation_details ) ) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2004-11-27 16:31:19 -07:00
|
|
|
bool GParted_Core::Set_Disklabel( const Glib::ustring & device_path, const Glib::ustring & disklabel )
|
|
|
|
{
|
|
|
|
bool return_value = false ;
|
|
|
|
|
2005-11-26 17:57:11 -07:00
|
|
|
if ( open_device_and_disk( device_path, false ) )
|
2004-11-27 16:31:19 -07:00
|
|
|
{
|
|
|
|
PedDiskType *type = NULL ;
|
2006-02-17 16:20:28 -07:00
|
|
|
type = ped_disk_type_get( disklabel .c_str() ) ;
|
2004-11-27 16:31:19 -07:00
|
|
|
|
|
|
|
if ( type )
|
|
|
|
{
|
2006-02-17 16:20:28 -07:00
|
|
|
lp_disk = ped_disk_new_fresh( lp_device, type );
|
2004-11-27 16:31:19 -07:00
|
|
|
|
2006-02-17 16:20:28 -07:00
|
|
|
return_value = commit() ;
|
2004-11-27 16:31:19 -07:00
|
|
|
}
|
|
|
|
|
2006-02-17 16:20:28 -07:00
|
|
|
close_device_and_disk() ;
|
2004-11-27 16:31:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return return_value ;
|
|
|
|
}
|
|
|
|
|
2006-02-17 16:20:28 -07:00
|
|
|
const std::vector<FS> & GParted_Core::get_filesystems() const
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
|
|
|
return FILESYSTEMS ;
|
|
|
|
}
|
|
|
|
|
2005-12-07 04:21:27 -07:00
|
|
|
const FS & GParted_Core::get_fs( GParted::FILESYSTEM filesystem ) const
|
2004-12-25 14:40:18 -07:00
|
|
|
{
|
2006-03-31 03:49:27 -07:00
|
|
|
for ( unsigned int t = 0 ; t < FILESYSTEMS .size() ; t++ )
|
2004-12-25 14:40:18 -07:00
|
|
|
if ( FILESYSTEMS[ t ] .filesystem == filesystem )
|
|
|
|
return FILESYSTEMS[ t ] ;
|
|
|
|
|
2006-03-31 03:49:27 -07:00
|
|
|
return FILESYSTEMS .back() ;
|
2004-12-25 14:40:18 -07:00
|
|
|
}
|
|
|
|
|
2006-03-31 03:49:27 -07:00
|
|
|
std::vector<Glib::ustring> GParted_Core::get_disklabeltypes()
|
2005-09-13 11:09:20 -06:00
|
|
|
{
|
|
|
|
std::vector<Glib::ustring> disklabeltypes ;
|
|
|
|
|
|
|
|
//msdos should be first in the list
|
|
|
|
disklabeltypes .push_back( "msdos" ) ;
|
|
|
|
|
|
|
|
PedDiskType *disk_type ;
|
|
|
|
for ( disk_type = ped_disk_type_get_next( NULL ) ; disk_type ; disk_type = ped_disk_type_get_next( disk_type ) )
|
|
|
|
if ( static_cast<Glib::ustring>( disk_type->name ) != "msdos" )
|
|
|
|
disklabeltypes .push_back( disk_type->name ) ;
|
|
|
|
|
|
|
|
return disklabeltypes ;
|
|
|
|
}
|
|
|
|
|
2006-02-20 07:41:05 -07:00
|
|
|
std::vector<Glib::ustring> GParted_Core::get_all_mountpoints()
|
|
|
|
{
|
|
|
|
std::vector<Glib::ustring> mountpoints ;
|
|
|
|
|
|
|
|
for ( iter_mp = mount_info .begin() ; iter_mp != mount_info .end() ; ++iter_mp )
|
|
|
|
mountpoints .insert( mountpoints .end(), iter_mp ->second .begin(), iter_mp ->second .end() ) ;
|
|
|
|
|
|
|
|
return mountpoints ;
|
|
|
|
}
|
2006-03-31 03:49:27 -07:00
|
|
|
|
|
|
|
std::map<Glib::ustring, bool> GParted_Core::get_available_flags( const Partition & partition )
|
|
|
|
{
|
|
|
|
std::map<Glib::ustring, bool> flag_info ;
|
|
|
|
|
|
|
|
if ( open_device_and_disk( partition .device_path ) )
|
|
|
|
{
|
|
|
|
lp_partition = NULL ;
|
|
|
|
if ( partition .type == GParted::TYPE_EXTENDED )
|
|
|
|
lp_partition = ped_disk_extended_partition( lp_disk ) ;
|
|
|
|
else
|
|
|
|
lp_partition = ped_disk_get_partition_by_sector(
|
|
|
|
lp_disk,
|
|
|
|
(partition .sector_end + partition .sector_start) / 2 ) ;
|
|
|
|
|
|
|
|
if ( lp_partition )
|
|
|
|
{
|
|
|
|
for ( unsigned int t = 0 ; t < flags .size() ; t++ )
|
|
|
|
if ( ped_partition_is_flag_available( lp_partition, flags[ t ] ) )
|
|
|
|
flag_info[ ped_partition_flag_get_name( flags[ t ] ) ] =
|
|
|
|
ped_partition_get_flag( lp_partition, flags[ t ] ) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
close_device_and_disk() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return flag_info ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GParted_Core::toggle_flag( const Partition & partition, const Glib::ustring & flag, bool state )
|
|
|
|
{
|
|
|
|
bool succes = false ;
|
|
|
|
|
|
|
|
if ( open_device_and_disk( partition .device_path ) )
|
|
|
|
{
|
|
|
|
lp_partition = NULL ;
|
|
|
|
if ( partition .type == GParted::TYPE_EXTENDED )
|
|
|
|
lp_partition = ped_disk_extended_partition( lp_disk ) ;
|
|
|
|
else
|
|
|
|
lp_partition = ped_disk_get_partition_by_sector(
|
|
|
|
lp_disk,
|
|
|
|
(partition .sector_end + partition .sector_start) / 2 ) ;
|
|
|
|
|
|
|
|
if ( lp_partition )
|
|
|
|
{
|
|
|
|
PedPartitionFlag lp_flag = ped_partition_flag_get_by_name( flag .c_str() ) ;
|
2006-02-20 07:41:05 -07:00
|
|
|
|
2006-03-31 03:49:27 -07:00
|
|
|
if ( lp_flag > 0 && ped_partition_set_flag( lp_partition, lp_flag, state ) )
|
|
|
|
succes = commit() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
close_device_and_disk() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return succes ;
|
|
|
|
}
|
|
|
|
|
2005-11-26 17:57:11 -07:00
|
|
|
void GParted_Core::LP_Set_Used_Sectors( Partition & partition )
|
|
|
|
{
|
|
|
|
PedFileSystem *fs = NULL;
|
|
|
|
PedConstraint *constraint = NULL;
|
2005-12-28 17:10:05 -07:00
|
|
|
|
2005-11-26 17:57:11 -07:00
|
|
|
if ( lp_disk )
|
2004-11-21 14:49:38 -07:00
|
|
|
{
|
2006-02-17 16:20:28 -07:00
|
|
|
lp_partition = ped_disk_get_partition_by_sector(
|
|
|
|
lp_disk,
|
|
|
|
(partition .sector_end + partition .sector_start) / 2 ) ;
|
2005-12-28 17:10:05 -07:00
|
|
|
|
2005-11-26 17:57:11 -07:00
|
|
|
if ( lp_partition )
|
|
|
|
{
|
|
|
|
fs = ped_file_system_open( & lp_partition ->geom );
|
|
|
|
|
|
|
|
if ( fs )
|
|
|
|
{
|
2005-12-07 04:21:27 -07:00
|
|
|
constraint = ped_file_system_get_resize_constraint( fs ) ;
|
2005-11-26 17:57:11 -07:00
|
|
|
if ( constraint )
|
|
|
|
{
|
2006-03-02 14:55:04 -07:00
|
|
|
partition .Set_Unused( partition .get_length() - constraint ->min_size ) ;
|
2005-11-26 17:57:11 -07:00
|
|
|
|
2005-12-07 04:21:27 -07:00
|
|
|
ped_constraint_destroy( constraint );
|
2005-11-26 17:57:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ped_file_system_close( fs ) ;
|
|
|
|
}
|
|
|
|
}
|
2004-11-21 14:49:38 -07:00
|
|
|
}
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2006-03-31 06:10:32 -07:00
|
|
|
bool GParted_Core::create_empty_partition( Partition & new_partition,
|
|
|
|
std::vector<OperationDetails> & operation_details,
|
|
|
|
Sector min_size )
|
|
|
|
{
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .push_back( OperationDetails( _("create empty partition") ) ) ;
|
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
new_partition .partition_number = 0 ;
|
2006-02-25 09:30:43 -07:00
|
|
|
ped_error .clear() ;
|
2004-11-19 04:55:38 -07:00
|
|
|
|
2005-12-07 15:44:40 -07:00
|
|
|
if ( open_device_and_disk( new_partition .device_path ) )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
|
|
|
PedPartitionType type;
|
2006-02-17 14:18:07 -07:00
|
|
|
lp_partition = NULL ;
|
2004-11-17 06:00:25 -07:00
|
|
|
PedConstraint *constraint = NULL ;
|
|
|
|
|
|
|
|
//create new partition
|
|
|
|
switch ( new_partition .type )
|
|
|
|
{
|
2005-12-07 04:21:27 -07:00
|
|
|
case GParted::TYPE_PRIMARY:
|
|
|
|
type = PED_PARTITION_NORMAL ;
|
|
|
|
break ;
|
|
|
|
case GParted::TYPE_LOGICAL:
|
|
|
|
type = PED_PARTITION_LOGICAL ;
|
|
|
|
break ;
|
|
|
|
case GParted::TYPE_EXTENDED:
|
|
|
|
type = PED_PARTITION_EXTENDED ;
|
|
|
|
break ;
|
|
|
|
|
|
|
|
default :
|
|
|
|
type = PED_PARTITION_FREESPACE;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2006-02-17 16:20:28 -07:00
|
|
|
lp_partition = ped_partition_new( lp_disk,
|
|
|
|
type,
|
|
|
|
NULL,
|
|
|
|
new_partition .sector_start,
|
|
|
|
new_partition .sector_end ) ;
|
2006-03-14 14:37:47 -07:00
|
|
|
|
2006-02-17 14:18:07 -07:00
|
|
|
if ( lp_partition )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2006-01-07 08:04:42 -07:00
|
|
|
if ( new_partition .strict )
|
|
|
|
{
|
2006-02-17 16:20:28 -07:00
|
|
|
PedGeometry *geom = ped_geometry_new( lp_device,
|
|
|
|
new_partition .sector_start,
|
|
|
|
new_partition .get_length() ) ;
|
2006-01-07 08:04:42 -07:00
|
|
|
|
|
|
|
if ( geom )
|
|
|
|
constraint = ped_constraint_exact( geom ) ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
constraint = ped_constraint_any( lp_device );
|
2004-11-19 04:55:38 -07:00
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
if ( constraint )
|
|
|
|
{
|
fixed issues with copying (see also #335004) cleanups + added FIXME added
* include/GParted_Core.h,
src/GParted_Core.cc,
src/Win_GParted.cc,
src/ext2.cc,
src/ext3.cc,
src/fat16.cc,
src/fat32.cc,
src/jfs.cc,
src/ntfs.cc,
src/reiserfs.cc: fixed issues with copying (see also #335004)
* include/Operation.h,
src/Operation.cc: cleanups + added FIXME
* include/Partition.h,
src/Partition.cc: added clear_mountpoints()
* src/DrawingAreaVisualDisk.cc: added FIXME
2006-03-19 08:30:20 -07:00
|
|
|
if ( min_size > 0 )
|
|
|
|
constraint ->min_size = min_size ;
|
2006-03-14 14:37:47 -07:00
|
|
|
|
2006-02-17 14:18:07 -07:00
|
|
|
if ( ped_disk_add_partition( lp_disk, lp_partition, constraint ) && commit() )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2006-03-28 11:46:08 -07:00
|
|
|
//we have to free the result of ped_partition_get_path()..
|
|
|
|
char * lp_path = ped_partition_get_path( lp_partition ) ;
|
|
|
|
new_partition .add_path( lp_path, true ) ;
|
|
|
|
free( lp_path ) ;
|
|
|
|
|
2006-02-17 14:18:07 -07:00
|
|
|
new_partition .partition_number = lp_partition ->num ;
|
|
|
|
|
|
|
|
Sector start = lp_partition ->geom .start ;
|
|
|
|
Sector end = lp_partition ->geom .end ;
|
|
|
|
|
|
|
|
operation_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails(
|
|
|
|
"<i>" +
|
2006-03-14 14:37:47 -07:00
|
|
|
String::ucompose( _("path: %1"), new_partition .get_path() ) + "\n" +
|
2006-02-17 14:18:07 -07:00
|
|
|
String::ucompose( _("start: %1"), start ) + "\n" +
|
|
|
|
String::ucompose( _("end: %1"), end ) + "\n" +
|
|
|
|
String::ucompose( _("size: %1"), Utils::format_size( end - start + 1 ) ) +
|
|
|
|
"</i>",
|
|
|
|
OperationDetails::NONE ) ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2005-11-25 05:59:47 -07:00
|
|
|
ped_constraint_destroy( constraint );
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
2004-11-19 04:55:38 -07:00
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
2004-11-19 04:55:38 -07:00
|
|
|
|
2006-01-21 17:07:27 -07:00
|
|
|
close_device_and_disk() ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
2005-12-07 15:44:40 -07:00
|
|
|
|
2006-02-25 09:30:43 -07:00
|
|
|
if ( new_partition .partition_number > 0 &&
|
|
|
|
(
|
|
|
|
new_partition .type == GParted::TYPE_EXTENDED ||
|
|
|
|
(
|
2006-03-14 14:37:47 -07:00
|
|
|
wait_for_node( new_partition .get_path() ) &&
|
2006-02-25 09:30:43 -07:00
|
|
|
erase_filesystem_signatures( new_partition )
|
|
|
|
)
|
2005-12-15 08:42:09 -07:00
|
|
|
)
|
|
|
|
)
|
2006-01-19 12:15:15 -07:00
|
|
|
{
|
2006-02-25 09:30:43 -07:00
|
|
|
operation_details .back() .status = OperationDetails::SUCCES ;
|
2006-01-19 12:15:15 -07:00
|
|
|
|
2006-03-31 06:10:32 -07:00
|
|
|
return new_partition .partition_number > 0 ;
|
2006-01-19 12:15:15 -07:00
|
|
|
}
|
2005-12-15 08:42:09 -07:00
|
|
|
else
|
2006-02-25 09:30:43 -07:00
|
|
|
{
|
|
|
|
if ( ! ped_error .empty() )
|
|
|
|
operation_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails( "<i>" + ped_error + "</i>", OperationDetails::NONE ) ) ;
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .back() .status = OperationDetails::ERROR ;
|
2006-02-25 09:30:43 -07:00
|
|
|
|
2006-03-31 06:10:32 -07:00
|
|
|
return false ;
|
2006-01-19 12:15:15 -07:00
|
|
|
}
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool GParted_Core::resize_container_partition( const Partition & partition_old,
|
|
|
|
const Partition & partition_new,
|
|
|
|
bool fixed_start,
|
|
|
|
std::vector<OperationDetails> & operation_details )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .push_back( OperationDetails( _("resize partition") ) ) ;
|
2006-02-17 14:18:07 -07:00
|
|
|
|
|
|
|
operation_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails(
|
|
|
|
"<i>" +
|
|
|
|
String::ucompose( _("old start: %1"), partition_old .sector_start ) + "\n" +
|
|
|
|
String::ucompose( _("old end: %1"), partition_old .sector_end ) + "\n" +
|
|
|
|
String::ucompose( _("old size: %1"), Utils::format_size( partition_old .get_length() ) ) +
|
|
|
|
"</i>",
|
|
|
|
OperationDetails::NONE ) ) ;
|
2006-01-19 12:15:15 -07:00
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
bool return_value = false ;
|
|
|
|
|
2004-11-21 14:49:38 -07:00
|
|
|
PedConstraint *constraint = NULL ;
|
2005-11-26 17:57:11 -07:00
|
|
|
lp_partition = NULL ;
|
2006-02-25 09:30:43 -07:00
|
|
|
ped_error .clear() ;
|
2004-11-21 14:49:38 -07:00
|
|
|
|
2005-12-07 15:44:40 -07:00
|
|
|
if ( open_device_and_disk( partition_old .device_path ) )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2005-12-07 04:21:27 -07:00
|
|
|
if ( partition_old .type == GParted::TYPE_EXTENDED )
|
2005-11-26 17:57:11 -07:00
|
|
|
lp_partition = ped_disk_extended_partition( lp_disk ) ;
|
2004-11-21 14:49:38 -07:00
|
|
|
else
|
2006-02-17 16:20:28 -07:00
|
|
|
lp_partition = ped_disk_get_partition_by_sector(
|
|
|
|
lp_disk,
|
|
|
|
(partition_old .sector_end + partition_old .sector_start) / 2 ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2005-11-26 17:57:11 -07:00
|
|
|
if ( lp_partition )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2005-11-26 17:57:11 -07:00
|
|
|
constraint = ped_constraint_any( lp_device );
|
2004-11-24 03:32:56 -07:00
|
|
|
|
2006-02-17 14:18:07 -07:00
|
|
|
if ( fixed_start && constraint )
|
|
|
|
{
|
2006-02-17 16:20:28 -07:00
|
|
|
//create a constraint which keeps de startpoint intact and rounds the end to a cylinder
|
2006-02-17 14:18:07 -07:00
|
|
|
ped_disk_set_partition_geom( lp_disk,
|
|
|
|
lp_partition,
|
|
|
|
constraint,
|
|
|
|
partition_new .sector_start,
|
|
|
|
partition_new .sector_end ) ;
|
2005-11-29 07:50:20 -07:00
|
|
|
ped_constraint_destroy( constraint );
|
2004-11-24 03:32:56 -07:00
|
|
|
constraint = NULL ;
|
|
|
|
|
2005-11-29 07:50:20 -07:00
|
|
|
ped_geometry_set_start( & lp_partition ->geom, partition_new .sector_start ) ;
|
|
|
|
constraint = ped_constraint_exact( & lp_partition ->geom ) ;
|
2004-11-24 03:32:56 -07:00
|
|
|
}
|
2006-02-25 09:30:43 -07:00
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
if ( constraint )
|
|
|
|
{
|
2006-02-17 14:18:07 -07:00
|
|
|
if ( ped_disk_set_partition_geom( lp_disk,
|
|
|
|
lp_partition,
|
|
|
|
constraint,
|
|
|
|
partition_new .sector_start,
|
|
|
|
partition_new .sector_end ) )
|
2006-01-21 17:07:27 -07:00
|
|
|
return_value = commit() ;
|
2004-11-21 14:49:38 -07:00
|
|
|
|
2005-11-29 07:50:20 -07:00
|
|
|
ped_constraint_destroy( constraint );
|
2004-11-21 14:49:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-17 14:18:07 -07:00
|
|
|
close_device_and_disk() ;
|
2004-11-21 14:49:38 -07:00
|
|
|
}
|
2006-02-17 14:18:07 -07:00
|
|
|
|
|
|
|
if ( return_value )
|
|
|
|
{
|
|
|
|
//use start/end vars since lp_partition ->geom loses his values after a functioncall :/
|
|
|
|
//this is actually quite weird, but i don't have time to investigate it more thorough.
|
|
|
|
Sector start = lp_partition ->geom .start ;
|
|
|
|
Sector end = lp_partition ->geom .end ;
|
|
|
|
|
|
|
|
operation_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails(
|
|
|
|
"<i>" +
|
|
|
|
String::ucompose( _("new start: %1"), start ) + "\n" +
|
|
|
|
String::ucompose( _("new end: %1"), end ) + "\n" +
|
|
|
|
String::ucompose( _("new size: %1"), Utils::format_size( end - start + 1 ) ) +
|
|
|
|
"</i>",
|
|
|
|
OperationDetails::NONE ) ) ;
|
|
|
|
}
|
2006-02-25 09:30:43 -07:00
|
|
|
else if ( ! ped_error .empty() )
|
|
|
|
operation_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails( "<i>" + ped_error + "</i>", OperationDetails::NONE ) ) ;
|
2006-02-17 14:18:07 -07:00
|
|
|
|
2005-12-12 02:36:42 -07:00
|
|
|
if ( partition_old .type == GParted::TYPE_EXTENDED )
|
2006-01-19 12:15:15 -07:00
|
|
|
{
|
|
|
|
operation_details .back() .status = return_value ? OperationDetails::SUCCES : OperationDetails::ERROR ;
|
2005-12-12 02:36:42 -07:00
|
|
|
return return_value ;
|
2006-01-19 12:15:15 -07:00
|
|
|
}
|
2005-12-12 02:36:42 -07:00
|
|
|
else
|
2006-01-19 12:15:15 -07:00
|
|
|
{
|
2006-03-14 14:37:47 -07:00
|
|
|
return_value &= wait_for_node( partition_new .get_path() ) ;
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .back() .status = return_value ? OperationDetails::SUCCES : OperationDetails::ERROR ;
|
|
|
|
|
|
|
|
return return_value ;
|
|
|
|
}
|
2004-11-21 14:49:38 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool GParted_Core::resize_normal_using_libparted( const Partition & partition_old,
|
|
|
|
const Partition & partition_new,
|
|
|
|
std::vector<OperationDetails> & operation_details )
|
2004-11-21 14:49:38 -07:00
|
|
|
{
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .push_back( OperationDetails( _("resize partition and filesystem using libparted") ) ) ;
|
|
|
|
|
2004-11-21 14:49:38 -07:00
|
|
|
bool return_value = false ;
|
|
|
|
|
|
|
|
PedFileSystem *fs = NULL ;
|
|
|
|
PedConstraint *constraint = NULL ;
|
2005-11-26 17:57:11 -07:00
|
|
|
lp_partition = NULL ;
|
2006-02-25 09:30:43 -07:00
|
|
|
ped_error .clear() ;
|
2004-11-21 14:49:38 -07:00
|
|
|
|
2005-12-07 15:44:40 -07:00
|
|
|
if ( open_device_and_disk( partition_old .device_path ) )
|
2004-11-21 14:49:38 -07:00
|
|
|
{
|
2006-02-17 16:20:28 -07:00
|
|
|
lp_partition = ped_disk_get_partition_by_sector(
|
|
|
|
lp_disk,
|
|
|
|
(partition_old .sector_end + partition_old .sector_start) / 2 ) ;
|
2005-11-26 17:57:11 -07:00
|
|
|
if ( lp_partition )
|
2004-11-21 14:49:38 -07:00
|
|
|
{
|
2006-02-17 14:18:07 -07:00
|
|
|
fs = ped_file_system_open( & lp_partition ->geom );
|
2004-11-21 14:49:38 -07:00
|
|
|
if ( fs )
|
|
|
|
{
|
2006-02-17 14:18:07 -07:00
|
|
|
constraint = ped_file_system_get_resize_constraint( fs );
|
2004-11-21 14:49:38 -07:00
|
|
|
if ( constraint )
|
|
|
|
{
|
2006-02-17 14:18:07 -07:00
|
|
|
if ( ped_disk_set_partition_geom( lp_disk,
|
|
|
|
lp_partition,
|
|
|
|
constraint,
|
|
|
|
partition_new .sector_start,
|
|
|
|
partition_new .sector_end )
|
|
|
|
&&
|
|
|
|
ped_file_system_resize( fs, & lp_partition ->geom, NULL )
|
2004-11-21 14:49:38 -07:00
|
|
|
)
|
2006-02-17 14:18:07 -07:00
|
|
|
return_value = commit() ;
|
2004-11-21 14:49:38 -07:00
|
|
|
|
2006-02-17 14:18:07 -07:00
|
|
|
ped_constraint_destroy( constraint );
|
2004-11-21 14:49:38 -07:00
|
|
|
}
|
|
|
|
|
2006-02-17 14:18:07 -07:00
|
|
|
ped_file_system_close( fs );
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-17 14:18:07 -07:00
|
|
|
close_device_and_disk() ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .back() .status = return_value ? OperationDetails::SUCCES : OperationDetails::ERROR ;
|
2006-02-25 09:30:43 -07:00
|
|
|
|
|
|
|
if ( ! return_value && ! ped_error .empty() )
|
|
|
|
operation_details .back() .sub_details .push_back(
|
|
|
|
OperationDetails( "<i>" + ped_error + "</i>", OperationDetails::NONE ) ) ;
|
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
return return_value ;
|
|
|
|
}
|
|
|
|
|
2006-02-17 16:20:28 -07:00
|
|
|
void GParted_Core::set_flags( Partition & partition )
|
|
|
|
{
|
|
|
|
for ( unsigned int t = 0 ; t < flags .size() ; t++ )
|
2006-03-31 03:49:27 -07:00
|
|
|
if ( ped_partition_is_flag_available( lp_partition, flags[ t ] ) &&
|
|
|
|
ped_partition_get_flag( lp_partition, flags[ t ] ) )
|
2006-02-17 16:20:28 -07:00
|
|
|
partition .flags .push_back( ped_partition_flag_get_name( flags[ t ] ) ) ;
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2005-12-07 04:21:27 -07:00
|
|
|
void GParted_Core::set_proper_filesystem( const FILESYSTEM & filesystem )
|
2004-11-17 06:00:25 -07:00
|
|
|
{
|
2005-12-24 16:55:54 -07:00
|
|
|
if ( p_filesystem )
|
2004-11-17 06:00:25 -07:00
|
|
|
delete p_filesystem ;
|
|
|
|
|
2005-12-07 04:21:27 -07:00
|
|
|
switch( filesystem )
|
|
|
|
{
|
|
|
|
case FS_EXT2 : p_filesystem = new ext2() ; break ;
|
|
|
|
case FS_EXT3 : p_filesystem = new ext3() ; break ;
|
|
|
|
case FS_LINUX_SWAP : p_filesystem = new linux_swap() ; break ;
|
|
|
|
case FS_FAT16 : p_filesystem = new fat16() ; break ;
|
|
|
|
case FS_FAT32 : p_filesystem = new fat32() ; break ;
|
|
|
|
case FS_NTFS : p_filesystem = new ntfs() ; break ;
|
|
|
|
case FS_REISERFS : p_filesystem = new reiserfs() ; break ;
|
|
|
|
case FS_REISER4 : p_filesystem = new reiser4() ; break ;
|
|
|
|
case FS_XFS : p_filesystem = new xfs() ; break ;
|
|
|
|
case FS_JFS : p_filesystem = new jfs() ; break ;
|
|
|
|
case FS_HFS : p_filesystem = new hfs() ; break ;
|
|
|
|
case FS_HFSPLUS : p_filesystem = new hfsplus() ; break ;
|
2006-04-02 08:35:21 -06:00
|
|
|
case FS_UFS : p_filesystem = new ufs() ; break ;
|
2005-12-07 04:21:27 -07:00
|
|
|
|
|
|
|
default : p_filesystem = NULL ;
|
|
|
|
}
|
2004-11-17 06:00:25 -07:00
|
|
|
}
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
bool GParted_Core::set_partition_type( const Partition & partition,
|
|
|
|
std::vector<OperationDetails> & operation_details )
|
2005-11-24 08:59:31 -07:00
|
|
|
{
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .push_back( OperationDetails( _("set partitiontype") ) ) ;
|
|
|
|
|
2005-11-29 07:50:20 -07:00
|
|
|
bool return_value = false ;
|
|
|
|
|
2005-12-07 15:44:40 -07:00
|
|
|
if ( open_device_and_disk( partition .device_path ) )
|
2005-11-24 08:59:31 -07:00
|
|
|
{
|
2006-02-17 16:20:28 -07:00
|
|
|
PedFileSystemType * fs_type =
|
2006-03-28 05:40:29 -07:00
|
|
|
ped_file_system_type_get( Utils::get_filesystem_string( partition .filesystem ) .c_str() ) ;
|
2005-11-24 08:59:31 -07:00
|
|
|
|
|
|
|
//default is Linux (83)
|
|
|
|
if ( ! fs_type )
|
|
|
|
fs_type = ped_file_system_type_get( "ext2" ) ;
|
|
|
|
|
|
|
|
if ( fs_type )
|
|
|
|
{
|
2006-02-17 16:20:28 -07:00
|
|
|
lp_partition = ped_disk_get_partition_by_sector(
|
|
|
|
lp_disk,
|
|
|
|
(partition .sector_end + partition .sector_start) / 2 ) ;
|
2005-11-24 08:59:31 -07:00
|
|
|
|
2006-02-17 14:18:07 -07:00
|
|
|
if ( lp_partition && ped_partition_set_system( lp_partition, fs_type ) && commit() )
|
2006-03-14 14:37:47 -07:00
|
|
|
return_value = wait_for_node( partition .get_path() ) ;
|
2005-11-24 08:59:31 -07:00
|
|
|
}
|
|
|
|
|
2006-02-17 14:18:07 -07:00
|
|
|
close_device_and_disk() ;
|
2005-11-24 08:59:31 -07:00
|
|
|
}
|
2005-11-29 07:50:20 -07:00
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
operation_details .back() .status = return_value ? OperationDetails::SUCCES : OperationDetails::ERROR ;
|
2005-11-29 07:50:20 -07:00
|
|
|
return return_value ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GParted_Core::wait_for_node( const Glib::ustring & node )
|
|
|
|
{
|
|
|
|
//we'll loop for 10 seconds or till 'node' appeares...
|
|
|
|
for( short t = 0 ; t < 50 ; t++ )
|
|
|
|
{
|
2006-03-29 12:21:42 -07:00
|
|
|
//FIXME: find a better way to check if a file exists
|
|
|
|
//the current way is suboptimal (at best)
|
2005-12-29 07:34:20 -07:00
|
|
|
if ( Glib::file_test( node, Glib::FILE_TEST_EXISTS ) )
|
2005-11-29 07:50:20 -07:00
|
|
|
{
|
2006-03-29 12:21:42 -07:00
|
|
|
sleep( 2 ) ; //apperantly the node isn't available immediatly after file_test returns succesfully :/
|
2005-11-29 07:50:20 -07:00
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
usleep( 200000 ) ; //200 milliseconds
|
|
|
|
}
|
|
|
|
|
|
|
|
return false ;
|
2005-11-24 08:59:31 -07:00
|
|
|
}
|
|
|
|
|
2005-12-07 15:44:40 -07:00
|
|
|
bool GParted_Core::erase_filesystem_signatures( const Partition & partition )
|
|
|
|
{
|
|
|
|
bool return_value = false ;
|
|
|
|
|
|
|
|
if ( open_device_and_disk( partition .device_path ) )
|
|
|
|
{
|
2006-02-17 16:20:28 -07:00
|
|
|
lp_partition = ped_disk_get_partition_by_sector(
|
|
|
|
lp_disk,
|
|
|
|
(partition .sector_end + partition .sector_start) / 2 ) ;
|
2005-12-07 15:44:40 -07:00
|
|
|
|
|
|
|
if ( lp_partition && ped_file_system_clobber( & lp_partition ->geom ) )
|
|
|
|
{
|
|
|
|
//filesystems not yet supported by libparted
|
|
|
|
if ( ped_device_open( lp_device ) )
|
|
|
|
{
|
|
|
|
//reiser4 stores "ReIsEr4" at sector 128
|
|
|
|
return_value = ped_geometry_write( & lp_partition ->geom, "0000000", 128, 1 ) ;
|
|
|
|
|
|
|
|
ped_device_close( lp_device ) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-17 14:18:07 -07:00
|
|
|
close_device_and_disk() ;
|
2005-12-07 15:44:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return return_value ;
|
|
|
|
}
|
|
|
|
|
2005-11-26 17:57:11 -07:00
|
|
|
bool GParted_Core::open_device( const Glib::ustring & device_path )
|
|
|
|
{
|
2006-02-17 14:18:07 -07:00
|
|
|
lp_device = ped_device_get( device_path .c_str() );
|
2005-11-26 17:57:11 -07:00
|
|
|
|
|
|
|
return lp_device ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GParted_Core::open_device_and_disk( const Glib::ustring & device_path, bool strict )
|
|
|
|
{
|
2006-03-27 12:21:37 -07:00
|
|
|
lp_device = NULL ;
|
|
|
|
lp_disk = NULL ;
|
|
|
|
|
2005-11-26 17:57:11 -07:00
|
|
|
if ( open_device( device_path ) )
|
2006-03-27 12:21:37 -07:00
|
|
|
{
|
2005-11-26 17:57:11 -07:00
|
|
|
lp_disk = ped_disk_new( lp_device );
|
|
|
|
|
2006-03-27 12:21:37 -07:00
|
|
|
//if ! disk and writeable it's probably a HD without disklabel.
|
|
|
|
//We return true here and deal with them in GParted_Core::get_devices
|
|
|
|
if ( lp_disk || ( ! strict && ! lp_device ->read_only ) )
|
|
|
|
return true ;
|
2005-11-26 17:57:11 -07:00
|
|
|
|
2006-03-27 12:21:37 -07:00
|
|
|
close_device_and_disk() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false ;
|
2005-11-26 17:57:11 -07:00
|
|
|
}
|
|
|
|
|
2006-02-17 14:18:07 -07:00
|
|
|
void GParted_Core::close_device_and_disk()
|
2005-11-26 17:57:11 -07:00
|
|
|
{
|
|
|
|
if ( lp_device )
|
|
|
|
ped_device_destroy( lp_device ) ;
|
|
|
|
|
|
|
|
if ( lp_disk )
|
|
|
|
ped_disk_destroy( lp_disk ) ;
|
|
|
|
|
|
|
|
lp_device = NULL ;
|
|
|
|
lp_disk = NULL ;
|
|
|
|
}
|
|
|
|
|
2006-02-17 14:18:07 -07:00
|
|
|
bool GParted_Core::commit()
|
2005-11-26 17:57:11 -07:00
|
|
|
{
|
|
|
|
bool return_value = ped_disk_commit_to_dev( lp_disk ) ;
|
|
|
|
|
|
|
|
ped_disk_commit_to_os( lp_disk ) ;
|
|
|
|
|
|
|
|
return return_value ;
|
|
|
|
}
|
2006-02-25 09:30:43 -07:00
|
|
|
|
|
|
|
PedExceptionOption GParted_Core::ped_exception_handler( PedException * e )
|
|
|
|
{
|
|
|
|
std::cout << e ->message << std::endl ;
|
|
|
|
ped_error = e ->message ;
|
|
|
|
|
|
|
|
return PED_EXCEPTION_UNHANDLED ;
|
|
|
|
}
|
2006-03-28 12:01:20 -07:00
|
|
|
|
|
|
|
GParted_Core::~GParted_Core()
|
|
|
|
{
|
2006-03-29 12:21:42 -07:00
|
|
|
if ( p_filesystem )
|
|
|
|
delete p_filesystem ;
|
2006-03-28 12:01:20 -07:00
|
|
|
}
|
2006-03-14 14:37:47 -07:00
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
} //GParted
|