You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2021/07/04 21:51:26 UTC
[incubator-nuttx] 03/03: fs/tmpfs: Account the filename in the
allocation block
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 7b54b7502c2165b4628cf40438ef8681d1feeb0d
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jun 25 14:35:01 2021 +0800
fs/tmpfs: Account the filename in the allocation block
and caclulate the available block more accurately
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
Change-Id: Ia6382239f422970771ccefbd6e461241a5f995a5
---
fs/tmpfs/fs_tmpfs.c | 31 +++++++++++++++----------------
fs/tmpfs/fs_tmpfs.h | 2 +-
2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c
index a60d70c..2fb5013 100644
--- a/fs/tmpfs/fs_tmpfs.c
+++ b/fs/tmpfs/fs_tmpfs.c
@@ -1094,7 +1094,8 @@ static int tmpfs_statfs_callout(FAR struct tmpfs_directory_s *tdo,
* for this object.
*/
- tmpbuf->tsf_alloc += to->to_alloc;
+ tmpbuf->tsf_alloc += to->to_alloc +
+ strlen(tdo->tdo_entry[index].tde_name) + 1;
/* Is this directory entry a file object? */
@@ -1108,13 +1109,12 @@ static int tmpfs_statfs_callout(FAR struct tmpfs_directory_s *tdo,
tmptfo = (FAR struct tmpfs_file_s *)to;
tmpbuf->tsf_alloc += sizeof(struct tmpfs_file_s);
- tmpbuf->tsf_inuse += tmptfo->tfo_size;
+ tmpbuf->tsf_avail += to->to_alloc - tmptfo->tfo_size;
tmpbuf->tsf_files++;
}
else /* if (to->to_type == TMPFS_DIRECTORY) */
{
FAR struct tmpfs_directory_s *tmptdo;
- size_t inuse;
size_t avail;
/* It is a directory object. Update the amount of memory in use
@@ -1122,11 +1122,11 @@ static int tmpfs_statfs_callout(FAR struct tmpfs_directory_s *tdo,
*/
tmptdo = (FAR struct tmpfs_directory_s *)to;
- inuse = SIZEOF_TMPFS_DIRECTORY(tmptdo->tdo_nentries);
- avail = tmptdo->tdo_alloc - inuse;
+ avail = tmptdo->tdo_alloc -
+ SIZEOF_TMPFS_DIRECTORY(tmptdo->tdo_nentries);
tmpbuf->tsf_alloc += sizeof(struct tmpfs_directory_s);
- tmpbuf->tsf_inuse += inuse;
+ tmpbuf->tsf_avail += avail;
tmpbuf->tsf_ffree += avail / sizeof(struct tmpfs_dirent_s);
}
@@ -2101,10 +2101,9 @@ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf)
FAR struct tmpfs_s *fs;
FAR struct tmpfs_directory_s *tdo;
struct tmpfs_statfs_s tmpbuf;
- size_t inuse;
size_t avail;
off_t blkalloc;
- off_t blkused;
+ off_t blkavail;
int ret;
finfo("mountpt: %p buf: %p\n", mountpt, buf);
@@ -2126,13 +2125,13 @@ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf)
/* Set up the memory use for the file system and root directory object */
tdo = (FAR struct tmpfs_directory_s *)fs->tfs_root.tde_object;
- inuse = sizeof(struct tmpfs_s) +
+ avail = tdo->tdo_alloc -
SIZEOF_TMPFS_DIRECTORY(tdo->tdo_nentries);
- avail = sizeof(struct tmpfs_s) +
- tdo->tdo_alloc - inuse;
- tmpbuf.tsf_alloc = tdo->tdo_alloc;
- tmpbuf.tsf_inuse = inuse;
+ tmpbuf.tsf_alloc = sizeof(struct tmpfs_s) +
+ sizeof(struct tmpfs_directory_s) +
+ tdo->tdo_alloc;
+ tmpbuf.tsf_avail = avail;
tmpbuf.tsf_files = 0;
tmpbuf.tsf_ffree = avail / sizeof(struct tmpfs_dirent_s);
@@ -2148,15 +2147,15 @@ static int tmpfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf)
blkalloc = (tmpbuf.tsf_alloc + CONFIG_FS_TMPFS_BLOCKSIZE - 1) /
CONFIG_FS_TMPFS_BLOCKSIZE;
- blkused = (tmpbuf.tsf_inuse + CONFIG_FS_TMPFS_BLOCKSIZE - 1) /
+ blkavail = (tmpbuf.tsf_avail + CONFIG_FS_TMPFS_BLOCKSIZE - 1) /
CONFIG_FS_TMPFS_BLOCKSIZE;
buf->f_type = TMPFS_MAGIC;
buf->f_namelen = NAME_MAX;
buf->f_bsize = CONFIG_FS_TMPFS_BLOCKSIZE;
buf->f_blocks = blkalloc;
- buf->f_bfree = blkalloc - blkused;
- buf->f_bavail = blkalloc - blkused;
+ buf->f_bfree = blkavail;
+ buf->f_bavail = blkavail;
buf->f_files = tmpbuf.tsf_files;
buf->f_ffree = tmpbuf.tsf_ffree;
diff --git a/fs/tmpfs/fs_tmpfs.h b/fs/tmpfs/fs_tmpfs.h
index 1ff08c3..27c1eb7 100644
--- a/fs/tmpfs/fs_tmpfs.h
+++ b/fs/tmpfs/fs_tmpfs.h
@@ -156,7 +156,7 @@ struct tmpfs_s
struct tmpfs_statfs_s
{
size_t tsf_alloc; /* Total memory allocated */
- size_t tsf_inuse; /* Total memory in use */
+ size_t tsf_avail; /* Total memory available */
off_t tsf_files; /* Total file nodes in the file system */
off_t tsf_ffree; /* Free directory nodes in the file system */
};