Showing the changes to blockdev (2 of 28 files). Show all
Unified · Split
| @@ -33,14 +33,14 @@ · 32 unmodified lines | |||
| 33 | #include <string.h> | 33 | #include <string.h> |
| 34 | #include <fcntl.h> | 34 | #include <fcntl.h> |
| 35 | 35 | ||
| 36 | /**@brief Default filename.*/ | 36 | /**@brief Default filename.*/ |
| 37 | static const char *fname = "ext2"; | 37 | static const char *fname = "ext2"; |
| 38 | 38 | ||
| 39 | /**@brief Image block size.*/ | 39 | /**@brief Image block size.*/ |
| 40 | #define EXT4_FILEDEV_BSIZE 512 | 40 | #define EXT4_FILEDEV_BSIZE 512 |
| 41 | 41 | ||
| 42 | /**@brief Image file descriptor.*/ | 42 | /**@brief Image file descriptor.*/ |
| 43 | static FILE *dev_file; | 43 | static FILE *dev_file; |
| 44 | 44 | ||
| 45 | #define DROP_LINUXCACHE_BUFFERS 1 | 45 | #define DROP_LINUXCACHE_BUFFERS 1 |
| 46 | 46 | ||
| @@ -48,21 +48,21 @@ static FILE *dev_file; · 1 unmodified line | |||
| 48 | /**********************BLOCKDEV INTERFACE**************************************/ | 48 | /**********************BLOCKDEV INTERFACE**************************************/ |
| 49 | static int filedev_open(struct ext4_blockdev *bdev); | 49 | static int filedev_open(struct ext4_blockdev *bdev); |
| 50 | static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id, | 50 | static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id, |
| 51 | uint32_t blk_cnt); | 51 | uint32_t blk_cnt); |
| 52 | static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf, | 52 | static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf, |
| 53 | uint64_t blk_id, uint32_t blk_cnt); | 53 | uint64_t blk_id, uint32_t blk_cnt); |
| 54 | static int filedev_close(struct ext4_blockdev *bdev); | 54 | static int filedev_close(struct ext4_blockdev *bdev); |
| 55 | 55 | ||
| 56 | 56 | ||
| 57 | /******************************************************************************/ | 57 | /******************************************************************************/ |
| 58 | EXT4_BLOCKDEV_STATIC_INSTANCE( | 58 | EXT4_BLOCKDEV_STATIC_INSTANCE( |
| 59 | _filedev, | 59 | _filedev, |
| 60 | EXT4_FILEDEV_BSIZE, | 60 | EXT4_FILEDEV_BSIZE, |
| 61 | 0, | 61 | 0, |
| 62 | filedev_open, | 62 | filedev_open, |
| 63 | filedev_bread, | 63 | filedev_bread, |
| 64 | filedev_bwrite, | 64 | filedev_bwrite, |
| 65 | filedev_close | 65 | filedev_close |
| 66 | ); | 66 | ); |
| 67 | 67 | ||
| 68 | /******************************************************************************/ | 68 | /******************************************************************************/ |
| @@ -71,34 +71,34 @@ EXT4_BCACHE_STATIC_INSTANCE(__cache, CONFIG_BLOCK_DEV_CACHE_SIZE, 1024); · 2 unmodified lines | |||
| 71 | /******************************************************************************/ | 71 | /******************************************************************************/ |
| 72 | static int filedev_open(struct ext4_blockdev *bdev) | 72 | static int filedev_open(struct ext4_blockdev *bdev) |
| 73 | { | 73 | { |
| 74 | dev_file = fopen(fname, "r+b"); | 74 | dev_file = fopen(fname, "r+b"); |
| 75 | 75 | ||
| 76 | if(!dev_file) | 76 | if(!dev_file) |
| 77 | return EIO; | 77 | return EIO; |
| 78 | 78 | ||
| 79 | /*No buffering at file.*/ | 79 | /*No buffering at file.*/ |
| 80 | setbuf(dev_file, 0); | 80 | setbuf(dev_file, 0); |
| 81 | 81 | ||
| 82 | if(fseek(dev_file, 0, SEEK_END)) | 82 | if(fseek(dev_file, 0, SEEK_END)) |
| 83 | return EFAULT; | 83 | return EFAULT; |
| 84 | 84 | ||
| 85 | _filedev.ph_bcnt = ftell(dev_file) / _filedev.ph_bsize; | 85 | _filedev.ph_bcnt = ftell(dev_file) / _filedev.ph_bsize; |
| 86 | 86 | ||
| 87 | return EOK; | 87 | return EOK; |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | /******************************************************************************/ | 90 | /******************************************************************************/ |
| 91 | 91 | ||
| 92 | static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id, | 92 | static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id, |
| 93 | uint32_t blk_cnt) | 93 | uint32_t blk_cnt) |
| 94 | { | 94 | { |
| 95 | if(fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET)) | 95 | if(fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET)) |
| 96 | return EIO; | 96 | return EIO; |
| 97 | 97 | ||
| 98 | if(!fread(buf, bdev->ph_bsize * blk_cnt, 1, dev_file)) | 98 | if(!fread(buf, bdev->ph_bsize * blk_cnt, 1, dev_file)) |
| 99 | return EIO; | 99 | return EIO; |
| 100 | 100 | ||
| 101 | return EOK; | 101 | return EOK; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | static void drop_cache(void) | 104 | static void drop_cache(void) |
| @@ -130,26 +130,26 @@ static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf, · 25 unmodified lines | |||
| 130 | /******************************************************************************/ | 130 | /******************************************************************************/ |
| 131 | static int filedev_close(struct ext4_blockdev *bdev) | 131 | static int filedev_close(struct ext4_blockdev *bdev) |
| 132 | { | 132 | { |
| 133 | fclose(dev_file); | 133 | fclose(dev_file); |
| 134 | return EOK; | 134 | return EOK; |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | 137 | ||
| 138 | /******************************************************************************/ | 138 | /******************************************************************************/ |
| 139 | 139 | ||
| 140 | struct ext4_bcache* ext4_filecache_get(void) | 140 | struct ext4_bcache* ext4_filecache_get(void) |
| 141 | { | 141 | { |
| 142 | return &__cache; | 142 | return &__cache; |
| 143 | } | 143 | } |
| 144 | /******************************************************************************/ | 144 | /******************************************************************************/ |
| 145 | struct ext4_blockdev* ext4_filedev_get(void) | 145 | struct ext4_blockdev* ext4_filedev_get(void) |
| 146 | { | 146 | { |
| 147 | return &_filedev; | 147 | return &_filedev; |
| 148 | } | 148 | } |
| 149 | /******************************************************************************/ | 149 | /******************************************************************************/ |
| 150 | void ext4_filedev_filename(const char *n) | 150 | void ext4_filedev_filename(const char *n) |
| 151 | { | 151 | { |
| 152 | fname = n; | 152 | fname = n; |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | /******************************************************************************/ | 155 | /******************************************************************************/ |
| @@ -34,12 +34,12 @@ · 33 unmodified lines | |||
| 34 | #include <stdint.h> | 34 | #include <stdint.h> |
| 35 | #include <stdbool.h> | 35 | #include <stdbool.h> |
| 36 | 36 | ||
| 37 | /**@brief Filecache get.*/ | 37 | /**@brief Filecache get.*/ |
| 38 | struct ext4_bcache* ext4_filecache_get(void); | 38 | struct ext4_bcache* ext4_filecache_get(void); |
| 39 | 39 | ||
| 40 | /**@brief File blockdev get.*/ | 40 | /**@brief File blockdev get.*/ |
| 41 | struct ext4_blockdev* ext4_filedev_get(void); | 41 | struct ext4_blockdev* ext4_filedev_get(void); |
| 42 | 42 | ||
| 43 | void ext4_filedev_filename(const char *n); | 43 | void ext4_filedev_filename(const char *n); |
| 44 | 44 | ||
| 45 | #endif /* EXT4_FILEDEV_H_ */ | 45 | #endif /* EXT4_FILEDEV_H_ */ |