From 181eb79616a343905f5f9c2656d6e956c9b58135 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 13 Feb 2017 08:22:05 -0600 Subject: [PATCH] fstat: Add fstat() support to nxffs. --- fs/nxffs/nxffs_stat.c | 48 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/fs/nxffs/nxffs_stat.c b/fs/nxffs/nxffs_stat.c index a896c299aa..7a0f3a2b04 100644 --- a/fs/nxffs/nxffs_stat.c +++ b/fs/nxffs/nxffs_stat.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -149,6 +150,8 @@ int nxffs_stat(FAR struct inode *mountpt, FAR const char *relpath, goto errout_with_semaphore; } + /* Return status information based on the directory entry */ + buf->st_blocks = entry.datlen / (volume->geo.blocksize - SIZEOF_NXFFS_BLOCK_HDR); buf->st_mode = S_IFREG | S_IXOTH | S_IXGRP | S_IXUSR; buf->st_size = entry.datlen; @@ -187,7 +190,46 @@ errout: int nxffs_fstat(FAR const struct file *filep, FAR struct stat *buf) { -#warning Missing logic - return -ENOSYS; -} + FAR struct nxffs_volume_s *volume; + FAR struct nxffs_ofile_s *ofile; + int ret; + + finfo("Buf %s\n", buf); + DEBUGASSERT(filep != NULL && buf != NULL); + + /* Recover the open file state from the struct file instance */ + + DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); + ofile = (FAR struct nxffs_ofile_s *)filep->f_priv; + + /* Recover the volume state from the open file */ + + volume = (FAR struct nxffs_volume_s *)filep->f_inode->i_private; + DEBUGASSERT(volume != NULL); + + /* Get exclusive access to the volume. Note that the volume exclsem + * protects the open file list. + */ + + ret = sem_wait(&volume->exclsem); + if (ret != OK) + { + int errcode = get_errno(); + ferr("ERROR: sem_wait failed: %d\n", errcode); + return -errcode; + } + + /* Return status information based on the directory entry */ + + buf->st_blocks = ofile->entry.datlen / + (volume->geo.blocksize - SIZEOF_NXFFS_BLOCK_HDR); + buf->st_mode = S_IFREG | S_IXOTH | S_IXGRP | S_IXUSR; + buf->st_size = ofile->entry.datlen; + buf->st_atime = ofile->entry.utc; + buf->st_mtime = ofile->entry.utc; + buf->st_ctime = ofile->entry.utc; + + sem_post(&volume->exclsem); + return OK; +}