1 // KDiskSystem.cpp 2 3 #include <stdio.h> 4 #include <stdlib.h> 5 6 #include <KernelExport.h> 7 #include <util/kernel_cpp.h> 8 9 #include "ddm_userland_interface.h" 10 #include "KDiskDeviceManager.h" 11 #include "KDiskDeviceUtils.h" 12 #include "KDiskSystem.h" 13 14 15 // debugging 16 //#define DBG(x) 17 #define DBG(x) x 18 #define OUT dprintf 19 20 21 // constructor 22 KDiskSystem::KDiskSystem(const char *name) 23 : fID(_NextID()), 24 fName(NULL), 25 fPrettyName(NULL), 26 fLoadCounter(0) 27 { 28 set_string(fName, name); 29 } 30 31 32 // destructor 33 KDiskSystem::~KDiskSystem() 34 { 35 free(fName); 36 } 37 38 39 // Init 40 status_t 41 KDiskSystem::Init() 42 { 43 return (fName ? B_OK : B_NO_MEMORY); 44 } 45 46 47 // SetID 48 /*void 49 KDiskSystem::SetID(disk_system_id id) 50 { 51 fID = id; 52 }*/ 53 54 55 // ID 56 disk_system_id 57 KDiskSystem::ID() const 58 { 59 return fID; 60 } 61 62 63 // Name 64 const char * 65 KDiskSystem::Name() const 66 { 67 return fName; 68 } 69 70 71 // PrettyName 72 const char * 73 KDiskSystem::PrettyName() 74 { 75 return fPrettyName; 76 } 77 78 79 // Flags 80 uint32 81 KDiskSystem::Flags() const 82 { 83 return fFlags; 84 } 85 86 87 // IsFileSystem 88 bool 89 KDiskSystem::IsFileSystem() const 90 { 91 return (fFlags & B_DISK_SYSTEM_IS_FILE_SYSTEM); 92 } 93 94 95 // IsPartitioningSystem 96 bool 97 KDiskSystem::IsPartitioningSystem() const 98 { 99 return !(fFlags & B_DISK_SYSTEM_IS_FILE_SYSTEM); 100 } 101 102 103 // GetInfo 104 void 105 KDiskSystem::GetInfo(user_disk_system_info *info) 106 { 107 if (!info) 108 return; 109 info->id = ID(); 110 strcpy(info->name, Name()); 111 strcpy(info->pretty_name, PrettyName()); 112 info->flags = Flags(); 113 } 114 115 116 // Load 117 status_t 118 KDiskSystem::Load() 119 { 120 ManagerLocker locker(KDiskDeviceManager::Default()); 121 dprintf("KDiskSystem::Load(): %s -> %ld\n", Name(), fLoadCounter + 1); 122 status_t error = B_OK; 123 if (fLoadCounter == 0) 124 error = LoadModule(); 125 if (error == B_OK) 126 fLoadCounter++; 127 return error; 128 } 129 130 131 // Unload 132 void 133 KDiskSystem::Unload() 134 { 135 ManagerLocker locker(KDiskDeviceManager::Default()); 136 dprintf("KDiskSystem::Unload(): %s -> %ld\n", Name(), fLoadCounter - 1); 137 if (fLoadCounter > 0 && --fLoadCounter == 0) 138 UnloadModule(); 139 } 140 141 142 // IsLoaded 143 bool 144 KDiskSystem::IsLoaded() const 145 { 146 ManagerLocker locker(KDiskDeviceManager::Default()); 147 return (fLoadCounter > 0); 148 } 149 150 151 // Identify 152 float 153 KDiskSystem::Identify(KPartition *partition, void **cookie) 154 { 155 // to be implemented by derived classes 156 return -1; 157 } 158 159 160 // Scan 161 status_t 162 KDiskSystem::Scan(KPartition *partition, void *cookie) 163 { 164 // to be implemented by derived classes 165 return B_ERROR; 166 } 167 168 169 // FreeIdentifyCookie 170 void 171 KDiskSystem::FreeIdentifyCookie(KPartition *partition, void *cookie) 172 { 173 // to be implemented by derived classes 174 } 175 176 177 // FreeCookie 178 void 179 KDiskSystem::FreeCookie(KPartition *partition) 180 { 181 // to be implemented by derived classes 182 } 183 184 185 // FreeContentCookie 186 void 187 KDiskSystem::FreeContentCookie(KPartition *partition) 188 { 189 // to be implemented by derived classes 190 } 191 192 193 // Defragment 194 status_t 195 KDiskSystem::Defragment(KPartition* partition, disk_job_id job) 196 { 197 // to be implemented by derived classes 198 return B_ERROR; 199 } 200 201 202 // Repair 203 status_t 204 KDiskSystem::Repair(KPartition* partition, bool checkOnly, disk_job_id job) 205 { 206 // to be implemented by derived classes 207 return B_ERROR; 208 } 209 210 211 // Resize 212 status_t 213 KDiskSystem::Resize(KPartition* partition, off_t size, disk_job_id job) 214 { 215 // to be implemented by derived classes 216 return B_ERROR; 217 } 218 219 220 // ResizeChild 221 status_t 222 KDiskSystem::ResizeChild(KPartition* child, off_t size, disk_job_id job) 223 { 224 // to be implemented by derived classes 225 return B_ERROR; 226 } 227 228 229 // Move 230 status_t 231 KDiskSystem::Move(KPartition* partition, off_t offset, disk_job_id job) 232 { 233 // to be implemented by derived classes 234 return B_ERROR; 235 } 236 237 238 // MoveChild 239 status_t 240 KDiskSystem::MoveChild(KPartition* child, off_t offset, disk_job_id job) 241 { 242 // to be implemented by derived classes 243 return B_ERROR; 244 } 245 246 247 // SetName 248 status_t 249 KDiskSystem::SetName(KPartition* partition, const char* name, disk_job_id job) 250 { 251 // to be implemented by derived classes 252 return B_ERROR; 253 } 254 255 256 // SetContentName 257 status_t 258 KDiskSystem::SetContentName(KPartition* partition, const char* name, 259 disk_job_id job) 260 { 261 // to be implemented by derived classes 262 return B_ERROR; 263 } 264 265 266 // SetType 267 status_t 268 KDiskSystem::SetType(KPartition* partition, const char *type, disk_job_id job) 269 { 270 // to be implemented by derived classes 271 return B_ERROR; 272 } 273 274 275 // SetParameters 276 status_t 277 KDiskSystem::SetParameters(KPartition* partition, const char* parameters, 278 disk_job_id job) 279 { 280 // to be implemented by derived classes 281 return B_ERROR; 282 } 283 284 285 // SetContentParameters 286 status_t 287 KDiskSystem::SetContentParameters(KPartition* partition, 288 const char* parameters, disk_job_id job) 289 { 290 // to be implemented by derived classes 291 return B_ERROR; 292 } 293 294 295 // Initialize 296 status_t 297 KDiskSystem::Initialize(KPartition* partition, const char* name, 298 const char* parameters, disk_job_id job) 299 { 300 // to be implemented by derived classes 301 return B_ERROR; 302 } 303 304 305 // CreateChild 306 status_t 307 KDiskSystem::CreateChild(KPartition* partition, off_t offset, off_t size, 308 const char* type, const char* name, const char* parameters, disk_job_id job, 309 KPartition **child, partition_id childID) 310 { 311 // to be implemented by derived classes 312 return B_ERROR; 313 } 314 315 316 // DeleteChild 317 status_t 318 KDiskSystem::DeleteChild(KPartition* child, disk_job_id job) 319 { 320 // to be implemented by derived classes 321 return B_ERROR; 322 } 323 324 325 // LoadModule 326 status_t 327 KDiskSystem::LoadModule() 328 { 329 // to be implemented by derived classes 330 return B_ERROR; 331 } 332 333 334 // UnloadModule 335 void 336 KDiskSystem::UnloadModule() 337 { 338 // to be implemented by derived classes 339 } 340 341 342 // SetPrettyName 343 status_t 344 KDiskSystem::SetPrettyName(const char *name) 345 { 346 return set_string(fPrettyName, name); 347 } 348 349 350 // SetFlags 351 void 352 KDiskSystem::SetFlags(uint32 flags) 353 { 354 fFlags = flags; 355 } 356 357 358 // _NextID 359 int32 360 KDiskSystem::_NextID() 361 { 362 return atomic_add(&fNextID, 1); 363 } 364 365 366 // fNextID 367 int32 KDiskSystem::fNextID = 0; 368 369