xfs_linux.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #ifndef __XFS_LINUX__
  33. #define __XFS_LINUX__
  34. #include <linux/types.h>
  35. #include <linux/config.h>
  36. /*
  37. * Some types are conditional depending on the target system.
  38. * XFS_BIG_BLKNOS needs block layer disk addresses to be 64 bits.
  39. * XFS_BIG_INUMS needs the VFS inode number to be 64 bits, as well
  40. * as requiring XFS_BIG_BLKNOS to be set.
  41. */
  42. #if defined(CONFIG_LBD) || (BITS_PER_LONG == 64)
  43. # define XFS_BIG_BLKNOS 1
  44. # if BITS_PER_LONG == 64
  45. # define XFS_BIG_INUMS 1
  46. # else
  47. # define XFS_BIG_INUMS 0
  48. # endif
  49. #else
  50. # define XFS_BIG_BLKNOS 0
  51. # define XFS_BIG_INUMS 0
  52. #endif
  53. #include <xfs_types.h>
  54. #include <xfs_arch.h>
  55. #include <kmem.h>
  56. #include <mrlock.h>
  57. #include <spin.h>
  58. #include <sv.h>
  59. #include <mutex.h>
  60. #include <sema.h>
  61. #include <time.h>
  62. #include <support/qsort.h>
  63. #include <support/ktrace.h>
  64. #include <support/debug.h>
  65. #include <support/move.h>
  66. #include <support/uuid.h>
  67. #include <linux/mm.h>
  68. #include <linux/kernel.h>
  69. #include <linux/blkdev.h>
  70. #include <linux/slab.h>
  71. #include <linux/module.h>
  72. #include <linux/file.h>
  73. #include <linux/swap.h>
  74. #include <linux/errno.h>
  75. #include <linux/sched.h>
  76. #include <linux/bitops.h>
  77. #include <linux/major.h>
  78. #include <linux/pagemap.h>
  79. #include <linux/vfs.h>
  80. #include <linux/seq_file.h>
  81. #include <linux/init.h>
  82. #include <linux/list.h>
  83. #include <linux/proc_fs.h>
  84. #include <linux/version.h>
  85. #include <linux/sort.h>
  86. #include <asm/page.h>
  87. #include <asm/div64.h>
  88. #include <asm/param.h>
  89. #include <asm/uaccess.h>
  90. #include <asm/byteorder.h>
  91. #include <asm/unaligned.h>
  92. #include <xfs_behavior.h>
  93. #include <xfs_vfs.h>
  94. #include <xfs_cred.h>
  95. #include <xfs_vnode.h>
  96. #include <xfs_stats.h>
  97. #include <xfs_sysctl.h>
  98. #include <xfs_iops.h>
  99. #include <xfs_super.h>
  100. #include <xfs_globals.h>
  101. #include <xfs_fs_subr.h>
  102. #include <xfs_lrw.h>
  103. #include <xfs_buf.h>
  104. /*
  105. * Feature macros (disable/enable)
  106. */
  107. #undef HAVE_REFCACHE /* reference cache not needed for NFS in 2.6 */
  108. #define HAVE_SENDFILE /* sendfile(2) exists in 2.6, but not in 2.4 */
  109. /*
  110. * State flag for unwritten extent buffers.
  111. *
  112. * We need to be able to distinguish between these and delayed
  113. * allocate buffers within XFS. The generic IO path code does
  114. * not need to distinguish - we use the BH_Delay flag for both
  115. * delalloc and these ondisk-uninitialised buffers.
  116. */
  117. BUFFER_FNS(PrivateStart, unwritten);
  118. static inline void set_buffer_unwritten_io(struct buffer_head *bh)
  119. {
  120. bh->b_end_io = linvfs_unwritten_done;
  121. }
  122. #define restricted_chown xfs_params.restrict_chown.val
  123. #define irix_sgid_inherit xfs_params.sgid_inherit.val
  124. #define irix_symlink_mode xfs_params.symlink_mode.val
  125. #define xfs_panic_mask xfs_params.panic_mask.val
  126. #define xfs_error_level xfs_params.error_level.val
  127. #define xfs_syncd_centisecs xfs_params.syncd_timer.val
  128. #define xfs_stats_clear xfs_params.stats_clear.val
  129. #define xfs_inherit_sync xfs_params.inherit_sync.val
  130. #define xfs_inherit_nodump xfs_params.inherit_nodump.val
  131. #define xfs_inherit_noatime xfs_params.inherit_noatim.val
  132. #define xfs_buf_timer_centisecs xfs_params.xfs_buf_timer.val
  133. #define xfs_buf_age_centisecs xfs_params.xfs_buf_age.val
  134. #define xfs_inherit_nosymlinks xfs_params.inherit_nosym.val
  135. #define xfs_rotorstep xfs_params.rotorstep.val
  136. #ifndef raw_smp_processor_id
  137. #define raw_smp_processor_id() smp_processor_id()
  138. #endif
  139. #define current_cpu() raw_smp_processor_id()
  140. #define current_pid() (current->pid)
  141. #define current_fsuid(cred) (current->fsuid)
  142. #define current_fsgid(cred) (current->fsgid)
  143. #define NBPP PAGE_SIZE
  144. #define DPPSHFT (PAGE_SHIFT - 9)
  145. #define NDPP (1 << (PAGE_SHIFT - 9))
  146. #define dtop(DD) (((DD) + NDPP - 1) >> DPPSHFT)
  147. #define dtopt(DD) ((DD) >> DPPSHFT)
  148. #define dpoff(DD) ((DD) & (NDPP-1))
  149. #define NBBY 8 /* number of bits per byte */
  150. #define NBPC PAGE_SIZE /* Number of bytes per click */
  151. #define BPCSHIFT PAGE_SHIFT /* LOG2(NBPC) if exact */
  152. /*
  153. * Size of block device i/o is parameterized here.
  154. * Currently the system supports page-sized i/o.
  155. */
  156. #define BLKDEV_IOSHIFT BPCSHIFT
  157. #define BLKDEV_IOSIZE (1<<BLKDEV_IOSHIFT)
  158. /* number of BB's per block device block */
  159. #define BLKDEV_BB BTOBB(BLKDEV_IOSIZE)
  160. /* bytes to clicks */
  161. #define btoc(x) (((__psunsigned_t)(x)+(NBPC-1))>>BPCSHIFT)
  162. #define btoct(x) ((__psunsigned_t)(x)>>BPCSHIFT)
  163. #define btoc64(x) (((__uint64_t)(x)+(NBPC-1))>>BPCSHIFT)
  164. #define btoct64(x) ((__uint64_t)(x)>>BPCSHIFT)
  165. #define io_btoc(x) (((__psunsigned_t)(x)+(IO_NBPC-1))>>IO_BPCSHIFT)
  166. #define io_btoct(x) ((__psunsigned_t)(x)>>IO_BPCSHIFT)
  167. /* off_t bytes to clicks */
  168. #define offtoc(x) (((__uint64_t)(x)+(NBPC-1))>>BPCSHIFT)
  169. #define offtoct(x) ((xfs_off_t)(x)>>BPCSHIFT)
  170. /* clicks to off_t bytes */
  171. #define ctooff(x) ((xfs_off_t)(x)<<BPCSHIFT)
  172. /* clicks to bytes */
  173. #define ctob(x) ((__psunsigned_t)(x)<<BPCSHIFT)
  174. #define btoct(x) ((__psunsigned_t)(x)>>BPCSHIFT)
  175. #define ctob64(x) ((__uint64_t)(x)<<BPCSHIFT)
  176. #define io_ctob(x) ((__psunsigned_t)(x)<<IO_BPCSHIFT)
  177. /* bytes to clicks */
  178. #define btoc(x) (((__psunsigned_t)(x)+(NBPC-1))>>BPCSHIFT)
  179. #ifndef CELL_CAPABLE
  180. #define FSC_NOTIFY_NAME_CHANGED(vp)
  181. #endif
  182. #ifndef ENOATTR
  183. #define ENOATTR ENODATA /* Attribute not found */
  184. #endif
  185. /* Note: EWRONGFS never visible outside the kernel */
  186. #define EWRONGFS EINVAL /* Mount with wrong filesystem type */
  187. /*
  188. * XXX EFSCORRUPTED needs a real value in errno.h. asm-i386/errno.h won't
  189. * return codes out of its known range in errno.
  190. * XXX Also note: needs to be < 1000 and fairly unique on Linux (mustn't
  191. * conflict with any code we use already or any code a driver may use)
  192. * XXX Some options (currently we do #2):
  193. * 1/ New error code ["Filesystem is corrupted", _after_ glibc updated]
  194. * 2/ 990 ["Unknown error 990"]
  195. * 3/ EUCLEAN ["Structure needs cleaning"]
  196. * 4/ Convert EFSCORRUPTED to EIO [just prior to return into userspace]
  197. */
  198. #define EFSCORRUPTED 990 /* Filesystem is corrupted */
  199. #define SYNCHRONIZE() barrier()
  200. #define __return_address __builtin_return_address(0)
  201. /*
  202. * IRIX (BSD) quotactl makes use of separate commands for user/group,
  203. * whereas on Linux the syscall encodes this information into the cmd
  204. * field (see the QCMD macro in quota.h). These macros help keep the
  205. * code portable - they are not visible from the syscall interface.
  206. */
  207. #define Q_XSETGQLIM XQM_CMD(8) /* set groups disk limits */
  208. #define Q_XGETGQUOTA XQM_CMD(9) /* get groups disk limits */
  209. #define Q_XSETPQLIM XQM_CMD(10) /* set projects disk limits */
  210. #define Q_XGETPQUOTA XQM_CMD(11) /* get projects disk limits */
  211. /* IRIX uses a dynamic sizing algorithm (ndquot = 200 + numprocs*2) */
  212. /* we may well need to fine-tune this if it ever becomes an issue. */
  213. #define DQUOT_MAX_HEURISTIC 1024 /* NR_DQUOTS */
  214. #define ndquot DQUOT_MAX_HEURISTIC
  215. /* IRIX uses the current size of the name cache to guess a good value */
  216. /* - this isn't the same but is a good enough starting point for now. */
  217. #define DQUOT_HASH_HEURISTIC files_stat.nr_files
  218. /* IRIX inodes maintain the project ID also, zero this field on Linux */
  219. #define DEFAULT_PROJID 0
  220. #define dfltprid DEFAULT_PROJID
  221. #define MAXPATHLEN 1024
  222. #define MIN(a,b) (min(a,b))
  223. #define MAX(a,b) (max(a,b))
  224. #define howmany(x, y) (((x)+((y)-1))/(y))
  225. #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
  226. #define xfs_stack_trace() dump_stack()
  227. #define xfs_itruncate_data(ip, off) \
  228. (-vmtruncate(LINVFS_GET_IP(XFS_ITOV(ip)), (off)))
  229. /* Move the kernel do_div definition off to one side */
  230. #if defined __i386__
  231. /* For ia32 we need to pull some tricks to get past various versions
  232. * of the compiler which do not like us using do_div in the middle
  233. * of large functions.
  234. */
  235. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  236. {
  237. __u32 mod;
  238. switch (n) {
  239. case 4:
  240. mod = *(__u32 *)a % b;
  241. *(__u32 *)a = *(__u32 *)a / b;
  242. return mod;
  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. *(__u64 *)a = c;
  256. return __mod;
  257. }
  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. unsigned long __upper, __low, __high, __mod;
  271. __u64 c = *(__u64 *)a;
  272. __upper = __high = c >> 32;
  273. __low = c;
  274. if (__high) {
  275. __upper = __high % (b);
  276. __high = __high / (b);
  277. }
  278. asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
  279. asm("":"=A" (c):"a" (__low),"d" (__high));
  280. return __mod;
  281. }
  282. }
  283. /* NOTREACHED */
  284. return 0;
  285. }
  286. #else
  287. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  288. {
  289. __u32 mod;
  290. switch (n) {
  291. case 4:
  292. mod = *(__u32 *)a % b;
  293. *(__u32 *)a = *(__u32 *)a / b;
  294. return mod;
  295. case 8:
  296. mod = do_div(*(__u64 *)a, b);
  297. return mod;
  298. }
  299. /* NOTREACHED */
  300. return 0;
  301. }
  302. /* Side effect free 64 bit mod operation */
  303. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  304. {
  305. switch (n) {
  306. case 4:
  307. return *(__u32 *)a % b;
  308. case 8:
  309. {
  310. __u64 c = *(__u64 *)a;
  311. return do_div(c, b);
  312. }
  313. }
  314. /* NOTREACHED */
  315. return 0;
  316. }
  317. #endif
  318. #undef do_div
  319. #define do_div(a, b) xfs_do_div(&(a), (b), sizeof(a))
  320. #define do_mod(a, b) xfs_do_mod(&(a), (b), sizeof(a))
  321. static inline __uint64_t roundup_64(__uint64_t x, __uint32_t y)
  322. {
  323. x += y - 1;
  324. do_div(x, y);
  325. return(x * y);
  326. }
  327. #define qsort(a, n, s, cmp) sort(a, n, s, cmp, NULL)
  328. #endif /* __XFS_LINUX__ */