ref: e21fe5fe454fce1b3a555fc1268e2f77a5d35274
parent: cb473bbcead90b2541817f81f7a030d6e8215185
author: ngkaho1234 <[email protected]>
date: Fri Dec 25 18:27:21 EST 2015
ext4: file data read/write now do direct io in case of unaligned io.
--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -1294,7 +1294,6 @@
uint8_t *u8_buf = buf;
int r;
- struct ext4_block b;
struct ext4_inode_ref ref;
ext4_assert(f && f->mp);
@@ -1361,15 +1360,11 @@
/* Do we get an unwritten range? */
if (fblock != 0) {
- r = ext4_block_get(f->mp->fs.bdev, &b, fblock);
+ uint64_t off = fblock * block_size + unalg;
+ r = ext4_block_readbytes(f->mp->fs.bdev, off, u8_buf, len);
if (r != EOK)
goto Finish;
- memcpy(u8_buf, b.data + unalg, len);
-
- r = ext4_block_set(f->mp->fs.bdev, &b);
- if (r != EOK)
- goto Finish;
} else {
/* Yes, we do. */
memset(u8_buf, 0, len);
@@ -1422,20 +1417,16 @@
}
if (size) {
+ uint64_t off;
r = ext4_fs_get_inode_dblk_idx(&ref, iblock_idx, &fblock, true);
if (r != EOK)
goto Finish;
- r = ext4_block_get(f->mp->fs.bdev, &b, fblock);
+ off = fblock * block_size;
+ r = ext4_block_readbytes(f->mp->fs.bdev, off, u8_buf, size);
if (r != EOK)
goto Finish;
- memcpy(u8_buf, b.data, size);
-
- r = ext4_block_set(f->mp->fs.bdev, &b);
- if (r != EOK)
- goto Finish;
-
f->fpos += size;
if (rcnt)
@@ -1460,7 +1451,6 @@
ext4_fsblk_t fblk;
ext4_fsblk_t fblock_start;
- struct ext4_block b;
struct ext4_inode_ref ref;
const uint8_t *u8_buf = buf;
int r, rr = EOK;
@@ -1499,6 +1489,7 @@
if (unalg) {
size_t len = size;
+ uint64_t off;
if (size > (block_size - unalg))
len = block_size - unalg;
@@ -1506,17 +1497,11 @@
if (r != EOK)
goto Finish;
- r = ext4_block_get(f->mp->fs.bdev, &b, fblk);
+ off = fblk * block_size + unalg;
+ r = ext4_block_writebytes(f->mp->fs.bdev, off, u8_buf, len);
if (r != EOK)
goto Finish;
- memcpy(b.data + unalg, u8_buf, len);
- ext4_bcache_set_dirty(b.buf);
-
- r = ext4_block_set(f->mp->fs.bdev, &b);
- if (r != EOK)
- goto Finish;
-
u8_buf += len;
size -= len;
f->fpos += len;
@@ -1596,6 +1581,7 @@
goto Finish;
if (size) {
+ uint64_t off;
if (iblk_idx < ifile_blocks) {
r = ext4_fs_init_inode_dblk_idx(&ref, iblk_idx, &fblk);
if (r != EOK)
@@ -1607,17 +1593,11 @@
goto out_fsize;
}
- r = ext4_block_get(f->mp->fs.bdev, &b, fblk);
+ off = fblk * block_size;
+ r = ext4_block_writebytes(f->mp->fs.bdev, off, u8_buf, size);
if (r != EOK)
goto Finish;
- memcpy(b.data, u8_buf, size);
- ext4_bcache_set_dirty(b.buf);
-
- r = ext4_block_set(f->mp->fs.bdev, &b);
- if (r != EOK)
- goto Finish;
-
f->fpos += size;
if (wcnt)
@@ -1847,7 +1827,6 @@
static int ext4_fsymlink_set(ext4_file *f, const void *buf, uint32_t size)
{
- struct ext4_block b;
struct ext4_inode_ref ref;
uint32_t sblock;
ext4_fsblk_t fblock;
@@ -1889,15 +1868,10 @@
if (r != EOK)
goto Finish;
- r = ext4_block_get(f->mp->fs.bdev, &b, fblock);
+ r = ext4_block_writebytes(f->mp->fs.bdev, 0, buf, size);
if (r != EOK)
goto Finish;
- memcpy(b.data, buf, size);
- ext4_bcache_set_dirty(b.buf);
- r = ext4_block_set(f->mp->fs.bdev, &b);
- if (r != EOK)
- goto Finish;
}
/*Stop write back cache mode*/