1169695Skan#ifndef __XFS_COMPAT_H__ 2169695Skan#define __XFS_COMPAT_H__ 3169695Skan 4169695Skan#include <sys/param.h> 5169695Skan#include <sys/libkern.h> 6169695Skan#include <sys/limits.h> 7169695Skan#include <sys/uuid.h> 8169695Skan#include <sys/conf.h> 9169695Skan#include <sys/sbuf.h> 10169695Skan#include <sys/stat.h> 11169695Skan#include <sys/ioccom.h> 12169695Skan#include <sys/fcntl.h> 13169695Skan#include <sys/dirent.h> 14169695Skan#include <sys/ktr.h> 15169695Skan#include <sys/kdb.h> 16169695Skan 17169695Skan#ifdef _KERNEL 18169695Skan#define __KERNEL__ 19169695Skan#endif 20169695Skan 21169695Skan#define printk printf 22169695Skan 23169695Skan#define MAJOR(x) major(x) 24169695Skan#define MINOR(x) minor(x) 25169695Skan 26169695Skan/* 27169695Skan * SYSV compatibility types missing in FreeBSD. 28169695Skan */ 29169695Skantypedef unsigned long ulong; 30169695Skantypedef unsigned int uint; 31169695Skantypedef unsigned short ushort; 32169695Skan 33169695Skan/* 34169695Skan * Additional type declarations for XFS. 35169695Skan */ 36169695Skantypedef signed char __s8; 37169695Skantypedef unsigned char __u8; 38169695Skantypedef signed short int __s16; 39169695Skantypedef unsigned short int __u16; 40169695Skantypedef signed int __s32; 41169695Skantypedef unsigned int __u32; 42169695Skantypedef signed long long int __s64; 43169695Skantypedef unsigned long long int __u64; 44169695Skan 45169695Skan/* linus now has sparse which expects big endian or little endian */ 46169695Skantypedef __u16 __be16; 47169695Skantypedef __u32 __be32; 48169695Skantypedef __u64 __be64; 49169695Skan 50169695Skan/* 51169695Skan * Linux types with direct FreeBSD conterparts 52169695Skan */ 53169695Skantypedef off_t loff_t; 54169695Skantypedef struct timespec timespec_t; 55169695Skantypedef struct uuid uuid_t; 56169695Skantypedef struct fid fid_t; 57169695Skantypedef dev_t os_dev_t; 58169695Skan 59169695Skan/* 60169695Skan * Linux block devices are device vnodes in FreeBSD. 61169695Skan */ 62169695Skan#define block_device vnode 63169695Skan 64169695Skan/* 65169695Skan * Get the current CPU ID. 66169695Skan */ 67169695Skan#define smp_processor_id() PCPU_GET(cpuid) 68169695Skan 69169695Skan/* 70169695Skan * FreeBSD does not have BITS_PER_LONG defined. 71169695Skan */ 72169695Skan#if defined(LONG_BIT) 73169695Skan#define BITS_PER_LONG LONG_BIT 74169695Skan#elif defined(__i386__) 75169695Skan#define BITS_PER_LONG 32 76169695Skan#endif 77169695Skan 78169695Skan#define rol32(x, y) (((x)<<(y))|((x)>>(32-(y)))) 79169695Skan/* 80169695Skan * boolean_t is enum on Linux, int on FreeBSD. 81169695Skan * Provide value defines. 82169695Skan */ 83169695Skan#define B_FALSE 0 84169695Skan#define B_TRUE 1 85169695Skan 86169695Skan/* 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/* 133 * Map simple global vairables to FreeBSD kernel equivalents 134 */ 135#if !defined(xfs_physmem) 136#define xfs_physmem physmem 137#endif 138 139#ifndef HZ 140#define HZ hz 141#endif 142 143/* 144 * These should be implemented properly for all architectures 145 * we want to support. 146 */ 147#define get_unaligned(ptr) (*(ptr)) 148#define put_unaligned(val, ptr) ((void)( *(ptr) = (val) )) 149 150/* 151 * Linux type-safe min/max macros. 152 */ 153#define min_t(type,x,y) MIN((x),(y)) 154#define max_t(type,x,y) MAX((x),(y)) 155 156 157typedef struct mtx xfs_mutex_t; 158/* 159 * Cedentials manipulation. 160 */ 161#define current_fsuid(credp) (credp)->cr_uid 162#define current_fsgid(credp) (credp)->cr_groups[0] 163 164#define PAGE_CACHE_SIZE PAGE_SIZE 165 166#define IS_ERR(err) (err) 167 168static inline unsigned long ffz(unsigned long val) 169{ 170 return ffsl(~val); 171} 172 173#endif /* __XFS_COMPAT_H__ */ 174