ref: 6b299ffc4ffe49f98dbb837f660b93f70bf2ab3c
parent: d24a490d30a7a1565eb5970a8232a091e6e9dd1b
author: gkostka <kostka.grzegorz@gmail.com>
date: Tue Jun 16 06:01:47 EDT 2015
clang-format: ext4_bcache
--- a/lwext4/ext4_bcache.c
+++ b/lwext4/ext4_bcache.c
@@ -42,9 +42,8 @@
#include <string.h>
#include <stdlib.h>
-
int ext4_bcache_init_dynamic(struct ext4_bcache *bc, uint32_t cnt,
- uint32_t itemsize)
+ uint32_t itemsize)
{
ext4_assert(bc && cnt && itemsize);
@@ -51,7 +50,7 @@
memset(bc, 0, sizeof(struct ext4_bcache));
bc->data = malloc(cnt * itemsize);
- if(!bc->data)
+ if (!bc->data)
goto error;
bc->cnt = cnt;
@@ -61,9 +60,9 @@
return EOK;
- error:
+error:
- if(bc->data)
+ if (bc->data)
free(bc->data);
memset(bc, 0, sizeof(struct ext4_bcache));
@@ -73,7 +72,7 @@
int ext4_bcache_fini_dynamic(struct ext4_bcache *bc)
{
- if(bc->data)
+ if (bc->data)
free(bc->data);
memset(bc, 0, sizeof(struct ext4_bcache));
@@ -81,9 +80,8 @@
return EOK;
}
-
int ext4_bcache_alloc(struct ext4_bcache *bc, struct ext4_block *b,
- bool *is_new)
+ bool *is_new)
{
uint32_t i;
ext4_assert(bc && b && is_new);
@@ -90,7 +88,7 @@
/*Check if valid.*/
ext4_assert(b->lb_id);
- if(!b->lb_id){
+ if (!b->lb_id) {
ext4_assert(b->lb_id);
}
@@ -103,9 +101,9 @@
for (i = 0; i < bc->cnt; ++i) {
/*Check if block is already in cache*/
- if(b->lb_id == bc->lba[i]){
+ if (b->lb_id == bc->lba[i]) {
- if(!bc->refctr[i] && !bc->free_delay[i])
+ if (!bc->refctr[i] && !bc->free_delay[i])
bc->ref_blocks++;
/*Update reference counter*/
@@ -122,10 +120,10 @@
}
/*Best fit calculations.*/
- if(bc->refctr[i])
+ if (bc->refctr[i])
continue;
- if(bc->free_delay[i])
+ if (bc->free_delay[i])
continue;
/*Block is unreferenced, but it may exist block with
@@ -132,7 +130,7 @@
* lower usage marker*/
/*First find.*/
- if(cache_id == bc->cnt){
+ if (cache_id == bc->cnt) {
cache_id = i;
alloc_id = bc->lru_id[i];
continue;
@@ -139,7 +137,7 @@
}
/*Next find*/
- if(alloc_id <= bc->lru_id[i])
+ if (alloc_id <= bc->lru_id[i])
continue;
/*This block has lower alloc id marker*/
@@ -147,8 +145,7 @@
alloc_id = bc->lru_id[i];
}
-
- if(cache_id != bc->cnt){
+ if (cache_id != bc->cnt) {
/*There was unreferenced block*/
bc->lba[cache_id] = b->lb_id;
bc->refctr[cache_id] = 1;
@@ -160,10 +157,9 @@
/*Statistics*/
bc->ref_blocks++;
- if(bc->ref_blocks > bc->max_ref_blocks)
+ if (bc->ref_blocks > bc->max_ref_blocks)
bc->max_ref_blocks = bc->ref_blocks;
-
/*Block needs to be read.*/
*is_new = true;
@@ -171,12 +167,12 @@
}
ext4_dprintf(EXT4_DEBUG_BCACHE,
- "ext4_bcache_alloc: FAIL, unable to alloc block cache!\n");
+ "ext4_bcache_alloc: FAIL, unable to alloc block cache!\n");
return ENOMEM;
}
-int ext4_bcache_free (struct ext4_bcache *bc, struct ext4_block *b,
- uint8_t free_delay)
+int ext4_bcache_free(struct ext4_bcache *bc, struct ext4_block *b,
+ uint8_t free_delay)
{
ext4_assert(bc && b);
@@ -190,14 +186,14 @@
ext4_assert(bc->refctr[b->cache_id]);
/*Just decrease reference counter*/
- if(bc->refctr[b->cache_id])
+ if (bc->refctr[b->cache_id])
bc->refctr[b->cache_id]--;
- if(free_delay)
+ if (free_delay)
bc->free_delay[b->cache_id] = free_delay;
/*Update statistics*/
- if(!bc->refctr[b->cache_id] && !bc->free_delay[b->cache_id])
+ if (!bc->refctr[b->cache_id] && !bc->free_delay[b->cache_id])
bc->ref_blocks--;
b->lb_id = 0;
@@ -207,8 +203,6 @@
return EOK;
}
-
-
bool ext4_bcache_is_full(struct ext4_bcache *bc)
{
return (bc->cnt == bc->ref_blocks);
@@ -217,5 +211,3 @@
/**
* @}
*/
-
-
--- a/lwext4/ext4_bcache.h
+++ b/lwext4/ext4_bcache.h
@@ -43,7 +43,8 @@
#include <stdbool.h>
/**@brief Single block descriptor.*/
-struct ext4_block {
+struct ext4_block
+{
/**@brief Dirty flag.*/
bool dirty;
@@ -57,9 +58,9 @@
uint8_t *data;
};
-
/**@brief Block cache descriptor.*/
-struct ext4_bcache {
+struct ext4_bcache
+{
/**@brief Item count in block cache*/
uint32_t cnt;
@@ -93,20 +94,18 @@
/**@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, \
- }
+#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
@@ -113,7 +112,7 @@
* @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);
+ uint32_t itemsize);
/**@brief Dynamic de-initialization of block cache.
* @param bc block cache descriptor
@@ -128,7 +127,7 @@
* @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);
+ bool *is_new);
/**@brief Free block from cache memory (decrement reference counter).
* @param bc block cache descriptor
@@ -135,9 +134,8 @@
* @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);
-
+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