File: Partition.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 (198 lines) | stat: -rw-r--r-- 8,112 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
/* Copyright (C) 2004 Bart
 * Copyright (C) 2008, 2009, 2010 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/>.
 */
 
 /* READ THIS!!
  * Partition isn't really a partition. It's more like a geometry, a continuous part of the disk. 
  * I use it to represent partitions as well as unallocated spaces
  */

#ifndef GPARTED_PARTITION_H
#define GPARTED_PARTITION_H

#include "Utils.h"
#include "PartitionVector.h"

#include <glibmm/ustring.h>

namespace GParted
{
	

enum PartitionType {
	TYPE_PRIMARY       = 0,  // Primary partition on a partitioned drive
	TYPE_LOGICAL       = 1,  // Logical partition on a partitioned drive
	TYPE_EXTENDED      = 2,  // Extended partition on a partitioned drive
	TYPE_UNALLOCATED   = 3,  // Unallocated space on a partitioned drive
	TYPE_UNPARTITIONED = 4   // Unpartitioned whole drive
};


enum PartitionStatus {
	STAT_REAL = 0,  // All other cases.  Read from drive or composed by all other operations
	STAT_NEW  = 1,  // Composed by the Create New dialog, but not yet applied
	STAT_COPY = 2   // Composed by the Paste into New dialog, but not yet applied
};


enum PartitionAlignment {
	ALIGN_CYLINDER = 0,    //Align to nearest cylinder
	ALIGN_MEBIBYTE = 1,    //Align to nearest mebibyte
	ALIGN_STRICT   = 2     //Strict alignment - no rounding
	                       //  Indicator if start and end sectors must remain unchanged
};

class Partition;        // Forward declarations as Partition and PartitionVector are
class PartitionVector;  // mutually recursive classes.
                        // References:
                        // *   Mutually recursive classes
                        //     http://stackoverflow.com/questions/3410637/mutually-recursive-classes
                        // *   recursive definition in CPP
                        //     http://stackoverflow.com/questions/4300420/recursive-definition-in-cpp

class Partition
{
public:
	Partition() ;
	virtual ~Partition();
	virtual Partition * clone() const;

	void Reset() ;
	
	//simple Set-functions.  only for convenience, since most members are public
	void Set( const Glib::ustring & device_path,
	          const Glib::ustring & partition,
	          int partition_number,
	          PartitionType type,
	          FSType fstype,
	          Sector sector_start,
	          Sector sector_end,
	          Byte_Value sector_size,
	          bool inside_extended,
	          bool busy );

	void set_sector_usage( Sector sectors_fs_size, Sector sectors_fs_unused ) ;
	virtual bool sector_usage_known() const;
	virtual Sector estimated_min_size() const;
	virtual Sector get_sectors_used() const;
	virtual Sector get_sectors_unused() const;
	virtual Sector get_sectors_unallocated() const;
	void get_usage_triple( int imax, int & i1, int & i2, int & i3 ) const ;
	virtual void resize( const Partition & new_size );

	void Set_Unallocated( const Glib::ustring & device_path,
	                      Sector sector_start,
	                      Sector sector_end,
	                      Byte_Value sector_size,
	                      bool inside_extended );
	void set_unpartitioned( const Glib::ustring & device_path,
	                        const Glib::ustring & partition_path,
	                        FSType fstype,
	                        Sector length,
	                        Byte_Value sector_size,
	                        bool busy );

	//update partition number (used when a logical partition is deleted) 
	void Update_Number( int new_number );
	
	void set_path( const Glib::ustring & path );
	Byte_Value get_byte_length() const ;
	Sector get_sector_length() const ; 
	const Glib::ustring& get_path() const;
	void add_mountpoint( const Glib::ustring & mountpoint );
	void add_mountpoints( const std::vector<Glib::ustring> & mountpoints );
	const Glib::ustring& get_mountpoint() const;
	void clear_mountpoints() ;
	const std::vector<Glib::ustring>& get_mountpoints() const;
	Sector get_sector() const ;
	bool test_overlap( const Partition & partition ) const ;
	bool filesystem_label_known() const;
	const Glib::ustring& get_filesystem_label() const;
	void set_filesystem_label( const Glib::ustring & filesystem_label );

	// Message accessors.  Messages are stored locally and accessed globally.
	// Stored locally means the messages are stored in the Partition object to which
	// they are added so push_back_messages() and append_messages() are non-virtual.
	// Accessed globally means that in the case of derived objects which are composed
	// of more that one Partition object, i.e. PartitionLUKS, the messages have to be
	// accessible from all copies within the derived object hierarchy.  Hence
	// have_messages(), get_messages() and clear_messages() are virtual to allow for
	// overridden implementations.
	virtual bool have_messages() const                             { return ! messages.empty(); };
	virtual std::vector<Glib::ustring> get_messages() const        { return messages; };
	virtual void clear_messages()                                  { messages.clear(); };
	void push_back_message(const Glib::ustring& msg)               { messages.push_back(msg); };
	void append_messages(const std::vector<Glib::ustring>& msgs)
	                                { messages.insert( messages.end(), msgs.begin(), msgs.end() ); }

	// Interface to return reference to the Partition object directly containing the
	// file system.  Will be overridden in derived PartitionLUKS.
	virtual const Partition & get_filesystem_partition() const     { return *this; };
	virtual Partition & get_filesystem_partition()                 { return *this; };

	virtual const Glib::ustring get_filesystem_string() const
	                                { return Utils::get_filesystem_string(fstype); };

	bool operator==( const Partition & partition ) const ;
	bool operator!=( const Partition & partition ) const ;

	static const Glib::ustring get_partition_type_string(PartitionType type);

	//some public members
	Glib::ustring device_path ;
	int partition_number;
	PartitionType type;// UNALLOCATED, PRIMARY, LOGICAL, etc...
	PartitionStatus status; //STAT_REAL, STAT_NEW, etc..
	PartitionAlignment alignment;   //ALIGN_CYLINDER, ALIGN_STRICT, etc
	FSType fstype;
	Glib::ustring uuid ;
	Glib::ustring name;
	Sector sector_start;
	Sector sector_end;
	Sector sectors_used;
	Sector sectors_unused;
	Sector sectors_unallocated;  //Difference between the size of the partition and the file system
	Sector significant_threshold;  //Threshold from intrinsic to significant unallocated sectors
	bool inside_extended;
	bool busy;
	bool fs_readonly;  // Is the file system mounted read-only?
	std::vector<Glib::ustring> flags ;

	PartitionVector logicals;

	bool strict_start ;	//Indicator if start sector must stay unchanged
	Sector free_space_before ;  //Free space preceding partition value

	Byte_Value sector_size ;  //Sector size of the disk device needed for converting to/from sectors and bytes.
	Byte_Value fs_block_size;  // Block size of of the file system, or -1 when unknown.

private:
	Partition & operator=( Partition & rhs );  // Not implemented copy assignment operator

	static void get_usage_triple_helper( Sector stot, Sector s1, Sector s2, Sector s3, int imax, int & i1, int & i2, int & i3 ) ;

	Sector calc_significant_unallocated_sectors() const ;

	Glib::ustring path;
	std::vector<Glib::ustring> mountpoints ;
	bool have_filesystem_label;
	Glib::ustring filesystem_label;
	std::vector<Glib::ustring> messages;
};

}//GParted

#endif /* GPARTED_PARTITION_H */