Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu
[pandora-kernel.git] / fs / xfs / linux-2.6 / xfs_linux.h
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
21 #include <linux/types.h>
22
23 /*
24  * XFS_BIG_BLKNOS needs block layer disk addresses to be 64 bits.
25  * XFS_BIG_INUMS requires XFS_BIG_BLKNOS to be set.
26  */
27 #if defined(CONFIG_LBDAF) || (BITS_PER_LONG == 64)
28 # define XFS_BIG_BLKNOS 1
29 # define XFS_BIG_INUMS  1
30 #else
31 # define XFS_BIG_BLKNOS 0
32 # define XFS_BIG_INUMS  0
33 #endif
34
35 #include <xfs_types.h>
36 #include <xfs_arch.h>
37
38 #include <kmem.h>
39 #include <mrlock.h>
40 #include <time.h>
41
42 #include <support/uuid.h>
43
44 #include <linux/semaphore.h>
45 #include <linux/mm.h>
46 #include <linux/kernel.h>
47 #include <linux/blkdev.h>
48 #include <linux/slab.h>
49 #include <linux/module.h>
50 #include <linux/mutex.h>
51 #include <linux/file.h>
52 #include <linux/swap.h>
53 #include <linux/errno.h>
54 #include <linux/sched.h>
55 #include <linux/bitops.h>
56 #include <linux/major.h>
57 #include <linux/pagemap.h>
58 #include <linux/vfs.h>
59 #include <linux/seq_file.h>
60 #include <linux/init.h>
61 #include <linux/list.h>
62 #include <linux/proc_fs.h>
63 #include <linux/sort.h>
64 #include <linux/cpu.h>
65 #include <linux/notifier.h>
66 #include <linux/delay.h>
67 #include <linux/log2.h>
68 #include <linux/spinlock.h>
69 #include <linux/random.h>
70 #include <linux/ctype.h>
71 #include <linux/writeback.h>
72 #include <linux/capability.h>
73 #include <linux/list_sort.h>
74
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
82 #include <xfs_vnode.h>
83 #include <xfs_stats.h>
84 #include <xfs_sysctl.h>
85 #include <xfs_iops.h>
86 #include <xfs_aops.h>
87 #include <xfs_super.h>
88 #include <xfs_buf.h>
89 #include <xfs_message.h>
90
91 /*
92  * Feature macros (disable/enable)
93  */
94 #ifdef CONFIG_SMP
95 #define HAVE_PERCPU_SB  /* per cpu superblock counters are a 2.6 feature */
96 #else
97 #undef  HAVE_PERCPU_SB  /* per cpu superblock counters are a 2.6 feature */
98 #endif
99
100 #define irix_sgid_inherit       xfs_params.sgid_inherit.val
101 #define irix_symlink_mode       xfs_params.symlink_mode.val
102 #define xfs_panic_mask          xfs_params.panic_mask.val
103 #define xfs_error_level         xfs_params.error_level.val
104 #define xfs_syncd_centisecs     xfs_params.syncd_timer.val
105 #define xfs_stats_clear         xfs_params.stats_clear.val
106 #define xfs_inherit_sync        xfs_params.inherit_sync.val
107 #define xfs_inherit_nodump      xfs_params.inherit_nodump.val
108 #define xfs_inherit_noatime     xfs_params.inherit_noatim.val
109 #define xfs_buf_timer_centisecs xfs_params.xfs_buf_timer.val
110 #define xfs_buf_age_centisecs   xfs_params.xfs_buf_age.val
111 #define xfs_inherit_nosymlinks  xfs_params.inherit_nosym.val
112 #define xfs_rotorstep           xfs_params.rotorstep.val
113 #define xfs_inherit_nodefrag    xfs_params.inherit_nodfrg.val
114 #define xfs_fstrm_centisecs     xfs_params.fstrm_timer.val
115
116 #define current_cpu()           (raw_smp_processor_id())
117 #define current_pid()           (current->pid)
118 #define current_test_flags(f)   (current->flags & (f))
119 #define current_set_flags_nested(sp, f)         \
120                 (*(sp) = current->flags, current->flags |= (f))
121 #define current_clear_flags_nested(sp, f)       \
122                 (*(sp) = current->flags, current->flags &= ~(f))
123 #define current_restore_flags_nested(sp, f)     \
124                 (current->flags = ((current->flags & ~(f)) | (*(sp) & (f))))
125
126 #define spinlock_destroy(lock)
127
128 #define NBBY            8               /* number of bits per byte */
129
130 /*
131  * Size of block device i/o is parameterized here.
132  * Currently the system supports page-sized i/o.
133  */
134 #define BLKDEV_IOSHIFT          PAGE_CACHE_SHIFT
135 #define BLKDEV_IOSIZE           (1<<BLKDEV_IOSHIFT)
136 /* number of BB's per block device block */
137 #define BLKDEV_BB               BTOBB(BLKDEV_IOSIZE)
138
139 #define ENOATTR         ENODATA         /* Attribute not found */
140 #define EWRONGFS        EINVAL          /* Mount with wrong filesystem type */
141 #define EFSCORRUPTED    EUCLEAN         /* Filesystem is corrupted */
142
143 #define SYNCHRONIZE()   barrier()
144 #define __return_address __builtin_return_address(0)
145
146 #define XFS_PROJID_DEFAULT      0
147 #define MAXPATHLEN      1024
148
149 #define MIN(a,b)        (min(a,b))
150 #define MAX(a,b)        (max(a,b))
151 #define howmany(x, y)   (((x)+((y)-1))/(y))
152
153 /*
154  * Various platform dependent calls that don't fit anywhere else
155  */
156 #define xfs_sort(a,n,s,fn)      sort(a,n,s,fn,NULL)
157 #define xfs_stack_trace()       dump_stack()
158
159
160 /* Move the kernel do_div definition off to one side */
161
162 #if defined __i386__
163 /* For ia32 we need to pull some tricks to get past various versions
164  * of the compiler which do not like us using do_div in the middle
165  * of large functions.
166  */
167 static inline __u32 xfs_do_div(void *a, __u32 b, int n)
168 {
169         __u32   mod;
170
171         switch (n) {
172                 case 4:
173                         mod = *(__u32 *)a % b;
174                         *(__u32 *)a = *(__u32 *)a / b;
175                         return mod;
176                 case 8:
177                         {
178                         unsigned long __upper, __low, __high, __mod;
179                         __u64   c = *(__u64 *)a;
180                         __upper = __high = c >> 32;
181                         __low = c;
182                         if (__high) {
183                                 __upper = __high % (b);
184                                 __high = __high / (b);
185                         }
186                         asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
187                         asm("":"=A" (c):"a" (__low),"d" (__high));
188                         *(__u64 *)a = c;
189                         return __mod;
190                         }
191         }
192
193         /* NOTREACHED */
194         return 0;
195 }
196
197 /* Side effect free 64 bit mod operation */
198 static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
199 {
200         switch (n) {
201                 case 4:
202                         return *(__u32 *)a % b;
203                 case 8:
204                         {
205                         unsigned long __upper, __low, __high, __mod;
206                         __u64   c = *(__u64 *)a;
207                         __upper = __high = c >> 32;
208                         __low = c;
209                         if (__high) {
210                                 __upper = __high % (b);
211                                 __high = __high / (b);
212                         }
213                         asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
214                         asm("":"=A" (c):"a" (__low),"d" (__high));
215                         return __mod;
216                         }
217         }
218
219         /* NOTREACHED */
220         return 0;
221 }
222 #else
223 static inline __u32 xfs_do_div(void *a, __u32 b, int n)
224 {
225         __u32   mod;
226
227         switch (n) {
228                 case 4:
229                         mod = *(__u32 *)a % b;
230                         *(__u32 *)a = *(__u32 *)a / b;
231                         return mod;
232                 case 8:
233                         mod = do_div(*(__u64 *)a, b);
234                         return mod;
235         }
236
237         /* NOTREACHED */
238         return 0;
239 }
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                         __u64   c = *(__u64 *)a;
250                         return do_div(c, b);
251                         }
252         }
253
254         /* NOTREACHED */
255         return 0;
256 }
257 #endif
258
259 #undef do_div
260 #define do_div(a, b)    xfs_do_div(&(a), (b), sizeof(a))
261 #define do_mod(a, b)    xfs_do_mod(&(a), (b), sizeof(a))
262
263 static inline __uint64_t roundup_64(__uint64_t x, __uint32_t y)
264 {
265         x += y - 1;
266         do_div(x, y);
267         return(x * y);
268 }
269
270 static inline __uint64_t howmany_64(__uint64_t x, __uint32_t y)
271 {
272         x += y - 1;
273         do_div(x, y);
274         return x;
275 }
276
277 /* ARM old ABI has some weird alignment/padding */
278 #if defined(__arm__) && !defined(__ARM_EABI__)
279 #define __arch_pack __attribute__((packed))
280 #else
281 #define __arch_pack
282 #endif
283
284 #define ASSERT_ALWAYS(expr)     \
285         (unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
286
287 #ifndef DEBUG
288 #define ASSERT(expr)    ((void)0)
289
290 #ifndef STATIC
291 # define STATIC static noinline
292 #endif
293
294 #else /* DEBUG */
295
296 #define ASSERT(expr)    \
297         (unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
298
299 #ifndef STATIC
300 # define STATIC noinline
301 #endif
302
303 #endif /* DEBUG */
304
305 #endif /* __XFS_LINUX__ */