From e384438b9c5dbd7fe0dc5e67b93f2d749b4b3874 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 23 Apr 2012 15:46:07 +0200 Subject: 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 file changed, 37 insertions(+), 9 deletions(-) (limited to 'cpukit/libfs') diff --git a/cpukit/libfs/src/nfsclient/src/nfs.c b/cpukit/libfs/src/nfsclient/src/nfs.c index ebcdbb3863..da4bae6ac5 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, -- cgit v1.2.3