1*0636a2feSchristos /* $NetBSD: bswap.h,v 1.3 2016/01/31 18:57:29 christos Exp $ */ 2d3724ba4Stsutsui 3d3724ba4Stsutsui /*- 4d3724ba4Stsutsui * Copyright (c) 2009 Izumi Tsutsui. All rights reserved. 5d3724ba4Stsutsui * 6d3724ba4Stsutsui * Redistribution and use in source and binary forms, with or without 7d3724ba4Stsutsui * modification, are permitted provided that the following conditions 8d3724ba4Stsutsui * are met: 9d3724ba4Stsutsui * 1. Redistributions of source code must retain the above copyright 10d3724ba4Stsutsui * notice, this list of conditions and the following disclaimer. 11d3724ba4Stsutsui * 2. Redistributions in binary form must reproduce the above copyright 12d3724ba4Stsutsui * notice, this list of conditions and the following disclaimer in the 13d3724ba4Stsutsui * documentation and/or other materials provided with the distribution. 14d3724ba4Stsutsui * 15d3724ba4Stsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16d3724ba4Stsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17d3724ba4Stsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18d3724ba4Stsutsui * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19d3724ba4Stsutsui * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20d3724ba4Stsutsui * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21d3724ba4Stsutsui * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22d3724ba4Stsutsui * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23d3724ba4Stsutsui * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24d3724ba4Stsutsui * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25d3724ba4Stsutsui */ 26d3724ba4Stsutsui 27d3724ba4Stsutsui #include <sys/types.h> 28d3724ba4Stsutsui 29d3724ba4Stsutsui #if HAVE_NBTOOL_CONFIG_H 30d3724ba4Stsutsui #ifndef BYTE_ORDER 31d3724ba4Stsutsui #ifdef WORDS_BIGENDIAN 32d3724ba4Stsutsui #define BYTE_ORDER BIG_ENDIAN 33d3724ba4Stsutsui #else 34d3724ba4Stsutsui #define BYTE_ORDER LITTLE_ENDIAN 35d3724ba4Stsutsui #endif 36d3724ba4Stsutsui #endif 37d3724ba4Stsutsui #else 38af8f0546Smatt #include <sys/endian.h> 39d3724ba4Stsutsui #endif 40af8f0546Smatt 41*0636a2feSchristos #if !defined(NATIVELABEL_ONLY) 42af8f0546Smatt extern int bswap_p; 43af8f0546Smatt extern u_int maxpartitions; 44af8f0546Smatt 45af8f0546Smatt #define htotarget16(x) (bswap_p ? bswap16(x) : (x)) 46af8f0546Smatt #define target16toh(x) (bswap_p ? bswap16(x) : (x)) 47af8f0546Smatt #define htotarget32(x) (bswap_p ? bswap32(x) : (x)) 48af8f0546Smatt #define target32toh(x) (bswap_p ? bswap32(x) : (x)) 49af8f0546Smatt 50af8f0546Smatt void htotargetlabel(struct disklabel *, const struct disklabel *); 51af8f0546Smatt void targettohlabel(struct disklabel *, const struct disklabel *); 52af8f0546Smatt uint16_t dkcksum_target(struct disklabel *); 53*0636a2feSchristos #else 54*0636a2feSchristos #define htotarget16(x) (x) 55*0636a2feSchristos #define target16toh(x) (x) 56*0636a2feSchristos #define htotarget32(x) (x) 57*0636a2feSchristos #define target32toh(x) (x) 58*0636a2feSchristos 59*0636a2feSchristos #define htotargetlabel(dl, sl) do { *(dl) = *(sl); } while (0) 60*0636a2feSchristos #define targettohlabel(dl, sl) do { *(dl) = *(sl); } while (0) 61*0636a2feSchristos #define dkcksum_target(label) dkcksum(label) 62*0636a2feSchristos #endif /* !NATIVELABEL_ONLY */ 63