summaryrefslogtreecommitdiff
path: root/fs.c
diff options
context:
space:
mode:
authorrsc <rsc>2007-08-24 20:54:23 +0000
committerrsc <rsc>2007-08-24 20:54:23 +0000
commit07090dd705df557cba5ce4ea46b2a274876343a5 (patch)
tree4e4c4415c702ff4c041e101ab3c7173fd636d9d0 /fs.c
parentfa1b34106ad99cf8021227b4c1e62353ae4d0fda (diff)
downloadxv6-labs-07090dd705df557cba5ce4ea46b2a274876343a5.tar.gz
xv6-labs-07090dd705df557cba5ce4ea46b2a274876343a5.tar.bz2
xv6-labs-07090dd705df557cba5ce4ea46b2a274876343a5.zip
Remove struct uinode.
Remove type arg to mknod (assume T_DEV).
Diffstat (limited to 'fs.c')
-rw-r--r--fs.c94
1 files changed, 42 insertions, 52 deletions
diff --git a/fs.c b/fs.c
index 58893b1..bc3cccd 100644
--- a/fs.c
+++ b/fs.c
@@ -129,7 +129,7 @@ iinit(void)
// Find the inode with number inum on device dev
// and return the in-memory copy. h
-static struct uinode*
+static struct inode*
iget(uint dev, uint inum)
{
struct inode *ip, *empty;
@@ -142,7 +142,7 @@ iget(uint dev, uint inum)
if(ip->ref > 0 && ip->dev == dev && ip->inum == inum){
ip->ref++;
release(&icache.lock);
- return (struct uinode*)ip;
+ return ip;
}
if(empty == 0 && ip->ref == 0) // Remember empty slot.
empty = ip;
@@ -159,37 +159,29 @@ iget(uint dev, uint inum)
ip->flags = 0;
release(&icache.lock);
- return (struct uinode*)ip;
+ return ip;
}
// Increment reference count for ip.
// Returns ip to enable ip = idup(ip1) idiom.
-struct uinode*
-idup(struct uinode *uip)
+struct inode*
+idup(struct inode *ip)
{
- struct inode *ip;
-
- ip = (struct inode*)uip;
acquire(&icache.lock);
ip->ref++;
release(&icache.lock);
- return uip;
+ return ip;
}
// Lock the given inode.
-struct inode*
-ilock(struct uinode *uip)
+void
+ilock(struct inode *ip)
{
struct buf *bp;
struct dinode *dip;
- struct inode *ip;
-
- ip = (struct inode*)uip;
- if(ip == 0)
- return 0;
- if(ip->ref < 1)
- panic("ilock: no refs");
+ if(ip == 0 || ip->ref < 1)
+ panic("ilock");
acquire(&icache.lock);
while(ip->flags & I_BUSY)
@@ -211,33 +203,25 @@ ilock(struct uinode *uip)
if(ip->type == 0)
panic("ilock: no type");
}
- return ip;
}
// Unlock the given inode.
-struct uinode*
+void
iunlock(struct inode *ip)
{
- if(ip == 0)
- return 0;
-
- if(!(ip->flags & I_BUSY) || ip->ref < 1)
+ if(ip == 0 || !(ip->flags & I_BUSY) || ip->ref < 1)
panic("iunlock");
acquire(&icache.lock);
ip->flags &= ~I_BUSY;
wakeup(ip);
release(&icache.lock);
- return (struct uinode*)ip;
}
// Caller holds reference to unlocked ip. Drop reference.
void
-iput(struct uinode *uip)
+iput(struct inode *ip)
{
- struct inode *ip;
-
- ip = (struct inode*)uip;
acquire(&icache.lock);
if(ip->ref == 1 && (ip->flags & I_VALID) && ip->nlink == 0) {
// inode is no longer used: truncate and free inode.
@@ -256,8 +240,15 @@ iput(struct uinode *uip)
release(&icache.lock);
}
+void
+iunlockput(struct inode *ip)
+{
+ iunlock(ip);
+ iput(ip);
+}
+
// Allocate a new inode with the given type on device dev.
-struct uinode*
+struct inode*
ialloc(uint dev, short type)
{
int inum, ninodes;
@@ -478,7 +469,7 @@ namecmp(const char *s, const char *t)
// Look for a directory entry in a directory.
// If found, set *poff to byte offset of entry.
// Caller must have already locked dp.
-struct uinode*
+struct inode*
dirlookup(struct inode *dp, char *name, uint *poff)
{
uint off, inum;
@@ -527,11 +518,11 @@ dirlink(struct inode *dp, char *name, uint ino)
{
int off;
struct dirent de;
- struct uinode *ipu;
+ struct inode *ip;
// Check that name is not present.
- if((ipu = dirlookup(dp, name, 0)) != 0){
- iput(ipu);
+ if((ip = dirlookup(dp, name, 0)) != 0){
+ iput(ip);
return -1;
}
@@ -593,53 +584,52 @@ skipelem(char *path, char *name)
// If parent is set, return the inode for the parent
// and write the final path element to name, which
// should have room for DIRSIZ bytes.
-static struct uinode*
+static struct inode*
_namei(char *path, int parent, char *name)
{
- struct uinode *dpu, *ipu;
- struct inode *dp;
+ struct inode *ip, *next;
uint off;
if(*path == '/')
- dpu = iget(ROOTDEV, 1);
+ ip = iget(ROOTDEV, 1);
else
- dpu = idup(cp->cwd);
+ ip = idup(cp->cwd);
while((path = skipelem(path, name)) != 0){
- dp = ilock(dpu);
- if(dp->type != T_DIR){
- iput(iunlock(dp));
+ ilock(ip);
+ if(ip->type != T_DIR){
+ iunlockput(ip);
return 0;
}
if(parent && *path == '\0'){
// Stop one level early.
- iunlock(dp);
- return dpu;
+ iunlock(ip);
+ return ip;
}
- if((ipu = dirlookup(dp, name, &off)) == 0){
- iput(iunlock(dp));
+ if((next = dirlookup(ip, name, &off)) == 0){
+ iunlockput(ip);
return 0;
}
- iput(iunlock(dp));
- dpu = ipu;
+ iunlockput(ip);
+ ip = next;
}
if(parent){
- iput(dpu);
+ iput(ip);
return 0;
}
- return dpu;
+ return ip;
}
-struct uinode*
+struct inode*
namei(char *path)
{
char name[DIRSIZ];
return _namei(path, 0, name);
}
-struct uinode*
+struct inode*
nameiparent(char *path, char *name)
{
return _namei(path, 1, name);