From 5504af82d3a67230db5dd2283edfa494fb2177b7 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 10 Jun 2012 01:16:46 +0000 Subject: NFS update git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4823 7fd9a85b-ad96-42d3-883c-3090e2eb8679 --- nuttx/fs/nfs/nfs_util.c | 36 ++++++++++++++++++++++++++---------- nuttx/fs/nfs/nfs_vfsops.c | 4 ++-- nuttx/fs/nfs/xdr_subs.h | 2 ++ 3 files changed, 30 insertions(+), 12 deletions(-) (limited to 'nuttx/fs') diff --git a/nuttx/fs/nfs/nfs_util.c b/nuttx/fs/nfs/nfs_util.c index c07c6e519..e9d7ac863 100644 --- a/nuttx/fs/nfs/nfs_util.c +++ b/nuttx/fs/nfs/nfs_util.c @@ -312,6 +312,8 @@ int nfs_lookup(struct nfsmount *nmp, FAR const char *filename, { struct LOOKUP3args request; struct rpc_reply_lookup response; + uint32_t *ptr; + uint32_t value; int namelen; int error = 0; @@ -321,8 +323,8 @@ int nfs_lookup(struct nfsmount *nmp, FAR const char *filename, memset(&request, 0, sizeof(struct LOOKUP3args)); memset(&response, 0, sizeof(struct rpc_reply_lookup)); - memset(&obj_attributes, 0, sizeof(struct nfs_fattr)); - memset(&dir_attributes, 0, sizeof(struct nfs_fattr)); + memset(obj_attributes, 0, sizeof(struct nfs_fattr)); + memset(dir_attributes, 0, sizeof(struct nfs_fattr)); /* Get the length of the string to be sent */ @@ -352,20 +354,34 @@ int nfs_lookup(struct nfsmount *nmp, FAR const char *filename, return error; } - /* Return the data to the caller's buffers */ + /* Return the data to the caller's buffers. NOTE: Here we ignore the + * the exact layout of the rpc_reply_lookup structure. File handles + * may differ in size whereas struct rpc_reply_lookup uses a fixed size. + */ + + ptr = (uint32_t*)&response.lookup; - memcpy(fhandle, &response.lookup.fshandle, sizeof(struct file_handle)); + /* Get the length of the file handle and return the file handle */ - if (response.lookup.obj_attributes_follow != 0) + value = txdr_unsigned(*ptr) + sizeof(uint32_t); + memcpy(fhandle, ptr, value); + ptr += uint32_increment(value); + + /* Check if there are object attributes and, if so, copy them to the user buffer */ + + value = *ptr++; + if (value) { - memcpy(obj_attributes, &response.lookup.obj_attributes, - sizeof(struct nfs_fattr)); + memcpy(obj_attributes, ptr, sizeof(struct nfs_fattr)); + ptr += uint32_increment(sizeof(struct nfs_fattr)); } - if (response.lookup.dir_attributes_follow != 0) + /* Check if there are directory attributes and, if so, copy them to the user buffer */ + + value = *ptr++; + if (value) { - memcpy(dir_attributes, &response.lookup.dir_attributes, - sizeof(struct nfs_fattr)); + memcpy(dir_attributes, ptr, sizeof(struct nfs_fattr)); } return OK; diff --git a/nuttx/fs/nfs/nfs_vfsops.c b/nuttx/fs/nfs/nfs_vfsops.c index c3268efbf..ad4100539 100644 --- a/nuttx/fs/nfs/nfs_vfsops.c +++ b/nuttx/fs/nfs/nfs_vfsops.c @@ -936,7 +936,7 @@ int nfs_readdirrpc(struct nfsmount *nmp, struct nfsnode *np, * now points to the cookie. */ - ptr += (length + 3) >> 2; + ptr += uint32_increment(length); /* Save the cookie and increment the pointer to the next entry */ @@ -972,7 +972,7 @@ int nfs_readdirrpc(struct nfsmount *nmp, struct nfsnode *np, /* Set the dirent file type */ - switch (obj_attributes.fa_type) + switch (fxdr_unsigned(uint32_t, obj_attributes.fa_type)) { default: case NFNON: /* Unknown type */ diff --git a/nuttx/fs/nfs/xdr_subs.h b/nuttx/fs/nfs/xdr_subs.h index 9c36a69e7..a95249118 100644 --- a/nuttx/fs/nfs/xdr_subs.h +++ b/nuttx/fs/nfs/xdr_subs.h @@ -118,4 +118,6 @@ ((uint32_t *)(t))[1] = htonl((uint32_t)((f) & 0xffffffff)); \ } +#define uint32_increment(b) (((b) + 3) >> 2) + #endif /* __FS_NFS_XDR_SUBS_H */ -- cgit v1.2.3