From e4a5ba42b8212574a6c75ac518e7b3be6e619a5b Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 21 Jun 2011 06:07:29 +1000 Subject: [PATCH] When doping chunked multi-reads of a blob bigger than the max readsize, a read can sometimes span beyond the end of file. In which case individual smal read chunks beyond the end of file will return OK, 0 bytes of data and EOF==1 For this case, trap when len==0 and ignore these chunks. Do not update the read-count if / when len is 0. --- examples/nfsclient-sync.c | 4 ++-- lib/libnfs.c | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/nfsclient-sync.c b/examples/nfsclient-sync.c index 460af53..d4f6b0c 100644 --- a/examples/nfsclient-sync.c +++ b/examples/nfsclient-sync.c @@ -20,7 +20,7 @@ #define SERVER "10.1.1.27" #define EXPORT "/VIRTUAL" -#define NFSFILE "/BOOKS/Classics/Dracula.djvu" +#define NFSFILE "/BOOKS/Classics/Dracula.djvu.truncated" #define NFSFILER "/BOOKS/Classics/Dracula.djvu.renamed" #define NFSFILEW "/BOOKS/Classics/foo" #define NFSDIR "/BOOKS/Classics/" @@ -46,7 +46,7 @@ struct client { }; -char buf[2*1024*1024]; +char buf[5*1024*1024]; int main(int argc _U_, char *argv[] _U_) { diff --git a/lib/libnfs.c b/lib/libnfs.c index 905e9d8..4380653 100644 --- a/lib/libnfs.c +++ b/lib/libnfs.c @@ -859,10 +859,12 @@ static void nfs_pread_mcb(struct rpc_context *rpc _U_, int status, void *command if (res->status != NFS3_OK) { rpc_set_error(nfs->rpc, "NFS: Read failed with %s(%d)", nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); data->error = 1; - } else { - memcpy(&data->buffer[mdata->offset - data->start_offset], res->READ3res_u.resok.data.data_val, res->READ3res_u.resok.count); - if ((unsigned)data->max_offset < mdata->offset + res->READ3res_u.resok.count) { - data->max_offset = mdata->offset + res->READ3res_u.resok.count; + } else { + if (res->READ3res_u.resok.count > 0) { + memcpy(&data->buffer[mdata->offset - data->start_offset], res->READ3res_u.resok.data.data_val, res->READ3res_u.resok.count); + if ((unsigned)data->max_offset < mdata->offset + res->READ3res_u.resok.count) { + data->max_offset = mdata->offset + res->READ3res_u.resok.count; + } } } } -- 2.34.1