2 * Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <bonefish@cs.tu-berlin.de>
8 #ifndef _K_DISK_DEVICE_PARTITION_H
9 #define _K_DISK_DEVICE_PARTITION_H
11 #include <disk_device_manager.h>
14 struct user_partition_data
;
17 namespace DiskDevice
{
23 class KPartitionListener
;
24 class KPartitionVisitor
;
26 class KPhysicalPartition
;
28 //! \brief Class representing a single partition.
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)
39 int32
CountReferences() const;
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
);
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
);
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
);
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();
126 status_t
SetParameters(const char *parameters
);
127 const char *Parameters() const;
129 status_t
SetContentParameters(const char *parameters
);
130 const char *ContentParameters() const;
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
);
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
162 void SetCookie(void *cookie
);
163 void *Cookie() const;
165 void SetContentCookie(void *cookie
);
166 void *ContentCookie() const;
170 bool AddListener(KPartitionListener
*listener
);
171 bool RemoveListener(KPartitionListener
*listener
);
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
);
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
);
213 void _UpdateChildIndices(int32 start
, int32 end
);
214 static int32
_NextID();
217 typedef Vector
<KPartition
*> PartitionVector
;
220 partition_data fPartitionData
;
221 PartitionVector fChildren
;
222 KDiskDevice
*fDevice
;
224 KDiskSystem
*fDiskSystem
;
225 float fDiskSystemPriority
;
226 ListenerSet
*fListeners
;
228 int32 fChangeCounter
;
229 uint32 fAlgorithmData
;
230 int32 fReferenceCount
;
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