From dd9d9878add676d4f77528955b076ba84b9a1d2b Mon Sep 17 00:00:00 2001 From: Oleg Date: Mon, 25 May 2020 19:22:15 +0300 Subject: [PATCH] fs/vfs/fs_stat.c: fill file size for mtd inode Now when stat() is calling for mtd device it also set size of file as number of bytes of all sectors related to this mtd device. --- fs/vfs/fs_stat.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/vfs/fs_stat.c b/fs/vfs/fs_stat.c index 91e8631b87..74b11e9402 100644 --- a/fs/vfs/fs_stat.c +++ b/fs/vfs/fs_stat.c @@ -46,6 +46,8 @@ #include #include "inode/inode.h" +#include +#include /**************************************************************************** * Pre-processor Definitions @@ -303,6 +305,14 @@ int inode_stat(FAR struct inode *inode, FAR struct stat *buf) buf->st_mode = S_IFMTD; buf->st_mode |= S_IROTH | S_IRGRP | S_IRUSR; buf->st_mode |= S_IWOTH | S_IWGRP | S_IWUSR; + + struct mtd_geometry_s mtdgeo; + if (inode->u.i_mtd + && MTD_IOCTL(inode->u.i_mtd, MTDIOC_GEOMETRY, + (unsigned long)((uintptr_t)&mtdgeo)) >= 0) + { + buf->st_size = mtdgeo.neraseblocks * mtdgeo.erasesize; + } } else #endif