diff --git a/headers/private/kernel/fs/KPath.h b/headers/private/kernel/fs/KPath.h index be3decbffb..7a4685514d 100644 --- a/headers/private/kernel/fs/KPath.h +++ b/headers/private/kernel/fs/KPath.h @@ -13,15 +13,17 @@ namespace DiskDevice { class KPath { public: KPath(int32 bufferSize = B_PATH_NAME_LENGTH); - KPath(const char* path, int32 bufferSize = B_PATH_NAME_LENGTH); + KPath(const char* path, bool normalize = false, + int32 bufferSize = B_PATH_NAME_LENGTH); KPath(const KPath& other); ~KPath(); - status_t SetTo(const char *path, int32 bufferSize = B_PATH_NAME_LENGTH); + status_t SetTo(const char *path, bool normalize = false, + int32 bufferSize = B_PATH_NAME_LENGTH); status_t InitCheck() const; - status_t SetPath(const char *path); + status_t SetPath(const char *path, bool normalize = false); const char *Path() const; int32 Length() const; diff --git a/src/kernel/core/fs/KPath.cpp b/src/kernel/core/fs/KPath.cpp index 1b645b9834..dff26a73dd 100644 --- a/src/kernel/core/fs/KPath.cpp +++ b/src/kernel/core/fs/KPath.cpp @@ -4,6 +4,8 @@ #include #include +#include +#include // debugging #define DBG(x) @@ -21,13 +23,13 @@ KPath::KPath(int32 bufferSize) } // constructor -KPath::KPath(const char* path, int32 bufferSize) +KPath::KPath(const char* path, bool normalize, int32 bufferSize) : fBuffer(NULL), fBufferSize(0), fPathLength(0), fLocked(false) { - SetTo(path, bufferSize); + SetTo(path, normalize, bufferSize); } // copy constructor @@ -48,7 +50,7 @@ KPath::~KPath() // SetTo status_t -KPath::SetTo(const char* path, int32 bufferSize) +KPath::SetTo(const char* path, bool normalize, int32 bufferSize) { if (bufferSize <= 0) bufferSize = B_PATH_NAME_LENGTH; @@ -69,7 +71,7 @@ KPath::SetTo(const char* path, int32 bufferSize) fBufferSize = bufferSize; fBuffer[0] = '\0'; } - return SetPath(path); + return SetPath(path, normalize); } // InitCheck @@ -81,17 +83,29 @@ KPath::InitCheck() const // SetPath status_t -KPath::SetPath(const char *path) +KPath::SetPath(const char *path, bool normalize) { if (!fBuffer) return B_NO_INIT; if (path) { - int32 len = strlen(path); - if (len >= fBufferSize) - return B_BUFFER_OVERFLOW; - memcpy(fBuffer, path, len + 1); - fPathLength = len; - _ChopTrailingSlashes(); + if (normalize) { + // normalize path + status_t error = vfs_normalize_path(path, fBuffer, fBufferSize, + team_get_kernel_team_id() == team_get_current_team_id()); + if (error != B_OK) { + SetPath(NULL); + return error; + } + fPathLength = strlen(fBuffer); + } else { + // don't normalize path + int32 len = strlen(path); + if (len >= fBufferSize) + return B_BUFFER_OVERFLOW; + memcpy(fBuffer, path, len + 1); + fPathLength = len; + _ChopTrailingSlashes(); + } } else { fBuffer[0] = '\0'; fPathLength = 0;