mirror of
https://github.com/pellepl/spiffs.git
synced 2026-08-30 22:00:02 +00:00
fix double write of same data in certain cache situations
This commit is contained in:
@@ -546,8 +546,7 @@ s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, s32_t len) {
|
||||
fd->cache_page->offset, fd->cache_page->size);
|
||||
spiffs_cache_fd_release(fs, fd->cache_page);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
res = spiffs_hydro_write(fs, fd, buf, offset, len);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
// data written below
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -765,6 +765,40 @@ TEST(remove_single_by_fd)
|
||||
TEST_END
|
||||
|
||||
|
||||
TEST(write_cache)
|
||||
{
|
||||
int res;
|
||||
spiffs_file fd;
|
||||
u8_t buf[1024];
|
||||
u8_t fbuf[1024];
|
||||
res = test_create_file("f");
|
||||
TEST_CHECK(res >= 0);
|
||||
fd = SPIFFS_open(FS, "f", SPIFFS_RDWR, 0);
|
||||
TEST_CHECK(fd >= 0);
|
||||
memrand(buf, sizeof(buf));
|
||||
res = SPIFFS_write(FS, fd, buf, SPIFFS_CFG_LOG_PAGE_SZ(FS)/2);
|
||||
TEST_CHECK(res >= 0);
|
||||
res = SPIFFS_write(FS, fd, buf, SPIFFS_CFG_LOG_PAGE_SZ(FS)*2);
|
||||
TEST_CHECK(res >= 0);
|
||||
res = SPIFFS_close(FS, fd);
|
||||
TEST_CHECK(res >= 0);
|
||||
|
||||
fd = SPIFFS_open(FS, "f", SPIFFS_RDWR, 0);
|
||||
TEST_CHECK(fd >= 0);
|
||||
res = SPIFFS_read(FS, fd, fbuf, SPIFFS_CFG_LOG_PAGE_SZ(FS)/2 + SPIFFS_CFG_LOG_PAGE_SZ(FS)*2);
|
||||
TEST_CHECK(res >= 0);
|
||||
TEST_CHECK(0 == memcmp(&buf[0], &fbuf[0], SPIFFS_CFG_LOG_PAGE_SZ(FS)/2));
|
||||
TEST_CHECK(0 == memcmp(&buf[0], &fbuf[SPIFFS_CFG_LOG_PAGE_SZ(FS)/2], SPIFFS_CFG_LOG_PAGE_SZ(FS)*2));
|
||||
res = SPIFFS_close(FS, fd);
|
||||
TEST_CHECK(res >= 0);
|
||||
|
||||
TEST_CHECK(SPIFFS_errno(FS) == SPIFFS_OK);
|
||||
|
||||
return TEST_RES_OK;
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
||||
TEST(write_big_file_chunks_page)
|
||||
{
|
||||
int size = ((50*(FS)->cfg.phys_size)/100);
|
||||
@@ -1891,6 +1925,7 @@ SUITE_TESTS(hydrogen_tests)
|
||||
ADD_TEST(rename)
|
||||
ADD_TEST(remove_single_by_path)
|
||||
ADD_TEST(remove_single_by_fd)
|
||||
ADD_TEST(write_cache)
|
||||
ADD_TEST(write_big_file_chunks_page)
|
||||
ADD_TEST(write_big_files_chunks_page)
|
||||
ADD_TEST(write_big_file_chunks_index)
|
||||
|
||||
Reference in New Issue
Block a user