File: GParted_Core.h

package info (click to toggle)
gparted 1.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,752 kB
  • sloc: cpp: 34,868; sh: 5,073; makefile: 462; sed: 16; ansic: 9
file content (248 lines) | stat: -rw-r--r-- 12,061 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/* Copyright (C) 2004 Bart
 * Copyright (C) 2008, 2009, 2010, 2011, 2012 Curtis Gedak
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef GPARTED_GPARTED_CORE_H
#define GPARTED_GPARTED_CORE_H

#include "BlockSpecial.h"
#include "Device.h"
#include "FileSystem.h"
#include "Operation.h"
#include "Partition.h"
#include "PartitionLUKS.h"
#include "PartitionVector.h"
#include "SupportedFileSystems.h"
#include "Utils.h"

#include <parted/parted.h>
#include <vector>
#include <fstream>
#include <glibmm/thread.h>
#include <glibmm/ustring.h>


namespace GParted
{

class GParted_Core
{
friend class EraseFileSystemSignaturesTest;  // To allow unit testing to call private
                                             // method.

public:
	static Glib::Thread *mainthread;
	GParted_Core() ;
	~GParted_Core() ;

	static Glib::ustring get_version_and_config_string();
	static void find_supported_core();
	void find_supported_filesystems() ;
	void set_user_devices( const std::vector<Glib::ustring> & user_devices ) ;
	void set_devices( std::vector<Device> & devices ) ;
	void set_devices_thread( std::vector<Device> * pdevices );

	bool valid_partition(const Device& device, Partition& partition, Glib::ustring& error);
	bool apply_operation_to_disk( Operation * operation );

	bool set_disklabel( const Device & device, const Glib::ustring & disklabel );
	bool new_disklabel( const Glib::ustring & device_path, const Glib::ustring & disklabel,
	                    bool recreate_dmraid_devs = true );

	bool toggle_flag( const Partition & partition, const Glib::ustring & flag, bool state ) ;
	
	const std::vector<FS> & get_filesystems() const ;
	const FS& get_fs(FSType fstype) const;
	static std::vector<Glib::ustring> get_disklabeltypes() ;
	std::map<Glib::ustring, bool> get_available_flags( const Partition & partition ) ;
	Glib::ustring get_thread_status_message() ;

	static FileSystem * get_filesystem_object( FSType fstype );
	static bool supported_filesystem( FSType fstype );
	static FS_Limits get_filesystem_limits( FSType fstype, const Partition & partition );
	static bool filesystem_resize_disallowed( const Partition & partition ) ;
	static void insert_unallocated( const Glib::ustring & device_path,
	                                PartitionVector & partitions,
	                                Sector start,
	                                Sector end,
	                                Byte_Value sector_size,
	                                bool inside_extended );

private:
	//detectionstuff..
	void set_thread_status_message( Glib::ustring msg ) ;
	static Glib::ustring get_partition_path(const PedPartition *lp_partition);
	void set_device_from_disk( Device & device, const Glib::ustring & device_path );
	void set_device_serial_number( Device & device );
	void set_device_partitions( Device & device, PedDevice* lp_device, PedDisk* lp_disk ) ;
	void set_device_one_partition( Device & device, PedDevice * lp_device, FSType fstype,
	                               std::vector<Glib::ustring> & messages );
	void set_luks_partition( PartitionLUKS & partition );
	void set_partition_label_and_uuid( Partition & partition );
	static FSType detect_filesystem_in_encryption_mapping(const Glib::ustring& path,
	                                                      std::vector<Glib::ustring>& messages);
	static FSType detect_filesystem_internal(const Glib::ustring& path, Byte_Value sector_size);
	static FSType detect_filesystem(const PedDevice *lp_device, const PedPartition *lp_partition,
	                                std::vector<Glib::ustring> &messages);
	void read_label( Partition & partition ) ;
	void read_uuid( Partition & partition ) ;
	void set_mountpoints( Partition & partition );
	bool set_mountpoints_helper( Partition & partition, const Glib::ustring & path );
	bool is_busy(const Glib::ustring& device_path, FSType fstype, const Glib::ustring& partition_path);
	void set_used_sectors( Partition & partition, PedDisk* lp_disk );
	void mounted_fs_set_used_sectors(Partition& partition);
#ifdef HAVE_LIBPARTED_FS_RESIZE
	void LP_set_used_sectors( Partition & partition, PedDisk* lp_disk ) ;
#endif
	void set_flags( Partition & partition, PedPartition* lp_partition ) ;
	
	//operationstuff...
	bool create( 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 ) ;

	bool format( const Partition & partition, OperationDetail & operationdetail ) ;

	bool delete_partition( const Partition & partition, OperationDetail & operationdetail );

	bool remove_filesystem( const Partition & partition, OperationDetail & operationdetail ) ;

	bool label_filesystem( const Partition & partition, OperationDetail & operationdetail );

	bool name_partition( const Partition & partition, OperationDetail & operationdetail );

	bool change_filesystem_uuid( const Partition & partition, OperationDetail & operation_detail );

	bool resize_move( const Partition & partition_old,
	                  Partition & partition_new,
	                  OperationDetail & operationdetail );
	bool move( const Partition & partition_old,
	           const Partition & partition_new,
	           OperationDetail & operationdetail );
	bool move_filesystem( const Partition & partition_old,
			      const Partition & partition_new,
			      OperationDetail & operationdetail ) ;
#ifdef HAVE_LIBPARTED_FS_RESIZE
	bool resize_move_filesystem_using_libparted( const Partition & partition_old,
				      		     const Partition & partition_new,
					      	     OperationDetail & operationdetail ) ;
	void thread_lp_ped_file_system_resize( PedFileSystem * fs,
	                                       PedGeometry * lp_geom,
	                                       bool * return_value );
#endif
	bool resize( const Partition & partition_old,
		     const Partition & partition_new,
		     OperationDetail & operationdetail ) ;
	bool resize_encryption( const Partition & partition_old,
	                        const Partition & partition_new,
	                        OperationDetail & operationdetail );
	bool resize_plain( const Partition & partition_old,
	                   const Partition & partition_new,
	                   OperationDetail & operationdetail );
	bool resize_move_partition( const Partition & partition_old,
	                            const Partition & partition_new,
	                            OperationDetail & operationdetail,
	                            bool rollback_on_fail );
	bool resize_move_partition_implement( const Partition & partition_old,
	                                      const Partition & partition_new,
	                                      Sector & new_start,
	                                      Sector & new_end );
	bool shrink_encryption( const Partition & partition_old,
	                        const Partition & partition_new,
	                        OperationDetail & operationdetail );
	bool maximize_encryption( const Partition & partition,
	                          OperationDetail & operationdetail );
	bool shrink_filesystem( const Partition & partition_old,
	                        const Partition & partition_new,
	                        OperationDetail & operationdetail );
	bool maximize_filesystem( const Partition & partition, OperationDetail & operationdetail ) ;
	bool recreate_linux_swap_filesystem( const Partition & partition,
	                                     OperationDetail & operationdetail );
	bool resize_filesystem_implement( const Partition & partition_old,
	                                  const Partition & partition_new,
	                                  OperationDetail & operationdetail );

	bool copy( const Partition & partition_src,
	           Partition & partition_dst,
	           OperationDetail & operationdetail );
	bool copy_filesystem( const Partition & partition_src,
	                      Partition & partition_dst,
	                      OperationDetail & operationdetail );
	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 );
	void rollback_move_filesystem( const Partition & partition_src,
	                               const Partition & partition_dst,
	                               OperationDetail & operationdetail,
	                               Byte_Value total_done );

	bool check_repair_filesystem( const Partition & partition, OperationDetail & operationdetail ) ;
	bool check_repair_maximize( const Partition & partition,
	                            OperationDetail & operationdetail );

	bool set_partition_type( const Partition & partition, OperationDetail & operationdetail ) ;

	bool calibrate_partition( Partition & partition, OperationDetail & operationdetail ) ;
	bool calculate_exact_geom( const Partition & partition_old,
			           Partition & partition_new,
				   OperationDetail & operationdetail ) ;
	bool update_dmraid_entry( const Partition & partition_new, OperationDetail & operationdetail );
	bool erase_filesystem_signatures( const Partition & partition, OperationDetail & operationdetail ) ;
	bool update_bootsector( const Partition & partition, OperationDetail & operationdetail ) ;

	//general..	
	void capture_libparted_messages( OperationDetail & operationdetail, bool success );

	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);
	static bool get_device_and_disk(const Glib::ustring& device_path,
	                                PedDevice*& lp_device, PedDisk*& lp_disk, 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 );
	static bool useable_device(const PedDevice* lp_device);
	static PedPartition* get_lp_partition( const PedDisk* lp_disk, const Partition & partition );

	static PedExceptionOption ped_exception_handler( PedException * e ) ;

	std::vector<PedPartitionFlag> flags;
	std::vector<Glib::ustring> device_paths ;
	bool probe_devices ;
	Glib::ustring thread_status_message;  //Used to pass data to show_pulsebar method
	static SupportedFileSystems* supported_filesystems;
};

} //GParted

#endif /* GPARTED_GPARTED_CORE_H */