From 5a12c443b892b7b35d770db59da71a2cbb73ce91 Mon Sep 17 00:00:00 2001 From: Freddie Chopin Date: Fri, 9 Aug 2019 23:02:33 +0200 Subject: [PATCH 1/5] Revert "Don't bypass cache in `lfs_cache_prog()` and `lfs_cache_read()`" This reverts commit fdd239fe21a3721dc7fb55a9cf816544af7e9647. Bypassing cache turned out to be a mistake which causes more problems than it solves. Device driver should deal with alignment if this is required - trying to do that in a file system is not a viable solution anyway. --- lfs.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lfs.c b/lfs.c index b10c186..a96f327 100644 --- a/lfs.c +++ b/lfs.c @@ -71,6 +71,21 @@ static int lfs_bd_read(lfs_t *lfs, diff = lfs_min(diff, rcache->off-off); } + if (size >= hint && off % lfs->cfg->read_size == 0 && + size >= lfs->cfg->read_size) { + // bypass cache? + diff = lfs_aligndown(diff, lfs->cfg->read_size); + int err = lfs->cfg->read(lfs->cfg, block, off, data, diff); + if (err) { + return err; + } + + data += diff; + off += diff; + size -= diff; + continue; + } + // load to cache, first condition can no longer fail LFS_ASSERT(block < lfs->cfg->block_count); rcache->block = block; From 626006af0caefc0ad3f1749ceb06410e5704d130 Mon Sep 17 00:00:00 2001 From: Joe Doyle Date: Thu, 2 Jan 2020 13:46:07 -0800 Subject: [PATCH 2/5] Fix incorrect comment on `lfs_npw2` `lfs_npw2` returns a value v such that `2^v >= a` and `2^(v-1) < a`, but the previous comment incorrectly describes it as "less than or equal to a". --- lfs_util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lfs_util.h b/lfs_util.h index 80fab55..696876f 100644 --- a/lfs_util.h +++ b/lfs_util.h @@ -107,7 +107,7 @@ static inline uint32_t lfs_alignup(uint32_t a, uint32_t alignment) { return lfs_aligndown(a + alignment-1, alignment); } -// Find the next smallest power of 2 less than or equal to a +// Find the smallest power of 2 greater than or equal to a static inline uint32_t lfs_npw2(uint32_t a) { #if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM)) return 32 - __builtin_clz(a-1); From c8e9a64a2140b08ad2e7eddbf8be067c84aebf57 Mon Sep 17 00:00:00 2001 From: Henry Gabryjelski Date: Mon, 27 Jan 2020 21:51:12 -0800 Subject: [PATCH 3/5] Indicate C99 standard as target for LittleFS code Resolve #358 --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 41d5890..f900674 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,9 @@ the filesystem until sync or close is called on the file. ## Other notes +Littlefs is written in C, and specifically should compile with any compiler +that conforms to the `C99` standard. + All littlefs calls have the potential to return a negative error code. The errors can be either one of those found in the `enum lfs_error` in [lfs.h](lfs.h), or an error returned by the user's block device operations. From 4fb188369dbdc037c291d342e798a9091d3ba2cc Mon Sep 17 00:00:00 2001 From: zhuangqiubin Date: Thu, 19 Dec 2019 20:58:53 +0800 Subject: [PATCH 4/5] Update SPEC.md 1.fix size in Layout of the CRC tag 2.update (size) to (size * 8) --- SPEC.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/SPEC.md b/SPEC.md index e6622d3..cc602c1 100644 --- a/SPEC.md +++ b/SPEC.md @@ -289,8 +289,8 @@ Layout of the name tag: ``` tag data [-- 32 --][--- variable length ---] -[1| 3| 8 | 10 | 10 ][--- (size) ---] - ^ ^ ^ ^ ^- size ^- file name +[1| 3| 8 | 10 | 10 ][--- (size * 8) ---] + ^ ^ ^ ^ ^- size ^- file name | | | '------ id | | '----------- file type | '-------------- type1 (0x0) @@ -470,8 +470,8 @@ Layout of the inline-struct tag: ``` tag data [-- 32 --][--- variable length ---] -[1|- 11 -| 10 | 10 ][--- (size) ---] - ^ ^ ^ ^- size ^- inline data +[1|- 11 -| 10 | 10 ][--- (size * 8) ---] + ^ ^ ^ ^- size ^- inline data | | '------ id | '------------ type (0x201) '----------------- valid bit @@ -556,8 +556,8 @@ Layout of the user-attr tag: ``` tag data [-- 32 --][--- variable length ---] -[1| 3| 8 | 10 | 10 ][--- (size) ---] - ^ ^ ^ ^ ^- size ^- attr data +[1| 3| 8 | 10 | 10 ][--- (size * 8) ---] + ^ ^ ^ ^ ^- size ^- attr data | | | '------ id | | '----------- attr type | '-------------- type1 (0x3) @@ -764,9 +764,9 @@ Layout of the CRC tag: ``` tag data [-- 32 --][-- 32 --|--- variable length ---] -[1| 3| 8 | 10 | 10 ][-- 32 --|--- (size) ---] - ^ ^ ^ ^ ^ ^- crc ^- padding - | | | | '- size (12) +[1| 3| 8 | 10 | 10 ][-- 32 --|--- (size * 8 - 32) ---] + ^ ^ ^ ^ ^ ^- crc ^- padding + | | | | '- size | | | '------ id (0x3ff) | | '----------- valid state | '-------------- type1 (0x5) From 6372f515fe59616bd7e00ca7bcce762c05ab029b Mon Sep 17 00:00:00 2001 From: John Hemmick <33430538+hemmick@users.noreply.github.com> Date: Tue, 5 Nov 2019 14:43:02 -0600 Subject: [PATCH 5/5] Allow debug prints without __VA_ARGS__ __VA_ARGS__ are frustrating in C. Even for their main purpose (printf), they fall short in that they don't have a _portable_ way to have zero arguments after the format string in a printf call. Even if we detect compilers and use ##__VA_ARGS__ where available, GCC emits a warning with -pedantic that is _impossible_ to explicitly disable. This commit contains the best solution we can think of. A bit of indirection that adds a hidden "%s" % "" to the end of the format string. This solution does not work everywhere as it has a runtime cost, but it is hopefully ok for debug statements. --- lfs_util.h | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lfs_util.h b/lfs_util.h index 80fab55..2544bc9 100644 --- a/lfs_util.h +++ b/lfs_util.h @@ -50,31 +50,35 @@ extern "C" // Logging functions #ifdef LFS_YES_TRACE -#define LFS_TRACE(fmt, ...) \ - printf("lfs_trace:%d: " fmt "\n", __LINE__, __VA_ARGS__) +#define LFS_TRACE_(fmt, ...) \ + printf("lfs_trace:%d: " fmt "%s\n", __LINE__, __VA_ARGS__) +#define LFS_TRACE(...) LFS_TRACE_(__VA_ARGS__, "") #else -#define LFS_TRACE(fmt, ...) +#define LFS_TRACE(...) #endif #ifndef LFS_NO_DEBUG -#define LFS_DEBUG(fmt, ...) \ - printf("lfs_debug:%d: " fmt "\n", __LINE__, __VA_ARGS__) +#define LFS_DEBUG_(fmt, ...) \ + printf("lfs_debug:%d: " fmt "%s\n", __LINE__, __VA_ARGS__) +#define LFS_DEBUG(...) LFS_DEBUG_(__VA_ARGS__, "") #else -#define LFS_DEBUG(fmt, ...) +#define LFS_DEBUG(...) #endif #ifndef LFS_NO_WARN -#define LFS_WARN(fmt, ...) \ - printf("lfs_warn:%d: " fmt "\n", __LINE__, __VA_ARGS__) +#define LFS_WARN_(fmt, ...) \ + printf("lfs_warn:%d: " fmt "%s\n", __LINE__, __VA_ARGS__) +#define LFS_WARN(...) LFS_WARN_(__VA_ARGS__, "") #else -#define LFS_WARN(fmt, ...) +#define LFS_WARN(...) #endif #ifndef LFS_NO_ERROR -#define LFS_ERROR(fmt, ...) \ - printf("lfs_error:%d: " fmt "\n", __LINE__, __VA_ARGS__) +#define LFS_ERROR_(fmt, ...) \ + printf("lfs_error:%d: " fmt "%s\n", __LINE__, __VA_ARGS__) +#define LFS_ERROR(...) LFS_ERROR_(__VA_ARGS__, "") #else -#define LFS_ERROR(fmt, ...) +#define LFS_ERROR(...) #endif // Runtime assertions