Remove readBlock method in order to simplify low level API.
[bertos.git] / bertos / io / kblock.h
index 4dffe18b198ed96d9c5bd3e7d747cdba10c7682b..c0d23e03687b69ea95848fbb3b2fc762f91bc715 100644 (file)
@@ -57,10 +57,13 @@ struct KBlock;
  *  \{
  */
 typedef size_t (* kblock_read_direct_t) (struct KBlock *b, block_idx_t index, void *buf, size_t offset, size_t size);
+typedef int    (* kblock_write_block_t) (struct KBlock *b, block_idx_t index, const void *buf);
+
 typedef size_t (* kblock_read_t)        (struct KBlock *b, void *buf, size_t offset, size_t size);
 typedef size_t (* kblock_write_t)       (struct KBlock *b, const void *buf, size_t offset, size_t size);
 typedef int    (* kblock_load_t)        (struct KBlock *b, block_idx_t index);
 typedef int    (* kblock_store_t)       (struct KBlock *b, block_idx_t index);
+
 typedef int    (* kblock_error_t)       (struct KBlock *b);
 typedef int    (* kblock_clearerr_t)    (struct KBlock *b);
 typedef int    (* kblock_close_t)       (struct KBlock *b);
@@ -72,11 +75,13 @@ typedef int    (* kblock_close_t)       (struct KBlock *b);
 typedef struct KBlockVTable
 {
        kblock_read_direct_t readDirect;
-    kblock_read_t  readBuf;
+       kblock_write_block_t writeBlock;
+       
+       kblock_read_t  readBuf;
        kblock_write_t writeBuf;
        kblock_load_t  load;
        kblock_store_t store;
-
+               
        kblock_error_t    error;    ///< \sa kblock_error()
        kblock_clearerr_t clearerr; ///< \sa kblock_clearerr()
 
@@ -84,6 +89,9 @@ typedef struct KBlockVTable
 } KBlockVTable;
 
 
+#define KB_BUFFERED    BV(0)
+#define KB_CACHE_DIRTY BV(1)
+
 /**
  * KBlock private members.
  * These are the private members of the KBlock class, please do not
@@ -93,11 +101,11 @@ typedef struct KBlockPriv
 {
        DB(id_t type);         ///< Used to keep track, at runtime, of the class type.
        int flags;             ///< Status and error flags.
+       void *buf;
        block_idx_t blk_start; ///< Start block number when the device is trimmed. \sa kblock_trim()
        block_idx_t curr_blk;
-       bool cache_dirty;
 
-       struct KBlockVTable *vt; ///< Virtual table of interface functions.
+       const struct KBlockVTable *vt; ///< Virtual table of interface functions.
 } KBlockPriv;
 
 /**
@@ -117,7 +125,7 @@ typedef struct KBlock
 {
        KBlockPriv priv;         ///< Interface private data, do not use directly.
 
-       /* Public access members/methods */
+       /* Public access members */
        size_t blk_size;         ///< Block size.
        block_idx_t blk_cnt;     ///< Number of blocks available in the device.
 } KBlock;
@@ -215,12 +223,34 @@ INLINE int kblock_close(struct KBlock *b)
        return b->priv.vt->close(b);
 }
 
-size_t kblock_read(struct KBlock *b, block_idx_t idx, void *buf, size_t offset, size_t size);
+INLINE bool kblock_cacheDirty(struct KBlock *b)
+{
+       ASSERT(b);
+       return (b->priv.flags & KB_CACHE_DIRTY);
+}
 
-int kblock_flush(struct KBlock *b);
+INLINE block_idx_t kblock_cachedBlock(struct KBlock *b)
+{
+       return b->priv.curr_blk;
+}
+
+INLINE bool kblock_buffered(struct KBlock *b)
+{
+       ASSERT(b);
+       return (b->priv.flags & KB_BUFFERED);
+}
+
+size_t kblock_read(struct KBlock *b, block_idx_t idx, 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);
 
+int kblock_flush(struct KBlock *b);
+
 int kblock_copy(struct KBlock *b, block_idx_t idx1, block_idx_t idx2);
 
+int kblock_swLoad(struct KBlock *b, block_idx_t index);
+int kblock_swStore(struct KBlock *b, block_idx_t index);
+size_t kblock_swReadBuf(struct KBlock *b, void *buf, size_t offset, size_t size);
+size_t kblock_swWriteBuf(struct KBlock *b, const void *buf, size_t offset, size_t size);
+
 #endif /* IO_KBLOCK_H */