xref: /haiku/headers/private/kernel/disk_device_manager/KDiskSystem.h (revision d9cebac2b77547b7064f22497514eecd2d047160)
1 /*
2  * Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Ingo Weinhold <bonefish@cs.tu-berlin.de>
7  */
8 #ifndef _K_DISK_DEVICE_SYSTEM_H
9 #define _K_DISK_DEVICE_SYSTEM_H
10 
11 #include "disk_device_manager.h"
12 
13 struct user_disk_system_info;
14 
15 namespace BPrivate {
16 namespace DiskDevice {
17 
18 class KDiskDeviceJob;
19 class KPartition;
20 
21 //!	\brief Common ancestor for disk system add-on wrappers
22 class KDiskSystem {
23 public:
24 	KDiskSystem(const char *name);
25 	virtual ~KDiskSystem();
26 
27 	virtual status_t Init();
28 
29 //	void SetID(disk_system_id id);
30 	disk_system_id ID() const;
31 	const char *Name() const;
32 	const char *PrettyName();
33 	uint32 Flags() const;
34 
35 	bool IsFileSystem() const;
36 	bool IsPartitioningSystem() const;
37 
38 	void GetInfo(user_disk_system_info *info);
39 
40 	// manager will be locked
41 	status_t Load();		// load/unload -- can be nested
42 	void Unload();			//
43 	bool IsLoaded() const;
44 
45 	// Scanning
46 	// Device must be write locked.
47 
48 	virtual float Identify(KPartition *partition, void **cookie);
49 	virtual status_t Scan(KPartition *partition, void *cookie);
50 	virtual void FreeIdentifyCookie(KPartition *partition, void *cookie);
51 	virtual void FreeCookie(KPartition *partition);
52 	virtual void FreeContentCookie(KPartition *partition);
53 
54 	// Querying
55 	// Device must be read locked.
56 
57 	virtual uint32 GetSupportedOperations(KPartition* partition, uint32 mask);
58 	virtual uint32 GetSupportedChildOperations(KPartition* child, uint32 mask);
59 
60 	// for convenience
61 	bool SupportsOperations(KPartition* partition, uint32 operations)
62 		{ return (GetSupportedOperations(partition, operations) & operations)
63 			== operations; }
64 	bool SupportsChildOperations(KPartition* child, uint32 operations)
65 		{ return (GetSupportedChildOperations(child, operations) & operations)
66 			== operations; }
67 
68 	virtual bool SupportsInitializingChild(KPartition *child,
69 		const char *diskSystem);
70 	virtual bool IsSubSystemFor(KPartition *partition);
71 
72 	virtual bool ValidateResize(KPartition *partition, off_t *size);
73 	virtual bool ValidateResizeChild(KPartition *child, off_t *size);
74 	virtual bool ValidateMove(KPartition *partition, off_t *start);
75 	virtual bool ValidateMoveChild(KPartition *child, off_t *start);
76 	virtual bool ValidateSetName(KPartition *partition, char *name);
77 	virtual bool ValidateSetContentName(KPartition *partition, char *name);
78 	virtual bool ValidateSetType(KPartition *partition, const char *type);
79 	virtual bool ValidateSetParameters(KPartition *partition,
80 									   const char *parameters);
81 	virtual bool ValidateSetContentParameters(KPartition *parameters,
82 											  const char *parameters);
83 	virtual bool ValidateInitialize(KPartition *partition, char *name,
84 									const char *parameters);
85 	virtual bool ValidateCreateChild(KPartition *partition, off_t *start,
86 									 off_t *size, const char *type,
87 									 const char *parameters, int32 *index);
88 	virtual int32 CountPartitionableSpaces(KPartition *partition);
89 	virtual status_t GetPartitionableSpaces(KPartition *partition,
90 											partitionable_space_data *buffer,
91 											int32 count,
92 											int32 *actualCount = NULL);
93 
94 	virtual status_t GetNextSupportedType(KPartition *partition, int32 *cookie,
95 										  char *type);
96 	virtual status_t GetTypeForContentType(const char *contentType,
97 										   char *type);
98 
99 	// Shadow partition modification
100 	// Device must be write locked.
101 
102 	virtual status_t ShadowPartitionChanged(KPartition *partition,
103 		KPartition *child, uint32 operation);
104 
105 	// Writing
106 	// Device should not be locked.
107 
108 	virtual status_t Defragment(KPartition *partition, KDiskDeviceJob *job);
109 	virtual status_t Repair(KPartition *partition, bool checkOnly,
110 							KDiskDeviceJob *job);
111 	virtual status_t Resize(KPartition *partition, off_t size,
112 							KDiskDeviceJob *job);
113 	virtual status_t ResizeChild(KPartition *child, off_t size,
114 								 KDiskDeviceJob *job);
115 	virtual status_t Move(KPartition *partition, off_t offset,
116 						  KDiskDeviceJob *job);
117 	virtual status_t MoveChild(KPartition *child, off_t offset,
118 							   KDiskDeviceJob *job);
119 	virtual status_t SetName(KPartition *partition, char *name,
120 							 KDiskDeviceJob *job);
121 	virtual status_t SetContentName(KPartition *partition, char *name,
122 									KDiskDeviceJob *job);
123 	virtual status_t SetType(KPartition *partition, char *type,
124 							 KDiskDeviceJob *job);
125 	virtual status_t SetParameters(KPartition *partition,
126 								   const char *parameters,
127 								   KDiskDeviceJob *job);
128 	virtual status_t SetContentParameters(KPartition *partition,
129 										  const char *parameters,
130 										  KDiskDeviceJob *job);
131 	virtual status_t Initialize(KPartition *partition, const char *name,
132 								const char *parameters, KDiskDeviceJob *job);
133 	virtual status_t CreateChild(KPartition *partition, off_t offset,
134 								 off_t size, const char *type,
135 								 const char *parameters, KDiskDeviceJob *job,
136 								 KPartition **child = NULL,
137 								 partition_id childID = -1);
138 	virtual status_t DeleteChild(KPartition *child, KDiskDeviceJob *job);
139 // The KPartition* parameters for the writing methods are a bit `volatile',
140 // since the device will not be locked, when they are called. The KPartition
141 // is registered though, so that it is at least guaranteed that the object
142 // won't go away.
143 
144 protected:
145 	virtual status_t LoadModule();
146 	virtual void UnloadModule();
147 
148 	status_t SetPrettyName(const char *name);
149 	void SetFlags(uint32 flags);
150 
151 	static int32 _NextID();
152 
153 private:
154 	disk_system_id	fID;
155 	char			*fName;
156 	char			*fPrettyName;
157 	uint32			fFlags;
158 	int32			fLoadCounter;
159 
160 	static int32	fNextID;
161 };
162 
163 } // namespace DiskDevice
164 } // namespace BPrivate
165 
166 using BPrivate::DiskDevice::KDiskSystem;
167 
168 #endif	// _K_DISK_DEVICE_SYSTEM_H
169