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