littlefs_stat: Fix directory size

lfs_info.size is only valid for LFS_TYPE_REG.
For directory, use 0 instead of stack garbage.
This commit is contained in:
YAMAMOTO Takashi 2022-05-20 19:07:54 +09:00 committed by Petro Karashchenko
parent 91063e85f0
commit 0a1ac4762a
1 changed files with 2 additions and 1 deletions

View File

@ -1430,13 +1430,14 @@ static int littlefs_stat(FAR struct inode *mountpt, FAR const char *relpath,
if (info.type == LFS_TYPE_REG) if (info.type == LFS_TYPE_REG)
{ {
buf->st_mode |= S_IFREG; buf->st_mode |= S_IFREG;
buf->st_size = info.size;
} }
else else
{ {
buf->st_mode |= S_IFDIR; buf->st_mode |= S_IFDIR;
buf->st_size = 0;
} }
buf->st_size = info.size;
buf->st_blksize = fs->cfg.block_size; buf->st_blksize = fs->cfg.block_size;
buf->st_blocks = (buf->st_size + buf->st_blksize - 1) / buf->st_blocks = (buf->st_size + buf->st_blksize - 1) /
buf->st_blksize; buf->st_blksize;