* Removed VisitEach{Initializable,Partitionable}Partition() -- they are
too specific for a general API.
* Implemented {Register,Unregister}FileDevice().
* Implemented Get{Device,Partition}WithID() and
Get{Device,Partition}ForPath().
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3979 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -102,7 +102,6 @@ public:
|
|||||||
// publishes: /dev/disk/virtual/files/<disk device ID>/raw
|
// publishes: /dev/disk/virtual/files/<disk device ID>/raw
|
||||||
status_t UnregisterFileDevice(const char *filename);
|
status_t UnregisterFileDevice(const char *filename);
|
||||||
status_t UnregisterFileDevice(partition_id device);
|
status_t UnregisterFileDevice(partition_id device);
|
||||||
// TODO: Add the respective syscalls. Also for Get{Device,Partition}ForPath()
|
|
||||||
|
|
||||||
bool VisitEachDevice(BDiskDeviceVisitor *visitor,
|
bool VisitEachDevice(BDiskDeviceVisitor *visitor,
|
||||||
BDiskDevice *device = NULL);
|
BDiskDevice *device = NULL);
|
||||||
@@ -117,22 +116,14 @@ public:
|
|||||||
bool VisitEachMountablePartition(BDiskDeviceVisitor *visitor,
|
bool VisitEachMountablePartition(BDiskDeviceVisitor *visitor,
|
||||||
BDiskDevice *device = NULL,
|
BDiskDevice *device = NULL,
|
||||||
BPartition **partition = NULL);
|
BPartition **partition = NULL);
|
||||||
bool VisitEachInitializablePartition(BDiskDeviceVisitor *visitor,
|
|
||||||
BDiskDevice *device = NULL,
|
|
||||||
BPartition **partition = NULL);
|
|
||||||
bool VisitEachPartitionablePartition(BDiskDeviceVisitor *visitor,
|
|
||||||
BDiskDevice *device = NULL,
|
|
||||||
BPartition **partition = NULL);
|
|
||||||
|
|
||||||
status_t GetDeviceWithID(partition_id id, BDiskDevice *device) const;
|
status_t GetDeviceWithID(partition_id id, BDiskDevice *device) const;
|
||||||
status_t GetPartitionWithID(partition_id id, BDiskDevice *device,
|
status_t GetPartitionWithID(partition_id id, BDiskDevice *device,
|
||||||
BPartition **partition) const;
|
BPartition **partition) const;
|
||||||
|
|
||||||
partition_id GetDeviceForPath(const char *filename, BDiskDevice *device,
|
status_t GetDeviceForPath(const char *filename, BDiskDevice *device);
|
||||||
bool registerIfFile = false);
|
status_t GetPartitionForPath(const char *filename, BDiskDevice *device,
|
||||||
partition_id GetPartitionForPath(const char *filename, BDiskDevice *device,
|
BPartition **partition);
|
||||||
BPartition **partition,
|
|
||||||
bool registerIfFile = false);
|
|
||||||
|
|
||||||
status_t StartWatching(BMessenger target,
|
status_t StartWatching(BMessenger target,
|
||||||
uint32 eventMask = B_DEVICE_REQUEST_ALL);
|
uint32 eventMask = B_DEVICE_REQUEST_ALL);
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ BDiskDeviceRoster::GetNextDevice(BDiskDevice *device)
|
|||||||
&neededSize);
|
&neededSize);
|
||||||
if (id < 0)
|
if (id < 0)
|
||||||
return id;
|
return id;
|
||||||
return device->_SetTo(id, neededSize);
|
return device->_SetTo(id, true, false, neededSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// RewindDevices
|
// RewindDevices
|
||||||
@@ -141,24 +141,27 @@ BDiskDeviceRoster::RewindActiveJobs()
|
|||||||
partition_id
|
partition_id
|
||||||
BDiskDeviceRoster::RegisterFileDevice(const char *filename)
|
BDiskDeviceRoster::RegisterFileDevice(const char *filename)
|
||||||
{
|
{
|
||||||
// not implemented
|
if (!filename)
|
||||||
return B_ERROR;
|
return B_BAD_VALUE;
|
||||||
|
return _kern_register_file_device(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnregisterFileDevice
|
// UnregisterFileDevice
|
||||||
status_t
|
status_t
|
||||||
BDiskDeviceRoster::UnregisterFileDevice(const char *filename)
|
BDiskDeviceRoster::UnregisterFileDevice(const char *filename)
|
||||||
{
|
{
|
||||||
// not implemented
|
if (!filename)
|
||||||
return B_ERROR;
|
return B_BAD_VALUE;
|
||||||
|
return _kern_unregister_file_device(-1, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnregisterFileDevice
|
// UnregisterFileDevice
|
||||||
status_t
|
status_t
|
||||||
BDiskDeviceRoster::UnregisterFileDevice(partition_id device)
|
BDiskDeviceRoster::UnregisterFileDevice(partition_id device)
|
||||||
{
|
{
|
||||||
// not implemented
|
if (device < 0)
|
||||||
return B_ERROR;
|
return B_BAD_VALUE;
|
||||||
|
return _kern_unregister_file_device(device, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisitEachDevice
|
// VisitEachDevice
|
||||||
@@ -334,66 +337,6 @@ BDiskDeviceRoster::VisitEachMountablePartition(BDiskDeviceVisitor *visitor,
|
|||||||
return terminatedEarly;
|
return terminatedEarly;
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisitEachInitializablePartition
|
|
||||||
/*! \brief Iterates through the all devices' partitions that are initializable.
|
|
||||||
|
|
||||||
The supplied visitor's Visit(BPartition*) is invoked for each
|
|
||||||
initializable partition.
|
|
||||||
If Visit() returns \c true, the iteration is terminated and this method
|
|
||||||
returns \c true. If supplied, \a device is set to the concerned device
|
|
||||||
and in \a partition the pointer to the partition object is returned.
|
|
||||||
|
|
||||||
\param visitor The visitor.
|
|
||||||
\param device Pointer to a pre-allocated BDiskDevice to be initialized
|
|
||||||
to the device at which the iteration was terminated.
|
|
||||||
May be \c NULL.
|
|
||||||
\param partition Pointer to a pre-allocated BPartition pointer to be set
|
|
||||||
to the partition at which the iteration was terminated.
|
|
||||||
May be \c NULL.
|
|
||||||
\return \c true, if the iteration was terminated, \c false otherwise.
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
BDiskDeviceRoster::VisitEachInitializablePartition(BDiskDeviceVisitor *visitor,
|
|
||||||
BDiskDevice *device,
|
|
||||||
BPartition **partition)
|
|
||||||
{
|
|
||||||
/* bool terminatedEarly = false;
|
|
||||||
if (visitor) {
|
|
||||||
struct InitializablePartitionFilter : public PartitionFilter {
|
|
||||||
virtual bool Filter(BPartition *partition, int32)
|
|
||||||
{ return !partition->CanInitialize(NULL); }
|
|
||||||
// TODO: ???
|
|
||||||
} filter;
|
|
||||||
PartitionFilterVisitor filterVisitor(visitor, &filter);
|
|
||||||
terminatedEarly
|
|
||||||
= VisitEachPartition(&filterVisitor, device, partition);
|
|
||||||
}
|
|
||||||
return terminatedEarly;
|
|
||||||
*/
|
|
||||||
// not implemented
|
|
||||||
return false;
|
|
||||||
// TODO: Clarify semantics.
|
|
||||||
}
|
|
||||||
|
|
||||||
// VisitEachPartitionablePartition
|
|
||||||
bool
|
|
||||||
BDiskDeviceRoster::VisitEachPartitionablePartition(BDiskDeviceVisitor *visitor,
|
|
||||||
BDiskDevice *device,
|
|
||||||
BPartition **partition)
|
|
||||||
{
|
|
||||||
bool terminatedEarly = false;
|
|
||||||
if (visitor) {
|
|
||||||
struct PartitionablePartitionFilter : public PartitionFilter {
|
|
||||||
virtual bool Filter(BPartition *partition, int32)
|
|
||||||
{ return partition->ContainsPartitioningSystem(); }
|
|
||||||
} filter;
|
|
||||||
PartitionFilterVisitor filterVisitor(visitor, &filter);
|
|
||||||
terminatedEarly
|
|
||||||
= VisitEachPartition(&filterVisitor, device, partition);
|
|
||||||
}
|
|
||||||
return terminatedEarly;
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDeviceWithID
|
// GetDeviceWithID
|
||||||
/*! \brief Returns a BDiskDevice for a given ID.
|
/*! \brief Returns a BDiskDevice for a given ID.
|
||||||
|
|
||||||
@@ -410,9 +353,9 @@ BDiskDeviceRoster::VisitEachPartitionablePartition(BDiskDeviceVisitor *visitor,
|
|||||||
status_t
|
status_t
|
||||||
BDiskDeviceRoster::GetDeviceWithID(int32 id, BDiskDevice *device) const
|
BDiskDeviceRoster::GetDeviceWithID(int32 id, BDiskDevice *device) const
|
||||||
{
|
{
|
||||||
// return _GetObjectWithID("device_id", id, device);
|
if (!device)
|
||||||
// not implemented
|
return B_BAD_VALUE;
|
||||||
return B_ERROR;
|
return device->_SetTo(id, true, false, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPartitionWithID
|
// GetPartitionWithID
|
||||||
@@ -436,35 +379,56 @@ status_t
|
|||||||
BDiskDeviceRoster::GetPartitionWithID(int32 id, BDiskDevice *device,
|
BDiskDeviceRoster::GetPartitionWithID(int32 id, BDiskDevice *device,
|
||||||
BPartition **partition) const
|
BPartition **partition) const
|
||||||
{
|
{
|
||||||
/* status_t error = (device && partition ? B_OK : B_BAD_VALUE);
|
if (!device || !partition)
|
||||||
if (error == B_OK)
|
return B_BAD_VALUE;
|
||||||
error = _GetObjectWithID("partition_id", id, device);
|
// download the device data
|
||||||
if (error == B_OK)
|
status_t error = device->_SetTo(id, false, false, 0);
|
||||||
*partition = device->PartitionWithID(id);
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
*/
|
// find the partition object
|
||||||
// not implemented
|
*partition = device->FindDescendant(id);
|
||||||
return B_ERROR;
|
if (!*partition) // should never happen!
|
||||||
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDeviceForPath
|
// GetDeviceForPath
|
||||||
partition_id
|
status_t
|
||||||
BDiskDeviceRoster::GetDeviceForPath(const char *filename, BDiskDevice *device,
|
BDiskDeviceRoster::GetDeviceForPath(const char *filename, BDiskDevice *device)
|
||||||
bool registerIfFile)
|
|
||||||
{
|
{
|
||||||
// not implemented
|
if (!filename || !device)
|
||||||
return B_ERROR;
|
return B_BAD_VALUE;
|
||||||
|
// get the device ID
|
||||||
|
size_t neededSize = 0;
|
||||||
|
partition_id id = _kern_find_disk_device(filename, &neededSize);
|
||||||
|
if (id < 0)
|
||||||
|
return id;
|
||||||
|
// download the device data
|
||||||
|
return device->_SetTo(id, true, false, neededSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPartitionForPath
|
// GetPartitionForPath
|
||||||
partition_id
|
status_t
|
||||||
BDiskDeviceRoster::GetPartitionForPath(const char *filename,
|
BDiskDeviceRoster::GetPartitionForPath(const char *filename,
|
||||||
BDiskDevice *device,
|
BDiskDevice *device,
|
||||||
BPartition **partition,
|
BPartition **partition)
|
||||||
bool registerIfFile)
|
|
||||||
{
|
{
|
||||||
// not implemented
|
if (!filename || !device || !partition)
|
||||||
return B_ERROR;
|
return B_BAD_VALUE;
|
||||||
|
// get the partition ID
|
||||||
|
size_t neededSize = 0;
|
||||||
|
partition_id id = _kern_find_partition(filename, &neededSize);
|
||||||
|
if (id < 0)
|
||||||
|
return id;
|
||||||
|
// download the device data
|
||||||
|
status_t error = device->_SetTo(id, false, false, neededSize);
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
// find the partition object
|
||||||
|
*partition = device->FindDescendant(id);
|
||||||
|
if (!*partition) // should never happen!
|
||||||
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartWatching
|
// StartWatching
|
||||||
|
|||||||
Reference in New Issue
Block a user