From ff63fc5d204cb5c49e2d1e86b567f199e85d31ff Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Thu, 1 Feb 2024 12:31:46 +0200 Subject: [PATCH] fs/shmfs: Fix stat() system call for shmfs object Set i_size for shmfs objects --- fs/shm/shmfs.c | 5 +++++ fs/vfs/fs_stat.c | 1 + include/nuttx/fs/fs.h | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/shm/shmfs.c b/fs/shm/shmfs.c index 1c9da72709d02..43633f70a3837 100644 --- a/fs/shm/shmfs.c +++ b/fs/shm/shmfs.c @@ -238,8 +238,13 @@ static int shmfs_truncate(FAR struct file *filep, off_t length) filep->f_inode->i_private = shmfs_alloc_object(length); if (!filep->f_inode->i_private) { + filep->f_inode->i_size = 0; ret = -EFAULT; } + else + { + filep->f_inode->i_size = length; + } } else if (object->length != length) { diff --git a/fs/vfs/fs_stat.c b/fs/vfs/fs_stat.c index 74984fb300d38..200e629dcf7c1 100644 --- a/fs/vfs/fs_stat.c +++ b/fs/vfs/fs_stat.c @@ -284,6 +284,7 @@ int inode_stat(FAR struct inode *inode, FAR struct stat *buf, int resolve) if (INODE_IS_SHM(inode)) { buf->st_mode = S_IFSHM; + buf->st_size = inode->i_size; } else #endif diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index fd6e0157bffab..1504b905d449b 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -408,7 +408,7 @@ struct inode uint16_t i_flags; /* Flags for inode */ union inode_ops_u u; /* Inode operations */ ino_t i_ino; /* Inode serial number */ -#ifdef CONFIG_PSEUDOFS_FILE +#if defined(CONFIG_PSEUDOFS_FILE) || defined(CONFIG_FS_SHMFS) size_t i_size; /* The size of per inode driver */ #endif #ifdef CONFIG_PSEUDOFS_ATTRIBUTES