xfs_linux.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. #include <linux/config.h>
  22. /*
  23. * Some types are conditional depending on the target system.
  24. * XFS_BIG_BLKNOS needs block layer disk addresses to be 64 bits.
  25. * XFS_BIG_INUMS needs the VFS inode number to be 64 bits, as well
  26. * as requiring XFS_BIG_BLKNOS to be set.
  27. */
  28. #if defined(CONFIG_LBD) || (BITS_PER_LONG == 64)
  29. # define XFS_BIG_BLKNOS 1
  30. # if BITS_PER_LONG == 64
  31. # define XFS_BIG_INUMS 1
  32. # else
  33. # define XFS_BIG_INUMS 0
  34. # endif
  35. #else
  36. # define XFS_BIG_BLKNOS 0
  37. # define XFS_BIG_INUMS 0
  38. #endif
  39. #include <xfs_types.h>
  40. #include <xfs_arch.h>
  41. #include <kmem.h>
  42. #include <mrlock.h>
  43. #include <spin.h>
  44. #include <sv.h>
  45. #include <mutex.h>
  46. #include <sema.h>
  47. #include <time.h>
  48. #include <support/ktrace.h>
  49. #include <support/debug.h>
  50. #include <support/move.h>
  51. #include <support/uuid.h>
  52. #include <linux/mm.h>
  53. #include <linux/kernel.h>
  54. #include <linux/blkdev.h>
  55. #include <linux/slab.h>
  56. #include <linux/module.h>
  57. #include <linux/file.h>
  58. #include <linux/swap.h>
  59. #include <linux/errno.h>
  60. #include <linux/sched.h>
  61. #include <linux/bitops.h>
  62. #include <linux/major.h>
  63. #include <linux/pagemap.h>
  64. #include <linux/vfs.h>
  65. #include <linux/seq_file.h>
  66. #include <linux/init.h>
  67. #include <linux/list.h>
  68. #include <linux/proc_fs.h>
  69. #include <linux/sort.h>
  70. #include <asm/page.h>
  71. #include <asm/div64.h>
  72. #include <asm/param.h>
  73. #include <asm/uaccess.h>
  74. #include <asm/byteorder.h>
  75. #include <asm/unaligned.h>
  76. #include <xfs_behavior.h>
  77. #include <xfs_vfs.h>
  78. #include <xfs_cred.h>
  79. #include <xfs_vnode.h>
  80. #include <xfs_stats.h>
  81. #include <xfs_sysctl.h>
  82. #include <xfs_iops.h>
  83. #include <xfs_aops.h>
  84. #include <xfs_super.h>
  85. #include <xfs_globals.h>
  86. #include <xfs_fs_subr.h>
  87. #include <xfs_lrw.h>
  88. #include <xfs_buf.h>
  89. /*
  90. * Feature macros (disable/enable)
  91. */
  92. #undef HAVE_REFCACHE /* reference cache not needed for NFS in 2.6 */
  93. #define HAVE_SENDFILE /* sendfile(2) exists in 2.6, but not in 2.4 */
  94. /*
  95. * State flag for unwritten extent buffers.
  96. *
  97. * We need to be able to distinguish between these and delayed
  98. * allocate buffers within XFS. The generic IO path code does
  99. * not need to distinguish - we use the BH_Delay flag for both
  100. * delalloc and these ondisk-uninitialised buffers.
  101. */
  102. BUFFER_FNS(PrivateStart, unwritten);
  103. #define restricted_chown xfs_params.restrict_chown.val
  104. #define irix_sgid_inherit xfs_params.sgid_inherit.val
  105. #define irix_symlink_mode xfs_params.symlink_mode.val
  106. #define xfs_panic_mask xfs_params.panic_mask.val
  107. #define xfs_error_level xfs_params.error_level.val
  108. #define xfs_syncd_centisecs xfs_params.syncd_timer.val
  109. #define xfs_stats_clear xfs_params.stats_clear.val
  110. #define xfs_inherit_sync xfs_params.inherit_sync.val
  111. #define xfs_inherit_nodump xfs_params.inherit_nodump.val
  112. #define xfs_inherit_noatime xfs_params.inherit_noatim.val
  113. #define xfs_buf_timer_centisecs xfs_params.xfs_buf_timer.val
  114. #define xfs_buf_age_centisecs xfs_params.xfs_buf_age.val
  115. #define xfs_inherit_nosymlinks xfs_params.inherit_nosym.val
  116. #define xfs_rotorstep xfs_params.rotorstep.val
  117. #ifndef raw_smp_processor_id
  118. #define raw_smp_processor_id() smp_processor_id()
  119. #endif
  120. #define current_cpu() raw_smp_processor_id()
  121. #define current_pid() (current->pid)
  122. #define current_fsuid(cred) (current->fsuid)
  123. #define current_fsgid(cred) (current->fsgid)
  124. #define NBPP PAGE_SIZE
  125. #define DPPSHFT (PAGE_SHIFT - 9)
  126. #define NDPP (1 << (PAGE_SHIFT - 9))
  127. #define dtop(DD) (((DD) + NDPP - 1) >> DPPSHFT)
  128. #define dtopt(DD) ((DD) >> DPPSHFT)
  129. #define dpoff(DD) ((DD) & (NDPP-1))
  130. #define NBBY 8 /* number of bits per byte */
  131. #define NBPC PAGE_SIZE /* Number of bytes per click */
  132. #define BPCSHIFT PAGE_SHIFT /* LOG2(NBPC) if exact */
  133. /*
  134. * Size of block device i/o is parameterized here.
  135. * Currently the system supports page-sized i/o.
  136. */
  137. #define BLKDEV_IOSHIFT BPCSHIFT
  138. #define BLKDEV_IOSIZE (1<<BLKDEV_IOSHIFT)
  139. /* number of BB's per block device block */
  140. #define BLKDEV_BB BTOBB(BLKDEV_IOSIZE)
  141. /* bytes to clicks */
  142. #define btoc(x) (((__psunsigned_t)(x)+(NBPC-1))>>BPCSHIFT)
  143. #define btoct(x) ((__psunsigned_t)(x)>>BPCSHIFT)
  144. #define btoc64(x) (((__uint64_t)(x)+(NBPC-1))>>BPCSHIFT)
  145. #define btoct64(x) ((__uint64_t)(x)>>BPCSHIFT)
  146. #define io_btoc(x) (((__psunsigned_t)(x)+(IO_NBPC-1))>>IO_BPCSHIFT)
  147. #define io_btoct(x) ((__psunsigned_t)(x)>>IO_BPCSHIFT)
  148. /* off_t bytes to clicks */
  149. #define offtoc(x) (((__uint64_t)(x)+(NBPC-1))>>BPCSHIFT)
  150. #define offtoct(x) ((xfs_off_t)(x)>>BPCSHIFT)
  151. /* clicks to off_t bytes */
  152. #define ctooff(x) ((xfs_off_t)(x)<<BPCSHIFT)
  153. /* clicks to bytes */
  154. #define ctob(x) ((__psunsigned_t)(x)<<BPCSHIFT)
  155. #define btoct(x) ((__psunsigned_t)(x)>>BPCSHIFT)
  156. #define ctob64(x) ((__uint64_t)(x)<<BPCSHIFT)
  157. #define io_ctob(x) ((__psunsigned_t)(x)<<IO_BPCSHIFT)
  158. /* bytes to clicks */
  159. #define btoc(x) (((__psunsigned_t)(x)+(NBPC-1))>>BPCSHIFT)
  160. #ifndef ENOATTR
  161. #define ENOATTR ENODATA /* Attribute not found */
  162. #endif
  163. /* Note: EWRONGFS never visible outside the kernel */
  164. #define EWRONGFS EINVAL /* Mount with wrong filesystem type */
  165. /*
  166. * XXX EFSCORRUPTED needs a real value in errno.h. asm-i386/errno.h won't
  167. * return codes out of its known range in errno.
  168. * XXX Also note: needs to be < 1000 and fairly unique on Linux (mustn't
  169. * conflict with any code we use already or any code a driver may use)
  170. * XXX Some options (currently we do #2):
  171. * 1/ New error code ["Filesystem is corrupted", _after_ glibc updated]
  172. * 2/ 990 ["Unknown error 990"]
  173. * 3/ EUCLEAN ["Structure needs cleaning"]
  174. * 4/ Convert EFSCORRUPTED to EIO [just prior to return into userspace]
  175. */
  176. #define EFSCORRUPTED 990 /* Filesystem is corrupted */
  177. #define SYNCHRONIZE() barrier()
  178. #define __return_address __builtin_return_address(0)
  179. /*
  180. * IRIX (BSD) quotactl makes use of separate commands for user/group,
  181. * whereas on Linux the syscall encodes this information into the cmd
  182. * field (see the QCMD macro in quota.h). These macros help keep the
  183. * code portable - they are not visible from the syscall interface.
  184. */
  185. #define Q_XSETGQLIM XQM_CMD(8) /* set groups disk limits */
  186. #define Q_XGETGQUOTA XQM_CMD(9) /* get groups disk limits */
  187. #define Q_XSETPQLIM XQM_CMD(10) /* set projects disk limits */
  188. #define Q_XGETPQUOTA XQM_CMD(11) /* get projects disk limits */
  189. #define dfltprid 0
  190. #define MAXPATHLEN 1024
  191. #define MIN(a,b) (min(a,b))
  192. #define MAX(a,b) (max(a,b))
  193. #define howmany(x, y) (((x)+((y)-1))/(y))
  194. #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
  195. /*
  196. * Various platform dependent calls that don't fit anywhere else
  197. */
  198. #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL)
  199. #define xfs_stack_trace() dump_stack()
  200. #define xfs_itruncate_data(ip, off) \
  201. (-vmtruncate(LINVFS_GET_IP(XFS_ITOV(ip)), (off)))
  202. #define xfs_statvfs_fsid(statp, mp) \
  203. ({ u64 id = huge_encode_dev((mp)->m_ddev_targp->bt_dev); \
  204. __kernel_fsid_t *fsid = &(statp)->f_fsid; \
  205. (fsid->val[0] = (u32)id, fsid->val[1] = (u32)(id >> 32)); })
  206. /* Move the kernel do_div definition off to one side */
  207. #if defined __i386__
  208. /* For ia32 we need to pull some tricks to get past various versions
  209. * of the compiler which do not like us using do_div in the middle
  210. * of large functions.
  211. */
  212. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  213. {
  214. __u32 mod;
  215. switch (n) {
  216. case 4:
  217. mod = *(__u32 *)a % b;
  218. *(__u32 *)a = *(__u32 *)a / b;
  219. return mod;
  220. case 8:
  221. {
  222. unsigned long __upper, __low, __high, __mod;
  223. __u64 c = *(__u64 *)a;
  224. __upper = __high = c >> 32;
  225. __low = c;
  226. if (__high) {
  227. __upper = __high % (b);
  228. __high = __high / (b);
  229. }
  230. asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
  231. asm("":"=A" (c):"a" (__low),"d" (__high));
  232. *(__u64 *)a = c;
  233. return __mod;
  234. }
  235. }
  236. /* NOTREACHED */
  237. return 0;
  238. }
  239. /* Side effect free 64 bit mod operation */
  240. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  241. {
  242. switch (n) {
  243. case 4:
  244. return *(__u32 *)a % b;
  245. case 8:
  246. {
  247. unsigned long __upper, __low, __high, __mod;
  248. __u64 c = *(__u64 *)a;
  249. __upper = __high = c >> 32;
  250. __low = c;
  251. if (__high) {
  252. __upper = __high % (b);
  253. __high = __high / (b);
  254. }
  255. asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
  256. asm("":"=A" (c):"a" (__low),"d" (__high));
  257. return __mod;
  258. }
  259. }
  260. /* NOTREACHED */
  261. return 0;
  262. }
  263. #else
  264. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  265. {
  266. __u32 mod;
  267. switch (n) {
  268. case 4:
  269. mod = *(__u32 *)a % b;
  270. *(__u32 *)a = *(__u32 *)a / b;
  271. return mod;
  272. case 8:
  273. mod = do_div(*(__u64 *)a, b);
  274. return mod;
  275. }
  276. /* NOTREACHED */
  277. return 0;
  278. }
  279. /* Side effect free 64 bit mod operation */
  280. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  281. {
  282. switch (n) {
  283. case 4:
  284. return *(__u32 *)a % b;
  285. case 8:
  286. {
  287. __u64 c = *(__u64 *)a;
  288. return do_div(c, b);
  289. }
  290. }
  291. /* NOTREACHED */
  292. return 0;
  293. }
  294. #endif
  295. #undef do_div
  296. #define do_div(a, b) xfs_do_div(&(a), (b), sizeof(a))
  297. #define do_mod(a, b) xfs_do_mod(&(a), (b), sizeof(a))
  298. static inline __uint64_t roundup_64(__uint64_t x, __uint32_t y)
  299. {
  300. x += y - 1;
  301. do_div(x, y);
  302. return(x * y);
  303. }
  304. #endif /* __XFS_LINUX__ */