btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / kernel / disk_device_manager / KPartition.h
blob577d23a893efe8c70dc41c4e354385c272fba728
1 /*
2 * Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ingo Weinhold <bonefish@cs.tu-berlin.de>
7 */
8 #ifndef _K_DISK_DEVICE_PARTITION_H
9 #define _K_DISK_DEVICE_PARTITION_H
11 #include <disk_device_manager.h>
12 #include <Vector.h>
14 struct user_partition_data;
16 namespace BPrivate {
17 namespace DiskDevice {
19 class UserDataWriter;
21 class KDiskDevice;
22 class KDiskSystem;
23 class KPartitionListener;
24 class KPartitionVisitor;
25 class KPath;
26 class KPhysicalPartition;
28 //! \brief Class representing a single partition.
29 class KPartition {
30 public:
31 KPartition(partition_id id = -1);
32 virtual ~KPartition();
34 // Reference counting. As long as there's at least one referrer, the
35 // object won't be deleted.
36 // manager must be locked (Unregister() locks itself)
37 void Register();
38 void Unregister();
39 int32 CountReferences() const;
41 void MarkObsolete();
42 // called by the manager only
43 bool IsObsolete() const;
45 virtual bool PrepareForRemoval();
46 virtual bool PrepareForDeletion();
48 virtual status_t Open(int flags, int *fd);
49 virtual status_t PublishDevice();
50 virtual status_t UnpublishDevice();
51 virtual status_t RepublishDevice();
52 bool IsPublished() const;
54 void SetBusy(bool busy);
55 bool IsBusy() const;
56 bool IsBusy(bool includeDescendants);
57 bool CheckAndMarkBusy(bool includeDescendants);
58 void MarkBusy(bool includeDescendants);
59 void UnmarkBusy(bool includeDescendants);
61 void SetOffset(off_t offset);
62 off_t Offset() const; // 0 for devices
64 void SetSize(off_t size);
65 off_t Size() const;
67 void SetContentSize(off_t size);
68 off_t ContentSize() const;
70 void SetBlockSize(uint32 blockSize);
71 uint32 BlockSize() const;
73 void SetIndex(int32 index);
74 int32 Index() const; // 0 for devices
76 void SetStatus(uint32 status);
77 uint32 Status() const;
78 bool IsUninitialized() const;
80 void SetFlags(uint32 flags); // comprises the ones below
81 void AddFlags(uint32 flags);
82 void ClearFlags(uint32 flags);
83 uint32 Flags() const;
84 bool ContainsFileSystem() const;
85 bool ContainsPartitioningSystem() const;
86 bool IsReadOnly() const;
87 bool IsMounted() const;
88 bool IsChildMounted();
90 bool IsDevice() const;
92 status_t SetName(const char *name);
93 const char *Name() const;
95 status_t SetContentName(const char *name);
96 const char *ContentName() const;
98 status_t SetType(const char *type);
99 const char *Type() const;
101 const char *ContentType() const;
102 // ContentType() == DiskSystem()->NamePretty()
104 // access to C style partition data
105 partition_data *PartitionData();
106 const partition_data *PartitionData() const;
108 virtual void SetID(partition_id id);
109 partition_id ID() const;
111 virtual status_t GetFileName(char* buffer, size_t size) const;
112 virtual status_t GetPath(KPath *path) const;
113 // no setter (see BDiskDevice) -- built on the fly
115 void SetVolumeID(dev_t volumeID);
116 dev_t VolumeID() const;
118 void SetMountCookie(void *cookie);
119 void *MountCookie() const;
121 virtual status_t Mount(uint32 mountFlags, const char *parameters);
122 virtual status_t Unmount();
124 // Parameters
126 status_t SetParameters(const char *parameters);
127 const char *Parameters() const;
129 status_t SetContentParameters(const char *parameters);
130 const char *ContentParameters() const;
132 // Hierarchy
134 void SetDevice(KDiskDevice *device);
135 KDiskDevice *Device() const;
137 void SetParent(KPartition *parent);
138 KPartition *Parent() const;
140 status_t AddChild(KPartition *partition, int32 index = -1);
141 status_t CreateChild(partition_id id, int32 index, off_t offset, off_t size,
142 KPartition **child = NULL);
143 bool RemoveChild(int32 index);
144 bool RemoveChild(KPartition *child);
145 bool RemoveAllChildren();
146 KPartition *ChildAt(int32 index) const;
147 int32 CountChildren() const;
148 int32 CountDescendants() const;
150 KPartition *VisitEachDescendant(KPartitionVisitor *visitor);
152 // DiskSystem
154 void SetDiskSystem(KDiskSystem *diskSystem, float priority = 0.0f);
155 KDiskSystem *DiskSystem() const;
156 float DiskSystemPriority() const;
157 KDiskSystem *ParentDiskSystem() const;
158 // When setting a disk system, it must already be loaded.
159 // The partition will load it too, hence it won't be unloaded before
160 // it is unset here.
162 void SetCookie(void *cookie);
163 void *Cookie() const;
165 void SetContentCookie(void *cookie);
166 void *ContentCookie() const;
168 // Listener Support
170 bool AddListener(KPartitionListener *listener);
171 bool RemoveListener(KPartitionListener *listener);
173 // Change Tracking
175 void Changed(uint32 flags, uint32 clearFlags = 0);
176 void SetChangeFlags(uint32 flags);
177 uint32 ChangeFlags() const;
178 int32 ChangeCounter() const;
179 status_t UninitializeContents(bool logChanges = true);
181 void SetAlgorithmData(uint32 data);
182 uint32 AlgorithmData() const;
183 // temporary storage freely usable by algorithms
185 virtual void WriteUserData(UserDataWriter &writer,
186 user_partition_data *data);
188 virtual void Dump(bool deep, int32 level);
190 protected:
191 void FireOffsetChanged(off_t offset);
192 void FireSizeChanged(off_t size);
193 void FireContentSizeChanged(off_t size);
194 void FireBlockSizeChanged(uint32 blockSize);
195 void FireIndexChanged(int32 index);
196 void FireStatusChanged(uint32 status);
197 void FireFlagsChanged(uint32 flags);
198 void FireNameChanged(const char *name);
199 void FireContentNameChanged(const char *name);
200 void FireTypeChanged(const char *type);
201 void FireIDChanged(partition_id id);
202 void FireVolumeIDChanged(dev_t volumeID);
203 void FireMountCookieChanged(void *cookie);
204 void FireParametersChanged(const char *parameters);
205 void FireContentParametersChanged(const char *parameters);
206 void FireChildAdded(KPartition *child, int32 index);
207 void FireChildRemoved(KPartition *child, int32 index);
208 void FireDiskSystemChanged(KDiskSystem *diskSystem);
209 void FireCookieChanged(void *cookie);
210 void FireContentCookieChanged(void *cookie);
212 private:
213 void _UpdateChildIndices(int32 start, int32 end);
214 static int32 _NextID();
216 protected:
217 typedef Vector<KPartition*> PartitionVector;
218 struct ListenerSet;
220 partition_data fPartitionData;
221 PartitionVector fChildren;
222 KDiskDevice *fDevice;
223 KPartition *fParent;
224 KDiskSystem *fDiskSystem;
225 float fDiskSystemPriority;
226 ListenerSet *fListeners;
227 uint32 fChangeFlags;
228 int32 fChangeCounter;
229 uint32 fAlgorithmData;
230 int32 fReferenceCount;
231 bool fObsolete;
232 char *fPublishedName;
233 static int32 sNextID;
236 } // namespace DiskDevice
237 } // namespace BPrivate
239 using BPrivate::DiskDevice::KPartition;
241 #endif // _K_DISK_DEVICE_PARTITION_H