2 * Copyright 2003-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
10 #include <KernelExport.h>
11 #include <util/kernel_cpp.h>
13 #include "ddm_userland_interface.h"
14 #include "KDiskDeviceManager.h"
15 #include "KDiskDeviceUtils.h"
16 #include "KDiskSystem.h"
20 //#define TRACE_KDISK_SYSTEM
21 #ifdef TRACE_KDISK_SYSTEM
22 # define TRACE(x...) dprintf(x)
24 # define TRACE(x...) do { } while (false)
29 KDiskSystem::KDiskSystem(const char *name
)
36 set_string(fName
, name
);
41 KDiskSystem::~KDiskSystem()
53 return fName
? B_OK
: B_NO_MEMORY
;
59 KDiskSystem::SetID(disk_system_id id)
67 KDiskSystem::ID() const
75 KDiskSystem::Name() const
83 KDiskSystem::ShortName() const
91 KDiskSystem::PrettyName() const
99 KDiskSystem::Flags() const
107 KDiskSystem::IsFileSystem() const
109 return (fFlags
& B_DISK_SYSTEM_IS_FILE_SYSTEM
);
113 // IsPartitioningSystem
115 KDiskSystem::IsPartitioningSystem() const
117 return !(fFlags
& B_DISK_SYSTEM_IS_FILE_SYSTEM
);
123 KDiskSystem::GetInfo(user_disk_system_info
*info
)
129 strlcpy(info
->name
, Name(), sizeof(info
->name
));
130 strlcpy(info
->short_name
, ShortName(), sizeof(info
->short_name
));
131 strlcpy(info
->pretty_name
, PrettyName(), sizeof(info
->pretty_name
));
132 info
->flags
= Flags();
140 ManagerLocker
locker(KDiskDeviceManager::Default());
141 TRACE("KDiskSystem::Load(): %s -> %ld\n", Name(), fLoadCounter
+ 1);
142 status_t error
= B_OK
;
143 if (fLoadCounter
== 0)
144 error
= LoadModule();
153 KDiskSystem::Unload()
155 ManagerLocker
locker(KDiskDeviceManager::Default());
156 TRACE("KDiskSystem::Unload(): %s -> %ld\n", Name(), fLoadCounter
- 1);
157 if (fLoadCounter
> 0 && --fLoadCounter
== 0)
164 KDiskSystem::IsLoaded() const
166 ManagerLocker
locker(KDiskDeviceManager::Default());
167 return (fLoadCounter
> 0);
173 KDiskSystem::Identify(KPartition
*partition
, void **cookie
)
175 // to be implemented by derived classes
182 KDiskSystem::Scan(KPartition
*partition
, void *cookie
)
184 // to be implemented by derived classes
189 // FreeIdentifyCookie
191 KDiskSystem::FreeIdentifyCookie(KPartition
*partition
, void *cookie
)
193 // to be implemented by derived classes
199 KDiskSystem::FreeCookie(KPartition
*partition
)
201 // to be implemented by derived classes
207 KDiskSystem::FreeContentCookie(KPartition
*partition
)
209 // to be implemented by derived classes
215 KDiskSystem::Defragment(KPartition
* partition
, disk_job_id job
)
217 // to be implemented by derived classes
224 KDiskSystem::Repair(KPartition
* partition
, bool checkOnly
, disk_job_id job
)
226 // to be implemented by derived classes
233 KDiskSystem::Resize(KPartition
* partition
, off_t size
, disk_job_id job
)
235 // to be implemented by derived classes
242 KDiskSystem::ResizeChild(KPartition
* child
, off_t size
, disk_job_id job
)
244 // to be implemented by derived classes
251 KDiskSystem::Move(KPartition
* partition
, off_t offset
, disk_job_id job
)
253 // to be implemented by derived classes
260 KDiskSystem::MoveChild(KPartition
* child
, off_t offset
, disk_job_id job
)
262 // to be implemented by derived classes
269 KDiskSystem::SetName(KPartition
* partition
, const char* name
, disk_job_id job
)
271 // to be implemented by derived classes
278 KDiskSystem::SetContentName(KPartition
* partition
, const char* name
,
281 // to be implemented by derived classes
288 KDiskSystem::SetType(KPartition
* partition
, const char *type
, disk_job_id job
)
290 // to be implemented by derived classes
297 KDiskSystem::SetParameters(KPartition
* partition
, const char* parameters
,
300 // to be implemented by derived classes
305 // SetContentParameters
307 KDiskSystem::SetContentParameters(KPartition
* partition
,
308 const char* parameters
, disk_job_id job
)
310 // to be implemented by derived classes
317 KDiskSystem::Initialize(KPartition
* partition
, const char* name
,
318 const char* parameters
, disk_job_id job
)
320 // to be implemented by derived classes
326 KDiskSystem::Uninitialize(KPartition
* partition
, disk_job_id job
)
328 // to be implemented by derived classes
329 return B_NOT_SUPPORTED
;
335 KDiskSystem::CreateChild(KPartition
* partition
, off_t offset
, off_t size
,
336 const char* type
, const char* name
, const char* parameters
, disk_job_id job
,
337 KPartition
**child
, partition_id childID
)
339 // to be implemented by derived classes
346 KDiskSystem::DeleteChild(KPartition
* child
, disk_job_id job
)
348 // to be implemented by derived classes
355 KDiskSystem::LoadModule()
357 // to be implemented by derived classes
364 KDiskSystem::UnloadModule()
366 // to be implemented by derived classes
372 KDiskSystem::SetShortName(const char *name
)
374 return set_string(fShortName
, name
);
380 KDiskSystem::SetPrettyName(const char *name
)
382 return set_string(fPrettyName
, name
);
388 KDiskSystem::SetFlags(uint32 flags
)
396 KDiskSystem::_NextID()
398 return atomic_add(&fNextID
, 1);
403 int32
KDiskSystem::fNextID
= 0;