Tweaked lfsr_file_open to only sync when LFS_O_SYNC + LFS_O_CREAT

So we keep the behavior of creating reg files with lfsr_file_open +
LFS_O_SYNC, but only clear the desync flag if lfsr_file_open would
mutate the filesystem.

This is hopefully a simpler model to reason about, and makes LFS_O_SYNC
+ LFS_O_DESYNC a bit less weird.

Saves a little bit of code:

           code          stack          ctx
  before: 35836           2488          640
  after:  35820 (-0.0%)   2480 (-0.3%)  640 (+0.0%)
This commit is contained in:
Christopher Haster
2025-04-25 21:17:50 -05:00
parent 0f4ad6d842
commit 4b87499605
2 changed files with 164 additions and 98 deletions
+1 -8
View File
@@ -11459,19 +11459,12 @@ int lfsr_file_opencfg(lfs_t *lfs, lfsr_file_t *file,
lfsr_omdir_open(lfs, &file->b.o);
// sync if requested
if (lfsr_o_issync(flags) && !lfsr_o_isrdonly(flags)) {
if (lfsr_o_iscreat(flags) && lfsr_o_issync(flags)) {
err = lfsr_file_sync(lfs, file);
if (err) {
lfsr_omdir_close(lfs, &file->b.o);
goto failed;
}
// TODO should we do this for all LFS_O_SYNC operations?
// sync clears the desync flag, so reset it if we're desync
//
// note this matches the behavior of calling lfsr_file_sync and
// then lfsr_file_desync after opening the file
file->b.o.flags |= flags & LFS_O_DESYNC;
}
return 0;