diff options
Diffstat (limited to 'blockdev/filedev/ext4_filedev.c')
| -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) { |
