nfs4: Implement nfs4_mount() procedure
This commit is contained in:
@@ -26,7 +26,7 @@ Inode::Inode(Filesystem* fs, const Filehandle &fh)
|
|||||||
RequestBuilder req(ProcCompound);
|
RequestBuilder req(ProcCompound);
|
||||||
req.PutFH(fh);
|
req.PutFH(fh);
|
||||||
|
|
||||||
Attribute attr[] = { FATTR4_FILEID };
|
Attribute attr[] = { FATTR4_TYPE, FATTR4_FILEID };
|
||||||
req.GetAttr(attr, sizeof(attr) / sizeof(Attribute));
|
req.GetAttr(attr, sizeof(attr) / sizeof(Attribute));
|
||||||
|
|
||||||
RPC::Reply *rpl;
|
RPC::Reply *rpl;
|
||||||
@@ -41,14 +41,17 @@ Inode::Inode(Filesystem* fs, const Filehandle &fh)
|
|||||||
AttrValue* values;
|
AttrValue* values;
|
||||||
uint32 count;
|
uint32 count;
|
||||||
result = reply.GetAttr(&values, &count);
|
result = reply.GetAttr(&values, &count);
|
||||||
if (result != B_OK)
|
if (result != B_OK || count < 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (count < 1 || values[0].fAttribute != FATTR4_FILEID) {
|
if (count < 2 || values[1].fAttribute != FATTR4_FILEID) {
|
||||||
// Server does not provide fileid. We need to make something up.
|
// Server does not provide fileid. We need to make something up.
|
||||||
fFileId = fs->GetId();
|
fFileId = fs->GetId();
|
||||||
} else
|
} else
|
||||||
fFileId = values[0].fData.fValue64;
|
fFileId = values[1].fData.fValue64;
|
||||||
|
|
||||||
|
// FATTR4_TYPE is mandatory
|
||||||
|
fType = values[0].fData.fValue32;
|
||||||
|
|
||||||
delete values;
|
delete values;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,11 @@ public:
|
|||||||
Inode(Filesystem* fs, const Filehandle &fh);
|
Inode(Filesystem* fs, const Filehandle &fh);
|
||||||
|
|
||||||
inline ino_t ID() const;
|
inline ino_t ID() const;
|
||||||
|
inline mode_t Type() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint64 fFileId;
|
uint64 fFileId;
|
||||||
|
uint32 fType;
|
||||||
|
|
||||||
Filehandle fHandle;
|
Filehandle fHandle;
|
||||||
Filesystem* fFilesystem;
|
Filesystem* fFilesystem;
|
||||||
@@ -40,5 +42,12 @@ Inode::ID() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline mode_t
|
||||||
|
Inode::Type() const
|
||||||
|
{
|
||||||
|
return sNFSFileTypeToHaiku[fType];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // INODE_H
|
#endif // INODE_H
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#define NFS4DEFS_H
|
#define NFS4DEFS_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -104,6 +106,23 @@ enum Attribute {
|
|||||||
FATTR4_MOUNTED_ON_FILEID = 55
|
FATTR4_MOUNTED_ON_FILEID = 55
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum FileType {
|
||||||
|
NF4REG = 1, /* Regular File */
|
||||||
|
NF4DIR = 2, /* Directory */
|
||||||
|
NF4BLK = 3, /* Special File - block device */
|
||||||
|
NF4CHR = 4, /* Special File - character device */
|
||||||
|
NF4LNK = 5, /* Symbolic Link */
|
||||||
|
NF4SOCK = 6, /* Special File - socket */
|
||||||
|
NF4FIFO = 7, /* Special File - fifo */
|
||||||
|
NF4ATTRDIR = 8, /* Attribute Directory */
|
||||||
|
NF4NAMEDATTR = 9 /* Named Attribute */
|
||||||
|
};
|
||||||
|
|
||||||
|
static const mode_t sNFSFileTypeToHaiku[] = {
|
||||||
|
S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK, S_IFSOCK, S_IFIFO, S_IFDIR,
|
||||||
|
S_IFREG
|
||||||
|
};
|
||||||
|
|
||||||
enum FileHandleExpiryType {
|
enum FileHandleExpiryType {
|
||||||
FH4_PERSISTENT = 0x00,
|
FH4_PERSISTENT = 0x00,
|
||||||
FH4_NOEXPIRE_WITH_OPEN = 0x01,
|
FH4_NOEXPIRE_WITH_OPEN = 0x01,
|
||||||
|
|||||||
@@ -11,10 +11,11 @@
|
|||||||
|
|
||||||
#include "Connection.h"
|
#include "Connection.h"
|
||||||
#include "RPCServer.h"
|
#include "RPCServer.h"
|
||||||
|
#include "NFS4Defs.h"
|
||||||
|
#include "Inode.h"
|
||||||
#define NFS_PROC_NULL 0
|
#include "RequestBuilder.h"
|
||||||
#define NFS_PROC_COMPOUND 1
|
#include "ReplyInterpreter.h"
|
||||||
|
#include "Filesystem.h"
|
||||||
|
|
||||||
|
|
||||||
extern fs_volume_ops gNFSv4VolumeOps;
|
extern fs_volume_ops gNFSv4VolumeOps;
|
||||||
@@ -31,30 +32,33 @@ static status_t
|
|||||||
nfs4_mount(fs_volume* volume, const char* device, uint32 flags,
|
nfs4_mount(fs_volume* volume, const char* device, uint32 flags,
|
||||||
const char* args, ino_t* _rootVnodeID)
|
const char* args, ino_t* _rootVnodeID)
|
||||||
{
|
{
|
||||||
dprintf("NFS4 Mounting...\n");
|
status_t result;
|
||||||
|
|
||||||
RPC::Server *s;
|
RPC::Server *server;
|
||||||
// hardcoded ip 192.168.1.70
|
// hardcoded ip 192.168.1.70
|
||||||
gRPCServerManager->Acquire(&s, 0xc0a80146, 2049, ProtocolTCP);
|
result = gRPCServerManager->Acquire(&server, 0xc0a80146, 2049, ProtocolUDP);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
RPC::Reply *r;
|
Filesystem* fs;
|
||||||
RPC::Call *c = RPC::Call::Create(NFS_PROC_NULL, RPC::Auth::CreateSys(),
|
// hardcoded path
|
||||||
RPC::Auth::CreateNone());
|
result = Filesystem::Mount(&fs, server, "haiku/src/add-ons/kernel");
|
||||||
s->SendCall(c, &r);
|
if (result != B_OK) {
|
||||||
delete r;
|
gRPCServerManager->Release(server);
|
||||||
delete c;
|
return result;
|
||||||
gRPCServerManager->Release(s);
|
}
|
||||||
|
|
||||||
|
Inode* inode = fs->CreateRootInode();
|
||||||
|
|
||||||
|
volume->private_volume = fs;
|
||||||
volume->ops = &gNFSv4VolumeOps;
|
volume->ops = &gNFSv4VolumeOps;
|
||||||
|
|
||||||
status_t error = publish_vnode(volume, 0, (void*)0xdeadbeef,
|
result = publish_vnode(volume, inode->ID(), inode, &gNFSv4VnodeOps,
|
||||||
&gNFSv4VnodeOps, S_IFDIR, 0);
|
inode->Type(), 0);
|
||||||
if (error != B_OK)
|
if (result != B_OK)
|
||||||
return error;
|
return result;
|
||||||
|
|
||||||
*_rootVnodeID = 0;
|
*_rootVnodeID = inode->ID();
|
||||||
|
|
||||||
dprintf("NFS4 Mounted\n");
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user