xref: /haiku/headers/private/storage/Partition.h (revision 323b65468e5836bb27a5e373b14027d902349437)
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 
16 class BBitmap;
17 class BDiskDevice;
18 class BPartitionParameterEditor;
19 class BDiskDeviceVisitor;
20 class BDiskSystem;
21 class BMutablePartition;
22 template <class T> class BObjectList;
23 class BPartitioningInfo;
24 class BPath;
25 class BVolume;
26 struct user_partition_data;
27 
28 
29 namespace BPrivate {
30 	class DiskDeviceJobGenerator;
31 }
32 
33 class BPartition {
34 public:
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 			dev_t				Mount(const char* mountPoint = NULL,
72 									uint32 mountFlags = 0,
73 									const char* parameters = NULL);
74 			status_t			Unmount(uint32 unmountFlags = 0);
75 
76 	// Hierarchy Info
77 
78 			BDiskDevice*		Device() const;
79 			BPartition*			Parent() const;
80 			BPartition*			ChildAt(int32 index) const;
81 			int32				CountChildren() const;
82 			int32				CountDescendants() const;
83 			BPartition*			FindDescendant(partition_id id) const;
84 
85 			status_t			GetPartitioningInfo(
86 									BPartitioningInfo* info) const;
87 
88 			BPartition*			VisitEachChild(BDiskDeviceVisitor* visitor)
89 									const;
90 	virtual BPartition*			VisitEachDescendant(
91 									BDiskDeviceVisitor* visitor) const;
92 
93 	// Self Modification
94 
95 			bool				CanDefragment(bool* whileMounted = NULL) const;
96 			status_t			Defragment() const;
97 
98 			bool				CanRepair(bool checkOnly,
99 									bool* whileMounted = NULL) const;
100 			status_t			Repair(bool checkOnly) const;
101 
102 			bool				CanResize(bool* canResizeContents = NULL,
103 									bool* whileMounted = NULL) const;
104 			status_t			ValidateResize(off_t* size) const;
105 			status_t			Resize(off_t size);
106 
107 			bool				CanMove(BObjectList<BPartition>*
108 										unmovableDescendants = NULL,
109 									BObjectList<BPartition>*
110 										movableOnlyIfUnmounted = NULL) const;
111 			status_t			ValidateMove(off_t* newOffset) const;
112 			status_t			Move(off_t newOffset);
113 
114 			bool				CanSetName() const;
115 			status_t			ValidateSetName(BString* name) const;
116 									// adjusts name to be suitable
117 			status_t			SetName(const char* name);
118 
119 			bool				CanSetContentName(
120 									bool* whileMounted = NULL) const;
121 			status_t			ValidateSetContentName(BString* name) const;
122 									// adjusts name to be suitable
123 			status_t			SetContentName(const char* name);
124 
125 			bool				CanSetType() const;
126 			status_t			ValidateSetType(const char* type) const;
127 									// type must be one the parent disk system's
128 									// GetNextSupportedType() returns.
129 			status_t			SetType(const char* type);
130 
131 			bool				CanEditParameters() const;
132 			status_t			GetParameterEditor(
133 									B_PARAMETER_EDITOR_TYPE type,
134 									BPartitionParameterEditor** editor);
135 			status_t			SetParameters(const char* parameters);
136 
137 			bool				CanEditContentParameters(
138 									bool* whileMounted = NULL) const;
139 			status_t			SetContentParameters(const char* parameters);
140 
141 			status_t			GetNextSupportedType(int32 *cookie,
142 									BString* type) const;
143 									// Returns all partition types for this
144 									// partition supported by the parent disk
145 									// system.
146 			status_t			GetNextSupportedChildType(int32 *cookie,
147 									BString* type) const;
148 									// Returns all partition types for a child
149 									// of this partition supported by its disk
150 									// system.
151 			bool				IsSubSystem(const char* diskSystem) const;
152 
153 			bool				CanInitialize(const char* diskSystem) const;
154 			status_t			ValidateInitialize(const char* diskSystem,
155 									BString* name, const char* parameters);
156 			status_t			Initialize(const char* diskSystem,
157 									const char* name, const char* parameters);
158 			status_t			Uninitialize();
159 
160 	// Modification of child partitions
161 
162 			bool				CanCreateChild() const;
163 			status_t			ValidateCreateChild(off_t* start, off_t* size,
164 									const char* type, BString* name,
165 									const char* parameters) const;
166 			status_t			CreateChild(off_t start, off_t size,
167 									const char* type, const char* name,
168 									const char* parameters,
169 									BPartition** child = NULL);
170 
171 			bool				CanDeleteChild(int32 index) const;
172 			status_t			DeleteChild(int32 index);
173 
174 			bool				SupportsChildName() const;
175 
176 private:
177 			class Delegate;
178 
179 								BPartition();
180 								BPartition(const BPartition&);
181 	virtual						~BPartition();
182 
183 			BPartition&			operator=(const BPartition&);
184 
185 			status_t			_SetTo(BDiskDevice* device, BPartition* parent,
186 									user_partition_data* data);
187 			void				_Unset();
188 			status_t			_RemoveObsoleteDescendants(
189 									user_partition_data* data, bool* updated);
190 			status_t			_Update(user_partition_data* data,
191 									bool* updated);
192 			void				_RemoveChild(int32 index);
193 
194 			BPartition*			_ChildAt(int32 index) const;
195 			int32				_CountChildren() const;
196 			int32				_CountDescendants() const;
197 
198 			int32				_Level() const;
199 			virtual	bool		_AcceptVisitor(BDiskDeviceVisitor* visitor,
200 									int32 level);
201 			BPartition*			_VisitEachDescendant(
202 									BDiskDeviceVisitor* visitor,
203 									int32 level = -1);
204 
205 			const user_partition_data* _PartitionData() const;
206 
207 			bool				_HasContent() const;
208 			bool				_SupportsOperation(uint32 flag,
209 									uint32 whileMountedFlag,
210 									bool* whileMounted) const;
211 			bool				_SupportsChildOperation(const BPartition* child,
212 									uint32 flag) const;
213 
214 			status_t			_CreateDelegates();
215 			status_t			_InitDelegates();
216 			void				_DeleteDelegates();
217 			bool				_IsModified() const;
218 
219 			friend class BDiskDevice;
220 			friend class BDiskSystem;
221 			friend class BMutablePartition;
222 			friend class BPrivate::DiskDeviceJobGenerator;
223 
224 			BDiskDevice*		fDevice;
225 			BPartition*			fParent;
226 			user_partition_data* fPartitionData;
227 			Delegate*			fDelegate;
228 };
229 
230 
231 #endif	// _PARTITION_H
232