[rtems commit] nfsclient: POSIX conformance

Sebastian Huber sebh at rtems.org
Mon Apr 23 13:59:11 UTC 2012


Module:    rtems
Branch:    master
Commit:    e384438b9c5dbd7fe0dc5e67b93f2d749b4b3874
Changeset: http://git.rtems.org/rtems/commit/?id=e384438b9c5dbd7fe0dc5e67b93f2d749b4b3874

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Apr 23 15:46:07 2012 +0200

nfsclient: POSIX conformance

According to POSIX the read() call should return the maximum number of
bytes available for regular files.

---

 cpukit/libfs/src/nfsclient/src/nfs.c |   46 +++++++++++++++++++++++++++------
 1 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/cpukit/libfs/src/nfsclient/src/nfs.c b/cpukit/libfs/src/nfsclient/src/nfs.c
index ebcdbb3..da4bae6 100644
--- a/cpukit/libfs/src/nfsclient/src/nfs.c
+++ b/cpukit/libfs/src/nfsclient/src/nfs.c
@@ -2200,20 +2200,17 @@ static int nfs_dir_close(
 	return 0;
 }
 
-static ssize_t nfs_file_read(
-	rtems_libio_t *iop,
-	void          *buffer,
-	size_t        count
+static ssize_t nfs_file_read_chunk(
+	NfsNode node,
+	uint32_t offset,
+	void *buffer,
+	size_t count
 )
 {
 readres	rr;
-NfsNode node = iop->pathinfo.node_access;
 Nfs		nfs  = node->nfs;
 
-	if (count > NFS_MAXDATA)
-		count = NFS_MAXDATA;
-
-	SERP_ARGS(node).readarg.offset		= iop->offset;
+	SERP_ARGS(node).readarg.offset		= offset;
 	SERP_ARGS(node).readarg.count	  	= count;
 	SERP_ARGS(node).readarg.totalcount	= UINT32_C(0xdeadbeef);
 
@@ -2244,6 +2241,37 @@ Nfs		nfs  = node->nfs;
 	return rr.readres_u.reply.data.data_len;
 }
 
+static ssize_t nfs_file_read(
+	rtems_libio_t *iop,
+	void *buffer,
+	size_t count
+)
+{
+	ssize_t rv = 0;
+	NfsNode node = iop->pathinfo.node_access;
+	uint32_t offset = iop->offset;
+	char *in = buffer;
+
+	do {
+		size_t chunk = count <= NFS_MAXDATA ? count : NFS_MAXDATA;
+		ssize_t done = nfs_file_read_chunk(node, offset, in, chunk);
+
+		if (done > 0) {
+			offset += (uint32_t) done;
+			in += done;
+			count -= (size_t) done;
+			rv += done;
+		} else {
+			count = 0;
+			if (done < 0) {
+				rv = -1;
+			}
+		}
+	} while (count > 0);
+
+	return rv;
+}
+
 /* this is called by readdir() / getdents() */
 static ssize_t nfs_dir_read(
 	rtems_libio_t *iop,




More information about the vc mailing list