Merged from external project:
[bertos.git] / bertos / io / kblock.c
index 0f8ac27454172c76bac159dac3048ff028bdf394..9c21f56659b6e34a9f92c53bd8e35755395aba32 100644 (file)
@@ -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);