nfs4: Ignore superfluous slashes and get proper NFS4 share name

This commit is contained in:
Pawel Dziepak
2013-09-25 00:58:43 +02:00
parent 1f4aeff06a
commit 2b66a08acb
3 changed files with 34 additions and 24 deletions
@@ -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<RootInode*>(inode);
fs->fRoot = rootInode;
char* name = strrchr(fsPath, '/');
if (name != NULL) {
name++;
reinterpret_cast<RootInode*>(inode)->SetName(name);
} else if (fsPath[0] != '\0')
reinterpret_cast<RootInode*>(inode)->SetName(fsPath);
else {
char* address = serv->ID().UniversalAddress();
if (address != NULL)
reinterpret_cast<RootInode*>(inode)->SetName(address);
else
reinterpret_cast<RootInode*>(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<RootInode*>(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;
@@ -32,7 +32,8 @@ struct MountConfiguration {
class FileSystem : public DoublyLinkedListLinkImpl<FileSystem> {
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();
@@ -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;