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:
@@ -10,6 +10,7 @@
|
|||||||
#include <DiskDeviceVisitor.h>
|
#include <DiskDeviceVisitor.h>
|
||||||
|
|
||||||
class BMessenger;
|
class BMessenger;
|
||||||
|
class BPath;
|
||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
@@ -45,10 +46,14 @@ private:
|
|||||||
partition_id fID;
|
partition_id fID;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
status_t get_unique_partition_mount_point(BPartition *partition,
|
||||||
|
BPath *mountPoint);
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|
||||||
using BPrivate::PartitionFilter;
|
using BPrivate::PartitionFilter;
|
||||||
using BPrivate::PartitionFilterVisitor;
|
using BPrivate::PartitionFilterVisitor;
|
||||||
using BPrivate::IDFinderVisitor;
|
using BPrivate::IDFinderVisitor;
|
||||||
|
using BPrivate::get_unique_partition_mount_point;
|
||||||
|
|
||||||
#endif // _DISK_DEVICE_PRIVATE_H
|
#endif // _DISK_DEVICE_PRIVATE_H
|
||||||
|
|||||||
@@ -5,7 +5,10 @@
|
|||||||
|
|
||||||
#include <DiskDevicePrivate.h>
|
#include <DiskDevicePrivate.h>
|
||||||
#include <DiskDevice.h>
|
#include <DiskDevice.h>
|
||||||
|
#include <Entry.h>
|
||||||
#include <Partition.h>
|
#include <Partition.h>
|
||||||
|
#include <Path.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
// PartitionFilterVisitor
|
// PartitionFilterVisitor
|
||||||
|
|
||||||
@@ -37,6 +40,8 @@ PartitionFilterVisitor::Visit(BPartition *partition, int32 level)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
// IDFinderVisitor
|
// IDFinderVisitor
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
@@ -60,3 +65,46 @@ IDFinderVisitor::Visit(BPartition *partition, int32 level)
|
|||||||
return (partition->ID() == fID);
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -387,7 +387,7 @@ status_t
|
|||||||
BPartition::Mount(const char *mountPoint, uint32 mountFlags,
|
BPartition::Mount(const char *mountPoint, uint32 mountFlags,
|
||||||
const char *parameters)
|
const char *parameters)
|
||||||
{
|
{
|
||||||
if (!fPartitionData || IsMounted())
|
if (!fPartitionData || IsMounted() || !ContainsFileSystem())
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
// get the partition path
|
// get the partition path
|
||||||
@@ -398,38 +398,14 @@ BPartition::Mount(const char *mountPoint, uint32 mountFlags,
|
|||||||
|
|
||||||
// create a mount point, if none is given
|
// create a mount point, if none is given
|
||||||
bool deleteMountPoint = false;
|
bool deleteMountPoint = false;
|
||||||
BString mountPointPath;
|
BPath mountPointPath;
|
||||||
if (!mountPoint) {
|
if (!mountPoint) {
|
||||||
// get the volume name
|
// get a unique mount point
|
||||||
const char *volumeName = ContentName();
|
error = get_unique_partition_mount_point(this, &mountPointPath);
|
||||||
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());
|
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
if (!entry.Exists())
|
mountPoint = mountPointPath.Path();
|
||||||
break;
|
|
||||||
mountPointPath = basePath;
|
|
||||||
mountPointPath << counter;
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
mountPoint = mountPointPath.String();
|
|
||||||
|
|
||||||
// create the directory
|
// create the directory
|
||||||
if (mkdir(mountPoint, S_IRWXU | S_IRWXG | S_IRWXO) < 0)
|
if (mkdir(mountPoint, S_IRWXU | S_IRWXG | S_IRWXO) < 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user