plan9port/src/lib9/convM2D.c

131 lines
1.9 KiB
C
Raw Normal View History

2003-12-06 18:08:52 +00:00
#include <u.h>
#include <libc.h>
#include <fcall.h>
int
2005-09-13 01:37:14 +00:00
statchecku(uchar *buf, uint nbuf, int dotu)
2003-12-06 18:08:52 +00:00
{
uchar *ebuf;
2005-09-13 01:37:14 +00:00
int i, nstr;
2003-12-06 18:08:52 +00:00
ebuf = buf + nbuf;
if(nbuf < STATFIXLEN || nbuf != BIT16SZ + GBIT16(buf))
return -1;
buf += STATFIXLEN - 4 * BIT16SZ;
2005-09-13 01:37:14 +00:00
nstr = 4;
if(dotu)
nstr = 5;
for(i = 0; i < nstr; i++){
2003-12-06 18:08:52 +00:00
if(buf + BIT16SZ > ebuf)
return -1;
buf += BIT16SZ + GBIT16(buf);
}
2005-09-13 01:37:14 +00:00
if(dotu)
buf += 3*BIT32SZ;
2003-12-06 18:08:52 +00:00
if(buf != ebuf)
return -1;
return 0;
}
2005-09-13 02:40:46 +00:00
int
statcheck(uchar *buf, uint nbuf)
{
return statchecku(buf, nbuf, 0);
}
2003-12-06 18:08:52 +00:00
static char nullstring[] = "";
uint
2005-09-13 01:37:14 +00:00
convM2Du(uchar *buf, uint nbuf, Dir *d, char *strs, int dotu)
2003-12-06 18:08:52 +00:00
{
uchar *p, *ebuf;
2005-09-13 01:37:14 +00:00
char *sv[5];
int i, ns, nstr;
2003-12-06 18:08:52 +00:00
if(nbuf < STATFIXLEN)
return 0;
p = buf;
ebuf = buf + nbuf;
p += BIT16SZ; /* ignore size */
d->type = GBIT16(p);
p += BIT16SZ;
d->dev = GBIT32(p);
p += BIT32SZ;
d->qid.type = GBIT8(p);
p += BIT8SZ;
d->qid.vers = GBIT32(p);
p += BIT32SZ;
d->qid.path = GBIT64(p);
p += BIT64SZ;
d->mode = GBIT32(p);
p += BIT32SZ;
d->atime = GBIT32(p);
p += BIT32SZ;
d->mtime = GBIT32(p);
p += BIT32SZ;
d->length = GBIT64(p);
p += BIT64SZ;
2005-09-13 01:37:14 +00:00
nstr = 4;
if(dotu)
nstr = 5;
for(i = 0; i < nstr; i++){
2003-12-06 18:08:52 +00:00
if(p + BIT16SZ > ebuf)
return 0;
ns = GBIT16(p);
p += BIT16SZ;
if(p + ns > ebuf)
return 0;
if(strs){
sv[i] = strs;
memmove(strs, p, ns);
strs += ns;
*strs++ = '\0';
}
p += ns;
}
2005-09-13 01:37:14 +00:00
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;
}
2003-12-06 18:08:52 +00:00
if(strs){
d->name = sv[0];
d->uid = sv[1];
d->gid = sv[2];
d->muid = sv[3];
2005-09-13 01:37:14 +00:00
d->ext = nullstring;
if(dotu)
d->ext = sv[4];
2003-12-06 18:08:52 +00:00
}else{
d->name = nullstring;
d->uid = nullstring;
d->gid = nullstring;
d->muid = nullstring;
2005-09-13 01:37:14 +00:00
d->ext = nullstring;
2003-12-06 18:08:52 +00:00
}
return p - buf;
}
2005-09-13 01:37:14 +00:00
uint
convM2D(uchar *buf, uint nbuf, Dir *d, char *strs)
{
return convM2Du(buf, nbuf, d, strs, 0);
}