-
Couldn't load subscription status.
- Fork 931
Open
Labels
needs investigationno idea what is wrongno idea what is wrong
Description
We're using LFS 1.7.1 in our system and recently had an issue on a single device where an LFS_ASSERT was triggered when lfs_file_read was called. We're wondering if this is a flaw in 1.7.1 or possibly related to something we might be doing incorrectly in our use of the lfs API?
The LFS_ASSERT occurred in lfs_ctz_find in lfs.c line 1144.
The specific assertion says: LFS_ASSERT(head >= 2 && head <= lfs->cfg->block_count);
This is the relevant code:
static int lfs_ctz_find(lfs_t *lfs,
lfs_cache_t *rcache, const lfs_cache_t *pcache,
lfs_block_t head, lfs_size_t size,
lfs_size_t pos, lfs_block_t *block, lfs_off_t *off) {
if (size == 0) {
*block = 0xffffffff;
*off = 0;
return 0;
}
lfs_off_t current = lfs_ctz_index(lfs, &(lfs_off_t){size-1});
lfs_off_t target = lfs_ctz_index(lfs, &pos);
while (current > target) {
lfs_size_t skip = lfs_min(
lfs_npw2(current-target+1) - 1,
lfs_ctz(current));
int err = lfs_cache_read(lfs, rcache, pcache, head, 4*skip, &head, 4);
head = lfs_fromle32(head);
if (err) {
return err;
}
LFS_ASSERT(head >= 2 && head <= lfs->cfg->block_count);
current -= 1 << skip;
}
*block = head;
*off = pos;
return 0;
}The git hash we are using:
SHA-1: d3a2cf4
Our configuration is:
// Statically allocated read buffer. Must be read sized.
static uint8_t read_buffer[256];
// Statically allocated program buffer. Must be program sized.
static uint8_t prog_buffer[256];
// Statically allocated lookahead buffer. Must be 1 bit per lookahead block.
static uint8_t lookahead_buffer[128];
// configuration of the filesystem is provided by this struct
static struct lfs_config m_lfsCfg = {
// block device operations
.read = lfs_read,
.prog = lfs_prog,
.erase = lfs_erase,
.sync = lfs_sync,
// block device configuration
#define FLASH_SIZE_BYTES ((128*1024*1024)/8)
#define SERIAL_FLASH_BLOCK_ERASE_BYTES (32768)
#define SERIAL_FLASH_READ_SIZE (256)
#define SERIAL_FLASH_WRITE_SIZE (256)
.read_size = SERIAL_FLASH_READ_SIZE,
.prog_size = SERIAL_FLASH_WRITE_SIZE,
.block_size = SERIAL_FLASH_BLOCK_ERASE_BYTES,
.block_count = FLASH_SIZE_BYTES/SERIAL_FLASH_BLOCK_ERASE_BYTES,
.lookahead = 128, // Should be a multiple of 32.
// Statically allocated read buffer. Must be read sized.
.read_buffer = read_buffer,
// Statically allocated program buffer. Must be program sized.
.prog_buffer = prog_buffer,
// Statically allocated lookahead buffer. Must be 1 bit per lookahead block.
.lookahead_buffer = lookahead_buffer,
//Statically allocated buffer for files. Must be program sized.
// If enabled, only one file may be opened at a time.
//.file_buffer = file_buffer,
}Metadata
Metadata
Assignees
Labels
needs investigationno idea what is wrongno idea what is wrong