summaryrefslogtreecommitdiffstats
path: root/sys/gnu/fs/xfs/FreeBSD/xfs_compat.h
blob: 55a03c96bdad4d6db90bae8a5dd6242b1136096c (plain)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#ifndef __XFS_COMPAT_H__
#define	__XFS_COMPAT_H__

#include <sys/param.h>
#include <sys/libkern.h>
#include <sys/limits.h>
#include <sys/uuid.h>
#include <sys/conf.h>
#include <sys/sbuf.h>
#include <sys/stat.h>
#include <sys/ioccom.h>
#include <sys/fcntl.h>
#include <sys/dirent.h>
#include <sys/ktr.h>
#include <sys/kdb.h>

#ifdef _KERNEL
#define __KERNEL__
#endif

#define printk printf

#define MAJOR(x) major(x)
#define MINOR(x) minor(x)

/*
 * SYSV compatibility types missing in FreeBSD.
 */
typedef unsigned long		ulong;
typedef unsigned int		uint;
typedef unsigned short		ushort;

/*
 * Additional type declarations for XFS.
 */
typedef signed char		__s8;
typedef unsigned char		__u8;
typedef signed short int	__s16;
typedef unsigned short int	__u16;
typedef signed int		__s32;
typedef unsigned int		__u32;
typedef signed long long int	__s64;
typedef unsigned long long int	__u64;

/* linus now has sparse which expects big endian or little endian */
typedef __u16 __be16;
typedef __u32 __be32;
typedef __u64 __be64;

/*
 * Linux types with direct FreeBSD conterparts
 */
typedef off_t			loff_t;
typedef struct timespec		timespec_t;
typedef	struct uuid		uuid_t;
typedef struct fid		fid_t;
typedef dev_t			os_dev_t;

/*
 *  Linux block devices are device vnodes in FreeBSD.
 */
#define	block_device		vnode

/*
 *  Get the current CPU ID. 
 */
#define	smp_processor_id()	PCPU_GET(cpuid)

/*
 * FreeBSD does not have BITS_PER_LONG defined.
 */
#if defined(LONG_BIT)
#define	BITS_PER_LONG		LONG_BIT
#elif defined(__i386__)
#define	BITS_PER_LONG		32
#endif

#define rol32(x, y)	(((x)<<(y))|((x)>>(32-(y))))
/*
 * boolean_t is enum on Linux, int on FreeBSD.
 * Provide value defines.
 */
#define	B_FALSE			0
#define	B_TRUE			1

/*
 * GCC 3.x static branch prediction hints
 */
#if __GNUC__ < 3
#define __builtin_expect(x, expected_value) (x)
#endif

#ifndef likely
#define	likely(x)	__builtin_expect((x), 1)
#endif

#ifndef unlikely
#define	unlikely(x)	__builtin_expect((x), 0)
#endif

/*
 * ANSI and GCC extension keywords compatibity
 */
#ifndef inline
#define	inline __inline__
#endif

#ifndef asm
#define	asm __asm
#endif

#ifndef typeof
#define	typeof __typeof
#endif

/*
 * Miscellaneous limit constants
 */
#define	MAX_LFS_FILESIZE	0x7fffffffffffffffLL

/*
 * Map simple functions to their FreeBSD kernel equivalents
 */
#ifndef copy_to_user
#define	copy_to_user(dst, src, len)	copyout((src), (dst), (len))
#endif

#ifndef copy_from_user
#define	copy_from_user(dst, src, len)	copyin((src), (dst), (len))
#endif

/*
 * Map simple global vairables to FreeBSD kernel equivalents
 */
#if !defined(xfs_physmem)
#define	xfs_physmem	physmem
#endif

#ifndef HZ
#define	HZ		hz
#endif

/*
 * These should be implemented properly for all architectures
 * we want to support.
 */
#define	get_unaligned(ptr)	(*(ptr))
#define	put_unaligned(val, ptr)	((void)( *(ptr) = (val) ))

/*
 * Linux type-safe min/max macros.
 */
#define	min_t(type,x,y)		MIN((x),(y)) 
#define	max_t(type,x,y)		MAX((x),(y)) 


typedef struct mtx xfs_mutex_t;
/*
 * Cedentials manipulation.
 */
#define current_fsuid(credp)	(credp)->cr_uid
#define current_fsgid(credp)	(credp)->cr_groups[0]

#define PAGE_CACHE_SIZE PAGE_SIZE

#define IS_ERR(err) (err)

static inline unsigned long ffz(unsigned long val)
{
        return ffsl(~val);
}

#endif /* __XFS_COMPAT_H__ */
OpenPOWER on IntegriCloud