Add 9P2000.u functions.

This commit is contained in:
rsc 2005-09-13 01:37:14 +00:00
parent b7eed2e0e1
commit fb941e08c5
4 changed files with 120 additions and 22 deletions

View file

@ -3,30 +3,44 @@
#include <fcall.h> #include <fcall.h>
uint uint
sizeD2M(Dir *d) sizeD2Mu(Dir *d, int dotu)
{ {
char *sv[4]; char *sv[5];
int i, ns; int i, ns, nstr, fixlen;
sv[0] = d->name; sv[0] = d->name;
sv[1] = d->uid; sv[1] = d->uid;
sv[2] = d->gid; sv[2] = d->gid;
sv[3] = d->muid; sv[3] = d->muid;
fixlen = STATFIXLEN;
nstr = 4;
if(dotu){
fixlen = STATFIXLENU;
sv[4] = d->ext;
nstr = 5;
}
ns = 0; ns = 0;
for(i = 0; i < 4; i++) for(i = 0; i < nstr; i++)
if(sv[i]) if(sv[i])
ns += strlen(sv[i]); ns += strlen(sv[i]);
return STATFIXLEN + ns; return fixlen + ns;
} }
uint uint
convD2M(Dir *d, uchar *buf, uint nbuf) sizeD2M(Dir *d)
{
return sizeD2Mu(d, 0);
}
uint
convD2Mu(Dir *d, uchar *buf, uint nbuf, int dotu)
{ {
uchar *p, *ebuf; uchar *p, *ebuf;
char *sv[4]; char *sv[5];
int i, ns, nsv[4], ss; int i, ns, nsv[4], ss, nstr, fixlen;
if(nbuf < BIT16SZ) if(nbuf < BIT16SZ)
return 0; return 0;
@ -39,8 +53,16 @@ convD2M(Dir *d, uchar *buf, uint nbuf)
sv[2] = d->gid; sv[2] = d->gid;
sv[3] = d->muid; sv[3] = d->muid;
fixlen = STATFIXLEN;
nstr = 4;
if(dotu){
fixlen = STATFIXLENU;
sv[4] = d->ext;
nstr = 5;
}
ns = 0; ns = 0;
for(i = 0; i < 4; i++){ for(i = 0; i < nstr; i++){
if(sv[i]) if(sv[i])
nsv[i] = strlen(sv[i]); nsv[i] = strlen(sv[i]);
else else
@ -48,7 +70,7 @@ convD2M(Dir *d, uchar *buf, uint nbuf)
ns += nsv[i]; ns += nsv[i];
} }
ss = STATFIXLEN + ns; ss = fixlen + ns;
/* set size befor erroring, so user can know how much is needed */ /* set size befor erroring, so user can know how much is needed */
/* note that length excludes count field itself */ /* note that length excludes count field itself */
@ -77,7 +99,7 @@ convD2M(Dir *d, uchar *buf, uint nbuf)
PBIT64(p, d->length); PBIT64(p, d->length);
p += BIT64SZ; p += BIT64SZ;
for(i = 0; i < 4; i++){ for(i = 0; i < nstr; i++){
ns = nsv[i]; ns = nsv[i];
if(p + ns + BIT16SZ > ebuf) if(p + ns + BIT16SZ > ebuf)
return 0; return 0;
@ -87,9 +109,24 @@ convD2M(Dir *d, uchar *buf, uint nbuf)
memmove(p, sv[i], ns); memmove(p, sv[i], ns);
p += ns; p += ns;
} }
if(dotu){
PBIT32(p, d->uidnum);
p += BIT32SZ;
PBIT32(p, d->gidnum);
p += BIT32SZ;
PBIT32(p, d->muidnum);
p += BIT32SZ;
}
if(ss != p - buf) if(ss != p - buf)
return 0; return 0;
return p - buf; return p - buf;
} }
uint
convD2M(Dir *d, uchar *buf, uint nbuf)
{
return convD2Mu(d, buf, nbuf, 0);
}

View file

