2009-11-05 11:08:32 -07:00
|
|
|
/* Copyright (C) 2004 Bart
|
2012-03-03 11:47:39 -07:00
|
|
|
* Copyright (C) 2008, 2009, 2010, 2011, 2012 Curtis Gedak
|
2004-11-17 06:00:25 -07:00
|
|
|
*
|
|
|
|
* 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
|
2014-01-23 03:59:48 -07:00
|
|
|
* GNU General Public License for more details.
|
2004-11-17 06:00:25 -07:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-23 03:59:48 -07:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2004-11-17 06:00:25 -07:00
|
|
|
*/
|
2013-05-27 05:20:16 -06:00
|
|
|
|
|
|
|
#ifndef GPARTED_GPARTED_CORE_H
|
|
|
|
#define GPARTED_GPARTED_CORE_H
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2006-04-02 08:35:21 -06:00
|
|
|
#include "../include/FileSystem.h"
|
2004-11-17 06:00:25 -07:00
|
|
|
#include "../include/Operation.h"
|
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
#include <parted/parted.h>
|
2012-03-03 11:47:39 -07:00
|
|
|
#ifdef HAVE_LIBPARTED_3_1_0_PLUS
|
|
|
|
#include <parted/filesys.h>
|
|
|
|
#endif
|
2004-11-17 06:00:25 -07:00
|
|
|
#include <vector>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
|
|
|
class GParted_Core
|
|
|
|
{
|
|
|
|
public:
|
2012-01-04 17:30:28 -07:00
|
|
|
static Glib::Thread *mainthread;
|
2006-02-25 09:30:43 -07:00
|
|
|
GParted_Core() ;
|
2006-03-28 12:01:20 -07:00
|
|
|
~GParted_Core() ;
|
2006-06-17 14:52:25 -06:00
|
|
|
|
2014-03-23 17:09:07 -06:00
|
|
|
void init_filesystems() ;
|
2006-02-25 09:30:43 -07:00
|
|
|
void find_supported_filesystems() ;
|
2006-02-02 06:50:37 -07:00
|
|
|
void set_user_devices( const std::vector<Glib::ustring> & user_devices ) ;
|
2006-06-18 02:50:17 -06:00
|
|
|
void set_devices( std::vector<Device> & devices ) ;
|
2013-02-21 17:57:33 -07:00
|
|
|
void set_devices_thread( std::vector<Device> * pdevices );
|
2011-01-28 11:09:21 -07:00
|
|
|
void guess_partition_table(const Device & device, Glib::ustring &buff);
|
2004-11-19 04:55:38 -07:00
|
|
|
|
2006-07-20 13:14:44 -06:00
|
|
|
bool snap_to_cylinder( const Device & device, Partition & partition, Glib::ustring & error ) ;
|
2010-05-20 10:00:14 -06:00
|
|
|
bool snap_to_mebibyte( const Device & device, Partition & partition, Glib::ustring & error ) ;
|
|
|
|
bool snap_to_alignment( const Device & device, Partition & partition, Glib::ustring & error ) ;
|
2006-03-24 12:08:41 -07:00
|
|
|
bool apply_operation_to_disk( Operation * operation );
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2006-06-18 02:50:17 -06:00
|
|
|
bool set_disklabel( const Glib::ustring & device_path, const Glib::ustring & disklabel ) ;
|
2006-06-17 14:52:25 -06:00
|
|
|
|
|
|
|
bool toggle_flag( const Partition & partition, const Glib::ustring & flag, bool state ) ;
|
2006-05-31 14:03:49 -06:00
|
|
|
|
|
|
|
const std::vector<FS> & get_filesystems() const ;
|
|
|
|
const FS & get_fs( GParted::FILESYSTEM filesystem ) const ;
|
2014-01-03 13:56:57 -07:00
|
|
|
static std::vector<Glib::ustring> get_disklabeltypes() ;
|
2014-02-16 06:29:33 -07:00
|
|
|
static bool is_dev_mounted( const Glib::ustring & path ) ;
|
|
|
|
static std::vector<Glib::ustring> get_all_mountpoints() ;
|
2006-05-31 14:03:49 -06:00
|
|
|
std::map<Glib::ustring, bool> get_available_flags( const Partition & partition ) ;
|
2006-12-01 06:01:46 -07:00
|
|
|
Glib::ustring get_libparted_version() ;
|
2008-10-30 12:50:38 -06:00
|
|
|
Glib::ustring get_thread_status_message() ;
|
|
|
|
|
2012-01-27 11:07:11 -07:00
|
|
|
FileSystem * get_filesystem_object( const FILESYSTEM & filesystem ) ;
|
2012-08-25 13:49:10 -06:00
|
|
|
static bool filesystem_resize_disallowed( const Partition & partition ) ;
|
2006-05-31 14:03:49 -06:00
|
|
|
private:
|
2006-06-17 14:52:25 -06:00
|
|
|
//detectionstuff..
|
2014-02-16 06:29:33 -07:00
|
|
|
static void init_maps() ;
|
2008-10-30 12:50:38 -06:00
|
|
|
void set_thread_status_message( Glib::ustring msg ) ;
|
2014-02-16 06:29:33 -07:00
|
|
|
static void read_mountpoints_from_file( const Glib::ustring & filename,
|
Fallback to reading mount command output instead of /etc/mtab (#723842)
With linux 3.5 and later, the device used to mount a btrfs file system
is updated in /proc/mounts when the previous mounting device is removed
from the file system. Most recent distributions make /etc/mtab a
symbolic link to /proc/mounts. However some still have /etc/mtab as a
plain file only updated by mount and umount, thus showing the old device
name which is no longer part of the file system.
On Ubuntu 13.10, which has /etc/mtab as a plain file managed by mount
and umount:
# mkfs.btrfs /dev/sdb1
# mount /dev/sdb1 /mnt/1
# btrfs device add /dev/sdb2 /mnt/1
# btrfs device delete /dev/sdb1 /mnt/1
# sync
# btrfs filesystem show /dev/sdb1
# btrfs filesystem show /dev/sdb2
Label: none uuid: e47775a6-e5ad-4fb4-9ea4-1570aa5b4009
Total devices 2 FS bytes used 28.00KB
devid 2 size 2.00GB used 272.00MB path /dev/sdb2
# fgrep btrfs /proc/mounts
/dev/sdb2 /mnt/1 btrfs rw,relatime,space_cache 0 0
# ls -l /etc/mtab
-rw-r--r-- 1 root root 842 Apr 15 19:41 /etc/mtab
# fgrep btrfs /etc/mtab
/dev/sdb1 /mnt/1 btrfs rw 0 0
This causes GParted to report /dev/sdb1 as busy and mounted at /mnt/1
when it is no longer mounted. This effects recent releases of Ubuntu,
13.04, 13.10 and 14.04.
Either /etc/mtab is a symlink and is identical to /proc/mounts or
/etc/mtab is a plain file with wrong information. Fix by not reading
mounted file systems from /etc/mtab.
However old distributions only contain 'rootfs' and '/dev/root' device
names for the / (root) file system with '/dev/root' being a block device
rather than a symlink to the true device. For example from CentOS 5.x:
# fgrep ' / ' /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / ext3 rw,data=ordered 0 0
# ls -l /dev/root
brw------- 1 root root 8, 3 Jun 4 2013 /dev/root
This prevents identification, and therefore busy detection, of the
device containing the / (root) file system. Used to read /etc/mtab to
get the root file system device name.
# fgrep ' / ' /etc/mtab
/dev/sda3 / ext3 rw 0 0
# ls -l /dev/sda3
brw-r----- 1 root disk 8, 3 Jun 4 2013 /dev/sda3
As per commit:
409096f739118af95e3bff4484fdedb7885c97a2
improved scanning for root mountpoint (/) ...
but, as discussed above, this contains an out of date device name after
the mounting device has been dynamically removed from a multi-device
btrfs, thus identifying the wrong device as busy. Instead fall back to
reading mounted file systems from the output of the mount command, but
only when required.
# mount | fgrep ' / '
/dev/sda3 on / type ext3 (rw)
Bug #723842 - GParted resizes the wrong filesystem (does not pass the
devid to btrfs filesystem resize)
2014-04-14 08:21:55 -06:00
|
|
|
std::map< Glib::ustring, std::vector<Glib::ustring> > & map ) ;
|
|
|
|
static void add_node_and_mountpoint( std::map< Glib::ustring, std::vector<Glib::ustring> > & map,
|
|
|
|
Glib::ustring & node,
|
|
|
|
Glib::ustring & mountpoint ) ;
|
2014-02-16 06:29:33 -07:00
|
|
|
static void read_mountpoints_from_file_swaps( const Glib::ustring & filename,
|
Fallback to reading mount command output instead of /etc/mtab (#723842)
With linux 3.5 and later, the device used to mount a btrfs file system
is updated in /proc/mounts when the previous mounting device is removed
from the file system. Most recent distributions make /etc/mtab a
symbolic link to /proc/mounts. However some still have /etc/mtab as a
plain file only updated by mount and umount, thus showing the old device
name which is no longer part of the file system.
On Ubuntu 13.10, which has /etc/mtab as a plain file managed by mount
and umount:
# mkfs.btrfs /dev/sdb1
# mount /dev/sdb1 /mnt/1
# btrfs device add /dev/sdb2 /mnt/1
# btrfs device delete /dev/sdb1 /mnt/1
# sync
# btrfs filesystem show /dev/sdb1
# btrfs filesystem show /dev/sdb2
Label: none uuid: e47775a6-e5ad-4fb4-9ea4-1570aa5b4009
Total devices 2 FS bytes used 28.00KB
devid 2 size 2.00GB used 272.00MB path /dev/sdb2
# fgrep btrfs /proc/mounts
/dev/sdb2 /mnt/1 btrfs rw,relatime,space_cache 0 0
# ls -l /etc/mtab
-rw-r--r-- 1 root root 842 Apr 15 19:41 /etc/mtab
# fgrep btrfs /etc/mtab
/dev/sdb1 /mnt/1 btrfs rw 0 0
This causes GParted to report /dev/sdb1 as busy and mounted at /mnt/1
when it is no longer mounted. This effects recent releases of Ubuntu,
13.04, 13.10 and 14.04.
Either /etc/mtab is a symlink and is identical to /proc/mounts or
/etc/mtab is a plain file with wrong information. Fix by not reading
mounted file systems from /etc/mtab.
However old distributions only contain 'rootfs' and '/dev/root' device
names for the / (root) file system with '/dev/root' being a block device
rather than a symlink to the true device. For example from CentOS 5.x:
# fgrep ' / ' /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / ext3 rw,data=ordered 0 0
# ls -l /dev/root
brw------- 1 root root 8, 3 Jun 4 2013 /dev/root
This prevents identification, and therefore busy detection, of the
device containing the / (root) file system. Used to read /etc/mtab to
get the root file system device name.
# fgrep ' / ' /etc/mtab
/dev/sda3 / ext3 rw 0 0
# ls -l /dev/sda3
brw-r----- 1 root disk 8, 3 Jun 4 2013 /dev/sda3
As per commit:
409096f739118af95e3bff4484fdedb7885c97a2
improved scanning for root mountpoint (/) ...
but, as discussed above, this contains an out of date device name after
the mounting device has been dynamically removed from a multi-device
btrfs, thus identifying the wrong device as busy. Instead fall back to
reading mounted file systems from the output of the mount command, but
only when required.
# mount | fgrep ' / '
/dev/sda3 on / type ext3 (rw)
Bug #723842 - GParted resizes the wrong filesystem (does not pass the
devid to btrfs filesystem resize)
2014-04-14 08:21:55 -06:00
|
|
|
std::map< Glib::ustring, std::vector<Glib::ustring> > & map ) ;
|
|
|
|
static bool have_rootfs_dev( std::map< Glib::ustring, std::vector<Glib::ustring> > & map ) ;
|
|
|
|
static void read_mountpoints_from_mount_command( std::map< Glib::ustring, std::vector<Glib::ustring> > & map ) ;
|
2010-08-15 14:14:04 -06:00
|
|
|
Glib::ustring get_partition_path( PedPartition * lp_partition ) ;
|
2012-10-30 03:30:49 -06:00
|
|
|
void set_device_partitions( Device & device, PedDevice* lp_device, PedDisk* lp_disk ) ;
|
2012-09-01 04:58:41 -06:00
|
|
|
GParted::FILESYSTEM get_filesystem( PedDevice* lp_device, PedPartition* lp_partition,
|
|
|
|
std::vector<Glib::ustring>& messages ) ;
|
2008-11-08 16:55:17 -07:00
|
|
|
void read_label( Partition & partition ) ;
|
2012-01-22 13:49:52 -07:00
|
|
|
void read_uuid( Partition & partition ) ;
|
2006-02-17 16:20:28 -07:00
|
|
|
void insert_unallocated( const Glib::ustring & device_path,
|
|
|
|
std::vector<Partition> & partitions,
|
|
|
|
Sector start,
|
|
|
|
Sector end,
|
2010-04-19 19:22:31 -06:00
|
|
|
Byte_Value sector_size,
|
2006-02-17 16:20:28 -07:00
|
|
|
bool inside_extended ) ;
|
2006-06-18 02:50:17 -06:00
|
|
|
void set_mountpoints( std::vector<Partition> & partitions ) ;
|
2014-03-25 17:03:30 -06:00
|
|
|
bool set_mountpoints_helper( Partition & partitions, const Glib::ustring & path ) ;
|
2014-02-14 18:26:32 -07:00
|
|
|
bool is_busy( FILESYSTEM fstype, const Glib::ustring & path ) ;
|
2012-10-30 03:30:49 -06:00
|
|
|
void set_used_sectors( std::vector<Partition> & partitions, PedDisk* lp_disk ) ;
|
2012-09-10 09:41:58 -06:00
|
|
|
void mounted_set_used_sectors( Partition & partition ) ;
|
2012-03-03 11:47:39 -07:00
|
|
|
#ifdef HAVE_LIBPARTED_FS_RESIZE
|
2012-10-30 03:30:49 -06:00
|
|
|
void LP_set_used_sectors( Partition & partition, PedDisk* lp_disk ) ;
|
2011-06-09 09:59:41 -06:00
|
|
|
#endif
|
2012-10-30 03:43:46 -06:00
|
|
|
void set_flags( Partition & partition, PedPartition* lp_partition ) ;
|
2008-10-30 12:50:38 -06:00
|
|
|
|
2006-06-17 14:52:25 -06:00
|
|
|
//operationstuff...
|
2006-08-20 03:33:54 -06:00
|
|
|
bool create( const Device & device, Partition & new_partition, OperationDetail & operationdetail ) ;
|
|
|
|
bool create_partition( Partition & new_partition, OperationDetail & operationdetail, Sector min_size = 0 ) ;
|
|
|
|
bool create_filesystem( const Partition & partition, OperationDetail & operationdetail ) ;
|
2006-06-17 14:52:25 -06:00
|
|
|
|
2006-08-20 03:33:54 -06:00
|
|
|
bool format( const Partition & partition, OperationDetail & operationdetail ) ;
|
2006-06-17 14:52:25 -06:00
|
|
|
|
2006-08-20 03:33:54 -06:00
|
|
|
bool Delete( const Partition & partition, OperationDetail & operationdetail ) ;
|
2012-07-25 14:05:33 -06:00
|
|
|
|
|
|
|
bool remove_filesystem( const Partition & partition, OperationDetail & operationdetail ) ;
|
|
|
|
|
2008-04-07 13:41:18 -06:00
|
|
|
bool label_partition( const Partition & partition, OperationDetail & operation_detail ) ;
|
|
|
|
|
2012-01-22 13:49:52 -07:00
|
|
|
bool change_uuid( const Partition & partition, OperationDetail & operation_detail ) ;
|
|
|
|
|
2006-06-17 14:52:25 -06:00
|
|
|
bool resize_move( const Device & device,
|
|
|
|
const Partition & partition_old,
|
|
|
|
Partition & partition_new,
|
2006-08-20 03:33:54 -06:00
|
|
|
OperationDetail & operationdetail ) ;
|
2006-06-17 14:52:25 -06:00
|
|
|
bool move( const Device & device,
|
|
|
|
const Partition & partition_old,
|
2006-07-23 10:51:38 -06:00
|
|
|
const Partition & partition_new,
|
2006-08-20 03:33:54 -06:00
|
|
|
OperationDetail & operationdetail ) ;
|
2006-06-18 13:27:52 -06:00
|
|
|
bool move_filesystem( const Partition & partition_old,
|
2006-07-23 03:58:45 -06:00
|
|
|
const Partition & partition_new,
|
2006-08-20 03:33:54 -06:00
|
|
|
OperationDetail & operationdetail ) ;
|
2012-03-03 11:47:39 -07:00
|
|
|
#ifdef HAVE_LIBPARTED_FS_RESIZE
|
2006-07-23 03:58:45 -06:00
|
|
|
bool resize_move_filesystem_using_libparted( const Partition & partition_old,
|
|
|
|
const Partition & partition_new,
|
2006-08-20 03:33:54 -06:00
|
|
|
OperationDetail & operationdetail ) ;
|
2011-06-09 09:59:41 -06:00
|
|
|
#endif
|
2006-07-23 12:43:15 -06:00
|
|
|
bool resize( const Partition & partition_old,
|
2006-07-23 10:51:38 -06:00
|
|
|
const Partition & partition_new,
|
2006-08-20 03:33:54 -06:00
|
|
|
OperationDetail & operationdetail ) ;
|
2006-06-18 13:38:29 -06:00
|
|
|
bool resize_move_partition( const Partition & partition_old,
|
2006-07-23 03:58:45 -06:00
|
|
|
const Partition & partition_new,
|
2006-08-20 03:33:54 -06:00
|
|
|
OperationDetail & operationdetail ) ;
|
2006-06-17 14:52:25 -06:00
|
|
|
bool resize_filesystem( const Partition & partition_old,
|
|
|
|
const Partition & partition_new,
|
2006-08-20 03:33:54 -06:00
|
|
|
OperationDetail & operationdetail,
|
2006-06-17 14:52:25 -06:00
|
|
|
bool fill_partition = false ) ;
|
2006-08-20 03:33:54 -06:00
|
|
|
bool maximize_filesystem( const Partition & partition, OperationDetail & operationdetail ) ;
|
2006-06-17 14:52:25 -06:00
|
|
|
|
|
|
|
bool copy( const Partition & partition_src,
|
2006-09-03 12:24:09 -06:00
|
|
|
Partition & partition_dst,
|
2010-04-07 11:33:21 -06:00
|
|
|
Byte_Value min_size,
|
2006-08-20 03:33:54 -06:00
|
|
|
OperationDetail & operationdetail ) ;
|
2006-05-23 15:17:34 -06:00
|
|
|
bool copy_filesystem( const Partition & partition_src,
|
2006-09-10 06:17:33 -06:00
|
|
|
const Partition & partition_dst,
|
2006-09-07 14:31:05 -06:00
|
|
|
OperationDetail & operationdetail,
|
2013-01-20 19:50:55 -07:00
|
|
|
bool cancel_safe );
|
2006-09-10 06:17:33 -06:00
|
|
|
bool copy_filesystem( const Partition & partition_src,
|
|
|
|
const Partition & partition_dst,
|
|
|
|
OperationDetail & operationdetail,
|
2013-01-20 19:50:55 -07:00
|
|
|
Byte_Value & total_done,
|
|
|
|
bool cancel_safe );
|
2006-09-10 06:17:33 -06:00
|
|
|
bool copy_filesystem( const Glib::ustring & src_device,
|
|
|
|
const Glib::ustring & dst_device,
|
|
|
|
Sector src_start,
|
|
|
|
Sector dst_start,
|
2010-04-26 11:35:30 -06:00
|
|
|
Byte_Value src_sector_size,
|
|
|
|
Byte_Value dst_sector_size,
|
2010-04-07 11:33:21 -06:00
|
|
|
Byte_Value src_length,
|
2006-09-10 06:17:33 -06:00
|
|
|
OperationDetail & operationdetail,
|
2013-01-20 19:50:55 -07:00
|
|
|
Byte_Value & total_done,
|
|
|
|
bool cancel_safe ) ;
|
2006-09-10 06:17:33 -06:00
|
|
|
void rollback_transaction( const Partition & partition_src,
|
2010-04-07 11:33:21 -06:00
|
|
|
const Partition & partition_dst,
|
|
|
|
OperationDetail & operationdetail,
|
|
|
|
Byte_Value total_done ) ;
|
2006-06-17 14:52:25 -06:00
|
|
|
|
2006-08-20 03:33:54 -06:00
|
|
|
bool check_repair_filesystem( const Partition & partition, OperationDetail & operationdetail ) ;
|
2006-06-17 14:52:25 -06:00
|
|
|
|
2006-08-20 03:33:54 -06:00
|
|
|
bool set_partition_type( const Partition & partition, OperationDetail & operationdetail ) ;
|
2006-06-17 14:52:25 -06:00
|
|
|
|
2006-09-03 08:24:05 -06:00
|
|
|
bool calibrate_partition( Partition & partition, OperationDetail & operationdetail ) ;
|
2006-07-23 03:58:45 -06:00
|
|
|
bool calculate_exact_geom( const Partition & partition_old,
|
|
|
|
Partition & partition_new,
|
2006-08-27 02:41:25 -06:00
|
|
|
OperationDetail & operationdetail ) ;
|
2012-12-01 05:49:29 -07:00
|
|
|
bool erase_filesystem_signatures( const Partition & partition, OperationDetail & operationdetail ) ;
|
2006-09-04 13:18:44 -06:00
|
|
|
bool update_bootsector( const Partition & partition, OperationDetail & operationdetail ) ;
|
2006-06-17 14:52:25 -06:00
|
|
|
|
|
|
|
//general..
|
2013-02-25 10:28:07 -07:00
|
|
|
bool get_device_and_disk( const Glib::ustring & device_path,
|
|
|
|
PedDevice*& lp_device, PedDisk*& lp_disk, bool strict = true ) ;
|
|
|
|
void destroy_device_and_disk( PedDevice*& lp_device, PedDisk*& lp_disk ) ;
|
2012-10-30 03:30:49 -06:00
|
|
|
bool commit( PedDisk* lp_disk ) ;
|
|
|
|
bool commit_to_os( PedDisk* lp_disk, std::time_t timeout ) ;
|
2009-05-02 10:49:49 -06:00
|
|
|
void settle_device( std::time_t timeout ) ;
|
2005-11-26 17:57:11 -07:00
|
|
|
|
2006-02-25 09:30:43 -07:00
|
|
|
static PedExceptionOption ped_exception_handler( PedException * e ) ;
|
|
|
|
|
2004-11-17 06:00:25 -07:00
|
|
|
std::vector<FS> FILESYSTEMS ;
|
2012-01-27 11:07:11 -07:00
|
|
|
std::map< FILESYSTEM, FileSystem * > FILESYSTEM_MAP ;
|
2006-02-15 15:32:54 -07:00
|
|
|
std::vector<PedPartitionFlag> flags;
|
2006-02-02 06:50:37 -07:00
|
|
|
std::vector<Glib::ustring> device_paths ;
|
|
|
|
bool probe_devices ;
|
2008-10-30 12:50:38 -06:00
|
|
|
Glib::ustring thread_status_message; //Used to pass data to show_pulsebar method
|
2011-01-28 11:09:21 -07:00
|
|
|
Glib::RefPtr<Glib::IOChannel> iocInput, iocOutput; // Used to send data to gpart command
|
2004-11-17 06:00:25 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} //GParted
|
|
|
|
|
2013-05-27 05:20:16 -06:00
|
|
|
#endif /* GPARTED_GPARTED_CORE_H */
|