xfs_linux.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. /*
  2. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef __XFS_LINUX__
  19. #define __XFS_LINUX__
  20. #include <linux/types.h>
  21. /*
  22. * XFS_BIG_BLKNOS needs block layer disk addresses to be 64 bits.
  23. * XFS_BIG_INUMS requires XFS_BIG_BLKNOS to be set.
  24. */
  25. #if defined(CONFIG_LBDAF) || (BITS_PER_LONG == 64)
  26. # define XFS_BIG_BLKNOS 1
  27. # define XFS_BIG_INUMS 1
  28. #else
  29. # define XFS_BIG_BLKNOS 0
  30. # define XFS_BIG_INUMS 0
  31. #endif
  32. /*
  33. * Kernel specific type declarations for XFS
  34. */
  35. typedef signed char __int8_t;
  36. typedef unsigned char __uint8_t;
  37. typedef signed short int __int16_t;
  38. typedef unsigned short int __uint16_t;
  39. typedef signed int __int32_t;
  40. typedef unsigned int __uint32_t;
  41. typedef signed long long int __int64_t;
  42. typedef unsigned long long int __uint64_t;
  43. typedef __uint32_t inst_t; /* an instruction */
  44. typedef __s64 xfs_off_t; /* <file offset> type */
  45. typedef unsigned long long xfs_ino_t; /* <inode> type */
  46. typedef __s64 xfs_daddr_t; /* <disk address> type */
  47. typedef char * xfs_caddr_t; /* <core address> type */
  48. typedef __u32 xfs_dev_t;
  49. typedef __u32 xfs_nlink_t;
  50. /* __psint_t is the same size as a pointer */
  51. #if (BITS_PER_LONG == 32)
  52. typedef __int32_t __psint_t;
  53. typedef __uint32_t __psunsigned_t;
  54. #elif (BITS_PER_LONG == 64)
  55. typedef __int64_t __psint_t;
  56. typedef __uint64_t __psunsigned_t;
  57. #else
  58. #error BITS_PER_LONG must be 32 or 64
  59. #endif
  60. #include "xfs_types.h"
  61. #include "kmem.h"
  62. #include "mrlock.h"
  63. #include "time.h"
  64. #include "uuid.h"
  65. #include <linux/semaphore.h>
  66. #include <linux/mm.h>
  67. #include <linux/kernel.h>
  68. #include <linux/blkdev.h>
  69. #include <linux/slab.h>
  70. #include <linux/crc32c.h>
  71. #include <linux/module.h>
  72. #include <linux/mutex.h>
  73. #include <linux/file.h>
  74. #include <linux/swap.h>
  75. #include <linux/errno.h>
  76. #include <linux/sched.h>
  77. #include <linux/bitops.h>
  78. #include <linux/major.h>
  79. #include <linux/pagemap.h>
  80. #include <linux/vfs.h>
  81. #include <linux/seq_file.h>
  82. #include <linux/init.h>
  83. #include <linux/list.h>
  84. #include <linux/proc_fs.h>
  85. #include <linux/sort.h>
  86. #include <linux/cpu.h>
  87. #include <linux/notifier.h>
  88. #include <linux/delay.h>
  89. #include <linux/log2.h>
  90. #include <linux/spinlock.h>
  91. #include <linux/random.h>
  92. #include <linux/ctype.h>
  93. #include <linux/writeback.h>
  94. #include <linux/capability.h>
  95. #include <linux/kthread.h>
  96. #include <linux/freezer.h>
  97. #include <linux/list_sort.h>
  98. #include <linux/ratelimit.h>
  99. #include <asm/page.h>
  100. #include <asm/div64.h>
  101. #include <asm/param.h>
  102. #include <asm/uaccess.h>
  103. #include <asm/byteorder.h>
  104. #include <asm/unaligned.h>
  105. #include "xfs_vnode.h"
  106. #include "xfs_stats.h"
  107. #include "xfs_sysctl.h"
  108. #include "xfs_iops.h"
  109. #include "xfs_aops.h"
  110. #include "xfs_super.h"
  111. #include "xfs_buf.h"
  112. #include "xfs_message.h"
  113. #ifdef __BIG_ENDIAN
  114. #define XFS_NATIVE_HOST 1
  115. #else
  116. #undef XFS_NATIVE_HOST
  117. #endif
  118. /*
  119. * Feature macros (disable/enable)
  120. */
  121. #ifdef CONFIG_SMP
  122. #define HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */
  123. #else
  124. #undef HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */
  125. #endif
  126. #define irix_sgid_inherit xfs_params.sgid_inherit.val
  127. #define irix_symlink_mode xfs_params.symlink_mode.val
  128. #define xfs_panic_mask xfs_params.panic_mask.val
  129. #define xfs_error_level xfs_params.error_level.val
  130. #define xfs_syncd_centisecs xfs_params.syncd_timer.val
  131. #define xfs_stats_clear xfs_params.stats_clear.val
  132. #define xfs_inherit_sync xfs_params.inherit_sync.val
  133. #define xfs_inherit_nodump xfs_params.inherit_nodump.val
  134. #define xfs_inherit_noatime xfs_params.inherit_noatim.val
  135. #define xfs_inherit_nosymlinks xfs_params.inherit_nosym.val
  136. #define xfs_rotorstep xfs_params.rotorstep.val
  137. #define xfs_inherit_nodefrag xfs_params.inherit_nodfrg.val
  138. #define xfs_fstrm_centisecs xfs_params.fstrm_timer.val
  139. #define xfs_eofb_secs xfs_params.eofb_timer.val
  140. #define current_cpu() (raw_smp_processor_id())
  141. #define current_pid() (current->pid)
  142. #define current_test_flags(f) (current->flags & (f))
  143. #define current_set_flags_nested(sp, f) \
  144. (*(sp) = current->flags, current->flags |= (f))
  145. #define current_clear_flags_nested(sp, f) \
  146. (*(sp) = current->flags, current->flags &= ~(f))
  147. #define current_restore_flags_nested(sp, f) \
  148. (current->flags = ((current->flags & ~(f)) | (*(sp) & (f))))
  149. #define spinlock_destroy(lock)
  150. #define NBBY 8 /* number of bits per byte */
  151. /*
  152. * Size of block device i/o is parameterized here.
  153. * Currently the system supports page-sized i/o.
  154. */
  155. #define BLKDEV_IOSHIFT PAGE_CACHE_SHIFT
  156. #define BLKDEV_IOSIZE (1<<BLKDEV_IOSHIFT)
  157. /* number of BB's per block device block */
  158. #define BLKDEV_BB BTOBB(BLKDEV_IOSIZE)
  159. #define ENOATTR ENODATA /* Attribute not found */
  160. #define EWRONGFS EINVAL /* Mount with wrong filesystem type */
  161. #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
  162. #define SYNCHRONIZE() barrier()
  163. #define __return_address __builtin_return_address(0)
  164. #define XFS_PROJID_DEFAULT 0
  165. #define MAXPATHLEN 1024
  166. #define MIN(a,b) (min(a,b))
  167. #define MAX(a,b) (max(a,b))
  168. #define howmany(x, y) (((x)+((y)-1))/(y))
  169. /* Kernel uid/gid conversion. These are used to convert to/from the on disk
  170. * uid_t/gid_t types to the kuid_t/kgid_t types that the kernel uses internally.
  171. * The conversion here is type only, the value will remain the same since we
  172. * are converting to the init_user_ns. The uid is later mapped to a particular
  173. * user namespace value when crossing the kernel/user boundary.
  174. */
  175. static inline __uint32_t xfs_kuid_to_uid(kuid_t uid)
  176. {
  177. return from_kuid(&init_user_ns, uid);
  178. }
  179. static inline kuid_t xfs_uid_to_kuid(__uint32_t uid)
  180. {
  181. return make_kuid(&init_user_ns, uid);
  182. }
  183. static inline __uint32_t xfs_kgid_to_gid(kgid_t gid)
  184. {
  185. return from_kgid(&init_user_ns, gid);
  186. }
  187. static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
  188. {
  189. return make_kgid(&init_user_ns, gid);
  190. }
  191. /*
  192. * Various platform dependent calls that don't fit anywhere else
  193. */
  194. #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL)
  195. #define xfs_stack_trace() dump_stack()
  196. /* Move the kernel do_div definition off to one side */
  197. #if defined __i386__
  198. /* For ia32 we need to pull some tricks to get past various versions
  199. * of the compiler which do not like us using do_div in the middle
  200. * of large functions.
  201. */
  202. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  203. {
  204. __u32 mod;
  205. switch (n) {
  206. case 4:
  207. mod = *(__u32 *)a % b;
  208. *(__u32 *)a = *(__u32 *)a / b;
  209. return mod;
  210. case 8:
  211. {
  212. unsigned long __upper, __low, __high, __mod;
  213. __u64 c = *(__u64 *)a;
  214. __upper = __high = c >> 32;
  215. __low = c;
  216. if (__high) {
  217. __upper = __high % (b);
  218. __high = __high / (b);
  219. }
  220. asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
  221. asm("":"=A" (c):"a" (__low),"d" (__high));
  222. *(__u64 *)a = c;
  223. return __mod;
  224. }
  225. }
  226. /* NOTREACHED */
  227. return 0;
  228. }
  229. /* Side effect free 64 bit mod operation */
  230. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  231. {
  232. switch (n) {
  233. case 4:
  234. return *(__u32 *)a % b;
  235. case 8:
  236. {
  237. unsigned long __upper, __low, __high, __mod;
  238. __u64 c = *(__u64 *)a;
  239. __upper = __high = c >> 32;
  240. __low = c;
  241. if (__high) {
  242. __upper = __high % (b);
  243. __high = __high / (b);
  244. }
  245. asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
  246. asm("":"=A" (c):"a" (__low),"d" (__high));
  247. return __mod;
  248. }
  249. }
  250. /* NOTREACHED */
  251. return 0;
  252. }
  253. #else
  254. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  255. {
  256. __u32 mod;
  257. switch (n) {
  258. case 4:
  259. mod = *(__u32 *)a % b;
  260. *(__u32 *)a = *(__u32 *)a / b;
  261. return mod;
  262. case 8:
  263. mod = do_div(*(__u64 *)a, b);
  264. return mod;
  265. }
  266. /* NOTREACHED */
  267. return 0;
  268. }
  269. /* Side effect free 64 bit mod operation */
  270. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  271. {
  272. switch (n) {
  273. case 4:
  274. return *(__u32 *)a % b;
  275. case 8:
  276. {
  277. __u64 c = *(__u64 *)a;
  278. return do_div(c, b);
  279. }
  280. }
  281. /* NOTREACHED */
  282. return 0;
  283. }
  284. #endif
  285. #undef do_div
  286. #define do_div(a, b) xfs_do_div(&(a), (b), sizeof(a))
  287. #define do_mod(a, b) xfs_do_mod(&(a), (b), sizeof(a))
  288. static inline __uint64_t roundup_64(__uint64_t x, __uint32_t y)
  289. {
  290. x += y - 1;
  291. do_div(x, y);
  292. return(x * y);
  293. }
  294. static inline __uint64_t howmany_64(__uint64_t x, __uint32_t y)
  295. {
  296. x += y - 1;
  297. do_div(x, y);
  298. return x;
  299. }
  300. /* ARM old ABI has some weird alignment/padding */
  301. #if defined(__arm__) && !defined(__ARM_EABI__)
  302. #define __arch_pack __attribute__((packed))
  303. #else
  304. #define __arch_pack
  305. #endif
  306. #define ASSERT_ALWAYS(expr) \
  307. (unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
  308. #ifdef DEBUG
  309. #define ASSERT(expr) \
  310. (unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
  311. #ifndef STATIC
  312. # define STATIC noinline
  313. #endif
  314. #else /* !DEBUG */
  315. #ifdef XFS_WARN
  316. #define ASSERT(expr) \
  317. (unlikely(expr) ? (void)0 : asswarn(#expr, __FILE__, __LINE__))
  318. #ifndef STATIC
  319. # define STATIC static noinline
  320. #endif
  321. #else /* !DEBUG && !XFS_WARN */
  322. #define ASSERT(expr) ((void)0)
  323. #ifndef STATIC
  324. # define STATIC static noinline
  325. #endif
  326. #endif /* XFS_WARN */
  327. #endif /* DEBUG */
  328. #endif /* __XFS_LINUX__ */