shithub: lwext4

Download patch

ref: 2c61a24dfa6b65ae4292915c7ede68f01005bfa5
parent: 0f1cc07213540e99bdfe5c4ee6c49b6e583ffbb7
author: gkostka <kostka.grzegorz@gmail.com>
date: Sun Oct 27 10:50:30 EDT 2013

Disable buffering for filedev and raw_io.

--- a/blockdev/filedev/ext4_filedev.c
+++ b/blockdev/filedev/ext4_filedev.c
@@ -31,6 +31,7 @@
 #include <stdio.h>
 #include <stdbool.h>
 #include <string.h>
+#include <fcntl.h>
 
 /**@brief	Default filename.*/
 static const char *fname = "ext2";
@@ -41,7 +42,9 @@
 /**@brief	Image file descriptor.*/
 static FILE	*dev_file;
 
+#define DROP_LINUXCACHE_BUFFERS 0
 
+
 /**********************BLOCKDEV INTERFACE**************************************/
 static int filedev_open(struct ext4_blockdev *bdev);
 static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
@@ -98,18 +101,32 @@
 	return EOK;
 }
 
+static void drop_cache(void)
+{
+#if defined(LINUX) && DROP_LINUXCACHE_BUFFERS
+    int fd;
+    char* data = "3";
+
+    sync();
+    fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
+    write(fd, data, sizeof(char));
+    close(fd);
+#endif
+}
+
 /******************************************************************************/
 static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf,
-		uint64_t blk_id, uint32_t blk_cnt)
+    uint64_t blk_id, uint32_t blk_cnt)
 {
-	if(fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
-		return EIO;
+    if(fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
+        return EIO;
 
-	if(!fwrite(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
-		return EIO;
-	return EOK;
-}
+    if(!fwrite(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
+        return EIO;
 
+    drop_cache();
+    return EOK;
+}
 /******************************************************************************/
 static int filedev_close(struct  ext4_blockdev *bdev)
 {
--- a/blockdev/io_raw/io_raw.c
+++ b/blockdev/io_raw/io_raw.c
@@ -89,7 +89,7 @@
             FILE_SHARE_WRITE | FILE_SHARE_READ,
             NULL,
             OPEN_EXISTING,
-            0,
+            FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH,
             NULL);
 
     if (dev_file == INVALID_HANDLE_VALUE){