nfs4: Add stub Inode class, fix and extend Filesystem class
Additionally PUTFH support is added to both RequestBuilder and ReplyInterpreter.
This commit is contained in:
@@ -14,8 +14,12 @@
|
|||||||
#include "ReplyInterpreter.h"
|
#include "ReplyInterpreter.h"
|
||||||
#include "RequestBuilder.h"
|
#include "RequestBuilder.h"
|
||||||
|
|
||||||
|
#include "Inode.h"
|
||||||
|
|
||||||
|
|
||||||
Filesystem::Filesystem()
|
Filesystem::Filesystem()
|
||||||
|
:
|
||||||
|
fId(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +36,7 @@ Filesystem::Mount(Filesystem** pfs, RPC::Server* serv, const char* fsPath)
|
|||||||
req.PutRootFH();
|
req.PutRootFH();
|
||||||
|
|
||||||
// Better way of doing this will be needed
|
// Better way of doing this will be needed
|
||||||
uint32 lookupCount;
|
uint32 lookupCount = 0;
|
||||||
char* path = strdup(fsPath);
|
char* path = strdup(fsPath);
|
||||||
char* pathStart = path;
|
char* pathStart = path;
|
||||||
char* pathEnd;
|
char* pathEnd;
|
||||||
@@ -104,7 +108,7 @@ Filesystem::Mount(Filesystem** pfs, RPC::Server* serv, const char* fsPath)
|
|||||||
return B_UNSUPPORTED;
|
return B_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
Filesystem* fs = new Filesystem;
|
Filesystem* fs = new(std::nothrow) Filesystem;
|
||||||
fs->fFHExpiryType = values[0].fData.fValue32;
|
fs->fFHExpiryType = values[0].fData.fValue32;
|
||||||
memcpy(&fs->fRootFH, &fh, sizeof(Filehandle));
|
memcpy(&fs->fRootFH, &fh, sizeof(Filehandle));
|
||||||
fs->fServer = serv;
|
fs->fServer = serv;
|
||||||
@@ -116,3 +120,10 @@ Filesystem::Mount(Filesystem** pfs, RPC::Server* serv, const char* fsPath)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Inode*
|
||||||
|
Filesystem::CreateRootInode()
|
||||||
|
{
|
||||||
|
return new(std::nothrow)Inode(this, fRootFH);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,13 +13,19 @@
|
|||||||
#include "RPCServer.h"
|
#include "RPCServer.h"
|
||||||
|
|
||||||
|
|
||||||
|
class Inode;
|
||||||
|
|
||||||
class Filesystem {
|
class Filesystem {
|
||||||
public:
|
public:
|
||||||
static status_t Mount(Filesystem** pfs, RPC::Server* serv,
|
static status_t Mount(Filesystem** pfs, RPC::Server* serv,
|
||||||
const char* path);
|
const char* path);
|
||||||
~Filesystem();
|
~Filesystem();
|
||||||
|
|
||||||
|
Inode* CreateRootInode();
|
||||||
|
|
||||||
inline uint32 FHExpiryType() const;
|
inline uint32 FHExpiryType() const;
|
||||||
|
inline RPC::Server* Server();
|
||||||
|
inline uint64 GetId();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Filesystem();
|
Filesystem();
|
||||||
@@ -29,8 +35,24 @@ private:
|
|||||||
Filehandle fRootFH;
|
Filehandle fRootFH;
|
||||||
|
|
||||||
RPC::Server* fServer;
|
RPC::Server* fServer;
|
||||||
|
|
||||||
|
vint64 fId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline RPC::Server*
|
||||||
|
Filesystem::Server()
|
||||||
|
{
|
||||||
|
return fServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline uint64
|
||||||
|
Filesystem::GetId()
|
||||||
|
{
|
||||||
|
return atomic_add64(&fId, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // FILESYSTEM_H
|
#endif // FILESYSTEM_H
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Paweł Dziepak, [email protected]
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "Inode.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "ReplyInterpreter.h"
|
||||||
|
#include "RequestBuilder.h"
|
||||||
|
|
||||||
|
|
||||||
|
// Creating Inode object from Filehandle probably is not a good idea when
|
||||||
|
// filehandles are volatile.
|
||||||
|
Inode::Inode(Filesystem* fs, const Filehandle &fh)
|
||||||
|
:
|
||||||
|
fFilesystem(fs)
|
||||||
|
{
|
||||||
|
memcpy(&fHandle, &fh, sizeof(fh));
|
||||||
|
|
||||||
|
RequestBuilder req(ProcCompound);
|
||||||
|
req.PutFH(fh);
|
||||||
|
|
||||||
|
Attribute attr[] = { FATTR4_FILEID };
|
||||||
|
req.GetAttr(attr, sizeof(attr) / sizeof(Attribute));
|
||||||
|
|
||||||
|
RPC::Reply *rpl;
|
||||||
|
fs->Server()->SendCall(req.Request(), &rpl);
|
||||||
|
ReplyInterpreter reply(rpl);
|
||||||
|
|
||||||
|
status_t result;
|
||||||
|
result = reply.PutFH();
|
||||||
|
if (result != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AttrValue* values;
|
||||||
|
uint32 count;
|
||||||
|
result = reply.GetAttr(&values, &count);
|
||||||
|
if (result != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (count < 1 || values[0].fAttribute != FATTR4_FILEID) {
|
||||||
|
// Server does not provide fileid. We need to make something up.
|
||||||
|
fFileId = fs->GetId();
|
||||||
|
} else
|
||||||
|
fFileId = values[0].fData.fValue64;
|
||||||
|
|
||||||
|
delete values;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Paweł Dziepak, [email protected]
|
||||||
|
*/
|
||||||
|
#ifndef INODE_H
|
||||||
|
#define INODE_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
#include "Filesystem.h"
|
||||||
|
#include "NFS4Defs.h"
|
||||||
|
|
||||||
|
|
||||||
|
class Inode {
|
||||||
|
public:
|
||||||
|
Inode(Filesystem* fs, const Filehandle &fh);
|
||||||
|
|
||||||
|
inline ino_t ID() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint64 fFileId;
|
||||||
|
|
||||||
|
Filehandle fHandle;
|
||||||
|
Filesystem* fFilesystem;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline ino_t
|
||||||
|
Inode::ID() const
|
||||||
|
{
|
||||||
|
if (sizeof(ino_t) >= sizeof(uint64))
|
||||||
|
return fFileId;
|
||||||
|
else
|
||||||
|
return (ino_t)fFileId ^ (fFileId >>
|
||||||
|
(sizeof(uint64) - sizeof(ino_t)) * 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // INODE_H
|
||||||
|
|
||||||
@@ -5,6 +5,7 @@ UsePrivateHeaders kernel ;
|
|||||||
KernelAddon nfs4 :
|
KernelAddon nfs4 :
|
||||||
Connection.cpp
|
Connection.cpp
|
||||||
Filesystem.cpp
|
Filesystem.cpp
|
||||||
|
Inode.cpp
|
||||||
kernel_interface.cpp
|
kernel_interface.cpp
|
||||||
ReplyInterpreter.cpp
|
ReplyInterpreter.cpp
|
||||||
RequestBuilder.cpp
|
RequestBuilder.cpp
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ enum Opcode {
|
|||||||
OpGetAttr = 9,
|
OpGetAttr = 9,
|
||||||
OpGetFH = 10,
|
OpGetFH = 10,
|
||||||
OpLookUp = 15,
|
OpLookUp = 15,
|
||||||
|
OpPutFH = 22,
|
||||||
OpPutRootFH = 24
|
OpPutRootFH = 24
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public:
|
|||||||
status_t GetAttr(AttrValue** attrs, uint32* count);
|
status_t GetAttr(AttrValue** attrs, uint32* count);
|
||||||
status_t GetFH(Filehandle* fh);
|
status_t GetFH(Filehandle* fh);
|
||||||
inline status_t LookUp();
|
inline status_t LookUp();
|
||||||
|
inline status_t PutFH();
|
||||||
inline status_t PutRootFH();
|
inline status_t PutRootFH();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -51,6 +52,13 @@ ReplyInterpreter::LookUp()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline status_t
|
||||||
|
ReplyInterpreter::PutFH()
|
||||||
|
{
|
||||||
|
return _OperationError(OpPutFH);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline status_t
|
inline status_t
|
||||||
ReplyInterpreter::PutRootFH()
|
ReplyInterpreter::PutRootFH()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -114,6 +114,22 @@ RequestBuilder::LookUp(const char* name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
RequestBuilder::PutFH(const Filehandle& fh)
|
||||||
|
{
|
||||||
|
if (fProcedure != ProcCompound)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
if (fRequest == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
fRequest->Stream().AddUInt(OpPutFH);
|
||||||
|
fRequest->Stream().AddOpaque(fh.fFH, fh.fSize);
|
||||||
|
fOpCount++;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
RequestBuilder::PutRootFH()
|
RequestBuilder::PutRootFH()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public:
|
|||||||
status_t GetAttr(Attribute* attrs, uint32 count);
|
status_t GetAttr(Attribute* attrs, uint32 count);
|
||||||
status_t GetFH();
|
status_t GetFH();
|
||||||
status_t LookUp(const char* name);
|
status_t LookUp(const char* name);
|
||||||
|
status_t PutFH(const Filehandle& fh);
|
||||||
status_t PutRootFH();
|
status_t PutRootFH();
|
||||||
|
|
||||||
RPC::Call* Request();
|
RPC::Call* Request();
|
||||||
|
|||||||
Reference in New Issue
Block a user