Blob


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