xfs_linux.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  4. * All Rights Reserved.
  5. */
  6. #ifndef __XFS_LINUX__
  7. #define __XFS_LINUX__
  8. #include <linux/types.h>
  9. #include <linux/uuid.h>
  10. /*
  11. * Kernel specific type declarations for XFS
  12. */
  13. typedef __s64 xfs_off_t; /* <file offset> type */
  14. typedef unsigned long long xfs_ino_t; /* <inode> type */
  15. typedef __s64 xfs_daddr_t; /* <disk address> type */
  16. typedef __u32 xfs_dev_t;
  17. typedef __u32 xfs_nlink_t;
  18. #include "xfs_types.h"
  19. #include "kmem.h"
  20. #include "mrlock.h"
  21. #include <linux/semaphore.h>
  22. #include <linux/mm.h>
  23. #include <linux/sched/mm.h>
  24. #include <linux/kernel.h>
  25. #include <linux/blkdev.h>
  26. #include <linux/slab.h>
  27. #include <linux/crc32c.h>
  28. #include <linux/module.h>
  29. #include <linux/mutex.h>
  30. #include <linux/file.h>
  31. #include <linux/swap.h>
  32. #include <linux/errno.h>
  33. #include <linux/sched/signal.h>
  34. #include <linux/bitops.h>
  35. #include <linux/major.h>
  36. #include <linux/pagemap.h>
  37. #include <linux/vfs.h>
  38. #include <linux/seq_file.h>
  39. #include <linux/init.h>
  40. #include <linux/list.h>
  41. #include <linux/proc_fs.h>
  42. #include <linux/sort.h>
  43. #include <linux/cpu.h>
  44. #include <linux/notifier.h>
  45. #include <linux/delay.h>
  46. #include <linux/log2.h>
  47. #include <linux/spinlock.h>
  48. #include <linux/random.h>
  49. #include <linux/ctype.h>
  50. #include <linux/writeback.h>
  51. #include <linux/capability.h>
  52. #include <linux/kthread.h>
  53. #include <linux/freezer.h>
  54. #include <linux/list_sort.h>
  55. #include <linux/ratelimit.h>
  56. #include <linux/rhashtable.h>
  57. #include <asm/page.h>
  58. #include <asm/div64.h>
  59. #include <asm/param.h>
  60. #include <linux/uaccess.h>
  61. #include <asm/byteorder.h>
  62. #include <asm/unaligned.h>
  63. #include "xfs_fs.h"
  64. #include "xfs_stats.h"
  65. #include "xfs_sysctl.h"
  66. #include "xfs_iops.h"
  67. #include "xfs_aops.h"
  68. #include "xfs_super.h"
  69. #include "xfs_cksum.h"
  70. #include "xfs_buf.h"
  71. #include "xfs_message.h"
  72. #ifdef __BIG_ENDIAN
  73. #define XFS_NATIVE_HOST 1
  74. #else
  75. #undef XFS_NATIVE_HOST
  76. #endif
  77. #define irix_sgid_inherit xfs_params.sgid_inherit.val
  78. #define irix_symlink_mode xfs_params.symlink_mode.val
  79. #define xfs_panic_mask xfs_params.panic_mask.val
  80. #define xfs_error_level xfs_params.error_level.val
  81. #define xfs_syncd_centisecs xfs_params.syncd_timer.val
  82. #define xfs_stats_clear xfs_params.stats_clear.val
  83. #define xfs_inherit_sync xfs_params.inherit_sync.val
  84. #define xfs_inherit_nodump xfs_params.inherit_nodump.val
  85. #define xfs_inherit_noatime xfs_params.inherit_noatim.val
  86. #define xfs_inherit_nosymlinks xfs_params.inherit_nosym.val
  87. #define xfs_rotorstep xfs_params.rotorstep.val
  88. #define xfs_inherit_nodefrag xfs_params.inherit_nodfrg.val
  89. #define xfs_fstrm_centisecs xfs_params.fstrm_timer.val
  90. #define xfs_eofb_secs xfs_params.eofb_timer.val
  91. #define xfs_cowb_secs xfs_params.cowb_timer.val
  92. #define current_cpu() (raw_smp_processor_id())
  93. #define current_pid() (current->pid)
  94. #define current_test_flags(f) (current->flags & (f))
  95. #define current_set_flags_nested(sp, f) \
  96. (*(sp) = current->flags, current->flags |= (f))
  97. #define current_clear_flags_nested(sp, f) \
  98. (*(sp) = current->flags, current->flags &= ~(f))
  99. #define current_restore_flags_nested(sp, f) \
  100. (current->flags = ((current->flags & ~(f)) | (*(sp) & (f))))
  101. #define spinlock_destroy(lock)
  102. #define NBBY 8 /* number of bits per byte */
  103. /*
  104. * Size of block device i/o is parameterized here.
  105. * Currently the system supports page-sized i/o.
  106. */
  107. #define BLKDEV_IOSHIFT PAGE_SHIFT
  108. #define BLKDEV_IOSIZE (1<<BLKDEV_IOSHIFT)
  109. /* number of BB's per block device block */
  110. #define BLKDEV_BB BTOBB(BLKDEV_IOSIZE)
  111. #define ENOATTR ENODATA /* Attribute not found */
  112. #define EWRONGFS EINVAL /* Mount with wrong filesystem type */
  113. #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
  114. #define EFSBADCRC EBADMSG /* Bad CRC detected */
  115. #define SYNCHRONIZE() barrier()
  116. #define __return_address __builtin_return_address(0)
  117. /*
  118. * Return the address of a label. Use barrier() so that the optimizer
  119. * won't reorder code to refactor the error jumpouts into a single
  120. * return, which throws off the reported address.
  121. */
  122. #define __this_address ({ __label__ __here; __here: barrier(); &&__here; })
  123. #define XFS_PROJID_DEFAULT 0
  124. #define howmany(x, y) (((x)+((y)-1))/(y))
  125. static inline void delay(long ticks)
  126. {
  127. schedule_timeout_uninterruptible(ticks);
  128. }
  129. /*
  130. * XFS wrapper structure for sysfs support. It depends on external data
  131. * structures and is embedded in various internal data structures to implement
  132. * the XFS sysfs object heirarchy. Define it here for broad access throughout
  133. * the codebase.
  134. */
  135. struct xfs_kobj {
  136. struct kobject kobject;
  137. struct completion complete;
  138. };
  139. struct xstats {
  140. struct xfsstats __percpu *xs_stats;
  141. struct xfs_kobj xs_kobj;
  142. };
  143. extern struct xstats xfsstats;
  144. /* Kernel uid/gid conversion. These are used to convert to/from the on disk
  145. * uid_t/gid_t types to the kuid_t/kgid_t types that the kernel uses internally.
  146. * The conversion here is type only, the value will remain the same since we
  147. * are converting to the init_user_ns. The uid is later mapped to a particular
  148. * user namespace value when crossing the kernel/user boundary.
  149. */
  150. static inline uint32_t xfs_kuid_to_uid(kuid_t uid)
  151. {
  152. return from_kuid(&init_user_ns, uid);
  153. }
  154. static inline kuid_t xfs_uid_to_kuid(uint32_t uid)
  155. {
  156. return make_kuid(&init_user_ns, uid);
  157. }
  158. static inline uint32_t xfs_kgid_to_gid(kgid_t gid)
  159. {
  160. return from_kgid(&init_user_ns, gid);
  161. }
  162. static inline kgid_t xfs_gid_to_kgid(uint32_t gid)
  163. {
  164. return make_kgid(&init_user_ns, gid);
  165. }
  166. static inline dev_t xfs_to_linux_dev_t(xfs_dev_t dev)
  167. {
  168. return MKDEV(sysv_major(dev) & 0x1ff, sysv_minor(dev));
  169. }
  170. static inline xfs_dev_t linux_to_xfs_dev_t(dev_t dev)
  171. {
  172. return sysv_encode_dev(dev);
  173. }
  174. /*
  175. * Various platform dependent calls that don't fit anywhere else
  176. */
  177. #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL)
  178. #define xfs_stack_trace() dump_stack()
  179. static inline uint64_t roundup_64(uint64_t x, uint32_t y)
  180. {
  181. x += y - 1;
  182. do_div(x, y);
  183. return x * y;
  184. }
  185. static inline uint64_t howmany_64(uint64_t x, uint32_t y)
  186. {
  187. x += y - 1;
  188. do_div(x, y);
  189. return x;
  190. }
  191. #define ASSERT_ALWAYS(expr) \
  192. (likely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
  193. #ifdef DEBUG
  194. #define ASSERT(expr) \
  195. (likely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
  196. #else /* !DEBUG */
  197. #ifdef XFS_WARN
  198. #define ASSERT(expr) \
  199. (likely(expr) ? (void)0 : asswarn(#expr, __FILE__, __LINE__))
  200. #else /* !DEBUG && !XFS_WARN */
  201. #define ASSERT(expr) ((void)0)
  202. #endif /* XFS_WARN */
  203. #endif /* DEBUG */
  204. #define STATIC static noinline
  205. #ifdef CONFIG_XFS_RT
  206. /*
  207. * make sure we ignore the inode flag if the filesystem doesn't have a
  208. * configured realtime device.
  209. */
  210. #define XFS_IS_REALTIME_INODE(ip) \
  211. (((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME) && \
  212. (ip)->i_mount->m_rtdev_targp)
  213. #define XFS_IS_REALTIME_MOUNT(mp) ((mp)->m_rtdev_targp ? 1 : 0)
  214. #else
  215. #define XFS_IS_REALTIME_INODE(ip) (0)
  216. #define XFS_IS_REALTIME_MOUNT(mp) (0)
  217. #endif
  218. /*
  219. * Starting in Linux 4.15, the %p (raw pointer value) printk modifier
  220. * prints a hashed version of the pointer to avoid leaking kernel
  221. * pointers into dmesg. If we're trying to debug the kernel we want the
  222. * raw values, so override this behavior as best we can.
  223. */
  224. #ifdef DEBUG
  225. # define PTR_FMT "%px"
  226. #else
  227. # define PTR_FMT "%p"
  228. #endif
  229. #endif /* __XFS_LINUX__ */