xfs_linux.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 <asm/page.h>
  73. #include <asm/div64.h>
  74. #include <asm/param.h>
  75. #include <asm/uaccess.h>
  76. #include <asm/byteorder.h>
  77. #include <asm/unaligned.h>
  78. #include <xfs_behavior.h>
  79. #include <xfs_vfs.h>
  80. #include <xfs_cred.h>
  81. #include <xfs_vnode.h>
  82. #include <xfs_stats.h>
  83. #include <xfs_sysctl.h>
  84. #include <xfs_iops.h>
  85. #include <xfs_aops.h>
  86. #include <xfs_super.h>
  87. #include <xfs_globals.h>
  88. #include <xfs_fs_subr.h>
  89. #include <xfs_lrw.h>
  90. #include <xfs_buf.h>
  91. /*
  92. * Feature macros (disable/enable)
  93. */
  94. #undef HAVE_REFCACHE /* reference cache not needed for NFS in 2.6 */
  95. #define HAVE_SENDFILE /* sendfile(2) exists in 2.6, but not in 2.4 */
  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. /*
  103. * State flag for unwritten extent buffers.
  104. *
  105. * We need to be able to distinguish between these and delayed
  106. * allocate buffers within XFS. The generic IO path code does
  107. * not need to distinguish - we use the BH_Delay flag for both
  108. * delalloc and these ondisk-uninitialised buffers.
  109. */
  110. BUFFER_FNS(PrivateStart, unwritten);
  111. #define restricted_chown xfs_params.restrict_chown.val
  112. #define irix_sgid_inherit xfs_params.sgid_inherit.val
  113. #define irix_symlink_mode xfs_params.symlink_mode.val
  114. #define xfs_panic_mask xfs_params.panic_mask.val
  115. #define xfs_error_level xfs_params.error_level.val
  116. #define xfs_syncd_centisecs xfs_params.syncd_timer.val
  117. #define xfs_stats_clear xfs_params.stats_clear.val
  118. #define xfs_inherit_sync xfs_params.inherit_sync.val
  119. #define xfs_inherit_nodump xfs_params.inherit_nodump.val
  120. #define xfs_inherit_noatime xfs_params.inherit_noatim.val
  121. #define xfs_buf_timer_centisecs xfs_params.xfs_buf_timer.val
  122. #define xfs_buf_age_centisecs xfs_params.xfs_buf_age.val
  123. #define xfs_inherit_nosymlinks xfs_params.inherit_nosym.val
  124. #define xfs_rotorstep xfs_params.rotorstep.val
  125. #define xfs_inherit_nodefrag xfs_params.inherit_nodfrg.val
  126. #define current_cpu() (raw_smp_processor_id())
  127. #define current_pid() (current->pid)
  128. #define current_fsuid(cred) (current->fsuid)
  129. #define current_fsgid(cred) (current->fsgid)
  130. #define current_test_flags(f) (current->flags & (f))
  131. #define current_set_flags_nested(sp, f) \
  132. (*(sp) = current->flags, current->flags |= (f))
  133. #define current_clear_flags_nested(sp, f) \
  134. (*(sp) = current->flags, current->flags &= ~(f))
  135. #define current_restore_flags_nested(sp, f) \
  136. (current->flags = ((current->flags & ~(f)) | (*(sp) & (f))))
  137. #define NBPP PAGE_SIZE
  138. #define DPPSHFT (PAGE_SHIFT - 9)
  139. #define NDPP (1 << (PAGE_SHIFT - 9))
  140. #define dtop(DD) (((DD) + NDPP - 1) >> DPPSHFT)
  141. #define dtopt(DD) ((DD) >> DPPSHFT)
  142. #define dpoff(DD) ((DD) & (NDPP-1))
  143. #define NBBY 8 /* number of bits per byte */
  144. #define NBPC PAGE_SIZE /* Number of bytes per click */
  145. #define BPCSHIFT PAGE_SHIFT /* LOG2(NBPC) if exact */
  146. /*
  147. * Size of block device i/o is parameterized here.
  148. * Currently the system supports page-sized i/o.
  149. */
  150. #define BLKDEV_IOSHIFT BPCSHIFT
  151. #define BLKDEV_IOSIZE (1<<BLKDEV_IOSHIFT)
  152. /* number of BB's per block device block */
  153. #define BLKDEV_BB BTOBB(BLKDEV_IOSIZE)
  154. /* bytes to clicks */
  155. #define btoc(x) (((__psunsigned_t)(x)+(NBPC-1))>>BPCSHIFT)
  156. #define btoct(x) ((__psunsigned_t)(x)>>BPCSHIFT)
  157. #define btoc64(x) (((__uint64_t)(x)+(NBPC-1))>>BPCSHIFT)
  158. #define btoct64(x) ((__uint64_t)(x)>>BPCSHIFT)
  159. #define io_btoc(x) (((__psunsigned_t)(x)+(IO_NBPC-1))>>IO_BPCSHIFT)
  160. #define io_btoct(x) ((__psunsigned_t)(x)>>IO_BPCSHIFT)
  161. /* off_t bytes to clicks */
  162. #define offtoc(x) (((__uint64_t)(x)+(NBPC-1))>>BPCSHIFT)
  163. #define offtoct(x) ((xfs_off_t)(x)>>BPCSHIFT)
  164. /* clicks to off_t bytes */
  165. #define ctooff(x) ((xfs_off_t)(x)<<BPCSHIFT)
  166. /* clicks to bytes */
  167. #define ctob(x) ((__psunsigned_t)(x)<<BPCSHIFT)
  168. #define btoct(x) ((__psunsigned_t)(x)>>BPCSHIFT)
  169. #define ctob64(x) ((__uint64_t)(x)<<BPCSHIFT)
  170. #define io_ctob(x) ((__psunsigned_t)(x)<<IO_BPCSHIFT)
  171. /* bytes to clicks */
  172. #define btoc(x) (((__psunsigned_t)(x)+(NBPC-1))>>BPCSHIFT)
  173. #define ENOATTR ENODATA /* Attribute not found */
  174. #define EWRONGFS EINVAL /* Mount with wrong filesystem type */
  175. #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
  176. #define SYNCHRONIZE() barrier()
  177. #define __return_address __builtin_return_address(0)
  178. /*
  179. * IRIX (BSD) quotactl makes use of separate commands for user/group,
  180. * whereas on Linux the syscall encodes this information into the cmd
  181. * field (see the QCMD macro in quota.h). These macros help keep the
  182. * code portable - they are not visible from the syscall interface.
  183. */
  184. #define Q_XSETGQLIM XQM_CMD(8) /* set groups disk limits */
  185. #define Q_XGETGQUOTA XQM_CMD(9) /* get groups disk limits */
  186. #define Q_XSETPQLIM XQM_CMD(10) /* set projects disk limits */
  187. #define Q_XGETPQUOTA XQM_CMD(11) /* get projects disk limits */
  188. #define dfltprid 0
  189. #define MAXPATHLEN 1024
  190. #define MIN(a,b) (min(a,b))
  191. #define MAX(a,b) (max(a,b))
  192. #define howmany(x, y) (((x)+((y)-1))/(y))
  193. /*
  194. * Various platform dependent calls that don't fit anywhere else
  195. */
  196. #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL)
  197. #define xfs_stack_trace() dump_stack()
  198. #define xfs_itruncate_data(ip, off) \
  199. (-vmtruncate(vn_to_inode(XFS_ITOV(ip)), (off)))
  200. #define xfs_statvfs_fsid(statp, mp) \
  201. ({ u64 id = huge_encode_dev((mp)->m_ddev_targp->bt_dev); \
  202. __kernel_fsid_t *fsid = &(statp)->f_fsid; \
  203. (fsid->val[0] = (u32)id, fsid->val[1] = (u32)(id >> 32)); })
  204. /* Move the kernel do_div definition off to one side */
  205. #if defined __i386__
  206. /* For ia32 we need to pull some tricks to get past various versions
  207. * of the compiler which do not like us using do_div in the middle
  208. * of large functions.
  209. */
  210. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  211. {
  212. __u32 mod;
  213. switch (n) {
  214. case 4:
  215. mod = *(__u32 *)a % b;
  216. *(__u32 *)a = *(__u32 *)a / b;
  217. return mod;
  218. case 8:
  219. {
  220. unsigned long __upper, __low, __high, __mod;
  221. __u64 c = *(__u64 *)a;
  222. __upper = __high = c >> 32;
  223. __low = c;
  224. if (__high) {
  225. __upper = __high % (b);
  226. __high = __high / (b);
  227. }
  228. asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
  229. asm("":"=A" (c):"a" (__low),"d" (__high));
  230. *(__u64 *)a = c;
  231. return __mod;
  232. }
  233. }
  234. /* NOTREACHED */
  235. return 0;
  236. }
  237. /* Side effect free 64 bit mod operation */
  238. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  239. {
  240. switch (n) {
  241. case 4:
  242. return *(__u32 *)a % b;
  243. case 8:
  244. {
  245. unsigned long __upper, __low, __high, __mod;
  246. __u64 c = *(__u64 *)a;
  247. __upper = __high = c >> 32;
  248. __low = c;
  249. if (__high) {
  250. __upper = __high % (b);
  251. __high = __high / (b);
  252. }
  253. asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
  254. asm("":"=A" (c):"a" (__low),"d" (__high));
  255. return __mod;
  256. }
  257. }
  258. /* NOTREACHED */
  259. return 0;
  260. }
  261. #else
  262. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  263. {
  264. __u32 mod;
  265. switch (n) {
  266. case 4:
  267. mod = *(__u32 *)a % b;
  268. *(__u32 *)a = *(__u32 *)a / b;
  269. return mod;
  270. case 8:
  271. mod = do_div(*(__u64 *)a, b);
  272. return mod;
  273. }
  274. /* NOTREACHED */
  275. return 0;
  276. }
  277. /* Side effect free 64 bit mod operation */
  278. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  279. {
  280. switch (n) {
  281. case 4:
  282. return *(__u32 *)a % b;
  283. case 8:
  284. {
  285. __u64 c = *(__u64 *)a;
  286. return do_div(c, b);
  287. }
  288. }
  289. /* NOTREACHED */
  290. return 0;
  291. }
  292. #endif
  293. #undef do_div
  294. #define do_div(a, b) xfs_do_div(&(a), (b), sizeof(a))
  295. #define do_mod(a, b) xfs_do_mod(&(a), (b), sizeof(a))
  296. static inline __uint64_t roundup_64(__uint64_t x, __uint32_t y)
  297. {
  298. x += y - 1;
  299. do_div(x, y);
  300. return(x * y);
  301. }
  302. #endif /* __XFS_LINUX__ */