Linux line-endings
[lwext4.git] / lwext4 / ext4_bcache.h
index 5a3fdbeab69050edc79b99d298969bc69aa071f8..e080664165ac009dee506de56d13fc0f9ef401a6 100644 (file)
-/*\r
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * - Redistributions of source code must retain the above copyright\r
- *   notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- *   notice, this list of conditions and the following disclaimer in the\r
- *   documentation and/or other materials provided with the distribution.\r
- * - The name of the author may not be used to endorse or promote products\r
- *   derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- */\r
-\r
-/** @addtogroup lwext4\r
- * @{\r
- */\r
-/**\r
- * @file  ext4_bcache.h\r
- * @brief Block cache allocator.\r
- */\r
-\r
-#ifndef EXT4_BCACHE_H_\r
-#define EXT4_BCACHE_H_\r
-\r
-#include "ext4_config.h"\r
-\r
-#include <stdint.h>\r
-#include <stdbool.h>\r
-\r
-/**@brief   Single block descriptor*/\r
-struct ext4_block {\r
-       /**@brief   Dirty flag*/\r
-       bool dirty;\r
-\r
-       /**@brief   Logical block ID*/\r
-       uint64_t lb_id;\r
-\r
-       /**@brief   Cache id*/\r
-       uint32_t cache_id;\r
-\r
-       /**@brief   Data buffer.*/\r
-       uint8_t *data;\r
-};\r
-\r
-/**@brief   Block cache descriptor*/\r
-struct ext4_bcache {\r
-\r
-       /**@brief   Item count in block cache*/\r
-       uint32_t cnt;\r
-\r
-       /**@brief   Item size in block cache*/\r
-       uint32_t itemsize;\r
-\r
-       /**@brief   Last recently used counter*/\r
-       uint32_t lru_ctr;\r
-\r
-       /**@brief   Reference count table*/\r
-       uint32_t refctr[CONFIG_BLOCK_DEV_CACHE_SIZE];\r
-\r
-       /**@brief   Last recently used ID table*/\r
-       uint32_t lru_id[CONFIG_BLOCK_DEV_CACHE_SIZE];\r
-\r
-       /**@brief   Writeback free delay mode table*/\r
-       uint8_t free_delay[CONFIG_BLOCK_DEV_CACHE_SIZE];\r
-\r
-       /**@brief   Logical block table*/\r
-       uint64_t lba[CONFIG_BLOCK_DEV_CACHE_SIZE];\r
-\r
-       /**@brief   Dirty mark*/\r
-       bool dirty[CONFIG_BLOCK_DEV_CACHE_SIZE];\r
-\r
-       /**@brief   Cache data buffers*/\r
-       uint8_t *data;\r
-\r
-       /**@brief   Currently referenced datablocks*/\r
-       uint32_t ref_blocks;\r
-\r
-       /**@brief   Maximum referenced datablocks*/\r
-       uint32_t max_ref_blocks;\r
-};\r
-\r
-/**@brief   Static initializer of block cache structure.*/\r
-#define EXT4_BCACHE_STATIC_INSTANCE(__name, __cnt, __itemsize)                 \\r
-       static uint8_t __name##_data[(__cnt) * (__itemsize)];                  \\r
-       static struct ext4_bcache __name = {                                   \\r
-           .cnt = __cnt,                                                      \\r
-           .itemsize = __itemsize,                                            \\r
-           .lru_ctr = 0,                                                      \\r
-           .data = __name##_data,                                             \\r
-       }\r
-\r
-/**@brief   Dynamic initialization of block cache.\r
- * @param   bc block cache descriptor\r
- * @param   cnt items count in block cache\r
- * @param   itemsize single item size (in bytes)\r
- * @return  standard error code*/\r
-int ext4_bcache_init_dynamic(struct ext4_bcache *bc, uint32_t cnt,\r
-                            uint32_t itemsize);\r
-\r
-/**@brief   Dynamic de-initialization of block cache.\r
- * @param   bc block cache descriptor\r
- * @return  standard error code*/\r
-int ext4_bcache_fini_dynamic(struct ext4_bcache *bc);\r
-\r
-/**@brief   Allocate block from block cache memory.\r
- *          Unreferenced block allocation is based on LRU\r
- *          (Last Recently Used) algorithm.\r
- * @param   bc block cache descriptor\r
- * @param   b block to alloc\r
- * @param   is_new block is new (needs to be read)\r
- * @return  standard error code*/\r
-int ext4_bcache_alloc(struct ext4_bcache *bc, struct ext4_block *b,\r
-                     bool *is_new);\r
-\r
-/**@brief   Free block from cache memory (decrement reference counter).\r
- * @param   bc block cache descriptor\r
- * @param   b block to free\r
- * @param   cache writeback mode\r
- * @return  standard error code*/\r
-int ext4_bcache_free(struct ext4_bcache *bc, struct ext4_block *b,\r
-                    uint8_t free_delay);\r
-\r
-/**@brief   Return a full status of block cache.\r
- * @param   bc block cache descriptor\r
- * @return  full status*/\r
-bool ext4_bcache_is_full(struct ext4_bcache *bc);\r
-\r
-#endif /* EXT4_BCACHE_H_ */\r
-\r
-/**\r
- * @}\r
- */\r
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup lwext4
+ * @{
+ */
+/**
+ * @file  ext4_bcache.h
+ * @brief Block cache allocator.
+ */
+
+#ifndef EXT4_BCACHE_H_
+#define EXT4_BCACHE_H_
+
+#include "ext4_config.h"
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/**@brief   Single block descriptor*/
+struct ext4_block {
+       /**@brief   Dirty flag*/
+       bool dirty;
+
+       /**@brief   Logical block ID*/
+       uint64_t lb_id;
+
+       /**@brief   Cache id*/
+       uint32_t cache_id;
+
+       /**@brief   Data buffer.*/
+       uint8_t *data;
+};
+
+/**@brief   Block cache descriptor*/
+struct ext4_bcache {
+
+       /**@brief   Item count in block cache*/
+       uint32_t cnt;
+
+       /**@brief   Item size in block cache*/
+       uint32_t itemsize;
+
+       /**@brief   Last recently used counter*/
+       uint32_t lru_ctr;
+
+       /**@brief   Reference count table*/
+       uint32_t refctr[CONFIG_BLOCK_DEV_CACHE_SIZE];
+
+       /**@brief   Last recently used ID table*/
+       uint32_t lru_id[CONFIG_BLOCK_DEV_CACHE_SIZE];
+
+       /**@brief   Writeback free delay mode table*/
+       uint8_t free_delay[CONFIG_BLOCK_DEV_CACHE_SIZE];
+
+       /**@brief   Logical block table*/
+       uint64_t lba[CONFIG_BLOCK_DEV_CACHE_SIZE];
+
+       /**@brief   Dirty mark*/
+       bool dirty[CONFIG_BLOCK_DEV_CACHE_SIZE];
+
+       /**@brief   Cache data buffers*/
+       uint8_t *data;
+
+       /**@brief   Currently referenced datablocks*/
+       uint32_t ref_blocks;
+
+       /**@brief   Maximum referenced datablocks*/
+       uint32_t max_ref_blocks;
+};
+
+/**@brief   Static initializer of block cache structure.*/
+#define EXT4_BCACHE_STATIC_INSTANCE(__name, __cnt, __itemsize)                 \
+       static uint8_t __name##_data[(__cnt) * (__itemsize)];                  \
+       static struct ext4_bcache __name = {                                   \
+           .cnt = __cnt,                                                      \
+           .itemsize = __itemsize,                                            \
+           .lru_ctr = 0,                                                      \
+           .data = __name##_data,                                             \
+       }
+
+/**@brief   Dynamic initialization of block cache.
+ * @param   bc block cache descriptor
+ * @param   cnt items count in block cache
+ * @param   itemsize single item size (in bytes)
+ * @return  standard error code*/
+int ext4_bcache_init_dynamic(struct ext4_bcache *bc, uint32_t cnt,
+                            uint32_t itemsize);
+
+/**@brief   Dynamic de-initialization of block cache.
+ * @param   bc block cache descriptor
+ * @return  standard error code*/
+int ext4_bcache_fini_dynamic(struct ext4_bcache *bc);
+
+/**@brief   Allocate block from block cache memory.
+ *          Unreferenced block allocation is based on LRU
+ *          (Last Recently Used) algorithm.
+ * @param   bc block cache descriptor
+ * @param   b block to alloc
+ * @param   is_new block is new (needs to be read)
+ * @return  standard error code*/
+int ext4_bcache_alloc(struct ext4_bcache *bc, struct ext4_block *b,
+                     bool *is_new);
+
+/**@brief   Free block from cache memory (decrement reference counter).
+ * @param   bc block cache descriptor
+ * @param   b block to free
+ * @param   cache writeback mode
+ * @return  standard error code*/
+int ext4_bcache_free(struct ext4_bcache *bc, struct ext4_block *b,
+                    uint8_t free_delay);
+
+/**@brief   Return a full status of block cache.
+ * @param   bc block cache descriptor
+ * @return  full status*/
+bool ext4_bcache_is_full(struct ext4_bcache *bc);
+
+#endif /* EXT4_BCACHE_H_ */
+
+/**
+ * @}
+ */