#include <string.h>\r
#include <stdlib.h>\r
\r
-\r
int ext4_bcache_init_dynamic(struct ext4_bcache *bc, uint32_t cnt,\r
- uint32_t itemsize)\r
+ uint32_t itemsize)\r
{\r
ext4_assert(bc && cnt && itemsize);\r
\r
memset(bc, 0, sizeof(struct ext4_bcache));\r
\r
bc->data = malloc(cnt * itemsize);\r
- if(!bc->data)\r
+ if (!bc->data)\r
goto error;\r
\r
bc->cnt = cnt;\r
\r
return EOK;\r
\r
- error:\r
+error:\r
\r
- if(bc->data)\r
+ if (bc->data)\r
free(bc->data);\r
\r
memset(bc, 0, sizeof(struct ext4_bcache));\r
\r
int ext4_bcache_fini_dynamic(struct ext4_bcache *bc)\r
{\r
- if(bc->data)\r
+ if (bc->data)\r
free(bc->data);\r
\r
memset(bc, 0, sizeof(struct ext4_bcache));\r
return EOK;\r
}\r
\r
-\r
int ext4_bcache_alloc(struct ext4_bcache *bc, struct ext4_block *b,\r
- bool *is_new)\r
+ bool *is_new)\r
{\r
uint32_t i;\r
ext4_assert(bc && b && is_new);\r
\r
/*Check if valid.*/\r
ext4_assert(b->lb_id);\r
- if(!b->lb_id){\r
+ if (!b->lb_id) {\r
ext4_assert(b->lb_id);\r
}\r
\r
for (i = 0; i < bc->cnt; ++i) {\r
\r
/*Check if block is already in cache*/\r
- if(b->lb_id == bc->lba[i]){\r
+ if (b->lb_id == bc->lba[i]) {\r
\r
- if(!bc->refctr[i] && !bc->free_delay[i])\r
+ if (!bc->refctr[i] && !bc->free_delay[i])\r
bc->ref_blocks++;\r
\r
/*Update reference counter*/\r
}\r
\r
/*Best fit calculations.*/\r
- if(bc->refctr[i])\r
+ if (bc->refctr[i])\r
continue;\r
\r
- if(bc->free_delay[i])\r
+ if (bc->free_delay[i])\r
continue;\r
\r
/*Block is unreferenced, but it may exist block with\r
* lower usage marker*/\r
\r
/*First find.*/\r
- if(cache_id == bc->cnt){\r
+ if (cache_id == bc->cnt) {\r
cache_id = i;\r
alloc_id = bc->lru_id[i];\r
continue;\r
}\r
\r
/*Next find*/\r
- if(alloc_id <= bc->lru_id[i])\r
+ if (alloc_id <= bc->lru_id[i])\r
continue;\r
\r
/*This block has lower alloc id marker*/\r
alloc_id = bc->lru_id[i];\r
}\r
\r
-\r
- if(cache_id != bc->cnt){\r
+ if (cache_id != bc->cnt) {\r
/*There was unreferenced block*/\r
bc->lba[cache_id] = b->lb_id;\r
bc->refctr[cache_id] = 1;\r
\r
/*Statistics*/\r
bc->ref_blocks++;\r
- if(bc->ref_blocks > bc->max_ref_blocks)\r
+ if (bc->ref_blocks > bc->max_ref_blocks)\r
bc->max_ref_blocks = bc->ref_blocks;\r
\r
-\r
/*Block needs to be read.*/\r
*is_new = true;\r
\r
}\r
\r
ext4_dprintf(EXT4_DEBUG_BCACHE,\r
- "ext4_bcache_alloc: FAIL, unable to alloc block cache!\n");\r
+ "ext4_bcache_alloc: FAIL, unable to alloc block cache!\n");\r
return ENOMEM;\r
}\r
\r
-int ext4_bcache_free (struct ext4_bcache *bc, struct ext4_block *b,\r
- uint8_t free_delay)\r
+int ext4_bcache_free(struct ext4_bcache *bc, struct ext4_block *b,\r
+ uint8_t free_delay)\r
{\r
ext4_assert(bc && b);\r
\r
ext4_assert(bc->refctr[b->cache_id]);\r
\r
/*Just decrease reference counter*/\r
- if(bc->refctr[b->cache_id])\r
+ if (bc->refctr[b->cache_id])\r
bc->refctr[b->cache_id]--;\r
\r
- if(free_delay)\r
+ if (free_delay)\r
bc->free_delay[b->cache_id] = free_delay;\r
\r
/*Update statistics*/\r
- if(!bc->refctr[b->cache_id] && !bc->free_delay[b->cache_id])\r
+ if (!bc->refctr[b->cache_id] && !bc->free_delay[b->cache_id])\r
bc->ref_blocks--;\r
\r
b->lb_id = 0;\r
return EOK;\r
}\r
\r
-\r
-\r
bool ext4_bcache_is_full(struct ext4_bcache *bc)\r
{\r
return (bc->cnt == bc->ref_blocks);\r
/**\r
* @}\r
*/\r
-\r
-\r
#include <stdbool.h>\r
\r
/**@brief Single block descriptor.*/\r
-struct ext4_block {\r
+struct ext4_block\r
+{\r
/**@brief Dirty flag.*/\r
bool dirty;\r
\r
uint8_t *data;\r
};\r
\r
-\r
/**@brief Block cache descriptor.*/\r
-struct ext4_bcache {\r
+struct ext4_bcache\r
+{\r
\r
/**@brief Item count in block cache*/\r
uint32_t cnt;\r
\r
/**@brief Maximum referenced datablocks*/\r
uint32_t max_ref_blocks;\r
-\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
+#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 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
+ uint32_t itemsize);\r
\r
/**@brief Dynamic de-initialization of block cache.\r
* @param bc block cache descriptor\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
+ 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
+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