From 606584d032b29f076400c6ea9fccd2b5fef96c6b Mon Sep 17 00:00:00 2001 From: Loris Nardo Date: Fri, 2 Aug 2024 06:56:48 +0200 Subject: [PATCH] msdos: Fix file truncated to 0 Previously the first cluster of the file was not updated when truncating to 0 but was in any case freed. Now the first cluster of the file is updated during the truncation, leaving the directory entry in a consistent state. Closes #2757 --- cpukit/libfs/src/dosfs/fat_file.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cpukit/libfs/src/dosfs/fat_file.c b/cpukit/libfs/src/dosfs/fat_file.c index 31c74abaf6..33ff4d5390 100644 --- a/cpukit/libfs/src/dosfs/fat_file.c +++ b/cpukit/libfs/src/dosfs/fat_file.c @@ -862,6 +862,13 @@ fat_file_truncate( fat_fd->map.disk_cln = new_last_cln; fat_fd->map.last_cln = new_last_cln; } + else + { + fat_file_set_first_cluster_num(fat_fd, FAT_GENFAT_FREE); + fat_fd->map.file_cln = FAT_UNDEFINED_VALUE; + fat_fd->map.disk_cln = FAT_UNDEFINED_VALUE; + fat_fd->map.last_cln = FAT_UNDEFINED_VALUE; + } return RC_OK; }