diff --git a/src/add-ons/kernel/file_systems/nfs4/Inode.cpp b/src/add-ons/kernel/file_systems/nfs4/Inode.cpp index f2af559ca4..eecf8358ce 100644 --- a/src/add-ons/kernel/file_systems/nfs4/Inode.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/Inode.cpp @@ -26,7 +26,7 @@ Inode::Inode(Filesystem* fs, const Filehandle &fh) RequestBuilder req(ProcCompound); req.PutFH(fh); - Attribute attr[] = { FATTR4_FILEID }; + Attribute attr[] = { FATTR4_TYPE, FATTR4_FILEID }; req.GetAttr(attr, sizeof(attr) / sizeof(Attribute)); RPC::Reply *rpl; @@ -41,14 +41,17 @@ Inode::Inode(Filesystem* fs, const Filehandle &fh) AttrValue* values; uint32 count; result = reply.GetAttr(&values, &count); - if (result != B_OK) + if (result != B_OK || count < 1) 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. fFileId = fs->GetId(); } else - fFileId = values[0].fData.fValue64; + fFileId = values[1].fData.fValue64; + + // FATTR4_TYPE is mandatory + fType = values[0].fData.fValue32; delete values; } diff --git a/src/add-ons/kernel/file_systems/nfs4/Inode.h b/src/add-ons/kernel/file_systems/nfs4/Inode.h index 39d9ea4514..1d878cd014 100644 --- a/src/add-ons/kernel/file_systems/nfs4/Inode.h +++ b/src/add-ons/kernel/file_systems/nfs4/Inode.h @@ -20,9 +20,11 @@ public: Inode(Filesystem* fs, const Filehandle &fh); inline ino_t ID() const; + inline mode_t Type() const; private: uint64 fFileId; + uint32 fType; Filehandle fHandle; Filesystem* fFilesystem; @@ -40,5 +42,12 @@ Inode::ID() const } +inline mode_t +Inode::Type() const +{ + return sNFSFileTypeToHaiku[fType]; +} + + #endif // INODE_H diff --git a/src/add-ons/kernel/file_systems/nfs4/NFS4Defs.h b/src/add-ons/kernel/file_systems/nfs4/NFS4Defs.h index 5938eff370..7c2f3dad2e 100644 --- a/src/add-ons/kernel/file_systems/nfs4/NFS4Defs.h +++ b/src/add-ons/kernel/file_systems/nfs4/NFS4Defs.h @@ -9,6 +9,8 @@ #define NFS4DEFS_H +#include + #include @@ -104,6 +106,23 @@ enum Attribute { 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 { FH4_PERSISTENT = 0x00, FH4_NOEXPIRE_WITH_OPEN = 0x01, 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 111a2ddad2..078a3457d6 100644 --- a/src/add-ons/kernel/file_systems/nfs4/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/kernel_interface.cpp @@ -11,10 +11,11 @@ #include "Connection.h" #include "RPCServer.h" - - -#define NFS_PROC_NULL 0 -#define NFS_PROC_COMPOUND 1 +#include "NFS4Defs.h" +#include "Inode.h" +#include "RequestBuilder.h" +#include "ReplyInterpreter.h" +#include "Filesystem.h" extern fs_volume_ops gNFSv4VolumeOps; @@ -31,30 +32,33 @@ static status_t nfs4_mount(fs_volume* volume, const char* device, uint32 flags, 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 - gRPCServerManager->Acquire(&s, 0xc0a80146, 2049, ProtocolTCP); + result = gRPCServerManager->Acquire(&server, 0xc0a80146, 2049, ProtocolUDP); + if (result != B_OK) + return result; - RPC::Reply *r; - RPC::Call *c = RPC::Call::Create(NFS_PROC_NULL, RPC::Auth::CreateSys(), - RPC::Auth::CreateNone()); - s->SendCall(c, &r); - delete r; - delete c; - gRPCServerManager->Release(s); + Filesystem* fs; + // hardcoded path + result = Filesystem::Mount(&fs, server, "haiku/src/add-ons/kernel"); + if (result != B_OK) { + gRPCServerManager->Release(server); + return result; + } + Inode* inode = fs->CreateRootInode(); + + volume->private_volume = fs; volume->ops = &gNFSv4VolumeOps; - status_t error = publish_vnode(volume, 0, (void*)0xdeadbeef, - &gNFSv4VnodeOps, S_IFDIR, 0); - if (error != B_OK) - return error; + result = publish_vnode(volume, inode->ID(), inode, &gNFSv4VnodeOps, + inode->Type(), 0); + if (result != B_OK) + return result; - *_rootVnodeID = 0; - - dprintf("NFS4 Mounted\n"); + *_rootVnodeID = inode->ID(); return B_OK; }