mirror of
https://github.com/pellepl/spiffs.git
synced 2025-05-17 15:26:18 +08:00
Unable to recover from filesystem full #82
This commit is contained in:
@ -1503,8 +1503,10 @@ s32_t spiffs_object_truncate(
|
||||
}
|
||||
|
||||
// need 2 pages if not removing: object index page + possibly chopped data page
|
||||
res = spiffs_gc_check(fs, remove ? 0 : SPIFFS_DATA_PAGE_SIZE(fs) * 2);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
if (remove == 0) {
|
||||
res = spiffs_gc_check(fs, SPIFFS_DATA_PAGE_SIZE(fs) * 2);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
}
|
||||
|
||||
spiffs_page_ix objix_pix = fd->objix_hdr_pix;
|
||||
spiffs_span_ix data_spix = (fd->size > 0 ? fd->size-1 : 0) / SPIFFS_DATA_PAGE_SIZE(fs);
|
||||
@ -1543,11 +1545,18 @@ s32_t spiffs_object_truncate(
|
||||
SPIFFS_CHECK_RES(res);
|
||||
spiffs_cb_object_event(fs, fd, SPIFFS_EV_IX_DEL, fd->obj_id, objix->p_hdr.span_ix, objix_pix, 0);
|
||||
if (prev_objix_spix > 0) {
|
||||
// update object index header page
|
||||
SPIFFS_DBG("truncate: update objix hdr page %04x:%04x to size %i\n", fd->objix_hdr_pix, prev_objix_spix, cur_size);
|
||||
res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
|
||||
fd->objix_hdr_pix, 0, 0, cur_size, &new_objix_hdr_pix);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
// Update object index header page, unless we totally want to remove the file.
|
||||
// If fully removing, we're not keeping consistency as good as when storing the header between chunks,
|
||||
// would we be aborted. But when removing full files, a crammed system may otherwise
|
||||
// report ERR_FULL a la windows. We cannot have that.
|
||||
// Hence, take the risk - if aborted, a file check would free the lost pages and mend things
|
||||
// as the file is marked as fully deleted in the beginning.
|
||||
if (remove == 0) {
|
||||
SPIFFS_DBG("truncate: update objix hdr page %04x:%04x to size %i\n", fd->objix_hdr_pix, prev_objix_spix, cur_size);
|
||||
res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
|
||||
fd->objix_hdr_pix, 0, 0, cur_size, &new_objix_hdr_pix);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
}
|
||||
fd->size = cur_size;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user