The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/mchain.h

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    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: releng/5.0/sys/sys/mchain.h 106667 2002-11-08 21:26:32Z jhb $
   33  */
   34 #ifndef _SYS_MCHAIN_H_
   35 #define _SYS_MCHAIN_H_
   36 
   37 #include <machine/endian.h>
   38 
   39 #ifdef _KERNEL
   40 
   41 /*
   42  * XXX: remove these defines and change the function calls in the code. Use
   43  * it unconditionally if (when) the extended byte order functions become
   44  * available in user space.
   45  */
   46 #define htoles(x)       htole16((x))
   47 #define letohs(x)       le16toh((x))
   48 #define htolel(x)       htole32((x))
   49 #define letohl(x)       le32toh((x))
   50 #define htoleq(x)       htole64((int64_t)(x))
   51 #define letohq(x)       le64toh((int64_t)(x))
   52 
   53 #define htobes(x)       htobe16((x))
   54 #define betohs(x)       be16toh((x))
   55 #define htobel(x)       htobe32((x))
   56 #define betohl(x)       be32toh((x))
   57 #define htobeq(x)       htobe64((int64_t)(x))
   58 #define betohq(x)       be64toh((int64_t)(x))
   59 
   60 #else
   61 /*
   62  * This macros probably belongs to the endian.h
   63  */
   64 #if (BYTE_ORDER == LITTLE_ENDIAN)
   65 
   66 #define htoles(x)       ((u_int16_t)(x))
   67 #define letohs(x)       ((u_int16_t)(x))
   68 #define htolel(x)       ((u_int32_t)(x))
   69 #define letohl(x)       ((u_int32_t)(x))
   70 #define htoleq(x)       ((int64_t)(x))
   71 #define letohq(x)       ((int64_t)(x))
   72 
   73 #define htobes(x)       (__htons(x))
   74 #define betohs(x)       (__ntohs(x))
   75 #define htobel(x)       (__htonl(x))
   76 #define betohl(x)       (__ntohl(x))
   77 
   78 static __inline int64_t
   79 htobeq(int64_t x)
   80 {
   81         return (int64_t)__htonl((u_int32_t)(x >> 32)) |
   82             (int64_t)__htonl((u_int32_t)(x & 0xffffffff)) << 32;
   83 }
   84 
   85 static __inline int64_t
   86 betohq(int64_t x)
   87 {
   88         return (int64_t)__ntohl((u_int32_t)(x >> 32)) |
   89             (int64_t)__ntohl((u_int32_t)(x & 0xffffffff)) << 32;
   90 }
   91 
   92 #else   /* (BYTE_ORDER == LITTLE_ENDIAN) */
   93 
   94 #error "Macros for Big-Endians are incomplete"
   95 
   96 /*
   97 #define htoles(x)       ((u_int16_t)(x))
   98 #define letohs(x)       ((u_int16_t)(x))
   99 #define htolel(x)       ((u_int32_t)(x))
  100 #define letohl(x)       ((u_int32_t)(x))
  101 */
  102 #endif  /* (BYTE_ORDER == LITTLE_ENDIAN) */
  103 #endif  /* _KERNEL */
  104 
  105 
  106 #ifdef _KERNEL
  107 
  108 /*
  109  * Type of copy for mb_{put|get}_mem()
  110  */
  111 #define MB_MSYSTEM      0               /* use bcopy() */
  112 #define MB_MUSER        1               /* use copyin()/copyout() */
  113 #define MB_MINLINE      2               /* use an inline copy loop */
  114 #define MB_MZERO        3               /* bzero(), mb_put_mem only */
  115 #define MB_MCUSTOM      4               /* use an user defined function */
  116 
  117 struct mbuf;
  118 struct mbchain;
  119 
  120 typedef int mb_copy_t(struct mbchain *mbp, c_caddr_t src, caddr_t dst, size_t len);
  121 
  122 struct mbchain {
  123         struct mbuf *   mb_top;         /* head of mbufs chain */
  124         struct mbuf *   mb_cur;         /* current mbuf */
  125         int             mb_mleft;       /* free space in the current mbuf */
  126         int             mb_count;       /* total number of bytes */
  127         mb_copy_t *     mb_copy;        /* user defined copy function */
  128         void *          mb_udata;       /* user data */
  129 };
  130 
  131 struct mdchain {
  132         struct mbuf *   md_top;         /* head of mbufs chain */
  133         struct mbuf *   md_cur;         /* current mbuf */
  134         u_char *        md_pos;         /* offset in the current mbuf */
  135 };
  136 
  137 int  mb_init(struct mbchain *mbp);
  138 void mb_initm(struct mbchain *mbp, struct mbuf *m);
  139 void mb_done(struct mbchain *mbp);
  140 struct mbuf *mb_detach(struct mbchain *mbp);
  141 int  mb_fixhdr(struct mbchain *mbp);
  142 caddr_t mb_reserve(struct mbchain *mbp, int size);
  143 
  144 int  mb_put_uint8(struct mbchain *mbp, u_int8_t x);
  145 int  mb_put_uint16be(struct mbchain *mbp, u_int16_t x);
  146 int  mb_put_uint16le(struct mbchain *mbp, u_int16_t x);
  147 int  mb_put_uint32be(struct mbchain *mbp, u_int32_t x);
  148 int  mb_put_uint32le(struct mbchain *mbp, u_int32_t x);
  149 int  mb_put_int64be(struct mbchain *mbp, int64_t x);
  150 int  mb_put_int64le(struct mbchain *mbp, int64_t x);
  151 int  mb_put_mem(struct mbchain *mbp, c_caddr_t source, int size, int type);
  152 int  mb_put_mbuf(struct mbchain *mbp, struct mbuf *m);
  153 int  mb_put_uio(struct mbchain *mbp, struct uio *uiop, int size);
  154 
  155 int  md_init(struct mdchain *mdp);
  156 void md_initm(struct mdchain *mbp, struct mbuf *m);
  157 void md_done(struct mdchain *mdp);
  158 void md_append_record(struct mdchain *mdp, struct mbuf *top);
  159 int  md_next_record(struct mdchain *mdp);
  160 int  md_get_uint8(struct mdchain *mdp, u_int8_t *x);
  161 int  md_get_uint16(struct mdchain *mdp, u_int16_t *x);
  162 int  md_get_uint16le(struct mdchain *mdp, u_int16_t *x);
  163 int  md_get_uint16be(struct mdchain *mdp, u_int16_t *x);
  164 int  md_get_uint32(struct mdchain *mdp, u_int32_t *x);
  165 int  md_get_uint32be(struct mdchain *mdp, u_int32_t *x);
  166 int  md_get_uint32le(struct mdchain *mdp, u_int32_t *x);
  167 int  md_get_int64(struct mdchain *mdp, int64_t *x);
  168 int  md_get_int64be(struct mdchain *mdp, int64_t *x);
  169 int  md_get_int64le(struct mdchain *mdp, int64_t *x);
  170 int  md_get_mem(struct mdchain *mdp, caddr_t target, int size, int type);
  171 int  md_get_mbuf(struct mdchain *mdp, int size, struct mbuf **m);
  172 int  md_get_uio(struct mdchain *mdp, struct uio *uiop, int size);
  173 
  174 #endif  /* ifdef _KERNEL */
  175 
  176 #endif  /* !_SYS_MCHAIN_H_ */

Cache object: 03e1d6a582ba2cf9283ab8f4ee351561


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.