1139825Simp/*-
272980Sbp * Copyright (c) 2000, 2001 Boris Popov
372980Sbp * All rights reserved.
472980Sbp *
572980Sbp * Redistribution and use in source and binary forms, with or without
672980Sbp * modification, are permitted provided that the following conditions
772980Sbp * are met:
872980Sbp * 1. Redistributions of source code must retain the above copyright
972980Sbp *    notice, this list of conditions and the following disclaimer.
1072980Sbp * 2. Redistributions in binary form must reproduce the above copyright
1172980Sbp *    notice, this list of conditions and the following disclaimer in the
1272980Sbp *    documentation and/or other materials provided with the distribution.
1372980Sbp *
1472980Sbp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1572980Sbp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1672980Sbp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1772980Sbp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1872980Sbp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1972980Sbp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2072980Sbp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2172980Sbp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2272980Sbp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2372980Sbp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2472980Sbp * SUCH DAMAGE.
2572980Sbp *
2672980Sbp * $FreeBSD$
2772980Sbp */
2872980Sbp#ifndef _SYS_MCHAIN_H_
2972980Sbp#define _SYS_MCHAIN_H_
3072980Sbp
3172980Sbp#ifdef _KERNEL
3272980Sbp
3372980Sbp/*
3472980Sbp * Type of copy for mb_{put|get}_mem()
3572980Sbp */
3672980Sbp#define	MB_MSYSTEM	0		/* use bcopy() */
37111217Sbmilekic#define	MB_MUSER	1		/* use copyin()/copyout() */
38111217Sbmilekic#define	MB_MINLINE	2		/* use an inline copy loop */
3972980Sbp#define	MB_MZERO	3		/* bzero(), mb_put_mem only */
4072980Sbp#define	MB_MCUSTOM	4		/* use an user defined function */
4172980Sbp
4272980Sbpstruct mbuf;
4372980Sbpstruct mbchain;
4472980Sbp
45148517Simuratypedef int mb_copy_t(struct mbchain *mbp, c_caddr_t src, caddr_t dst,
46148517Simura    size_t *srclen, size_t *dstlen);
4772980Sbp
4872980Sbpstruct mbchain {
4972980Sbp	struct mbuf *	mb_top;		/* head of mbufs chain */
5072980Sbp	struct mbuf * 	mb_cur;		/* current mbuf */
5172980Sbp	int		mb_mleft;	/* free space in the current mbuf */
5272980Sbp	int		mb_count;	/* total number of bytes */
5372980Sbp	mb_copy_t *	mb_copy;	/* user defined copy function */
5472980Sbp	void *		mb_udata;	/* user data */
5572980Sbp};
5672980Sbp
5772980Sbpstruct mdchain {
5872980Sbp	struct mbuf *	md_top;		/* head of mbufs chain */
5972980Sbp	struct mbuf * 	md_cur;		/* current mbuf */
6072980Sbp	u_char *	md_pos;		/* offset in the current mbuf */
6172980Sbp};
6272980Sbp
6372980Sbpint  mb_init(struct mbchain *mbp);
6472980Sbpvoid mb_initm(struct mbchain *mbp, struct mbuf *m);
6572980Sbpvoid mb_done(struct mbchain *mbp);
6672980Sbpstruct mbuf *mb_detach(struct mbchain *mbp);
6772980Sbpint  mb_fixhdr(struct mbchain *mbp);
6872980Sbpcaddr_t mb_reserve(struct mbchain *mbp, int size);
6972980Sbp
70227650Skevloint  mb_put_padbyte(struct mbchain *mbp);
7172980Sbpint  mb_put_uint8(struct mbchain *mbp, u_int8_t x);
7272980Sbpint  mb_put_uint16be(struct mbchain *mbp, u_int16_t x);
7372980Sbpint  mb_put_uint16le(struct mbchain *mbp, u_int16_t x);
7472980Sbpint  mb_put_uint32be(struct mbchain *mbp, u_int32_t x);
7572980Sbpint  mb_put_uint32le(struct mbchain *mbp, u_int32_t x);
7672980Sbpint  mb_put_int64be(struct mbchain *mbp, int64_t x);
7772980Sbpint  mb_put_int64le(struct mbchain *mbp, int64_t x);
7872980Sbpint  mb_put_mem(struct mbchain *mbp, c_caddr_t source, int size, int type);
7972980Sbpint  mb_put_mbuf(struct mbchain *mbp, struct mbuf *m);
8072980Sbpint  mb_put_uio(struct mbchain *mbp, struct uio *uiop, int size);
8172980Sbp
8272980Sbpint  md_init(struct mdchain *mdp);
8372980Sbpvoid md_initm(struct mdchain *mbp, struct mbuf *m);
8472980Sbpvoid md_done(struct mdchain *mdp);
8572980Sbpvoid md_append_record(struct mdchain *mdp, struct mbuf *top);
8672980Sbpint  md_next_record(struct mdchain *mdp);
8772980Sbpint  md_get_uint8(struct mdchain *mdp, u_int8_t *x);
8872980Sbpint  md_get_uint16(struct mdchain *mdp, u_int16_t *x);
8972980Sbpint  md_get_uint16le(struct mdchain *mdp, u_int16_t *x);
9072980Sbpint  md_get_uint16be(struct mdchain *mdp, u_int16_t *x);
9172980Sbpint  md_get_uint32(struct mdchain *mdp, u_int32_t *x);
9272980Sbpint  md_get_uint32be(struct mdchain *mdp, u_int32_t *x);
9372980Sbpint  md_get_uint32le(struct mdchain *mdp, u_int32_t *x);
9472980Sbpint  md_get_int64(struct mdchain *mdp, int64_t *x);
9572980Sbpint  md_get_int64be(struct mdchain *mdp, int64_t *x);
9672980Sbpint  md_get_int64le(struct mdchain *mdp, int64_t *x);
9772980Sbpint  md_get_mem(struct mdchain *mdp, caddr_t target, int size, int type);
9872980Sbpint  md_get_mbuf(struct mdchain *mdp, int size, struct mbuf **m);
9972980Sbpint  md_get_uio(struct mdchain *mdp, struct uio *uiop, int size);
10072980Sbp
10172980Sbp#endif	/* ifdef _KERNEL */
10272980Sbp
10372980Sbp#endif	/* !_SYS_MCHAIN_H_ */
104