blob: 52d7fad5a594bc57190070fccdcb4742612bad04 [file] [log] [blame]
rscd3df3082003-12-06 18:08:52 +00001#include <u.h>
2#include <libc.h>
3#include <fcall.h>
4
5int
rscfb941e02005-09-13 01:37:14 +00006statchecku(uchar *buf, uint nbuf, int dotu)
rscd3df3082003-12-06 18:08:52 +00007{
8 uchar *ebuf;
rscfb941e02005-09-13 01:37:14 +00009 int i, nstr;
rscd3df3082003-12-06 18:08:52 +000010
11 ebuf = buf + nbuf;
12
13 if(nbuf < STATFIXLEN || nbuf != BIT16SZ + GBIT16(buf))
14 return -1;
15
16 buf += STATFIXLEN - 4 * BIT16SZ;
17
rscfb941e02005-09-13 01:37:14 +000018 nstr = 4;
19 if(dotu)
20 nstr = 5;
21 for(i = 0; i < nstr; i++){
rscd3df3082003-12-06 18:08:52 +000022 if(buf + BIT16SZ > ebuf)
23 return -1;
24 buf += BIT16SZ + GBIT16(buf);
25 }
26
rscfb941e02005-09-13 01:37:14 +000027 if(dotu)
28 buf += 3*BIT32SZ;
29
rscd3df3082003-12-06 18:08:52 +000030 if(buf != ebuf)
31 return -1;
32
33 return 0;
34}
35
rsc3ce03fa2005-09-13 02:40:46 +000036int
37statcheck(uchar *buf, uint nbuf)
38{
39 return statchecku(buf, nbuf, 0);
40}
41
rscd3df3082003-12-06 18:08:52 +000042static char nullstring[] = "";
43
44uint
rscfb941e02005-09-13 01:37:14 +000045convM2Du(uchar *buf, uint nbuf, Dir *d, char *strs, int dotu)
rscd3df3082003-12-06 18:08:52 +000046{
47 uchar *p, *ebuf;
rscfb941e02005-09-13 01:37:14 +000048 char *sv[5];
49 int i, ns, nstr;
rscd3df3082003-12-06 18:08:52 +000050
51 if(nbuf < STATFIXLEN)
52 return 0;
53
54 p = buf;
55 ebuf = buf + nbuf;
56
57 p += BIT16SZ; /* ignore size */
58 d->type = GBIT16(p);
59 p += BIT16SZ;
60 d->dev = GBIT32(p);
61 p += BIT32SZ;
62 d->qid.type = GBIT8(p);
63 p += BIT8SZ;
64 d->qid.vers = GBIT32(p);
65 p += BIT32SZ;
66 d->qid.path = GBIT64(p);
67 p += BIT64SZ;
68 d->mode = GBIT32(p);
69 p += BIT32SZ;
70 d->atime = GBIT32(p);
71 p += BIT32SZ;
72 d->mtime = GBIT32(p);
73 p += BIT32SZ;
74 d->length = GBIT64(p);
75 p += BIT64SZ;
76
rscfb941e02005-09-13 01:37:14 +000077 nstr = 4;
78 if(dotu)
79 nstr = 5;
80 for(i = 0; i < nstr; i++){
rscd3df3082003-12-06 18:08:52 +000081 if(p + BIT16SZ > ebuf)
82 return 0;
83 ns = GBIT16(p);
84 p += BIT16SZ;
85 if(p + ns > ebuf)
86 return 0;
87 if(strs){
88 sv[i] = strs;
89 memmove(strs, p, ns);
90 strs += ns;
91 *strs++ = '\0';
92 }
93 p += ns;
94 }
95
rscfb941e02005-09-13 01:37:14 +000096 if(dotu){
97 if(p + BIT32SZ*3 > ebuf)
98 return 0;
99 d->uidnum = GBIT32(p);
100 p += BIT32SZ;
101 d->gidnum = GBIT32(p);
102 p += BIT32SZ;
103 d->muidnum = GBIT32(p);
104 p += BIT32SZ;
105 }
106
rscd3df3082003-12-06 18:08:52 +0000107 if(strs){
108 d->name = sv[0];
109 d->uid = sv[1];
110 d->gid = sv[2];
111 d->muid = sv[3];
rscfb941e02005-09-13 01:37:14 +0000112 d->ext = nullstring;
113 if(dotu)
114 d->ext = sv[4];
rscd3df3082003-12-06 18:08:52 +0000115 }else{
116 d->name = nullstring;
117 d->uid = nullstring;
118 d->gid = nullstring;
119 d->muid = nullstring;
rscfb941e02005-09-13 01:37:14 +0000120 d->ext = nullstring;
rscd3df3082003-12-06 18:08:52 +0000121 }
122
123 return p - buf;
124}
rscfb941e02005-09-13 01:37:14 +0000125
126uint
127convM2D(uchar *buf, uint nbuf, Dir *d, char *strs)
128{
129 return convM2Du(buf, nbuf, d, strs, 0);
130}