libroot_debug: Merge guarded heap into libroot_debug.
[haiku.git] / src / system / kernel / disk_device_manager / KDiskSystem.cpp
blobd451e21be1993b72f86f369a7c26a45e7e9ae4de
1 /*
2 * Copyright 2003-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <stdio.h>
8 #include <stdlib.h>
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"
19 // debugging
20 //#define TRACE_KDISK_SYSTEM
21 #ifdef TRACE_KDISK_SYSTEM
22 # define TRACE(x...) dprintf(x)
23 #else
24 # define TRACE(x...) do { } while (false)
25 #endif
28 // constructor
29 KDiskSystem::KDiskSystem(const char *name)
30 : fID(_NextID()),
31 fName(NULL),
32 fShortName(NULL),
33 fPrettyName(NULL),
34 fLoadCounter(0)
36 set_string(fName, name);
40 // destructor
41 KDiskSystem::~KDiskSystem()
43 free(fName);
44 free(fShortName);
45 free(fPrettyName);
49 // Init
50 status_t
51 KDiskSystem::Init()
53 return fName ? B_OK : B_NO_MEMORY;
57 // SetID
58 /*void
59 KDiskSystem::SetID(disk_system_id id)
61 fID = id;
62 }*/
65 // ID
66 disk_system_id
67 KDiskSystem::ID() const
69 return fID;
73 // Name
74 const char *
75 KDiskSystem::Name() const
77 return fName;
81 // ShortName
82 const char *
83 KDiskSystem::ShortName() const
85 return fShortName;
89 // PrettyName
90 const char *
91 KDiskSystem::PrettyName() const
93 return fPrettyName;
97 // Flags
98 uint32
99 KDiskSystem::Flags() const
101 return fFlags;
105 // IsFileSystem
106 bool
107 KDiskSystem::IsFileSystem() const
109 return (fFlags & B_DISK_SYSTEM_IS_FILE_SYSTEM);
113 // IsPartitioningSystem
114 bool
115 KDiskSystem::IsPartitioningSystem() const
117 return !(fFlags & B_DISK_SYSTEM_IS_FILE_SYSTEM);
121 // GetInfo
122 void
123 KDiskSystem::GetInfo(user_disk_system_info *info)
125 if (!info)
126 return;
128 info->id = ID();
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();
136 // Load
137 status_t
138 KDiskSystem::Load()
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();
145 if (error == B_OK)
146 fLoadCounter++;
147 return error;
151 // Unload
152 void
153 KDiskSystem::Unload()
155 ManagerLocker locker(KDiskDeviceManager::Default());
156 TRACE("KDiskSystem::Unload(): %s -> %ld\n", Name(), fLoadCounter - 1);
157 if (fLoadCounter > 0 && --fLoadCounter == 0)
158 UnloadModule();
162 // IsLoaded
163 bool
164 KDiskSystem::IsLoaded() const
166 ManagerLocker locker(KDiskDeviceManager::Default());
167 return (fLoadCounter > 0);
171 // Identify
172 float
173 KDiskSystem::Identify(KPartition *partition, void **cookie)
175 // to be implemented by derived classes
176 return -1;
180 // Scan
181 status_t
182 KDiskSystem::Scan(KPartition *partition, void *cookie)
184 // to be implemented by derived classes
185 return B_ERROR;
189 // FreeIdentifyCookie
190 void
191 KDiskSystem::FreeIdentifyCookie(KPartition *partition, void *cookie)
193 // to be implemented by derived classes
197 // FreeCookie
198 void
199 KDiskSystem::FreeCookie(KPartition *partition)
201 // to be implemented by derived classes
205 // FreeContentCookie
206 void
207 KDiskSystem::FreeContentCookie(KPartition *partition)
209 // to be implemented by derived classes
213 // Defragment
214 status_t
215 KDiskSystem::Defragment(KPartition* partition, disk_job_id job)
217 // to be implemented by derived classes
218 return B_ERROR;
222 // Repair
223 status_t
224 KDiskSystem::Repair(KPartition* partition, bool checkOnly, disk_job_id job)
226 // to be implemented by derived classes
227 return B_ERROR;
231 // Resize
232 status_t
233 KDiskSystem::Resize(KPartition* partition, off_t size, disk_job_id job)
235 // to be implemented by derived classes
236 return B_ERROR;
240 // ResizeChild
241 status_t
242 KDiskSystem::ResizeChild(KPartition* child, off_t size, disk_job_id job)
244 // to be implemented by derived classes
245 return B_ERROR;
249 // Move
250 status_t
251 KDiskSystem::Move(KPartition* partition, off_t offset, disk_job_id job)
253 // to be implemented by derived classes
254 return B_ERROR;
258 // MoveChild
259 status_t
260 KDiskSystem::MoveChild(KPartition* child, off_t offset, disk_job_id job)
262 // to be implemented by derived classes
263 return B_ERROR;
267 // SetName
268 status_t
269 KDiskSystem::SetName(KPartition* partition, const char* name, disk_job_id job)
271 // to be implemented by derived classes
272 return B_ERROR;
276 // SetContentName
277 status_t
278 KDiskSystem::SetContentName(KPartition* partition, const char* name,
279 disk_job_id job)
281 // to be implemented by derived classes
282 return B_ERROR;
286 // SetType
287 status_t
288 KDiskSystem::SetType(KPartition* partition, const char *type, disk_job_id job)
290 // to be implemented by derived classes
291 return B_ERROR;
295 // SetParameters
296 status_t
297 KDiskSystem::SetParameters(KPartition* partition, const char* parameters,
298 disk_job_id job)
300 // to be implemented by derived classes
301 return B_ERROR;
305 // SetContentParameters
306 status_t
307 KDiskSystem::SetContentParameters(KPartition* partition,
308 const char* parameters, disk_job_id job)
310 // to be implemented by derived classes
311 return B_ERROR;
315 // Initialize
316 status_t
317 KDiskSystem::Initialize(KPartition* partition, const char* name,
318 const char* parameters, disk_job_id job)
320 // to be implemented by derived classes
321 return B_ERROR;
325 status_t
326 KDiskSystem::Uninitialize(KPartition* partition, disk_job_id job)
328 // to be implemented by derived classes
329 return B_NOT_SUPPORTED;
333 // CreateChild
334 status_t
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
340 return B_ERROR;
344 // DeleteChild
345 status_t
346 KDiskSystem::DeleteChild(KPartition* child, disk_job_id job)
348 // to be implemented by derived classes
349 return B_ERROR;
353 // LoadModule
354 status_t
355 KDiskSystem::LoadModule()
357 // to be implemented by derived classes
358 return B_ERROR;
362 // UnloadModule
363 void
364 KDiskSystem::UnloadModule()
366 // to be implemented by derived classes
370 // SetShortName
371 status_t
372 KDiskSystem::SetShortName(const char *name)
374 return set_string(fShortName, name);
378 // SetPrettyName
379 status_t
380 KDiskSystem::SetPrettyName(const char *name)
382 return set_string(fPrettyName, name);
386 // SetFlags
387 void
388 KDiskSystem::SetFlags(uint32 flags)
390 fFlags = flags;
394 // _NextID
395 int32
396 KDiskSystem::_NextID()
398 return atomic_add(&fNextID, 1);
402 // fNextID
403 int32 KDiskSystem::fNextID = 0;