shithub: lwext4

Download patch

ref: e299c8d66002d6b9c8d77b3c6c3247e0915fd8c6
parent: 85a64ca0685fe854e830c0b25565e5ca015d2dd3
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Tue Dec 15 18:31:29 EST 2015

ext4_blockdev: add ext4_block_cache_flush routine.

--- a/lwext4/ext4_blockdev.c
+++ b/lwext4/ext4_blockdev.c
@@ -140,7 +140,7 @@
 {
 	int r;
 	struct ext4_bcache *bc = bdev->bc;
-	/*Only flushing unreferenced buffer is allowed.*/
+	/*Only flushing data in an unreferenced buffer is allowed.*/
 	ext4_assert(!buf->refctr);
 
 	if (ext4_bcache_test_flag(buf, BC_DIRTY)) {
@@ -409,11 +409,22 @@
 	return r;
 }
 
-int ext4_block_cache_write_back(struct ext4_blockdev *bdev, uint8_t on_off)
+int ext4_block_cache_flush(struct ext4_blockdev *bdev)
 {
-	int r;
-	struct ext4_buf *buf;
+	while (!SLIST_EMPTY(&bdev->bc->dirty_list)) {
+		int r;
+		struct ext4_buf *buf = SLIST_FIRST(&bdev->bc->dirty_list);
+		ext4_assert(buf);
+		r = ext4_block_flush_buf(bdev, buf);
+		if (r != EOK)
+			return r;
 
+	}
+	return EOK;
+}
+
+int ext4_block_cache_write_back(struct ext4_blockdev *bdev, uint8_t on_off)
+{
 	if (on_off)
 		bdev->cache_write_back++;
 
@@ -423,17 +434,8 @@
 	if (bdev->cache_write_back)
 		return EOK;
 
-	/*Flush all delayed cache blocks*/
-	while (!SLIST_EMPTY(&bdev->bc->dirty_list)) {
-
-		buf = SLIST_FIRST(&bdev->bc->dirty_list);
-		ext4_assert(buf);
-		r = ext4_block_flush_buf(bdev, buf);
-		if (r != EOK)
-			return r;
-
-	}
-	return EOK;
+	/*Flush data in all delayed cache blocks*/
+	return ext4_block_cache_flush(bdev);
 }
 
 /**
--- a/lwext4/ext4_blockdev.h
+++ b/lwext4/ext4_blockdev.h
@@ -231,6 +231,11 @@
 int ext4_block_readbytes(struct ext4_blockdev *bdev, uint64_t off, void *buf,
 			 uint32_t len);
 
+/**@brief   Flush all dirty buffers to disk
+ * @param   bdev block device descriptor
+ * @return  standard error code*/
+int ext4_block_cache_flush(struct ext4_blockdev *bdev);
+
 /**@brief   Enable/disable write back cache mode
  * @param   bdev block device descriptor
  * @param   on_off