@ -3,10 +3,10 @@
#include <fcall.h> #include <fcall.h>
int int
statcheck(uchar *buf, uint nbuf) statchecku(uchar *buf, uint nbuf, int dotu)
{ {
uchar *ebuf; uchar *ebuf;
int i; int i, nstr;
ebuf = buf + nbuf; ebuf = buf + nbuf;
@ -15,12 +15,18 @@ statcheck(uchar *buf, uint nbuf)
buf += STATFIXLEN - 4 * BIT16SZ; buf += STATFIXLEN - 4 * BIT16SZ;
for(i = 0; i < 4; i++){ nstr = 4;
if(dotu)
nstr = 5;
for(i = 0; i < nstr; i++){
if(buf + BIT16SZ > ebuf) if(buf + BIT16SZ > ebuf)
return -1; return -1;
buf += BIT16SZ + GBIT16(buf); buf += BIT16SZ + GBIT16(buf);
} }
if(dotu)
buf += 3*BIT32SZ;
if(buf != ebuf) if(buf != ebuf)
return -1; return -1;
@ -30,11 +36,11 @@ statcheck(uchar *buf, uint nbuf)
static char nullstring[] = ""; static char nullstring[] = "";
uint uint
convM2D(uchar *buf, uint nbuf, Dir *d, char *strs) convM2Du(uchar *buf, uint nbuf, Dir *d, char *strs, int dotu)
{ {
uchar *p, *ebuf; uchar *p, *ebuf;
char *sv[4]; char *sv[5];
int i, ns; int i, ns, nstr;
if(nbuf < STATFIXLEN) if(nbuf < STATFIXLEN)
return 0; return 0;
@ -62,7 +68,10 @@ convM2D(uchar *buf, uint nbuf, Dir *d, char *strs)
d->length = GBIT64(p); d->length = GBIT64(p);
p += BIT64SZ; p += BIT64SZ;
for(i = 0; i < 4; i++){ nstr = 4;
if(dotu)
nstr = 5;
for(i = 0; i < nstr; i++){
if(p + BIT16SZ > ebuf) if(p + BIT16SZ > ebuf)
return 0; return 0;
ns = GBIT16(p); ns = GBIT16(p);
@ -78,17 +87,38 @@ convM2D(uchar *buf, uint nbuf, Dir *d, char *strs)
p += ns; p += ns;
} }
if(dotu){
if(p + BIT32SZ*3 > ebuf)
return 0;
d->uidnum = GBIT32(p);
p += BIT32SZ;
d->gidnum = GBIT32(p);
p += BIT32SZ;
d->muidnum = GBIT32(p);
p += BIT32SZ;
}
if(strs){ if(strs){
d->name = sv[0]; d->name = sv[0];
d->uid = sv[1]; d->uid = sv[1];
d->gid = sv[2]; d->gid = sv[2];
d->muid = sv[3]; d->muid = sv[3];
d->ext = nullstring;
if(dotu)
d->ext = sv[4];
}else{ }else{
d->name = nullstring; d->name = nullstring;
d->uid = nullstring; d->uid = nullstring;
d->gid = nullstring; d->gid = nullstring;
d->muid = nullstring; d->muid = nullstring;
d->ext = nullstring;
} }
return p - buf; return p - buf;
} }
uint
convM2D(uchar *buf, uint nbuf, Dir *d, char *strs)
{
return convM2Du(buf, nbuf, d, strs, 0);
}

View file

@ -48,7 +48,7 @@ gqid(uchar *p, uchar *ep, Qid *q)
* to test at end of routine. * to test at end of routine.
*/ */
uint uint
convM2S(uchar *ap, uint nap, Fcall *f) convM2Su(uchar *ap, uint nap, Fcall *f, int dotu)
{ {
uchar *p, *ep; uchar *p, *ep;
uint i, size; uint i, size;
@ -229,6 +229,13 @@ convM2S(uchar *ap, uint nap, Fcall *f)
case Rerror: case Rerror:
p = gstring(p, ep, &f->ename); p = gstring(p, ep, &f->ename);
f->errornum = 0;
if(dotu){
if(p+BIT16SZ > ep)
return 0;
f->errornum = GBIT16(p);
p += BIT16SZ;
}
break; break;
case Rflush: case Rflush:
@ -321,3 +328,9 @@ convM2S(uchar *ap, uint nap, Fcall *f)
return size; return size;
return 0; return 0;
} }
uint
convM2S(uchar *ap, uint nap, Fcall *f)
{
return convM2Su(ap, nap, f, 0);
}

View file

@ -46,7 +46,7 @@ stringsz(char *s)
} }
uint uint
sizeS2M(Fcall *f) sizeS2Mu(Fcall *f, int dotu)
{ {
uint n; uint n;
int i; int i;
@ -141,6 +141,8 @@ sizeS2M(Fcall *f)
case Rerror: case Rerror:
n += stringsz(f->ename); n += stringsz(f->ename);
if(dotu)
n += BIT16SZ;
break; break;
case Rflush: case Rflush:
@ -198,7 +200,13 @@ sizeS2M(Fcall *f)
} }
uint uint
convS2M(Fcall *f, uchar *ap, uint nap) sizeS2M(Fcall *f)
{
return sizeS2Mu(f, 0);
}
uint
convS2Mu(Fcall *f, uchar *ap, uint nap, int dotu)
{ {
uchar *p; uchar *p;
uint i, size; uint i, size;
@ -331,6 +339,10 @@ convS2M(Fcall *f, uchar *ap, uint nap)
case Rerror: case Rerror:
p = pstring(p, f->ename); p = pstring(p, f->ename);
if(dotu){
PBIT16(p, f->errornum);
p += BIT16SZ;
}
break; break;
case Rflush: case Rflush:
@ -397,3 +409,9 @@ convS2M(Fcall *f, uchar *ap, uint nap)
return 0; return 0;
return size; return size;
} }
uint
convS2M(Fcall *f, uchar *ap, uint nap)
{
return convS2Mu(f, ap, nap, 0);
}