Partition.h revision 8bfb30ce
1/*
2 * Copyright 2003-2007, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2003, Tyler Akidau, haiku@akidau.net.
4 * Distributed under the terms of the MIT License.
5 */
6
7#ifndef _PARTITION_H
8#define _PARTITION_H
9
10
11#include <DiskDeviceDefs.h>
12#include <Messenger.h>
13#include <Mime.h>
14
15
16class BBitmap;
17class BDiskDevice;
18class BPartitionParameterEditor;
19class BDiskDeviceVisitor;
20class BDiskSystem;
21class BMutablePartition;
22template <class T> class BObjectList;
23class BPartitioningInfo;
24class BPath;
25class BVolume;
26struct user_partition_data;
27
28
29namespace BPrivate {
30	class DiskDeviceJobGenerator;
31}
32
33class BPartition {
34public:
35	// Partition Info
36
37			off_t				Offset() const;		// 0 for devices
38			off_t				Size() const;
39			off_t				ContentSize() const;	// 0 if uninitialized
40			uint32				BlockSize() const;
41			int32				Index() const;		// 0 for devices
42			uint32				Status() const;
43
44			bool				ContainsFileSystem() const;
45			bool				ContainsPartitioningSystem() const;
46
47			bool				IsDevice() const;
48			bool				IsReadOnly() const;
49			bool				IsMounted() const;
50			bool				IsBusy() const;
51
52			uint32				Flags() const;
53
54			const char*			Name() const;
55			const char*			ContentName() const;
56			const char*			Type() const;			// See DiskDeviceTypes.h
57			const char*			ContentType() const;	// See DiskDeviceTypes.h
58			partition_id		ID() const;
59			const char*			Parameters() const;
60			const char*			ContentParameters() const;
61
62			status_t			GetDiskSystem(BDiskSystem* diskSystem) const;
63
64	virtual	status_t			GetPath(BPath* path) const;
65			status_t			GetVolume(BVolume* volume) const;
66			status_t			GetIcon(BBitmap* icon, icon_size which) const;
67			status_t			GetIcon(uint8** _data, size_t* _size,
68									type_code* _type) const;
69			status_t			GetMountPoint(BPath* mountPoint) const;
70
71			status_t			Mount(const char* mountPoint = NULL,
72									uint32 mountFlags = 0,
73									const char* parameters = NULL,
74									dev_t* devicePointer = NULL);
75			status_t			Unmount(uint32 unmountFlags = 0);
76
77	// Hierarchy Info
78
79			BDiskDevice*		Device() const;
80			BPartition*			Parent() const;
81			BPartition*			ChildAt(int32 index) const;
82			int32				CountChildren() const;
83			int32				CountDescendants() const;
84			BPartition*			FindDescendant(partition_id id) const;
85
86			status_t			GetPartitioningInfo(
87									BPartitioningInfo* info) const;
88
89			BPartition*			VisitEachChild(BDiskDeviceVisitor* visitor)
90									const;
91	virtual BPartition*			VisitEachDescendant(
92									BDiskDeviceVisitor* visitor) const;
93
94	// Self Modification
95
96			bool				CanDefragment(bool* whileMounted = NULL) const;
97			status_t			Defragment() const;
98
99			bool				CanRepair(bool checkOnly,
100									bool* whileMounted = NULL) const;
101			status_t			Repair(bool checkOnly) const;
102
103			bool				CanResize(bool* canResizeContents = NULL,
104									bool* whileMounted = NULL) const;
105			status_t			ValidateResize(off_t* size) const;
106			status_t			Resize(off_t size);
107
108			bool				CanMove(BObjectList<BPartition>*
109										unmovableDescendants = NULL,
110									BObjectList<BPartition>*
111										movableOnlyIfUnmounted = NULL) const;
112			status_t			ValidateMove(off_t* newOffset) const;
113			status_t			Move(off_t newOffset);
114
115			bool				CanSetName() const;
116			status_t			ValidateSetName(BString* name) const;
117									// adjusts name to be suitable
118			status_t			SetName(const char* name);
119
120			bool				CanSetContentName(
121									bool* whileMounted = NULL) const;
122			status_t			ValidateSetContentName(BString* name) const;
123									// adjusts name to be suitable
124			status_t			SetContentName(const char* name);
125
126			bool				CanSetType() const;
127			status_t			ValidateSetType(const char* type) const;
128									// type must be one the parent disk system's
129									// GetNextSupportedType() returns.
130			status_t			SetType(const char* type);
131
132			bool				CanEditParameters() const;
133			status_t			GetParameterEditor(
134									B_PARAMETER_EDITOR_TYPE type,
135									BPartitionParameterEditor** editor);
136			status_t			SetParameters(const char* parameters);
137
138			bool				CanEditContentParameters(
139									bool* whileMounted = NULL) const;
140			status_t			SetContentParameters(const char* parameters);
141
142			status_t			GetNextSupportedType(int32 *cookie,
143									BString* type) const;
144									// Returns all partition types for this
145									// partition supported by the parent disk
146									// system.
147			status_t			GetNextSupportedChildType(int32 *cookie,
148									BString* type) const;
149									// Returns all partition types for a child
150									// of this partition supported by its disk
151									// system.
152			bool				IsSubSystem(const char* diskSystem) const;
153
154			bool				CanInitialize(const char* diskSystem) const;
155			status_t			ValidateInitialize(const char* diskSystem,
156									BString* name, const char* parameters);
157			status_t			Initialize(const char* diskSystem,
158									const char* name, const char* parameters);
159			status_t			Uninitialize();
160
161	// Modification of child partitions
162
163			bool				CanCreateChild() const;
164			status_t			ValidateCreateChild(off_t* start, off_t* size,
165									const char* type, BString* name,
166									const char* parameters) const;
167			status_t			CreateChild(off_t start, off_t size,
168									const char* type, const char* name,
169									const char* parameters,
170									BPartition** child = NULL);
171
172			bool				CanDeleteChild(int32 index) const;
173			status_t			DeleteChild(int32 index);
174
175			bool				SupportsChildName() const;
176
177private:
178			class Delegate;
179
180								BPartition();
181								BPartition(const BPartition&);
182	virtual						~BPartition();
183
184			BPartition&			operator=(const BPartition&);
185
186			status_t			_SetTo(BDiskDevice* device, BPartition* parent,
187									user_partition_data* data);
188			void				_Unset();
189			status_t			_RemoveObsoleteDescendants(
190									user_partition_data* data, bool* updated);
191			status_t			_Update(user_partition_data* data,
192									bool* updated);
193			void				_RemoveChild(int32 index);
194
195			BPartition*			_ChildAt(int32 index) const;
196			int32				_CountChildren() const;
197			int32				_CountDescendants() const;
198
199			int32				_Level() const;
200			virtual	bool		_AcceptVisitor(BDiskDeviceVisitor* visitor,
201									int32 level);
202			BPartition*			_VisitEachDescendant(
203									BDiskDeviceVisitor* visitor,
204									int32 level = -1);
205
206			const user_partition_data* _PartitionData() const;
207
208			bool				_HasContent() const;
209			bool				_SupportsOperation(uint32 flag,
210									uint32 whileMountedFlag,
211									bool* whileMounted) const;
212			bool				_SupportsChildOperation(const BPartition* child,
213									uint32 flag) const;
214
215			status_t			_CreateDelegates();
216			status_t			_InitDelegates();
217			void				_DeleteDelegates();
218			bool				_IsModified() const;
219
220			friend class BDiskDevice;
221			friend class BDiskSystem;
222			friend class BMutablePartition;
223			friend class BPrivate::DiskDeviceJobGenerator;
224
225			BDiskDevice*		fDevice;
226			BPartition*			fParent;
227			user_partition_data* fPartitionData;
228			Delegate*			fDelegate;
229};
230
231
232#endif	// _PARTITION_H
233