diff --git a/src/add-ons/kernel/file_systems/nfs4/FileInfo.cpp b/src/add-ons/kernel/file_systems/nfs4/FileInfo.cpp index 4838fa4e6f..43bb3b4604 100644 --- a/src/add-ons/kernel/file_systems/nfs4/FileInfo.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/FileInfo.cpp @@ -13,8 +13,10 @@ #include "Request.h" -static status_t -ParsePath(RequestBuilder& req, uint32& count, const char* _path) +// TODO: This function probably needs more strict checking against incorrect +// paths. Correct handling of '..' and '.' also may be useful. +status_t +FileInfo::ParsePath(RequestBuilder& req, uint32& count, const char* _path) { char* path = strdup(_path); if (path == NULL) diff --git a/src/add-ons/kernel/file_systems/nfs4/FileInfo.h b/src/add-ons/kernel/file_systems/nfs4/FileInfo.h index a250262afe..169967a872 100644 --- a/src/add-ons/kernel/file_systems/nfs4/FileInfo.h +++ b/src/add-ons/kernel/file_systems/nfs4/FileInfo.h @@ -28,6 +28,7 @@ struct Filehandle { class Filesystem; +class RequestBuilder; // Complete information needed to identify a file in any situation. // Unfortunately just a filehandle is not enough even when they are persistent @@ -46,6 +47,9 @@ struct FileInfo { inline FileInfo& operator=(const FileInfo& fi); status_t UpdateFileHandles(Filesystem* fs); + + static status_t ParsePath(RequestBuilder& req, uint32& count, + const char* _path); }; struct FilesystemId { diff --git a/src/add-ons/kernel/file_systems/nfs4/Filesystem.cpp b/src/add-ons/kernel/file_systems/nfs4/Filesystem.cpp index 61b3ce705e..df8b169896 100644 --- a/src/add-ons/kernel/file_systems/nfs4/Filesystem.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/Filesystem.cpp @@ -73,30 +73,10 @@ Filesystem::Mount(Filesystem** pfs, RPC::Server* serv, const char* fsPath, req.PutRootFH(); - // Better way of doing this will be needed uint32 lookupCount = 0; - char* path = strdup(fsPath); - char* pathStart = path; - char* pathEnd; - while (pathStart != NULL && pathStart[0] != '\0') { - pathEnd = strpbrk(pathStart, "/"); - if (pathEnd != NULL) - *pathEnd = '\0'; - if (pathEnd == pathStart) { - pathStart++; - continue; - } - - req.LookUp(pathStart); - - if (pathEnd != NULL && pathEnd[1] != '\0') - pathStart = pathEnd + 1; - else - pathStart = NULL; - - lookupCount++; - } - free(path); + status_t result = FileInfo::ParsePath(req, lookupCount, fsPath); + if (result != B_OK) + return result; req.GetFH(); req.Access(); @@ -105,7 +85,7 @@ Filesystem::Mount(Filesystem** pfs, RPC::Server* serv, const char* fsPath, FATTR4_FSID, FATTR4_FS_LOCATIONS }; req.GetAttr(attr, sizeof(attr) / sizeof(Attribute)); - status_t result = request.Send(); + result = request.Send(); if (result != B_OK) return result;