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