2 * Copyright 2003-2007, Ingo Weinhold, bonefish@cs.tu-berlin.de.
3 * Distributed under the terms of the MIT License.
6 #include <DiskSystem.h>
8 #include <DiskSystemAddOn.h>
11 #include <ddm_userland_interface_defs.h>
14 #include "DiskSystemAddOnManager.h"
18 BDiskSystem::BDiskSystem()
27 BDiskSystem::BDiskSystem(const BDiskSystem
& other
)
31 fShortName(other
.fShortName
),
32 fPrettyName(other
.fPrettyName
),
39 BDiskSystem::~BDiskSystem()
46 BDiskSystem::InitCheck() const
48 return fID
> 0 ? B_OK
: fID
;
54 BDiskSystem::Name() const
56 return fName
.String();
62 BDiskSystem::ShortName() const
64 return fShortName
.String();
70 BDiskSystem::PrettyName() const
72 return fPrettyName
.String();
76 // SupportsDefragmenting
78 BDiskSystem::SupportsDefragmenting(bool* whileMounted
) const
80 if (InitCheck() != B_OK
81 || !(fFlags
& B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING
)) {
83 *whileMounted
= false;
88 *whileMounted
= IsFileSystem() && (fFlags
89 & B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED
) != 0;
98 BDiskSystem::SupportsRepairing(bool checkOnly
, bool* whileMounted
) const
100 uint32 mainBit
= B_DISK_SYSTEM_SUPPORTS_REPAIRING
;
101 uint32 mountedBit
= B_DISK_SYSTEM_SUPPORTS_REPAIRING_WHILE_MOUNTED
;
104 mainBit
= B_DISK_SYSTEM_SUPPORTS_CHECKING
;
105 mountedBit
= B_DISK_SYSTEM_SUPPORTS_CHECKING_WHILE_MOUNTED
;
108 if (InitCheck() != B_OK
|| !(fFlags
& mainBit
)) {
110 *whileMounted
= false;
115 *whileMounted
= (IsFileSystem() && (fFlags
& mountedBit
));
123 BDiskSystem::SupportsResizing(bool* whileMounted
) const
125 if (InitCheck() != B_OK
126 || !(fFlags
& B_DISK_SYSTEM_SUPPORTS_RESIZING
)) {
128 *whileMounted
= false;
133 *whileMounted
= (IsFileSystem()
134 && (fFlags
& B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED
));
141 // SupportsResizingChild
143 BDiskSystem::SupportsResizingChild() const
145 return (InitCheck() == B_OK
&& IsPartitioningSystem()
146 && (fFlags
& B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD
));
152 BDiskSystem::SupportsMoving(bool* whileMounted
) const
154 if (InitCheck() != B_OK
155 || !(fFlags
& B_DISK_SYSTEM_SUPPORTS_MOVING
)) {
157 *whileMounted
= false;
162 *whileMounted
= (IsFileSystem()
163 && (fFlags
& B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED
));
170 // SupportsMovingChild
172 BDiskSystem::SupportsMovingChild() const
174 return (InitCheck() == B_OK
&& IsPartitioningSystem()
175 && (fFlags
& B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD
));
181 BDiskSystem::SupportsName() const
183 return (InitCheck() == B_OK
&& IsPartitioningSystem()
184 && (fFlags
& B_DISK_SYSTEM_SUPPORTS_NAME
));
188 // SupportsContentName
190 BDiskSystem::SupportsContentName() const
192 return (InitCheck() == B_OK
193 && (fFlags
& B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME
));
197 // SupportsSettingName
199 BDiskSystem::SupportsSettingName() const
201 return (InitCheck() == B_OK
&& IsPartitioningSystem()
202 && (fFlags
& B_DISK_SYSTEM_SUPPORTS_SETTING_NAME
));
206 // SupportsSettingContentName
208 BDiskSystem::SupportsSettingContentName(bool* whileMounted
) const
210 if (InitCheck() != B_OK
211 || !(fFlags
& B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME
)) {
213 *whileMounted
= false;
218 *whileMounted
= (IsFileSystem()
220 & B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED
));
227 // SupportsSettingType
229 BDiskSystem::SupportsSettingType() const
231 return (InitCheck() == B_OK
&& IsPartitioningSystem()
232 && (fFlags
& B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE
));
236 // SupportsSettingParameters
238 BDiskSystem::SupportsSettingParameters() const
240 return (InitCheck() == B_OK
&& IsPartitioningSystem()
241 && (fFlags
& B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS
));
245 // SupportsSettingContentParameters
247 BDiskSystem::SupportsSettingContentParameters(bool* whileMounted
) const
249 if (InitCheck() != B_OK
250 || !(fFlags
& B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS
)) {
252 *whileMounted
= false;
257 uint32 whileMountedFlag
258 = B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED
;
259 *whileMounted
= (IsFileSystem() && (fFlags
& whileMountedFlag
));
266 // SupportsCreatingChild
268 BDiskSystem::SupportsCreatingChild() const
270 return (InitCheck() == B_OK
&& IsPartitioningSystem()
271 && (fFlags
& B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD
));
275 // SupportsDeletingChild
277 BDiskSystem::SupportsDeletingChild() const
279 return (InitCheck() == B_OK
&& IsPartitioningSystem()
280 && (fFlags
& B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD
));
284 // SupportsInitializing
286 BDiskSystem::SupportsInitializing() const
288 return (InitCheck() == B_OK
289 && (fFlags
& B_DISK_SYSTEM_SUPPORTS_INITIALIZING
));
294 BDiskSystem::SupportsWriting() const
296 if (InitCheck() != B_OK
300 return (fFlags
& B_DISK_SYSTEM_SUPPORTS_WRITING
) != 0;
304 // GetTypeForContentType
306 BDiskSystem::GetTypeForContentType(const char* contentType
, BString
* type
) const
308 if (InitCheck() != B_OK
)
311 if (!contentType
|| !type
|| !IsPartitioningSystem())
314 // get the disk system add-on
315 DiskSystemAddOnManager
* manager
= DiskSystemAddOnManager::Default();
316 BDiskSystemAddOn
* addOn
= manager
->GetAddOn(fName
.String());
318 return B_ENTRY_NOT_FOUND
;
320 status_t result
= addOn
->GetTypeForContentType(contentType
, type
);
323 manager
->PutAddOn(addOn
);
329 // IsPartitioningSystem
331 BDiskSystem::IsPartitioningSystem() const
333 return InitCheck() == B_OK
&& !(fFlags
& B_DISK_SYSTEM_IS_FILE_SYSTEM
);
339 BDiskSystem::IsFileSystem() const
341 return InitCheck() == B_OK
&& (fFlags
& B_DISK_SYSTEM_IS_FILE_SYSTEM
);
347 BDiskSystem::operator=(const BDiskSystem
& other
)
351 fShortName
= other
.fShortName
;
352 fPrettyName
= other
.fPrettyName
;
353 fFlags
= other
.fFlags
;
361 BDiskSystem::_SetTo(disk_system_id id
)
368 user_disk_system_info info
;
369 status_t error
= _kern_get_disk_system_info(id
, &info
);
371 return (fID
= error
);
373 return _SetTo(&info
);
379 BDiskSystem::_SetTo(const user_disk_system_info
* info
)
384 return (fID
= B_BAD_VALUE
);
388 fShortName
= info
->short_name
;
389 fPrettyName
= info
->pretty_name
;
390 fFlags
= info
->flags
;
398 BDiskSystem::_Unset()
401 fName
= (const char*)NULL
;
402 fPrettyName
= (const char*)NULL
;