From f0846e1d2ddd1787a811f43f8790717a028de0ff 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 fef22222ef..b7095907e7 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 74984fb300..200e629dcf 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 f17a04f5eb..3d2ccec42b 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -412,7 +412,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