X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fio%2Fkblock.h;h=f2966bafea2fd4def8512452e760a98f6e03e6c1;hb=d49a3c80ba504db32d50f1a45593d58669ee601b;hp=7775d7b87f14f9f28df7c014b89f6f3e15fb2bda;hpb=09befbcd1ee296ad30790e303adec8dc1a104f07;p=bertos.git diff --git a/bertos/io/kblock.h b/bertos/io/kblock.h index 7775d7b8..f2966baf 100644 --- a/bertos/io/kblock.h +++ b/bertos/io/kblock.h @@ -33,6 +33,8 @@ * \author Francesco Sacchi * * \brief KBlock interface + * + * $WIZ$ module_name = "kblock" */ #ifndef IO_KBLOCK_H @@ -66,11 +68,11 @@ 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 void (* kblock_clearerr_t) (struct KBlock *b); typedef int (* kblock_close_t) (struct KBlock *b); /* \} */ -/** +/* * Table of interface functions for a KBlock device. */ typedef struct KBlockVTable @@ -83,31 +85,32 @@ typedef struct KBlockVTable kblock_load_t load; kblock_store_t store; - kblock_error_t error; ///< \sa kblock_error() - kblock_clearerr_t clearerr; ///< \sa kblock_clearerr() + kblock_error_t error; // \sa kblock_error() + kblock_clearerr_t clearerr; // \sa kblock_clearerr() - kblock_close_t close; ///< \sa kblock_close() + kblock_close_t close; // \sa kblock_close() } KBlockVTable; -#define KB_BUFFERED BV(0) ///< Internal flag: true if the KBlock has a buffer -#define KB_CACHE_DIRTY BV(1) ///< Internal flag: true if the cache is dirty -#define KB_PARTIAL_WRITE BV(2) ///< Internal flag: true if the device allows partial block write +#define KB_BUFFERED BV(0) ///< Internal flag: true if the KBlock has a buffer +#define KB_CACHE_DIRTY BV(1) ///< Internal flag: true if the cache is dirty +#define KB_PARTIAL_WRITE BV(2) ///< Internal flag: true if the device allows partial block write -/** + +/* * KBlock private members. * These are the private members of the KBlock interface, please do not * access these directly, use the KBlock API. */ 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; ///< Pointer to the page buffer for RAM-cached KBlocks. - block_idx_t blk_start; ///< Start block number when the device is trimmed. \sa kblock_trim(). - block_idx_t curr_blk; ///< Current cached block number in cached KBlocks. + DB(id_t type); // Used to keep track, at runtime, of the class type. + int flags; // Status and error flags. + void *buf; // Pointer to the page buffer for RAM-cached KBlocks. + block_idx_t blk_start; // Start block number when the device is trimmed. \sa kblock_trim(). + block_idx_t curr_blk; // Current cached block number in cached KBlocks. - const struct KBlockVTable *vt; ///< Virtual table of interface functions. + const struct KBlockVTable *vt; // Virtual table of interface functions. } KBlockPriv; /** @@ -202,16 +205,27 @@ INLINE int kblock_error(struct KBlock *b) * * \param b KBlock device. * - * \return 0 on success, EOF on errors. * * \sa kblock_error() */ -INLINE int kblock_clearerr(struct KBlock *b) +INLINE void kblock_clearerr(struct KBlock *b) { KB_ASSERT_METHOD(b, clearerr); - return b->priv.vt->clearerr(b); + b->priv.vt->clearerr(b); } + +/** + * Flush the cache (if any) to the device. + * + * This function will write any pending modifications to the device. + * If the device does not have a cache, this function will do nothing. + * + * \return 0 if all is OK, EOF on errors. + * \sa kblock_read(), kblock_write(), kblock_buffered(). + */ +int kblock_flush(struct KBlock *b); + /** * Close the device. * @@ -222,7 +236,7 @@ INLINE int kblock_clearerr(struct KBlock *b) INLINE int kblock_close(struct KBlock *b) { KB_ASSERT_METHOD(b, close); - return b->priv.vt->close(b); + return kblock_flush(b) | b->priv.vt->close(b); } /** @@ -331,19 +345,6 @@ size_t kblock_read(struct KBlock *b, block_idx_t idx, void *buf, size_t offset, */ size_t kblock_write(struct KBlock *b, block_idx_t idx, const void *buf, size_t offset, size_t size); - -/** - * Flush the cache (if any) to the device. - * - * This function will write any pending modifications to the device. - * If the device does not have a cache, this function will do nothing. - * - * \return 0 if all is OK, EOF on errors. - * \sa kblock_read(), kblock_write(), kblock_buffered(). - */ -int kblock_flush(struct KBlock *b); - - /** * Copy one block to another. * @@ -364,5 +365,6 @@ 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); +int kblock_swClose(struct KBlock *b); #endif /* IO_KBLOCK_H */