You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/03/10 06:15:30 UTC
[incubator-nuttx] branch master updated: xtensa hostfs: Make
host_stat populate st_size
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang 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 16d3e78 xtensa hostfs: Make host_stat populate st_size
16d3e78 is described below
commit 16d3e787de940041277bfffa85acad0126afb877
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Wed Mar 10 11:17:33 2021 +0900
xtensa hostfs: Make host_stat populate st_size
A clumsy implementation using lseek.
This would allow more applications to use hostfs directly.
Tested lightly with CONFIG_EXAMPLES_STAT.
---
arch/xtensa/src/common/xtensa_hostfs.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/arch/xtensa/src/common/xtensa_hostfs.c b/arch/xtensa/src/common/xtensa_hostfs.c
index 094a657..d63682d 100644
--- a/arch/xtensa/src/common/xtensa_hostfs.c
+++ b/arch/xtensa/src/common/xtensa_hostfs.c
@@ -135,10 +135,21 @@ int host_dup(int fd)
int host_fstat(int fd, struct stat *buf)
{
- /* XXX determine the size using lseek? */
+ /* Determine the size using lseek.
+ *
+ * Assumptions:
+ * - host_lseek never fails
+ * - It's ok to change the file offset temporarily as
+ * hostfs_semtake provides enough serialization.
+ */
+
+ off_t saved_off = host_lseek(fd, 0, SEEK_CUR);
+ off_t size = host_lseek(fd, 0, SEEK_END);
+ host_lseek(fd, saved_off, SEEK_SET);
memset(buf, 0, sizeof(*buf));
buf->st_mode = S_IFREG | 0777;
+ buf->st_size = size;
return 0;
}