1/* 2 * Copyright (c) 2000, 2001 Boris Popov 3 * All rights reserved. 4 * 5 * Portions Copyright (C) 2001 - 2012 Apple Inc. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Boris Popov. 18 * 4. Neither the name of the author nor the names of any co-contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 */ 35#ifndef _SYS_MCHAIN_H_ 36#define _SYS_MCHAIN_H_ 37 38/* 39 * Type of copy for mb_{put|get}_mem() 40 */ 41#define MB_MSYSTEM 0 /* use bcopy() */ 42#define MB_MINLINE 2 /* use an inline copy loop */ 43#define MB_MZERO 3 /* bzero(), mb_put_mem only */ 44#define MB_MCUSTOM 4 /* use an user defined function */ 45 46 47struct mbchain { 48 mbuf_t mb_top; /* head of mbufs chain */ 49 mbuf_t mb_cur; /* current mbuf */ 50 size_t mb_mleft; /* free space in the current mbuf */ 51 size_t mb_count; /* used for byte counting */ 52 size_t mb_len; /* nbr bytes added in SMB2 compound requests */ 53}; 54 55struct mdchain { 56 mbuf_t md_top; /* head of mbufs chain */ 57 mbuf_t md_cur; /* current mbuf */ 58 u_char * md_pos; /* offset in the current mbuf */ 59 size_t md_len; /* nbr bytes parsed in SMB2 compound replies */ 60}; 61 62typedef struct mbchain* mbchain_t; 63typedef struct mdchain* mdchain_t; 64 65 66size_t m_fixhdr(mbuf_t ); 67 68int mb_init(mbchain_t ); 69void mb_done(mbchain_t ); 70 71mbuf_t mb_detach(mbchain_t ); /* KERNEL */ 72int mb_pullup(mbchain_t); /* USERLAND */ 73void * mb_getbuffer(mbchain_t , size_t ); /* USERLAND */ 74void mb_consume(mbchain_t , size_t ); /* USERLAND */ 75 76size_t mb_fixhdr(mbchain_t ); 77void * mb_reserve(mbchain_t , size_t size); 78 79int mb_put_padbyte(mbchain_t ); /* KERENL */ 80int mb_put_uint8(mbchain_t , uint8_t ); 81int mb_put_uint16be(mbchain_t , uint16_t ); 82int mb_put_uint16le(mbchain_t , uint16_t ); 83int mb_put_uint32be(mbchain_t , uint32_t ); 84int mb_put_uint32le(mbchain_t , uint32_t ); 85int mb_put_uint64be(mbchain_t , uint64_t ); 86int mb_put_uint64le(mbchain_t , uint64_t ); 87 88int mb_put_mem(mbchain_t , const char * , size_t , int ); 89int mb_put_mbuf(mbchain_t , mbuf_t ); 90 91#ifdef KERNEL 92void mbuf_cat_internal(mbuf_t md_top, mbuf_t m0); 93int mb_put_uio(mbchain_t mbp, uio_t uiop, size_t size); 94int mb_put_user_mem(mbchain_t mbp, user_addr_t bufp, int size, off_t offset, vfs_context_t context); 95#endif // KERNEL 96 97int md_init(mdchain_t mdp); 98#ifndef KERNEL 99/* Non kernel special verson when the receive buffer is greater than page size */ 100int md_init_rcvsize(mdchain_t, size_t); 101#endif // KERNEL 102void md_shadow_copy(const mdchain_t mdp, mdchain_t shadow); 103 104void md_initm(mdchain_t mbp, mbuf_t m); /* KERNEL */ 105void md_done(mdchain_t mdp); 106 107void md_append_record(mdchain_t mdp, mbuf_t top); 108int md_next_record(mdchain_t mdp); 109 110int md_get_uint8(mdchain_t mdp, uint8_t *x); 111int md_get_uint16(mdchain_t mdp, uint16_t *x); 112int md_get_uint16le(mdchain_t mdp, uint16_t *x); 113int md_get_uint16be(mdchain_t mdp, uint16_t *x); 114int md_get_uint32(mdchain_t mdp, uint32_t *x); 115int md_get_uint32be(mdchain_t mdp, uint32_t *x); 116int md_get_uint32le(mdchain_t mdp, uint32_t *x); 117int md_get_uint64(mdchain_t mdp, uint64_t *x); 118int md_get_uint64be(mdchain_t mdp, uint64_t *x); 119int md_get_uint64le(mdchain_t mdp, uint64_t *x); 120 121size_t md_get_utf16_strlen(mdchain_t mdp); 122size_t md_get_size(mdchain_t mdp); 123int md_get_mem(mdchain_t mdp, caddr_t target, size_t size, int type); 124 125#ifdef KERNEL 126int md_get_mbuf(mdchain_t mdp, size_t size, mbuf_t *m); 127int md_get_uio(mdchain_t mdp, uio_t uiop, int32_t size); 128int md_get_user_mem(mdchain_t mbp, user_addr_t bufp, int size, off_t offset, vfs_context_t context); 129#endif // KERNEL 130 131 132#endif /* !_SYS_MCHAIN_H_ */ 133