sys_unlink doesn't touch parent diretory references

上级 04f26a8d
...@@ -168,23 +168,24 @@ sys_unlink(const char *path) ...@@ -168,23 +168,24 @@ sys_unlink(const char *path)
{ {
struct inode *ip, *dp; struct inode *ip, *dp;
char name[DIRSIZ]; char name[DIRSIZ];
bool haveref = false;
if(argcheckstr(path) < 0) if(argcheckstr(path) < 0)
return -1; return -1;
if((dp = nameiparent(myproc()->cwd, path, name)) == 0) if((dp = __nameiparent(myproc()->cwd, path, name, &haveref)) == 0)
return -1; return -1;
if(dp->type != T_DIR) if(dp->type != T_DIR)
panic("sys_unlink"); panic("sys_unlink");
// Cannot unlink "." or "..". // Cannot unlink "." or "..".
if(namecmp(name, ".") == 0 || namecmp(name, "..") == 0){ if(namecmp(name, ".") == 0 || namecmp(name, "..") == 0){
iput(dp); iput(dp, haveref);
return -1; return -1;
} }
retry: retry:
if((ip = dirlookup(dp, name)) == 0){ if((ip = dirlookup(dp, name)) == 0){
iput(dp); iput(dp, haveref);
return -1; return -1;
} }
ilock(ip, 1); ilock(ip, 1);
...@@ -193,7 +194,7 @@ sys_unlink(const char *path) ...@@ -193,7 +194,7 @@ sys_unlink(const char *path)
panic("unlink: nlink < 1"); panic("unlink: nlink < 1");
if(ip->type == T_DIR && !isdirempty(ip)){ if(ip->type == T_DIR && !isdirempty(ip)){
iunlockput(ip); iunlockput(ip);
iput(dp); iput(dp, haveref);
return -1; return -1;
} }
...@@ -210,8 +211,7 @@ sys_unlink(const char *path) ...@@ -210,8 +211,7 @@ sys_unlink(const char *path)
iunlock(dp); iunlock(dp);
} }
//nc_invalidate(dp, name); iput(dp, haveref);
iput(dp);
ip->unlink(); ip->unlink();
iupdate(ip); iupdate(ip);
...@@ -276,7 +276,8 @@ create(inode *cwd, const char *path, short type, short major, short minor) ...@@ -276,7 +276,8 @@ create(inode *cwd, const char *path, short type, short major, short minor)
if (!dp->valid()) { if (!dp->valid()) {
// XXX(sbw) we need to undo everything we just did // XXX(sbw) we need to undo everything we just did
// (at least all the modifications to dp) and retry. // (at least all the modifications to dp) and retry
// (or return an error).
panic("create: race"); panic("create: race");
} }
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论