dossrv: make GLONG() return ulong, handle getsect() error in dostat()

This commit is contained in:
cinap_lenrek 2018-12-23 22:43:29 +01:00
parent d843bc8e22
commit 1e0b65c8bf
3 changed files with 32 additions and 24 deletions

View file

@ -172,8 +172,8 @@ enum
DARCH = 0x20, DARCH = 0x20,
}; };
#define GSHORT(p) (((p)[0])|(p)[1]<<8) #define GSHORT(p) (((ushort)(p)[0])|(ushort)(p)[1]<<8)
#define GLONG(p) (((long)(p)[0])|(p)[1]<<8|(p)[2]<<16|(p)[3]<<24) #define GLONG(p) (((ulong)(p)[0])|(ulong)(p)[1]<<8|(ulong)(p)[2]<<16|(ulong)(p)[3]<<24)
#define PSHORT(p,v) ((p)[0]=(v),(p)[1]=(v)>>8) #define PSHORT(p,v) ((p)[0]=(v),(p)[1]=(v)>>8)
#define PLONG(p,v) ((p)[0]=(v),(p)[1]=(v)>>8,(p)[2]=(v)>>16,(p)[3]=(v)>>24) #define PLONG(p,v) ((p)[0]=(v),(p)[1]=(v)>>8,(p)[2]=(v)>>16,(p)[3]=(v)>>24)

View file

