endians.h revision 7e7bd3dccbfe8f79e25e5c1554b5bc3a9aaca321
/*
* endians.h - Definitions related to handling of byte ordering. Part of the
* Linux-NTFS project.
*
* Copyright (c) 2000-2005 Anton Altaparmakov
* Copyright (c) 2007 Yura Pakhuchiy
*
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (in the main directory of the Linux-NTFS
* distribution in the file COPYING); if not, write to the Free Software
* Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _NTFS_ENDIANS_H
#define _NTFS_ENDIANS_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/*
* Notes:
* We define the conversion functions including typecasts since the
* defaults don't necessarily perform appropriate typecasts.
* Also, using our own functions means that we can change them if it
* turns out that we do need to use the unaligned access macros on
* architectures requiring aligned memory accesses...
*/
#ifdef HAVE_ENDIAN_H
#include <endian.h>
#endif
#ifdef HAVE_SYS_ENDIAN_H
#endif
#ifdef HAVE_MACHINE_ENDIAN_H
#endif
#ifdef HAVE_SYS_BYTEORDER_H
#include <sys/byteorder.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#endif
#ifndef __BYTE_ORDER
# if defined(_BYTE_ORDER)
# define __BYTE_ORDER _BYTE_ORDER
# define __LITTLE_ENDIAN _LITTLE_ENDIAN
# define __BIG_ENDIAN _BIG_ENDIAN
# elif defined(BYTE_ORDER)
# define __BYTE_ORDER BYTE_ORDER
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __BIG_ENDIAN BIG_ENDIAN
# elif defined(__BYTE_ORDER__)
# define __BYTE_ORDER __BYTE_ORDER__
# define __LITTLE_ENDIAN __LITTLE_ENDIAN__
# define __BIG_ENDIAN __BIG_ENDIAN__
defined(WORDS_LITTLEENDIAN)
# define __BYTE_ORDER 1
# define __LITTLE_ENDIAN 1
# define __BIG_ENDIAN 0
defined(WORDS_BIGENDIAN)
# define __BYTE_ORDER 0
# define __LITTLE_ENDIAN 1
# define __BIG_ENDIAN 0
# else
# error "__BYTE_ORDER is not defined."
# endif
#endif
#define __ntfs_bswap_constant_16(x) \
#define __ntfs_bswap_constant_32(x) \
#define __ntfs_bswap_constant_64(x) \
#ifdef HAVE_BYTESWAP_H
# include <byteswap.h>
#else
# define bswap_16(x) __ntfs_bswap_constant_16(x)
# define bswap_32(x) __ntfs_bswap_constant_32(x)
# define bswap_64(x) __ntfs_bswap_constant_64(x)
#endif
#define __constant_cpu_to_le16(x) \
#define __constant_cpu_to_le32(x) \
#define __constant_cpu_to_le64(x) \
#else
#error "You must define __BYTE_ORDER to be __LITTLE_ENDIAN or __BIG_ENDIAN."
#endif
/* Unsigned from LE to CPU conversion. */
/* Signed from LE to CPU conversion. */
/* Unsigned from CPU to LE conversion. */
/* Signed from CPU to LE conversion. */
/* Constant endianness conversion defines. */
#ifdef __CHECKER__
static void ntfs_endian_self_test(void)
{
/* Should not generate warnings. */
/*
* TODO: Need some how to test that warnings are actually generated,
* but without flooding output with them and vice-versa print warning
* in case if some one warning is not triggered, but should. (Yura)
*
* I think it can only be done in a ./configure like script / shell
* script that will compile known good and known bad code and pipe the
* output from sparse to a file, then grep the file for the wanted
* "Tests: FAILED" or whatever. And you can then hook that into a
* "make test" make target or similar so it is only done when one
* wants to do it... (Anton)
*
* Also we can look on sparse self test script. (Yura)
*/
}
#endif
#endif /* defined _NTFS_ENDIANS_H */