From 950124146cd9a2e1539ca6969338c44f118ead5f Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 5 Jul 2024 16:20:54 -0500 Subject: [PATCH] Adopted implied LFS_O_FLUSH bit pattern in LFS_O_SYNC LFS_O_SYNC always implies LFS_O_FLUSH, otherwise what exactly are you syncing? Making this explicit in the bit pattern should hopefully make this clear for curious users, though lfsr_file_flush would be called anyways because of how lfsr_file_sync is implemented. This also moves the LFS_O_DESYNC bit pattern around so SYNC/FLUSH are neighbors. SYNC/DESYNC may seem related, but in lfsr_file_open they actually are quite different: LFS_O_FLUSH 0x0040 ---- ---- -1-- ---- LFS_O_SYNC 0x00c0 ---- ---- 11-- ---- LFS_O_DESYNC 0x0100 ---- ---1 ---- ---- Code changes, mostly just noise from moving bits around: code stack before: 35228 2680 after: 35244 (+0.0%) 2680 (+0.0%) --- lfs.c | 10 +++++----- lfs.h | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lfs.c b/lfs.c index 88e57f2e..d99a5948 100644 --- a/lfs.c +++ b/lfs.c @@ -9760,18 +9760,18 @@ static inline bool lfsr_o_isappend(uint32_t flags) { return flags & LFS_O_APPEND; } +static inline bool lfsr_o_isflush(uint32_t flags) { + return flags & LFS_O_FLUSH; +} + static inline bool lfsr_o_issync(uint32_t flags) { - return flags & LFS_O_SYNC; + return flags & (LFS_O_SYNC ^ LFS_O_FLUSH); } static inline bool lfsr_o_isdesync(uint32_t flags) { return flags & LFS_O_DESYNC; } -static inline bool lfsr_o_isflush(uint32_t flags) { - return flags & LFS_O_FLUSH; -} - static inline bool lfsr_f_isunflush(uint32_t flags) { return flags & LFS_F_UNFLUSH; } diff --git a/lfs.h b/lfs.h index 33b605a8..3c1bff24 100644 --- a/lfs.h +++ b/lfs.h @@ -137,9 +137,9 @@ enum lfs_open_flags { LFS_O_EXCL = 0x0008, // Fail if a file already exists LFS_O_TRUNC = 0x0010, // Truncate the existing file to zero size LFS_O_APPEND = 0x0020, // Move to end of file on every write - LFS_O_SYNC = 0x0040, // Sync metadata on every write - LFS_O_DESYNC = 0x0080, // Do not sync or recieve file updates - LFS_O_FLUSH = 0x0100, // Flush data on every write + LFS_O_FLUSH = 0x0040, // Flush data on every write + LFS_O_SYNC = 0x00c0, // Sync metadata on every write + LFS_O_DESYNC = 0x0100, // Do not sync or recieve file updates #endif // internally used flags