* Added functions FindPartitionByVolume() and FindPartitionByMountPoint()
that conveniently bridge BVolumes/mount points with BPartitions. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28346 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -18,6 +18,7 @@ class BDiskDeviceVisitor;
|
|||||||
class BDiskScannerPartitionAddOn;
|
class BDiskScannerPartitionAddOn;
|
||||||
class BDiskSystem;
|
class BDiskSystem;
|
||||||
class BPartition;
|
class BPartition;
|
||||||
|
class BVolume;
|
||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
class AddOnImage;
|
class AddOnImage;
|
||||||
@@ -115,6 +116,13 @@ public:
|
|||||||
BDiskDevice* device = NULL,
|
BDiskDevice* device = NULL,
|
||||||
BPartition** _partition = NULL);
|
BPartition** _partition = NULL);
|
||||||
|
|
||||||
|
status_t FindPartitionByVolume(BVolume* volume,
|
||||||
|
BDiskDevice* device,
|
||||||
|
BPartition** _partition);
|
||||||
|
status_t FindPartitionByMountPoint(const char* mountPoint,
|
||||||
|
BDiskDevice* device,
|
||||||
|
BPartition** _partition);
|
||||||
|
|
||||||
status_t GetDeviceWithID(partition_id id,
|
status_t GetDeviceWithID(partition_id id,
|
||||||
BDiskDevice* device) const;
|
BDiskDevice* device) const;
|
||||||
status_t GetPartitionWithID(partition_id id,
|
status_t GetPartitionWithID(partition_id id,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Partition.h>
|
#include <Partition.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
#include <Volume.h>
|
||||||
|
|
||||||
#include <syscalls.h>
|
#include <syscalls.h>
|
||||||
#include <ddm_userland_interface_defs.h>
|
#include <ddm_userland_interface_defs.h>
|
||||||
@@ -186,7 +187,7 @@ BDiskDeviceRoster::UnregisterFileDevice(partition_id device)
|
|||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
BDiskDeviceRoster::VisitEachDevice(BDiskDeviceVisitor *visitor,
|
BDiskDeviceRoster::VisitEachDevice(BDiskDeviceVisitor *visitor,
|
||||||
BDiskDevice *device)
|
BDiskDevice *device)
|
||||||
{
|
{
|
||||||
bool terminatedEarly = false;
|
bool terminatedEarly = false;
|
||||||
if (visitor) {
|
if (visitor) {
|
||||||
@@ -224,8 +225,7 @@ BDiskDeviceRoster::VisitEachDevice(BDiskDeviceVisitor *visitor,
|
|||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
BDiskDeviceRoster::VisitEachPartition(BDiskDeviceVisitor *visitor,
|
BDiskDeviceRoster::VisitEachPartition(BDiskDeviceVisitor *visitor,
|
||||||
BDiskDevice *device,
|
BDiskDevice *device, BPartition **partition)
|
||||||
BPartition **partition)
|
|
||||||
{
|
{
|
||||||
bool terminatedEarly = false;
|
bool terminatedEarly = false;
|
||||||
if (visitor) {
|
if (visitor) {
|
||||||
@@ -270,8 +270,7 @@ BDiskDeviceRoster::VisitEachPartition(BDiskDeviceVisitor *visitor,
|
|||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
BDiskDeviceRoster::VisitEachMountedPartition(BDiskDeviceVisitor *visitor,
|
BDiskDeviceRoster::VisitEachMountedPartition(BDiskDeviceVisitor *visitor,
|
||||||
BDiskDevice *device,
|
BDiskDevice *device, BPartition **partition)
|
||||||
BPartition **partition)
|
|
||||||
{
|
{
|
||||||
bool terminatedEarly = false;
|
bool terminatedEarly = false;
|
||||||
if (visitor) {
|
if (visitor) {
|
||||||
@@ -306,8 +305,7 @@ BDiskDeviceRoster::VisitEachMountedPartition(BDiskDeviceVisitor *visitor,
|
|||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
BDiskDeviceRoster::VisitEachMountablePartition(BDiskDeviceVisitor *visitor,
|
BDiskDeviceRoster::VisitEachMountablePartition(BDiskDeviceVisitor *visitor,
|
||||||
BDiskDevice *device,
|
BDiskDevice *device, BPartition **partition)
|
||||||
BPartition **partition)
|
|
||||||
{
|
{
|
||||||
bool terminatedEarly = false;
|
bool terminatedEarly = false;
|
||||||
if (visitor) {
|
if (visitor) {
|
||||||
@@ -322,7 +320,59 @@ BDiskDeviceRoster::VisitEachMountablePartition(BDiskDeviceVisitor *visitor,
|
|||||||
return terminatedEarly;
|
return terminatedEarly;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDeviceWithID
|
|
||||||
|
/*! \brief Finds a BPartition by BVolume.
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
BDiskDeviceRoster::FindPartitionByVolume(BVolume* volume, BDiskDevice* device,
|
||||||
|
BPartition** _partition)
|
||||||
|
{
|
||||||
|
class FindPartitionVisitor : public BDiskDeviceVisitor {
|
||||||
|
public:
|
||||||
|
FindPartitionVisitor(dev_t volume)
|
||||||
|
:
|
||||||
|
fVolume(volume)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool Visit(BDiskDevice* device)
|
||||||
|
{
|
||||||
|
return Visit(device, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool Visit(BPartition* partition, int32 level)
|
||||||
|
{
|
||||||
|
BVolume volume;
|
||||||
|
return partition->GetVolume(&volume) == B_OK
|
||||||
|
&& volume.Device() == fVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
dev_t fVolume;
|
||||||
|
} visitor(volume->Device());
|
||||||
|
|
||||||
|
if (VisitEachMountedPartition(&visitor, device, _partition))
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \brief Finds a BPartition by mount path.
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
BDiskDeviceRoster::FindPartitionByMountPoint(const char* mountPoint,
|
||||||
|
BDiskDevice* device, BPartition** _partition)
|
||||||
|
{
|
||||||
|
BVolume volume(dev_for_path(mountPoint));
|
||||||
|
if (volume.InitCheck() == B_OK
|
||||||
|
&& FindPartitionByVolume(&volume, device, _partition))
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Returns a BDiskDevice for a given ID.
|
/*! \brief Returns a BDiskDevice for a given ID.
|
||||||
|
|
||||||
The supplied \a device is initialized to the device identified by \a id.
|
The supplied \a device is initialized to the device identified by \a id.
|
||||||
|
|||||||
Reference in New Issue
Block a user