| 10 |
10 |
* 2. Redistributions in binary form must reproduce the above copyright
|
| 11 |
11 |
* notice, this list of conditions and the following disclaimer in the
|
| 12 |
12 |
* documentation and/or other materials provided with the distribution.
|
| 13 |
|
* 3. All advertising materials mentioning features or use of this software
|
| 14 |
|
* must display the following acknowledgement:
|
| 15 |
|
* This product includes software developed by Boris Popov.
|
| 16 |
13 |
* 4. Neither the name of the author nor the names of any co-contributors
|
| 17 |
14 |
* may be used to endorse or promote products derived from this software
|
| 18 |
15 |
* without specific prior written permission.
|
| ... | ... | |
| 37 |
34 |
#include <sys/param.h>
|
| 38 |
35 |
#include <sys/systm.h>
|
| 39 |
36 |
#include <sys/kernel.h>
|
|
37 |
#include <sys/endian.h>
|
| 40 |
38 |
#include <sys/errno.h>
|
| 41 |
|
#include <sys/malloc.h>
|
| 42 |
39 |
#include <sys/mbuf.h>
|
| 43 |
40 |
#include <sys/module.h>
|
| 44 |
41 |
#include <sys/uio.h>
|
| ... | ... | |
| 47 |
44 |
|
| 48 |
45 |
MODULE_VERSION(libmchain, 1);
|
| 49 |
46 |
|
| 50 |
|
#define MBERROR(format, args...) printf("%s(%d): "format, __func__ , \
|
| 51 |
|
__LINE__ ,## args)
|
|
47 |
#define MBERROR(format, ...) printf("%s(%d): "format, __func__ , \
|
|
48 |
__LINE__ , ## __VA_ARGS__)
|
| 52 |
49 |
|
| 53 |
|
#define MBPANIC(format, args...) printf("%s(%d): "format, __func__ , \
|
| 54 |
|
__LINE__ ,## args)
|
|
50 |
#define MBPANIC(format, ...) printf("%s(%d): "format, __func__ , \
|
|
51 |
__LINE__ , ## __VA_ARGS__)
|
| 55 |
52 |
|
| 56 |
53 |
/*
|
| 57 |
54 |
* Various helper functions
|
| ... | ... | |
| 157 |
154 |
int
|
| 158 |
155 |
mb_put_uint16be(struct mbchain *mbp, u_int16_t x)
|
| 159 |
156 |
{
|
| 160 |
|
x = htobes(x);
|
|
157 |
x = htobe16(x);
|
| 161 |
158 |
return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM);
|
| 162 |
159 |
}
|
| 163 |
160 |
|
| 164 |
161 |
int
|
| 165 |
162 |
mb_put_uint16le(struct mbchain *mbp, u_int16_t x)
|
| 166 |
163 |
{
|
| 167 |
|
x = htoles(x);
|
|
164 |
x = htole16(x);
|
| 168 |
165 |
return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM);
|
| 169 |
166 |
}
|
| 170 |
167 |
|
| 171 |
168 |
int
|
| 172 |
169 |
mb_put_uint32be(struct mbchain *mbp, u_int32_t x)
|
| 173 |
170 |
{
|
| 174 |
|
x = htobel(x);
|
|
171 |
x = htobe32(x);
|
| 175 |
172 |
return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM);
|
| 176 |
173 |
}
|
| 177 |
174 |
|
| 178 |
175 |
int
|
| 179 |
176 |
mb_put_uint32le(struct mbchain *mbp, u_int32_t x)
|
| 180 |
177 |
{
|
| 181 |
|
x = htolel(x);
|
|
178 |
x = htole32(x);
|
| 182 |
179 |
return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM);
|
| 183 |
180 |
}
|
| 184 |
181 |
|
| 185 |
182 |
int
|
| 186 |
183 |
mb_put_int64be(struct mbchain *mbp, int64_t x)
|
| 187 |
184 |
{
|
| 188 |
|
x = htobeq(x);
|
|
185 |
x = htobe64(x);
|
| 189 |
186 |
return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM);
|
| 190 |
187 |
}
|
| 191 |
188 |
|
| 192 |
189 |
int
|
| 193 |
190 |
mb_put_int64le(struct mbchain *mbp, int64_t x)
|
| 194 |
191 |
{
|
| 195 |
|
x = htoleq(x);
|
|
192 |
x = htole64(x);
|
| 196 |
193 |
return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM);
|
| 197 |
194 |
}
|
| 198 |
195 |
|
| ... | ... | |
| 203 |
200 |
caddr_t dst;
|
| 204 |
201 |
c_caddr_t src;
|
| 205 |
202 |
int cplen, error, mleft, count;
|
|
203 |
size_t srclen, dstlen;
|
| 206 |
204 |
|
| 207 |
205 |
m = mbp->mb_cur;
|
| 208 |
206 |
mleft = mbp->mb_mleft;
|
| ... | ... | |
| 219 |
217 |
continue;
|
| 220 |
218 |
}
|
| 221 |
219 |
cplen = mleft > size ? size : mleft;
|
|
220 |
srclen = dstlen = cplen;
|
| 222 |
221 |
dst = mtod(m, caddr_t) + m->m_len;
|
| 223 |
222 |
switch (type) {
|
| 224 |
223 |
case MB_MCUSTOM:
|
| 225 |
|
error = mbp->mb_copy(mbp, source, dst, cplen);
|
|
224 |
srclen = size;
|
|
225 |
dstlen = mleft;
|
|
226 |
error = mbp->mb_copy(mbp, source, dst, &srclen, &dstlen);
|
| 226 |
227 |
if (error)
|
| 227 |
228 |
return error;
|
| 228 |
229 |
break;
|
| ... | ... | |
| 242 |
243 |
bzero(dst, cplen);
|
| 243 |
244 |
break;
|
| 244 |
245 |
}
|
| 245 |
|
size -= cplen;
|
| 246 |
|
source += cplen;
|
| 247 |
|
m->m_len += cplen;
|
| 248 |
|
mleft -= cplen;
|
| 249 |
|
mbp->mb_count += cplen;
|
|
246 |
size -= srclen;
|
|
247 |
source += srclen;
|
|
248 |
m->m_len += dstlen;
|
|
249 |
mleft -= dstlen;
|
|
250 |
mbp->mb_count += dstlen;
|
| 250 |
251 |
}
|
| 251 |
252 |
mbp->mb_cur = m;
|
| 252 |
253 |
mbp->mb_mleft = mleft;
|
| ... | ... | |
| 295 |
296 |
return error;
|
| 296 |
297 |
uiop->uio_offset += left;
|
| 297 |
298 |
uiop->uio_resid -= left;
|
| 298 |
|
uiop->uio_iov->iov_base += left;
|
|
299 |
uiop->uio_iov->iov_base =
|
|
300 |
(char *)uiop->uio_iov->iov_base + left;
|
| 299 |
301 |
uiop->uio_iov->iov_len -= left;
|
| 300 |
302 |
size -= left;
|
| 301 |
303 |
}
|
| ... | ... | |
| 393 |
395 |
u_int16_t v;
|
| 394 |
396 |
int error = md_get_uint16(mdp, &v);
|
| 395 |
397 |
|
| 396 |
|
*x = letohs(v);
|
|
398 |
if (x != NULL)
|
|
399 |
*x = le16toh(v);
|
| 397 |
400 |
return error;
|
| 398 |
401 |
}
|
| 399 |
402 |
|
| ... | ... | |
| 402 |
405 |
u_int16_t v;
|
| 403 |
406 |
int error = md_get_uint16(mdp, &v);
|
| 404 |
407 |
|
| 405 |
|
*x = betohs(v);
|
|
408 |
if (x != NULL)
|
|
409 |
*x = be16toh(v);
|
| 406 |
410 |
return error;
|
| 407 |
411 |
}
|
| 408 |
412 |
|
| ... | ... | |
| 419 |
423 |
int error;
|
| 420 |
424 |
|
| 421 |
425 |
error = md_get_uint32(mdp, &v);
|
| 422 |
|
*x = betohl(v);
|
|
426 |
if (x != NULL)
|
|
427 |
*x = be32toh(v);
|
| 423 |
428 |
return error;
|
| 424 |
429 |
}
|
| 425 |
430 |
|
| ... | ... | |
| 430 |
435 |
int error;
|
| 431 |
436 |
|
| 432 |
437 |
error = md_get_uint32(mdp, &v);
|
| 433 |
|
*x = letohl(v);
|
|
438 |
if (x != NULL)
|
|
439 |
*x = le32toh(v);
|
| 434 |
440 |
return error;
|
| 435 |
441 |
}
|
| 436 |
442 |
|
| ... | ... | |
| 447 |
453 |
int error;
|
| 448 |
454 |
|
| 449 |
455 |
error = md_get_int64(mdp, &v);
|
| 450 |
|
*x = betohq(v);
|
|
456 |
if (x != NULL)
|
|
457 |
*x = be64toh(v);
|
| 451 |
458 |
return error;
|
| 452 |
459 |
}
|
| 453 |
460 |
|
| ... | ... | |
| 458 |
465 |
int error;
|
| 459 |
466 |
|
| 460 |
467 |
error = md_get_int64(mdp, &v);
|
| 461 |
|
*x = letohq(v);
|
|
468 |
if (x != NULL)
|
|
469 |
*x = le64toh(v);
|
| 462 |
470 |
return error;
|
| 463 |
471 |
}
|
| 464 |
472 |
|
| ... | ... | |
| 546 |
554 |
return error;
|
| 547 |
555 |
uiop->uio_offset += left;
|
| 548 |
556 |
uiop->uio_resid -= left;
|
| 549 |
|
uiop->uio_iov->iov_base += left;
|
|
557 |
uiop->uio_iov->iov_base =
|
|
558 |
(char *)uiop->uio_iov->iov_base + left;
|
| 550 |
559 |
uiop->uio_iov->iov_len -= left;
|
| 551 |
560 |
size -= left;
|
| 552 |
561 |
}
|