xfs_linux.h 7.9 KB

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