rearrangements and cleanup for text

This commit is contained in:
Russ Cox 2009-07-11 19:26:01 -07:00
parent 2de1c550ca
commit f9a06440ab
4 changed files with 102 additions and 107 deletions

99
fs.c
View file

@ -141,6 +141,53 @@ iinit(void)
initlock(&icache.lock, "icache");
}
static struct inode* iget(uint dev, uint inum);
//PAGEBREAK!
// Allocate a new inode with the given type on device dev.
struct inode*
ialloc(uint dev, short type)
{
int inum;
struct buf *bp;
struct dinode *dip;
struct superblock sb;
readsb(dev, &sb);
for(inum = 1; inum < sb.ninodes; inum++){ // loop over inode blocks
bp = bread(dev, IBLOCK(inum));
dip = (struct dinode*)bp->data + inum%IPB;
if(dip->type == 0){ // a free inode
memset(dip, 0, sizeof(*dip));
dip->type = type;
bwrite(bp); // mark it allocated on the disk
brelse(bp);
return iget(dev, inum);
}
brelse(bp);
}
panic("ialloc: no inodes");
}
// Copy inode, which has changed, from memory to disk.
void
iupdate(struct inode *ip)
{
struct buf *bp;
struct dinode *dip;
bp = bread(ip->dev, IBLOCK(ip->inum));
dip = (struct dinode*)bp->data + ip->inum%IPB;
dip->type = ip->type;
dip->major = ip->major;
dip->minor = ip->minor;
dip->nlink = ip->nlink;
dip->size = ip->size;
memmove(dip->addrs, ip->addrs, sizeof(ip->addrs));
bwrite(bp);
brelse(bp);
}
// Find the inode with number inum on device dev
// and return the in-memory copy.
static struct inode*
@ -262,51 +309,6 @@ iunlockput(struct inode *ip)
iput(ip);
}
//PAGEBREAK!
// Allocate a new inode with the given type on device dev.
struct inode*
ialloc(uint dev, short type)
{
int inum;
struct buf *bp;
struct dinode *dip;
struct superblock sb;
readsb(dev, &sb);
for(inum = 1; inum < sb.ninodes; inum++){ // loop over inode blocks
bp = bread(dev, IBLOCK(inum));
dip = (struct dinode*)bp->data + inum%IPB;
if(dip->type == 0){ // a free inode
memset(dip, 0, sizeof(*dip));
dip->type = type;
bwrite(bp); // mark it allocated on the disk
brelse(bp);
return iget(dev, inum);
}
brelse(bp);
}
panic("ialloc: no inodes");
}
// Copy inode, which has changed, from memory to disk.
void
iupdate(struct inode *ip)
{
struct buf *bp;
struct dinode *dip;
bp = bread(ip->dev, IBLOCK(ip->inum));
dip = (struct dinode*)bp->data + ip->inum%IPB;
dip->type = ip->type;
dip->major = ip->major;
dip->minor = ip->minor;
dip->nlink = ip->nlink;
dip->size = ip->size;
memmove(dip->addrs, ip->addrs, sizeof(ip->addrs));
bwrite(bp);
brelse(bp);
}
//PAGEBREAK!
// Inode contents
//
@ -336,7 +338,6 @@ bmap(struct inode *ip, uint bn)
ip->addrs[NDIRECT] = addr = balloc(ip->dev);
bp = bread(ip->dev, addr);
a = (uint*)bp->data;
if((addr = a[bn]) == 0){
a[bn] = addr = balloc(ip->dev);
bwrite(bp);
@ -571,7 +572,7 @@ skipelem(char *path, char *name)
// If parent != 0, return the inode for the parent and copy the final
// path element into name, which must have room for DIRSIZ bytes.
static struct inode*
namex(char *path, int parent, char *name)
namex(char *path, int nameiparent, char *name)
{
struct inode *ip, *next;
@ -586,7 +587,7 @@ namex(char *path, int parent, char *name)
iunlockput(ip);
return 0;
}
if(parent && *path == '\0'){
if(nameiparent && *path == '\0'){
// Stop one level early.
iunlock(ip);
return ip;
@ -598,7 +599,7 @@ namex(char *path, int parent, char *name)
iunlockput(ip);
ip = next;
}
if(parent){
if(nameiparent){
iput(ip);
return 0;
}