This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 86c4b9b8afb fs/littlefs: report the file type without optional
attributes
86c4b9b8afb is described below
commit 86c4b9b8afb27bb654dd13332d2ecc9bf08b8cf4
Author: jingfei <[email protected]>
AuthorDate: Sun Nov 29 07:58:37 2026 +0800
fs/littlefs: report the file type without optional attributes
Set S_IFREG independently of CONFIG_FS_LITTLEFS_ATTR_UPDATE in fstat.
With this option disabled, fstat currently returns success with a zero
st_mode, so S_ISREG fails for an open regular file.
Keep stored permissions and other optional attributes conditional, and
document that the file type remains available without them.
Signed-off-by: jingfei <[email protected]>
---
Documentation/os/filesystem/littlefs.rst | 4 ++++
fs/littlefs/lfs_vfs.c | 3 ++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/Documentation/os/filesystem/littlefs.rst
b/Documentation/os/filesystem/littlefs.rst
index 9c202952375..e0aca573a35 100644
--- a/Documentation/os/filesystem/littlefs.rst
+++ b/Documentation/os/filesystem/littlefs.rst
@@ -40,6 +40,10 @@ add ``lfs_file_path()`` (used by
``CONFIG_FS_LITTLEFS_GETPATH``) and
``CONFIG_FS_LITTLEFS_ATTR_UPDATE``). With any other version the patches are
skipped and both options are unavailable.
+``fstat()`` reports the regular-file type even when
+``CONFIG_FS_LITTLEFS_ATTR_UPDATE`` is disabled. Reading the stored permission
+bits, ownership, and timestamps through ``fstat()`` requires this option.
+
littlefs v2.11.2 writes on-disk version 2.1, while v2.5.1 and earlier wrote
2.0. littlefs 2.1 mounts 2.0 images and upgrades the superblock on the first
write. To keep writing 2.0 images, for example for older bootloaders, enable
diff --git a/fs/littlefs/lfs_vfs.c b/fs/littlefs/lfs_vfs.c
index 94f09de9271..dab05181b69 100644
--- a/fs/littlefs/lfs_vfs.c
+++ b/fs/littlefs/lfs_vfs.c
@@ -1067,7 +1067,7 @@ static int littlefs_fstat(FAR const struct file *filep,
FAR struct stat *buf)
}
ret = 0;
- buf->st_mode = attr.at_mode | S_IFREG;
+ buf->st_mode = attr.at_mode;
buf->st_uid = attr.at_uid;
buf->st_gid = attr.at_gid;
buf->st_atim.tv_sec = attr.at_atim / 1000000000ull;
@@ -1077,6 +1077,7 @@ static int littlefs_fstat(FAR const struct file *filep,
FAR struct stat *buf)
buf->st_ctim.tv_sec = attr.at_ctim / 1000000000ull;
buf->st_ctim.tv_nsec = attr.at_ctim % 1000000000ull;
#endif /* CONFIG_FS_LITTLEFS_ATTR_UPDATE */
+ buf->st_mode |= S_IFREG;
buf->st_blksize = fs->cfg.block_size;
buf->st_blocks = (buf->st_size + buf->st_blksize - 1) /
buf->st_blksize;