summaryrefslogtreecommitdiff
path: root/fs.c
diff options
context:
space:
mode:
authorrtm <rtm>2006-07-27 21:10:00 +0000
committerrtm <rtm>2006-07-27 21:10:00 +0000
commitc59361f1430ec485596d1bf5d43339af0b5a2705 (patch)
tree1cb1898c928857c94f2927f74fdb0e2cd3772793 /fs.c
parent54a4b00346575f3e2da1c9aeb023aaba4412a31d (diff)
downloadxv6-labs-c59361f1430ec485596d1bf5d43339af0b5a2705.tar.gz
xv6-labs-c59361f1430ec485596d1bf5d43339af0b5a2705.tar.bz2
xv6-labs-c59361f1430ec485596d1bf5d43339af0b5a2705.zip
primitive exec
Diffstat (limited to 'fs.c')
-rw-r--r--fs.c23
1 files changed, 23 insertions, 0 deletions
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)
{