]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/gnu/fs/xfs/FreeBSD/xfs_compat.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / gnu / fs / xfs / FreeBSD / xfs_compat.h
1 #ifndef __XFS_COMPAT_H__
2 #define __XFS_COMPAT_H__
3
4 #include <sys/param.h>
5 #include <sys/libkern.h>
6 #include <sys/limits.h>
7 #include <sys/uuid.h>
8 #include <sys/conf.h>
9 #include <sys/sbuf.h>
10 #include <sys/stat.h>
11 #include <sys/ioccom.h>
12 #include <sys/fcntl.h>
13 #include <sys/dirent.h>
14 #include <sys/ktr.h>
15 #include <sys/kdb.h>
16
17 #ifdef _KERNEL
18 #define __KERNEL__
19 #endif
20
21 #define printk printf
22
23 #define MAJOR(x) major(x)
24 #define MINOR(x) minor(x)
25
26 /*
27  * SYSV compatibility types missing in FreeBSD.
28  */
29 typedef unsigned long           ulong;
30 typedef unsigned int            uint;
31 typedef unsigned short          ushort;
32
33 /*
34  * Additional type declarations for XFS.
35  */
36 typedef signed char             __s8;
37 typedef unsigned char           __u8;
38 typedef signed short int        __s16;
39 typedef unsigned short int      __u16;
40 typedef signed int              __s32;
41 typedef unsigned int            __u32;
42 typedef signed long long int    __s64;
43 typedef unsigned long long int  __u64;
44
45 /* linus now has sparse which expects big endian or little endian */
46 typedef __u16 __be16;
47 typedef __u32 __be32;
48 typedef __u64 __be64;
49
50 /*
51  * Linux types with direct FreeBSD conterparts
52  */
53 typedef off_t                   loff_t;
54 typedef struct timespec         timespec_t;
55 typedef struct uuid             uuid_t;
56 typedef struct fid              fid_t;
57 typedef dev_t                   os_dev_t;
58
59 /*
60  *  Linux block devices are device vnodes in FreeBSD.
61  */
62 #define block_device            vnode
63
64 /*
65  *  Get the current CPU ID. 
66  */
67 #define smp_processor_id()      PCPU_GET(cpuid)
68
69 /*
70  * FreeBSD does not have BITS_PER_LONG defined.
71  */
72 #if defined(LONG_BIT)
73 #define BITS_PER_LONG           LONG_BIT
74 #elif defined(__i386__)
75 #define BITS_PER_LONG           32
76 #endif
77
78 #define rol32(x, y)     (((x)<<(y))|((x)>>(32-(y))))
79 /*
80  * boolean_t is enum on Linux, int on FreeBSD.
81  * Provide value defines.
82  */
83 #define B_FALSE                 0
84 #define B_TRUE                  1
85
86 /*
87  * GCC 3.x static branch prediction hints
88  */
89 #if __GNUC__ < 3
90 #define __builtin_expect(x, expected_value) (x)
91 #endif
92
93 #ifndef likely
94 #define likely(x)       __builtin_expect((x), 1)
95 #endif
96
97 #ifndef unlikely
98 #define unlikely(x)     __builtin_expect((x), 0)
99 #endif
100
101 /*
102  * ANSI and GCC extension keywords compatibity
103  */
104 #ifndef inline
105 #define inline __inline__
106 #endif
107
108 #ifndef asm
109 #define asm __asm
110 #endif
111
112 #ifndef typeof
113 #define typeof __typeof
114 #endif
115
116 /*
117  * Miscellaneous limit constants
118  */
119 #define MAX_LFS_FILESIZE        0x7fffffffffffffffLL
120
121 /*
122  * Map simple functions to their FreeBSD kernel equivalents
123  */
124 #ifndef copy_to_user
125 #define copy_to_user(dst, src, len)     copyout((src), (dst), (len))
126 #endif
127
128 #ifndef copy_from_user
129 #define copy_from_user(dst, src, len)   copyin((src), (dst), (len))
130 #endif
131
132 #ifndef barrier
133 #define barrier()       __asm__ __volatile__("": : :"memory")
134 #endif
135
136 /*
137  * Map simple global vairables to FreeBSD kernel equivalents
138  */
139 #if !defined(xfs_physmem)
140 #define xfs_physmem     physmem
141 #endif
142
143 #ifndef HZ
144 #define HZ              hz
145 #endif
146
147 /*
148  * These should be implemented properly for all architectures
149  * we want to support.
150  */
151 #define get_unaligned(ptr)      (*(ptr))
152 #define put_unaligned(val, ptr) ((void)( *(ptr) = (val) ))
153
154 /*
155  * Linux type-safe min/max macros.
156  */
157 #define min_t(type,x,y)         MIN((x),(y)) 
158 #define max_t(type,x,y)         MAX((x),(y)) 
159
160
161 typedef struct mtx xfs_mutex_t;
162 /*
163  * Cedentials manipulation.
164  */
165 #define current_fsuid(credp)    (credp)->cr_uid
166 #define current_fsgid(credp)    (credp)->cr_groups[0]
167
168 #define PAGE_CACHE_SIZE PAGE_SIZE
169
170 #define IS_ERR(err) (err)
171
172 static inline unsigned long ffz(unsigned long val)
173 {
174         return ffsl(~val);
175 }
176
177 #endif /* __XFS_COMPAT_H__ */