xfs_linux.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 <linux/xattr.h>
  58. #include <asm/page.h>
  59. #include <asm/div64.h>
  60. #include <asm/param.h>
  61. #include <linux/uaccess.h>
  62. #include <asm/byteorder.h>
  63. #include <asm/unaligned.h>
  64. #include "xfs_fs.h"
  65. #include "xfs_stats.h"
  66. #include "xfs_sysctl.h"
  67. #include "xfs_iops.h"
  68. #include "xfs_aops.h"
  69. #include "xfs_super.h"
  70. #include "xfs_cksum.h"
  71. #include "xfs_buf.h"
  72. #include "xfs_message.h"
  73. #ifdef __BIG_ENDIAN
  74. #define XFS_NATIVE_HOST 1
  75. #else
  76. #undef XFS_NATIVE_HOST
  77. #endif
  78. #define irix_sgid_inherit xfs_params.sgid_inherit.val
  79. #define irix_symlink_mode xfs_params.symlink_mode.val
  80. #define xfs_panic_mask xfs_params.panic_mask.val
  81. #define xfs_error_level xfs_params.error_level.val
  82. #define xfs_syncd_centisecs xfs_params.syncd_timer.val
  83. #define xfs_stats_clear xfs_params.stats_clear.val
  84. #define xfs_inherit_sync xfs_params.inherit_sync.val
  85. #define xfs_inherit_nodump xfs_params.inherit_nodump.val
  86. #define xfs_inherit_noatime xfs_params.inherit_noatim.val
  87. #define xfs_inherit_nosymlinks xfs_params.inherit_nosym.val
  88. #define xfs_rotorstep xfs_params.rotorstep.val
  89. #define xfs_inherit_nodefrag xfs_params.inherit_nodfrg.val
  90. #define xfs_fstrm_centisecs xfs_params.fstrm_timer.val
  91. #define xfs_eofb_secs xfs_params.eofb_timer.val
  92. #define xfs_cowb_secs xfs_params.cowb_timer.val
  93. #define current_cpu() (raw_smp_processor_id())
  94. #define current_set_flags_nested(sp, f) \
  95. (*(sp) = current->flags, current->flags |= (f))
  96. #define current_restore_flags_nested(sp, f) \
  97. (current->flags = ((current->flags & ~(f)) | (*(sp) & (f))))
  98. #define NBBY 8 /* number of bits per byte */
  99. /*
  100. * Size of block device i/o is parameterized here.
  101. * Currently the system supports page-sized i/o.
  102. */
  103. #define BLKDEV_IOSHIFT PAGE_SHIFT
  104. #define BLKDEV_IOSIZE (1<<BLKDEV_IOSHIFT)
  105. /* number of BB's per block device block */
  106. #define BLKDEV_BB BTOBB(BLKDEV_IOSIZE)
  107. #define ENOATTR ENODATA /* Attribute not found */
  108. #define EWRONGFS EINVAL /* Mount with wrong filesystem type */
  109. #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
  110. #define EFSBADCRC EBADMSG /* Bad CRC detected */
  111. #define __return_address __builtin_return_address(0)
  112. /*
  113. * Return the address of a label. Use barrier() so that the optimizer
  114. * won't reorder code to refactor the error jumpouts into a single
  115. * return, which throws off the reported address.
  116. */
  117. #define __this_address ({ __label__ __here; __here: barrier(); &&__here; })
  118. #define XFS_PROJID_DEFAULT 0
  119. #define howmany(x, y) (((x)+((y)-1))/(y))
  120. static inline void delay(long ticks)
  121. {
  122. schedule_timeout_uninterruptible(ticks);
  123. }
  124. /*
  125. * XFS wrapper structure for sysfs support. It depends on external data
  126. * structures and is embedded in various internal data structures to implement
  127. * the XFS sysfs object heirarchy. Define it here for broad access throughout
  128. * the codebase.
  129. */
  130. struct xfs_kobj {
  131. struct kobject kobject;
  132. struct completion complete;
  133. };
  134. struct xstats {
  135. struct xfsstats __percpu *xs_stats;
  136. struct xfs_kobj xs_kobj;
  137. };
  138. extern struct xstats xfsstats;
  139. static inline dev_t xfs_to_linux_dev_t(xfs_dev_t dev)
  140. {
  141. return MKDEV(sysv_major(dev) & 0x1ff, sysv_minor(dev));
  142. }
  143. static inline xfs_dev_t linux_to_xfs_dev_t(dev_t dev)
  144. {
  145. return sysv_encode_dev(dev);
  146. }
  147. /*
  148. * Various platform dependent calls that don't fit anywhere else
  149. */
  150. #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL)
  151. #define xfs_stack_trace() dump_stack()
  152. static inline uint64_t rounddown_64(uint64_t x, uint32_t y)
  153. {
  154. do_div(x, y);
  155. return x * y;
  156. }
  157. static inline uint64_t roundup_64(uint64_t x, uint32_t y)
  158. {
  159. x += y - 1;
  160. do_div(x, y);
  161. return x * y;
  162. }
  163. static inline uint64_t howmany_64(uint64_t x, uint32_t y)
  164. {
  165. x += y - 1;
  166. do_div(x, y);
  167. return x;
  168. }
  169. int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count,
  170. char *data, unsigned int op);
  171. #define ASSERT_ALWAYS(expr) \
  172. (likely(expr) ? (void)0 : assfail(NULL, #expr, __FILE__, __LINE__))
  173. #ifdef DEBUG
  174. #define ASSERT(expr) \
  175. (likely(expr) ? (void)0 : assfail(NULL, #expr, __FILE__, __LINE__))
  176. #else /* !DEBUG */
  177. #ifdef XFS_WARN
  178. #define ASSERT(expr) \
  179. (likely(expr) ? (void)0 : asswarn(NULL, #expr, __FILE__, __LINE__))
  180. #else /* !DEBUG && !XFS_WARN */
  181. #define ASSERT(expr) ((void)0)
  182. #endif /* XFS_WARN */
  183. #endif /* DEBUG */
  184. #define XFS_IS_CORRUPT(mp, expr) \
  185. (unlikely(expr) ? xfs_corruption_error(#expr, XFS_ERRLEVEL_LOW, (mp), \
  186. NULL, 0, __FILE__, __LINE__, \
  187. __this_address), \
  188. true : false)
  189. #define STATIC static noinline
  190. #ifdef CONFIG_XFS_RT
  191. /*
  192. * make sure we ignore the inode flag if the filesystem doesn't have a
  193. * configured realtime device.
  194. */
  195. #define XFS_IS_REALTIME_INODE(ip) \
  196. (((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME) && \
  197. (ip)->i_mount->m_rtdev_targp)
  198. #define XFS_IS_REALTIME_MOUNT(mp) ((mp)->m_rtdev_targp ? 1 : 0)
  199. #else
  200. #define XFS_IS_REALTIME_INODE(ip) (0)
  201. #define XFS_IS_REALTIME_MOUNT(mp) (0)
  202. #endif
  203. /*
  204. * Starting in Linux 4.15, the %p (raw pointer value) printk modifier
  205. * prints a hashed version of the pointer to avoid leaking kernel
  206. * pointers into dmesg. If we're trying to debug the kernel we want the
  207. * raw values, so override this behavior as best we can.
  208. */
  209. #ifdef DEBUG
  210. # define PTR_FMT "%px"
  211. #else
  212. # define PTR_FMT "%p"
  213. #endif
  214. #endif /* __XFS_LINUX__ */