提交 4f7cfcd5 编写于 作者: G goprife@gmail.com

add DFS_NFS_MAX_MTU to nfs to support read/write more than one mtu data in...

add DFS_NFS_MAX_MTU to nfs to support read/write more than one mtu data in nfs; 2) fix a bug in nfs_lseek when offset is at the end of file.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2485 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 ea4082b7
...@@ -22,6 +22,11 @@ ...@@ -22,6 +22,11 @@
#include "nfs.h" #include "nfs.h"
#define NAME_MAX 64 #define NAME_MAX 64
#define DFS_NFS_MAX_MTU 1024
#ifdef _WIN32
#define strtok_r strtok_s
#endif
struct nfs_file struct nfs_file
{ {
...@@ -532,7 +537,7 @@ int nfs_read(struct dfs_fd *file, void *buf, rt_size_t count) ...@@ -532,7 +537,7 @@ int nfs_read(struct dfs_fd *file, void *buf, rt_size_t count)
{ {
READ3args args; READ3args args;
READ3res res; READ3res res;
ssize_t bytes; ssize_t bytes, total=0;
nfs_file *fd; nfs_file *fd;
struct nfs_filesystem *nfs; struct nfs_filesystem *nfs;
...@@ -553,43 +558,52 @@ int nfs_read(struct dfs_fd *file, void *buf, rt_size_t count) ...@@ -553,43 +558,52 @@ int nfs_read(struct dfs_fd *file, void *buf, rt_size_t count)
return 0; return 0;
args.file = fd->handle; args.file = fd->handle;
do {
args.offset = fd->offset; args.offset = fd->offset;
args.count = count; args.count = count > DFS_NFS_MAX_MTU ? DFS_NFS_MAX_MTU : count;
count -= args.count;
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
if (nfsproc3_read_3(args, &res, nfs->nfs_client) != RPC_SUCCESS) if (nfsproc3_read_3(args, &res, nfs->nfs_client) != RPC_SUCCESS)
{ {
rt_kprintf("Read failed\n"); rt_kprintf("Read failed\n");
bytes = 0; total = 0;
break;
} }
else if (res.status != NFS3_OK) else if (res.status != NFS3_OK)
{ {
rt_kprintf("Read failed: %d\n", res.status); rt_kprintf("Read failed: %d\n", res.status);
bytes = 0; total = 0;
break;
} }
else else
{ {
if (res.READ3res_u.resok.eof)
{
/* something should probably be here */
fd->eof = TRUE;
}
bytes = res.READ3res_u.resok.count; bytes = res.READ3res_u.resok.count;
total += bytes;
fd->offset += bytes; fd->offset += bytes;
/* update current position */ /* update current position */
file->pos = fd->offset; file->pos = fd->offset;
memcpy(buf, res.READ3res_u.resok.data.data_val, bytes); memcpy(buf, res.READ3res_u.resok.data.data_val, bytes);
buf = (void *)((char *)buf + args.count);
if (res.READ3res_u.resok.eof)
{
/* something should probably be here */
fd->eof = TRUE;
break;
}
} }
xdr_free((xdrproc_t)xdr_READ3res, (char *)&res); xdr_free((xdrproc_t)xdr_READ3res, (char *)&res);
} while(count > 0);
return bytes; xdr_free((xdrproc_t)xdr_READ3res, (char *)&res);
return total;
} }
int nfs_write(struct dfs_fd *file, const void *buf, rt_size_t count) int nfs_write(struct dfs_fd *file, const void *buf, rt_size_t count)
{ {
WRITE3args args; WRITE3args args;
WRITE3res res; WRITE3res res;
ssize_t bytes; ssize_t bytes, total=0;
nfs_file *fd; nfs_file *fd;
struct nfs_filesystem *nfs; struct nfs_filesystem *nfs;
...@@ -607,33 +621,43 @@ int nfs_write(struct dfs_fd *file, const void *buf, rt_size_t count) ...@@ -607,33 +621,43 @@ int nfs_write(struct dfs_fd *file, const void *buf, rt_size_t count)
args.file = fd->handle; args.file = fd->handle;
args.stable = FILE_SYNC; args.stable = FILE_SYNC;
do {
args.offset = fd->offset; args.offset = fd->offset;
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
args.data.data_val=(void *)buf; args.data.data_val=(void *)buf;
args.count=args.data.data_len = count; args.count = count > DFS_NFS_MAX_MTU ? DFS_NFS_MAX_MTU : count;
args.data.data_len = args.count;
count -= args.count;
buf = (const void *)((char *)buf + args.count);
if (nfsproc3_write_3(args, &res, nfs->nfs_client) != RPC_SUCCESS) if (nfsproc3_write_3(args, &res, nfs->nfs_client) != RPC_SUCCESS)
{ {
rt_kprintf("Write failed\n"); rt_kprintf("Write failed\n");
bytes = 0; total = 0;
break;
} }
else if (res.status != NFS3_OK) else if (res.status != NFS3_OK)
{ {
rt_kprintf("Write failed: %d\n", res.status); rt_kprintf("Write failed: %d\n", res.status);
bytes = 0; total = 0;
break;
} }
else else
{ {
bytes = res.WRITE3res_u.resok.count; bytes = res.WRITE3res_u.resok.count;
fd->offset += bytes; fd->offset += bytes;
total += bytes;
/* update current position */ /* update current position */
file->pos = fd->offset; file->pos = fd->offset;
/* todo: update file size */ /* todo: update file size */
} }
xdr_free((xdrproc_t)xdr_WRITE3res, (char *)&res); xdr_free((xdrproc_t)xdr_WRITE3res, (char *)&res);
} while (count > 0);
return bytes; xdr_free((xdrproc_t)xdr_WRITE3res, (char *)&res);
return total;
} }
int nfs_lseek(struct dfs_fd *file, rt_off_t offset) int nfs_lseek(struct dfs_fd *file, rt_off_t offset)
...@@ -646,7 +670,7 @@ int nfs_lseek(struct dfs_fd *file, rt_off_t offset) ...@@ -646,7 +670,7 @@ int nfs_lseek(struct dfs_fd *file, rt_off_t offset)
fd = (nfs_file *)(file->data); fd = (nfs_file *)(file->data);
RT_ASSERT(fd != RT_NULL); RT_ASSERT(fd != RT_NULL);
if (offset < fd->size) if (offset <= fd->size)
{ {
fd->offset = offset; fd->offset = offset;
return offset; return offset;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册