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:
@@ -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
|
// if the superblock is up-to-date, we must be on the most recent
|
||||||
// minor version of littlefs
|
// minor version of littlefs
|
||||||
if (!lfs_gstate_needssuperblock(&lfs->gstate)) {
|
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
|
// otherwise we need to read the minor version on disk
|
||||||
} else {
|
} else {
|
||||||
@@ -4444,8 +4444,8 @@ static int lfs_fs_rawstat(lfs_t *lfs, struct lfs_fsinfo *fsinfo) {
|
|||||||
}
|
}
|
||||||
lfs_superblock_fromle32(&superblock);
|
lfs_superblock_fromle32(&superblock);
|
||||||
|
|
||||||
// read the minor version
|
// read the on-disk version
|
||||||
fsinfo->minor_version = (0xffff & (superblock.version >> 0));
|
fsinfo->disk_version = superblock.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the current block usage
|
// find the current block usage
|
||||||
|
|||||||
@@ -282,8 +282,8 @@ struct lfs_info {
|
|||||||
|
|
||||||
// Filesystem info structure
|
// Filesystem info structure
|
||||||
struct lfs_fsinfo {
|
struct lfs_fsinfo {
|
||||||
// On-disk minor version.
|
// On-disk version.
|
||||||
uint16_t minor_version;
|
uint32_t disk_version;
|
||||||
|
|
||||||
// Number of blocks in use, this is the same as lfs_fs_size.
|
// Number of blocks in use, this is the same as lfs_fs_size.
|
||||||
//
|
//
|
||||||
|
|||||||
+13
-13
@@ -80,7 +80,7 @@ code = '''
|
|||||||
// we should be able to read the version using lfs_fs_stat
|
// we should be able to read the version using lfs_fs_stat
|
||||||
struct lfs_fsinfo fsinfo;
|
struct lfs_fsinfo fsinfo;
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
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;
|
lfs_unmount(&lfs) => 0;
|
||||||
'''
|
'''
|
||||||
@@ -113,7 +113,7 @@ code = '''
|
|||||||
// we should be able to read the version using lfs_fs_stat
|
// we should be able to read the version using lfs_fs_stat
|
||||||
struct lfs_fsinfo fsinfo;
|
struct lfs_fsinfo fsinfo;
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
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?
|
// can we list the directories?
|
||||||
lfs_dir_t dir;
|
lfs_dir_t dir;
|
||||||
@@ -182,7 +182,7 @@ code = '''
|
|||||||
// we should be able to read the version using lfs_fs_stat
|
// we should be able to read the version using lfs_fs_stat
|
||||||
struct lfs_fsinfo fsinfo;
|
struct lfs_fsinfo fsinfo;
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
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?
|
// can we list the files?
|
||||||
lfs_dir_t dir;
|
lfs_dir_t dir;
|
||||||
@@ -272,7 +272,7 @@ code = '''
|
|||||||
// we should be able to read the version using lfs_fs_stat
|
// we should be able to read the version using lfs_fs_stat
|
||||||
struct lfs_fsinfo fsinfo;
|
struct lfs_fsinfo fsinfo;
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
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?
|
// can we list the directories?
|
||||||
lfs_dir_t dir;
|
lfs_dir_t dir;
|
||||||
@@ -369,7 +369,7 @@ code = '''
|
|||||||
// we should be able to read the version using lfs_fs_stat
|
// we should be able to read the version using lfs_fs_stat
|
||||||
struct lfs_fsinfo fsinfo;
|
struct lfs_fsinfo fsinfo;
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
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
|
// write another COUNT/2 dirs
|
||||||
for (lfs_size_t i = COUNT/2; i < COUNT; i++) {
|
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
|
// we should be able to read the version using lfs_fs_stat
|
||||||
struct lfs_fsinfo fsinfo;
|
struct lfs_fsinfo fsinfo;
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
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
|
// write half COUNT files
|
||||||
prng = 42;
|
prng = 42;
|
||||||
@@ -573,7 +573,7 @@ code = '''
|
|||||||
// we should be able to read the version using lfs_fs_stat
|
// we should be able to read the version using lfs_fs_stat
|
||||||
struct lfs_fsinfo fsinfo;
|
struct lfs_fsinfo fsinfo;
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
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
|
// write half COUNT files
|
||||||
prng = 42;
|
prng = 42;
|
||||||
@@ -1358,7 +1358,7 @@ code = '''
|
|||||||
|
|
||||||
struct lfs_fsinfo fsinfo;
|
struct lfs_fsinfo fsinfo;
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 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_RDONLY) => 0;
|
lfs_file_open(&lfs, &file, "test", LFS_O_RDONLY) => 0;
|
||||||
uint8_t buffer[8];
|
uint8_t buffer[8];
|
||||||
@@ -1368,7 +1368,7 @@ code = '''
|
|||||||
|
|
||||||
// minor version should be unchanged
|
// minor version should be unchanged
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 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_unmount(&lfs) => 0;
|
lfs_unmount(&lfs) => 0;
|
||||||
|
|
||||||
@@ -1376,7 +1376,7 @@ code = '''
|
|||||||
lfs_mount(&lfs, cfg) => 0;
|
lfs_mount(&lfs, cfg) => 0;
|
||||||
|
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 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_open(&lfs, &file, "test", LFS_O_WRONLY | LFS_O_TRUNC) => 0;
|
||||||
lfs_file_write(&lfs, &file, "teeeeest", 8) => 8;
|
lfs_file_write(&lfs, &file, "teeeeest", 8) => 8;
|
||||||
@@ -1384,7 +1384,7 @@ code = '''
|
|||||||
|
|
||||||
// minor version should be changed
|
// minor version should be changed
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
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;
|
lfs_unmount(&lfs) => 0;
|
||||||
|
|
||||||
@@ -1393,7 +1393,7 @@ code = '''
|
|||||||
|
|
||||||
// minor version should have changed
|
// minor version should have changed
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
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_open(&lfs, &file, "test", LFS_O_RDONLY) => 0;
|
||||||
lfs_file_read(&lfs, &file, buffer, 8) => 8;
|
lfs_file_read(&lfs, &file, buffer, 8) => 8;
|
||||||
@@ -1402,7 +1402,7 @@ code = '''
|
|||||||
|
|
||||||
// yep, still changed
|
// yep, still changed
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
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;
|
lfs_unmount(&lfs) => 0;
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ code = '''
|
|||||||
|
|
||||||
struct lfs_fsinfo fsinfo;
|
struct lfs_fsinfo fsinfo;
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
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.block_usage > 0 && fsinfo.block_usage < BLOCK_COUNT);
|
||||||
assert(fsinfo.name_max == LFS_NAME_MAX);
|
assert(fsinfo.name_max == LFS_NAME_MAX);
|
||||||
assert(fsinfo.file_max == LFS_FILE_MAX);
|
assert(fsinfo.file_max == LFS_FILE_MAX);
|
||||||
@@ -73,7 +73,7 @@ code = '''
|
|||||||
|
|
||||||
struct lfs_fsinfo fsinfo;
|
struct lfs_fsinfo fsinfo;
|
||||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
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.block_usage > 0 && fsinfo.block_usage < BLOCK_COUNT);
|
||||||
assert(fsinfo.name_max == TWEAKED_NAME_MAX);
|
assert(fsinfo.name_max == TWEAKED_NAME_MAX);
|
||||||
assert(fsinfo.file_max == TWEAKED_FILE_MAX);
|
assert(fsinfo.file_max == TWEAKED_FILE_MAX);
|
||||||
|
|||||||
Reference in New Issue
Block a user