* Added an UninitializeMedia() method to KDiskDevice that also resets the

device geometry.
* If SetTo() reports no media, and GetGeometry() fails, the device geometry
  is now reset as well.
* KDiskDeviceManager::_ScanPartition() no longer unmarks the partition busy;
  this is now done by the caller, and done independently from the outcome of
  _ScanPartition(). This also fixes the problem that devices with no media
  were never marked unbusy (and thus were ignored subsequently).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22912 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-11-12 23:20:33 +00:00
parent ef6f42349c
commit 88ef411154
3 changed files with 33 additions and 22 deletions
@@ -55,6 +55,7 @@ public:
bool MediaChanged() const;
void UpdateMediaStatusIfNeeded();
void UninitializeMedia();
status_t SetPath(const char *path);
// TODO: Remove this method or make it private. Once initialized the
@@ -82,6 +83,7 @@ protected:
virtual status_t GetGeometry(device_geometry *geometry);
private:
void _ResetGeometry();
void _InitPartitionData();
disk_device_data fDeviceData;
@@ -71,7 +71,8 @@ KDiskDevice::SetTo(const char *path)
} else {
// no media: try to get the device geometry, but don't fail, if
// we can't get it
GetGeometry(&fDeviceData.geometry);
if (GetGeometry(&fDeviceData.geometry) != B_OK)
_ResetGeometry();
}
// set device flags
if (fDeviceData.geometry.removable)
@@ -102,14 +103,7 @@ KDiskDevice::Unset()
free(fDeviceData.path);
fDeviceData.path = NULL;
}
fDeviceData.geometry.bytes_per_sector = 0;
fDeviceData.geometry.sectors_per_track = 0;
fDeviceData.geometry.cylinder_count = 0;
fDeviceData.geometry.head_count = 0;
fDeviceData.geometry.device_type = B_DISK;
fDeviceData.geometry.removable = true;
fDeviceData.geometry.read_only = true;
fDeviceData.geometry.write_once = false;
_ResetGeometry();
}
// InitCheck
@@ -248,6 +242,14 @@ KDiskDevice::UpdateMediaStatusIfNeeded()
}
void
KDiskDevice::UninitializeMedia()
{
UninitializeContents();
_ResetGeometry();
}
// SetPath
status_t
KDiskDevice::SetPath(const char *path)
@@ -383,3 +385,17 @@ KDiskDevice::_InitPartitionData()
fPartitionData.flags |= B_PARTITION_IS_DEVICE;
}
void
KDiskDevice::_ResetGeometry()
{
fDeviceData.geometry.bytes_per_sector = 0;
fDeviceData.geometry.sectors_per_track = 0;
fDeviceData.geometry.cylinder_count = 0;
fDeviceData.geometry.head_count = 0;
fDeviceData.geometry.device_type = B_DISK;
fDeviceData.geometry.removable = true;
fDeviceData.geometry.read_only = true;
fDeviceData.geometry.write_once = false;
}
@@ -531,6 +531,7 @@ KDiskDeviceManager::CreateFileDevice(const char *filePath, bool* newlyCreated)
// scan device
if (error == B_OK) {
_ScanPartition(device, false);
device->UnmarkBusy(true);
if (newlyCreated)
*newlyCreated = true;
@@ -746,6 +747,7 @@ KDiskDeviceManager::InitialDeviceScan()
if (DeviceWriteLocker deviceLocker = device) {
if (ManagerLocker locker = this) {
error = _ScanPartition(device, false);
device->UnmarkBusy(true);
if (error != B_OK)
break;
} else
@@ -1034,18 +1036,7 @@ KDiskDeviceManager::_ScanPartition(KPartition *partition, bool async)
// scan synchronously
if (!partition->Device()->HasMedia())
return B_OK;
status_t error = _ScanPartition(partition);
// mark all partitions un-busy
// TODO: This is not quite correct here. Partitions are created marked "busy",
// hence the one creating it should be responsible for clearing the flag, not
// us.
partition->UnmarkBusy(true);
return error;
return _ScanPartition(partition);
}
@@ -1055,6 +1046,8 @@ KDiskDeviceManager::_ScanPartition(KPartition *partition)
// the partition's device must be write-locked
if (!partition)
return B_BAD_VALUE;
if (!partition->Device()->HasMedia())
return B_OK;
if (partition->DiskSystem() != NULL) {
// TODO: this is more or less a hack to allow rescanning a partition
for (int32 i = 0; KPartition *child = partition->ChildAt(i); i++)
@@ -1151,7 +1144,7 @@ KDiskDeviceManager::_CheckMediaStatus()
continue;
device->MarkBusy(true);
device->UninitializeContents(true);
device->UninitializeMedia();
if (device->MediaChanged()) {
dprintf("Media changed from %s\n", device->Path());