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
|
|
|
|
Add BlockSpecial into mount_info and fstab_info (#767842)
On some distributions having btrfs on top of LUKS encrypted partitions,
adding a second device and removing the first device used to mount the
file system causes GParted to no longer be able to report the file
system as busy or the mount points themselves.
For example, on CentOS 7, create a single btrfs file system and mount
it. The provided /dev/mapper/sdb1_crypt name is reported, via
/proc/mounts, as the mounting device:
# cryptsetup luksFormat --force-password /dev/sdb1
# cryptsetup luksOpen /dev/sdb1 sdb1_crypt
# mkfs.btrfs -L encrypted-btrfs /dev/mapper/sdb1_crypt
# mount /dev/mapper/sdb1_crypt /mnt/1
# ls -l /dev/mapper
total 0
lrwxrwxrwx. 1 root root 7 Jul 2 14:15 centos-root -> ../dm-1
lrwxrwxrwx. 1 root root 7 Jul 2 14:15 centos-swap -> ../dm-0
crw-------. 1 root root 10, 236 Jul 2 14:15 control
lrwxrwxrwx. 1 root root 7 Jul 2 15:14 sdb1_crypt -> ../dm-2
# fgrep btrfs /proc/mounts
/dev/mapper/sdb1_crypt /mnt/1 btrfs rw,seclabel,relatime,space_cache 0 0
Add a second device to the btrfs file system:
# cryptsetup luksFormat --force-password /dev/sdb2
# cryptsetup luksOpen /dev/sdb2 sdb2_crypt
# btrfs device add /dev/mapper/sdb2_crypt /mnt/1
# ls -l /dev/mapper
...
lrwxrwxrwx. 1 root root 7 Jul 2 15:12 sdb2_crypt -> ../dm-3
# btrfs filesystem show /dev/mapper/sdb1_crypt
Label: 'encrypted-btrfs' uuid: 45d7b1ef-820c-4ef8-8abd-c70d928afb49
Total devices 2 FS bytes used 32.00KiB
devid 1 size 1022.00MiB used 12.00MiB path /dev/mapper/sdb1_crypt
devid 2 size 1022.00MiB used 0.00B path /dev/mapper/sdb2_crypt
Remove the first mounting device from the btrfs file system. Now the
non-canonical name /dev/dm-3 is reported, via /proc/mounts, as the
mounting device:
# btrfs device delete /dev/mapper/sdb1_crypt /mnt/1
# btrfs filesystem show /dev/mapper/sdb2_crypt
Label: 'encrypted-btrfs' uuid: 45d7b1ef-820c-4ef8-8abd-c70d928afb49
Total devices 1 FS bytes used 96.00KiB
devid 2 size 1022.00MiB used 144.00MiB path /dev/mapper/sdb2_crypt
# fgrep btrfs /proc/mounts
/dev/dm-3 /mnt/1 btrfs rw,seclabel,relatime,space_cache 0 0
# ls -l /dev/dm-3
brw-rw----. 1 root disk 253, 3 Jul 2 15:12 /dev/dm-3
GParted loads the mount_info mapping from /proc/mounts and with it the
/dev/dm-3 name. When GParted is determining if the encrypted btrfs file
system is mounted or getting the mount points it is using the
/dev/mapper/sdb2_crypt name. Therefore no information is found and the
file system is incorrectly reported as unmounted.
Fix by changing mount_info and fstab_info to use BlockSpecial objects
instead of strings so that matching is performed by major, minor device
numbers rather than by string compare. Note that as BlockSpecial
objects are used as the key of std::map [1] mappings operator<() [2]
needs to be provided to order the key values.
[1] std::map
http://www.cplusplus.com/reference/map/map/
[2] std::map::key_comp
http://www.cplusplus.com/reference/map/map/key_comp/
Bug 767842 - File system usage missing when tools report alternate block
device names
2016-06-25 01:29:17 -06:00
|
|
|
#include "../include/BlockSpecial.h"
|
2006-04-02 08:35:21 -06:00
|
|
|
#include "../include/FileSystem.h"
|
2004-11-17 06:00:25 -07:00
|
|
|
#include "../include/Operation.h"
|
2015-05-23 13:22:37 -06:00
|
|
|
#include "../include/Partition.h"
|
2015-12-23 05:26:17 -07:00
|
|
|
#include "../include/PartitionLUKS.h"
|
2015-05-23 13:22:37 -06:00
|
|
|
#include "../include/PartitionVector.h"
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2006-01-19 12:15:15 -07:00
|
|
|
#include <parted/parted.h>
|
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
|
|
|
|
Remember result of searching the PATH for the hdparm command (#751251)
Previously on every refresh for every device, GParted was searching the
PATH to discover if the hdparm command existed. Stracing GParted showed
that calling Glib::find_program_in_path("hdparm") made the following OS
calls:
access("/usr/lib64/qt-3.3/bin/hdparm", X_OK) = -1 ENOENT (No such file or directory)
access("/usr/local/sbin/hdparm", X_OK) = -1 ENOENT (No such file or directory)
access("/usr/local/bin/hdparm", X_OK) = -1 ENOENT (No such file or directory)
access("/sbin/hdparm", X_OK) = 0
getuid() = 0
stat("/sbin/hdparm", {st_mode=S_IFREG|0755, st_size=137, ...}) = 0
stat("/sbin/hdparm", {st_mode=S_IFREG|0755, st_size=137, ...}) = 0
The Linux VFS is very fast but repeatedly doing this is wasteful.
Remember the result of searching the PATH for the hdparm command at
startup and refresh this when the [Rescan For Supported Actions] button
is pressed in the File System Support dialog. This is the same as
GParted already does for file system specific commands and their
capabilities.
Bug 751251 - Show serial number in device information
2015-06-30 05:14:20 -06:00
|
|
|
static void find_supported_core();
|
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 );
|
2015-02-14 13:49:45 -07:00
|
|
|
|
|
|
|
bool set_disklabel( const Device & device, const Glib::ustring & disklabel );
|
2015-02-21 09:43:42 -07:00
|
|
|
bool new_disklabel( const Glib::ustring & device_path, const Glib::ustring & disklabel,
|
|
|
|
bool recreate_dmraid_devs = true );
|
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() ;
|
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() ;
|
|
|
|
|
2014-10-13 06:03:47 -06:00
|
|
|
static FileSystem * get_filesystem_object( FILESYSTEM filesystem );
|
|
|
|
static bool supported_filesystem( FILESYSTEM fstype );
|
2012-08-25 13:49:10 -06:00
|
|
|
static bool filesystem_resize_disallowed( const Partition & partition ) ;
|
2015-12-07 00:24:38 -07:00
|
|
|
static void insert_unallocated( const Glib::ustring & device_path,
|
|
|
|
PartitionVector & partitions,
|
|
|
|
Sector start,
|
|
|
|
Sector end,
|
|
|
|
Byte_Value sector_size,
|
|
|
|
bool inside_extended );
|
|
|
|
|
2006-05-31 14:03:49 -06:00
|
|
|
private:
|
2006-06-17 14:52:25 -06:00
|
|
|
//detectionstuff..
|
2008-10-30 12:50:38 -06:00
|
|
|
void set_thread_status_message( Glib::ustring msg ) ;
|
2015-04-19 02:52:16 -06:00
|
|
|
static Glib::ustring get_partition_path( PedPartition * lp_partition );
|
2015-06-22 07:08:02 -06:00
|
|
|
void set_device_serial_number( Device & device );
|
2012-10-30 03:30:49 -06:00
|
|
|
void set_device_partitions( Device & device, PedDevice* lp_device, PedDisk* lp_disk ) ;
|
Display whole disk file systems via partition table "none" (#741430)
For file systems which libparted recognises, when found on the whole
disk device, it reports with partition table "loop" and a partition
covering the whole disk. GParted duly displays this to the user.
For file systems which libparted doesn't recognise it reports
"unrecognised disk label". As of the latest libparted 3.2, these file
system aren't recognised and can't currently be shown when on the whole
disk device:
BitLocker, Crypt LUKS, exFAT, F2FS, LVM2 Physical Volume,
Linux Software RAID, ReFS, Reiser 4
So only when libparted doesn't recognise a file system on the whole disk
device and GParted does, either via blkid or it's internal code, display
this with partition table "none".
Bug 741430 - GParted cannot recognise LVM signature on unpartitioned
drive
2014-12-27 07:10:54 -07:00
|
|
|
void set_device_one_partition( Device & device, PedDevice * lp_device, FILESYSTEM fstype,
|
|
|
|
std::vector<Glib::ustring> & messages );
|
2015-12-23 05:26:17 -07:00
|
|
|
void set_luks_partition( PartitionLUKS & partition );
|
2014-12-27 06:46:38 -07:00
|
|
|
void set_partition_label_and_uuid( Partition & partition );
|
2015-04-19 02:52:16 -06:00
|
|
|
static FILESYSTEM detect_filesystem_internal( PedDevice * lp_device, PedPartition * lp_partition );
|
|
|
|
static FILESYSTEM detect_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 ) ;
|
2015-11-27 01:30:56 -07:00
|
|
|
void set_mountpoints( Partition & partition );
|
|
|
|
bool set_mountpoints_helper( Partition & partition, const Glib::ustring & path );
|
2014-02-14 18:26:32 -07:00
|
|
|
bool is_busy( FILESYSTEM fstype, const Glib::ustring & path ) ;
|
2015-11-27 06:55:20 -07:00
|
|
|
void set_used_sectors( Partition & partition, 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...
|
2015-01-18 08:46:10 -07:00
|
|
|
bool create( Partition & new_partition, OperationDetail & operationdetail );
|
2006-08-20 03:33:54 -06:00
|
|
|
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
|
|
|
|
2016-11-19 04:49:44 -07:00
|
|
|
bool delete_partition( const Partition & partition, OperationDetail & operationdetail );
|
2012-07-25 14:05:33 -06:00
|
|
|
|
|
|
|
bool remove_filesystem( const Partition & partition, OperationDetail & operationdetail ) ;
|
|
|
|
|
2014-12-18 15:18:33 -07:00
|
|
|
bool label_filesystem( const Partition & partition, OperationDetail & operationdetail );
|
|
|
|
|
2014-12-12 00:00:02 -07:00
|
|
|
bool name_partition( const Partition & partition, OperationDetail & operationdetail );
|
|
|
|
|
2016-11-19 04:49:44 -07:00
|
|
|
bool change_filesystem_uuid( const Partition & partition, OperationDetail & operation_detail );
|
2012-01-22 13:49:52 -07:00
|
|
|
|
2015-01-18 08:46:10 -07:00
|
|
|
bool resize_move( const Partition & partition_old,
|
|
|
|
Partition & partition_new,
|
|
|
|
OperationDetail & operationdetail );
|
|
|
|
bool move( const Partition & partition_old,
|
|
|
|
const Partition & partition_new,
|
|
|
|
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 ) ;
|
2015-07-14 13:40:56 -06:00
|
|
|
void thread_lp_ped_file_system_resize( PedFileSystem * fs,
|
|
|
|
PedGeometry * lp_geom,
|
|
|
|
bool * return_value );
|
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,
|
2016-11-04 09:07:29 -06:00
|
|
|
Partition & partition_dst,
|
|
|
|
OperationDetail & operationdetail );
|
|
|
|
bool copy_filesystem( const Partition & partition_src,
|
|
|
|
Partition & partition_dst,
|
|
|
|
OperationDetail & operationdetail );
|
2016-11-04 07:45:50 -06:00
|
|
|
bool copy_filesystem_internal( const Partition & partition_src,
|
|
|
|
const Partition & partition_dst,
|
|
|
|
OperationDetail & operationdetail,
|
|
|
|
bool cancel_safe );
|
|
|
|
bool copy_filesystem_internal( const Partition & partition_src,
|
|
|
|
const Partition & partition_dst,
|
|
|
|
OperationDetail & operationdetail,
|
|
|
|
Byte_Value & total_done,
|
|
|
|
bool cancel_safe );
|
|
|
|
bool copy_blocks( const Glib::ustring & src_device,
|
|
|
|
const Glib::ustring & dst_device,
|
|
|
|
Sector src_start,
|
|
|
|
Sector dst_start,
|
|
|
|
Byte_Value src_sector_size,
|
|
|
|
Byte_Value dst_sector_size,
|
|
|
|
Byte_Value src_length,
|
|
|
|
OperationDetail & operationdetail,
|
|
|
|
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..
|
2015-04-24 14:57:49 -06:00
|
|
|
static void init_filesystems();
|
|
|
|
static void fini_filesystems();
|
|
|
|
|
2015-04-25 06:37:59 -06:00
|
|
|
static bool flush_device( PedDevice * lp_device );
|
|
|
|
static bool get_device( const Glib::ustring & device_path, PedDevice *& lp_device, bool flush = false );
|
|
|
|
static bool get_disk( PedDevice *& lp_device, PedDisk *& lp_disk, bool strict = true );
|
|
|
|
static bool get_device_and_disk( const Glib::ustring & device_path,
|
|
|
|
PedDevice*& lp_device, PedDisk*& lp_disk, bool strict = true, bool flush = false );
|
|
|
|
static void destroy_device_and_disk( PedDevice*& lp_device, PedDisk*& lp_disk );
|
|
|
|
static bool commit( PedDisk* lp_disk );
|
|
|
|
static bool commit_to_os( PedDisk* lp_disk, std::time_t timeout );
|
|
|
|
static void settle_device( std::time_t timeout );
|
2015-10-06 06:41:38 -06:00
|
|
|
static bool useable_device( PedDevice * lp_device );
|
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 ;
|
2014-10-13 06:03:47 -06:00
|
|
|
static 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 */
|