Added a deviceOnly flag to {Find,Register}Device(). Minor {Create,Delete}FileDevice() changes.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3975 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2003-07-15 01:05:50 +00:00
parent 5d22fa967a
commit 2438192b6c
3 changed files with 42 additions and 15 deletions

View File

@ -38,20 +38,21 @@ public:
// manager must be locked
KDiskDevice *FindDevice(const char *path);
KDiskDevice *FindDevice(partition_id id);
KDiskDevice *FindDevice(partition_id id, bool deviceOnly = true);
KPartition *FindPartition(const char *path, bool noShadow = false);
KPartition *FindPartition(partition_id id, bool noShadow = false);
KFileDiskDevice *FindFileDevice(const char *filePath);
KDiskDevice *RegisterDevice(const char *path);
KDiskDevice *RegisterDevice(partition_id id);
KDiskDevice *RegisterDevice(partition_id id, bool deviceOnly = true);
KDiskDevice *RegisterNextDevice(int32 *cookie);
KPartition *RegisterPartition(const char *path, bool noShadow = false);
KPartition *RegisterPartition(partition_id id, bool noShadow = false);
KFileDiskDevice *RegisterFileDevice(const char *filePath);
status_t CreateFileDevice(const char *filePath, partition_id *device = 0);
partition_id CreateFileDevice(const char *filePath);
status_t DeleteFileDevice(const char *filePath);
status_t DeleteFileDevice(partition_id id);
// manager must be locked
int32 CountDevices();

View File

@ -121,10 +121,18 @@ KDiskDeviceManager::~KDiskDeviceManager()
if (fPartitions->Count() > 0) {
DBG(OUT("WARNING: There are still %ld unremoved partitions!\n",
fPartitions->Count()));
for (PartitionMap::Iterator it = fPartitions->Begin();
it != fPartitions->End(); ++it) {
DBG(OUT(" partition: %ld\n", it->Value()->ID()));
}
}
if (fObsoletePartitions->Count() > 0) {
DBG(OUT("WARNING: There are still %ld obsolete partitions!\n",
fObsoletePartitions->Count()));
for (PartitionSet::Iterator it = fObsoletePartitions->Begin();
it != fObsoletePartitions->End(); ++it) {
DBG(OUT(" partition: %ld\n", (*it)->ID()));
}
}
// remove all disk systems
for (int32 cookie = 0;
@ -214,10 +222,13 @@ KDiskDeviceManager::FindDevice(const char *path)
// FindDevice
KDiskDevice *
KDiskDeviceManager::FindDevice(partition_id id)
KDiskDeviceManager::FindDevice(partition_id id, bool deviceOnly)
{
if (KPartition *partition = FindPartition(id))
return partition->Device();
if (KPartition *partition = FindPartition(id)) {
KDiskDevice *device = partition->Device();
if (!deviceOnly || id == device->ID())
return device;
}
return NULL;
}
@ -283,10 +294,10 @@ KDiskDeviceManager::RegisterDevice(const char *path)
// RegisterDevice
KDiskDevice *
KDiskDeviceManager::RegisterDevice(partition_id id)
KDiskDeviceManager::RegisterDevice(partition_id id, bool deviceOnly)
{
if (ManagerLocker locker = this) {
if (KDiskDevice *device = FindDevice(id)) {
if (KDiskDevice *device = FindDevice(id, deviceOnly)) {
device->Register();
return device;
}
@ -349,13 +360,13 @@ KDiskDeviceManager::RegisterFileDevice(const char *filePath)
}
// CreateFileDevice
status_t
KDiskDeviceManager::CreateFileDevice(const char *filePath,
partition_id *deviceID)
partition_id
KDiskDeviceManager::CreateFileDevice(const char *filePath)
{
if (!filePath)
return B_BAD_VALUE;
status_t error = B_ERROR;
partition_id deviceID = -1;
KFileDiskDevice *device = NULL;
if (ManagerLocker locker = this) {
// check, if the device does already exist
@ -374,8 +385,7 @@ KDiskDeviceManager::CreateFileDevice(const char *filePath,
delete device;
return error;
}
if (deviceID)
*deviceID = device->ID();
deviceID = device->ID();
device->Register();
}
// scan device
@ -383,7 +393,7 @@ KDiskDeviceManager::CreateFileDevice(const char *filePath,
_ScanDevice(device);
device->Unregister();
}
return error;
return (error == B_OK ? deviceID : error);
}
// DeleteFileDevice
@ -400,6 +410,22 @@ KDiskDeviceManager::DeleteFileDevice(const char *filePath)
return B_ERROR;
}
// DeleteFileDevice
status_t
KDiskDeviceManager::DeleteFileDevice(partition_id id)
{
if (KDiskDevice *device = RegisterDevice(id)) {
PartitionRegistrar _(device, true);
if (!dynamic_cast<KFileDiskDevice*>(device) || id != device->ID())
return B_ENTRY_NOT_FOUND;
if (DeviceWriteLocker locker = device) {
if (_RemoveDevice(device))
return B_OK;
}
}
return B_ERROR;
}
// CountDevices
int32
KDiskDeviceManager::CountDevices()

View File

@ -105,7 +105,7 @@ disk_device_data *
get_disk_device(partition_id partitionID)
{
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KDiskDevice *device = manager->FindDevice(partitionID);
KDiskDevice *device = manager->FindDevice(partitionID, false);
return (device ? device->DeviceData() : NULL);
}