Skip to content

Commit

Permalink
[inflate] resolve decompression issue with HAL_PLATFORM_INFLATE_USE_F…
Browse files Browse the repository at this point in the history
…ILESYSTEM
  • Loading branch information
avtolstoy committed Aug 15, 2023
1 parent 1d28036 commit 2858d78
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 8 additions & 0 deletions hal/shared/inflate.cpp
Expand Up @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions hal/shared/inflate_impl.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions services/inc/storage_streams.h
Expand Up @@ -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 {
Expand Down

0 comments on commit 2858d78

Please sign in to comment.