1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
/*
* compat.h - definitions for compatibility
*/
#ifndef __COMPAT_H__
#define __COMPAT_H__
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#if HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif /* HAVE_SYS_IOCTL_H */
#if HAVE_TIME_H
#include <time.h>
#endif /* HAVE_TIME_H */
#include <endian.h>
#include <byteswap.h>
/* GCC related declarations */
#ifdef __GNUC__
#define GCC_VERSION (__GNUC__ * 10000 \
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__)
#endif
#if GCC_VERSION < 29600
#define __builtin_expect(x, e) (x)
#endif
/* Old linux/magic.h may not have the file system magic number of NILFS */
#ifndef NILFS_SUPER_MAGIC
#define NILFS_SUPER_MAGIC 0x3434 /* NILFS filesystem magic number */
#endif
/* Sizes of integral types */
#ifndef U64_MAX
#define U64_MAX 18446744073709551615LL /* __u64 (or u64) max */
#endif
#ifndef S64_MAX
#define S64_MAX 9223372036854775807LL /* __s64 (or s64) max */
#endif
/* Ioctls for freeze and thaw */
#ifndef FIFREEZE
#define FIFREEZE _IOWR('X', 119, int)
#define FITHAW _IOWR('X', 120, int)
#endif
/* Linux specific system clocks */
#ifndef CLOCK_REALTIME_COARSE
#define CLOCK_REALTIME_COARSE 5 /* Supported on Linux 2.6.32 or later */
#endif
#ifndef CLOCK_MONOTONIC_COARSE
#define CLOCK_MONOTONIC_COARSE 6 /* Supported on Linux 2.6.32 or later */
#endif
#ifndef CLOCK_BOOTTIME
#define CLOCK_BOOTTIME 7 /* Supported on Linux 2.6.39 or later */
#endif
/* Operations on timespecs */
#ifndef timespecadd
#define timespecadd(a, b, res) \
do { \
(res)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
(res)->tv_nsec = (a)->tv_nsec + (b)->tv_nsec; \
if ((res)->tv_nsec >= 1000000000L) { \
(res)->tv_sec++; \
(res)->tv_nsec -= 1000000000L; \
} \
} while (0)
#endif
#ifndef timespecsub
#define timespecsub(a, b, res) \
do { \
(res)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(res)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \
if ((res)->tv_nsec < 0) { \
(res)->tv_sec--; \
(res)->tv_nsec += 1000000000L; \
} \
} while (0)
#endif
#ifndef timespecclear
#define timespecclear(ts) \
do { (ts)->tv_sec = 0; (ts)->tv_nsec = 0; } while (0)
#endif
#ifndef timespecisset
#define timespecisset(ts) ((ts)->tv_sec || (ts)->tv_nsec)
#endif
#ifndef timespeccmp
#define timespeccmp(a, b, cmp) \
(((a)->tv_sec == (b)->tv_sec) ? \
((a)->tv_nsec cmp (b)->tv_nsec) : \
((a)->tv_sec cmp (b)->tv_sec))
#endif
/* Byte order */
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define le16_to_cpu(x) ((__u16)(x))
#define le32_to_cpu(x) ((__u32)(x))
#define le64_to_cpu(x) ((__u64)(x))
#define cpu_to_le16(x) ((__u16)(x))
#define cpu_to_le32(x) ((__u32)(x))
#define cpu_to_le64(x) ((__u64)(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)
#elif __BYTE_ORDER == __BIG_ENDIAN
#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) ((__u16)(x))
#define be32_to_cpu(x) ((__u32)(x))
#define be64_to_cpu(x) ((__u64)(x))
#define cpu_to_be16(x) ((__u16)(x))
#define cpu_to_be32(x) ((__u32)(x))
#define cpu_to_be64(x) ((__u64)(x))
#else
#error "unknown endian"
#endif /* __BYTE_ORDER */
#if HAVE_LIMITS_H
#include <limits.h> /* PATH_MAX */
#endif /* HAVE_LIMITS_H */
#ifndef PATH_MAX
#define PATH_MAX 8192
#endif
#if HAVE_SYS_SYSMACROS_H
#include <sys/sysmacros.h> /* major(), minor() */
#else
#ifndef major
#define major(dev) gnu_dev_major(dev)
#define minor(dev) gnu_dev_minor(dev)
#endif
#endif /* HAVE_SYS_SYSMACROS_H */
#endif /* __COMPAT_H__ */
|