Tizen 2.1 base
[external/device-mapper.git] / lib / mm / xlate.h
1 /*
2  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.  
3  * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4  *
5  * This file is part of LVM2.
6  *
7  * This copyrighted material is made available to anyone wishing to use,
8  * modify, copy, or redistribute it subject to the terms and conditions
9  * of the GNU Lesser General Public License v.2.1.
10  *
11  * You should have received a copy of the GNU Lesser General Public License
12  * along with this program; if not, write to the Free Software Foundation,
13  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14  */
15
16 #ifndef _LVM_XLATE_H
17 #define _LVM_XLATE_H
18
19 #ifdef linux
20 #  include <endian.h>
21 #  include <byteswap.h>
22 #else
23 #  include <machine/endian.h>
24 #  define bswap_16(x) (((x) & 0x00ffU) << 8 | \
25                        ((x) & 0xff00U) >> 8)
26 #  define bswap_32(x) (((x) & 0x000000ffU) << 24 | \
27                        ((x) & 0xff000000U) >> 24 | \
28                        ((x) & 0x0000ff00U) << 8  | \
29                        ((x) & 0x00ff0000U) >> 8)
30 #  define bswap_64(x) (((x) & 0x00000000000000ffULL) << 56 | \
31                        ((x) & 0xff00000000000000ULL) >> 56 | \
32                        ((x) & 0x000000000000ff00ULL) << 40 | \
33                        ((x) & 0x00ff000000000000ULL) >> 40 | \
34                        ((x) & 0x0000000000ff0000ULL) << 24 | \
35                        ((x) & 0x0000ff0000000000ULL) >> 24 | \
36                        ((x) & 0x00000000ff000000ULL) << 8 | \
37                        ((x) & 0x000000ff00000000ULL) >> 8)
38 #endif
39
40 #if BYTE_ORDER == LITTLE_ENDIAN
41 #  define xlate16(x) (x)
42 #  define xlate32(x) (x)
43 #  define xlate64(x) (x)
44 #  define xlate16_be(x) bswap_16(x)
45 #  define xlate32_be(x) bswap_32(x)
46 #  define xlate64_be(x) bswap_64(x)
47 #elif BYTE_ORDER == BIG_ENDIAN
48 #  define xlate16(x) bswap_16(x)
49 #  define xlate32(x) bswap_32(x)
50 #  define xlate64(x) bswap_64(x)
51 #  define xlate16_be(x) (x)
52 #  define xlate32_be(x) (x)
53 #  define xlate64_be(x) (x)
54 #else
55 #  include <asm/byteorder.h>
56 #  define xlate16(x) __cpu_to_le16((x))
57 #  define xlate32(x) __cpu_to_le32((x))
58 #  define xlate64(x) __cpu_to_le64((x))
59 #  define xlate16_be(x) __cpu_to_be16((x))
60 #  define xlate32_be(x) __cpu_to_be32((x))
61 #  define xlate64_be(x) __cpu_to_be64((x))
62 #endif
63
64 #endif