-/**
- * Transfer data from the internal page buffer to user memory.
- *
- * This function accesses the internal page buffer of the block device and copy
- * the data to \a buf. The content is copied from the current cached block.
- *
- * \param b KBlock device.
- * \param buf User buffer to copy the data to.
- * \param offset Address offset within the block, from which to copy data.
- * \param size Size, in bytes, of the data to be copied.
- *
- * \return The number of bytes copied. Can be less than \a size on errors.
- *
- * \sa kblock_writeBuf()
- */
-INLINE size_t kblock_readBuf(struct KBlock *b, void *buf, size_t offset, size_t size)
-{
- ASSERT(b->vt);
- ASSERT(b->vt->readBuf);
- ASSERT(offset + size <= b->blk_size);
-
- return b->vt->readBuf(b, buf, offset, size);
-}
-
-/**
- * Write to the page buffer.
- *
- * Copies data from user memory to the device page buffer. The data is written
- * in the current cached block buffer.
- *
- * \param b KBlock device.
- * \param buf User buffer to copy the data from.
- * \param offset Address offset within the block, from which data has to be written.
- * \param size Size, in bytes, of the data to be written.
- *
- * \return The number of bytes written. Can be less than \a size on errors.
- *
- * \sa kblock_readBuf()
- */
-INLINE size_t kblock_writeBuf(struct KBlock *b, const void *buf, size_t offset, size_t size)
-{
- ASSERT(b->vt);
- ASSERT(b->vt->writeBuf);
- ASSERT(offset + size <= b->blk_size);
- return b->vt->writeBuf(b, buf, offset, size);
-}
-
-/**
- * Load a block from the device to the page buffer.
- *
- * The block \a index will be loaded in the internal page buffer.
- *
- * \param b KBlock device.
- * \param index Logical index of the block to be loaded.
- *
- * \return 0 on success, EOF on errors.
- */
-INLINE int kblock_load(struct KBlock *b, block_idx_t index)
-{
- ASSERT(b->vt);
- ASSERT(b->vt->load);
- ASSERT(index < b->blk_cnt);
-
- return b->vt->load(b, b->priv.blk_start + index);
-}
-
-/**
- * Store a block from the page buffer to the device.
- *
- * The current content of the page buffer will be flushed to the block \a index.
- *
- * \param b KBlock device.
- * \param index Logical index of the block to be stored.
- *
- * \return 0 on success, EOF on errors.
- */
-INLINE int kblock_store(struct KBlock *b, block_idx_t index)
-{
- ASSERT(b->vt);
- ASSERT(b->vt->store);
- ASSERT(index < b->blk_cnt);
-
- return b->vt->store(b, b->priv.blk_start + index);
-}
-
-
-/**
- * Memory map the current page buffer.
- *
- * To speed up access, instead of using kblock_readBuf() and kblock_writeBuf(),
- * you can memory map the page buffer and access it directly through the
- * returned pointer. You can freely access the pointer in any way you
- * like. Once done, call kblock_unmap() to release the lock on the page_buffer.
- *
- * \note This function may be not available on all drivers, since the page
- * buffer can be in the hardware and not directly accessible through memory.
- * For this devices you can still add generic software mapping features
- * thanks to kblock_addMapping().
- *
- * \note Only one mapping is available at a time, trying to map the page buffer
- * again before releasing it is an error.
- *
- * \param b KBlock device.
- * \param offset Address offset within the page buffer, from which data has to
- * be memory mapped.
- * \param size Size of the memory to be mapped.
- *
- * \return A pointer to the mapped region of the page buffer or NULL on errors.
- *
- * \sa kblock_addMapping(), kblock_unmap()
- */
-INLINE void * kblock_map(struct KBlock *b, size_t offset, size_t size)
-{
- ASSERT(b->vt);
- ASSERT(b->vt->map);
-
- if (b->priv.flags & BV(KBS_MAPPED))
- {
- b->priv.flags |= BV(KBS_ERR_ALREADY_MAPPED);
- return NULL;
- }
-
- ASSERT(size < b->priv.pagebuf_size);
- ASSERT(offset + size <= b->blk_size);
- DB(b->priv.map_off = offset);
- DB(b->priv.map_size = size);
-
- void *ret = b->vt->map(b, offset, size);
-
- if (ret)
- b->priv.flags |= BV(KBS_MAPPED);
-
- return ret;
-}