KPartition::GetPath() now uses the new KPath class, which makes it more convenient to use.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9545 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -17,6 +17,7 @@ class KDiskDevice;
|
|||||||
class KDiskSystem;
|
class KDiskSystem;
|
||||||
class KPartitionListener;
|
class KPartitionListener;
|
||||||
class KPartitionVisitor;
|
class KPartitionVisitor;
|
||||||
|
class KPath;
|
||||||
class KPhysicalPartition;
|
class KPhysicalPartition;
|
||||||
class KShadowPartition;
|
class KShadowPartition;
|
||||||
|
|
||||||
@@ -101,7 +102,7 @@ public:
|
|||||||
virtual void SetID(partition_id id);
|
virtual void SetID(partition_id id);
|
||||||
partition_id ID() const;
|
partition_id ID() const;
|
||||||
|
|
||||||
virtual status_t GetPath(char *path) const;
|
virtual status_t GetPath(KPath *path) const;
|
||||||
// no setter (see BDiskDevice) -- built on the fly
|
// no setter (see BDiskDevice) -- built on the fly
|
||||||
|
|
||||||
void SetVolumeID(dev_t volumeID);
|
void SetVolumeID(dev_t volumeID);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include <KPartition.h>
|
#include <KPartition.h>
|
||||||
#include <KPartitionListener.h>
|
#include <KPartitionListener.h>
|
||||||
#include <KPartitionVisitor.h>
|
#include <KPartitionVisitor.h>
|
||||||
|
#include <KPath.h>
|
||||||
#include <VectorSet.h>
|
#include <VectorSet.h>
|
||||||
|
|
||||||
#include "UserDataWriter.h"
|
#include "UserDataWriter.h"
|
||||||
@@ -145,18 +146,7 @@ KPartition::PrepareForDeletion()
|
|||||||
status_t
|
status_t
|
||||||
KPartition::Open(int flags, int *fd)
|
KPartition::Open(int flags, int *fd)
|
||||||
{
|
{
|
||||||
if (!fd)
|
return B_BAD_VALUE;
|
||||||
return B_BAD_VALUE;
|
|
||||||
// get the path
|
|
||||||
char path[B_PATH_NAME_LENGTH];
|
|
||||||
status_t error = GetPath(path);
|
|
||||||
if (error != B_OK)
|
|
||||||
return error;
|
|
||||||
// open the device
|
|
||||||
*fd = open(path, flags);
|
|
||||||
if (*fd < 0)
|
|
||||||
return errno;
|
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PublishDevice
|
// PublishDevice
|
||||||
@@ -477,33 +467,39 @@ KPartition::ID() const
|
|||||||
|
|
||||||
// GetPath
|
// GetPath
|
||||||
status_t
|
status_t
|
||||||
KPartition::GetPath(char *path) const
|
KPartition::GetPath(KPath *path) const
|
||||||
{
|
{
|
||||||
// For a KDiskDevice this version is never invoked, so the check for
|
// For a KDiskDevice this version is never invoked, so the check for
|
||||||
// Parent() is correct.
|
// Parent() is correct.
|
||||||
if (!path || !Parent() || Index() < 0)
|
if (!path || path->InitCheck() != B_OK || !Parent() || Index() < 0)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
// get the parent's path
|
// get the parent's path
|
||||||
status_t error = Parent()->GetPath(path);
|
status_t error = Parent()->GetPath(path);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
// check length for safety
|
// check length for safety
|
||||||
int32 len = strlen(path);
|
int32 len = path->Length();
|
||||||
if (len >= B_PATH_NAME_LENGTH - 10)
|
if (len >= path->BufferSize() - 10)
|
||||||
return B_NAME_TOO_LONG;
|
return B_NAME_TOO_LONG;
|
||||||
|
char* buffer = path->LockBuffer();
|
||||||
|
if (!buffer)
|
||||||
|
return B_ERROR;
|
||||||
if (Parent()->IsDevice()) {
|
if (Parent()->IsDevice()) {
|
||||||
// Our parent is a device, so we replace `raw' by our index.
|
// Our parent is a device, so we replace `raw' by our index.
|
||||||
int32 leafLen = strlen("/raw");
|
int32 leafLen = strlen("/raw");
|
||||||
if (len <= leafLen || strcmp(path + len - leafLen, "/raw"))
|
if (len <= leafLen || strcmp(path->Path() + len - leafLen, "/raw")) {
|
||||||
return B_ERROR;
|
error = B_ERROR;
|
||||||
|
} else {
|
||||||
// TODO: For the time being the name is "obos_*" to not interfere with R5's
|
// TODO: For the time being the name is "obos_*" to not interfere with R5's
|
||||||
// names.
|
// names.
|
||||||
// sprintf(path + len - leafLen + 1, "%ld", Index());
|
// sprintf(path + len - leafLen + 1, "%ld", Index());
|
||||||
sprintf(path + len - leafLen + 1, "obos_%ld", Index());
|
sprintf(buffer + len - leafLen + 1, "obos_%ld", Index());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Our parent is a normal partition, no device: Append our index.
|
// Our parent is a normal partition, no device: Append our index.
|
||||||
sprintf(path + len, "_%ld", Index());
|
sprintf(buffer + len, "_%ld", Index());
|
||||||
}
|
}
|
||||||
|
path->UnlockBuffer();
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1033,10 +1029,10 @@ KPartition::Dump(bool deep, int32 level)
|
|||||||
return;
|
return;
|
||||||
char prefix[256];
|
char prefix[256];
|
||||||
sprintf(prefix, "%*s%*s", (int)level, "", (int)level, "");
|
sprintf(prefix, "%*s%*s", (int)level, "", (int)level, "");
|
||||||
char path[B_PATH_NAME_LENGTH];
|
KPath path;
|
||||||
GetPath(path);
|
GetPath(&path);
|
||||||
if (level > 0)
|
if (level > 0)
|
||||||
OUT("%spartition %ld: %s\n", prefix, ID(), path);
|
OUT("%spartition %ld: %s\n", prefix, ID(), path.Path());
|
||||||
OUT("%s offset: %lld\n", prefix, Offset());
|
OUT("%s offset: %lld\n", prefix, Offset());
|
||||||
OUT("%s size: %lld (%.2f MB)\n", prefix, Size(), Size() / (1024.0*1024));
|
OUT("%s size: %lld (%.2f MB)\n", prefix, Size(), Size() / (1024.0*1024));
|
||||||
OUT("%s content size: %lld\n", prefix, ContentSize());
|
OUT("%s content size: %lld\n", prefix, ContentSize());
|
||||||
|
|||||||
Reference in New Issue
Block a user