From: Lawrence S. <ljs...@us...> - 2013-02-27 15:27:49
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 21deaf55920776d590cc8fd404355a45fcd711d6 (commit) from 8708f6205731cbbe1fd06848eeec1cdd5f15a4cf (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 21deaf55920776d590cc8fd404355a45fcd711d6 Author: Lawrence Sebald <ljs...@us...> Date: Wed Feb 27 10:25:29 2013 -0500 Fix a two rather stupid bugs with fs_ext2. 1. If the file pointer was offset within a block, reading wouldn't work properly. 2. If you tried to read more than one filesystem block's worth of data, the read would continuously write to the beginning of the buffer instead of moving within it as it should have. Basically, fs_ext2 was pretty much completely broken for files of more than 1024 bytes (since newlib seems to like splitting fread calls into read calls of 1024 bytes each). ----------------------------------------------------------------------- Summary of changes: addons/libkosext2fs/fs_ext2.c | 26 +++++++++++++++++++++++++- 1 files changed, 25 insertions(+), 1 deletions(-) diff --git a/addons/libkosext2fs/fs_ext2.c b/addons/libkosext2fs/fs_ext2.c index af138e2..fcb3f74 100644 --- a/addons/libkosext2fs/fs_ext2.c +++ b/addons/libkosext2fs/fs_ext2.c @@ -138,7 +138,7 @@ static void fs_ext2_close(void * h) { static ssize_t fs_ext2_read(void *h, void *buf, size_t cnt) { file_t fd = ((file_t)h) - 1; ext2_fs_t *fs; - uint32_t bs, lbs; + uint32_t bs, lbs, bo; uint8_t *block; uint8_t *bbuf = (uint8_t *)buf; ssize_t rv; @@ -160,6 +160,29 @@ static ssize_t fs_ext2_read(void *h, void *buf, size_t cnt) { bs = ext2_block_size(fs); lbs = ext2_log_block_size(fs); rv = (ssize_t)cnt; + bo = fh[fd].ptr & ((1 << lbs) - 1); + + /* Handle the first block specially if we are offset within it. */ + if(bo) { + if(!(block = ext2_inode_read_block(fs, fh[fd].inode, + fh[fd].ptr >> lbs))) { + mutex_unlock(&ext2_mutex); + errno = EBADF; + return -1; + } + + if(cnt > bs - bo) { + memcpy(bbuf, block + bo, bs - bo); + fh[fd].ptr += bs - bo; + cnt -= bs - bo; + bbuf += bs - bo; + } + else { + memcpy(bbuf, block + bo, cnt); + fh[fd].ptr += cnt; + cnt = 0; + } + } /* While we still have more to read, do it. */ while(cnt) { @@ -174,6 +197,7 @@ static ssize_t fs_ext2_read(void *h, void *buf, size_t cnt) { memcpy(bbuf, block, bs); fh[fd].ptr += bs; cnt -= bs; + bbuf += bs; } else { memcpy(bbuf, block, cnt); hooks/post-receive -- A pseudo Operating System for the Dreamcast. |