2001-10-08 13:45:16 +04:00
/*
2004-03-30 23:35:44 +04:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
2007-08-21 00:55:30 +04:00
* Copyright ( C ) 2004 - 2005 Red Hat , Inc . All rights reserved .
2001-10-08 13:45:16 +04:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
2001-10-08 13:45:16 +04:00
*
2004-03-30 23:35:44 +04:00
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
2007-08-21 00:55:30 +04:00
* of the GNU Lesser General Public License v .2 .1 .
2004-03-30 23:35:44 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2004-03-30 23:35:44 +04:00
* along with this program ; if not , write to the Free Software Foundation ,
2016-01-21 13:49:46 +03:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA
2001-10-08 13:45:16 +04:00
*/
# ifndef _LVM_XLATE_H
# define _LVM_XLATE_H
2013-11-13 17:56:29 +04:00
# ifdef __linux__
2004-09-02 17:53:25 +04:00
# include <endian.h>
# include <byteswap.h>
# else
# include <machine / endian.h>
# define bswap_16(x) (((x) & 0x00ffU) << 8 | \
( ( x ) & 0xff00U ) > > 8 )
# define bswap_32(x) (((x) & 0x000000ffU) << 24 | \
( ( x ) & 0xff000000U ) > > 24 | \
( ( x ) & 0x0000ff00U ) < < 8 | \
( ( x ) & 0x00ff0000U ) > > 8 )
2005-01-20 21:13:17 +03:00
# define bswap_64(x) (((x) & 0x00000000000000ffULL) << 56 | \
( ( x ) & 0xff00000000000000ULL ) > > 56 | \
( ( x ) & 0x000000000000ff00ULL ) < < 40 | \
( ( x ) & 0x00ff000000000000ULL ) > > 40 | \
( ( x ) & 0x0000000000ff0000ULL ) < < 24 | \
( ( x ) & 0x0000ff0000000000ULL ) > > 24 | \
( ( x ) & 0x00000000ff000000ULL ) < < 8 | \
( ( x ) & 0x000000ff00000000ULL ) > > 8 )
2004-09-02 17:53:25 +04:00
# endif
# if BYTE_ORDER == LITTLE_ENDIAN
2015-06-16 17:30:14 +03:00
/* New clearer variants. */
# define le16_to_cpu(x) (x)
# define le32_to_cpu(x) (x)
# define le64_to_cpu(x) (x)
# define cpu_to_le16(x) (x)
# define cpu_to_le32(x) (x)
# define cpu_to_le64(x) (x)
# define be16_to_cpu(x) bswap_16(x)
# define be32_to_cpu(x) bswap_32(x)
# define be64_to_cpu(x) bswap_64(x)
# define cpu_to_be16(x) bswap_16(x)
# define cpu_to_be32(x) bswap_32(x)
# define cpu_to_be64(x) bswap_64(x)
/* Old alternative variants. */
# define xlate16(x) (x)
# define xlate32(x) (x)
# define xlate64(x) (x)
# define xlate16_be(x) bswap_16(x)
# define xlate32_be(x) bswap_32(x)
# define xlate64_be(x) bswap_64(x)
2004-09-02 17:53:25 +04:00
# elif BYTE_ORDER == BIG_ENDIAN
2015-06-16 17:30:14 +03:00
/* New clearer variants. */
# define le16_to_cpu(x) bswap_16(x)
# define le32_to_cpu(x) bswap_32(x)
# define le64_to_cpu(x) bswap_64(x)
# define cpu_to_le16(x) bswap_16(x)
# define cpu_to_le32(x) bswap_32(x)
# define cpu_to_le64(x) bswap_64(x)
# define be16_to_cpu(x) (x)
# define be32_to_cpu(x) (x)
# define be64_to_cpu(x) (x)
# define cpu_to_be16(x) (x)
# define cpu_to_be32(x) (x)
# define cpu_to_be64(x) (x)
/* Old alternative variants. */
# define xlate16(x) bswap_16(x)
# define xlate32(x) bswap_32(x)
# define xlate64(x) bswap_64(x)
# define xlate16_be(x) (x)
# define xlate32_be(x) (x)
# define xlate64_be(x) (x)
2004-09-02 17:53:25 +04:00
# else
2015-06-16 17:30:14 +03:00
# include <asm/byteorder.h>
/* New clearer variants. */
# define le16_to_cpu(x) __le16_to_cpu(x)
# define le32_to_cpu(x) __le32_to_cpu(x)
# define le64_to_cpu(x) __le64_to_cpu(x)
# define cpu_to_le16(x) __cpu_to_le16(x)
# define cpu_to_le32(x) __cpu_to_le32(x)
# define cpu_to_le64(x) __cpu_to_le64(x)
# define be16_to_cpu(x) __be16_to_cpu(x)
# define be32_to_cpu(x) __be32_to_cpu(x)
# define be64_to_cpu(x) __be64_to_cpu(x)
# define cpu_to_be16(x) __cpu_to_be16(x)
# define cpu_to_be32(x) __cpu_to_be32(x)
# define cpu_to_be64(x) __cpu_to_be64(x)
/* Old alternative variants. */
# define xlate16(x) __cpu_to_le16(x)
# define xlate32(x) __cpu_to_le32(x)
# define xlate64(x) __cpu_to_le64(x)
# define xlate16_be(x) __cpu_to_be16(x)
# define xlate32_be(x) __cpu_to_be32(x)
# define xlate64_be(x) __cpu_to_be64(x)
2003-07-05 02:34:56 +04:00
# endif
2002-05-07 19:28:59 +04:00
2001-10-08 13:45:16 +04:00
# endif