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