xfs_linux.h 7.5 KB

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