hjfs: fix more missing dirty marks, error handling, cleanup
This commit is contained in:
parent
7ced300071
commit
df829e6c07
3 changed files with 41 additions and 54 deletions
|
@ -397,22 +397,22 @@ createuserdir(Fs *fs, char *name, short uid)
|
||||||
c = getbuf(ch->fs->d, f.blk, TDENTRY, 0);
|
c = getbuf(ch->fs->d, f.blk, TDENTRY, 0);
|
||||||
if(c == nil)
|
if(c == nil)
|
||||||
goto direrr2;
|
goto direrr2;
|
||||||
|
c->op |= BDELWRI;
|
||||||
d = &c->de[f.deind];
|
d = &c->de[f.deind];
|
||||||
memset(d, 0, sizeof(Dentry));
|
memset(d, 0, sizeof(*d));
|
||||||
strncpy(d->name, name, NAMELEN - 1);
|
|
||||||
d->uid = uid;
|
|
||||||
d->muid = uid;
|
|
||||||
d->gid = uid;
|
|
||||||
d->mode = DALLOC | 0775;
|
|
||||||
if(newqid(fs, &d->path) < 0){
|
if(newqid(fs, &d->path) < 0){
|
||||||
direrr3:
|
direrr3:
|
||||||
putbuf(c);
|
putbuf(c);
|
||||||
goto direrr2;
|
goto direrr2;
|
||||||
}
|
}
|
||||||
|
strncpy(d->name, name, NAMELEN - 1);
|
||||||
|
d->uid = uid;
|
||||||
|
d->muid = uid;
|
||||||
|
d->gid = uid;
|
||||||
|
d->mode = DALLOC | 0775;
|
||||||
d->type = QTDIR;
|
d->type = QTDIR;
|
||||||
d->atime = time(0);
|
d->atime = time(0);
|
||||||
d->mtime = d->atime;
|
d->mtime = d->atime;
|
||||||
c->op |= BDELWRI;
|
|
||||||
goto direrr3;
|
goto direrr3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -549,6 +549,7 @@ getblk(Fs *fs, FLoc *L, Buf *bd, uvlong blk, uvlong *r, int mode)
|
||||||
if(b == nil)
|
if(b == nil)
|
||||||
return -1;
|
return -1;
|
||||||
memset(b->offs, 0, sizeof(b->offs));
|
memset(b->offs, 0, sizeof(b->offs));
|
||||||
|
b->op |= BDELWRI;
|
||||||
}else{
|
}else{
|
||||||
if(mode != GBREAD && chref(fs, *loc, 0) > 1){
|
if(mode != GBREAD && chref(fs, *loc, 0) > 1){
|
||||||
if(dumpblk(fs, L, loc) < 0){
|
if(dumpblk(fs, L, loc) < 0){
|
||||||
|
@ -632,9 +633,10 @@ delindir(Fs *fs, uvlong *l, int n)
|
||||||
b = getbuf(fs->d, *l, TINDIR, 0);
|
b = getbuf(fs->d, *l, TINDIR, 0);
|
||||||
if(b != nil){
|
if(b != nil){
|
||||||
for(k = 0; k < OFFPERBLK; k++)
|
for(k = 0; k < OFFPERBLK; k++)
|
||||||
if(b->offs[k] != 0)
|
if(b->offs[k] != 0){
|
||||||
delindir(fs, &b->offs[k], n-1);
|
delindir(fs, &b->offs[k], n-1);
|
||||||
b->op |= BDELWRI;
|
b->op |= BDELWRI;
|
||||||
|
}
|
||||||
putbuf(b);
|
putbuf(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -702,6 +704,7 @@ trunc(Fs *fs, FLoc *ll, Buf *bd, uvlong size)
|
||||||
if(d->db[blk] != 0){
|
if(d->db[blk] != 0){
|
||||||
putfree(fs, d->db[blk]);
|
putfree(fs, d->db[blk]);
|
||||||
d->db[blk] = 0;
|
d->db[blk] = 0;
|
||||||
|
bd->op |= BDELWRI;
|
||||||
}
|
}
|
||||||
blk++;
|
blk++;
|
||||||
}
|
}
|
||||||
|
@ -856,6 +859,7 @@ delete(Fs *fs, FLoc *l, Buf *b)
|
||||||
if((d->type & QTDIR) == 0){
|
if((d->type & QTDIR) == 0){
|
||||||
trunc(fs, l, b, 0);
|
trunc(fs, l, b, 0);
|
||||||
memset(d, 0, sizeof(*d));
|
memset(d, 0, sizeof(*d));
|
||||||
|
b->op |= BDELWRI;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
first = last = emalloc(sizeof(Del));
|
first = last = emalloc(sizeof(Del));
|
||||||
|
|
|
@ -146,15 +146,19 @@ chancreat(Chan *ch, char *name, int perm, int mode)
|
||||||
c = getbuf(ch->fs->d, f.blk, TDENTRY, 0);
|
c = getbuf(ch->fs->d, f.blk, TDENTRY, 0);
|
||||||
if(c == nil)
|
if(c == nil)
|
||||||
goto error;
|
goto error;
|
||||||
|
c->op |= BDELWRI;
|
||||||
|
b->op |= BDELWRI;
|
||||||
modified(ch, d);
|
modified(ch, d);
|
||||||
if(isdir)
|
if(isdir)
|
||||||
perm &= ~0777 | d->mode & 0777;
|
perm &= ~0777 | d->mode & 0777;
|
||||||
else
|
else
|
||||||
perm &= ~0666 | d->mode & 0666;
|
perm &= ~0666 | d->mode & 0666;
|
||||||
d = &c->de[f.deind];
|
d = &c->de[f.deind];
|
||||||
memset(d, 0, sizeof(Dentry));
|
memset(d, 0, sizeof(*d));
|
||||||
if(newqid(ch->fs, &d->path) < 0)
|
if(newqid(ch->fs, &d->path) < 0){
|
||||||
|
putbuf(c);
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
d->type = perm >> 24;
|
d->type = perm >> 24;
|
||||||
strcpy(d->name, name);
|
strcpy(d->name, name);
|
||||||
d->mtime = time(0);
|
d->mtime = time(0);
|
||||||
|
@ -169,8 +173,6 @@ chancreat(Chan *ch, char *name, int perm, int mode)
|
||||||
ch->loc->lwrite = d->atime;
|
ch->loc->lwrite = d->atime;
|
||||||
qunlock(&ch->loc->ex);
|
qunlock(&ch->loc->ex);
|
||||||
}
|
}
|
||||||
c->op |= BDELWRI;
|
|
||||||
b->op |= BDELWRI;
|
|
||||||
putbuf(c);
|
putbuf(c);
|
||||||
putbuf(b);
|
putbuf(b);
|
||||||
switch(mode & OEXEC){
|
switch(mode & OEXEC){
|
||||||
|
@ -259,6 +261,7 @@ chanopen(Chan *ch, int mode)
|
||||||
if((mode & OTRUNC) != 0){
|
if((mode & OTRUNC) != 0){
|
||||||
trunc(ch->fs, ch->loc, b, 0);
|
trunc(ch->fs, ch->loc, b, 0);
|
||||||
modified(ch, d);
|
modified(ch, d);
|
||||||
|
b->op |= BDELWRI;
|
||||||
}
|
}
|
||||||
if((mode & ORCLOSE) != 0)
|
if((mode & ORCLOSE) != 0)
|
||||||
ch->open |= CHRCLOSE;
|
ch->open |= CHRCLOSE;
|
||||||
|
@ -568,6 +571,7 @@ chanclunk(Chan *ch)
|
||||||
|
|
||||||
chbegin(ch);
|
chbegin(ch);
|
||||||
rc = 1;
|
rc = 1;
|
||||||
|
b = p = nil;
|
||||||
if(ch->open & CHRCLOSE){
|
if(ch->open & CHRCLOSE){
|
||||||
if((ch->flags & CHFRO) != 0)
|
if((ch->flags & CHFRO) != 0)
|
||||||
goto inval;
|
goto inval;
|
||||||
|
@ -584,27 +588,17 @@ chanclunk(Chan *ch)
|
||||||
if(p == nil)
|
if(p == nil)
|
||||||
goto err;
|
goto err;
|
||||||
b = getbuf(ch->fs->d, ch->loc->blk, TDENTRY, 0);
|
b = getbuf(ch->fs->d, ch->loc->blk, TDENTRY, 0);
|
||||||
if(b == nil){
|
if(b == nil)
|
||||||
putbuf(p);
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
if(!permcheck(ch->fs, &p->de[ch->loc->next->deind], ch->uid, OWRITE)){
|
if(!permcheck(ch->fs, &p->de[ch->loc->next->deind], ch->uid, OWRITE)){
|
||||||
werrstr(Eperm);
|
werrstr(Eperm);
|
||||||
putbuf(b);
|
|
||||||
putbuf(p);
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
d = &b->de[ch->loc->deind];
|
d = &b->de[ch->loc->deind];
|
||||||
if((d->type & QTDIR) != 0 && findentry(ch->fs, ch->loc, b, nil, nil, ch->flags & CHFDUMP) != 0){
|
if((d->type & QTDIR) != 0 && findentry(ch->fs, ch->loc, b, nil, nil, ch->flags & CHFDUMP) != 0)
|
||||||
putbuf(b);
|
|
||||||
putbuf(p);
|
|
||||||
goto inval;
|
goto inval;
|
||||||
}
|
if((d->mode & DGONE) != 0)
|
||||||
if((d->mode & DGONE) != 0){
|
|
||||||
putbuf(b);
|
|
||||||
putbuf(p);
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
|
||||||
qlock(&ch->fs->loctree);
|
qlock(&ch->fs->loctree);
|
||||||
if(ch->loc->ref > 1){
|
if(ch->loc->ref > 1){
|
||||||
d->mode &= ~DALLOC;
|
d->mode &= ~DALLOC;
|
||||||
|
@ -617,10 +611,12 @@ chanclunk(Chan *ch)
|
||||||
rc = delete(ch->fs, ch->loc, b);
|
rc = delete(ch->fs, ch->loc, b);
|
||||||
}
|
}
|
||||||
b->op |= BDELWRI;
|
b->op |= BDELWRI;
|
||||||
putbuf(b);
|
|
||||||
putbuf(p);
|
|
||||||
}
|
}
|
||||||
done:
|
done:
|
||||||
|
if(b != nil)
|
||||||
|
putbuf(b);
|
||||||
|
if(p != nil)
|
||||||
|
putbuf(p);
|
||||||
if((ch->loc->type & QTEXCL) != 0){
|
if((ch->loc->type & QTEXCL) != 0){
|
||||||
qlock(&ch->loc->ex);
|
qlock(&ch->loc->ex);
|
||||||
if(ch->loc->exlock == ch)
|
if(ch->loc->exlock == ch)
|
||||||
|
@ -650,38 +646,24 @@ chanwstat(Chan *ch, Dir *di)
|
||||||
chend(ch);
|
chend(ch);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pb = nil;
|
b = pb = nil;
|
||||||
if(*di->name){
|
if(*di->name){
|
||||||
if(!namevalid(di->name) || ch->loc->next == nil){
|
if(!namevalid(di->name) || ch->loc->next == nil)
|
||||||
werrstr(Einval);
|
goto inval;
|
||||||
chend(ch);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
pb = getbuf(ch->fs->d, ch->loc->next->blk, TDENTRY, 0);
|
pb = getbuf(ch->fs->d, ch->loc->next->blk, TDENTRY, 0);
|
||||||
if(pb == nil){
|
if(pb == nil)
|
||||||
chend(ch);
|
goto error;
|
||||||
return -1;
|
if(!permcheck(ch->fs, &pb->de[ch->loc->next->deind], ch->uid, OWRITE))
|
||||||
}
|
goto perm;
|
||||||
if(!permcheck(ch->fs, &pb->de[ch->loc->next->deind], ch->uid, OWRITE)){
|
|
||||||
werrstr(Eperm);
|
|
||||||
putbuf(pb);
|
|
||||||
chend(ch);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
rc = findentry(ch->fs, ch->loc->next, pb, di->name, nil, ch->flags & CHFDUMP);
|
rc = findentry(ch->fs, ch->loc->next, pb, di->name, nil, ch->flags & CHFDUMP);
|
||||||
if(rc > 0)
|
if(rc > 0)
|
||||||
werrstr(Eexists);
|
werrstr(Eexists);
|
||||||
if(rc != 0){
|
if(rc != 0)
|
||||||
putbuf(pb);
|
goto error;
|
||||||
chend(ch);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
b = getbuf(ch->fs->d, ch->loc->blk, TDENTRY, 0);
|
b = getbuf(ch->fs->d, ch->loc->blk, TDENTRY, 0);
|
||||||
if(b == nil){
|
if(b == nil)
|
||||||
chend(ch);
|
goto error;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
d = &b->de[ch->loc->deind];
|
d = &b->de[ch->loc->deind];
|
||||||
isdir = (d->type & QTDIR) != 0;
|
isdir = (d->type & QTDIR) != 0;
|
||||||
owner = ch->uid == d->uid || ingroup(ch->fs, ch->uid, d->gid, 1) || (ch->fs->flags & FSNOPERM) != 0;
|
owner = ch->uid == d->uid || ingroup(ch->fs, ch->uid, d->gid, 1) || (ch->fs->flags & FSNOPERM) != 0;
|
||||||
|
@ -741,7 +723,8 @@ perm:
|
||||||
error:
|
error:
|
||||||
if(pb != nil)
|
if(pb != nil)
|
||||||
putbuf(pb);
|
putbuf(pb);
|
||||||
putbuf(b);
|
if(b != nil)
|
||||||
|
putbuf(b);
|
||||||
chend(ch);
|
chend(ch);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue