From 2b66a08acb5ff1e603fc47b0c54fb5cfe8f1066c Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Wed, 25 Sep 2013 00:58:43 +0200 Subject: [PATCH] nfs4: Ignore superfluous slashes and get proper NFS4 share name --- .../kernel/file_systems/nfs4/FileSystem.cpp | 34 +++++++++---------- .../kernel/file_systems/nfs4/FileSystem.h | 3 +- .../file_systems/nfs4/kernel_interface.cpp | 21 ++++++++---- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/add-ons/kernel/file_systems/nfs4/FileSystem.cpp b/src/add-ons/kernel/file_systems/nfs4/FileSystem.cpp index 184e79a373..51c1600c25 100644 --- a/src/add-ons/kernel/file_systems/nfs4/FileSystem.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/FileSystem.cpp @@ -125,8 +125,8 @@ GetInodeNames(const char** root, const char* _path) status_t -FileSystem::Mount(FileSystem** _fs, RPC::Server* serv, const char* fsPath, - dev_t id, const MountConfiguration& configuration) +FileSystem::Mount(FileSystem** _fs, RPC::Server* serv, const char* serverName, + const char* fsPath, dev_t id, const MountConfiguration& configuration) { ASSERT(_fs != NULL); ASSERT(serv != NULL); @@ -222,23 +222,23 @@ FileSystem::Mount(FileSystem** _fs, RPC::Server* serv, const char* fsPath, result = Inode::CreateInode(fs, fi, &inode); if (result != B_OK) return result; + RootInode* rootInode = reinterpret_cast(inode); + fs->fRoot = rootInode; - char* name = strrchr(fsPath, '/'); - if (name != NULL) { - name++; - reinterpret_cast(inode)->SetName(name); - } else if (fsPath[0] != '\0') - reinterpret_cast(inode)->SetName(fsPath); - else { - char* address = serv->ID().UniversalAddress(); - if (address != NULL) - reinterpret_cast(inode)->SetName(address); - else - reinterpret_cast(inode)->SetName("NFS4 Share"); - free(address); - } + char* fsName = strdup(fsPath); + if (fsName == NULL) + return B_NO_MEMORY; + for (int i = strlen(fsName) - 1; i >= 0 && fsName[i] == '/'; i--) + fsName[i] = '\0'; - fs->fRoot = reinterpret_cast(inode); + char* name = strrchr(fsName, '/'); + if (name != NULL) + rootInode->SetName(name + 1); + else if (fsName[0] != '\0') + rootInode->SetName(fsName); + else + rootInode->SetName(serverName); + free(fsName); fs->NFSServer()->AddFileSystem(fs); *_fs = fs; diff --git a/src/add-ons/kernel/file_systems/nfs4/FileSystem.h b/src/add-ons/kernel/file_systems/nfs4/FileSystem.h index 5d16d8d477..5ca172d484 100644 --- a/src/add-ons/kernel/file_systems/nfs4/FileSystem.h +++ b/src/add-ons/kernel/file_systems/nfs4/FileSystem.h @@ -32,7 +32,8 @@ struct MountConfiguration { class FileSystem : public DoublyLinkedListLinkImpl { public: static status_t Mount(FileSystem** pfs, RPC::Server* serv, - const char* path, dev_t id, + const char* path, const char* serverName, + dev_t id, const MountConfiguration& configuration); ~FileSystem(); diff --git a/src/add-ons/kernel/file_systems/nfs4/kernel_interface.cpp b/src/add-ons/kernel/file_systems/nfs4/kernel_interface.cpp index b8f7294dff..2f26e42a62 100644 --- a/src/add-ons/kernel/file_systems/nfs4/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/kernel_interface.cpp @@ -74,8 +74,8 @@ CreateNFS4Server(RPC::Server* serv) // dirtime=X - attempt revalidate directory cache not more often than each X // seconds static status_t -ParseArguments(const char* _args, AddressResolver** address, char** _path, - MountConfiguration* conf) +ParseArguments(const char* _args, AddressResolver** address, char** _server, + char** _path, MountConfiguration* conf) { if (_args == NULL) return B_BAD_VALUE; @@ -94,12 +94,18 @@ ParseArguments(const char* _args, AddressResolver** address, char** _path, return B_MISMATCHED_VALUES; *path++ = '\0'; - *address = new AddressResolver(args); - if (*address == NULL) + *_server = strdup(args); + if (*_server == NULL) return B_NO_MEMORY; + *address = new AddressResolver(args); + if (*address == NULL) { + delete *_server; + return B_NO_MEMORY; + } *_path = strdup(path); if (*_path == NULL) { + delete *_server; delete *address; return B_NO_MEMORY; } @@ -176,7 +182,8 @@ nfs4_mount(fs_volume* volume, const char* device, uint32 flags, AddressResolver* resolver; MountConfiguration config; char* path; - result = ParseArguments(args, &resolver, &path, &config); + char* serverName; + result = ParseArguments(args, &resolver, &serverName, &path, &config); if (result != B_OK) return result; MemoryDeleter pathDeleter(path); @@ -188,7 +195,9 @@ nfs4_mount(fs_volume* volume, const char* device, uint32 flags, return result; FileSystem* fs; - result = FileSystem::Mount(&fs, server, path, volume->id, config); + result = FileSystem::Mount(&fs, server, serverName, path, volume->id, + config); + free(serverName); if (result != B_OK) { gRPCServerManager->Release(server); return result;