xfs_linux.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. #include <xfs_types.h>
  33. #include <xfs_arch.h>
  34. #include <kmem.h>
  35. #include <mrlock.h>
  36. #include <sv.h>
  37. #include <time.h>
  38. #include <support/debug.h>
  39. #include <support/uuid.h>
  40. #include <linux/semaphore.h>
  41. #include <linux/mm.h>
  42. #include <linux/kernel.h>
  43. #include <linux/blkdev.h>
  44. #include <linux/slab.h>
  45. #include <linux/module.h>
  46. #include <linux/mutex.h>
  47. #include <linux/file.h>
  48. #include <linux/swap.h>
  49. #include <linux/errno.h>
  50. #include <linux/sched.h>
  51. #include <linux/bitops.h>
  52. #include <linux/major.h>
  53. #include <linux/pagemap.h>
  54. #include <linux/vfs.h>
  55. #include <linux/seq_file.h>
  56. #include <linux/init.h>
  57. #include <linux/list.h>
  58. #include <linux/proc_fs.h>
  59. #include <linux/sort.h>
  60. #include <linux/cpu.h>
  61. #include <linux/notifier.h>
  62. #include <linux/delay.h>
  63. #include <linux/log2.h>
  64. #include <linux/spinlock.h>
  65. #include <linux/random.h>
  66. #include <linux/ctype.h>
  67. #include <linux/writeback.h>
  68. #include <asm/page.h>
  69. #include <asm/div64.h>
  70. #include <asm/param.h>
  71. #include <asm/uaccess.h>
  72. #include <asm/byteorder.h>
  73. #include <asm/unaligned.h>
  74. #include <xfs_cred.h>
  75. #include <xfs_vnode.h>
  76. #include <xfs_stats.h>
  77. #include <xfs_sysctl.h>
  78. #include <xfs_iops.h>
  79. #include <xfs_aops.h>
  80. #include <xfs_super.h>
  81. #include <xfs_globals.h>
  82. #include <xfs_buf.h>
  83. /*
  84. * Feature macros (disable/enable)
  85. */
  86. #ifdef CONFIG_SMP
  87. #define HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */
  88. #else
  89. #undef HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */
  90. #endif
  91. #define irix_sgid_inherit xfs_params.sgid_inherit.val
  92. #define irix_symlink_mode xfs_params.symlink_mode.val
  93. #define xfs_panic_mask xfs_params.panic_mask.val
  94. #define xfs_error_level xfs_params.error_level.val
  95. #define xfs_syncd_centisecs xfs_params.syncd_timer.val
  96. #define xfs_stats_clear xfs_params.stats_clear.val
  97. #define xfs_inherit_sync xfs_params.inherit_sync.val
  98. #define xfs_inherit_nodump xfs_params.inherit_nodump.val
  99. #define xfs_inherit_noatime xfs_params.inherit_noatim.val
  100. #define xfs_buf_timer_centisecs xfs_params.xfs_buf_timer.val
  101. #define xfs_buf_age_centisecs xfs_params.xfs_buf_age.val
  102. #define xfs_inherit_nosymlinks xfs_params.inherit_nosym.val
  103. #define xfs_rotorstep xfs_params.rotorstep.val
  104. #define xfs_inherit_nodefrag xfs_params.inherit_nodfrg.val
  105. #define xfs_fstrm_centisecs xfs_params.fstrm_timer.val
  106. #define current_cpu() (raw_smp_processor_id())
  107. #define current_pid() (current->pid)
  108. #define current_test_flags(f) (current->flags & (f))
  109. #define current_set_flags_nested(sp, f) \
  110. (*(sp) = current->flags, current->flags |= (f))
  111. #define current_clear_flags_nested(sp, f) \
  112. (*(sp) = current->flags, current->flags &= ~(f))
  113. #define current_restore_flags_nested(sp, f) \
  114. (current->flags = ((current->flags & ~(f)) | (*(sp) & (f))))
  115. #define spinlock_destroy(lock)
  116. #define NBBY 8 /* number of bits per byte */
  117. /*
  118. * Size of block device i/o is parameterized here.
  119. * Currently the system supports page-sized i/o.
  120. */
  121. #define BLKDEV_IOSHIFT PAGE_CACHE_SHIFT
  122. #define BLKDEV_IOSIZE (1<<BLKDEV_IOSHIFT)
  123. /* number of BB's per block device block */
  124. #define BLKDEV_BB BTOBB(BLKDEV_IOSIZE)
  125. #define ENOATTR ENODATA /* Attribute not found */
  126. #define EWRONGFS EINVAL /* Mount with wrong filesystem type */
  127. #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
  128. #define SYNCHRONIZE() barrier()
  129. #define __return_address __builtin_return_address(0)
  130. #define dfltprid 0
  131. #define MAXPATHLEN 1024
  132. #define MIN(a,b) (min(a,b))
  133. #define MAX(a,b) (max(a,b))
  134. #define howmany(x, y) (((x)+((y)-1))/(y))
  135. /*
  136. * Various platform dependent calls that don't fit anywhere else
  137. */
  138. #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL)
  139. #define xfs_stack_trace() dump_stack()
  140. /* Move the kernel do_div definition off to one side */
  141. #if defined __i386__
  142. /* For ia32 we need to pull some tricks to get past various versions
  143. * of the compiler which do not like us using do_div in the middle
  144. * of large functions.
  145. */
  146. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  147. {
  148. __u32 mod;
  149. switch (n) {
  150. case 4:
  151. mod = *(__u32 *)a % b;
  152. *(__u32 *)a = *(__u32 *)a / b;
  153. return mod;
  154. case 8:
  155. {
  156. unsigned long __upper, __low, __high, __mod;
  157. __u64 c = *(__u64 *)a;
  158. __upper = __high = c >> 32;
  159. __low = c;
  160. if (__high) {
  161. __upper = __high % (b);
  162. __high = __high / (b);
  163. }
  164. asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
  165. asm("":"=A" (c):"a" (__low),"d" (__high));
  166. *(__u64 *)a = c;
  167. return __mod;
  168. }
  169. }
  170. /* NOTREACHED */
  171. return 0;
  172. }
  173. /* Side effect free 64 bit mod operation */
  174. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  175. {
  176. switch (n) {
  177. case 4:
  178. return *(__u32 *)a % b;
  179. case 8:
  180. {
  181. unsigned long __upper, __low, __high, __mod;
  182. __u64 c = *(__u64 *)a;
  183. __upper = __high = c >> 32;
  184. __low = c;
  185. if (__high) {
  186. __upper = __high % (b);
  187. __high = __high / (b);
  188. }
  189. asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
  190. asm("":"=A" (c):"a" (__low),"d" (__high));
  191. return __mod;
  192. }
  193. }
  194. /* NOTREACHED */
  195. return 0;
  196. }
  197. #else
  198. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  199. {
  200. __u32 mod;
  201. switch (n) {
  202. case 4:
  203. mod = *(__u32 *)a % b;
  204. *(__u32 *)a = *(__u32 *)a / b;
  205. return mod;
  206. case 8:
  207. mod = do_div(*(__u64 *)a, b);
  208. return mod;
  209. }
  210. /* NOTREACHED */
  211. return 0;
  212. }
  213. /* Side effect free 64 bit mod operation */
  214. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  215. {
  216. switch (n) {
  217. case 4:
  218. return *(__u32 *)a % b;
  219. case 8:
  220. {
  221. __u64 c = *(__u64 *)a;
  222. return do_div(c, b);
  223. }
  224. }
  225. /* NOTREACHED */
  226. return 0;
  227. }
  228. #endif
  229. #undef do_div
  230. #define do_div(a, b) xfs_do_div(&(a), (b), sizeof(a))
  231. #define do_mod(a, b) xfs_do_mod(&(a), (b), sizeof(a))
  232. static inline __uint64_t roundup_64(__uint64_t x, __uint32_t y)
  233. {
  234. x += y - 1;
  235. do_div(x, y);
  236. return(x * y);
  237. }
  238. static inline __uint64_t howmany_64(__uint64_t x, __uint32_t y)
  239. {
  240. x += y - 1;
  241. do_div(x, y);
  242. return x;
  243. }
  244. /* ARM old ABI has some weird alignment/padding */
  245. #if defined(__arm__) && !defined(__ARM_EABI__)
  246. #define __arch_pack __attribute__((packed))
  247. #else
  248. #define __arch_pack
  249. #endif
  250. #endif /* __XFS_LINUX__ */