move ialloc body up, avoiding double check for end of loop
This commit is contained in:
parent
32eea7665a
commit
95c07f8267
1 changed files with 7 additions and 11 deletions
12
fs.c
12
fs.c
|
@ -201,14 +201,6 @@ 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
|
||||||
|
@ -216,6 +208,10 @@ ialloc(uint dev, short type)
|
||||||
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.
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in a new issue