From: asterix Date: Thu, 12 Aug 2010 10:37:24 +0000 (+0000) Subject: Fix sw load and store. Fix log print. Add comments. X-Git-Tag: 2.6.0~217 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=04800615c9d06d85adc7c7b1487ad4e3007c6e67;p=bertos.git Fix sw load and store. Fix log print. Add comments. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4173 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/io/kblock.c b/bertos/io/kblock.c index 69b5b159..616e7bcd 100644 --- a/bertos/io/kblock.c +++ b/bertos/io/kblock.c @@ -26,7 +26,7 @@ * invalidate any other reasons why the executable file might be covered by * the GNU General Public License. * - * Copyright 2009 Develer S.r.l. (http://www.develer.com/) + * Copyright 2010 Develer S.r.l. (http://www.develer.com/) * * --> * @@ -38,8 +38,8 @@ #include "kblock.h" -#define LOG_LEVEL LOG_LVL_ERR -#define LOG_FORMAT LOG_FMT_VERBOSE +#define LOG_LEVEL LOG_LVL_ERR +#define LOG_FORMAT LOG_FMT_VERBOSE #include #include @@ -78,7 +78,7 @@ INLINE int kblock_load(struct KBlock *b, block_idx_t index) KB_ASSERT_METHOD(b, load); ASSERT(index < b->blk_cnt); - LOG_INFO("index %d\n", index); + LOG_INFO("index %ld\n", index); return b->priv.vt->load(b, b->priv.blk_start + index); } @@ -87,7 +87,7 @@ INLINE int kblock_store(struct KBlock *b, block_idx_t index) KB_ASSERT_METHOD(b, store); ASSERT(index < b->blk_cnt); - LOG_INFO("index %d\n", index); + LOG_INFO("index %ld\n", index); return b->priv.vt->store(b, b->priv.blk_start + index); } @@ -106,7 +106,7 @@ size_t kblock_read(struct KBlock *b, block_idx_t idx, void *buf, size_t offset, ASSERT(b); ASSERT(buf); ASSERT(offset + size <= b->blk_size); - LOG_INFO("blk_idx %d, offset %d, size %d\n", idx, offset, size); + LOG_INFO("blk_idx %ld, offset %u, size %u\n", idx, offset, size); if (kblock_buffered(b) && idx == b->priv.curr_blk) return kblock_readBuf(b, buf, offset, size); @@ -124,7 +124,7 @@ int kblock_flush(struct KBlock *b) if (kblock_cacheDirty(b)) { - LOG_INFO("flushing block %d\n", b->priv.curr_blk); + LOG_INFO("flushing block %ld\n", b->priv.curr_blk); if (kblock_store(b, b->priv.curr_blk) == 0) kblock_setDirty(b, false); else @@ -140,7 +140,7 @@ static bool kblock_loadPage(struct KBlock *b, block_idx_t idx) if (idx != b->priv.curr_blk) { - LOG_INFO("loading block %d\n", idx); + LOG_INFO("loading block %ld\n", idx); if (kblock_flush(b) != 0 || kblock_load(b, idx) != 0) return false; @@ -157,7 +157,7 @@ size_t kblock_write(struct KBlock *b, block_idx_t idx, const void *buf, size_t o ASSERT(idx < b->blk_cnt); ASSERT(offset + size <= b->blk_size); - LOG_INFO("blk_idx %d, offset %d, size %d\n", idx, offset, size); + LOG_INFO("blk_idx %ld, offset %u, size %u\n", idx, offset, size); if (kblock_buffered(b)) { @@ -220,12 +220,26 @@ int kblock_copy(struct KBlock *b, block_idx_t src, block_idx_t dest) int kblock_swLoad(struct KBlock *b, block_idx_t index) { - return (kblock_readDirect(b, index, b->priv.buf, 0, b->blk_size) == b->blk_size) ? 0 : EOF; + /* + * Since this is a low level API, the index here is a fisical index. + * If we call another low level API, logical to fisical translation + * would be applied twice. + * In order to avoid this we subtract the start block index. + */ + ASSERT(index >= b->priv.blk_start); + return (kblock_readDirect(b, index - b->priv.blk_start, b->priv.buf, 0, b->blk_size) == b->blk_size) ? 0 : EOF; } int kblock_swStore(struct KBlock *b, block_idx_t index) { - return (kblock_writeDirect(b, index, b->priv.buf, 0, b->blk_size) == b->blk_size) ? 0 : EOF; + /* + * Since this is a low level API, the index here is a fisical index. + * If we call another low level API, logical to fisical translation + * would be applied twice. + * In order to avoid this we subtract the start block index. + */ + ASSERT(index >= b->priv.blk_start); + return (kblock_writeDirect(b, index - b->priv.blk_start, b->priv.buf, 0, b->blk_size) == b->blk_size) ? 0 : EOF; } size_t kblock_swReadBuf(struct KBlock *b, void *buf, size_t offset, size_t size)