Mercurial > hg > Members > innparusu > xv6-rpi
diff src/fs.c @ 24:36bd61f5c847
rewrite sys_read cbc
author | mir3636 |
---|---|
date | Thu, 17 Jan 2019 19:11:19 +0900 |
parents | 83c23a36980d |
children | 1a64b5645cdd |
line wrap: on
line diff
--- a/src/fs.c Mon Dec 17 16:55:22 2018 +0900 +++ b/src/fs.c Thu Jan 17 19:11:19 2019 +0900 @@ -453,6 +453,37 @@ st->size = ip->size; } +__code cbc_readi (struct inode *ip, char *dst, uint off, uint n, __code (*next)(int ret)) +{ + uint tot, m; + struct buf *bp; + + if (ip->type == T_DEV) { + if (ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].read) { + goto next(-1); + } + + goto cbc_devsw[ip->major].read(ip, dst, n); + } + + if (off > ip->size || off + n < off) { + goto next(-1); + } + + if (off + n > ip->size) { + n = ip->size - off; + } + + for (tot = 0; tot < n; tot += m, off += m, dst += m) { + bp = bread(ip->dev, bmap(ip, off / BSIZE)); + m = min(n - tot, BSIZE - off%BSIZE); + memmove(dst, bp->data + off % BSIZE, m); + brelse(bp); + } + + goto next(n); +} + //PAGEBREAK! // Read data from inode. int readi (struct inode *ip, char *dst, uint off, uint n)