xfs_linux.h 7.3 KB

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