diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index 0271fc72d..d798c5bbd 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -364,8 +364,9 @@ int dfs_elm_write(struct dfs_fd* file, const void* buf, rt_size_t len) RT_ASSERT(fd != RT_NULL); result = f_write(fd, buf, len, &byte_write); - /* update position */ + /* update position and file size */ file->pos = fd->fptr; + file->size = fd->fsize; if (result == FR_OK) return byte_write; return elm_result_to_dfs(result); @@ -392,6 +393,11 @@ int dfs_elm_lseek(struct dfs_fd* file, rt_off_t offset) RT_ASSERT(fd != RT_NULL); result = f_lseek(fd, offset); + if (result == FR_OK) + { + /* return current position */ + return fd->fptr; + } return elm_result_to_dfs(result); } diff --git a/components/dfs/filesystems/nfs/dfs_nfs.c b/components/dfs/filesystems/nfs/dfs_nfs.c index a463b0dab..836f4f1d2 100644 --- a/components/dfs/filesystems/nfs/dfs_nfs.c +++ b/components/dfs/filesystems/nfs/dfs_nfs.c @@ -557,6 +557,8 @@ int nfs_read(struct dfs_fd* file, void *buf, rt_size_t count) } bytes=res.READ3res_u.resok.count; fd->offset += bytes; + /* update current position */ + file->pos = fd->offset; memcpy(buf, res.READ3res_u.resok.data.data_val, bytes); } xdr_free((xdrproc_t)xdr_READ3res, (char *)&res); @@ -606,6 +608,9 @@ int nfs_write(struct dfs_fd* file, const void *buf, rt_size_t count) { bytes=res.WRITE3res_u.resok.count; fd->offset+=bytes; + /* update current position */ + file->pos = fd->offset; + /* todo: update file size */ } xdr_free((xdrproc_t)xdr_WRITE3res, (char *)&res); diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 05b082e4a..a1b19941e 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -290,12 +290,19 @@ int dfs_file_flush(struct dfs_fd* fd) */ int dfs_file_lseek(struct dfs_fd* fd, rt_off_t offset) { + int result; struct dfs_filesystem* fs = fd->fs; if (fd == RT_NULL) return -DFS_STATUS_EINVAL; if (fs->ops->lseek == RT_NULL) return -DFS_STATUS_ENOSYS; - return fs->ops->lseek(fd, offset); + result = fs->ops->lseek(fd, offset); + + /* update current position */ + if (result >= 0) + fd->pos = result; + + return result; } /**