2 * Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 #include <linux/kernel.h>
37 #include <linux/slab.h>
38 #include <linux/module.h>
39 #include <linux/file.h>
40 #include <linux/swap.h>
41 #include <linux/errno.h>
42 #include <linux/sched.h>
43 #include <linux/bitops.h>
44 #include <linux/major.h>
45 #include <linux/pagemap.h>
46 #include <linux/vfs.h>
49 #include <asm/div64.h>
50 #include <asm/param.h>
51 #include <asm/uaccess.h>
52 #include <asm/byteorder.h>
54 #include <linux/xfs_behavior.h>
55 #include <linux/xfs_vfs.h>
56 #include <linux/xfs_cred.h>
57 #include <linux/xfs_vnode.h>
58 #include <linux/xfs_stats.h>
59 #include <linux/xfs_sysctl.h>
60 #include <linux/xfs_iops.h>
61 #include <linux/xfs_super.h>
62 #include <linux/xfs_globals.h>
63 #include <linux/xfs_fs_subr.h>
64 #include <linux/xfs_lrw.h>
66 #include <pagebuf/page_buf.h>
72 #define restricted_chown xfs_params.restrict_chown
73 #define irix_sgid_inherit xfs_params.sgid_inherit
74 #define irix_symlink_mode xfs_params.symlink_mode
75 #define xfs_panic_mask xfs_params.panic_mask
77 typedef struct xfs_dirent
{ /* data from readdir() */
78 xfs_ino_t d_ino
; /* inode number of entry */
79 xfs_off_t d_off
; /* offset of disk directory entry */
80 unsigned short d_reclen
; /* length of this record */
81 char d_name
[1]; /* name of file */
84 #define DIRENTBASESIZE (((xfs_dirent_t *)0)->d_name - (char *)0)
85 #define DIRENTSIZE(namelen) \
86 ((DIRENTBASESIZE + (namelen) + \
87 sizeof(xfs_off_t)) & ~(sizeof(xfs_off_t) - 1))
89 #define NBPP PAGE_SIZE
90 #define DPPSHFT (PAGE_SHIFT - 9)
91 #define NDPP (1 << (PAGE_SHIFT - 9))
92 #define dtop(DD) (((DD) + NDPP - 1) >> DPPSHFT)
93 #define dtopt(DD) ((DD) >> DPPSHFT)
94 #define dpoff(DD) ((DD) & (NDPP-1))
96 #define NBBY 8 /* number of bits per byte */
97 #define NBPC PAGE_SIZE /* Number of bytes per click */
98 #define BPCSHIFT PAGE_SHIFT /* LOG2(NBPC) if exact */
101 * Size of block device i/o is parameterized here.
102 * Currently the system supports page-sized i/o.
104 #define BLKDEV_IOSHIFT BPCSHIFT
105 #define BLKDEV_IOSIZE (1<<BLKDEV_IOSHIFT)
106 /* number of BB's per block device block */
107 #define BLKDEV_BB BTOBB(BLKDEV_IOSIZE)
109 /* bytes to clicks */
110 #define btoc(x) (((__psunsigned_t)(x)+(NBPC-1))>>BPCSHIFT)
111 #define btoct(x) ((__psunsigned_t)(x)>>BPCSHIFT)
112 #define btoc64(x) (((__uint64_t)(x)+(NBPC-1))>>BPCSHIFT)
113 #define btoct64(x) ((__uint64_t)(x)>>BPCSHIFT)
114 #define io_btoc(x) (((__psunsigned_t)(x)+(IO_NBPC-1))>>IO_BPCSHIFT)
115 #define io_btoct(x) ((__psunsigned_t)(x)>>IO_BPCSHIFT)
117 /* off_t bytes to clicks */
118 #define offtoc(x) (((__uint64_t)(x)+(NBPC-1))>>BPCSHIFT)
119 #define offtoct(x) ((xfs_off_t)(x)>>BPCSHIFT)
121 /* clicks to off_t bytes */
122 #define ctooff(x) ((xfs_off_t)(x)<<BPCSHIFT)
124 /* clicks to bytes */
125 #define ctob(x) ((__psunsigned_t)(x)<<BPCSHIFT)
126 #define btoct(x) ((__psunsigned_t)(x)>>BPCSHIFT)
127 #define ctob64(x) ((__uint64_t)(x)<<BPCSHIFT)
128 #define io_ctob(x) ((__psunsigned_t)(x)<<IO_BPCSHIFT)
130 /* bytes to clicks */
131 #define btoc(x) (((__psunsigned_t)(x)+(NBPC-1))>>BPCSHIFT)
134 #define FSC_NOTIFY_NAME_CHANGED(vp)
138 #define ENOATTR ENODATA /* Attribute not found */
141 /* Note: EWRONGFS never visible outside the kernel */
142 #define EWRONGFS EINVAL /* Mount with wrong filesystem type */
145 * XXX EFSCORRUPTED needs a real value in errno.h. asm-i386/errno.h won't
146 * return codes out of its known range in errno.
147 * XXX Also note: needs to be < 1000 and fairly unique on Linux (mustn't
148 * conflict with any code we use already or any code a driver may use)
149 * XXX Some options (currently we do #2):
150 * 1/ New error code ["Filesystem is corrupted", _after_ glibc updated]
151 * 2/ 990 ["Unknown error 990"]
152 * 3/ EUCLEAN ["Structure needs cleaning"]
153 * 4/ Convert EFSCORRUPTED to EIO [just prior to return into userspace]
155 #define EFSCORRUPTED 990 /* Filesystem is corrupted */
157 #define SYNCHRONIZE() barrier()
158 #define __return_address __builtin_return_address(0)
160 /* IRIX uses a dynamic sizing algorithm (ndquot = 200 + numprocs*2) */
161 /* we may well need to fine-tune this if it ever becomes an issue. */
162 #define DQUOT_MAX_HEURISTIC 1024 /* NR_DQUOTS */
163 #define ndquot DQUOT_MAX_HEURISTIC
165 /* IRIX uses the current size of the name cache to guess a good value */
166 /* - this isn't the same but is a good enough starting point for now. */
167 #define DQUOT_HASH_HEURISTIC files_stat.nr_files
169 /* IRIX inodes maintain the project ID also, zero this field on Linux */
170 #define DEFAULT_PROJID 0
171 #define dfltprid DEFAULT_PROJID
173 #define MAXPATHLEN 1024
175 #define FINVIS 0x0100 /* don't update timestamps - XFS */
177 #define MIN(a,b) (min(a,b))
178 #define MAX(a,b) (max(a,b))
179 #define howmany(x, y) (((x)+((y)-1))/(y))
180 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
182 /* Move the kernel do_div definition off to one side */
185 /* For ia32 we need to pull some tricks to get past various versions
186 * of the compiler which do not like us using do_div in the middle
187 * of large functions.
189 static inline __u32
xfs_do_div(void *a
, __u32 b
, int n
)
195 mod
= *(__u32
*)a
% b
;
196 *(__u32
*)a
= *(__u32
*)a
/ b
;
200 unsigned long __upper
, __low
, __high
, __mod
;
201 __u64 c
= *(__u64
*)a
;
202 __upper
= __high
= c
>> 32;
205 __upper
= __high
% (b
);
206 __high
= __high
/ (b
);
208 asm("divl %2":"=a" (__low
), "=d" (__mod
):"rm" (b
), "0" (__low
), "1" (__upper
));
209 asm("":"=A" (c
):"a" (__low
),"d" (__high
));
219 /* Side effect free 64 bit mod operation */
220 static inline __u32
xfs_do_mod(void *a
, __u32 b
, int n
)
224 return *(__u32
*)a
% b
;
227 unsigned long __upper
, __low
, __high
, __mod
;
228 __u64 c
= *(__u64
*)a
;
229 __upper
= __high
= c
>> 32;
232 __upper
= __high
% (b
);
233 __high
= __high
/ (b
);
235 asm("divl %2":"=a" (__low
), "=d" (__mod
):"rm" (b
), "0" (__low
), "1" (__upper
));
236 asm("":"=A" (c
):"a" (__low
),"d" (__high
));
245 static inline __u32
xfs_do_div(void *a
, __u32 b
, int n
)
251 mod
= *(__u32
*)a
% b
;
252 *(__u32
*)a
= *(__u32
*)a
/ b
;
255 mod
= do_div(*(__u64
*)a
, b
);
263 /* Side effect free 64 bit mod operation */
264 static inline __u32
xfs_do_mod(void *a
, __u32 b
, int n
)
268 return *(__u32
*)a
% b
;
271 __u64 c
= *(__u64
*)a
;
282 #define do_div(a, b) xfs_do_div(&(a), (b), sizeof(a))
283 #define do_mod(a, b) xfs_do_mod(&(a), (b), sizeof(a))
285 static inline __uint64_t
roundup_64(__uint64_t x
, __uint32_t y
)
292 #endif /* __XFS_LINUX__ */