Changed my mind. Now BPartition has a method to get the mount point of the partition, respectively a potential mount point, for partitions not yet mounted.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9713 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2004-11-01 19:38:47 +00:00
parent 419458bc96
commit 8370cac7f6
4 changed files with 68 additions and 51 deletions

View File

@ -46,14 +46,10 @@ private:
partition_id fID;
};
status_t get_unique_partition_mount_point(BPartition *partition,
BPath *mountPoint);
} // namespace BPrivate
using BPrivate::PartitionFilter;
using BPrivate::PartitionFilterVisitor;
using BPrivate::IDFinderVisitor;
using BPrivate::get_unique_partition_mount_point;
#endif // _DISK_DEVICE_PRIVATE_H

View File

@ -17,6 +17,7 @@ class BDiskDeviceParameterEditor;
class BDiskDeviceVisitor;
class BDiskSystem;
class BPartitioningInfo;
class BPath;
class BVolume;
struct user_partition_data;
@ -52,6 +53,7 @@ public:
virtual status_t GetPath(BPath *path) const;
status_t GetVolume(BVolume *volume) const;
status_t GetIcon(BBitmap *icon, icon_size which) const;
status_t GetMountPoint(BPath *mountPoint) const;
status_t Mount(const char *mountPoint = NULL, uint32 mountFlags = 0,
const char *parameters = NULL);

View File

@ -5,10 +5,7 @@
#include <DiskDevicePrivate.h>
#include <DiskDevice.h>
#include <Entry.h>
#include <Partition.h>
#include <Path.h>
#include <String.h>
// PartitionFilterVisitor
@ -65,46 +62,3 @@ IDFinderVisitor::Visit(BPartition *partition, int32 level)
return (partition->ID() == fID);
}
// #pragma mark -
// get_unique_partition_mount_point
status_t
BPrivate::get_unique_partition_mount_point(BPartition *partition,
BPath *mountPoint)
{
if (!partition || !mountPoint)
return B_BAD_VALUE;
// get the volume name
const char *volumeName = partition->ContentName();
if (volumeName || strlen(volumeName) == 0)
volumeName = partition->Name();
if (!volumeName || strlen(volumeName) == 0)
volumeName = "unnamed volume";
// construct a path name from the volume name
// replace '/'s and prepend a '/'
BString mountPointPath(volumeName);
mountPointPath.ReplaceAll('/', '-');
mountPointPath.Insert("/", 0);
// make the name unique
BString basePath(mountPointPath);
int counter = 1;
while (true) {
BEntry entry;
status_t error = entry.SetTo(mountPointPath.String());
if (error != B_OK)
return error;
if (!entry.Exists())
break;
mountPointPath = basePath;
mountPointPath << counter;
counter++;
}
return mountPoint->SetTo(mountPointPath.String());
}

View File

@ -10,6 +10,7 @@
#include <syscalls.h>
#include <Directory.h>
#include <DiskDevice.h>
#include <DiskDevicePrivate.h>
#include <DiskDeviceVisitor.h>
@ -365,6 +366,70 @@ BPartition::GetIcon(BBitmap *icon, icon_size which) const
return B_ERROR;
}
// GetMountPoint
/*! \brief Returns the mount point for the partition.
If the partition is mounted this is the actual mount point. If it is not
mounted, but contains a file system, derived from the partition name
the name for a not yet existing directory in the root directory is
constructed and the path to it returned.
For partitions not containing a file system the method returns an error.
\param mountPoint Pointer to the path to be set to refer the mount point
(respectively potential mount point) of the partition.
\return \c B_OK, if everything went fine, an error code otherwise.
*/
status_t
BPartition::GetMountPoint(BPath *mountPoint) const
{
if (!mountPoint || !ContainsFileSystem())
return B_BAD_VALUE;
// if the partition is mounted, return the actual mount point
BVolume volume;
if (GetVolume(&volume) == B_OK) {
BDirectory dir;
status_t error = volume.GetRootDirectory(&dir);
if (error == B_OK)
error = mountPoint->SetTo(&dir, NULL);
return error;
}
// partition not mounted
// get the volume name
const char *volumeName = ContentName();
if (volumeName || strlen(volumeName) == 0)
volumeName = Name();
if (!volumeName || strlen(volumeName) == 0)
volumeName = "unnamed volume";
// construct a path name from the volume name
// replace '/'s and prepend a '/'
BString mountPointPath(volumeName);
mountPointPath.ReplaceAll('/', '-');
mountPointPath.Insert("/", 0);
// make the name unique
BString basePath(mountPointPath);
int counter = 1;
while (true) {
BEntry entry;
status_t error = entry.SetTo(mountPointPath.String());
if (error != B_OK)
return error;
if (!entry.Exists())
break;
mountPointPath = basePath;
mountPointPath << counter;
counter++;
}
return mountPoint->SetTo(mountPointPath.String());
}
// Mount
/*! \brief Mounts the volume.
@ -401,7 +466,7 @@ BPartition::Mount(const char *mountPoint, uint32 mountFlags,
BPath mountPointPath;
if (!mountPoint) {
// get a unique mount point
error = get_unique_partition_mount_point(this, &mountPointPath);
error = GetMountPoint(&mountPointPath);
if (error != B_OK)
return error;