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

This commit is contained in:
rsc 2007-08-08 09:53:46 +00:00
parent 32eea7665a
commit 95c07f8267

18
fs.c
View file

@ -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; memset(dip, 0, sizeof(*dip));
dip->type = type;
bwrite(bp, IBLOCK(inum)); // mark it allocated on the disk
brelse(bp);
ip = iget(dev, inum);
return ip;
} }
brelse(bp); brelse(bp);
} }
panic("ialloc: no inodes");
if(inum >= ninodes)
panic("ialloc: no inodes left");
memset(dip, 0, sizeof(*dip));
dip->type = type;
bwrite(bp, IBLOCK(inum)); // mark it allocated on the disk
brelse(bp);
ip = iget(dev, inum);
return ip;
} }
// Free the given inode from its file system. // Free the given inode from its file system.