nfs4: Add create_dir() hook

This commit is contained in:
Pawel Dziepak
2012-06-29 02:15:12 +02:00
parent e27b9ff742
commit 69adfb6de2
5 changed files with 52 additions and 9 deletions
+33 -1
View File
@@ -336,7 +336,7 @@ Inode::CreateLink(const char* name, const char* path, int mode)
attr.fAttribute = FATTR4_MODE;
attr.fFreePointer = false;
attr.fData.fValue32 = mode;
req.Create(NF4LNK, name, path, &attr, 1);
req.Create(NF4LNK, name, &attr, 1, path);
status_t result = request.Send();
if (result != B_OK)
@@ -919,6 +919,38 @@ Inode::Write(OpenFileCookie* cookie, off_t pos, const void* _buffer,
}
status_t
Inode::CreateDir(const char* name, int mode)
{
do {
RPC::Server* serv = fFilesystem->Server();
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
AttrValue attr;
attr.fAttribute = FATTR4_MODE;
attr.fFreePointer = false;
attr.fData.fValue32 = mode;
req.Create(NF4DIR, name, &attr, 1);
status_t result = request.Send();
if (result != B_OK)
return result;
ReplyInterpreter& reply = request.Reply();
if (_HandleErrors(reply.NFS4Error(), serv))
continue;
reply.PutFH();
return reply.Create();
} while (true);
}
status_t
Inode::OpenDir(OpenDirCookie* cookie)
{
@@ -52,6 +52,7 @@ public:
status_t Write(OpenFileCookie* cookie, off_t pos,
const void* buffer, size_t *_length);
status_t CreateDir(const char* name, int mode);
status_t OpenDir(OpenDirCookie* cookie);
status_t ReadDir(void* buffer, uint32 size,
uint32* count, OpenDirCookie* cookie);
@@ -87,23 +87,24 @@ RequestBuilder::Close(uint32 seq, const uint32* id, uint32 stateSeq)
status_t
RequestBuilder::Create(FileType type, const char* name, const char* path,
AttrValue* attr, uint32 count)
RequestBuilder::Create(FileType type, const char* name, AttrValue* attr,
uint32 count, const char* path)
{
if (fProcedure != ProcCompound)
return B_BAD_VALUE;
if (fRequest == NULL)
return B_NO_MEMORY;
if (path == NULL)
if (type == NF4LNK && path == NULL)
return B_BAD_VALUE;
if (name == NULL)
return B_BAD_VALUE;
if (type != NF4LNK)
if (type == NF4BLK || type == NF4CHR)
return B_BAD_VALUE;
fRequest->Stream().AddUInt(OpCreate);
fRequest->Stream().AddUInt(type);
fRequest->Stream().AddString(path);
if (type == NF4LNK)
fRequest->Stream().AddString(path);
fRequest->Stream().AddString(name);
_EncodeAttrs(fRequest->Stream(), attr, count);
@@ -29,8 +29,8 @@ public:
status_t Close(uint32 seq, const uint32* id,
uint32 stateSeq);
status_t Create(FileType type, const char* name,
const char* path, AttrValue* attr,
uint32 count);
AttrValue* attr, uint32 count,
const char* path = NULL);
status_t GetAttr(Attribute* attrs, uint32 count);
status_t GetFH();
status_t Link(const char* name);
@@ -376,6 +376,15 @@ nfs4_write(fs_volume* volume, fs_vnode* vnode, void* _cookie, off_t pos,
}
static status_t
nfs4_create_dir(fs_volume* volume, fs_vnode* parent, const char* name,
int mode)
{
Inode* inode = reinterpret_cast<Inode*>(parent->private_node);
return inode->CreateDir(name, mode);
}
static status_t
nfs4_remove_dir(fs_volume* volume, fs_vnode* parent, const char* name)
{
@@ -526,7 +535,7 @@ fs_vnode_ops gNFSv4VnodeOps = {
nfs4_write,
/* directory operations */
NULL, // create_dir()
nfs4_create_dir,
nfs4_remove_dir,
nfs4_open_dir,
nfs4_close_dir,