xfs_linux.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. * Kernel specific type declarations for XFS
  23. */
  24. typedef signed char __int8_t;
  25. typedef unsigned char __uint8_t;
  26. typedef signed short int __int16_t;
  27. typedef unsigned short int __uint16_t;
  28. typedef signed int __int32_t;
  29. typedef unsigned int __uint32_t;
  30. typedef signed long long int __int64_t;
  31. typedef unsigned long long int __uint64_t;
  32. typedef __uint32_t inst_t; /* an instruction */
  33. typedef __s64 xfs_off_t; /* <file offset> type */
  34. typedef unsigned long long xfs_ino_t; /* <inode> type */
  35. typedef __s64 xfs_daddr_t; /* <disk address> type */
  36. typedef char * xfs_caddr_t; /* <core address> type */
  37. typedef __u32 xfs_dev_t;
  38. typedef __u32 xfs_nlink_t;
  39. /* __psint_t is the same size as a pointer */
  40. #if (BITS_PER_LONG == 32)
  41. typedef __int32_t __psint_t;
  42. typedef __uint32_t __psunsigned_t;
  43. #elif (BITS_PER_LONG == 64)
  44. typedef __int64_t __psint_t;
  45. typedef __uint64_t __psunsigned_t;
  46. #else
  47. #error BITS_PER_LONG must be 32 or 64
  48. #endif
  49. #include "xfs_types.h"
  50. #include "kmem.h"
  51. #include "mrlock.h"
  52. #include "uuid.h"
  53. #include <linux/semaphore.h>
  54. #include <linux/mm.h>
  55. #include <linux/kernel.h>
  56. #include <linux/blkdev.h>
  57. #include <linux/slab.h>
  58. #include <linux/crc32c.h>
  59. #include <linux/module.h>
  60. #include <linux/mutex.h>
  61. #include <linux/file.h>
  62. #include <linux/swap.h>
  63. #include <linux/errno.h>
  64. #include <linux/sched.h>
  65. #include <linux/bitops.h>
  66. #include <linux/major.h>
  67. #include <linux/pagemap.h>
  68. #include <linux/vfs.h>
  69. #include <linux/seq_file.h>
  70. #include <linux/init.h>
  71. #include <linux/list.h>
  72. #include <linux/proc_fs.h>
  73. #include <linux/sort.h>
  74. #include <linux/cpu.h>
  75. #include <linux/notifier.h>
  76. #include <linux/delay.h>
  77. #include <linux/log2.h>
  78. #include <linux/spinlock.h>
  79. #include <linux/random.h>
  80. #include <linux/ctype.h>
  81. #include <linux/writeback.h>
  82. #include <linux/capability.h>
  83. #include <linux/kthread.h>
  84. #include <linux/freezer.h>
  85. #include <linux/list_sort.h>
  86. #include <linux/ratelimit.h>
  87. #include <asm/page.h>
  88. #include <asm/div64.h>
  89. #include <asm/param.h>
  90. #include <asm/uaccess.h>
  91. #include <asm/byteorder.h>
  92. #include <asm/unaligned.h>
  93. #include "xfs_fs.h"
  94. #include "xfs_stats.h"
  95. #include "xfs_sysctl.h"
  96. #include "xfs_iops.h"
  97. #include "xfs_aops.h"
  98. #include "xfs_super.h"
  99. #include "xfs_cksum.h"
  100. #include "xfs_buf.h"
  101. #include "xfs_message.h"
  102. #ifdef __BIG_ENDIAN
  103. #define XFS_NATIVE_HOST 1
  104. #else
  105. #undef XFS_NATIVE_HOST
  106. #endif
  107. #define irix_sgid_inherit xfs_params.sgid_inherit.val
  108. #define irix_symlink_mode xfs_params.symlink_mode.val
  109. #define xfs_panic_mask xfs_params.panic_mask.val
  110. #define xfs_error_level xfs_params.error_level.val
  111. #define xfs_syncd_centisecs xfs_params.syncd_timer.val
  112. #define xfs_stats_clear xfs_params.stats_clear.val
  113. #define xfs_inherit_sync xfs_params.inherit_sync.val
  114. #define xfs_inherit_nodump xfs_params.inherit_nodump.val
  115. #define xfs_inherit_noatime xfs_params.inherit_noatim.val
  116. #define xfs_inherit_nosymlinks xfs_params.inherit_nosym.val
  117. #define xfs_rotorstep xfs_params.rotorstep.val
  118. #define xfs_inherit_nodefrag xfs_params.inherit_nodfrg.val
  119. #define xfs_fstrm_centisecs xfs_params.fstrm_timer.val
  120. #define xfs_eofb_secs xfs_params.eofb_timer.val
  121. #define current_cpu() (raw_smp_processor_id())
  122. #define current_pid() (current->pid)
  123. #define current_test_flags(f) (current->flags & (f))
  124. #define current_set_flags_nested(sp, f) \
  125. (*(sp) = current->flags, current->flags |= (f))
  126. #define current_clear_flags_nested(sp, f) \
  127. (*(sp) = current->flags, current->flags &= ~(f))
  128. #define current_restore_flags_nested(sp, f) \
  129. (current->flags = ((current->flags & ~(f)) | (*(sp) & (f))))
  130. #define spinlock_destroy(lock)
  131. #define NBBY 8 /* number of bits per byte */
  132. /*
  133. * Size of block device i/o is parameterized here.
  134. * Currently the system supports page-sized i/o.
  135. */
  136. #define BLKDEV_IOSHIFT PAGE_CACHE_SHIFT
  137. #define BLKDEV_IOSIZE (1<<BLKDEV_IOSHIFT)
  138. /* number of BB's per block device block */
  139. #define BLKDEV_BB BTOBB(BLKDEV_IOSIZE)
  140. #define ENOATTR ENODATA /* Attribute not found */
  141. #define EWRONGFS EINVAL /* Mount with wrong filesystem type */
  142. #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
  143. #define EFSBADCRC EBADMSG /* Bad CRC detected */
  144. #define SYNCHRONIZE() barrier()
  145. #define __return_address __builtin_return_address(0)
  146. #define XFS_PROJID_DEFAULT 0
  147. #define MAXPATHLEN 1024
  148. #define MIN(a,b) (min(a,b))
  149. #define MAX(a,b) (max(a,b))
  150. #define howmany(x, y) (((x)+((y)-1))/(y))
  151. static inline void delay(long ticks)
  152. {
  153. schedule_timeout_uninterruptible(ticks);
  154. }
  155. /*
  156. * XFS wrapper structure for sysfs support. It depends on external data
  157. * structures and is embedded in various internal data structures to implement
  158. * the XFS sysfs object heirarchy. Define it here for broad access throughout
  159. * the codebase.
  160. */
  161. struct xfs_kobj {
  162. struct kobject kobject;
  163. struct completion complete;
  164. };
  165. /* Kernel uid/gid conversion. These are used to convert to/from the on disk
  166. * uid_t/gid_t types to the kuid_t/kgid_t types that the kernel uses internally.
  167. * The conversion here is type only, the value will remain the same since we
  168. * are converting to the init_user_ns. The uid is later mapped to a particular
  169. * user namespace value when crossing the kernel/user boundary.
  170. */
  171. static inline __uint32_t xfs_kuid_to_uid(kuid_t uid)
  172. {
  173. return from_kuid(&init_user_ns, uid);
  174. }
  175. static inline kuid_t xfs_uid_to_kuid(__uint32_t uid)
  176. {
  177. return make_kuid(&init_user_ns, uid);
  178. }
  179. static inline __uint32_t xfs_kgid_to_gid(kgid_t gid)
  180. {
  181. return from_kgid(&init_user_ns, gid);
  182. }
  183. static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
  184. {
  185. return make_kgid(&init_user_ns, gid);
  186. }
  187. /*
  188. * Various platform dependent calls that don't fit anywhere else
  189. */
  190. #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL)
  191. #define xfs_stack_trace() dump_stack()
  192. /* Move the kernel do_div definition off to one side */
  193. #if defined __i386__
  194. /* For ia32 we need to pull some tricks to get past various versions
  195. * of the compiler which do not like us using do_div in the middle
  196. * of large functions.
  197. */
  198. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  199. {
  200. __u32 mod;
  201. switch (n) {
  202. case 4:
  203. mod = *(__u32 *)a % b;
  204. *(__u32 *)a = *(__u32 *)a / b;
  205. return mod;
  206. case 8:
  207. {
  208. unsigned long __upper, __low, __high, __mod;
  209. __u64 c = *(__u64 *)a;
  210. __upper = __high = c >> 32;
  211. __low = c;
  212. if (__high) {
  213. __upper = __high % (b);
  214. __high = __high / (b);
  215. }
  216. asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
  217. asm("":"=A" (c):"a" (__low),"d" (__high));
  218. *(__u64 *)a = c;
  219. return __mod;
  220. }
  221. }
  222. /* NOTREACHED */
  223. return 0;
  224. }
  225. /* Side effect free 64 bit mod operation */
  226. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  227. {
  228. switch (n) {
  229. case 4:
  230. return *(__u32 *)a % b;
  231. case 8:
  232. {
  233. unsigned long __upper, __low, __high, __mod;
  234. __u64 c = *(__u64 *)a;
  235. __upper = __high = c >> 32;
  236. __low = c;
  237. if (__high) {
  238. __upper = __high % (b);
  239. __high = __high / (b);
  240. }
  241. asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
  242. asm("":"=A" (c):"a" (__low),"d" (__high));
  243. return __mod;
  244. }
  245. }
  246. /* NOTREACHED */
  247. return 0;
  248. }
  249. #else
  250. static inline __u32 xfs_do_div(void *a, __u32 b, int n)
  251. {
  252. __u32 mod;
  253. switch (n) {
  254. case 4:
  255. mod = *(__u32 *)a % b;
  256. *(__u32 *)a = *(__u32 *)a / b;
  257. return mod;
  258. case 8:
  259. mod = do_div(*(__u64 *)a, b);
  260. return mod;
  261. }
  262. /* NOTREACHED */
  263. return 0;
  264. }
  265. /* Side effect free 64 bit mod operation */
  266. static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
  267. {
  268. switch (n) {
  269. case 4:
  270. return *(__u32 *)a % b;
  271. case 8:
  272. {
  273. __u64 c = *(__u64 *)a;
  274. return do_div(c, b);
  275. }
  276. }
  277. /* NOTREACHED */
  278. return 0;
  279. }
  280. #endif
  281. #undef do_div
  282. #define do_div(a, b) xfs_do_div(&(a), (b), sizeof(a))
  283. #define do_mod(a, b) xfs_do_mod(&(a), (b), sizeof(a))
  284. static inline __uint64_t roundup_64(__uint64_t x, __uint32_t y)
  285. {
  286. x += y - 1;
  287. do_div(x, y);
  288. return x * y;
  289. }
  290. static inline __uint64_t howmany_64(__uint64_t x, __uint32_t y)
  291. {
  292. x += y - 1;
  293. do_div(x, y);
  294. return x;
  295. }
  296. /* ARM old ABI has some weird alignment/padding */
  297. #if defined(__arm__) && !defined(__ARM_EABI__)
  298. #define __arch_pack __attribute__((packed))
  299. #else
  300. #define __arch_pack
  301. #endif
  302. #define ASSERT_ALWAYS(expr) \
  303. (unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
  304. #ifdef DEBUG
  305. #define ASSERT(expr) \
  306. (unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
  307. #ifndef STATIC
  308. # define STATIC noinline
  309. #endif
  310. #else /* !DEBUG */
  311. #ifdef XFS_WARN
  312. #define ASSERT(expr) \
  313. (unlikely(expr) ? (void)0 : asswarn(#expr, __FILE__, __LINE__))
  314. #ifndef STATIC
  315. # define STATIC static noinline
  316. #endif
  317. #else /* !DEBUG && !XFS_WARN */
  318. #define ASSERT(expr) ((void)0)
  319. #ifndef STATIC
  320. # define STATIC static noinline
  321. #endif
  322. #endif /* XFS_WARN */
  323. #endif /* DEBUG */
  324. #ifdef CONFIG_XFS_RT
  325. #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
  326. #else
  327. #define XFS_IS_REALTIME_INODE(ip) (0)
  328. #endif
  329. #endif /* __XFS_LINUX__ */