vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

convM2D.c (1418B)


      1 #include "u.h"
      2 #include "lib.h"
      3 #include "fcall.h"
      4 
      5 int
      6 statcheck(uchar *buf, uint nbuf)
      7 {
      8 	uchar *ebuf;
      9 	int i;
     10 
     11 	ebuf = buf + nbuf;
     12 
     13 	if(nbuf < STATFIXLEN || nbuf != BIT16SZ + GBIT16(buf))
     14 		return -1;
     15 
     16 	buf += STATFIXLEN - 4 * BIT16SZ;
     17 
     18 	for(i = 0; i < 4; i++){
     19 		if(buf + BIT16SZ > ebuf)
     20 			return -1;
     21 		buf += BIT16SZ + GBIT16(buf);
     22 	}
     23 
     24 	if(buf != ebuf)
     25 		return -1;
     26 
     27 	return 0;
     28 }
     29 
     30 static char nullstring[] = "";
     31 
     32 uint
     33 convM2D(uchar *buf, uint nbuf, Dir *d, char *strs)
     34 {
     35 	uchar *p, *ebuf;
     36 	char *sv[4];
     37 	int i, ns;
     38 
     39 	if(nbuf < STATFIXLEN)
     40 		return 0; 
     41 
     42 	p = buf;
     43 	ebuf = buf + nbuf;
     44 
     45 	p += BIT16SZ;	/* ignore size */
     46 	d->type = GBIT16(p);
     47 	p += BIT16SZ;
     48 	d->dev = GBIT32(p);
     49 	p += BIT32SZ;
     50 	d->qid.type = GBIT8(p);
     51 	p += BIT8SZ;
     52 	d->qid.vers = GBIT32(p);
     53 	p += BIT32SZ;
     54 	d->qid.path = GBIT64(p);
     55 	p += BIT64SZ;
     56 	d->mode = GBIT32(p);
     57 	p += BIT32SZ;
     58 	d->atime = GBIT32(p);
     59 	p += BIT32SZ;
     60 	d->mtime = GBIT32(p);
     61 	p += BIT32SZ;
     62 	d->length = GBIT64(p);
     63 	p += BIT64SZ;
     64 
     65 	for(i = 0; i < 4; i++){
     66 		if(p + BIT16SZ > ebuf)
     67 			return 0;
     68 		ns = GBIT16(p);
     69 		p += BIT16SZ;
     70 		if(p + ns > ebuf)
     71 			return 0;
     72 		if(strs){
     73 			sv[i] = strs;
     74 			memmove(strs, p, ns);
     75 			strs += ns;
     76 			*strs++ = '\0';
     77 		}
     78 		p += ns;
     79 	}
     80 
     81 	if(strs){
     82 		d->name = sv[0];
     83 		d->uid = sv[1];
     84 		d->gid = sv[2];
     85 		d->muid = sv[3];
     86 	}else{
     87 		d->name = nullstring;
     88 		d->uid = nullstring;
     89 		d->gid = nullstring;
     90 		d->muid = nullstring;
     91 	}
     92 	
     93 	return p - buf;
     94 }