From dbab72b300d373d567af36bdec5a09d2ac33b1f5 Mon Sep 17 00:00:00 2001 From: Niu Yawei Date: Thu, 5 Sep 2013 02:46:10 -0400 Subject: [PATCH] LU-3784 tune2fs: update i_size in ext2fs_file_write() ext2fs_file_write() needs to update i_size on successful write, otherwise, ext2fs_file_read() in same open/close cycle will not be able to read the just written data. Signed-off-by: Niu Yawei Change-Id: I7ec7d1fcd5e9a355ca0a4399e5e937f853f0a612 --- lib/ext2fs/fileio.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ext2fs/fileio.c b/lib/ext2fs/fileio.c index 1f7002c..331f349 100644 --- a/lib/ext2fs/fileio.c +++ b/lib/ext2fs/fileio.c @@ -270,7 +270,7 @@ errcode_t ext2fs_file_write(ext2_file_t file, const void *buf, unsigned int nbytes, unsigned int *written) { ext2_filsys fs; - errcode_t retval = 0; + errcode_t retval = 0, rc; unsigned int start, c, count = 0; const char *ptr = (const char *) buf; @@ -307,6 +307,13 @@ errcode_t ext2fs_file_write(ext2_file_t file, const void *buf, } fail: + /* Update inode size */ + if (count != 0 && EXT2_I_SIZE(&file->inode) < file->pos) { + rc = ext2fs_file_set_size2(file, file->pos); + if (retval == 0) + retval = rc; + } + if (written) *written = count; return retval; -- 1.8.3.1