From 265692e709a1e379019d596fddaff8bfb4efb5e9 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Thu, 29 Jun 2023 12:23:33 -0500 Subject: [PATCH] Removed fsinfo.block_usage for now In terms of ease-of-use, a user familiar with other filesystems expects block_usage in fsinfo. But in terms of practicality, block_usage can be expensive to find in littlefs, so if it's not needed in the resulting fsinfo, that operation is wasteful. It's not clear to me what the best course of action is, but since block_usage can always be added to fsinfo later, but not removed without breaking backwards compatibility, I'm leaving this out for now. Block usage can still be found by explicitly calling lfs_fs_size. --- lfs.c | 7 ------- lfs.h | 6 ------ tests/test_superblocks.toml | 2 -- 3 files changed, 15 deletions(-) diff --git a/lfs.c b/lfs.c index c930adc5..9736c18e 100644 --- a/lfs.c +++ b/lfs.c @@ -4448,13 +4448,6 @@ static int lfs_fs_rawstat(lfs_t *lfs, struct lfs_fsinfo *fsinfo) { fsinfo->disk_version = superblock.version; } - // find the current block usage - lfs_ssize_t usage = lfs_fs_rawsize(lfs); - if (usage < 0) { - return usage; - } - fsinfo->block_usage = usage; - // other on-disk configuration, we cache all of these for internal use fsinfo->name_max = lfs->name_max; fsinfo->file_max = lfs->file_max; diff --git a/lfs.h b/lfs.h index d477cdd4..596ba5ed 100644 --- a/lfs.h +++ b/lfs.h @@ -285,12 +285,6 @@ struct lfs_fsinfo { // On-disk version. uint32_t disk_version; - // Number of blocks in use, this is the same as lfs_fs_size. - // - // Note: block_usage is best effort. If files share COW structures, the - // calculated block_usage may be larger than the actual contents on-disk. - lfs_size_t block_usage; - // Upper limit on the length of file names in bytes. lfs_size_t name_max; diff --git a/tests/test_superblocks.toml b/tests/test_superblocks.toml index 6ce148ba..f2fe452a 100644 --- a/tests/test_superblocks.toml +++ b/tests/test_superblocks.toml @@ -46,7 +46,6 @@ code = ''' struct lfs_fsinfo fsinfo; lfs_fs_stat(&lfs, &fsinfo) => 0; assert(fsinfo.disk_version == LFS_DISK_VERSION); - assert(fsinfo.block_usage > 0 && fsinfo.block_usage < BLOCK_COUNT); assert(fsinfo.name_max == LFS_NAME_MAX); assert(fsinfo.file_max == LFS_FILE_MAX); assert(fsinfo.attr_max == LFS_ATTR_MAX); @@ -74,7 +73,6 @@ code = ''' struct lfs_fsinfo fsinfo; lfs_fs_stat(&lfs, &fsinfo) => 0; assert(fsinfo.disk_version == LFS_DISK_VERSION); - assert(fsinfo.block_usage > 0 && fsinfo.block_usage < BLOCK_COUNT); assert(fsinfo.name_max == TWEAKED_NAME_MAX); assert(fsinfo.file_max == TWEAKED_FILE_MAX); assert(fsinfo.attr_max == TWEAKED_ATTR_MAX);