drivers/fs: Control the behavior of FTL by passing oflags during the open process.

To save more space (equivalent to the size of one erase sector of
MTD device) and to achieve faster read and write speeds, a method
for direct writing was introduced at the FTL layer.
This can be accomplished simply by using the following oflags during
the open operation:

1. O_DIRECT. when this flag is passed in, ftl internally uses
   the direct write strategy and no read cache is used in ftl;
   otherwise, each write will be executed with the minimum
   granularity of flash erase sector size which means a
   "sector read back - erase sector - write sector" operation
   is performed by using a read cache buffer in heap.

2. O_SYNC. When this flag is passed in, we assume that the
   flash has been erased in advance and no erasure operation
   will be performed internally within ftl. O_SYNC will take
   effect only when both O_DIRECT and O_SYNC are passed in
   simultaneously.

3. For uniformity, we remapped the mount flag in mount.h and
   unified it with the open flag in fcntl.h. The repetitive
   parts of their definitions were reused, and the remaining
   part of the mount flag redefine to the unused bit of open
   flags.

Signed-off-by: jingfei <jingfei@xiaomi.com>
This commit is contained in:
jingfei
2025-07-04 22:54:43 +08:00
committed by Xiang Xiao
parent a6fdbc538b
commit c3e87dd3d1
10 changed files with 152 additions and 52 deletions
+11 -10
View File
@@ -29,6 +29,7 @@
#include <nuttx/compiler.h>
#include <nuttx/fs/ioctl.h>
#include <fcntl.h>
/****************************************************************************
* Pre-processor Definitions
@@ -39,16 +40,16 @@
/* Mount flags */
#define MS_RDONLY 1 /* Mount file system read-only */
#define MS_NOSUID 2 /* Ignore suid and sgid bits */
#define MS_NODEV 4 /* Disallow access to device special files */
#define MS_NOEXEC 8 /* Disallow program execution */
#define MS_SYNCHRONOUS 16 /* Writes are synced at once */
#define MS_REMOUNT 32 /* Alter flags of a mounted FS */
#define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
#define MS_DIRSYNC 128 /* Directory modifications are synchronous */
#define MS_NOSYMFOLLOW 256 /* Do not follow symlinks */
#define MS_NOATIME 1024 /* Do not update access times. */
#define MS_RDONLY O_RDONLY /* Mount file system read-only */
#define MS_SYNCHRONOUS O_SYNC /* Writes are synced at once */
#define MS_NOSYMFOLLOW O_NOFOLLOW /* Do not follow symlinks */
#define MS_NOATIME O_NOATIME /* Do not update access times. */
#define MS_NOSUID O_RESERVE14 /* Ignore suid and sgid bits */
#define MS_NODEV O_RESERVE15 /* Disallow access to device special files */
#define MS_DIRSYNC O_RESERVE16 /* Directory modifications are synchronous */
#define MS_REMOUNT O_RESERVE17 /* Alter flags of a mounted FS */
#define MS_MANDLOCK O_RESERVE19 /* Allow mandatory locks on an FS */
#define MS_NOEXEC O_RESERVE20 /* Disallow program execution */
/* Un-mount flags
*