summaryrefslogtreecommitdiff
path: root/sys/src/cmd/dossrv
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2018-12-23 22:43:29 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2018-12-23 22:43:29 +0100
commit1e0b65c8bfb2f1b6fbc189795b73a6e89b05dc75 (patch)
tree5e32d273de43cfc015c8efcd306e1bcdb28e20e4 /sys/src/cmd/dossrv
parentd843bc8e22a7db269867fdc702bd0043e4f499a0 (diff)
dossrv: make GLONG() return ulong, handle getsect() error in dostat()
Diffstat (limited to 'sys/src/cmd/dossrv')
-rw-r--r--sys/src/cmd/dossrv/dat.h4
-rw-r--r--sys/src/cmd/dossrv/dosfs.c22
-rw-r--r--sys/src/cmd/dossrv/dossubs.c30
3 files changed, 32 insertions, 24 deletions
diff --git a/sys/src/cmd/dossrv/dat.h b/sys/src/cmd/dossrv/dat.h
index 0347f0900..80af491b0 100644
--- a/sys/src/cmd/dossrv/dat.h
+++ b/sys/src/cmd/dossrv/dat.h
@@ -172,8 +172,8 @@ enum
DARCH = 0x20,
};
-#define GSHORT(p) (((p)[0])|(p)[1]<<8)
-#define GLONG(p) (((long)(p)[0])|(p)[1]<<8|(p)[2]<<16|(p)[3]<<24)
+#define GSHORT(p) (((ushort)(p)[0])|(ushort)(p)[1]<<8)
+#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 PLONG(p,v) ((p)[0]=(v),(p)[1]=(v)>>8,(p)[2]=(v)>>16,(p)[3]=(v)>>24)
diff --git a/sys/src/cmd/dossrv/dosfs.c b/sys/src/cmd/dossrv/dosfs.c
index 4dd344a9f..4a644fca5 100644
--- a/sys/src/cmd/dossrv/dosfs.c
+++ b/sys/src/cmd/dossrv/dosfs.c
@@ -631,7 +631,7 @@ out:
sync();
}
-static void
+static int
dostat(Xfile *f, Dir *d)
{
Dosptr *dp;
@@ -663,6 +663,8 @@ dostat(Xfile *f, Dir *d)
}
if(prevdo < 0 && dp->prevaddr != -1){
p = getsect(f->xf, dp->prevaddr);
+ if(p == nil)
+ return -1;
for(prevdo = ((Dosbpb*)f->xf->ptr)->sectsize-DOSDIRSIZE; prevdo >= 0; prevdo -= DOSDIRSIZE){
if(p->iobuf[prevdo+11] != 0xf)
break;
@@ -674,6 +676,7 @@ dostat(Xfile *f, Dir *d)
if(islong && sum == -1 && nameok(namebuf))
strcpy(d->name, namebuf);
}
+ return 0;
}
void
@@ -687,12 +690,13 @@ rstat(void)
errno = Eio;
return;
}
-
dir.name = repdata;
- dostat(f, &dir);
-
- rep->nstat = convD2M(&dir, statbuf, sizeof statbuf);
- rep->stat = statbuf;
+ if(dostat(f, &dir) < 0)
+ errno = Eio;
+ else {
+ rep->nstat = convD2M(&dir, statbuf, sizeof statbuf);
+ rep->stat = statbuf;
+ }
putfile(f);
}
@@ -724,7 +728,11 @@ rwstat(void)
changes = 0;
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){
errno = Ebadstat;
goto out;
diff --git a/sys/src/cmd/dossrv/dossubs.c b/sys/src/cmd/dossrv/dossubs.c
index bd172a28b..6347eabb9 100644
--- a/sys/src/cmd/dossrv/dossubs.c
+++ b/sys/src/cmd/dossrv/dossubs.c
@@ -73,7 +73,7 @@ dosfs(Xfs *xf)
}
p = getsect(xf, 0);
- if(p == 0)
+ if(p == nil)
return -1;
b = (Dosboot*)p->iobuf;
@@ -547,7 +547,7 @@ searchdir(Xfile *f, char *name, Dosptr *dp, int cflag, int longtype)
if(addr < 0)
break;
p = getsect(xf, addr);
- if(p == 0)
+ if(p == nil)
break;
for(o=0; o<bp->sectsize; o+=DOSDIRSIZE){
d = (Dosdir *)&p->iobuf[o];
@@ -653,7 +653,7 @@ emptydir(Xfile *f)
if(addr < 0)
break;
p = getsect(xf, addr);
- if(p == 0)
+ if(p == nil)
return -1;
for(o=0; o<bp->sectsize; o+=DOSDIRSIZE){
d = (Dosdir *)&p->iobuf[o];
@@ -703,7 +703,7 @@ readdir(Xfile *f, void *vbuf, vlong offset, long count)
if(addr < 0)
break;
p = getsect(xf, addr);
- if(p == 0)
+ if(p == nil)
return -1;
for(o=0; o<bp->sectsize; o+=DOSDIRSIZE){
d = (Dosdir *)&p->iobuf[o];
@@ -833,7 +833,7 @@ walkup(Xfile *f, Dosptr *ndp)
* verify that parent's . points to itself
*/
p = getsect(f->xf, clust2sect(bp, pstart));
- if(p == 0){
+ if(p == nil){
chat("getsect %ld failed\n", pstart);
goto error;
}
@@ -907,7 +907,7 @@ walkup(Xfile *f, Dosptr *ndp)
}
putsect(p);
p = getsect(f->xf, k);
- if(p == 0){
+ if(p == nil){
chat("getsect %lld failed\n", k);
goto error;
}
@@ -959,7 +959,7 @@ readfile(Xfile *f, void *vbuf, vlong offset, long count)
if(c > count)
c = count;
p = getsect(xf, addr);
- if(p == 0)
+ if(p == nil)
return -1;
memmove(&buf[rcnt], &p->iobuf[o], c);
putsect(p);
@@ -1115,7 +1115,7 @@ getdir(Xfs *xfs, Dir *dp, Dosdir *d, vlong addr, int offset)
dp->mode |= DMDIR|0111;
dp->length = 0;
}else
- dp->length = (ulong)GLONG(d->length);
+ dp->length = GLONG(d->length);
if(d->attr & DSYSTEM){
dp->mode |= DMEXCL;
if(iscontig(xfs, d))
@@ -1788,8 +1788,8 @@ bootdump(int fd, Dosboot *b)
Bprint(&bp, "fatsize: %d\n", GSHORT(b->fatsize));
Bprint(&bp, "trksize: %d\n", GSHORT(b->trksize));
Bprint(&bp, "nheads: %d\n", GSHORT(b->nheads));
- Bprint(&bp, "nhidden: %ld\n", GLONG(b->nhidden));
- Bprint(&bp, "bigvolsize: %ld\n", GLONG(b->bigvolsize));
+ Bprint(&bp, "nhidden: %lud\n", GLONG(b->nhidden));
+ Bprint(&bp, "bigvolsize: %lud\n", GLONG(b->bigvolsize));
Bprint(&bp, "driveno: %d\n", b->driveno);
Bprint(&bp, "reserved0: 0x%2.2x\n", b->reserved0);
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, "trksize: %d\n", GSHORT(b->trksize));
Bprint(&bp, "nheads: %d\n", GSHORT(b->nheads));
- Bprint(&bp, "nhidden: %ld\n", GLONG(b->nhidden));
- Bprint(&bp, "bigvolsize: %ld\n", GLONG(b->bigvolsize));
- Bprint(&bp, "fatsize32: %ld\n", GLONG(b->fatsize32));
+ Bprint(&bp, "nhidden: %lud\n", GLONG(b->nhidden));
+ Bprint(&bp, "bigvolsize: %lud\n", GLONG(b->bigvolsize));
+ Bprint(&bp, "fatsize32: %lud\n", GLONG(b->fatsize32));
Bprint(&bp, "extflags: %d\n", GSHORT(b->extflags));
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, "backupboot: %d\n", GSHORT(b->backupboot));
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);
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);
}