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