xref: /freebsd/share/man/man9/mdchain.9 (revision f16b3c0de48d0b845357e7cca843f645bc3117e3)
1a1a5ca55SBoris Popov.\" -*- nroff -*-
2a1a5ca55SBoris Popov.\"
3a1a5ca55SBoris Popov.\" Copyright (c) 2001 Boris Popov
4a1a5ca55SBoris Popov.\"
5a1a5ca55SBoris Popov.\" Redistribution and use in source and binary forms, with or without
6a1a5ca55SBoris Popov.\" modification, are permitted provided that the following conditions
7a1a5ca55SBoris Popov.\" are met:
8a1a5ca55SBoris Popov.\" 1. Redistributions of source code must retain the above copyright
9a1a5ca55SBoris Popov.\"    notice, this list of conditions and the following disclaimer.
10a1a5ca55SBoris Popov.\" 2. Redistributions in binary form must reproduce the above copyright
11a1a5ca55SBoris Popov.\"    notice, this list of conditions and the following disclaimer in the
12a1a5ca55SBoris Popov.\"    documentation and/or other materials provided with the distribution.
13a1a5ca55SBoris Popov.\"
14a1a5ca55SBoris Popov.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
15a1a5ca55SBoris Popov.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16a1a5ca55SBoris Popov.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17a1a5ca55SBoris Popov.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
18a1a5ca55SBoris Popov.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19a1a5ca55SBoris Popov.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20a1a5ca55SBoris Popov.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21a1a5ca55SBoris Popov.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22a1a5ca55SBoris Popov.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23a1a5ca55SBoris Popov.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24a1a5ca55SBoris Popov.\"
25a1a5ca55SBoris Popov.\" $FreeBSD$
26a1a5ca55SBoris Popov.\"
27a1a5ca55SBoris Popov.Dd February 28, 2001
28a1a5ca55SBoris Popov.Dt MDCHAIN 9
29a1a5ca55SBoris Popov.Os
30a1a5ca55SBoris Popov.Sh NAME
31a1a5ca55SBoris Popov.Nm mdchain ,
32a1a5ca55SBoris Popov.Nm md_initm ,
33a1a5ca55SBoris Popov.Nm md_done ,
34a1a5ca55SBoris Popov.Nm md_append_record ,
35a1a5ca55SBoris Popov.Nm md_next_record ,
36a1a5ca55SBoris Popov.Nm md_get_uint8 ,
37a1a5ca55SBoris Popov.Nm md_get_uint16 ,
38a1a5ca55SBoris Popov.Nm md_get_uint16be ,
39a1a5ca55SBoris Popov.Nm md_get_uint16le ,
40a1a5ca55SBoris Popov.Nm md_get_uint32 ,
41a1a5ca55SBoris Popov.Nm md_get_uint32be ,
42a1a5ca55SBoris Popov.Nm md_get_uint32le ,
43a1a5ca55SBoris Popov.Nm md_get_int64 ,
44a1a5ca55SBoris Popov.Nm md_get_int64be ,
45a1a5ca55SBoris Popov.Nm md_get_int64le ,
46a1a5ca55SBoris Popov.Nm md_get_mem ,
47a1a5ca55SBoris Popov.Nm md_get_mbuf ,
48a1a5ca55SBoris Popov.Nm md_get_uio
49a1a5ca55SBoris Popov.Nd "set of functions to dissect an mbuf chain to various data types"
50a1a5ca55SBoris Popov.Sh SYNOPSIS
51a1a5ca55SBoris Popov.Cd options LIBMCHAIN
52a1a5ca55SBoris Popov.Li kldload libmchain
53a1a5ca55SBoris Popov.Pp
5432eef9aeSRuslan Ermilov.In sys/param.h
55f16b3c0dSChad David.In sys/uio.h
5632eef9aeSRuslan Ermilov.In sys/mchain.h
57a1a5ca55SBoris Popov.Ft void
58a1a5ca55SBoris Popov.Fn md_initm "struct mdchain *mdp" "struct mbuf *m"
59a1a5ca55SBoris Popov.Ft void
60a1a5ca55SBoris Popov.Fn md_done "struct mdchain *mdp"
61a1a5ca55SBoris Popov.Ft void
62a1a5ca55SBoris Popov.Fn md_append_record "struct mdchain *mdp" "struct mbuf *top"
63a1a5ca55SBoris Popov.Ft int
64a1a5ca55SBoris Popov.Fn md_next_record "struct mdchain *mdp"
65a1a5ca55SBoris Popov.Ft int
66d063f1ebSBruce Evans.Fn md_get_uint8 "struct mdchain *mdp" "u_int8_t *x"
67a1a5ca55SBoris Popov.Ft int
68d063f1ebSBruce Evans.Fn md_get_uint16 "struct mdchain *mdp" "u_int16_t *x"
69a1a5ca55SBoris Popov.Ft int
70d063f1ebSBruce Evans.Fn md_get_uint16be "struct mdchain *mdp" "u_int16_t *x"
71a1a5ca55SBoris Popov.Ft int
72d063f1ebSBruce Evans.Fn md_get_uint16le "struct mdchain *mdp" "u_int16_t *x"
73a1a5ca55SBoris Popov.Ft int
74d063f1ebSBruce Evans.Fn md_get_uint32 "struct mdchain *mdp" "u_int32_t *x"
75a1a5ca55SBoris Popov.Ft int
76d063f1ebSBruce Evans.Fn md_get_uint32be "struct mdchain *mdp" "u_int32_t *x"
77a1a5ca55SBoris Popov.Ft int
78d063f1ebSBruce Evans.Fn md_get_uint32le "struct mdchain *mdp" "u_int32_t *x"
79a1a5ca55SBoris Popov.Ft int
80d063f1ebSBruce Evans.Fn md_get_int64 "struct mdchain *mdp" "int64_t *x"
81a1a5ca55SBoris Popov.Ft int
82d063f1ebSBruce Evans.Fn md_get_int64be "struct mdchain *mdp" "int64_t *x"
83a1a5ca55SBoris Popov.Ft int
84d063f1ebSBruce Evans.Fn md_get_int64le "struct mdchain *mdp" "int64_t *x"
85a1a5ca55SBoris Popov.Ft int
86a1a5ca55SBoris Popov.Fn md_get_mem "struct mdchain *mdp" "caddr_t target" "int size" "int type"
87a1a5ca55SBoris Popov.Ft int
88d063f1ebSBruce Evans.Fn md_get_mbuf "struct mdchain *mdp" "int size" "struct mbuf **m"
89a1a5ca55SBoris Popov.Ft int
90a1a5ca55SBoris Popov.Fn md_get_uio "struct mdchain *mdp" "struct uio *uiop" "int size"
91a1a5ca55SBoris Popov.Sh DESCRIPTION
92a1a5ca55SBoris PopovThese functions are used to decompose mbuf chains to various data types.
93a1a5ca55SBoris PopovThe
94a1a5ca55SBoris Popov.Vt mdchain
95a1a5ca55SBoris Popovstructure is used as a working context
96e95f5612SBoris Popovand should be initialized through a call of the
97a1a5ca55SBoris Popov.Fn mb_initm
98a1a5ca55SBoris Popovfunction.
99a1a5ca55SBoris PopovIt has the following fields:
100a1a5ca55SBoris Popov.Bl -tag -width "md_top"
101a1a5ca55SBoris Popov.It Va "md_top"
102a1a5ca55SBoris Popov.Vt ( "struct mbuf *" )
103a1a5ca55SBoris Popova pointer to the top of the parsed mbuf chain
104a1a5ca55SBoris Popov.It Va md_cur
105a1a5ca55SBoris Popov.Vt ( "struct mbuf *" )
106a1a5ca55SBoris Popova pointer to the currently parsed mbuf
107a1a5ca55SBoris Popov.It Va md_pas
108a1a5ca55SBoris Popov.Vt ( int )
109a1a5ca55SBoris Popovoffset in the current mbuf
110a1a5ca55SBoris Popov.El
111a1a5ca55SBoris Popov.Pp
112a1a5ca55SBoris PopovThe
113a1a5ca55SBoris Popov.Fn md_done
114a1a5ca55SBoris Popovfunction disposes of an mbuf chain pointed to by the
115a1a5ca55SBoris Popov.Fa mdp->md_top
116a1a5ca55SBoris Popovfield and sets the field to
117a1a5ca55SBoris Popov.Dv NULL .
118a1a5ca55SBoris Popov.Pp
119a1a5ca55SBoris PopovThe
120a1a5ca55SBoris Popov.Fn md_append_record
121a1a5ca55SBoris Popovappends a new mbuf chain using
122a1a5ca55SBoris Popov.Va m_nextpkt
123e95f5612SBoris Popovfield to form a single linked list of mbuf chains.
124e95f5612SBoris PopovIf the
12590bd2994SRuslan Ermilov.Fa mdp->md_top
126a1a5ca55SBoris Popovfield is
127a1a5ca55SBoris Popov.Dv NULL ,
128e95f5612SBoris Popovthen this function behaves exactly as the
129a1a5ca55SBoris Popov.Fn md_initm
130a1a5ca55SBoris Popovfunction.
131a1a5ca55SBoris Popov.Pp
132a1a5ca55SBoris PopovThe
133a1a5ca55SBoris Popov.Fn md_next_record
134e95f5612SBoris Popovfunction extracts the next mbuf chain and disposes the current one, if any.
135e95f5612SBoris PopovFor a new mbuf chain it calls the
136a1a5ca55SBoris Popov.Fn md_initm
137a1a5ca55SBoris Popovfunction.
138e95f5612SBoris PopovIf there is no data left the function returns
13990bd2994SRuslan Ermilov.Er ENOENT .
140a1a5ca55SBoris Popov.Pp
141a1a5ca55SBoris PopovAll
142a1a5ca55SBoris Popov.Fn md_get_*
143a1a5ca55SBoris Popovfunctions perform an actual copy of the data from an mbuf chain.
144a1a5ca55SBoris PopovFunctions which have
145a1a5ca55SBoris Popov.Cm le
146a1a5ca55SBoris Popovor
147a1a5ca55SBoris Popov.Cm be
14890bd2994SRuslan Ermilovsuffixes will perform conversion to the little\- or big\-endian data formats.
149a1a5ca55SBoris Popov.Pp
150a1a5ca55SBoris Popov.Fn md_get_mem
151a1a5ca55SBoris Popovfunction copies
152a1a5ca55SBoris Popov.Fa size
153a1a5ca55SBoris Popovbytes of data specified by the
154a1a5ca55SBoris Popov.Fa source
155a1a5ca55SBoris Popovargument from an mbuf chain.
156a1a5ca55SBoris PopovThe
157a1a5ca55SBoris Popov.Fa type
158a1a5ca55SBoris Popovargument specifies the method used to perform a copy,
159a1a5ca55SBoris Popovand can be one of the following:
160a1a5ca55SBoris Popov.Bl -tag -width "MB_MINLINE"
161a1a5ca55SBoris Popov.It Dv MB_MSYSTEM
162e95f5612SBoris PopovUse the
163a1a5ca55SBoris Popov.Fn bcopy
164e95f5612SBoris Popovfunction.
165a1a5ca55SBoris Popov.It Dv MB_MUSER
166e95f5612SBoris PopovUse the
167a1a5ca55SBoris Popov.Xr copyin 9
168e95f5612SBoris Popovfunction.
169a1a5ca55SBoris Popov.It Dv MB_MINLINE
170e95f5612SBoris PopovUse an
171a1a5ca55SBoris Popov.Dq inline
172e95f5612SBoris Popovloop which does not call any function.
173a1a5ca55SBoris Popov.El
174a1a5ca55SBoris Popov.Pp
175a1a5ca55SBoris PopovIf
17690bd2994SRuslan Ermilov.Fa target
177e95f5612SBoris Popovis
178a1a5ca55SBoris Popov.Dv NULL ,
179e95f5612SBoris Popovan actual copy is not performed
180e95f5612SBoris Popovand the function just skips the given number of bytes.
181a1a5ca55SBoris Popov.Sh RETURN VALUES
182a1a5ca55SBoris PopovAll
183a1a5ca55SBoris Popov.Ft int
184a1a5ca55SBoris Popovfunctions return zero if successful,
185a1a5ca55SBoris Popovotherwise an error code is returned.
186a1a5ca55SBoris Popov.Pp
187a1a5ca55SBoris Popov.Em Note :
188a1a5ca55SBoris Popovafter failure of any function,
189e95f5612SBoris Popovan mbuf chain is left in the broken state and only the
190a1a5ca55SBoris Popov.Fn md_done
191a1a5ca55SBoris Popovfunction can safely be called to destroy it.
192a1a5ca55SBoris Popov.Sh EXAMPLES
193a1a5ca55SBoris Popov.Bd -literal
194a1a5ca55SBoris Popovstruct mdchain *mdp;
195a1a5ca55SBoris Popovstruct mbuf *m;
196a1a5ca55SBoris Popovu_int16_t length;
197a1a5ca55SBoris Popovu_int8_t byte;
19890bd2994SRuslan Ermilov
199a1a5ca55SBoris Popovreceive(so, &m);
200a1a5ca55SBoris Popovmd_initm(mdp, m);
201a1a5ca55SBoris Popovif (md_get_uint8(mdp, &byte) != 0 ||
202a1a5ca55SBoris Popov    md_get_uint16le(mdp, &length) != 0)
203a1a5ca55SBoris Popov	error = EBADRPC;
204a1a5ca55SBoris Popovmb_done(mdp);
205a1a5ca55SBoris Popov.Ed
206a1a5ca55SBoris Popov.Sh SEE ALSO
2075521ff5aSRuslan Ermilov.Xr mbchain 9 ,
2085521ff5aSRuslan Ermilov.Xr mbuf 9
209a1a5ca55SBoris Popov.Sh AUTHORS
210a1a5ca55SBoris PopovThis manual page was written by
211a1a5ca55SBoris Popov.An Boris Popov Aq bp@FreeBSD.org .
212