xref: /haiku/src/system/kernel/disk_device_manager/KDiskSystem.cpp (revision 1d9d47fc72028bb71b5f232a877231e59cfe2438)
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 // debugging
15 //#define DBG(x)
16 #define DBG(x) x
17 #define OUT dprintf
18 
19 // constructor
20 KDiskSystem::KDiskSystem(const char *name)
21 	: fID(_NextID()),
22 	  fName(NULL),
23 	  fPrettyName(NULL),
24 	  fLoadCounter(0)
25 {
26 	set_string(fName, name);
27 }
28 
29 // destructor
30 KDiskSystem::~KDiskSystem()
31 {
32 	free(fName);
33 }
34 
35 // Init
36 status_t
37 KDiskSystem::Init()
38 {
39 	return (fName ? B_OK : B_NO_MEMORY);
40 }
41 
42 // SetID
43 /*void
44 KDiskSystem::SetID(disk_system_id id)
45 {
46 	fID = id;
47 }*/
48 
49 // ID
50 disk_system_id
51 KDiskSystem::ID() const
52 {
53 	return fID;
54 }
55 
56 // Name
57 const char *
58 KDiskSystem::Name() const
59 {
60 	return fName;
61 }
62 
63 // PrettyName
64 const char *
65 KDiskSystem::PrettyName()
66 {
67 	return fPrettyName;
68 }
69 
70 // Flags
71 uint32
72 KDiskSystem::Flags() const
73 {
74 	return fFlags;
75 }
76 
77 // IsFileSystem
78 bool
79 KDiskSystem::IsFileSystem() const
80 {
81 	return (fFlags & B_DISK_SYSTEM_IS_FILE_SYSTEM);
82 }
83 
84 // IsPartitioningSystem
85 bool
86 KDiskSystem::IsPartitioningSystem() const
87 {
88 	return !(fFlags & B_DISK_SYSTEM_IS_FILE_SYSTEM);
89 }
90 
91 // GetInfo
92 void
93 KDiskSystem::GetInfo(user_disk_system_info *info)
94 {
95 	if (!info)
96 		return;
97 	info->id = ID();
98 	strcpy(info->name, Name());
99 	strcpy(info->pretty_name, PrettyName());
100 	info->flags = Flags();
101 }
102 
103 // Load
104 status_t
105 KDiskSystem::Load()
106 {
107 	ManagerLocker locker(KDiskDeviceManager::Default());
108 	status_t error = B_OK;
109 	if (fLoadCounter == 0)
110 		error = LoadModule();
111 	if (error == B_OK)
112 		fLoadCounter++;
113 	return error;
114 }
115 
116 // Unload
117 void
118 KDiskSystem::Unload()
119 {
120 	ManagerLocker locker(KDiskDeviceManager::Default());
121 	if (fLoadCounter > 0 && --fLoadCounter == 0)
122 		UnloadModule();
123 }
124 
125 // IsLoaded
126 bool
127 KDiskSystem::IsLoaded() const
128 {
129 	ManagerLocker locker(KDiskDeviceManager::Default());
130 	return (fLoadCounter > 0);
131 }
132 
133 // Identify
134 float
135 KDiskSystem::Identify(KPartition *partition, void **cookie)
136 {
137 	// to be implemented by derived classes
138 	return -1;
139 }
140 
141 // Scan
142 status_t
143 KDiskSystem::Scan(KPartition *partition, void *cookie)
144 {
145 	// to be implemented by derived classes
146 	return B_ERROR;
147 }
148 
149 // FreeIdentifyCookie
150 void
151 KDiskSystem::FreeIdentifyCookie(KPartition *partition, void *cookie)
152 {
153 	// to be implemented by derived classes
154 }
155 
156 // FreeCookie
157 void
158 KDiskSystem::FreeCookie(KPartition *partition)
159 {
160 	// to be implemented by derived classes
161 }
162 
163 // FreeContentCookie
164 void
165 KDiskSystem::FreeContentCookie(KPartition *partition)
166 {
167 	// to be implemented by derived classes
168 }
169 
170 // SupportsDefragmenting
171 bool
172 KDiskSystem::SupportsDefragmenting(KPartition *partition, bool *whileMounted)
173 {
174 	// to be implemented by derived classes
175 	if (whileMounted)
176 		*whileMounted = false;
177 	return false;
178 }
179 
180 // SupportsRepairing
181 bool
182 KDiskSystem::SupportsRepairing(KPartition *partition, bool checkOnly,
183 							   bool *whileMounted)
184 {
185 	// to be implemented by derived classes
186 	if (whileMounted)
187 		*whileMounted = false;
188 	return false;
189 }
190 
191 // SupportsResizing
192 bool
193 KDiskSystem::SupportsResizing(KPartition *partition, bool *whileMounted)
194 {
195 	// to be implemented by derived classes
196 	if (whileMounted)
197 		*whileMounted = false;
198 	return false;
199 }
200 
201 // SupportsResizingChild
202 bool
203 KDiskSystem::SupportsResizingChild(KPartition *child)
204 {
205 	// to be implemented by derived classes
206 	return false;
207 }
208 
209 // SupportsMoving
210 bool
211 KDiskSystem::SupportsMoving(KPartition *partition, bool *isNoOp)
212 {
213 	// to be implemented by derived classes
214 	return false;
215 }
216 
217 // SupportsMovingChild
218 bool
219 KDiskSystem::SupportsMovingChild(KPartition *child)
220 {
221 	// to be implemented by derived classes
222 	return false;
223 }
224 
225 // SupportsSettingName
226 bool
227 KDiskSystem::SupportsSettingName(KPartition *partition)
228 {
229 	// to be implemented by derived classes
230 	return false;
231 }
232 
233 // SupportsSettingContentName
234 bool
235 KDiskSystem::SupportsSettingContentName(KPartition *partition,
236 										bool *whileMounted)
237 {
238 	// to be implemented by derived classes
239 	return false;
240 }
241 
242 // SupportsSettingType
243 bool
244 KDiskSystem::SupportsSettingType(KPartition *partition)
245 {
246 	// to be implemented by derived classes
247 	return false;
248 }
249 
250 // SupportsSettingParameters
251 bool
252 KDiskSystem::SupportsSettingParameters(KPartition *partition)
253 {
254 	// to be implemented by derived classes
255 	return false;
256 }
257 
258 // SupportsSettingContentParameters
259 bool
260 KDiskSystem::SupportsSettingContentParameters(KPartition *partition,
261 											  bool *whileMounted)
262 {
263 	// to be implemented by derived classes
264 	return false;
265 }
266 
267 // SupportsInitializing
268 bool
269 KDiskSystem::SupportsInitializing(KPartition *partition)
270 {
271 	// to be implemented by derived classes
272 	return false;
273 }
274 
275 // SupportsInitializingChild
276 bool
277 KDiskSystem::SupportsInitializingChild(KPartition *child,
278 									   const char *diskSystem)
279 {
280 	// to be implemented by derived classes
281 	return false;
282 }
283 
284 // SupportsCreatingChild
285 bool
286 KDiskSystem::SupportsCreatingChild(KPartition *parent)
287 {
288 	// to be implemented by derived classes
289 	return false;
290 }
291 
292 // SupportsDeletingChild
293 bool
294 KDiskSystem::SupportsDeletingChild(KPartition *child)
295 {
296 	// to be implemented by derived classes
297 	return false;
298 }
299 
300 // IsSubSystemFor
301 bool
302 KDiskSystem::IsSubSystemFor(KPartition *partition)
303 {
304 	// to be implemented by derived classes
305 	return false;
306 }
307 
308 // ValidateResize
309 bool
310 KDiskSystem::ValidateResize(KPartition *partition, off_t *size)
311 {
312 	// to be implemented by derived classes
313 	return false;
314 }
315 
316 // ValidateResizeChild
317 bool
318 KDiskSystem::ValidateResizeChild(KPartition *child, off_t *size)
319 {
320 	// to be implemented by derived classes
321 	return false;
322 }
323 
324 // ValidateMove
325 bool
326 KDiskSystem::ValidateMove(KPartition *partition, off_t *start)
327 {
328 	// to be implemented by derived classes
329 	return false;
330 }
331 
332 // ValidateMoveChild
333 bool
334 KDiskSystem::ValidateMoveChild(KPartition *child, off_t *start)
335 {
336 	// to be implemented by derived classes
337 	return false;
338 }
339 
340 // ValidateSetName
341 bool
342 KDiskSystem::ValidateSetName(KPartition *partition, char *name)
343 {
344 	// to be implemented by derived classes
345 	return false;
346 }
347 
348 // ValidateSetContentName
349 bool
350 KDiskSystem::ValidateSetContentName(KPartition *partition, char *name)
351 {
352 	// to be implemented by derived classes
353 	return false;
354 }
355 
356 // ValidateSetType
357 bool
358 KDiskSystem::ValidateSetType(KPartition *partition, const char *type)
359 {
360 	// to be implemented by derived classes
361 	return false;
362 }
363 
364 // ValidateSetParameters
365 bool
366 KDiskSystem::ValidateSetParameters(KPartition *partition,
367 								   const char *parameters)
368 {
369 	// to be implemented by derived classes
370 	return false;
371 }
372 
373 // ValidateSetContentParameters
374 bool
375 KDiskSystem::ValidateSetContentParameters(KPartition *partition,
376 										  const char *parameters)
377 {
378 	// to be implemented by derived classes
379 	return false;
380 }
381 
382 // ValidateInitialize
383 bool
384 KDiskSystem::ValidateInitialize(KPartition *partition, char *name,
385 								const char *parameters)
386 {
387 	// to be implemented by derived classes
388 	return false;
389 }
390 
391 // ValidateCreateChild
392 bool
393 KDiskSystem::ValidateCreateChild(KPartition *partition, off_t *start,
394 								 off_t *size, const char *type,
395 								 const char *parameters, int32 *index)
396 {
397 	// to be implemented by derived classes
398 	return false;
399 }
400 
401 // CountPartitionableSpaces
402 int32
403 KDiskSystem::CountPartitionableSpaces(KPartition *partition)
404 {
405 	// to be implemented by derived classes
406 	return 0;
407 }
408 
409 // GetPartitionableSpaces
410 status_t
411 KDiskSystem::GetPartitionableSpaces(KPartition *partition,
412 									partitionable_space_data *buffer,
413 									int32 count, int32 *actualCount)
414 {
415 	// to be implemented by derived classes
416 	return B_ERROR;
417 }
418 
419 // GetNextSupportedType
420 status_t
421 KDiskSystem::GetNextSupportedType(KPartition *partition, int32 *cookie,
422 								  char *type)
423 {
424 	// to be implemented by derived classes
425 	return B_ENTRY_NOT_FOUND;
426 }
427 
428 // ShadowPartitionChanged
429 status_t
430 KDiskSystem::ShadowPartitionChanged(KPartition *partition, uint32 operation)
431 {
432 	// to be implemented by derived classes
433 	return B_ENTRY_NOT_FOUND;
434 }
435 
436 // GetTypeForContentType
437 status_t
438 KDiskSystem::GetTypeForContentType(const char *contentType, char *type)
439 {
440 	// to be implemented by derived classes
441 	return B_ENTRY_NOT_FOUND;
442 }
443 
444 // Defragment
445 status_t
446 KDiskSystem::Defragment(KPartition *partition, KDiskDeviceJob *job)
447 {
448 	// to be implemented by derived classes
449 	return B_ERROR;
450 }
451 
452 // Repair
453 status_t
454 KDiskSystem::Repair(KPartition *partition, bool checkOnly,
455 					KDiskDeviceJob *job)
456 {
457 	// to be implemented by derived classes
458 	return B_ERROR;
459 }
460 
461 // Resize
462 status_t
463 KDiskSystem::Resize(KPartition *partition, off_t size, KDiskDeviceJob *job)
464 {
465 	// to be implemented by derived classes
466 	return B_ERROR;
467 }
468 
469 // ResizeChild
470 status_t
471 KDiskSystem::ResizeChild(KPartition *child, off_t size, KDiskDeviceJob *job)
472 {
473 	// to be implemented by derived classes
474 	return B_ERROR;
475 }
476 
477 // Move
478 status_t
479 KDiskSystem::Move(KPartition *partition, off_t offset, KDiskDeviceJob *job)
480 {
481 	// to be implemented by derived classes
482 	return B_ERROR;
483 }
484 
485 // MoveChild
486 status_t
487 KDiskSystem::MoveChild(KPartition *child, off_t offset, KDiskDeviceJob *job)
488 {
489 	// to be implemented by derived classes
490 	return B_ERROR;
491 }
492 
493 // SetName
494 status_t
495 KDiskSystem::SetName(KPartition *partition, char *name, KDiskDeviceJob *job)
496 {
497 	// to be implemented by derived classes
498 	return B_ERROR;
499 }
500 
501 // SetContentName
502 status_t
503 KDiskSystem::SetContentName(KPartition *partition, char *name,
504 							KDiskDeviceJob *job)
505 {
506 	// to be implemented by derived classes
507 	return B_ERROR;
508 }
509 
510 // SetType
511 status_t
512 KDiskSystem::SetType(KPartition *partition, char *type, KDiskDeviceJob *job)
513 {
514 	// to be implemented by derived classes
515 	return B_ERROR;
516 }
517 
518 // SetParameters
519 status_t
520 KDiskSystem::SetParameters(KPartition *partition, const char *parameters,
521 						   KDiskDeviceJob *job)
522 {
523 	// to be implemented by derived classes
524 	return B_ERROR;
525 }
526 
527 // SetContentParameters
528 status_t
529 KDiskSystem::SetContentParameters(KPartition *partition,
530 								  const char *parameters, KDiskDeviceJob *job)
531 {
532 	// to be implemented by derived classes
533 	return B_ERROR;
534 }
535 
536 // Initialize
537 status_t
538 KDiskSystem::Initialize(KPartition *partition, const char *name,
539 						const char *parameters, KDiskDeviceJob *job)
540 {
541 	// to be implemented by derived classes
542 	return B_ERROR;
543 }
544 
545 // CreateChild
546 status_t
547 KDiskSystem::CreateChild(KPartition *partition, off_t offset, off_t size,
548 						 const char *type, const char *parameters,
549 						 KDiskDeviceJob *job, KPartition **child,
550 						 partition_id childID)
551 {
552 	// to be implemented by derived classes
553 	return B_ERROR;
554 }
555 
556 // DeleteChild
557 status_t
558 KDiskSystem::DeleteChild(KPartition *child, KDiskDeviceJob *job)
559 {
560 	// to be implemented by derived classes
561 	return B_ERROR;
562 }
563 
564 // LoadModule
565 status_t
566 KDiskSystem::LoadModule()
567 {
568 	// to be implemented by derived classes
569 	return B_ERROR;
570 }
571 
572 // UnloadModule
573 void
574 KDiskSystem::UnloadModule()
575 {
576 	// to be implemented by derived classes
577 }
578 
579 // SetPrettyName
580 status_t
581 KDiskSystem::SetPrettyName(const char *name)
582 {
583 	return set_string(fPrettyName, name);
584 }
585 
586 // SetFlags
587 void
588 KDiskSystem::SetFlags(uint32 flags)
589 {
590 	fFlags = flags;
591 }
592 
593 // _NextID
594 int32
595 KDiskSystem::_NextID()
596 {
597 	return atomic_add(&fNextID, 1);
598 }
599 
600 
601 // fNextID
602 int32 KDiskSystem::fNextID = 0;
603 
604