xfs_linux.h 7.7 KB

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