From: lottaviano Date: Tue, 23 Nov 2010 15:20:32 +0000 (+0000) Subject: Merged from external project: X-Git-Tag: 2.7.0~370 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=db8a50ae8e0629647e21e5d5e3d2353153c93ae3;p=bertos.git Merged from external project: ********** r4565 | batt | 2010-11-23 15:05:35 +0100 (mar, 23 nov 2010) | 2 lines Fix kblock_trim() behaviour wrt cached block. ********** git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4567 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/io/kblock.c b/bertos/io/kblock.c index 0f8ac274..9c21f566 100644 --- a/bertos/io/kblock.c +++ b/bertos/io/kblock.c @@ -100,7 +100,6 @@ INLINE void kblock_setDirty(struct KBlock *b, bool dirty) } - size_t kblock_read(struct KBlock *b, block_idx_t idx, void *buf, size_t offset, size_t size) { ASSERT(b); @@ -150,6 +149,20 @@ static bool kblock_loadPage(struct KBlock *b, block_idx_t idx) } +int kblock_trim(struct KBlock *b, block_idx_t start, block_idx_t count) +{ + ASSERT(start + count <= b->blk_cnt); + + if (!kblock_loadPage(b, start)) + return EOF; + + b->priv.blk_start += start; + b->priv.curr_blk = 0; // adjust logical address + b->blk_cnt = count; + return 0; +} + + size_t kblock_write(struct KBlock *b, block_idx_t idx, const void *buf, size_t offset, size_t size) { ASSERT(b); diff --git a/bertos/io/kblock.h b/bertos/io/kblock.h index 56a0bf78..f3542947 100644 --- a/bertos/io/kblock.h +++ b/bertos/io/kblock.h @@ -195,13 +195,9 @@ typedef struct KBlock * \param start The index of the start block for the limiting window in logical addressing units. * \param count The number of blocks to be used. * + * \return 0 if all is OK, EOF on errors. */ -INLINE void kblock_trim(struct KBlock *b, block_idx_t start, block_idx_t count) -{ - ASSERT(start + count <= b->blk_cnt); - b->priv.blk_start += start; - b->blk_cnt = count; -} +int kblock_trim(struct KBlock *b, block_idx_t start, block_idx_t count); #define KB_ASSERT_METHOD(b, method) \