diff options
| author | gkostka <kostka.grzegorz@gmail.com> | 2013-10-27 14:50:30 +0000 |
|---|---|---|
| committer | gkostka <kostka.grzegorz@gmail.com> | 2013-10-27 14:50:30 +0000 |
| commit | 2c61a24dfa6b65ae4292915c7ede68f01005bfa5 (patch) | |
| tree | 86cd981b5185d248fbaa30b8f2f0a87b1fa7db8e /blockdev/filedev | |
| parent | 0f1cc07213540e99bdfe5c4ee6c49b6e583ffbb7 (diff) | |
Disable buffering for filedev and raw_io.
Diffstat (limited to 'blockdev/filedev')
| -rw-r--r-- | blockdev/filedev/ext4_filedev.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/blockdev/filedev/ext4_filedev.c b/blockdev/filedev/ext4_filedev.c index dc8db50..b2173ba 100644 --- 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,6 +42,8 @@ static const char *fname = "ext2"; /**@brief Image file descriptor.*/ static FILE *dev_file; +#define DROP_LINUXCACHE_BUFFERS 0 + /**********************BLOCKDEV INTERFACE**************************************/ static int filedev_open(struct ext4_blockdev *bdev); @@ -98,18 +101,32 @@ static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id 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) { |
