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.
This commit is contained in:
Christopher Haster
2023-06-06 21:52:04 -05:00
parent 8610f7c36b
commit c5fb3f181b
4 changed files with 20 additions and 20 deletions

6
lfs.c
View File

@@ -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

4
lfs.h
View File

@@ -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.
//

View File

@@ -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;
'''

View File

@@ -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);