From a58e2ed8f8bc9b786fa0d83fbe064d0eb686f174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 27 Oct 2008 15:33:37 +0000 Subject: [PATCH] * 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 --- headers/private/storage/DiskDeviceRoster.h | 8 +++ .../storage/disk_device/DiskDeviceRoster.cpp | 66 ++++++++++++++++--- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/headers/private/storage/DiskDeviceRoster.h b/headers/private/storage/DiskDeviceRoster.h index 17236ae1a1..b7d78df6bd 100644 --- a/headers/private/storage/DiskDeviceRoster.h +++ b/headers/private/storage/DiskDeviceRoster.h @@ -18,6 +18,7 @@ class BDiskDeviceVisitor; class BDiskScannerPartitionAddOn; class BDiskSystem; class BPartition; +class BVolume; namespace BPrivate { class AddOnImage; @@ -115,6 +116,13 @@ public: BDiskDevice* device = 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, BDiskDevice* device) const; status_t GetPartitionWithID(partition_id id, diff --git a/src/kits/storage/disk_device/DiskDeviceRoster.cpp b/src/kits/storage/disk_device/DiskDeviceRoster.cpp index 54aba98ca9..c7c1130173 100644 --- a/src/kits/storage/disk_device/DiskDeviceRoster.cpp +++ b/src/kits/storage/disk_device/DiskDeviceRoster.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -186,7 +187,7 @@ BDiskDeviceRoster::UnregisterFileDevice(partition_id device) */ bool BDiskDeviceRoster::VisitEachDevice(BDiskDeviceVisitor *visitor, - BDiskDevice *device) + BDiskDevice *device) { bool terminatedEarly = false; if (visitor) { @@ -224,8 +225,7 @@ BDiskDeviceRoster::VisitEachDevice(BDiskDeviceVisitor *visitor, */ bool BDiskDeviceRoster::VisitEachPartition(BDiskDeviceVisitor *visitor, - BDiskDevice *device, - BPartition **partition) + BDiskDevice *device, BPartition **partition) { bool terminatedEarly = false; if (visitor) { @@ -270,8 +270,7 @@ BDiskDeviceRoster::VisitEachPartition(BDiskDeviceVisitor *visitor, */ bool BDiskDeviceRoster::VisitEachMountedPartition(BDiskDeviceVisitor *visitor, - BDiskDevice *device, - BPartition **partition) + BDiskDevice *device, BPartition **partition) { bool terminatedEarly = false; if (visitor) { @@ -306,8 +305,7 @@ BDiskDeviceRoster::VisitEachMountedPartition(BDiskDeviceVisitor *visitor, */ bool BDiskDeviceRoster::VisitEachMountablePartition(BDiskDeviceVisitor *visitor, - BDiskDevice *device, - BPartition **partition) + BDiskDevice *device, BPartition **partition) { bool terminatedEarly = false; if (visitor) { @@ -322,7 +320,59 @@ BDiskDeviceRoster::VisitEachMountablePartition(BDiskDeviceVisitor *visitor, 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. The supplied \a device is initialized to the device identified by \a id.