提交 95c07f82 创建 作者: rsc's avatar rsc

move ialloc body up, avoiding double check for end of loop

上级 32eea766
...@@ -201,20 +201,16 @@ ialloc(uint dev, short type) ...@@ -201,20 +201,16 @@ ialloc(uint dev, short type)
bp = bread(dev, IBLOCK(inum)); bp = bread(dev, IBLOCK(inum));
dip = &((struct dinode*)(bp->data))[inum % IPB]; dip = &((struct dinode*)(bp->data))[inum % IPB];
if(dip->type == 0) { // a free inode if(dip->type == 0) { // a free inode
break;
}
brelse(bp);
}
if(inum >= ninodes)
panic("ialloc: no inodes left");
memset(dip, 0, sizeof(*dip)); memset(dip, 0, sizeof(*dip));
dip->type = type; dip->type = type;
bwrite(bp, IBLOCK(inum)); // mark it allocated on the disk bwrite(bp, IBLOCK(inum)); // mark it allocated on the disk
brelse(bp); brelse(bp);
ip = iget(dev, inum); ip = iget(dev, inum);
return ip; return ip;
}
brelse(bp);
}
panic("ialloc: no inodes");
} }
// Free the given inode from its file system. // Free the given inode from its file system.
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论