diff options
author | Christopher Haster <chaster@utexas.edu> | 2018-01-11 19:26:33 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2018-01-11 19:26:33 +0300 |
commit | 472ccc420343b7fe3463445dafad60f130cf027e (patch) | |
tree | a7f18387b83ee863e90683857e4caf995d20b007 /lfs.c | |
parent | aea3d3db46634bf26298c8df0be020c03b80daba (diff) |
Fixed file truncation without writes
In the open call, the LFS_O_TRUNC flag was correctly zeroing the file, but
it wasn't actually writing the change out to disk. This went unnoticed because
in the cases where the truncate was followed by a file write, the
updated contents would be written out correctly.
Marking the file as dirty if the file isn't already truncated fixes the
problem with the least impact. Also added better test cases around
truncating files.
Diffstat (limited to 'lfs.c')
-rw-r--r-- | lfs.c | 3 |
1 files changed, 3 insertions, 0 deletions
@@ -1261,6 +1261,9 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, file->pos = 0; if (flags & LFS_O_TRUNC) { + if (file->size != 0) { + file->flags |= LFS_F_DIRTY; + } file->head = 0xffffffff; file->size = 0; } |