In namex, drop the refs dirlookup returns

上级 91c171fc
...@@ -746,13 +746,15 @@ static struct inode* ...@@ -746,13 +746,15 @@ static struct inode*
namex(inode *cwd, const char *path, int nameiparent, char *name) namex(inode *cwd, const char *path, int nameiparent, char *name)
{ {
struct inode *ip, *next; struct inode *ip, *next;
bool drop_ref;
int r; int r;
scoped_gc_epoch e;
scoped_gc_epoch e;
if(*path == '/') if(*path == '/')
ip = igetnoref(ROOTDEV, ROOTINO); ip = igetnoref(ROOTDEV, ROOTINO);
else else
ip = cwd; ip = cwd;
drop_ref = false;
while((r = skipelem(&path, name)) == 1){ while((r = skipelem(&path, name)) == 1){
// XXX Doing this here requires some annoying reasoning about all // XXX Doing this here requires some annoying reasoning about all
...@@ -765,20 +767,23 @@ namex(inode *cwd, const char *path, int nameiparent, char *name) ...@@ -765,20 +767,23 @@ namex(inode *cwd, const char *path, int nameiparent, char *name)
// the caller declare the variables? Would it help for the caller // the caller declare the variables? Would it help for the caller
// to pass in an abstract scope? // to pass in an abstract scope?
mtreadavar("inode:%x.%x", ip->dev, ip->inum); mtreadavar("inode:%x.%x", ip->dev, ip->inum);
next = 0; if(ip->type == 0)
if(next == 0){ panic("namex");
if(ip->type == 0) if(ip->type != T_DIR)
panic("namex"); return 0;
if(ip->type != T_DIR) if(nameiparent && *path == '\0'){
return 0; // Stop one level early.
if(nameiparent && *path == '\0'){ if (!drop_ref)
// Stop one level early.
idup(ip); idup(ip);
return ip; return ip;
}
if((next = dirlookup(ip, name)) == 0)
return 0;
} }
if((next = dirlookup(ip, name)) == 0)
return 0;
if (drop_ref)
iput(ip);
drop_ref = true;
ip = next; ip = next;
} }
...@@ -792,7 +797,8 @@ namex(inode *cwd, const char *path, int nameiparent, char *name) ...@@ -792,7 +797,8 @@ namex(inode *cwd, const char *path, int nameiparent, char *name)
// mtreadavar("inode:%x.%x", ip->dev, ip->inum); // mtreadavar("inode:%x.%x", ip->dev, ip->inum);
mtwriteavar("inode:%x.%x", ip->dev, ip->inum); mtwriteavar("inode:%x.%x", ip->dev, ip->inum);
idup(ip); if (!drop_ref)
idup(ip);
return ip; return ip;
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论