~wb-munzinger/+junk/ocfs2-tools

« back to all changes in this revision

Viewing changes to include/ocfs2/byteorder.h

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2009-07-06 07:26:30 UTC
  • mfrom: (1.1.7 upstream) (0.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090706072630-59335sl51k3rvu74
Tags: 1.4.2-1
* New upstream release (Closes: #535471).
* Drop patch for limits.h, included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c; c-basic-offset: 8; -*-
 
2
 * vim: noexpandtab sw=8 ts=8 sts=0:
 
3
 *
 
4
 * byteorder.h
 
5
 *
 
6
 * Byteswapping!
 
7
 *
 
8
 * Copyright (C) 2004 Oracle.  All rights reserved.
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or
 
11
 * modify it under the terms of the GNU General Public
 
12
 * License, version 2,  as published by the Free Software Foundation.
 
13
 * 
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
 * General Public License for more details.
 
18
 * 
 
19
 * You should have received a copy of the GNU General Public
 
20
 * License along with this program; if not, write to the
 
21
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
22
 * Boston, MA 021110-1307, USA.
 
23
 *
 
24
 * Authors: Joel Becker
 
25
 */
 
26
 
 
27
#ifndef _BYTEORDER_H
 
28
#define _BYTEORDER_H
 
29
 
 
30
 
 
31
#include <endian.h>
 
32
#include <byteswap.h>
 
33
#include <stdint.h>
 
34
 
 
35
/*
 
36
 * All OCFS2 on-disk values are in little endian, except for jbd's journal
 
37
 * fields which it takes care of itself.
 
38
 */
 
39
 
 
40
#if __BYTE_ORDER == __LITTLE_ENDIAN
 
41
#define cpu_is_little_endian    1
 
42
# ifndef cpu_to_le16
 
43
#  define cpu_to_le16(x) ((uint16_t)(x))
 
44
# endif
 
45
# ifndef le16_to_cpu
 
46
#  define le16_to_cpu(x) ((uint16_t)(x))
 
47
# endif
 
48
# ifndef cpu_to_le32
 
49
#  define cpu_to_le32(x) ((uint32_t)(x))
 
50
# endif
 
51
# ifndef le32_to_cpu
 
52
#  define le32_to_cpu(x) ((uint32_t)(x))
 
53
# endif
 
54
# ifndef cpu_to_le64
 
55
#  define cpu_to_le64(x) ((uint64_t)(x))
 
56
# endif
 
57
# ifndef le64_to_cpu
 
58
#  define le64_to_cpu(x) ((uint64_t)(x))
 
59
# endif
 
60
# ifndef cpu_to_be16
 
61
#  define cpu_to_be16(x) ((uint16_t)bswap_16(x))
 
62
# endif
 
63
# ifndef be16_to_cpu
 
64
#  define be16_to_cpu(x) ((uint16_t)bswap_16(x))
 
65
# endif
 
66
# ifndef cpu_to_be32
 
67
#  define cpu_to_be32(x) ((uint32_t)bswap_32(x))
 
68
# endif
 
69
# ifndef be32_to_cpu
 
70
#  define be32_to_cpu(x) ((uint32_t)bswap_32(x))
 
71
# endif
 
72
# ifndef cpu_to_be64
 
73
#  define cpu_to_be64(x) ((uint64_t)bswap_64(x))
 
74
# endif
 
75
# ifndef be64_to_cpu
 
76
#  define be64_to_cpu(x) ((uint64_t)bswap_64(x))
 
77
# endif
 
78
#elif __BYTE_ORDER == __BIG_ENDIAN
 
79
#define cpu_is_little_endian    0
 
80
# ifndef cpu_to_le16
 
81
#  define cpu_to_le16(x) ((uint16_t)bswap_16(x))
 
82
# endif
 
83
# ifndef le16_to_cpu
 
84
#  define le16_to_cpu(x) ((uint16_t)bswap_16(x))
 
85
# endif
 
86
# ifndef cpu_to_le32
 
87
#  define cpu_to_le32(x) ((uint32_t)bswap_32(x))
 
88
# endif
 
89
# ifndef le32_to_cpu
 
90
#  define le32_to_cpu(x) ((uint32_t)bswap_32(x))
 
91
# endif
 
92
# ifndef cpu_to_le64
 
93
#  define cpu_to_le64(x) ((uint64_t)bswap_64(x))
 
94
# endif
 
95
# ifndef le64_to_cpu
 
96
#  define le64_to_cpu(x) ((uint64_t)bswap_64(x))
 
97
# endif
 
98
# ifndef cpu_to_be16
 
99
#  define cpu_to_be16(x) ((uint16_t)(x))
 
100
# endif
 
101
# ifndef be16_to_cpu
 
102
#  define be16_to_cpu(x) ((uint16_t)(x))
 
103
# endif
 
104
# ifndef cpu_to_be32
 
105
#  define cpu_to_be32(x) ((uint32_t)(x))
 
106
# endif
 
107
# ifndef be32_to_cpu
 
108
#  define be32_to_cpu(x) ((uint32_t)(x))
 
109
# endif
 
110
# ifndef cpu_to_be64
 
111
#  define cpu_to_be64(x) ((uint64_t)(x))
 
112
# endif
 
113
# ifndef be64_to_cpu
 
114
#  define be64_to_cpu(x) ((uint64_t)(x))
 
115
# endif
 
116
#else
 
117
# error Invalid byte order __BYTE_ORDER
 
118
#endif  /* __BYTE_ORDER */
 
119
 
 
120
#define cpu_is_big_endian       (!cpu_is_little_endian)
 
121
 
 
122
#endif  /* _BYTEORDER_H */