xfs_linux.h 9.8 KB

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