Skip to content

Commit 724762f

Browse files
Fymytenashif
authored andcommitted
fs: open: fix zfp flags not set when calling truncate
If filesystem relies on zfp flags being set after open, this can lead to inconsistency with the current implementation of FS_O_TRUNC. Move the assignment of zfp->flags before any other call to fs api to avoid such issues. Signed-off-by: Pierrick Guillaume <[email protected]>
1 parent a837117 commit 724762f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

subsys/fs/fs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ int fs_open(struct fs_file_t *zfp, const char *file_name, fs_mode_t flags)
182182
return rc;
183183
}
184184

185+
/* Copy flags to zfp for use with other fs_ API calls */
186+
zfp->flags = flags;
187+
185188
if (truncate_file) {
186189
/* Truncate the opened file to 0 length */
187190
rc = mp->fs->truncate(zfp, 0);
@@ -192,9 +195,6 @@ int fs_open(struct fs_file_t *zfp, const char *file_name, fs_mode_t flags)
192195
}
193196
}
194197

195-
/* Copy flags to zfp for use with other fs_ API calls */
196-
zfp->flags = flags;
197-
198198
return rc;
199199
}
200200

0 commit comments

Comments
 (0)