1 //---------------------------------------------------------------------- 2 // This software is part of the Haiku distribution and is covered 3 // by the MIT license. 4 //--------------------------------------------------------------------- 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 class BBitmap; 15 class BDiskDevice; 16 class BDiskDeviceParameterEditor; 17 class BDiskDeviceVisitor; 18 class BDiskSystem; 19 class BPartitioningInfo; 20 class BPath; 21 class BVolume; 22 struct user_partition_data; 23 24 class BPartition { 25 public: 26 // Partition Info 27 28 off_t Offset() const; // 0 for devices 29 off_t Size() const; 30 off_t ContentSize() const; // 0 if uninitialized 31 uint32 BlockSize() const; 32 int32 Index() const; // 0 for devices 33 uint32 Status() const; 34 35 bool ContainsFileSystem() const; 36 bool ContainsPartitioningSystem() const; 37 38 bool IsDevice() const; 39 bool IsReadOnly() const; 40 bool IsMounted() const; 41 bool IsBusy() const; 42 43 uint32 Flags() const; 44 45 const char *Name() const; 46 const char *ContentName() const; 47 const char *Type() const; // See DiskDeviceTypes.h 48 const char *ContentType() const; // See DiskDeviceTypes.h 49 partition_id ID() const; 50 51 status_t GetDiskSystem(BDiskSystem *diskSystem) const; 52 53 virtual status_t GetPath(BPath *path) const; 54 status_t GetVolume(BVolume *volume) const; 55 status_t GetIcon(BBitmap *icon, icon_size which) const; 56 status_t GetMountPoint(BPath *mountPoint) const; 57 58 dev_t Mount(const char *mountPoint = NULL, uint32 mountFlags = 0, 59 const char *parameters = NULL); 60 status_t Unmount(uint32 unmountFlags = 0); 61 62 // Hierarchy Info 63 64 BDiskDevice *Device() const; 65 BPartition *Parent() const; 66 BPartition *ChildAt(int32 index) const; 67 int32 CountChildren() const; 68 BPartition *FindDescendant(partition_id id) const; 69 70 status_t GetPartitioningInfo(BPartitioningInfo *info) const; 71 72 BPartition *VisitEachChild(BDiskDeviceVisitor *visitor); 73 virtual BPartition *VisitEachDescendant(BDiskDeviceVisitor *visitor); 74 75 // Self Modification 76 77 bool CanDefragment(bool *whileMounted = NULL) const; 78 status_t Defragment() const; 79 80 bool CanRepair(bool checkOnly, bool *whileMounted = NULL) const; 81 status_t Repair(bool checkOnly) const; 82 83 bool CanResize(bool *canResizeContents = NULL, 84 bool *whileMounted = NULL) const; 85 status_t ValidateResize(off_t *size) const; 86 status_t Resize(off_t size); 87 88 bool CanMove(BObjectList<BPartition> *unmovableDescendants = NULL, 89 BObjectList<BPartition> *movableOnlyIfUnmounted = NULL) const; 90 status_t ValidateMove(off_t *newOffset) const; 91 status_t Move(off_t newOffset); 92 93 bool CanSetName() const; 94 status_t ValidateSetName(char *name) const; 95 // adjusts name to be suitable 96 status_t SetName(const char *name); 97 98 bool CanSetContentName(bool *whileMounted = NULL) const; 99 status_t ValidateSetContentName(char *name) const; 100 // adjusts name to be suitable 101 status_t SetContentName(const char *name); 102 103 bool CanSetType() const; 104 status_t ValidateSetType(const char *type) const; 105 // type must be one the parent disk system's GetNextSupportedType() 106 // returns. 107 status_t SetType(const char *type); 108 109 bool CanEditParameters() const; 110 status_t GetParameterEditor(BDiskDeviceParameterEditor **editor); 111 status_t SetParameters(const char *parameters); 112 113 bool CanEditContentParameters(bool *whileMounted = NULL) const; 114 status_t GetContentParameterEditor(BDiskDeviceParameterEditor **editor); 115 status_t SetContentParameters(const char *parameters); 116 117 bool CanInitialize(const char *diskSystem) const; 118 status_t GetInitializationParameterEditor(const char *system, 119 BDiskDeviceParameterEditor **editor) const; 120 status_t ValidateInitialize(const char *diskSystem, char *name, 121 const char *parameters); 122 status_t Initialize(const char *diskSystem, const char *name, 123 const char *parameters); 124 status_t Uninitialize(); 125 126 // Modification of child partitions 127 128 bool CanCreateChild() const; 129 status_t GetChildCreationParameterEditor(const char *system, 130 BDiskDeviceParameterEditor **editor) const; 131 status_t ValidateCreateChild(off_t *start, off_t *size, 132 const char *type, const char *parameters) const; 133 status_t CreateChild(off_t start, off_t size, const char *type, 134 const char *parameters, BPartition **child = NULL); 135 136 bool CanDeleteChild(int32 index) const; 137 status_t DeleteChild(int32 index); 138 139 private: 140 BPartition(); 141 BPartition(const BPartition &); 142 virtual ~BPartition(); 143 BPartition & operator=(const BPartition &); 144 145 status_t _SetTo(BDiskDevice *device, BPartition *parent, 146 user_partition_data *data); 147 void _Unset(); 148 status_t _RemoveObsoleteDescendants(user_partition_data *data, 149 bool *updated); 150 status_t _Update(user_partition_data *data, bool *updated); 151 void _RemoveChild(int32 index); 152 153 bool _IsShadow() const; 154 partition_id _ShadowID() const; 155 disk_system_id _DiskSystem() const; 156 int32 _ChangeCounter() const; 157 158 int32 _CountDescendants() const; 159 int32 _Level() const; 160 virtual bool _AcceptVisitor(BDiskDeviceVisitor *visitor, int32 level); 161 BPartition *_VisitEachDescendant(BDiskDeviceVisitor *visitor, 162 int32 level = -1); 163 164 friend class BDiskDevice; 165 friend class BDiskSystem; 166 167 BDiskDevice *fDevice; 168 BPartition *fParent; 169 user_partition_data *fPartitionData; 170 }; 171 172 #endif // _PARTITION_H 173