Skip to content

Commit

Permalink
tolerate out of disk when creating . and .. in mkdir()
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Morris committed Aug 23, 2022
1 parent dc405cd commit 8621be8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
25 changes: 16 additions & 9 deletions kernel/sysfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,24 +272,31 @@ create(char *path, short type, short major, short minor)
iupdate(ip);

if(type == T_DIR){ // Create . and .. entries.
dp->nlink++; // for ".."
iupdate(dp);
// No ip->nlink++ for ".": avoid cyclic ref count.
if(dirlink(ip, ".", ip->inum) < 0 || dirlink(ip, "..", dp->inum) < 0)
panic("create dots");
goto fail;
}

if(dirlink(dp, name, ip->inum) < 0){
// oops. we don't need ip after all.
ip->nlink = 0;
iupdate(ip);
iunlockput(ip);
ip = 0;
if(dirlink(dp, name, ip->inum) < 0)
goto fail;

if(type == T_DIR){
// now that success is guaranteed:
dp->nlink++; // for ".."
iupdate(dp);
}

iunlockput(dp);

return ip;

fail:
// something went wrong. de-allocate ip.
ip->nlink = 0;
iupdate(ip);
iunlockput(ip);
iunlockput(dp);
return 0;
}

uint64
Expand Down
5 changes: 5 additions & 0 deletions user/usertests.c
Original file line number Diff line number Diff line change
Expand Up @@ -2712,6 +2712,8 @@ diskfull(char *s)
{
int fi;
int done = 0;

unlink("diskfulldir");

for(fi = 0; done == 0; fi++){
char name[32];
Expand Down Expand Up @@ -2758,6 +2760,9 @@ diskfull(char *s)
close(fd);
}

mkdir("diskfulldir");
unlink("diskfulldir");

for(int i = 0; i < nzz; i++){
char name[32];
name[0] = 'z';
Expand Down

0 comments on commit 8621be8

Please sign in to comment.