xref: /freebsd/share/man/man9/mbchain.9 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
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.Dd February 20, 2001
26a1a5ca55SBoris Popov.Dt MBCHAIN 9
27a1a5ca55SBoris Popov.Os
28a1a5ca55SBoris Popov.Sh NAME
29a1a5ca55SBoris Popov.Nm mbchain ,
30a1a5ca55SBoris Popov.Nm mb_init ,
31a1a5ca55SBoris Popov.Nm mb_initm ,
32a1a5ca55SBoris Popov.Nm mb_done ,
33a1a5ca55SBoris Popov.Nm mb_detach ,
34a1a5ca55SBoris Popov.Nm mb_fixhdr ,
35a1a5ca55SBoris Popov.Nm mb_reserve ,
36a1a5ca55SBoris Popov.Nm mb_put_uint8 ,
37a1a5ca55SBoris Popov.Nm mb_put_uint16be ,
38a1a5ca55SBoris Popov.Nm mb_put_uint16le ,
39a1a5ca55SBoris Popov.Nm mb_put_uint32be ,
40a1a5ca55SBoris Popov.Nm mb_put_uint32le ,
41a1a5ca55SBoris Popov.Nm mb_put_int64be ,
42a1a5ca55SBoris Popov.Nm mb_put_int64le ,
43a1a5ca55SBoris Popov.Nm mb_put_mem ,
44a1a5ca55SBoris Popov.Nm mb_put_mbuf ,
45a1a5ca55SBoris Popov.Nm mb_put_uio
46a1a5ca55SBoris Popov.Nd "set of functions to build an mbuf chain from various data types"
47a1a5ca55SBoris Popov.Sh SYNOPSIS
48a1a5ca55SBoris Popov.Cd options LIBMCHAIN
49a1a5ca55SBoris Popov.Li kldload libmchain
50a1a5ca55SBoris Popov.Pp
5132eef9aeSRuslan Ermilov.In sys/param.h
52f16b3c0dSChad David.In sys/uio.h
5332eef9aeSRuslan Ermilov.In sys/mchain.h
54a1a5ca55SBoris Popov.Ft int
55a1a5ca55SBoris Popov.Fn mb_init "struct mbchain *mbp"
56a1a5ca55SBoris Popov.Ft void
57a1a5ca55SBoris Popov.Fn mb_initm "struct mbchain *mbp" "struct mbuf *m"
58a1a5ca55SBoris Popov.Ft void
59a1a5ca55SBoris Popov.Fn mb_done "struct mbchain *mbp"
60a1a5ca55SBoris Popov.Ft struct mbuf *
61a1a5ca55SBoris Popov.Fn mb_detach "struct mbchain *mbp"
62a1a5ca55SBoris Popov.Ft int
63a1a5ca55SBoris Popov.Fn mb_fixhdr "struct mbchain *mbp"
64a1a5ca55SBoris Popov.Ft caddr_t
65a1a5ca55SBoris Popov.Fn mb_reserve "struct mbchain *mbp" "int size"
66a1a5ca55SBoris Popov.Ft int
676b99842aSEd Schouten.Fn mb_put_uint8 "struct mbchain *mbp" "uint8_t x"
68a1a5ca55SBoris Popov.Ft int
696b99842aSEd Schouten.Fn mb_put_uint16be "struct mbchain *mbp" "uint16_t x"
70a1a5ca55SBoris Popov.Ft int
716b99842aSEd Schouten.Fn mb_put_uint16le "struct mbchain *mbp" "uint16_t x"
72a1a5ca55SBoris Popov.Ft int
736b99842aSEd Schouten.Fn mb_put_uint32be "struct mbchain *mbp" "uint32_t x"
74a1a5ca55SBoris Popov.Ft int
756b99842aSEd Schouten.Fn mb_put_uint32le "struct mbchain *mbp" "uint32_t x"
76a1a5ca55SBoris Popov.Ft int
77a1a5ca55SBoris Popov.Fn mb_put_int64be "struct mbchain *mbp" "int64_t x"
78a1a5ca55SBoris Popov.Ft int
79a1a5ca55SBoris Popov.Fn mb_put_int64le "struct mbchain *mbp" "int64_t x"
80a1a5ca55SBoris Popov.Ft int
81a1a5ca55SBoris Popov.Fn mb_put_mem "struct mbchain *mbp" "c_caddr_t source" "int size" "int type"
82a1a5ca55SBoris Popov.Ft int
83a1a5ca55SBoris Popov.Fn mb_put_mbuf "struct mbchain *mbp" "struct mbuf *m"
84a1a5ca55SBoris Popov.Ft int
85a1a5ca55SBoris Popov.Fn mb_put_uio "struct mbchain *mbp" "struct uio *uiop" "int size"
86a1a5ca55SBoris Popov.Sh DESCRIPTION
87a1a5ca55SBoris PopovThese functions are used to compose mbuf chains from various data types.
88a1a5ca55SBoris PopovThe
89a1a5ca55SBoris Popov.Vt mbchain
90a1a5ca55SBoris Popovstructure is used as a working context and should be initialized with a call
91a1a5ca55SBoris Popovto either
92a1a5ca55SBoris Popov.Fn mb_init
93a1a5ca55SBoris Popovor
94a1a5ca55SBoris Popov.Fn mb_initm .
95a1a5ca55SBoris PopovIt has the following fields:
96b0536a9bSRuslan Ermilov.Bl -tag -width ".Va mb_count"
97a1a5ca55SBoris Popov.It Va "mb_top"
98b0536a9bSRuslan Ermilov.Pq Vt "struct mbuf *"
99b0536a9bSRuslan ErmilovA pointer to the top of constructed mbuf chain.
100a1a5ca55SBoris Popov.It Va mb_cur
101b0536a9bSRuslan Ermilov.Pq Vt "struct mbuf *"
102b0536a9bSRuslan ErmilovA pointer to the currently filled mbuf.
103a1a5ca55SBoris Popov.It Va mb_mleft
104b0536a9bSRuslan Ermilov.Pq Vt int
105b0536a9bSRuslan ErmilovNumber of bytes left in the current mbuf.
106a1a5ca55SBoris Popov.It Va mb_count
107b0536a9bSRuslan Ermilov.Pq Vt int
108b0536a9bSRuslan ErmilovTotal number of bytes placed in the mbuf chain.
109a1a5ca55SBoris Popov.It Va mb_copy
110b0536a9bSRuslan Ermilov.Pq Vt "mb_copy_t *"
111b0536a9bSRuslan ErmilovUser-defined function to perform a copy into mbuf;
112a1a5ca55SBoris Popovuseful if any unusual
113b0536a9bSRuslan Ermilovdata conversion is necessary.
114a1a5ca55SBoris Popov.It Va mb_udata
115b0536a9bSRuslan Ermilov.Pq Vt "void *"
116b0536a9bSRuslan ErmilovUser-supplied data which can be used in the
117a1a5ca55SBoris Popov.Va mb_copy
118b0536a9bSRuslan Ermilovfunction.
119a1a5ca55SBoris Popov.El
120a1a5ca55SBoris Popov.Pp
121a1a5ca55SBoris Popov.Fn mb_done
122a1a5ca55SBoris Popovfunction disposes an mbuf chain pointed to by
123a1a5ca55SBoris Popov.Fa mbp->mb_top
124a1a5ca55SBoris Popovfield and sets
125a1a5ca55SBoris Popovthe field to
126a1a5ca55SBoris Popov.Dv NULL .
127a1a5ca55SBoris Popov.Pp
128a1a5ca55SBoris Popov.Fn mb_detach
129a1a5ca55SBoris Popovfunction returns the value of
130a1a5ca55SBoris Popov.Fa mbp->mb_top
131a1a5ca55SBoris Popovfield and sets its value to
132a1a5ca55SBoris Popov.Dv NULL .
133a1a5ca55SBoris Popov.Pp
134a1a5ca55SBoris Popov.Fn mb_fixhdr
135a1a5ca55SBoris Popovrecalculates the length of an mbuf chain and updates the
136a1a5ca55SBoris Popov.Va m_pkthdr.len
137a1a5ca55SBoris Popovfield of the first mbuf in the chain.
138fa1b1bbcSMurray StokelyIt returns the calculated length.
139a1a5ca55SBoris Popov.Pp
140a1a5ca55SBoris Popov.Fn mb_reserve
141a1a5ca55SBoris Popovensures that the object of the length specified by the
142a1a5ca55SBoris Popov.Fa size
143a1a5ca55SBoris Popovargument will fit in the current mbuf (mbuf allocation is performed if
144a1a5ca55SBoris Popovnecessary), and advances all pointers as if the real data was placed.
145a1a5ca55SBoris PopovReturned
146a1a5ca55SBoris Popovvalue will point to the beginning of the reserved space.
147a1a5ca55SBoris PopovNote that the size
148a1a5ca55SBoris Popovof the object should not exceed
149a1a5ca55SBoris Popov.Dv MLEN
150a1a5ca55SBoris Popovbytes.
151a1a5ca55SBoris Popov.Pp
152a1a5ca55SBoris PopovAll
153a1a5ca55SBoris Popov.Fn mb_put_*
154a1a5ca55SBoris Popovfunctions perform an actual copy of the data into mbuf chain.
155a1a5ca55SBoris PopovFunctions which have
156a1a5ca55SBoris Popov.Cm le
157a1a5ca55SBoris Popovor
158a1a5ca55SBoris Popov.Cm be
159a1a5ca55SBoris Popovsuffixes will perform conversion to the little\- or big\-endian data formats.
160a1a5ca55SBoris Popov.Pp
161a1a5ca55SBoris Popov.Fn mb_put_mem
162a1a5ca55SBoris Popovfunction copies
163a1a5ca55SBoris Popov.Fa size
164a1a5ca55SBoris Popovbytes of data specified by the
165a1a5ca55SBoris Popov.Fa source
166a1a5ca55SBoris Popovargument to an mbuf chain.
167a1a5ca55SBoris PopovThe
168a1a5ca55SBoris Popov.Fa type
169a1a5ca55SBoris Popovargument specifies the method used to perform a copy,
170a1a5ca55SBoris Popovand can be one of the following:
171b0536a9bSRuslan Ermilov.Bl -tag -width ".Dv MB_MINLINE"
172a1a5ca55SBoris Popov.It Dv MB_MSYSTEM
173b0536a9bSRuslan ErmilovUse
174a1a5ca55SBoris Popov.Fn bcopy
175b0536a9bSRuslan Ermilovfunction.
176a1a5ca55SBoris Popov.It Dv MB_MUSER
177b0536a9bSRuslan ErmilovUse
178a1a5ca55SBoris Popov.Xr copyin 9
179b0536a9bSRuslan Ermilovfunction.
180a1a5ca55SBoris Popov.It Dv MB_MINLINE
181b0536a9bSRuslan ErmilovUse an
182a1a5ca55SBoris Popov.Dq inline
183b0536a9bSRuslan Ermilovloop which does not call any function.
184a1a5ca55SBoris Popov.It Dv MB_MZERO
185b0536a9bSRuslan ErmilovDo not copy any data, but just fill the destination with zero bytes.
186a1a5ca55SBoris Popov.It Dv MB_MCUSTOM
187b0536a9bSRuslan ErmilovCall function specified by the
188a1a5ca55SBoris Popov.Fa mbp->mb_copy
189b0536a9bSRuslan Ermilovfield.
190a1a5ca55SBoris Popov.El
191a1a5ca55SBoris Popov.Sh RETURN VALUES
192a1a5ca55SBoris PopovAll
193a1a5ca55SBoris Popov.Ft int
194fa1b1bbcSMurray Stokelyfunctions except
195fa1b1bbcSMurray Stokely.Fn mb_fixhdr
196fa1b1bbcSMurray Stokelyreturn zero if successful and an error code otherwise.
197a1a5ca55SBoris Popov.Pp
198a1a5ca55SBoris Popov.Em Note :
199a1a5ca55SBoris Popovafter failure of any function, an mbuf chain is left in the broken state,
200a1a5ca55SBoris Popovand only
201a1a5ca55SBoris Popov.Fn mb_done
202a1a5ca55SBoris Popovfunction can safely be called to destroy it.
203a1a5ca55SBoris Popov.Sh EXAMPLES
204a1a5ca55SBoris Popov.Bd -literal
205a1a5ca55SBoris Popovstruct mbchain *mbp;
206a1a5ca55SBoris Popovstruct mbuf *m;
207a1a5ca55SBoris Popov
208a1a5ca55SBoris Popovmb_init(mbp);
209a1a5ca55SBoris Popovmb_put_uint8(mbp, 33);
210a1a5ca55SBoris Popovmb_put_uint16le(mbp, length);
211eb085c43SRuslan Ermilovm = m_copym(mbp->mb_top, 0, M_COPYALL, M_WAIT);
212a1a5ca55SBoris Popovsend(m);
213a1a5ca55SBoris Popovmb_done(mbp);
214a1a5ca55SBoris Popov.Ed
215a1a5ca55SBoris Popov.Sh SEE ALSO
216a1a5ca55SBoris Popov.Xr mbuf 9 ,
217a1a5ca55SBoris Popov.Xr mdchain 9
218a1a5ca55SBoris Popov.Sh AUTHORS
219a1a5ca55SBoris PopovThis manual page was written by
220*8a7314fcSBaptiste Daroussin.An Boris Popov Aq Mt bp@FreeBSD.org .
221