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