From c59361f1430ec485596d1bf5d43339af0b5a2705 Mon Sep 17 00:00:00 2001 From: rtm Date: Thu, 27 Jul 2006 21:10:00 +0000 Subject: primitive exec --- fs.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'fs.c') diff --git a/fs.c b/fs.c index 3eda6e9..3b06bc7 100644 --- a/fs.c +++ b/fs.c @@ -133,6 +133,29 @@ bmap(struct inode *ip, uint bn) return x; } +#define min(a, b) ((a) < (b) ? (a) : (b)) + +int +readi(struct inode *ip, void *xdst, uint off, uint n) +{ + char *dst = (char *) xdst; + uint target = n, n1; + struct buf *bp; + + while(n > 0 && off < ip->size){ + bp = bread(ip->dev, bmap(ip, off / 512)); + n1 = min(n, ip->size - off); + n1 = min(n1, 512 - (off % 512)); + memmove(dst, bp->data + (off % 512), n1); + n -= n1; + off += n1; + dst += n1; + brelse(bp); + } + + return target - n; +} + struct inode * namei(char *path) { -- cgit v1.2.3