From c5fb3f181beff64de9cb2a7079594dfae29c982a Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 6 Jun 2023 21:52:04 -0500 Subject: [PATCH] Changed fsinfo.minor_version -> fsinfo.disk_version Version are now returned with major/minor packed into 32-bits, so 0x00020001 is the current disk version, for example. 1. This needed to change to use a disk_* prefix for consistency with the defines that already exist for LFS_VERSION/LFS_DISK_VERSION. 2. Encoding the version this way has the nice side effect of making 0 an invalid value. This is useful for adding a similar config option that needs to have reasonable default behavior for backwards compatibility. In theory this uses more space, but in practice most other config/status is 32-bits in littlefs. We would be wasting this space for alignment anyways. --- lfs.c | 6 +++--- lfs.h | 4 ++-- tests/test_compat.toml | 26 +++++++++++++------------- tests/test_superblocks.toml | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lfs.c b/lfs.c index 09fd71d9..c930adc5 100644 --- a/lfs.c +++ b/lfs.c @@ -4424,7 +4424,7 @@ static int lfs_fs_rawstat(lfs_t *lfs, struct lfs_fsinfo *fsinfo) { // if the superblock is up-to-date, we must be on the most recent // minor version of littlefs if (!lfs_gstate_needssuperblock(&lfs->gstate)) { - fsinfo->minor_version = LFS_DISK_VERSION_MINOR; + fsinfo->disk_version = LFS_DISK_VERSION; // otherwise we need to read the minor version on disk } else { @@ -4444,8 +4444,8 @@ static int lfs_fs_rawstat(lfs_t *lfs, struct lfs_fsinfo *fsinfo) { } lfs_superblock_fromle32(&superblock); - // read the minor version - fsinfo->minor_version = (0xffff & (superblock.version >> 0)); + // read the on-disk version + fsinfo->disk_version = superblock.version; } // find the current block usage diff --git a/lfs.h b/lfs.h index 25bd03c8..d477cdd4 100644 --- a/lfs.h +++ b/lfs.h @@ -282,8 +282,8 @@ struct lfs_info { // Filesystem info structure struct lfs_fsinfo { - // On-disk minor version. - uint16_t minor_version; + // On-disk version. + uint32_t disk_version; // Number of blocks in use, this is the same as lfs_fs_size. // diff --git a/tests/test_compat.toml b/tests/test_compat.toml index 4bb45d09..d84e68ea 100644 --- a/tests/test_compat.toml +++ b/tests/test_compat.toml @@ -80,7 +80,7 @@ code = ''' // we should be able to read the version using lfs_fs_stat struct lfs_fsinfo fsinfo; lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFSP_DISK_VERSION_MINOR); + assert(fsinfo.disk_version == LFSP_DISK_VERSION); lfs_unmount(&lfs) => 0; ''' @@ -113,7 +113,7 @@ code = ''' // we should be able to read the version using lfs_fs_stat struct lfs_fsinfo fsinfo; lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFSP_DISK_VERSION_MINOR); + assert(fsinfo.disk_version == LFSP_DISK_VERSION); // can we list the directories? lfs_dir_t dir; @@ -182,7 +182,7 @@ code = ''' // we should be able to read the version using lfs_fs_stat struct lfs_fsinfo fsinfo; lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFSP_DISK_VERSION_MINOR); + assert(fsinfo.disk_version == LFSP_DISK_VERSION); // can we list the files? lfs_dir_t dir; @@ -272,7 +272,7 @@ code = ''' // we should be able to read the version using lfs_fs_stat struct lfs_fsinfo fsinfo; lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFSP_DISK_VERSION_MINOR); + assert(fsinfo.disk_version == LFSP_DISK_VERSION); // can we list the directories? lfs_dir_t dir; @@ -369,7 +369,7 @@ code = ''' // we should be able to read the version using lfs_fs_stat struct lfs_fsinfo fsinfo; lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFSP_DISK_VERSION_MINOR); + assert(fsinfo.disk_version == LFSP_DISK_VERSION); // write another COUNT/2 dirs for (lfs_size_t i = COUNT/2; i < COUNT; i++) { @@ -451,7 +451,7 @@ code = ''' // we should be able to read the version using lfs_fs_stat struct lfs_fsinfo fsinfo; lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFSP_DISK_VERSION_MINOR); + assert(fsinfo.disk_version == LFSP_DISK_VERSION); // write half COUNT files prng = 42; @@ -573,7 +573,7 @@ code = ''' // we should be able to read the version using lfs_fs_stat struct lfs_fsinfo fsinfo; lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFSP_DISK_VERSION_MINOR); + assert(fsinfo.disk_version == LFSP_DISK_VERSION); // write half COUNT files prng = 42; @@ -1358,7 +1358,7 @@ code = ''' struct lfs_fsinfo fsinfo; lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFS_DISK_VERSION_MINOR-1); + assert(fsinfo.disk_version == LFS_DISK_VERSION-1); lfs_file_open(&lfs, &file, "test", LFS_O_RDONLY) => 0; uint8_t buffer[8]; @@ -1368,7 +1368,7 @@ code = ''' // minor version should be unchanged lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFS_DISK_VERSION_MINOR-1); + assert(fsinfo.disk_version == LFS_DISK_VERSION-1); lfs_unmount(&lfs) => 0; @@ -1376,7 +1376,7 @@ code = ''' lfs_mount(&lfs, cfg) => 0; lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFS_DISK_VERSION_MINOR-1); + assert(fsinfo.disk_version == LFS_DISK_VERSION-1); lfs_file_open(&lfs, &file, "test", LFS_O_WRONLY | LFS_O_TRUNC) => 0; lfs_file_write(&lfs, &file, "teeeeest", 8) => 8; @@ -1384,7 +1384,7 @@ code = ''' // minor version should be changed lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFS_DISK_VERSION_MINOR); + assert(fsinfo.disk_version == LFS_DISK_VERSION); lfs_unmount(&lfs) => 0; @@ -1393,7 +1393,7 @@ code = ''' // minor version should have changed lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFS_DISK_VERSION_MINOR); + assert(fsinfo.disk_version == LFS_DISK_VERSION); lfs_file_open(&lfs, &file, "test", LFS_O_RDONLY) => 0; lfs_file_read(&lfs, &file, buffer, 8) => 8; @@ -1402,7 +1402,7 @@ code = ''' // yep, still changed lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFS_DISK_VERSION_MINOR); + assert(fsinfo.disk_version == LFS_DISK_VERSION); lfs_unmount(&lfs) => 0; ''' diff --git a/tests/test_superblocks.toml b/tests/test_superblocks.toml index 3001fb41..6ce148ba 100644 --- a/tests/test_superblocks.toml +++ b/tests/test_superblocks.toml @@ -45,7 +45,7 @@ code = ''' struct lfs_fsinfo fsinfo; lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFS_DISK_VERSION_MINOR); + 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); @@ -73,7 +73,7 @@ code = ''' struct lfs_fsinfo fsinfo; lfs_fs_stat(&lfs, &fsinfo) => 0; - assert(fsinfo.minor_version == LFS_DISK_VERSION_MINOR); + 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);