xfs_linux.h 7.8 KB

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