From: batt Date: Thu, 1 Jul 2010 17:10:48 +0000 (+0000) Subject: Read/Write only one block at a time. X-Git-Tag: 2.6.0~326 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=67a447ed1a103117f947fd3ac6c9d2ea72f38c5d;p=bertos.git Read/Write only one block at a time. Since kblock API is meant to be used one block at a time, this committ remove the multiblock support. This will speed up access a bit in the common case. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3981 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/io/kblock.c b/bertos/io/kblock.c index c36fd0db..65f42790 100644 --- a/bertos/io/kblock.c +++ b/bertos/io/kblock.c @@ -84,36 +84,17 @@ INLINE int kblock_store(struct KBlock *b, block_idx_t index) -size_t kblock_read(struct KBlock *b, block_idx_t idx, void *_buf, size_t offset, size_t size) +size_t kblock_read(struct KBlock *b, block_idx_t idx, void *buf, size_t offset, size_t size) { - size_t tot_rd = 0; - uint8_t *buf = (uint8_t *)_buf; - ASSERT(b); ASSERT(buf); + ASSERT(offset + size <= b->blk_size); LOG_INFO("blk_idx %d, offset %d, size %d\n", idx, offset, size); - while (size) - { - size_t len = MIN(size, b->blk_size - offset); - size_t rlen; - - if (idx == b->priv.curr_blk) - rlen = kblock_readBuf(b, buf, offset, len); - else - rlen = kblock_readDirect(b, idx, buf, offset, len); - - tot_rd += rlen; - if (rlen != len) - break; - - idx++; - size -= rlen; - offset = 0; - buf += rlen; - } - - return tot_rd; + if (idx == b->priv.curr_blk) + return kblock_readBuf(b, buf, offset, size); + else + return kblock_readDirect(b, idx, buf, offset, size); } @@ -149,37 +130,19 @@ static bool kblock_loadPage(struct KBlock *b, block_idx_t idx) } -size_t kblock_write(struct KBlock *b, block_idx_t idx, const void *_buf, size_t offset, size_t size) +size_t kblock_write(struct KBlock *b, block_idx_t idx, const void *buf, size_t offset, size_t size) { - size_t tot_wr = 0; - const uint8_t *buf = (const uint8_t *)_buf; - ASSERT(b); ASSERT(buf); + ASSERT(offset + size <= b->blk_size); LOG_INFO("blk_idx %d, offset %d, size %d\n", idx, offset, size); - while (size) - { - size_t len = MIN(size, b->blk_size - offset); - size_t wlen; - - if (!kblock_loadPage(b, idx)) - break; - wlen = kblock_writeBuf(b, buf, offset, len); - b->priv.cache_dirty = true; + if (!kblock_loadPage(b, idx)) + return 0; - tot_wr += wlen; - if (wlen != len) - break; - - idx++; - size -= wlen; - offset = 0; - buf += wlen; - } - - return tot_wr; + b->priv.cache_dirty = true; + return kblock_writeBuf(b, buf, offset, size); } int kblock_copy(struct KBlock *b, block_idx_t idx1, block_idx_t idx2)