Enforced stat/dir_read of a dir results in size=0

The size field in lfs_info doesn't really make sense for stat/dir_read
when the file is a directory. Still, we should probably set it to 0 os
it's not uninitialized.

Fortunately we were already setting size=0 in _most_ cases, this commit
is mostly just checking for size=0 in more test cases.
This commit is contained in:
Christopher Haster
2024-01-19 02:12:11 -06:00
parent d32dbd297a
commit 9adb22eee0
7 changed files with 948 additions and 2 deletions
+5 -2
View File
@@ -8813,6 +8813,7 @@ int lfsr_stat(lfs_t *lfs, const char *path, struct lfs_info *info) {
if (err == LFS_ERR_INVAL) {
strcpy(info->name, "/");
info->type = LFS_TYPE_DIR;
info->size = 0;
return 0;
}
@@ -8901,13 +8902,15 @@ int lfsr_dir_read(lfs_t *lfs, lfsr_dir_t *dir, struct lfs_info *info) {
// handle dots specially
if (dir->pos == 0) {
info->type = LFS_TYPE_DIR;
strcpy(info->name, ".");
info->type = LFS_TYPE_DIR;
info->size = 0;
dir->pos += 1;
return 0;
} else if (dir->pos == 1) {
info->type = LFS_TYPE_DIR;
strcpy(info->name, "..");
info->type = LFS_TYPE_DIR;
info->size = 0;
dir->pos += 1;
return 0;
}