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
diff options
context:
space:
mode:
-rw-r--r--lfs.c15
-rw-r--r--lfs.h9
2 files changed, 11 insertions, 13 deletions
diff --git a/lfs.c b/lfs.c
index f6001a5..dbcf0f0 100644
--- a/lfs.c
+++ b/lfs.c
@@ -600,7 +600,7 @@ static int lfs_alloc_lookahead(void *p, lfs_block_t block) {
+ lfs->block_count) % lfs->block_count;
if (off < lfs->lookahead.size) {
- lfs->lookahead.buffer[off / 32] |= 1U << (off % 32);
+ lfs->lookahead.buffer[off / 8] |= 1U << (off % 8);
}
return 0;
@@ -653,8 +653,8 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
while (true) {
// scan our lookahead buffer for free blocks
while (lfs->lookahead.next < lfs->lookahead.size) {
- if (!(lfs->lookahead.buffer[lfs->lookahead.next / 32]
- & (1U << (lfs->lookahead.next % 32)))) {
+ if (!(lfs->lookahead.buffer[lfs->lookahead.next / 8]
+ & (1U << (lfs->lookahead.next % 8)))) {
// found a free block
*block = (lfs->lookahead.start + lfs->lookahead.next)
% lfs->block_count;
@@ -666,8 +666,8 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
lfs->lookahead.ckpoint -= 1;
if (lfs->lookahead.next >= lfs->lookahead.size
- || !(lfs->lookahead.buffer[lfs->lookahead.next / 32]
- & (1U << (lfs->lookahead.next % 32)))) {
+ || !(lfs->lookahead.buffer[lfs->lookahead.next / 8]
+ & (1U << (lfs->lookahead.next % 8)))) {
return 0;
}
}
@@ -4199,10 +4199,9 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
lfs_cache_zero(lfs, &lfs->rcache);
lfs_cache_zero(lfs, &lfs->pcache);
- // setup lookahead, must be multiple of 64-bits, 32-bit aligned
+ // setup lookahead buffer, note mount finishes initializing this after
+ // we establish a decent pseudo-random seed
LFS_ASSERT(lfs->cfg->lookahead_size > 0);
- LFS_ASSERT(lfs->cfg->lookahead_size % 8 == 0 &&
- (uintptr_t)lfs->cfg->lookahead_buffer % 4 == 0);
if (lfs->cfg->lookahead_buffer) {
lfs->lookahead.buffer = lfs->cfg->lookahead_buffer;
} else {
diff --git a/lfs.h b/lfs.h
index 524d087..ad1da35 100644
--- a/lfs.h
+++ b/lfs.h
@@ -226,7 +226,7 @@ struct lfs_config {
// Size of the lookahead buffer in bytes. A larger lookahead buffer
// increases the number of blocks found during an allocation pass. The
// lookahead buffer is stored as a compact bitmap, so each byte of RAM
- // can track 8 blocks. Must be a multiple of 8.
+ // can track 8 blocks.
lfs_size_t lookahead_size;
// Optional statically allocated read buffer. Must be cache_size.
@@ -237,9 +237,8 @@ struct lfs_config {
// By default lfs_malloc is used to allocate this buffer.
void *prog_buffer;
- // Optional statically allocated lookahead buffer. Must be lookahead_size
- // and aligned to a 32-bit boundary. By default lfs_malloc is used to
- // allocate this buffer.
+ // Optional statically allocated lookahead buffer. Must be lookahead_size.
+ // By default lfs_malloc is used to allocate this buffer.
void *lookahead_buffer;
// Optional upper limit on length of file names in bytes. No downside for
@@ -435,7 +434,7 @@ typedef struct lfs {
lfs_block_t size;
lfs_block_t next;
lfs_block_t ckpoint;
- uint32_t *buffer;
+ uint8_t *buffer;
} lookahead;
const struct lfs_config *cfg;