From 20615a9f6579fb9aaaedd435ceaacdb32fb0cd46 Mon Sep 17 00:00:00 2001 From: vau Date: Sun, 31 May 2020 16:48:53 +0300 Subject: [PATCH] Do not rewrite the root directory if it has not changed --- fs/fat/fs_fat32.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/fs/fat/fs_fat32.c b/fs/fat/fs_fat32.c index 0757ca2288b..d2c0ad174f4 100644 --- a/fs/fat/fs_fat32.c +++ b/fs/fat/fs_fat32.c @@ -1394,6 +1394,8 @@ static int fat_sync(FAR struct file *filep) if ((ff->ff_bflags & FFBUFF_MODIFIED) != 0) { + uint8_t dircopy[DIR_SIZE]; + /* Flush any unwritten data in the file buffer */ ret = fat_ffcacheflush(fs, ff); @@ -1419,6 +1421,10 @@ static int fat_sync(FAR struct file *filep) direntry = &fs->fs_buffer[(ff->ff_dirindex & DIRSEC_NDXMASK(fs)) * DIR_SIZE]; + /* Copy directory entry */ + + memcpy(dircopy, direntry, DIR_SIZE); + /* Set the archive bit, set the write time, and update * anything that may have* changed in the directory * entry: the file size, and the start cluster @@ -1438,11 +1444,17 @@ static int fat_sync(FAR struct file *filep) ff->ff_bflags &= ~FFBUFF_MODIFIED; + /* Compare old and new directory entry */ + + if (memcmp(direntry, dircopy, DIR_SIZE) != 0) + { + fs->fs_dirty = true; + } + /* Flush these change to disk and update FSINFO (if * appropriate. */ - fs->fs_dirty = true; ret = fat_updatefsinfo(fs); }