@ -631,7 +631,7 @@ out:
sync(); sync();
} }
static void static int
dostat(Xfile *f, Dir *d) dostat(Xfile *f, Dir *d)
{ {
Dosptr *dp; Dosptr *dp;
@ -663,6 +663,8 @@ dostat(Xfile *f, Dir *d)
} }
if(prevdo < 0 && dp->prevaddr != -1){ if(prevdo < 0 && dp->prevaddr != -1){
p = getsect(f->xf, dp->prevaddr); p = getsect(f->xf, dp->prevaddr);
if(p == nil)
return -1;
for(prevdo = ((Dosbpb*)f->xf->ptr)->sectsize-DOSDIRSIZE; prevdo >= 0; prevdo -= DOSDIRSIZE){ for(prevdo = ((Dosbpb*)f->xf->ptr)->sectsize-DOSDIRSIZE; prevdo >= 0; prevdo -= DOSDIRSIZE){
if(p->iobuf[prevdo+11] != 0xf) if(p->iobuf[prevdo+11] != 0xf)
break; break;
@ -674,6 +676,7 @@ dostat(Xfile *f, Dir *d)
if(islong && sum == -1 && nameok(namebuf)) if(islong && sum == -1 && nameok(namebuf))
strcpy(d->name, namebuf); strcpy(d->name, namebuf);
} }
return 0;
} }
void void
@ -687,12 +690,13 @@ rstat(void)
errno = Eio; errno = Eio;
return; return;
} }
dir.name = repdata; dir.name = repdata;
dostat(f, &dir); if(dostat(f, &dir) < 0)
errno = Eio;
else {
rep->nstat = convD2M(&dir, statbuf, sizeof statbuf); rep->nstat = convD2M(&dir, statbuf, sizeof statbuf);
rep->stat = statbuf; rep->stat = statbuf;
}
putfile(f); putfile(f);
} }
@ -724,7 +728,11 @@ rwstat(void)
changes = 0; changes = 0;
dir.name = repdata; dir.name = repdata;
dostat(f, &dir); if(dostat(f, &dir) < 0){
errno = Eio;
goto out;
}
if(convM2D(req->stat, req->nstat, &wdir, (char*)statbuf) != req->nstat){ if(convM2D(req->stat, req->nstat, &wdir, (char*)statbuf) != req->nstat){
errno = Ebadstat; errno = Ebadstat;
goto out; goto out;

View file

@ -73,7 +73,7 @@ dosfs(Xfs *xf)
} }
p = getsect(xf, 0); p = getsect(xf, 0);
if(p == 0) if(p == nil)
return -1; return -1;
b = (Dosboot*)p->iobuf; b = (Dosboot*)p->iobuf;
@ -547,7 +547,7 @@ searchdir(Xfile *f, char *name, Dosptr *dp, int cflag, int longtype)
if(addr < 0) if(addr < 0)
break; break;
p = getsect(xf, addr); p = getsect(xf, addr);
if(p == 0) if(p == nil)
break; break;
for(o=0; o<bp->sectsize; o+=DOSDIRSIZE){ for(o=0; o<bp->sectsize; o+=DOSDIRSIZE){
d = (Dosdir *)&p->iobuf[o]; d = (Dosdir *)&p->iobuf[o];
@ -653,7 +653,7 @@ emptydir(Xfile *f)
if(addr < 0) if(addr < 0)
break; break;
p = getsect(xf, addr); p = getsect(xf, addr);
if(p == 0) if(p == nil)
return -1; return -1;
for(o=0; o<bp->sectsize; o+=DOSDIRSIZE){ for(o=0; o<bp->sectsize; o+=DOSDIRSIZE){
d = (Dosdir *)&p->iobuf[o]; d = (Dosdir *)&p->iobuf[o];
@ -703,7 +703,7 @@ readdir(Xfile *f, void *vbuf, vlong offset, long count)
if(addr < 0) if(addr < 0)
break; break;
p = getsect(xf, addr); p = getsect(xf, addr);
if(p == 0) if(p == nil)
return -1; return -1;
for(o=0; o<bp->sectsize; o+=DOSDIRSIZE){ for(o=0; o<bp->sectsize; o+=DOSDIRSIZE){
d = (Dosdir *)&p->iobuf[o]; d = (Dosdir *)&p->iobuf[o];
@ -833,7 +833,7 @@ walkup(Xfile *f, Dosptr *ndp)
* verify that parent's . points to itself * verify that parent's . points to itself
*/ */
p = getsect(f->xf, clust2sect(bp, pstart)); p = getsect(f->xf, clust2sect(bp, pstart));
if(p == 0){ if(p == nil){
chat("getsect %ld failed\n", pstart); chat("getsect %ld failed\n", pstart);
goto error; goto error;
} }
@ -907,7 +907,7 @@ walkup(Xfile *f, Dosptr *ndp)
} }
putsect(p); putsect(p);
p = getsect(f->xf, k); p = getsect(f->xf, k);
if(p == 0){ if(p == nil){
chat("getsect %lld failed\n", k); chat("getsect %lld failed\n", k);
goto error; goto error;
} }
@ -959,7 +959,7 @@ readfile(Xfile *f, void *vbuf, vlong offset, long count)
if(c > count) if(c > count)
c = count; c = count;
p = getsect(xf, addr); p = getsect(xf, addr);
if(p == 0) if(p == nil)
return -1; return -1;
memmove(&buf[rcnt], &p->iobuf[o], c); memmove(&buf[rcnt], &p->iobuf[o], c);
putsect(p); putsect(p);
@ -1115,7 +1115,7 @@ getdir(Xfs *xfs, Dir *dp, Dosdir *d, vlong addr, int offset)
dp->mode |= DMDIR|0111; dp->mode |= DMDIR|0111;
dp->length = 0; dp->length = 0;
}else }else
dp->length = (ulong)GLONG(d->length); dp->length = GLONG(d->length);
if(d->attr & DSYSTEM){ if(d->attr & DSYSTEM){
dp->mode |= DMEXCL; dp->mode |= DMEXCL;
if(iscontig(xfs, d)) if(iscontig(xfs, d))
@ -1788,8 +1788,8 @@ bootdump(int fd, Dosboot *b)
Bprint(&bp, "fatsize: %d\n", GSHORT(b->fatsize)); Bprint(&bp, "fatsize: %d\n", GSHORT(b->fatsize));
Bprint(&bp, "trksize: %d\n", GSHORT(b->trksize)); Bprint(&bp, "trksize: %d\n", GSHORT(b->trksize));
Bprint(&bp, "nheads: %d\n", GSHORT(b->nheads)); Bprint(&bp, "nheads: %d\n", GSHORT(b->nheads));
Bprint(&bp, "nhidden: %ld\n", GLONG(b->nhidden)); Bprint(&bp, "nhidden: %lud\n", GLONG(b->nhidden));
Bprint(&bp, "bigvolsize: %ld\n", GLONG(b->bigvolsize)); Bprint(&bp, "bigvolsize: %lud\n", GLONG(b->bigvolsize));
Bprint(&bp, "driveno: %d\n", b->driveno); Bprint(&bp, "driveno: %d\n", b->driveno);
Bprint(&bp, "reserved0: 0x%2.2x\n", b->reserved0); Bprint(&bp, "reserved0: 0x%2.2x\n", b->reserved0);
Bprint(&bp, "bootsig: 0x%2.2x\n", b->bootsig); Bprint(&bp, "bootsig: 0x%2.2x\n", b->bootsig);
@ -1817,12 +1817,12 @@ bootdump32(int fd, Dosboot32 *b)
Bprint(&bp, "fatsize: %d\n", GSHORT(b->fatsize)); Bprint(&bp, "fatsize: %d\n", GSHORT(b->fatsize));
Bprint(&bp, "trksize: %d\n", GSHORT(b->trksize)); Bprint(&bp, "trksize: %d\n", GSHORT(b->trksize));
Bprint(&bp, "nheads: %d\n", GSHORT(b->nheads)); Bprint(&bp, "nheads: %d\n", GSHORT(b->nheads));
Bprint(&bp, "nhidden: %ld\n", GLONG(b->nhidden)); Bprint(&bp, "nhidden: %lud\n", GLONG(b->nhidden));
Bprint(&bp, "bigvolsize: %ld\n", GLONG(b->bigvolsize)); Bprint(&bp, "bigvolsize: %lud\n", GLONG(b->bigvolsize));
Bprint(&bp, "fatsize32: %ld\n", GLONG(b->fatsize32)); Bprint(&bp, "fatsize32: %lud\n", GLONG(b->fatsize32));
Bprint(&bp, "extflags: %d\n", GSHORT(b->extflags)); Bprint(&bp, "extflags: %d\n", GSHORT(b->extflags));
Bprint(&bp, "version: %d\n", GSHORT(b->version1)); Bprint(&bp, "version: %d\n", GSHORT(b->version1));
Bprint(&bp, "rootstart: %ld\n", GLONG(b->rootstart)); Bprint(&bp, "rootstart: %lud\n", GLONG(b->rootstart));
Bprint(&bp, "infospec: %d\n", GSHORT(b->infospec)); Bprint(&bp, "infospec: %d\n", GSHORT(b->infospec));
Bprint(&bp, "backupboot: %d\n", GSHORT(b->backupboot)); Bprint(&bp, "backupboot: %d\n", GSHORT(b->backupboot));
Bprint(&bp, "reserved: %d %d %d %d %d %d %d %d %d %d %d %d\n", Bprint(&bp, "reserved: %d %d %d %d %d %d %d %d %d %d %d %d\n",
@ -1919,7 +1919,7 @@ dirdump(void *vdbuf)
i = GSHORT(d->adate); i = GSHORT(d->adate);
s = seprint(s, ebuf, " %2.2d.%2.2d.%2.2d", 80+(i>>9), (i>>5)&15, i&31); s = seprint(s, ebuf, " %2.2d.%2.2d.%2.2d", 80+(i>>9), (i>>5)&15, i&31);
seprint(s, ebuf, " %d %lud", GSHORT(d->start), (ulong)GLONG(d->length)); seprint(s, ebuf, " %d %lud", GSHORT(d->start), GLONG(d->length));
} }
chat("%s\n", buf); chat("%s\n", buf);
} }