You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/05/25 19:54:20 UTC

[incubator-nuttx] branch master updated: fs/vfs/fs_stat.c: fill file size for mtd inode

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new dd9d987  fs/vfs/fs_stat.c: fill file size for mtd inode
dd9d987 is described below

commit dd9d9878add676d4f77528955b076ba84b9a1d2b
Author: Oleg <ev...@gmail.com>
AuthorDate: Mon May 25 19:22:15 2020 +0300

    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 91e8631..74b11e9 100644
--- a/fs/vfs/fs_stat.c
+++ b/fs/vfs/fs_stat.c
@@ -46,6 +46,8 @@
 #include <errno.h>
 
 #include "inode/inode.h"
+#include <nuttx/mtd/mtd.h>
+#include <nuttx/fs/ioctl.h>
 
 /****************************************************************************
  * 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