Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
.\"	@(#)xdr.3n	2.2 88/08/03 4.0 RPCSRC; from 1.16 88/03/14 SMI
.\"	$NetBSD: xdr.3,v 1.14 2011/07/08 19:28:22 wiz Exp $
.\"
.Dd July 4, 2011
.Dt XDR 3
.Os
.Sh NAME
.Nm xdr ,
.Nm xdr_array ,
.Nm xdr_bool ,
.Nm xdr_bytes ,
.Nm xdr_char ,
.Nm xdr_destroy ,
.Nm xdr_double ,
.Nm xdr_enum ,
.Nm xdr_float ,
.Nm xdr_free ,
.Nm xdr_getpos ,
.Nm xdr_hyper ,
.Nm xdr_inline ,
.Nm xdr_int ,
.Nm xdr_long ,
.Nm xdr_longlong_t ,
.Nm xdrmem_create ,
.Nm xdr_opaque ,
.Nm xdr_pointer ,
.Nm xdrrec_create ,
.Nm xdrrec_endofrecord ,
.Nm xdrrec_eof ,
.Nm xdrrec_skiprecord ,
.Nm xdr_reference ,
.Nm xdr_setpos ,
.Nm xdr_short ,
.Nm xdr_sizeof ,
.Nm xdrstdio_create ,
.Nm xdr_string ,
.Nm xdr_u_char ,
.Nm xdr_u_hyper ,
.Nm xdr_u_long ,
.Nm xdr_u_longlong_t ,
.Nm xdr_u_short ,
.Nm xdr_union ,
.Nm xdr_vector ,
.Nm xdr_void ,
.Nm xdr_wrapstring
.Nd library routines for external data representation
.Sh SYNOPSIS
.Ft int
.Fn xdr_array "XDR *xdrs" "char **arrp" "u_int *sizep" "u_int maxsize" \
"u_int elsize" "xdrproc_t elproc"
.Ft int
.Fn xdr_bool "XDR *xdrs" "bool_t *bp"
.Ft int
.Fn xdr_bytes "XDR *xdrs" "char **sp" "u_int *sizep" "u_int maxsize"
.Ft int
.Fn xdr_char "XDR *xdrs" "char *cp"
.Ft void
.Fn xdr_destroy "XDR *xdrs"
.Ft int
.Fn xdr_double "XDR *xdrs" "double *dp"
.Ft int
.Fn xdr_enum "XDR *xdrs" "enum_t *ep"
.Ft int
.Fn xdr_float "XDR *xdrs" "float *fp"
.Ft void
.Fn xdr_free "xdrproc_t proc" "char *objp"
.Ft u_int
.Fn xdr_getpos "XDR *xdrs"
.Ft int
.Fn xdr_hyper "XDR *xdrs" "longlong_t *llp"
.Ft long *
.Fn xdr_inline "XDR *xdrs" "int len"
.Ft int
.Fn xdr_int "XDR *xdrs" "int *ip"
.Ft int
.Fn xdr_long "XDR *xdrs" "long *lp"
.Ft int
.Fn xdr_longlong_t "XDR *xdrs" "longlong_t *llp"
.Ft void
.Fn xdrmem_create "XDR *xdrs" "char *addr" "u_int size" \
"enum xdr_op op"
.Ft int
.Fn xdr_opaque "XDR *xdrs" "char *cp" "u_int cnt"
.Ft int
.Fn xdr_pointer "XDR *xdrs" "char **objpp" "u_int objsize" \
"xdrproc_t xdrobj"
.Ft void
.Fn xdrrec_create "XDR *xdrs" "u_int sendsize" "u_int recvsize" \
"char *handle" "int (*readit)()" "int (*writeit)()"
.Ft int
.Fn xdrrec_endofrecord "XDR *xdrs" "int sendnow"
.Ft int
.Fn xdrrec_eof "XDR *xdrs"
.Ft int
.Fn xdrrec_skiprecord "XDR *xdrs"
.Ft int
.Fn xdr_reference "XDR *xdrs" "char **pp" "u_int size" \
"xdrproc_t proc"
.Ft int
.Fn xdr_setpos "XDR *xdrs" "u_int pos"
.Ft int
.Fn xdr_short "XDR *xdrs" "short *sp"
.Ft nsigned long
.Fn xdr_sizeof "xdrproc_t func" "void *data"
.Ft void
.Fn xdrstdio_create "XDR *xdrs" "FILE *file" "enum xdr_op op"
.Ft int
.Fn xdr_string "XDR *xdrs" "char **sp" "u_int maxsize"
.Ft int
.Fn xdr_u_char "XDR *xdrs" "unsigned char *ucp"
.Ft int
.Fn xdr_u_hyper "XDR *xdrs" "u_longlong_t *ullp"
.Ft int
.Fn xdr_u_int "XDR *xdrs" "unsigned *up"
.Ft int
.Fn xdr_u_long "XDR *xdrs" "unsigned long *ulp"
.Ft int
.Fn xdr_u_longlong_t "XDR *xdrs" "u_longlong_t *ullp"
.Ft int
.Fn xdr_u_short "XDR *xdrs" "unsigned short *usp"
.Ft int
.Fn xdr_union "XDR *xdrs" "int *dscmp" "char *unp" \
"struct xdr_discrim *choices" "bool_t (*defaultarm)(\|)"
.Ft int
.Fn xdr_vector "XDR *xdrs" "char *arrp" "u_int size" \
"u_int elsize" "xdrproc_t elproc"
.Ft int
.Fn xdr_void "void"
.Ft int
.Fn xdr_wrapstring "XDR *xdrs" "char **sp"
.Sh DESCRIPTION
These routines allow C programmers to describe
arbitrary data structures in a machine-independent fashion.
Data for remote procedure calls are transmitted using these
routines.
.Bl -tag -width xxx
.It Fn xdr_array
A filter primitive that translates between variable-length
arrays and their corresponding external representations.
The parameter
.Fa arrp
is the address of the pointer to the array, while
.Fa sizep
is the address of the element count of the array;
this element count cannot exceed
.Fa maxsize .
The parameter
.Fa elsize
is the
.Em sizeof
each of the array's elements, and
.Fa elproc
is an XDR filter that translates between the array elements' C form,
and their external representation.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_bool
A filter primitive that translates between booleans (C integers)
and their external representations.
When encoding data, this filter produces values of either one or
zero.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_bytes
A filter primitive that translates between counted byte
strings and their external representations.
The parameter
.Fa sp
is the address of the string pointer.
The length of the string is located at address
.Fa sizep ;
strings cannot be longer than
.Fa maxsize .
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_char
A filter primitive that translates between C characters
and their external representations.
This routine returns one if it succeeds, zero otherwise.
Note: encoded characters are not packed, and occupy 4 bytes each.
For arrays of characters, it is worthwhile to consider
.Fn xdr_bytes ,
.Fn xdr_opaque
or
.Fn xdr_string .
.It Fn xdr_destroy
A macro that invokes the destroy routine associated with the XDR
stream,
.Fa xdrs .
Destruction usually involves freeing private data structures
associated with the stream.
Using
.Fa xdrs
after invoking
.Fn xdr_destroy
is undefined.
.It Fn xdr_double
A filter primitive that translates between C double precision numbers
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_enum
A filter primitive that translates between C enums (actually integers)
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_float
A filter primitive that translates between C floats
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_free
Generic freeing routine.
The first argument is the XDR routine for the object being freed.
The second argument is a pointer to the object itself.
Note: the pointer passed to this routine is
.Em not
freed, but what it points to
.Em is
freed (recursively).
.It Fn xdr_getpos
A macro that invokes the get-position routine associated with the XDR
stream,
.Fa xdrs .
The routine returns an unsigned integer, which indicates the position
of the XDR byte stream.
A desirable feature of XDR streams is that simple arithmetic works
with this number, although the XDR stream instances need not guarantee
this.
.It Fn xdr_hyper
A filter primitive that translates between ANSI C long long integers
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_inline
A macro that invokes the in-line routine associated with the XDR
stream,
.Fa xdrs .
The routine returns a pointer
to a contiguous piece of the stream's buffer;
.Fa len
is the byte length of the desired buffer.
Note: pointer is cast to
.Vt "long *" .
.Pp
Warning:
.Fn xdr_inline
may return
.Dv NULL
if it cannot allocate a contiguous piece of a buffer.
Therefore the behavior may vary among stream instances;
it exists for the sake of efficiency.
.It Fn xdr_int
A filter primitive that translates between C integers
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_long
A filter primitive that translates between C long integers
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_longlong_t
A filter primitive that translates between ANSI C long long integers
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdrmem_create
This routine initializes the XDR stream object pointed to by
.Fa xdrs .
The stream's data is written to, or read from,
a chunk of memory at location
.Fa addr
whose length is no more than
.Fa size
bytes long.
The
.Fa op
determines the direction of the XDR stream (either
.Dv XDR_ENCODE ,
.Dv XDR_DECODE ,
or
.Dv XDR_FREE ) .
.It Fn xdr_opaque
A filter primitive that translates between fixed size opaque data
and its external representation.
The parameter
.Fa cp
is the address of the opaque object, and
.Fa cnt
is its size in bytes.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_pointer
Like
.Fn xdr_reference
except that it serializes
.Dv NULL
pointers, whereas
.Fn xdr_reference
does not.
Thus,
.Fn xdr_pointer
can represent recursive data structures, such as binary trees or
linked lists.
.It Fn xdrrec_create
This routine initializes the XDR stream object pointed to by
.Fa xdrs .
The stream's data is written to a buffer of size
.Fa sendsize ;
a value of zero indicates the system should use a suitable default.
The stream's data is read from a buffer of size
.Fa recvsize ;
it too can be set to a suitable default by passing a zero value.
When a stream's output buffer is full,
.Fa writeit
is called.
Similarly, when a stream's input buffer is empty,
.Fa readit
is called.
The behavior of these two routines is similar to the system calls
.Xr read 2
and
.Xr write 2 ,
except that
.Fa handle
is passed to the former routines as the first parameter.
Note: the XDR stream's
.Fa op
field must be set by the caller.
.Pp
Warning: this XDR stream implements an intermediate record stream.
Therefore there are additional bytes in the stream
to provide record boundary information.
.It Fn xdrrec_endofrecord
This routine can be invoked only on streams created by
.Fn xdrrec_create .
The data in the output buffer is marked as a completed record,
and the output buffer is optionally written out if
.Fa sendnow
is non-zero.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdrrec_eof
This routine can be invoked only on streams created by
.Fn xdrrec_create .
After consuming the rest of the current record in the stream,
this routine returns one if the stream has no more input,
zero otherwise.
.It Fn xdrrec_skiprecord
This routine can be invoked only on streams created by
.Fn xdrrec_create .
It tells the XDR implementation that the rest of the current record
in the stream's input buffer should be discarded.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_reference
A primitive that provides pointer chasing within structures.
The parameter
.Fa pp
is the address of the pointer;
.Fa size
is the
.Em sizeof
the structure that
.Fa *pp
points to; and
.Fa proc
is an XDR procedure that filters the structure
between its C form and its external representation.
This routine returns one if it succeeds, zero otherwise.
.Pp
Warning: this routine does not understand
.Dv NULL
pointers.
Use
.Fn xdr_pointer
instead.
.It Fn xdr_setpos
A macro that invokes the set position routine associated with the XDR
stream
.Fa xdrs .
The parameter
.Fa pos
is a position value obtained from
.Fn xdr_getpos .
This routine returns one if the XDR stream could be repositioned,
and zero otherwise.
.Pp
Warning: it is difficult to reposition some types of XDR streams, so
this routine may fail with one type of stream and succeed with
another.
.It Fn xdr_short
A filter primitive that translates between C short integers
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_sizeof
This routine returns the amount of memory required to encode
.Fa data
using filter
.Fa func .
.It Fn xdrstdio_create
This routine initializes the XDR stream object pointed to by
.Fa xdrs .
The XDR stream data is written to, or read from, the Standard I/O
stream
.Fa file .
The parameter
.Fa op
determines the direction of the XDR stream (either
.Dv XDR_ENCODE ,
.Dv XDR_DECODE ,
or
.Dv XDR_FREE ) .
.Pp
Warning: the destroy routine associated with such XDR streams calls
.Xr fflush 3
on the file stream, but never
.Xr fclose 3 .
.It Fn xdr_string
A filter primitive that translates between C strings and
their corresponding external representations.
Strings cannot be longer than
.Fa maxsize .
Note:
.Fa sp
is the address of the string's pointer.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_u_char
A filter primitive that translates between unsigned C characters
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_u_hyper
A filter primitive that translates between unsigned ANSI C long long
integers and their external representations.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_u_int
A filter primitive that translates between C unsigned integers
 and their external representations.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_u_long
