From bd5806a58271e753109c24ba13ac5288465ae345 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 3 Dec 1991 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1991-12-03 --- pc/devfloppy.c | 2 +- port/devarp.c | 3 ++- port/devwren.c | 70 +++++++++++++++++++++++++++----------------------- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/pc/devfloppy.c b/pc/devfloppy.c index 3b250b3e712a35106d21881e89fe3d6ab159c506..2be2495af170b64b345fe944e8e79e5c7453873c 100644 --- a/pc/devfloppy.c +++ b/pc/devfloppy.c @@ -284,7 +284,7 @@ floppystat(Chan *c, char *dp) Chan* floppyopen(Chan *c, int omode) { - devopen(c, omode, floppydir, conf.nfloppy*NFDIR, devgen); + return devopen(c, omode, floppydir, conf.nfloppy*NFDIR, devgen); } void diff --git a/port/devarp.c b/port/devarp.c index 7be20a4a6376659775b661d1a2f3ec27ed8864f2..d2060f936662aeb68354423dd35e7106a7440a24 100644 --- a/port/devarp.c +++ b/port/devarp.c @@ -18,7 +18,8 @@ #define ARPHASH(p) arphash[((p[2]^p[3])%Arphashsize)] typedef struct Arpcache Arpcache; -struct Arpcache { +struct Arpcache +{ uchar status; uchar type; uchar eip[4]; diff --git a/port/devwren.c b/port/devwren.c index 60d7da777f9d5bd189dc494df4144aefb40406b6..5efa396c8a3cc1ffa59a588eff63514f8c3db5a6 100644 --- a/port/devwren.c +++ b/port/devwren.c @@ -42,7 +42,7 @@ struct Drive static Drive wren[Ndisk]; static void wrenpart(int); -static long wrenio(Drive *, Partition *, int, char *, ulong, ulong); +static long wrenio(Chan*, int, char*, ulong, ulong); /* * accepts [0-7].[0-7], or abbreviation @@ -173,66 +173,72 @@ wrenwstat(Chan *c, char *dp) long wrenread(Chan *c, char *a, long n, ulong offset) { - Drive *d; - Partition *p; - - if(c->qid.path == CHDIR) return devdirread(c, a, n, 0, 0, wrengen); - - d = &wren[DRIVE(c->qid.path)]; - if(d->npart == 0) - errors("drive repartitioned"); - p = &d->p[PART(c->qid.path)]; - return wrenio(d, p, 0, a, n, offset); + return wrenio(c, 0, a, n, offset); } long wrenwrite(Chan *c, char *a, long n, ulong offset) +{ + return wrenio(c, 1, a, n, offset); +} + +static long +wrenio(Chan *c, int write, char *a, ulong len, ulong offset) { Drive *d; Partition *p; + Scsibuf *b; + ulong block, n, max, x; d = &wren[DRIVE(c->qid.path)]; if(d->npart == 0) errors("drive repartitioned"); p = &d->p[PART(c->qid.path)]; - return wrenio(d, p, 1, a, n, offset); -} -static long -wrenio(Drive *d, Partition *p, int write, char *a, ulong n, ulong offset) -{ - Scsibuf *b; - ulong block; - - if(n % d->bytes || offset % d->bytes) - errors("io not block aligned"); block = offset / d->bytes + p->start; - if(block >= p->end) - return 0; - if(n > DATASIZE) - n = DATASIZE; - n /= d->bytes; + n = (offset + len + d->bytes - 1) / d->bytes + p->start - block; + max = DATASIZE / d->bytes; + if(n > max) + n = max; if(block + n > p->end) n = p->end - block; - if(n == 0) + if(block >= p->end || n == 0) return 0; b = scsibuf(); if(waserror()){ scsifree(b); nexterror(); } + offset %= d->bytes; if(write){ - memmove(b->virt, a, n*d->bytes); - n = scsibwrite(d->drive, b, n, d->bytes, block); + if(offset || len % d->bytes){ + x = scsibread(d->drive, b, n, d->bytes, block); + if(x < n * d->bytes){ + n = x / d->bytes; + x = n * d->bytes - offset; + if(len > x) + len = x; + } + } + memmove((char*)b->virt + offset, a, len); + x = scsibwrite(d->drive, b, n, d->bytes, block); + if(x < offset) + len = 0; + else if(len > x - offset) + len = x - offset; }else{ - n = scsibread(d->drive, b, n, d->bytes, block); - memmove(a, b->virt, n); + x = scsibread(d->drive, b, n, d->bytes, block); + if(x < offset) + len = 0; + else if(len > x - offset) + len = x - offset; + memmove(a, (char*)b->virt + offset, len); } poperror(); scsifree(b); - return n; + return len; } /*