From f9a06440ab746256ecbf9fccdb251487cb2c29f7 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sat, 11 Jul 2009 19:26:01 -0700 Subject: rearrangements and cleanup for text --- fs.c | 99 ++++++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 50 insertions(+), 49 deletions(-) (limited to 'fs.c') diff --git a/fs.c b/fs.c index 13fc935..fe65338 100644 --- a/fs.c +++ b/fs.c @@ -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; } -- cgit v1.2.3