-/**
- * 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;
-}
-
-
-/**
- * Release the memory map on the page buffer.
- *
- * This function has to be called when memory mapped access has finished.
- * This is needed because only one mapping is allowed at a time.
- * The \a offset and \a size passed should be the same passed to
- * kblock_map() when the page buffer has been mapped.
- *
- * \note Trying to unmap the page buffer when there is no mapping ongoing is
- * an error.
- *
- * \param b KBlock device.
- * \param offset Address offset within the page buffer, from which data has been
- * memory mapped. Must be the same value passed to kblock_map()
- * when the memory was mapped.
- * \param size Size of the memory mapped. Must be the same value passed to
- * kblock_map() when the memory was mapped.
- *
- * \return 0 on success, EOF on errors.
- *
- * \sa kblock_addMapping(), kblock_map()
- */
-INLINE int kblock_unmap(struct KBlock *b, size_t offset, size_t size)
-{
- ASSERT(b->vt);
- ASSERT(b->vt->unmap);
-
- if (!(b->priv.flags & BV(KBS_MAPPED)))
- {
- b->priv.flags |= BV(KBS_ERR_NOT_MAPPED);
- return EOF;
- }
-
- ASSERT(b->priv.map_off == offset);
- ASSERT(b->priv.map_size == size);
- int ret = b->vt->unmap(b, offset, size);
-
- if (ret == 0)
- b->priv.flags &= ~BV(KBS_MAPPED);
- return ret;
-}