diff --git a/headers/private/storage/DiskDevicePrivate.h b/headers/private/storage/DiskDevicePrivate.h index 3939a003f5..02175b2eac 100644 --- a/headers/private/storage/DiskDevicePrivate.h +++ b/headers/private/storage/DiskDevicePrivate.h @@ -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 diff --git a/headers/private/storage/Partition.h b/headers/private/storage/Partition.h index df19960d61..ea05e38f9b 100644 --- a/headers/private/storage/Partition.h +++ b/headers/private/storage/Partition.h @@ -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); diff --git a/src/kits/storage/DiskDevicePrivate.cpp b/src/kits/storage/DiskDevicePrivate.cpp index 0510d6f7ca..2805a88f29 100644 --- a/src/kits/storage/DiskDevicePrivate.cpp +++ b/src/kits/storage/DiskDevicePrivate.cpp @@ -5,10 +5,7 @@ #include #include -#include #include -#include -#include // 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()); -} - diff --git a/src/kits/storage/Partition.cpp b/src/kits/storage/Partition.cpp index fdcd692b3d..1f1e30d687 100644 --- a/src/kits/storage/Partition.cpp +++ b/src/kits/storage/Partition.cpp @@ -10,6 +10,7 @@ #include +#include #include #include #include @@ -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;