Skip to content

Commit f694b14

Browse files
authored
Merge pull request #16 from geky/versioning
Add version info for software library and on-disk structures
2 parents 997c2e5 + 5a38d00 commit f694b14

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

.travis.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,31 @@ before_script:
4545
- sudo chmod a+rw /dev/loop0
4646
- dd if=/dev/zero bs=512 count=2048 of=disk
4747
- losetup /dev/loop0 disk
48+
49+
deploy:
50+
# Let before_deploy take over
51+
provider: script
52+
script: 'true'
53+
on:
54+
branch: master
55+
56+
before_deploy:
57+
- cd $TRAVIS_BUILD_DIR
58+
# Update tag for version defined in lfs.h
59+
- LFS_VERSION=$(grep -ox '#define LFS_VERSION .*' lfs.h | cut -d ' ' -f3)
60+
- LFS_VERSION_MAJOR=$((0xffff & ($LFS_VERSION >> 16)))
61+
- LFS_VERSION_MINOR=$((0xffff & ($LFS_VERSION >> 0)))
62+
- LFS_VERSION="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR"
63+
- |
64+
curl -u $GEKY_BOT -X POST \
65+
https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs \
66+
-d @- <<< "{
67+
\"ref\": \"refs/tags/$LFS_VERSION\",
68+
\"sha\": \"$TRAVIS_COMMIT\"
69+
}"
70+
- |
71+
curl -f -u $GEKY_BOT -X PATCH \
72+
https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs/tags/$LFS_VERSION \
73+
-d @- <<< "{
74+
\"sha\": \"$TRAVIS_COMMIT\"
75+
}"

lfs.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,7 +2067,7 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
20672067
.d.type = LFS_TYPE_SUPERBLOCK,
20682068
.d.elen = sizeof(superblock.d) - sizeof(superblock.d.magic) - 4,
20692069
.d.nlen = sizeof(superblock.d.magic),
2070-
.d.version = 0x00010001,
2070+
.d.version = LFS_DISK_VERSION,
20712071
.d.magic = {"littlefs"},
20722072
.d.block_size = lfs->cfg->block_size,
20732073
.d.block_count = lfs->cfg->block_count,
@@ -2140,10 +2140,11 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
21402140
return LFS_ERR_CORRUPT;
21412141
}
21422142

2143-
if (superblock.d.version > (0x00010001 | 0x0000ffff)) {
2144-
LFS_ERROR("Invalid version %d.%d",
2145-
0xffff & (superblock.d.version >> 16),
2146-
0xffff & (superblock.d.version >> 0));
2143+
uint16_t major_version = (0xffff & (superblock.d.version >> 16));
2144+
uint16_t minor_version = (0xffff & (superblock.d.version >> 0));
2145+
if ((major_version != LFS_DISK_VERSION_MAJOR ||
2146+
minor_version > LFS_DISK_VERSION_MINOR)) {
2147+
LFS_ERROR("Invalid version %d.%d", major_version, minor_version);
21472148
return LFS_ERR_INVAL;
21482149
}
21492150

lfs.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@
2222
#include <stdbool.h>
2323

2424

25+
/// Version info ///
26+
27+
// Software library version
28+
// Major (top-nibble), incremented on backwards incompatible changes
29+
// Minor (bottom-nibble), incremented on feature additions
30+
#define LFS_VERSION 0x00010002
31+
#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
32+
#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))
33+
34+
// Version of On-disk data structures
35+
// Major (top-nibble), incremented on backwards incompatible changes
36+
// Minor (bottom-nibble), incremented on feature additions
37+
#define LFS_DISK_VERSION 0x00010001
38+
#define LFS_DISK_VERSION_MAJOR (0xffff & (LFS_DISK_VERSION >> 16))
39+
#define LFS_DISK_VERSION_MINOR (0xffff & (LFS_DISK_VERSION >> 0))
40+
41+
2542
/// Definitions ///
2643

2744
// Type definitions

0 commit comments

Comments
 (0)