Moved getting a partition's future mount point into a separate function, so it can be reused by mountvolume.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9712 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2004-11-01 17:02:12 +00:00
parent f260cedb5a
commit 419458bc96
3 changed files with 60 additions and 31 deletions

View File

@ -10,6 +10,7 @@
#include <DiskDeviceVisitor.h>
class BMessenger;
class BPath;
namespace BPrivate {
@ -45,10 +46,14 @@ 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

@ -5,7 +5,10 @@
#include <DiskDevicePrivate.h>
#include <DiskDevice.h>
#include <Entry.h>
#include <Partition.h>
#include <Path.h>
#include <String.h>
// PartitionFilterVisitor
@ -37,6 +40,8 @@ PartitionFilterVisitor::Visit(BPartition *partition, int32 level)
}
// #pragma mark -
// IDFinderVisitor
// constructor
@ -60,3 +65,46 @@ 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

@ -387,7 +387,7 @@ status_t
BPartition::Mount(const char *mountPoint, uint32 mountFlags,
const char *parameters)
{
if (!fPartitionData || IsMounted())
if (!fPartitionData || IsMounted() || !ContainsFileSystem())
return B_BAD_VALUE;
// get the partition path
@ -398,38 +398,14 @@ BPartition::Mount(const char *mountPoint, uint32 mountFlags,
// create a mount point, if none is given
bool deleteMountPoint = false;
BString mountPointPath;
BPath mountPointPath;
if (!mountPoint) {
// 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 '/'
mountPointPath = volumeName;
mountPointPath.ReplaceAll('/', '-');
mountPointPath.Insert("/", 0);
// make the name unique
BString basePath(mountPointPath);
int counter = 1;
while (true) {
BEntry entry;
error = entry.SetTo(mountPointPath.String());
// get a unique mount point
error = get_unique_partition_mount_point(this, &mountPointPath);
if (error != B_OK)
return error;
if (!entry.Exists())
break;
mountPointPath = basePath;
mountPointPath << counter;
counter++;
}
mountPoint = mountPointPath.String();
mountPoint = mountPointPath.Path();
// create the directory
if (mkdir(mountPoint, S_IRWXU | S_IRWXG | S_IRWXO) < 0)