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