]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libsunrpc/portmap.c
sdiahci, sdodin: avoid calling kproc() while holding ilock()
[plan9front.git] / sys / src / libsunrpc / portmap.c
1 #include <u.h>
2 #include <libc.h>
3 #include <thread.h>
4 #include <sunrpc.h>
5
6 static void
7 portMapPrint(Fmt *fmt, PortMap *x)
8 {
9         fmtprint(fmt, "[%ud %ud %ud %ud]", x->prog, x->vers, x->prot, x->port);
10 }
11 static uint
12 portMapSize(PortMap *x)
13 {
14         uint a;
15         USED(x);
16         a = 0 + 4 + 4 + 4 + 4;
17         return a;
18 }
19 static int
20 portMapPack(uchar *a, uchar *ea, uchar **pa, PortMap *x)
21 {
22         if(sunUint32Pack(a, ea, &a, &x->prog) < 0) goto Err;
23         if(sunUint32Pack(a, ea, &a, &x->vers) < 0) goto Err;
24         if(sunUint32Pack(a, ea, &a, &x->prot) < 0) goto Err;
25         if(sunUint32Pack(a, ea, &a, &x->port) < 0) goto Err;
26         *pa = a;
27         return 0;
28 Err:
29         *pa = ea;
30         return -1;
31 }
32 static int
33 portMapUnpack(uchar *a, uchar *ea, uchar **pa, PortMap *x)
34 {
35         if(sunUint32Unpack(a, ea, &a, &x->prog) < 0) goto Err;
36         if(sunUint32Unpack(a, ea, &a, &x->vers) < 0) goto Err;
37         if(sunUint32Unpack(a, ea, &a, &x->prot) < 0) goto Err;
38         if(sunUint32Unpack(a, ea, &a, &x->port) < 0) goto Err;
39         *pa = a;
40         return 0;
41 Err:
42         *pa = ea;
43         return -1;
44 }
45 static void
46 portTNullPrint(Fmt *fmt, PortTNull *x)
47 {
48         USED(x);
49         fmtprint(fmt, "%s", "PortTNull");
50 }
51 static uint
52 portTNullSize(PortTNull *x)
53 {
54         uint a;
55         USED(x);
56         a = 0;
57         return a;
58 }
59 static int
60 portTNullPack(uchar *a, uchar *ea, uchar **pa, PortTNull *x)
61 {
62         USED(ea);
63         USED(x);
64         *pa = a;
65         return 0;
66 }
67 static int
68 portTNullUnpack(uchar *a, uchar *ea, uchar **pa, PortTNull *x)
69 {
70         USED(ea);
71         USED(x);
72         *pa = a;
73         return 0;
74 }
75 static void
76 portRNullPrint(Fmt *fmt, PortRNull *x)
77 {
78         USED(x);
79         fmtprint(fmt, "%s", "PortRNull");
80 }
81 static uint
82 portRNullSize(PortRNull *x)
83 {
84         uint a;
85         USED(x);
86         a = 0;
87         return a;
88 }
89 static int
90 portRNullPack(uchar *a, uchar *ea, uchar **pa, PortRNull *x)
91 {
92         USED(ea);
93         USED(x);
94         *pa = a;
95         return 0;
96 }
97 static int
98 portRNullUnpack(uchar *a, uchar *ea, uchar **pa, PortRNull *x)
99 {
100         USED(ea);
101         USED(x);
102         *pa = a;
103         return 0;
104 }
105 static void
106 portTSetPrint(Fmt *fmt, PortTSet *x)
107 {
108         fmtprint(fmt, "PortTSet ");
109         portMapPrint(fmt, &x->map);
110 }
111 static uint
112 portTSetSize(PortTSet *x)
113 {
114         uint a;
115         USED(x);
116         a = 0 + portMapSize(&x->map);
117         return a;
118 }
119 static int
120 portTSetPack(uchar *a, uchar *ea, uchar **pa, PortTSet *x)
121 {
122         if(portMapPack(a, ea, &a, &x->map) < 0) goto Err;
123         *pa = a;
124         return 0;
125 Err:
126         *pa = ea;
127         return -1;
128 }
129 static int
130 portTSetUnpack(uchar *a, uchar *ea, uchar **pa, PortTSet *x)
131 {
132         if(portMapUnpack(a, ea, &a, &x->map) < 0) goto Err;
133         *pa = a;
134         return 0;
135 Err:
136         *pa = ea;
137         return -1;
138 }
139 static void
140 portRSetPrint(Fmt *fmt, PortRSet *x)
141 {
142         fmtprint(fmt, "PortRSet %ud", x->b);
143 }
144 static uint
145 portRSetSize(PortRSet *x)
146 {
147         uint a;
148         USED(x);
149         a = 0 + 4;
150         return a;
151 }
152 static int
153 portRSetPack(uchar *a, uchar *ea, uchar **pa, PortRSet *x)
154 {
155         if(sunUint1Pack(a, ea, &a, &x->b) < 0) goto Err;
156         *pa = a;
157         return 0;
158 Err:
159         *pa = ea;
160         return -1;
161 }
162 static int
163 portRSetUnpack(uchar *a, uchar *ea, uchar **pa, PortRSet *x)
164 {
165         if(sunUint1Unpack(a, ea, &a, &x->b) < 0) goto Err;
166         *pa = a;
167         return 0;
168 Err:
169         *pa = ea;
170         return -1;
171 }
172 static void
173 portTUnsetPrint(Fmt *fmt, PortTUnset *x)
174 {
175         fmtprint(fmt, "PortTUnset ");
176         portMapPrint(fmt, &x->map);
177 }
178 static uint
179 portTUnsetSize(PortTUnset *x)
180 {
181         uint a;
182         USED(x);
183         a = 0 + portMapSize(&x->map);
184         return a;
185 }
186 static int
187 portTUnsetPack(uchar *a, uchar *ea, uchar **pa, PortTUnset *x)
188 {
189         if(portMapPack(a, ea, &a, &x->map) < 0) goto Err;
190         *pa = a;
191         return 0;
192 Err:
193         *pa = ea;
194         return -1;
195 }
196 static int
197 portTUnsetUnpack(uchar *a, uchar *ea, uchar **pa, PortTUnset *x)
198 {
199         if(portMapUnpack(a, ea, &a, &x->map) < 0) goto Err;
200         *pa = a;
201         return 0;
202 Err:
203         *pa = ea;
204         return -1;
205 }
206 static void
207 portRUnsetPrint(Fmt *fmt, PortRUnset *x)
208 {
209         fmtprint(fmt, "PortRUnset %ud", x->b);
210 }
211 static uint
212 portRUnsetSize(PortRUnset *x)
213 {
214         uint a;
215         USED(x);
216         a = 0 + 4;
217         return a;
218 }
219 static int
220 portRUnsetPack(uchar *a, uchar *ea, uchar **pa, PortRUnset *x)
221 {
222         if(sunUint1Pack(a, ea, &a, &x->b) < 0) goto Err;
223         *pa = a;
224         return 0;
225 Err:
226         *pa = ea;
227         return -1;
228 }
229 static int
230 portRUnsetUnpack(uchar *a, uchar *ea, uchar **pa, PortRUnset *x)
231 {
232         if(sunUint1Unpack(a, ea, &a, &x->b) < 0) goto Err;
233         *pa = a;
234         return 0;
235 Err:
236         *pa = ea;
237         return -1;
238 }
239 static void
240 portTGetportPrint(Fmt *fmt, PortTGetport *x)
241 {
242         fmtprint(fmt, "PortTGetport ");
243         portMapPrint(fmt, &x->map);
244 }
245 static uint
246 portTGetportSize(PortTGetport *x)
247 {
248         uint a;
249         USED(x);
250         a = 0 + portMapSize(&x->map);
251         return a;
252 }
253 static int
254 portTGetportPack(uchar *a, uchar *ea, uchar **pa, PortTGetport *x)
255 {
256         if(portMapPack(a, ea, &a, &x->map) < 0) goto Err;
257         *pa = a;
258         return 0;
259 Err:
260         *pa = ea;
261         return -1;
262 }
263 static int
264 portTGetportUnpack(uchar *a, uchar *ea, uchar **pa, PortTGetport *x)
265 {
266         if(portMapUnpack(a, ea, &a, &x->map) < 0) goto Err;
267         *pa = a;
268         return 0;
269 Err:
270         *pa = ea;
271         return -1;
272 }
273 static void
274 portRGetportPrint(Fmt *fmt, PortRGetport *x)
275 {
276         fmtprint(fmt, "PortRGetport %ud", x->port);
277 }
278 static uint
279 portRGetportSize(PortRGetport *x)
280 {
281         uint a;
282         USED(x);
283         a = 0 + 4;
284         return a;
285 }
286 static int
287 portRGetportPack(uchar *a, uchar *ea, uchar **pa, PortRGetport *x)
288 {
289         if(sunUint32Pack(a, ea, &a, &x->port) < 0) goto Err;
290         *pa = a;
291         return 0;
292 Err:
293         *pa = ea;
294         return -1;
295 }
296 static int
297 portRGetportUnpack(uchar *a, uchar *ea, uchar **pa, PortRGetport *x)
298 {
299         if(sunUint32Unpack(a, ea, &a, &x->port) < 0) goto Err;
300         *pa = a;
301         return 0;
302 Err:
303         *pa = ea;
304         return -1;
305 }
306 static void
307 portTDumpPrint(Fmt *fmt, PortTDump *x)
308 {
309         USED(x);
310         fmtprint(fmt, "PortTDump");
311 }
312 static uint
313 portTDumpSize(PortTDump *x)
314 {
315         uint a;
316         USED(x);
317         a = 0;
318         return a;
319 }
320 static int
321 portTDumpPack(uchar *a, uchar *ea, uchar **pa, PortTDump *x)
322 {
323         USED(ea);
324         USED(x);
325         *pa = a;
326         return 0;
327 }
328 static int
329 portTDumpUnpack(uchar *a, uchar *ea, uchar **pa, PortTDump *x)
330 {
331         USED(ea);
332         USED(x);
333         *pa = a;
334         return 0;
335 }
336 static void
337 portRDumpPrint(Fmt *fmt, PortRDump *x)
338 {
339         int i;
340
341         fmtprint(fmt, "PortRDump");
342         for(i=0; i<x->nmap; i++){
343                 fmtprint(fmt, " ");
344                 portMapPrint(fmt, &x->map[i]);
345         }
346 }
347 static uint
348 portRDumpSize(PortRDump *x)
349 {
350         return (5*4*x->nmap) + 4;
351 }
352 static int
353 portRDumpPack(uchar *a, uchar *ea, uchar **pa, PortRDump *x)
354 {
355         int i;
356         u32int zero, one;
357
358         zero = 0;
359         one = 1;
360         for(i=0; i<x->nmap; i++){
361                 if(sunUint32Pack(a, ea, &a, &one) < 0
362                 || portMapPack(a, ea, &a, &x->map[i]) < 0)
363                         goto Err;
364         }
365         if(sunUint32Pack(a, ea, &a, &zero) < 0)
366                 goto Err;
367         *pa = a;
368         return 0;
369 Err:
370         *pa = ea;
371         return -1;
372 }
373 static int
374 portRDumpUnpack(uchar *a, uchar *ea, uchar **pa, PortRDump *x)
375 {
376         int i;
377         u1int u1;
378         PortMap *m;
379
380         m = (PortMap*)a;
381         for(i=0;; i++){
382                 if(sunUint1Unpack(a, ea, &a, &u1) < 0)
383                         goto Err;
384                 if(u1 == 0)
385                         break;
386                 if(portMapUnpack(a, ea, &a, &m[i]) < 0)
387                         goto Err;
388         }
389         x->nmap = i;
390         x->map = m;
391         *pa = a;
392         return 0;
393
394 Err:
395         *pa = ea;
396         return -1;
397 }
398 static void
399 portTCallitPrint(Fmt *fmt, PortTCallit *x)
400 {
401         fmtprint(fmt, "PortTCallit [%ud,%ud,%ud] %ud", x->prog, x->vers, x->proc, x->count);
402 }
403 static uint
404 portTCallitSize(PortTCallit *x)
405 {
406         uint a;
407         USED(x);
408         a = 0 + 4 + 4 + 4 + sunVarOpaqueSize(x->count);
409         return a;
410 }
411 static int
412 portTCallitPack(uchar *a, uchar *ea, uchar **pa, PortTCallit *x)
413 {
414         if(sunUint32Pack(a, ea, &a, &x->prog) < 0) goto Err;
415         if(sunUint32Pack(a, ea, &a, &x->vers) < 0) goto Err;
416         if(sunUint32Pack(a, ea, &a, &x->proc) < 0) goto Err;
417         if(sunVarOpaquePack(a, ea, &a, &x->data, &x->count, -1) < 0) goto Err;
418         *pa = a;
419         return 0;
420 Err:
421         *pa = ea;
422         return -1;
423 }
424 static int
425 portTCallitUnpack(uchar *a, uchar *ea, uchar **pa, PortTCallit *x)
426 {
427         if(sunUint32Unpack(a, ea, &a, &x->prog) < 0) goto Err;
428         if(sunUint32Unpack(a, ea, &a, &x->vers) < 0) goto Err;
429         if(sunUint32Unpack(a, ea, &a, &x->proc) < 0) goto Err;
430         if(sunVarOpaqueUnpack(a, ea, &a, &x->data, &x->count, -1) < 0) goto Err;
431         *pa = a;
432         return 0;
433 Err:
434         *pa = ea;
435         return -1;
436 }
437 static void
438 portRCallitPrint(Fmt *fmt, PortRCallit *x)
439 {
440         fmtprint(fmt, "PortRCallit %ud %ud", x->port, x->count);
441 }
442 static uint
443 portRCallitSize(PortRCallit *x)
444 {
445         uint a;
446         USED(x);
447         a = 0 + 4 + sunVarOpaqueSize(x->count);
448         return a;
449 }
450 static int
451 portRCallitPack(uchar *a, uchar *ea, uchar **pa, PortRCallit *x)
452 {
453         if(sunUint32Pack(a, ea, &a, &x->port) < 0) goto Err;
454         if(sunVarOpaquePack(a, ea, &a, &x->data, &x->count, -1) < 0) goto Err;
455         *pa = a;
456         return 0;
457 Err:
458         *pa = ea;
459         return -1;
460 }
461 static int
462 portRCallitUnpack(uchar *a, uchar *ea, uchar **pa, PortRCallit *x)
463 {
464         if(sunUint32Unpack(a, ea, &a, &x->port) < 0) goto Err;
465         if(sunVarOpaqueUnpack(a, ea, &a, &x->data, &x->count, -1) < 0) goto Err;
466         *pa = a;
467         return 0;
468 Err:
469         *pa = ea;
470         return -1;
471 }
472
473 typedef int (*P)(uchar*, uchar*, uchar**, SunCall*);
474 typedef void (*F)(Fmt*, SunCall*);
475 typedef uint (*S)(SunCall*);
476
477 static SunProc proc[] = {
478         (P)portTNullPack, (P)portTNullUnpack, (S)portTNullSize, (F)portTNullPrint, sizeof(PortTNull),
479         (P)portRNullPack, (P)portRNullUnpack, (S)portRNullSize, (F)portRNullPrint, sizeof(PortRNull),
480         (P)portTSetPack, (P)portTSetUnpack, (S)portTSetSize, (F)portTSetPrint, sizeof(PortTSet),
481         (P)portRSetPack, (P)portRSetUnpack, (S)portRSetSize, (F)portRSetPrint, sizeof(PortRSet),
482         (P)portTUnsetPack, (P)portTUnsetUnpack, (S)portTUnsetSize, (F)portTUnsetPrint, sizeof(PortTUnset),
483         (P)portRUnsetPack, (P)portRUnsetUnpack, (S)portRUnsetSize, (F)portRUnsetPrint, sizeof(PortRUnset),
484         (P)portTGetportPack, (P)portTGetportUnpack, (S)portTGetportSize, (F)portTGetportPrint, sizeof(PortTGetport),
485         (P)portRGetportPack, (P)portRGetportUnpack, (S)portRGetportSize, (F)portRGetportPrint, sizeof(PortRGetport),
486         (P)portTDumpPack, (P)portTDumpUnpack, (S)portTDumpSize, (F)portTDumpPrint, sizeof(PortTDump),
487         (P)portRDumpPack, (P)portRDumpUnpack, (S)portRDumpSize, (F)portRDumpPrint, sizeof(PortRDump),
488         (P)portTCallitPack, (P)portTCallitUnpack, (S)portTCallitSize, (F)portTCallitPrint, sizeof(PortTCallit),
489         (P)portRCallitPack, (P)portRCallitUnpack, (S)portRCallitSize, (F)portRCallitPrint, sizeof(PortRCallit),
490 };
491
492 SunProg portProg = 
493 {
494         PortProgram,
495         PortVersion,
496         proc,
497         nelem(proc),
498 };