From 2858d78fc89c27c3e3a2eb47ac901f7e91b17809 Mon Sep 17 00:00:00 2001 From: Andrey Tolstoy Date: Tue, 15 Aug 2023 20:38:54 +0700 Subject: [PATCH] [inflate] resolve decompression issue with HAL_PLATFORM_INFLATE_USE_FILESYSTEM --- hal/shared/inflate.cpp | 8 ++++++++ hal/shared/inflate_impl.cpp | 7 ------- services/inc/storage_streams.h | 7 +++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/hal/shared/inflate.cpp b/hal/shared/inflate.cpp index 40f329ed40..44df94f362 100644 --- a/hal/shared/inflate.cpp +++ b/hal/shared/inflate.cpp @@ -121,7 +121,15 @@ int inflate_reset(inflate_ctx* ctx) { int inflate_input(inflate_ctx* ctx, const char* data, size_t* size, unsigned flags) { if (ctx->result <= 0) { // INFLATE_DONE or an error +#if HAL_PLATFORM_INFLATE_USE_FILESYSTEM + if (ctx->result == INFLATE_DONE && ctx->buf == nullptr && ctx->buf_avail > 0) { + // We still need to call into ctx->decomp.read_buf a few times + } else { + return SYSTEM_ERROR_INVALID_STATE; + } +#else return SYSTEM_ERROR_INVALID_STATE; +#endif // HAL_PLATFORM_INFLATE_USE_FILESYSTEM } size_t srcOffs = 0; bool needMore = false; diff --git a/hal/shared/inflate_impl.cpp b/hal/shared/inflate_impl.cpp index a634c779cd..93d707e030 100644 --- a/hal/shared/inflate_impl.cpp +++ b/hal/shared/inflate_impl.cpp @@ -190,7 +190,6 @@ int inflate_reset_impl(inflate_ctx* ctx) { if (buf) { if (toRead > 0) { - LOG(INFO, "read cache miss toRead=%u offset=%x read_cache_pos=%x write_cache_pos=%x", toRead, offset, ctx->read_cache_pos, ctx->write_cache_pos); const fs::FsLock lock(fs); // Read into target buffer if (lfs_file_seek(&fs->instance, f, offset, LFS_SEEK_SET) < 0) { @@ -228,7 +227,6 @@ int inflate_reset_impl(inflate_ctx* ctx) { return ctx->read_request_size; } if (toRead > 0) { - LOG(INFO, "read cache miss toRead=%u offset=%x read_cache_pos=%x write_cache_pos=%x", toRead, offset, ctx->read_cache_pos, ctx->write_cache_pos); const fs::FsLock lock(fs); // Fill read cache if (lfs_file_seek(&fs->instance, f, offset, LFS_SEEK_SET) < 0) { @@ -292,16 +290,11 @@ int inflate_reset_impl(inflate_ctx* ctx) { } size_t prevBlock = ctx->write_cache_pos; if (toWrite > 0) { - system_tick_t start = HAL_Timer_Get_Milli_Seconds(); - SCOPE_GUARD({ - LOG(INFO, "block change took %ums", HAL_Timer_Get_Milli_Seconds() - start); - }); // Flush the current block const fs::FsLock lock(fs); // NOTE: triggers a flush! size_t newBlock = (toWriteAbsOffset / ctx->write_cache_block_size) * ctx->write_cache_block_size; - LOG(INFO, "block change old=%x new=%x toWrite=%x", prevBlock, newBlock, toWrite); size_t flushSize = ctx->write_cache_block_size; if (newBlock != prevBlock + ctx->write_cache_block_size) { flushSize = ctx->write_cache_size; diff --git a/services/inc/storage_streams.h b/services/inc/storage_streams.h index 27a4fc30bc..5b896d5d9d 100644 --- a/services/inc/storage_streams.h +++ b/services/inc/storage_streams.h @@ -326,8 +326,11 @@ class InflatorStream: public InputStream { char tmp[256]; - while (CHECK(compressedStream_->waitEvent(InputStream::READABLE)) == InputStream::READABLE) { - size_t compressedChunk = CHECK(compressedStream_->peek(tmp, sizeof(tmp))); + while (true) { + size_t compressedChunk = 0; + if (compressedStream_->waitEvent(InputStream::READABLE) == InputStream::READABLE) { + compressedChunk = CHECK(compressedStream_->peek(tmp, sizeof(tmp))); + } size_t compressedPos = 0; int r = 0; do {