Skip to content

Commit

Permalink
fs/shmfs: Fix stat() system call for shmfs object
Browse files Browse the repository at this point in the history
Set i_size for shmfs objects
  • Loading branch information
pussuw committed Feb 2, 2024
1 parent ea1cbf0 commit ff63fc5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions fs/shm/shmfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions fs/vfs/fs_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/nuttx/fs/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff63fc5

Please sign in to comment.