AMD64 - Fix many compile-time warnings. int/ptr type mismatches, %llx, etc.
[dragonfly.git] / sys / sys / mchain.h
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 2000, 2001 Boris Popov
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
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 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $FreeBSD: src/sys/sys/mchain.h,v 1.1.2.1 2001/05/18 11:01:23 bp Exp $
1bd40720 33 * $DragonFly: src/sys/sys/mchain.h,v 1.4 2006/05/20 02:42:13 dillon Exp $
984263bc
MD
34 */
35#ifndef _SYS_MCHAIN_H_
36#define _SYS_MCHAIN_H_
37
1bd40720
MD
38#ifndef _SYS_TYPES_H_
39#include <sys/types.h>
40#endif
41#ifndef _MACHINE_ENDIAN_H_
984263bc 42#include <machine/endian.h>
1bd40720 43#endif
984263bc
MD
44
45/*
46 * This macros probably belongs to the endian.h
47 */
c16ad152 48#if _BYTE_ORDER == _LITTLE_ENDIAN
984263bc
MD
49
50#define htoles(x) ((u_int16_t)(x))
51#define letohs(x) ((u_int16_t)(x))
52#define htolel(x) ((u_int32_t)(x))
53#define letohl(x) ((u_int32_t)(x))
54#define htoleq(x) ((int64_t)(x))
55#define letohq(x) ((int64_t)(x))
56
1bd40720
MD
57#define htobes(x) (__htons(x))
58#define betohs(x) (__ntohs(x))
59#define htobel(x) (__htonl(x))
60#define betohl(x) (__ntohl(x))
984263bc
MD
61
62static __inline int64_t
63htobeq(int64_t x)
64{
1bd40720
MD
65 return (int64_t)__htonl((u_int32_t)(x >> 32)) |
66 (int64_t)__htonl((u_int32_t)(x & 0xffffffff)) << 32;
984263bc
MD
67}
68
69static __inline int64_t
70betohq(int64_t x)
71{
1bd40720
MD
72 return (int64_t)__ntohl((u_int32_t)(x >> 32)) |
73 (int64_t)__ntohl((u_int32_t)(x & 0xffffffff)) << 32;
984263bc
MD
74}
75
76#else /* (BYTE_ORDER == LITTLE_ENDIAN) */
77
78#error "Macros for Big-Endians are incomplete"
79
80/*
81#define htoles(x) ((u_int16_t)(x))
82#define letohs(x) ((u_int16_t)(x))
83#define htolel(x) ((u_int32_t)(x))
84#define letohl(x) ((u_int32_t)(x))
85*/
86#endif /* (BYTE_ORDER == LITTLE_ENDIAN) */
87
88
89#ifdef _KERNEL
90
91/*
92 * Type of copy for mb_{put|get}_mem()
93 */
94#define MB_MSYSTEM 0 /* use bcopy() */
95#define MB_MUSER 1 /* use copyin()/copyout() */
96#define MB_MINLINE 2 /* use an inline copy loop */
97#define MB_MZERO 3 /* bzero(), mb_put_mem only */
98#define MB_MCUSTOM 4 /* use an user defined function */
99
100struct mbuf;
101struct mbchain;
1bd40720 102struct uio;
984263bc 103
973c11b9 104typedef int mb_copy_t(struct mbchain *mbp, c_caddr_t src, caddr_t dst, size_t len);
984263bc
MD
105
106struct mbchain {
107 struct mbuf * mb_top; /* head of mbufs chain */
108 struct mbuf * mb_cur; /* current mbuf */
109 int mb_mleft; /* free space in the current mbuf */
110 int mb_count; /* total number of bytes */
111 mb_copy_t * mb_copy; /* user defined copy function */
112 void * mb_udata; /* user data */
113};
114
115struct mdchain {
116 struct mbuf * md_top; /* head of mbufs chain */
117 struct mbuf * md_cur; /* current mbuf */
118 u_char * md_pos; /* offset in the current mbuf */
119};
120
121int m_fixhdr(struct mbuf *m);
122
123int mb_init(struct mbchain *mbp);
124void mb_initm(struct mbchain *mbp, struct mbuf *m);
125void mb_done(struct mbchain *mbp);
126struct mbuf *mb_detach(struct mbchain *mbp);
127int mb_fixhdr(struct mbchain *mbp);
128caddr_t mb_reserve(struct mbchain *mbp, int size);
129
130int mb_put_uint8(struct mbchain *mbp, u_int8_t x);
131int mb_put_uint16be(struct mbchain *mbp, u_int16_t x);
132int mb_put_uint16le(struct mbchain *mbp, u_int16_t x);
133int mb_put_uint32be(struct mbchain *mbp, u_int32_t x);
134int mb_put_uint32le(struct mbchain *mbp, u_int32_t x);
135int mb_put_int64be(struct mbchain *mbp, int64_t x);
136int mb_put_int64le(struct mbchain *mbp, int64_t x);
137int mb_put_mem(struct mbchain *mbp, c_caddr_t source, int size, int type);
138int mb_put_mbuf(struct mbchain *mbp, struct mbuf *m);
139int mb_put_uio(struct mbchain *mbp, struct uio *uiop, int size);
140
141int md_init(struct mdchain *mdp);
142void md_initm(struct mdchain *mbp, struct mbuf *m);
143void md_done(struct mdchain *mdp);
144void md_append_record(struct mdchain *mdp, struct mbuf *top);
145int md_next_record(struct mdchain *mdp);
146int md_get_uint8(struct mdchain *mdp, u_int8_t *x);
147int md_get_uint16(struct mdchain *mdp, u_int16_t *x);
148int md_get_uint16le(struct mdchain *mdp, u_int16_t *x);
149int md_get_uint16be(struct mdchain *mdp, u_int16_t *x);
150int md_get_uint32(struct mdchain *mdp, u_int32_t *x);
151int md_get_uint32be(struct mdchain *mdp, u_int32_t *x);
152int md_get_uint32le(struct mdchain *mdp, u_int32_t *x);
153int md_get_int64(struct mdchain *mdp, int64_t *x);
154int md_get_int64be(struct mdchain *mdp, int64_t *x);
155int md_get_int64le(struct mdchain *mdp, int64_t *x);
156int md_get_mem(struct mdchain *mdp, caddr_t target, int size, int type);
157int md_get_mbuf(struct mdchain *mdp, int size, struct mbuf **m);
158int md_get_uio(struct mdchain *mdp, struct uio *uiop, int size);
159
160#endif /* ifdef _KERNEL */
161
162#endif /* !_SYS_MCHAIN_H_ */