Browse Source

file not visible in SPIFFS_readdir #90

Iterator bug - if an iteration was callbacked at last page in block -1,
the resumed iteration would skip the last page in block.
Fixing this revealed another bug, where free page marker was not advanced
but pointing to the same page found before when searching for new free page.
This is probably not a problem, as when searching for free pages the found
free page always becomes occupied. A new free page scan will simply skip
the previously found free page, which has been allocated by now. However,
it is suboptimal. Also, it might have messed with the wear leveling a bit.
pull/94/head
Peter Andersson 9 years ago
parent
commit
c6e94fdca5
  1. 3
      src/spiffs_hydrogen.c
  2. 4
      src/spiffs_nucleus.c
  3. 37
      src/test/test_bugreports.c

3
src/spiffs_hydrogen.c

@ -913,7 +913,7 @@ static s32_t spiffs_read_dir_v(
if (res != SPIFFS_OK) return res;
if ((obj_id & SPIFFS_OBJ_ID_IX_FLAG) &&
objix_hdr.p_hdr.span_ix == 0 &&
(objix_hdr.p_hdr.flags& (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_IXDELE)) ==
(objix_hdr.p_hdr.flags & (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_IXDELE)) ==
(SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_IXDELE)) {
struct spiffs_dirent *e = (struct spiffs_dirent*)user_var_p;
e->obj_id = obj_id;
@ -923,7 +923,6 @@ static s32_t spiffs_read_dir_v(
e->pix = pix;
return SPIFFS_OK;
}
return SPIFFS_VIS_COUNTINUE;
}

4
src/spiffs_nucleus.c

@ -142,7 +142,7 @@ s32_t spiffs_obj_lu_find_entry_visitor(
int entries_per_page = (SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(spiffs_obj_id));
// wrap initial
if (cur_entry >= (int)SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs) - 1) {
if (cur_entry > (int)SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs) - 1) {
cur_entry = 0;
cur_block++;
cur_block_addr = cur_block * SPIFFS_CFG_LOG_BLOCK_SZ(fs);
@ -467,7 +467,7 @@ s32_t spiffs_obj_lu_find_free(
SPIFFS_OBJ_ID_FREE, block_ix, lu_entry);
if (res == SPIFFS_OK) {
fs->free_cursor_block_ix = *block_ix;
fs->free_cursor_obj_lu_entry = *lu_entry;
fs->free_cursor_obj_lu_entry = (*lu_entry) + 1;
if (*lu_entry == 0) {
fs->free_blocks--;
}

37
src/test/test_bugreports.c

@ -540,6 +540,40 @@ TEST(spiffs_dup_file_74) {
return TEST_RES_OK;
} TEST_END
#if 0
TEST(spiffs_hidden_file_90) {
fs_mount_dump("imgs/90.hidden_file.spiffs", 0, 0, 1*1024*1024, 4096, 4096, 128);
SPIFFS_vis(FS);
dump_page(FS, 1);
dump_page(FS, 0x8fe);
dump_page(FS, 0x8ff);
{
spiffs_DIR dir;
SPIFFS_opendir(FS, "/", &dir);
struct spiffs_dirent dirent;
while (SPIFFS_readdir(&dir, &dirent)) {
printf("%-32s sz:%-7i obj_id:%08x pix:%08x\n", dirent.name, dirent.size, dirent.obj_id, dirent.pix);
}
}
printf("remove cli.bin res %i\n", SPIFFS_remove(FS, "cli.bin"));
{
spiffs_DIR dir;
SPIFFS_opendir(FS, "/", &dir);
struct spiffs_dirent dirent;
while (SPIFFS_readdir(&dir, &dirent)) {
printf("%-32s sz:%-7i obj_id:%08x pix:%08x\n", dirent.name, dirent.size, dirent.obj_id, dirent.pix);
}
}
return TEST_RES_OK;
} TEST_END
#endif
SUITE_TESTS(bug_tests)
ADD_TEST(nodemcu_full_fs_1)
ADD_TEST(nodemcu_full_fs_2)
@ -551,4 +585,7 @@ SUITE_TESTS(bug_tests)
ADD_TEST(truncate_48)
ADD_TEST(eof_tell_72)
ADD_TEST(spiffs_dup_file_74)
#if 0
ADD_TEST(spiffs_hidden_file_90)
#endif
SUITE_END(bug_tests)

Loading…
Cancel
Save