xfs_linux.h 9.7 KB

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