A filter primitive that translates between C unsigned long integers
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_u_longlong_t
A filter primitive that translates between unsigned ANSI C long long
integers and their external representations.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_u_short
A filter primitive that translates between C unsigned short integers
and their external representations.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_union
A filter primitive that translates between a discriminated C union
and its corresponding external representation.
It first translates the discriminant of the union located at
.Fa dscmp .
This discriminant is always an enum_t.
Next the union located at
.Fa unp
is translated.
The parameter
.Fa choices
is a pointer to an array of
.Fn xdr_discrim
structures.
Each structure contains an ordered pair of
.Fa [ value ,
.Fa proc ] .
If the union's discriminant is equal to the associated
.Fa value ,
then the
.Fa proc
is called to translate the union.
The end of the
.Fn xdr_discrim
structure array is denoted by a routine of value
.Dv NULL .
If the discriminant is not found in the
.Fa choices
array, then the
.Fa defaultarm
procedure is called (if it is not
.Dv NULL ) .
Returns one if it succeeds, zero otherwise.
.It Fn xdr_vector
A filter primitive that translates between fixed-length
arrays and their corresponding external representations.
The parameter
.Fa arrp
is the address of the pointer to the array, while
.Fa size
is the element count of the array.
The parameter
.Fa elsize
is the
.Em sizeof
each of the array's elements, and
.Fa elproc
is an XDR filter that translates between the array elements' C form,
and their external representation.
This routine returns one if it succeeds, zero otherwise.
.It Fn xdr_void
This routine always returns one.
It may be passed to RPC routines that require a function parameter,
where nothing is to be done.
.It Fn xdr_wrapstring
A primitive that calls
.Fn xdr_string "xdrs" "sp" "MAXUN.UNSIGNED" ;
where
.Dv MAXUN.UNSIGNED
is the maximum value of an unsigned integer.
.Fn xdr_wrapstring
is handy because the RPC package passes a maximum of two XDR
routines as parameters, and
.Fn xdr_string ,
one of the most frequently used primitives, requires three.
Returns one if it succeeds, zero otherwise.
.El
.Sh SEE ALSO
.Xr rpc 3
.Pp
The following manuals:
.Rs
.%B "eXternal Data Representation Standard: Protocol Specification"
.Re
.Rs
.%B "eXternal Data Representation: Sun Technical Notes"
.Re
.Rs
.%A Sun Microsystems, Inc., USC-ISI
.%T "XDR: External Data Representation Standard"
.%R "RFC 1014, USC-ISI"
.%V 1014
.Re