1 /* 2 * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include "BFSAddOn.h" 7 8 #include <new> 9 10 #include <List.h> 11 12 #include <DiskDeviceTypes.h> 13 #include <MutablePartition.h> 14 15 #include <AutoDeleter.h> 16 17 #include "bfs.h" 18 #include "bfs_disk_system.h" 19 20 21 using std::nothrow; 22 23 24 static const uint32 kDiskSystemFlags = 25 0 26 // | B_DISK_SYSTEM_SUPPORTS_CHECKING 27 // | B_DISK_SYSTEM_SUPPORTS_REPAIRING 28 // | B_DISK_SYSTEM_SUPPORTS_RESIZING 29 // | B_DISK_SYSTEM_SUPPORTS_MOVING 30 // | B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME 31 // | B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS 32 | B_DISK_SYSTEM_SUPPORTS_INITIALIZING 33 | B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME 34 // | B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING 35 // | B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED 36 // | B_DISK_SYSTEM_SUPPORTS_CHECKING_WHILE_MOUNTED 37 // | B_DISK_SYSTEM_SUPPORTS_REPAIRING_WHILE_MOUNTED 38 // | B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED 39 // | B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED 40 // | B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED 41 // | B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED 42 ; 43 44 45 // #pragma mark - BFSAddOn 46 47 48 // constructor 49 BFSAddOn::BFSAddOn() 50 : BDiskSystemAddOn(kPartitionTypeBFS, kDiskSystemFlags) 51 { 52 } 53 54 55 // destructor 56 BFSAddOn::~BFSAddOn() 57 { 58 } 59 60 61 // CreatePartitionHandle 62 status_t 63 BFSAddOn::CreatePartitionHandle(BMutablePartition* partition, 64 BPartitionHandle** _handle) 65 { 66 BFSPartitionHandle* handle = new(nothrow) BFSPartitionHandle(partition); 67 if (!handle) 68 return B_NO_MEMORY; 69 70 status_t error = handle->Init(); 71 if (error != B_OK) { 72 delete handle; 73 return error; 74 } 75 76 *_handle = handle; 77 return B_OK; 78 } 79 80 81 // CanInitialize 82 bool 83 BFSAddOn::CanInitialize(const BMutablePartition* partition) 84 { 85 // TODO: Check partition size. 86 return true; 87 } 88 89 90 // GetInitializationParameterEditor 91 status_t 92 BFSAddOn::GetInitializationParameterEditor(const BMutablePartition* partition, 93 BDiskDeviceParameterEditor** editor) 94 { 95 // TODO: Implement! 96 *editor = NULL; 97 return B_OK; 98 } 99 100 101 // ValidateInitialize 102 status_t 103 BFSAddOn::ValidateInitialize(const BMutablePartition* partition, BString* name, 104 const char* parameterString) 105 { 106 if (!CanInitialize(partition) || !name) 107 return B_BAD_VALUE; 108 109 // validate name 110 111 // truncate, if it is too long 112 if (name->Length() >= BFS_DISK_NAME_LENGTH) 113 name->Truncate(BFS_DISK_NAME_LENGTH - 1); 114 115 // replace '/' by '-' 116 name->ReplaceAll('/', '-'); 117 118 // check parameters 119 initialize_parameters parameters; 120 status_t error = parse_initialize_parameters(parameterString, parameters); 121 if (error != B_OK) 122 return error; 123 124 return B_OK; 125 } 126 127 128 // Initialize 129 status_t 130 BFSAddOn::Initialize(BMutablePartition* partition, const char* name, 131 const char* parameterString, BPartitionHandle** _handle) 132 { 133 if (!CanInitialize(partition) || check_volume_name(name) != B_OK) 134 return B_BAD_VALUE; 135 136 initialize_parameters parameters; 137 status_t error = parse_initialize_parameters(parameterString, parameters); 138 if (error != B_OK) 139 return error; 140 141 // create the handle 142 BFSPartitionHandle* handle = new(nothrow) BFSPartitionHandle(partition); 143 if (!handle) 144 return B_NO_MEMORY; 145 ObjectDeleter<BFSPartitionHandle> handleDeleter(handle); 146 147 // init the partition 148 error = partition->SetContentType(Name()); 149 if (error != B_OK) 150 return error; 151 // TODO: The content type could as well be set by the caller. 152 153 partition->SetContentName(name); 154 partition->SetContentParameters(parameterString); 155 uint32 blockSize = parameters.blockSize; 156 partition->SetBlockSize(blockSize); 157 partition->SetContentSize(partition->Size() / blockSize * blockSize); 158 partition->Changed(B_PARTITION_CHANGED_INITIALIZATION); 159 160 *_handle = handleDeleter.Detach(); 161 162 return B_OK; 163 } 164 165 166 // #pragma mark - BFSPartitionHandle 167 168 169 // constructor 170 BFSPartitionHandle::BFSPartitionHandle(BMutablePartition* partition) 171 : BPartitionHandle(partition) 172 { 173 } 174 175 176 // destructor 177 BFSPartitionHandle::~BFSPartitionHandle() 178 { 179 } 180 181 182 // Init 183 status_t 184 BFSPartitionHandle::Init() 185 { 186 // TODO: Check parameters. 187 return B_OK; 188 } 189 190 191 // #pragma mark - 192 193 194 // get_disk_system_add_ons 195 status_t 196 get_disk_system_add_ons(BList* addOns) 197 { 198 BFSAddOn* addOn = new(nothrow) BFSAddOn; 199 if (!addOn) 200 return B_NO_MEMORY; 201 202 if (!addOns->AddItem(addOn)) { 203 delete addOn; 204 return B_NO_MEMORY; 205 } 206 207 return B_OK; 208 } 209