xfs_linux.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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 <linux/cpu.h>
  71. #include <linux/notifier.h>
  72. #include <linux/delay.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_SENDFILE /* sendfile(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. #ifndef raw_smp_processor_id
  126. #define raw_smp_processor_id() smp_processor_id()
  127. #endif
  128. #define current_cpu() raw_smp_processor_id()
  129. #define current_pid() (current->pid)
  130. #define current_fsuid(cred) (current->fsuid)
  131. #define current_fsgid(cred) (current->fsgid)
  132. #define NBPP PAGE_SIZE
  133. #define DPPSHFT (PAGE_SHIFT - 9)
  134. #define NDPP (1 << (PAGE_SHIFT - 9))
  135. #define dtop(DD) (((DD) + NDPP - 1) >> DPPSHFT)
  136. #define dtopt(DD) ((DD) >> DPPSHFT)
  137. #define dpoff(DD) ((DD) & (NDPP-1))
  138. #define NBBY 8 /* number of bits per byte */
  139. #define NBPC PAGE_SIZE /* Number of bytes per click */
  140. #define BPCSHIFT PAGE_SHIFT /* LOG2(NBPC) if exact */
  141. /*
  142. * Size of block device i/o is parameterized here.
  143. * Currently the system supports page-sized i/o.
  144. */
  145. #define BLKDEV_IOSHIFT BPCSHIFT
  146. #define BLKDEV_IOSIZE (1<<BLKDEV_IOSHIFT)
  147. /* number of BB's per block device block */
  148. #define BLKDEV_BB BTOBB(BLKDEV_IOSIZE)
  149. /* bytes to clicks */
  150. #define btoc(x) (((__psunsigned_t)(x)+(NBPC-1))>>BPCSHIFT)
  151. #define btoct(x) ((__psunsigned_t)(x)>>BPCSHIFT)
  152. #define btoc64(x) (((__uint64_t)(x)+(NBPC-1))>>BPCSHIFT)
  153. #define btoct64(x) ((__uint64_t)(x)>>BPCSHIFT)
  154. #define io_btoc(x) (((__psunsigned_t)(x)+(IO_NBPC-1))>>IO_BPCSHIFT)
  155. #define io_btoct(x) ((__psunsigned_t)(x)>>IO_BPCSHIFT)
  156. /* off_t bytes to clicks */
  157. #define offtoc(x) (((__uint64_t)(x)+(NBPC-1))>>BPCSHIFT)
  158. #define offtoct(x) ((xfs_off_t)(x)>>BPCSHIFT)
  159. /* clicks to off_t bytes */
  160. #define ctooff(x) ((xfs_off_t)(x)<<BPCSHIFT)
  161. /* clicks to bytes */
  162. #define ctob(x) ((__psunsigned_t)(x)<<BPCSHIFT)
  163. #define btoct(x) ((__psunsigned_t)(x)>>BPCSHIFT)
  164. #define ctob64(x) ((__uint64_t)(x)<<BPCSHIFT)
  165. #define io_ctob(x) ((__psunsigned_t)(x)<<IO_BPCSHIFT)
  166. /* bytes to clicks */
  167. #define btoc(x) (((__psunsigned_t)(x)+(NBPC-1))>>BPCSHIFT)
  168. #ifndef ENOATTR
  169. #define ENOATTR ENODATA /* Attribute not found */
  170. #endif
  171. /* Note: EWRONGFS never visible outside the kernel */
  172. #define EWRONGFS EINVAL /* Mount with wrong filesystem type */
  173. /*
  174. * XXX EFSCORRUPTED needs a real value in errno.h. asm-i386/errno.h won't
  175. * return codes out of its known range in errno.
  176. * XXX Also note: needs to be < 1000 and fairly unique on Linux (mustn't
  177. * conflict with any code we use already or any code a driver may use)
  178. * XXX Some options (currently we do #2):
  179. * 1/ New error code ["Filesystem is corrupted", _after_ glibc updated]
  180. * 2/ 990 ["Unknown error 990"]
  181. * 3/ EUCLEAN ["Structure needs cleaning"]
  182. * 4/ Convert EFSCORRUPTED to EIO [just prior to return into userspace]
  183. */
  184. #define EFSCORRUPTED 990 /* Filesystem is corrupted */
  185. #define SYNCHRONIZE() barrier()
  186. #define __return_address __builtin_return_address(0)
  187. /*
  188. * IRIX (BSD) quotactl makes use of separate commands for user/group,
  189. * whereas on Linux the syscall encodes this information into the cmd
  190. * field (see the QCMD macro in quota.h). These macros help keep the
  191. * code portable - they are not visible from the syscall interface.
  192. */
  193. #define Q_XSETGQLIM XQM_CMD(8) /* set groups disk limits */
  194. #define Q_XGETGQUOTA XQM_CMD(9) /* get groups disk limits */
  195. #define Q_XSETPQLIM XQM_CMD(10) /* set projects disk limits */
  196. #define Q_XGETPQUOTA XQM_CMD(11) /* get projects disk limits */
  197. #define dfltprid 0
  198. #define MAXPATHLEN 1024
  199. #define MIN(a,b) (min(a,b))
  200. #define MAX(a,b) (max(a,b))
  201. #define howmany(x, y) (((x)+((y)-1))/(y))
  202. #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
  203. /*
  204. * Various platform dependent calls that don't fit anywhere else
  205. */
  206. #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL)
  207. #define xfs_stack_trace() dump_stack()
  208. #define xfs_itruncate_data(ip, off) \
  209. (-vmtruncate(LINVFS_GET_IP(XFS_ITOV(ip)), (off)))
  210. #define xfs_statvfs_fsid(statp, mp) \
  211. ({ u64 id = huge_encode_dev((mp)->m_ddev_targp->bt_dev); \
  212. __kernel_fsid_t *fsid = &(statp)->f_fsid; \
  213. (fsid->val[0] = (u32)id, fsid->val[1] = (u32)(id >> 32)); })
  214. /* Move the kernel do_div definition off to one side */
  215. #if defined __i386__
  216. /* For ia32 we need to pull some tricks to get past various versions
  217. * of the compiler which do not like us using do_div in the middle
  218. * of large functions.
  219. */
  220. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  221. {
  222. __u32 mod;
  223. switch (n) {
  224. case 4:
  225. mod = *(__u32 *)a % b;
  226. *(__u32 *)a = *(__u32 *)a / b;
  227. return mod;
  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. *(__u64 *)a = c;
  241. return __mod;
  242. }
  243. }
  244. /* NOTREACHED */
  245. return 0;
  246. }
  247. /* Side effect free 64 bit mod operation */
  248. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  249. {
  250. switch (n) {
  251. case 4:
  252. return *(__u32 *)a % b;
  253. case 8:
  254. {
  255. unsigned long __upper, __low, __high, __mod;
  256. __u64 c = *(__u64 *)a;
  257. __upper = __high = c >> 32;
  258. __low = c;
  259. if (__high) {
  260. __upper = __high % (b);
  261. __high = __high / (b);
  262. }
  263. asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
  264. asm("":"=A" (c):"a" (__low),"d" (__high));
  265. return __mod;
  266. }
  267. }
  268. /* NOTREACHED */
  269. return 0;
  270. }
  271. #else
  272. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  273. {
  274. __u32 mod;
  275. switch (n) {
  276. case 4:
  277. mod = *(__u32 *)a % b;
  278. *(__u32 *)a = *(__u32 *)a / b;
  279. return mod;
  280. case 8:
  281. mod = do_div(*(__u64 *)a, b);
  282. return mod;
  283. }
  284. /* NOTREACHED */
  285. return 0;
  286. }
  287. /* Side effect free 64 bit mod operation */
  288. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  289. {
  290. switch (n) {
  291. case 4:
  292. return *(__u32 *)a % b;
  293. case 8:
  294. {
  295. __u64 c = *(__u64 *)a;
  296. return do_div(c, b);
  297. }
  298. }
  299. /* NOTREACHED */
  300. return 0;
  301. }
  302. #endif
  303. #undef do_div
  304. #define do_div(a, b) xfs_do_div(&(a), (b), sizeof(a))
  305. #define do_mod(a, b) xfs_do_mod(&(a), (b), sizeof(a))
  306. static inline __uint64_t roundup_64(__uint64_t x, __uint32_t y)
  307. {
  308. x += y - 1;
  309. do_div(x, y);
  310. return(x * y);
  311. }
  312. #endif /* __XFS_LINUX__ */