tolerate out of disk when creating . and .. in mkdir()

This commit is contained in:
Robert Morris 2022-08-23 08:52:15 -04:00
parent dc405cdb7b
commit 8621be8f3d
2 changed files with 21 additions and 9 deletions

View file

@ -272,24 +272,31 @@ create(char *path, short type, short major, short minor)
iupdate(ip); iupdate(ip);
if(type == T_DIR){ // Create . and .. entries. if(type == T_DIR){ // Create . and .. entries.
dp->nlink++; // for ".."
iupdate(dp);
// No ip->nlink++ for ".": avoid cyclic ref count. // No ip->nlink++ for ".": avoid cyclic ref count.
if(dirlink(ip, ".", ip->inum) < 0 || dirlink(ip, "..", dp->inum) < 0) if(dirlink(ip, ".", ip->inum) < 0 || dirlink(ip, "..", dp->inum) < 0)
panic("create dots"); goto fail;
} }
if(dirlink(dp, name, ip->inum) < 0){ if(dirlink(dp, name, ip->inum) < 0)
// oops. we don't need ip after all. goto fail;
ip->nlink = 0;
iupdate(ip); if(type == T_DIR){
iunlockput(ip); // now that success is guaranteed:
ip = 0; dp->nlink++; // for ".."
iupdate(dp);
} }
iunlockput(dp); iunlockput(dp);
return ip; return ip;
fail:
// something went wrong. de-allocate ip.
ip->nlink = 0;
iupdate(ip);
iunlockput(ip);
iunlockput(dp);
return 0;
} }
uint64 uint64

View file

@ -2713,6 +2713,8 @@ diskfull(char *s)
int fi; int fi;
int done = 0; int done = 0;
unlink("diskfulldir");
for(fi = 0; done == 0; fi++){ for(fi = 0; done == 0; fi++){
char name[32]; char name[32];
name[0] = 'b'; name[0] = 'b';
@ -2758,6 +2760,9 @@ diskfull(char *s)
close(fd); close(fd);
} }
mkdir("diskfulldir");
unlink("diskfulldir");
for(int i = 0; i < nzz; i++){ for(int i = 0; i < nzz; i++){
char name[32]; char name[32];
name[0] = 'z'; name[0] = 'z';