diff options
author | Robert Morris <[email protected]> | 2011-08-19 13:30:57 -0400 |
---|---|---|
committer | Robert Morris <[email protected]> | 2011-08-19 13:30:57 -0400 |
commit | 327cc21fba38359c5b7fd4c9f39b1dc00fb4f182 (patch) | |
tree | bf9bfb4240d32dd4725b774e39ac7d270e2ab905 /fs.c | |
parent | cd3d739e6f3d4d356ac8c34b25f16df82a5f2789 (diff) | |
download | xv6-labs-327cc21fba38359c5b7fd4c9f39b1dc00fb4f182.tar.gz xv6-labs-327cc21fba38359c5b7fd4c9f39b1dc00fb4f182.tar.bz2 xv6-labs-327cc21fba38359c5b7fd4c9f39b1dc00fb4f182.zip |
make dirlookup and dirlink more similar
Diffstat (limited to 'fs.c')
-rw-r--r-- | fs.c | 31 |
1 files changed, 13 insertions, 18 deletions
@@ -469,30 +469,25 @@ struct inode* dirlookup(struct inode *dp, char *name, uint *poff) { uint off, inum; - struct buf *bp; - struct dirent *de; + struct dirent de; if(dp->type != T_DIR) panic("dirlookup not DIR"); - for(off = 0; off < dp->size; off += BSIZE){ - bp = bread(dp->dev, bmap(dp, off / BSIZE)); - for(de = (struct dirent*)bp->data; - de < (struct dirent*)(bp->data + BSIZE); - de++){ - if(de->inum == 0) - continue; - if(namecmp(name, de->name) == 0){ - // entry matches path element - if(poff) - *poff = off + (uchar*)de - bp->data; - inum = de->inum; - brelse(bp); - return iget(dp->dev, inum); - } + for(off = 0; off < dp->size; off += sizeof(de)){ + if(readi(dp, (char*)&de, off, sizeof(de)) != sizeof(de)) + panic("dirlink read"); + if(de.inum == 0) + continue; + if(namecmp(name, de.name) == 0){ + // entry matches path element + if(poff) + *poff = off; + inum = de.inum; + return iget(dp->dev, inum); } - brelse(bp); } + return 0; } |