-
Couldn't load subscription status.
- Fork 932
Closed
Labels
Description
I have a test where I create more and more files of size 511B, where block size is 4K and cache size is 0.5K, hence files are inline.
In some point close fails with error -28 (which make sense, space finished..) and the open file afterward causes assert from the pcache->block == LFS_BLOCK_NULL check.
I guess that the failing close wasn't really closed properly and didn't released all resources (left pcache not cleaned).
Code to reproduce (using rambd):
#include "lfs.h"
#include "bd/lfs_rambd.h"
// variables used by the filesystem
lfs_t lfs;
lfs_file_t file;
lfs_rambd_t bdCtx;
#define BLOCK_SIZE 0x1000
#define NUM_OF_BLOCKS 28
#define FLASH_SIZE (BLOCK_SIZE * NUM_OF_BLOCKS)
// configuration of the filesystem is provided by this struct
const struct lfs_config cfg = {
.context = &bdCtx,
// block device operations
.read = lfs_rambd_read,
.prog = lfs_rambd_prog,
.erase = lfs_rambd_erase,
.sync = lfs_rambd_sync,
// block device configuration
.read_size = 1,
.prog_size = 8,
.block_size = BLOCK_SIZE,
.block_count = NUM_OF_BLOCKS,
.cache_size = 512,
.lookahead_size = 16,
.block_cycles = 500,
};
struct lfs_rambd_config bdCfg={
// Minimum size of a read operation in bytes.
.read_size=1,
// Minimum size of a program operation in bytes.
.prog_size=8,
// Size of an erase operation in bytes.
.erase_size=BLOCK_SIZE,
// Number of erase blocks on the device.
.erase_count=NUM_OF_BLOCKS,
// Optional statically allocated buffer for the block device.
.buffer=NULL
};
// entry point
int main(void) {
int rc;
printf("going to create\n");
rc = lfs_rambd_create(&cfg, &bdCfg);
assert(rc == 0);
printf("created\n");
// mount the filesystem
int err = lfs_mount(&lfs, &cfg);
printf("mounted\n");
// reformat if we can't mount the filesystem
// this should only happen on the first boot
if (err) {
lfs_format(&lfs, &cfg);
lfs_mount(&lfs, &cfg);
}
for(int i = 1; i < 1000; i++)
{
int ret;
printf("loop %d\n", i);
char file_name[30];
uint8_t data_buffer[511];
sprintf(file_name, "%d.txt", i);
// read current count
ret = lfs_file_open(&lfs, &file, file_name, LFS_O_RDWR | LFS_O_CREAT);
if(ret != 0)
{
printf("ERROR: open file %d failed with return code %d\n", i, ret);
break;
}
ret = lfs_file_write(&lfs, &file, data_buffer, sizeof(data_buffer));
if (ret != 511)
{
printf("ERROR: write file %d failed with return code %d\n", i, ret);
}
// remember the storage is not updated until the file is closed successfully
ret = lfs_file_close(&lfs, &file);
if(ret < 0)
{
printf("ERROR: close file %d failed with return code %d\n", i, ret);
}
}
// release any resources we were using
lfs_unmount(&lfs);
}
The output I got (changed just the path in my computer):
going to create
created
<my path>/lfs.c:1382:error: Corrupted dir pair at {0x0, 0x1}
mounted
loop 1
loop 2
loop 3
loop 4
loop 5
loop 6
loop 7
loop 8
loop 9
loop 10
loop 11
loop 12
loop 13
loop 14
loop 15
loop 16
loop 17
loop 18
loop 19
loop 20
loop 21
loop 22
loop 23
loop 24
loop 25
loop 26
loop 27
loop 28
loop 29
loop 30
loop 31
loop 32
loop 33
loop 34
loop 35
loop 36
loop 37
loop 38
loop 39
loop 40
loop 41
loop 42
loop 43
loop 44
loop 45
loop 46
loop 47
<my path>/lfs.c:702:error: No more free space 0x12
<my path>/lfs.c:2189:warn: Unable to split {0xe, 0xf}
loop 48
loop 49
loop 50
loop 51
loop 52
loop 53
<my path>/lfs.c:702:error: No more free space 0x12
<my path>/lfs.c:2189:warn: Unable to split {0x14, 0x15}
ERROR: close file 53 failed with return code -28
loop 54
MyProject: <my path>/lfs.c:263: lfs_bd_prog: Assertion `pcache->block == ((lfs_block_t)-1)' failed.
Aborted