Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lfs.c
diff options
context:
space:
mode:
authorChristopher Haster <chaster@utexas.edu>2018-01-11 19:26:33 +0300
committerChristopher Haster <chaster@utexas.edu>2018-01-11 19:26:33 +0300
commit472ccc420343b7fe3463445dafad60f130cf027e (patch)
treea7f18387b83ee863e90683857e4caf995d20b007 /lfs.c
parentaea3d3db46634bf26298c8df0be020c03b80daba (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.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/lfs.c b/lfs.c
index 4267d7c..7c134f5 100644
--- a/lfs.c
+++ b/lfs.c
@@ -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;
}