Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lfs.c
diff options
context:
space:
mode:
authorChristopher Haster <chaster@utexas.edu>2018-01-26 23:26:25 +0300
committerChristopher Haster <chaster@utexas.edu>2018-01-26 23:26:25 +0300
commit035552a858f562872d9c47809606fbe329106030 (patch)
treee5055f467cb262b9cc3345a9e9061dd5aa9aa749 /lfs.c
parent997c2e594e2880b15d3ec069aae4320c110c3bf0 (diff)
Add version info for software library and on-disk structures
An annoying part of filesystems is that the software library can change independently of the on-disk structures. For this reason versioning is very important, and must be handled separately for the software and on-disk parts. In this patch, littlefs provides two version numbers at compile time, with major and minor parts, in the form of 6 macros. LFS_VERSION // Library version, uint32_t encoded LFS_VERSION_MAJOR // Major - Backwards incompatible changes LFS_VERSION_MINOR // Minor - Feature additions LFS_DISK_VERSION // On-disk version, uint32_t encoded LFS_DISK_VERSION_MAJOR // Major - Backwards incompatible changes LFS_DISK_VERSION_MINOR // Minor - Feature additions Note that littlefs will error if it finds a major version number that is different, or a minor version number that has regressed.
Diffstat (limited to 'lfs.c')
-rw-r--r--lfs.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lfs.c b/lfs.c
index ff4d1da..4f75989 100644
--- a/lfs.c
+++ b/lfs.c
@@ -2067,7 +2067,7 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
.d.type = LFS_TYPE_SUPERBLOCK,
.d.elen = sizeof(superblock.d) - sizeof(superblock.d.magic) - 4,
.d.nlen = sizeof(superblock.d.magic),
- .d.version = 0x00010001,
+ .d.version = LFS_DISK_VERSION,
.d.magic = {"littlefs"},
.d.block_size = lfs->cfg->block_size,
.d.block_count = lfs->cfg->block_count,
@@ -2140,10 +2140,11 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
return LFS_ERR_CORRUPT;
}
- if (superblock.d.version > (0x00010001 | 0x0000ffff)) {
- LFS_ERROR("Invalid version %d.%d",
- 0xffff & (superblock.d.version >> 16),
- 0xffff & (superblock.d.version >> 0));
+ uint16_t major_version = (0xffff & (superblock.d.version >> 16));
+ uint16_t minor_version = (0xffff & (superblock.d.version >> 0));
+ if ((major_version != LFS_DISK_VERSION_MAJOR ||
+ minor_version > LFS_DISK_VERSION_MINOR)) {
+ LFS_ERROR("Invalid version %d.%d", major_version, minor_version);
return LFS_ERR_INVAL;
}