diff options
author | Russ Cox <[email protected]> | 2009-07-11 19:26:01 -0700 |
---|---|---|
committer | Russ Cox <[email protected]> | 2009-07-11 19:26:01 -0700 |
commit | f9a06440ab746256ecbf9fccdb251487cb2c29f7 (patch) | |
tree | b8d19a36f16724e711bbe02f0b50c84fe8c1f21f /fs.c | |
parent | 2de1c550cab8a5812dc9965313fce00816a003eb (diff) | |
download | xv6-labs-f9a06440ab746256ecbf9fccdb251487cb2c29f7.tar.gz xv6-labs-f9a06440ab746256ecbf9fccdb251487cb2c29f7.tar.bz2 xv6-labs-f9a06440ab746256ecbf9fccdb251487cb2c29f7.zip |
rearrangements and cleanup for text
Diffstat (limited to 'fs.c')
-rw-r--r-- | fs.c | 99 |
1 files changed, 50 insertions, 49 deletions
@@ -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* @@ -263,51 +310,6 @@ iunlockput(struct inode *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 // // The contents (data) associated with each inode is stored @@ -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; } |