diff --git a/src/spiffs_gc.c b/src/spiffs_gc.c index c8fb01a..db1af4c 100644 --- a/src/spiffs_gc.c +++ b/src/spiffs_gc.c @@ -294,7 +294,7 @@ s32_t spiffs_gc_find_candidate( // calculate score and insert into candidate table // stoneage sort, but probably not so many blocks - if (res == SPIFFS_OK && deleted_pages_in_block > 0) { + if (res == SPIFFS_OK /*&& deleted_pages_in_block > 0*/) { // read erase count spiffs_obj_id erase_count; res = _spiffs_rd(fs, SPIFFS_OP_C_READ | SPIFFS_OP_T_OBJ_LU2, 0, diff --git a/src/test/test_bugreports.c b/src/test/test_bugreports.c index 2665b1d..a46ad97 100644 --- a/src/test/test_bugreports.c +++ b/src/test/test_bugreports.c @@ -1116,6 +1116,51 @@ TEST(null_deref_check_93) { } TEST_END #endif +TEST(spiffs_145) { + int res; + fs_reset_specific(0, 0, 1024*1024, 65536, 65536, 1024); + { + spiffs_file fd = SPIFFS_open(FS, "biggie", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_WRONLY, 0); + TEST_CHECK(fd >= 0); + char buf[1024*512]; + memset(buf, 0xee, sizeof(buf)); + TEST_CHECK_GT(SPIFFS_write(FS, fd, buf, sizeof(buf)), 0); + TEST_CHECK_EQ(SPIFFS_close(FS, fd), SPIFFS_OK); + } + const int runs = 1000; + int run = 0; + while (run++ < runs) { + spiffs_file fd = SPIFFS_open(FS, "clobber", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_WRONLY, 0); + TEST_CHECK(fd >= 0); + char buf[8192]; + memset(buf, 0xee, sizeof(buf)); + TEST_CHECK_GT(SPIFFS_write(FS, fd, buf, sizeof(buf)), 0); + TEST_CHECK_EQ(SPIFFS_close(FS, fd), SPIFFS_OK); + TEST_CHECK_EQ(SPIFFS_remove(FS, "clobber"), SPIFFS_OK); + } + + // below stolen from SPIFFS_vis + spiffs *fs = FS; + int entries_per_page = (SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(spiffs_obj_id)); + spiffs_obj_id *obj_lu_buf = (spiffs_obj_id *)fs->lu_work; + spiffs_block_ix bix = 0; + + while (bix < fs->block_count) { + // check each object lookup page + spiffs_obj_id erase_count; + TEST_CHECK_EQ(_spiffs_rd(fs, SPIFFS_OP_C_READ | SPIFFS_OP_T_OBJ_LU2, 0, + SPIFFS_ERASE_COUNT_PADDR(fs, bix), + sizeof(spiffs_obj_id), (u8_t *)&erase_count), SPIFFS_OK); + TEST_CHECK_NEQ(erase_count, (spiffs_obj_id)-1); + TEST_CHECK_NEQ(erase_count, 0); + bix++; + } // per block + + return TEST_RES_OK; +} TEST_END + + + SUITE_TESTS(bug_tests) ADD_TEST(nodemcu_full_fs_1) ADD_TEST(nodemcu_full_fs_2) @@ -1128,6 +1173,7 @@ SUITE_TESTS(bug_tests) ADD_TEST(eof_tell_72) ADD_TEST(spiffs_dup_file_74) ADD_TEST(temporal_fd_cache) + ADD_TEST(spiffs_145) //ADD_TEST(small_free_space) ADD_TEST(lots_of_overwrite) ADD_TEST_NON_DEFAULT(fuzzer_found_1) diff --git a/src/test/test_spiffs.c b/src/test/test_spiffs.c index 8989a9e..7f7c51b 100644 --- a/src/test/test_spiffs.c +++ b/src/test/test_spiffs.c @@ -354,22 +354,25 @@ void area_read(u32_t addr, u8_t *buf, u32_t size) { void dump_erase_counts(spiffs *fs) { spiffs_block_ix bix; + spiffs_block_ix bix_offs; printf(" BLOCK |\n"); printf(" AGE COUNT|\n"); - for (bix = 0; bix < fs->block_count; bix++) { - printf("----%3i ----|", bix); - } - printf("\n"); - for (bix = 0; bix < fs->block_count; bix++) { - spiffs_obj_id erase_mark; - _spiffs_rd(fs, 0, 0, SPIFFS_ERASE_COUNT_PADDR(fs, bix), sizeof(spiffs_obj_id), (u8_t *)&erase_mark); - if (_erases[bix] == 0) { - printf(" |"); - } else { - printf("%7i %4i|", (fs->max_erase_count - erase_mark), _erases[bix]); + for (bix_offs = 0; bix_offs < fs->block_count; bix_offs+=8) { + for (bix = bix_offs; bix < bix_offs+8 && bix < fs->block_count; bix++) { + printf("----%3i ----|", bix); } + printf("\n"); + for (bix = bix_offs; bix < bix_offs+8 && bix < fs->block_count; bix++) { + spiffs_obj_id erase_mark; + _spiffs_rd(fs, 0, 0, SPIFFS_ERASE_COUNT_PADDR(fs, bix), sizeof(spiffs_obj_id), (u8_t *)&erase_mark); + if (_erases[bix] == 0) { + printf(" |"); + } else { + printf("%7i %4i|", (fs->max_erase_count - erase_mark), _erases[bix]); + } + } + printf("\n"); } - printf("\n"); } void dump_flash_access_stats() {