ref: fa3bffb20e71983f71aaf17f6a287546c01b924d
parent: 3fd80de784471aedfb32c3fef2690827576032b6
author: ngkaho1234 <[email protected]>
date: Sun Dec 20 05:51:14 EST 2015
ext4_bcache: add ext4_bcache_cleanup routine.
--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -403,6 +403,7 @@
/*Bind block cache to block device*/
r = ext4_block_bind_bcache(bd, bc);
if (r != EOK) {
+ ext4_bcache_cleanup(bc);
ext4_block_fini(bd);
if (mp->cache_dynamic) {
ext4_bcache_fini_dynamic(bc);
@@ -437,6 +438,7 @@
mp->mounted = 0;
+ ext4_bcache_cleanup(mp->fs.bdev->bc);
if (mp->cache_dynamic) {
ext4_bcache_fini_dynamic(mp->fs.bdev->bc);
free(mp->fs.bdev->bc);
--- a/lwext4/ext4_bcache.c
+++ b/lwext4/ext4_bcache.c
@@ -81,6 +81,15 @@
return EOK;
}
+void ext4_bcache_cleanup(struct ext4_bcache *bc)
+{
+ struct ext4_buf *buf, *tmp;
+ RB_FOREACH_SAFE(buf, ext4_buf_lba, &bc->lba_root, tmp) {
+ ext4_block_flush_buf(bc->bdev, buf);
+ ext4_bcache_drop_buf(bc, buf);
+ }
+}
+
int ext4_bcache_fini_dynamic(struct ext4_bcache *bc)
{
memset(bc, 0, sizeof(struct ext4_bcache));
--- a/lwext4/ext4_bcache.h
+++ b/lwext4/ext4_bcache.h
@@ -219,6 +219,10 @@
int ext4_bcache_init_dynamic(struct ext4_bcache *bc, uint32_t cnt,
uint32_t itemsize);
+/**@brief Do cleanup works on block cache.
+ * @param bc block cache descriptor.*/
+void ext4_bcache_cleanup(struct ext4_bcache *bc);
+
/**@brief Dynamic de-initialization of block cache.
* @param bc block cache descriptor
* @return standard error code*/