xfs_linux.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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 <spin.h>
  43. #include <sv.h>
  44. #include <mutex.h>
  45. #include <sema.h>
  46. #include <time.h>
  47. #include <support/ktrace.h>
  48. #include <support/debug.h>
  49. #include <support/move.h>
  50. #include <support/uuid.h>
  51. #include <linux/mm.h>
  52. #include <linux/kernel.h>
  53. #include <linux/blkdev.h>
  54. #include <linux/slab.h>
  55. #include <linux/module.h>
  56. #include <linux/file.h>
  57. #include <linux/swap.h>
  58. #include <linux/errno.h>
  59. #include <linux/sched.h>
  60. #include <linux/bitops.h>
  61. #include <linux/major.h>
  62. #include <linux/pagemap.h>
  63. #include <linux/vfs.h>
  64. #include <linux/seq_file.h>
  65. #include <linux/init.h>
  66. #include <linux/list.h>
  67. #include <linux/proc_fs.h>
  68. #include <linux/sort.h>
  69. #include <linux/cpu.h>
  70. #include <linux/notifier.h>
  71. #include <linux/delay.h>
  72. #include <linux/log2.h>
  73. #include <asm/page.h>
  74. #include <asm/div64.h>
  75. #include <asm/param.h>
  76. #include <asm/uaccess.h>
  77. #include <asm/byteorder.h>
  78. #include <asm/unaligned.h>
  79. #include <xfs_behavior.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. #undef HAVE_REFCACHE /* reference cache not needed for NFS in 2.6 */
  96. #define HAVE_SPLICE /* a splice(2) exists in 2.6, but not in 2.4 */
  97. #ifdef CONFIG_SMP
  98. #define HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */
  99. #else
  100. #undef HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */
  101. #endif
  102. #define restricted_chown xfs_params.restrict_chown.val
  103. #define irix_sgid_inherit xfs_params.sgid_inherit.val
  104. #define irix_symlink_mode xfs_params.symlink_mode.val
  105. #define xfs_panic_mask xfs_params.panic_mask.val
  106. #define xfs_error_level xfs_params.error_level.val
  107. #define xfs_syncd_centisecs xfs_params.syncd_timer.val
  108. #define xfs_stats_clear xfs_params.stats_clear.val
  109. #define xfs_inherit_sync xfs_params.inherit_sync.val
  110. #define xfs_inherit_nodump xfs_params.inherit_nodump.val
  111. #define xfs_inherit_noatime xfs_params.inherit_noatim.val
  112. #define xfs_buf_timer_centisecs xfs_params.xfs_buf_timer.val
  113. #define xfs_buf_age_centisecs xfs_params.xfs_buf_age.val
  114. #define xfs_inherit_nosymlinks xfs_params.inherit_nosym.val
  115. #define xfs_rotorstep xfs_params.rotorstep.val
  116. #define xfs_inherit_nodefrag xfs_params.inherit_nodfrg.val
  117. #define xfs_fstrm_centisecs xfs_params.fstrm_timer.val
  118. #define current_cpu() (raw_smp_processor_id())
  119. #define current_pid() (current->pid)
  120. #define current_fsuid(cred) (current->fsuid)
  121. #define current_fsgid(cred) (current->fsgid)
  122. #define current_test_flags(f) (current->flags & (f))
  123. #define current_set_flags_nested(sp, f) \
  124. (*(sp) = current->flags, current->flags |= (f))
  125. #define current_clear_flags_nested(sp, f) \
  126. (*(sp) = current->flags, current->flags &= ~(f))
  127. #define current_restore_flags_nested(sp, f) \
  128. (current->flags = ((current->flags & ~(f)) | (*(sp) & (f))))
  129. #define NBPP PAGE_SIZE
  130. #define NDPP (1 << (PAGE_SHIFT - 9))
  131. #define NBBY 8 /* number of bits per byte */
  132. #define NBPC PAGE_SIZE /* Number of bytes per click */
  133. #define BPCSHIFT PAGE_SHIFT /* LOG2(NBPC) if exact */
  134. /*
  135. * Size of block device i/o is parameterized here.
  136. * Currently the system supports page-sized i/o.
  137. */
  138. #define BLKDEV_IOSHIFT BPCSHIFT
  139. #define BLKDEV_IOSIZE (1<<BLKDEV_IOSHIFT)
  140. /* number of BB's per block device block */
  141. #define BLKDEV_BB BTOBB(BLKDEV_IOSIZE)
  142. /* bytes to clicks */
  143. #define btoc(x) (((__psunsigned_t)(x)+(NBPC-1))>>BPCSHIFT)
  144. #define btoct(x) ((__psunsigned_t)(x)>>BPCSHIFT)
  145. #define btoc64(x) (((__uint64_t)(x)+(NBPC-1))>>BPCSHIFT)
  146. #define btoct64(x) ((__uint64_t)(x)>>BPCSHIFT)
  147. /* off_t bytes to clicks */
  148. #define offtoc(x) (((__uint64_t)(x)+(NBPC-1))>>BPCSHIFT)
  149. #define offtoct(x) ((xfs_off_t)(x)>>BPCSHIFT)
  150. /* clicks to off_t bytes */
  151. #define ctooff(x) ((xfs_off_t)(x)<<BPCSHIFT)
  152. /* clicks to bytes */
  153. #define ctob(x) ((__psunsigned_t)(x)<<BPCSHIFT)
  154. #define btoct(x) ((__psunsigned_t)(x)>>BPCSHIFT)
  155. #define ctob64(x) ((__uint64_t)(x)<<BPCSHIFT)
  156. /* bytes to clicks */
  157. #define btoc(x) (((__psunsigned_t)(x)+(NBPC-1))>>BPCSHIFT)
  158. #define ENOATTR ENODATA /* Attribute not found */
  159. #define EWRONGFS EINVAL /* Mount with wrong filesystem type */
  160. #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
  161. #define SYNCHRONIZE() barrier()
  162. #define __return_address __builtin_return_address(0)
  163. /*
  164. * IRIX (BSD) quotactl makes use of separate commands for user/group,
  165. * whereas on Linux the syscall encodes this information into the cmd
  166. * field (see the QCMD macro in quota.h). These macros help keep the
  167. * code portable - they are not visible from the syscall interface.
  168. */
  169. #define Q_XSETGQLIM XQM_CMD(8) /* set groups disk limits */
  170. #define Q_XGETGQUOTA XQM_CMD(9) /* get groups disk limits */
  171. #define Q_XSETPQLIM XQM_CMD(10) /* set projects disk limits */
  172. #define Q_XGETPQUOTA XQM_CMD(11) /* get projects disk limits */
  173. #define dfltprid 0
  174. #define MAXPATHLEN 1024
  175. #define MIN(a,b) (min(a,b))
  176. #define MAX(a,b) (max(a,b))
  177. #define howmany(x, y) (((x)+((y)-1))/(y))
  178. /*
  179. * Various platform dependent calls that don't fit anywhere else
  180. */
  181. #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL)
  182. #define xfs_stack_trace() dump_stack()
  183. #define xfs_itruncate_data(ip, off) \
  184. (-vmtruncate(vn_to_inode(XFS_ITOV(ip)), (off)))
  185. #define xfs_statvfs_fsid(statp, mp) \
  186. ({ u64 id = huge_encode_dev((mp)->m_ddev_targp->bt_dev); \
  187. __kernel_fsid_t *fsid = &(statp)->f_fsid; \
  188. (fsid->val[0] = (u32)id, fsid->val[1] = (u32)(id >> 32)); })
  189. /* Move the kernel do_div definition off to one side */
  190. #if defined __i386__
  191. /* For ia32 we need to pull some tricks to get past various versions
  192. * of the compiler which do not like us using do_div in the middle
  193. * of large functions.
  194. */
  195. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  196. {
  197. __u32 mod;
  198. switch (n) {
  199. case 4:
  200. mod = *(__u32 *)a % b;
  201. *(__u32 *)a = *(__u32 *)a / b;
  202. return mod;
  203. case 8:
  204. {
  205. unsigned long __upper, __low, __high, __mod;
  206. __u64 c = *(__u64 *)a;
  207. __upper = __high = c >> 32;
  208. __low = c;
  209. if (__high) {
  210. __upper = __high % (b);
  211. __high = __high / (b);
  212. }
  213. asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
  214. asm("":"=A" (c):"a" (__low),"d" (__high));
  215. *(__u64 *)a = c;
  216. return __mod;
  217. }
  218. }
  219. /* NOTREACHED */
  220. return 0;
  221. }
  222. /* Side effect free 64 bit mod operation */
  223. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  224. {
  225. switch (n) {
  226. case 4:
  227. return *(__u32 *)a % b;
  228. case 8:
  229. {
  230. unsigned long __upper, __low, __high, __mod;
  231. __u64 c = *(__u64 *)a;
  232. __upper = __high = c >> 32;
  233. __low = c;
  234. if (__high) {
  235. __upper = __high % (b);
  236. __high = __high / (b);
  237. }
  238. asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
  239. asm("":"=A" (c):"a" (__low),"d" (__high));
  240. return __mod;
  241. }
  242. }
  243. /* NOTREACHED */
  244. return 0;
  245. }
  246. #else
  247. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  248. {
  249. __u32 mod;
  250. switch (n) {
  251. case 4:
  252. mod = *(__u32 *)a % b;
  253. *(__u32 *)a = *(__u32 *)a / b;
  254. return mod;
  255. case 8:
  256. mod = do_div(*(__u64 *)a, b);
  257. return mod;
  258. }
  259. /* NOTREACHED */
  260. return 0;
  261. }
  262. /* Side effect free 64 bit mod operation */
  263. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  264. {
  265. switch (n) {
  266. case 4:
  267. return *(__u32 *)a % b;
  268. case 8:
  269. {
  270. __u64 c = *(__u64 *)a;
  271. return do_div(c, b);
  272. }
  273. }
  274. /* NOTREACHED */
  275. return 0;
  276. }
  277. #endif
  278. #undef do_div
  279. #define do_div(a, b) xfs_do_div(&(a), (b), sizeof(a))
  280. #define do_mod(a, b) xfs_do_mod(&(a), (b), sizeof(a))
  281. static inline __uint64_t roundup_64(__uint64_t x, __uint32_t y)
  282. {
  283. x += y - 1;
  284. do_div(x, y);
  285. return(x * y);
  286. }
  287. static inline __uint64_t howmany_64(__uint64_t x, __uint32_t y)
  288. {
  289. x += y - 1;
  290. do_div(x, y);
  291. return x;
  292. }
  293. #endif /* __XFS_LINUX__ */