Whamcloud - gitweb
22dad3cc61e2a9459080283b2407624ae74f78cc
[fs/lustre-release.git] / lustre / kernel_patches / patches / linux-2.4.21-xattr-0.8.54-suse.patch
1  Documentation/Configure.help  |   66 ++
2  arch/alpha/defconfig          |    7 
3  arch/alpha/kernel/entry.S     |   12 
4  arch/arm/defconfig            |    7 
5  arch/arm/kernel/calls.S       |   24 
6  arch/i386/defconfig           |    7 
7  arch/ia64/defconfig           |    7 
8  arch/ia64/kernel/entry.S      |   24 
9  arch/m68k/defconfig           |    7 
10  arch/mips/defconfig           |    7 
11  arch/mips64/defconfig         |    7 
12  arch/ppc/defconfig            |   14 
13  arch/ppc64/kernel/misc.S      |    2 
14  arch/s390/defconfig           |    7 
15  arch/s390/kernel/entry.S      |   24 
16  arch/s390x/defconfig          |    7 
17  arch/s390x/kernel/entry.S     |   24 
18  arch/s390x/kernel/wrapper32.S |   92 +++
19  arch/sparc/defconfig          |    7 
20  arch/sparc/kernel/systbls.S   |   10 
21  arch/sparc64/defconfig        |    7 
22  arch/sparc64/kernel/systbls.S |   20 
23  fs/Config.in                  |   14 
24  fs/Makefile                   |    3 
25  fs/ext2/Makefile              |    4 
26  fs/ext2/file.c                |    5 
27  fs/ext2/ialloc.c              |    2 
28  fs/ext2/inode.c               |   34 -
29  fs/ext2/namei.c               |   14 
30  fs/ext2/super.c               |   29 
31  fs/ext2/symlink.c             |   14 
32  fs/ext2/xattr.c               | 1212 +++++++++++++++++++++++++++++++++++++++++
33  fs/ext2/xattr_user.c          |  103 +++
34  fs/ext3/Makefile              |   10 
35  fs/ext3/file.c                |    5 
36  fs/ext3/ialloc.c              |    2 
37  fs/ext3/inode.c               |   35 -
38  fs/ext3/namei.c               |   21 
39  fs/ext3/super.c               |   36 +
40  fs/ext3/symlink.c             |   14 
41  fs/ext3/xattr.c               | 1225 ++++++++++++++++++++++++++++++++++++++++++
42  fs/ext3/xattr_user.c          |  111 +++
43  fs/jfs/jfs_xattr.h            |    6 
44  fs/jfs/xattr.c                |    6 
45  fs/mbcache.c                  |  648 ++++++++++++++++++++++
46  include/asm-arm/unistd.h      |    2 
47  include/asm-ia64/unistd.h     |   13 
48  include/asm-ppc64/unistd.h    |    2 
49  include/asm-s390/unistd.h     |   15 
50  include/asm-s390x/unistd.h    |   15 
51  include/asm-sparc/unistd.h    |   24 
52  include/asm-sparc64/unistd.h  |   24 
53  include/linux/cache_def.h     |   15 
54  include/linux/errno.h         |    4 
55  include/linux/ext2_fs.h       |   31 -
56  include/linux/ext2_xattr.h    |  157 +++++
57  include/linux/ext3_fs.h       |   31 -
58  include/linux/ext3_jbd.h      |    8 
59  include/linux/ext3_xattr.h    |  157 +++++
60  include/linux/fs.h            |    2 
61  include/linux/mbcache.h       |   69 ++
62  kernel/ksyms.c                |    4 
63  mm/vmscan.c                   |   35 +
64  fs/ext3/ext3-exports.c        |   14 +  
65  64 files changed, 4355 insertions(+), 195 deletions(-)
66
67 --- linux-2.4.20/Documentation/Configure.help~linux-2.4.20-xattr-0.8.54 2003-05-05 17:43:06.000000000 +0800
68 +++ linux-2.4.20-root/Documentation/Configure.help      2003-05-07 18:08:03.000000000 +0800
69 @@ -15242,6 +15242,39 @@ CONFIG_EXT2_FS
70    be compiled as a module, and so this could be dangerous.  Most
71    everyone wants to say Y here.
72  
73 +Ext2 extended attributes
74 +CONFIG_EXT2_FS_XATTR
75 +  Extended attributes are name:value pairs associated with inodes by
76 +  the kernel or by users (see the attr(5) manual page, or visit
77 +  <http://acl.bestbits.at/> for details).
78 +
79 +  If unsure, say N.
80 +
81 +Ext2 extended attribute block sharing
82 +CONFIG_EXT2_FS_XATTR_SHARING
83 +  This options enables code for sharing identical extended attribute
84 +  blocks among multiple inodes.
85 +
86 +  Usually, say Y.
87 +
88 +Ext2 extended user attributes
89 +CONFIG_EXT2_FS_XATTR_USER
90 +  This option enables extended user attributes on ext2. Processes can
91 +  associate extended user attributes with inodes to store additional
92 +  information such as the character encoding of files, etc. (see the
93 +  attr(5) manual page, or visit <http://acl.bestbits.at/> for details).
94 +
95 +  If unsure, say N.
96 +
97 +Ext2 trusted extended attributes
98 +CONFIG_EXT2_FS_XATTR_TRUSTED
99 +  This option enables extended attributes on ext2 that are accessible
100 +  (and visible) only to users capable of CAP_SYS_ADMIN. Usually this
101 +  is only the super user. Trusted extended attributes are meant for
102 +  implementing system/security services.
103 +
104 +  If unsure, say N.
105 +
106  Ext3 journalling file system support (EXPERIMENTAL)
107  CONFIG_EXT3_FS
108    This is the journalling version of the Second extended file system
109 @@ -15274,6 +15307,39 @@ CONFIG_EXT3_FS
110    of your root partition (the one containing the directory /) cannot
111    be compiled as a module, and so this may be dangerous.
112  
113 +Ext3 extended attributes
114 +CONFIG_EXT3_FS_XATTR
115 +  Extended attributes are name:value pairs associated with inodes by
116 +  the kernel or by users (see the attr(5) manual page, or visit
117 +  <http://acl.bestbits.at/> for details).
118 +
119 +  If unsure, say N.
120 +
121 +Ext3 extended attribute block sharing
122 +CONFIG_EXT3_FS_XATTR_SHARING
123 +  This options enables code for sharing identical extended attribute
124 +  blocks among multiple inodes.
125 +
126 +  Usually, say Y.
127 +
128 +Ext3 extended user attributes
129 +CONFIG_EXT3_FS_XATTR_USER
130 +  This option enables extended user attributes on ext3. Processes can
131 +  associate extended user attributes with inodes to store additional
132 +  information such as the character encoding of files, etc. (see the
133 +  attr(5) manual page, or visit <http://acl.bestbits.at/> for details).
134 +
135 +  If unsure, say N.
136 +
137 +Ext3 trusted extended attributes
138 +CONFIG_EXT3_FS_XATTR_TRUSTED
139 +  This option enables extended attributes on ext3 that are accessible
140 +  (and visible) only to users capable of CAP_SYS_ADMIN. Usually this
141 +  is only the super user. Trusted extended attributes are meant for
142 +  implementing system/security services.
143 +
144 +  If unsure, say N.
145 +
146  Journal Block Device support (JBD for ext3) (EXPERIMENTAL)
147  CONFIG_JBD
148    This is a generic journalling layer for block devices.  It is
149 --- linux-2.4.20/arch/alpha/defconfig~linux-2.4.20-xattr-0.8.54 2001-11-20 07:19:42.000000000 +0800
150 +++ linux-2.4.20-root/arch/alpha/defconfig      2003-05-07 18:08:03.000000000 +0800
151 @@ -1,6 +1,13 @@
152  #
153  # Automatically generated make config: don't edit
154  #
155 +CONFIG_EXT3_FS_XATTR=y
156 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
157 +# CONFIG_EXT3_FS_XATTR_USER is not set
158 +# CONFIG_EXT2_FS_XATTR is not set
159 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
160 +# CONFIG_EXT2_FS_XATTR_USER is not set
161 +# CONFIG_FS_MBCACHE is not set
162  CONFIG_ALPHA=y
163  # CONFIG_UID16 is not set
164  # CONFIG_RWSEM_GENERIC_SPINLOCK is not set
165 --- linux-2.4.20/arch/alpha/kernel/entry.S~linux-2.4.20-xattr-0.8.54    2002-08-03 08:39:42.000000000 +0800
166 +++ linux-2.4.20-root/arch/alpha/kernel/entry.S 2003-05-07 18:08:03.000000000 +0800
167 @@ -1154,6 +1154,18 @@ sys_call_table:
168         .quad sys_readahead
169         .quad sys_ni_syscall                    /* 380, sys_security */
170         .quad sys_tkill
171 +       .quad sys_setxattr
172 +       .quad sys_lsetxattr
173 +       .quad sys_fsetxattr
174 +       .quad sys_getxattr                      /* 385 */
175 +       .quad sys_lgetxattr
176 +       .quad sys_fgetxattr
177 +       .quad sys_listxattr
178 +       .quad sys_llistxattr
179 +       .quad sys_flistxattr                    /* 390 */
180 +       .quad sys_removexattr
181 +       .quad sys_lremovexattr
182 +       .quad sys_fremovexattr
183  
184  /* Remember to update everything, kids.  */
185  .ifne (. - sys_call_table) - (NR_SYSCALLS * 8)
186 --- linux-2.4.20/arch/arm/defconfig~linux-2.4.20-xattr-0.8.54   2001-05-20 08:43:05.000000000 +0800
187 +++ linux-2.4.20-root/arch/arm/defconfig        2003-05-07 18:08:03.000000000 +0800
188 @@ -1,6 +1,13 @@
189  #
190  # Automatically generated make config: don't edit
191  #
192 +CONFIG_EXT3_FS_XATTR=y
193 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
194 +# CONFIG_EXT3_FS_XATTR_USER is not set
195 +# CONFIG_EXT2_FS_XATTR is not set
196 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
197 +# CONFIG_EXT2_FS_XATTR_USER is not set
198 +# CONFIG_FS_MBCACHE is not set
199  CONFIG_ARM=y
200  # CONFIG_EISA is not set
201  # CONFIG_SBUS is not set
202 --- linux-2.4.20/arch/arm/kernel/calls.S~linux-2.4.20-xattr-0.8.54      2002-08-03 08:39:42.000000000 +0800
203 +++ linux-2.4.20-root/arch/arm/kernel/calls.S   2003-05-07 18:08:03.000000000 +0800
204 @@ -240,18 +240,18 @@ __syscall_start:
205                 .long   SYMBOL_NAME(sys_ni_syscall) /* Security */
206                 .long   SYMBOL_NAME(sys_gettid)
207  /* 225 */      .long   SYMBOL_NAME(sys_readahead)
208 -               .long   SYMBOL_NAME(sys_ni_syscall) /* sys_setxattr */
209 -               .long   SYMBOL_NAME(sys_ni_syscall) /* sys_lsetxattr */
210 -               .long   SYMBOL_NAME(sys_ni_syscall) /* sys_fsetxattr */
211 -               .long   SYMBOL_NAME(sys_ni_syscall) /* sys_getxattr */
212 -/* 230 */      .long   SYMBOL_NAME(sys_ni_syscall) /* sys_lgetxattr */
213 -               .long   SYMBOL_NAME(sys_ni_syscall) /* sys_fgetxattr */
214 -               .long   SYMBOL_NAME(sys_ni_syscall) /* sys_listxattr */
215 -               .long   SYMBOL_NAME(sys_ni_syscall) /* sys_llistxattr */
216 -               .long   SYMBOL_NAME(sys_ni_syscall) /* sys_flistxattr */
217 -/* 235 */      .long   SYMBOL_NAME(sys_ni_syscall) /* sys_removexattr */
218 -               .long   SYMBOL_NAME(sys_ni_syscall) /* sys_lremovexattr */
219 -               .long   SYMBOL_NAME(sys_ni_syscall) /* sys_fremovexattr */
220 +               .long   SYMBOL_NAME(sys_setxattr)
221 +               .long   SYMBOL_NAME(sys_lsetxattr)
222 +               .long   SYMBOL_NAME(sys_fsetxattr)
223 +               .long   SYMBOL_NAME(sys_getxattr)
224 +/* 230 */      .long   SYMBOL_NAME(sys_lgetxattr)
225 +               .long   SYMBOL_NAME(sys_fgetxattr)
226 +               .long   SYMBOL_NAME(sys_listxattr)
227 +               .long   SYMBOL_NAME(sys_llistxattr)
228 +               .long   SYMBOL_NAME(sys_flistxattr)
229 +/* 235 */      .long   SYMBOL_NAME(sys_removexattr)
230 +               .long   SYMBOL_NAME(sys_lremovexattr)
231 +               .long   SYMBOL_NAME(sys_fremovexattr)
232                 .long   SYMBOL_NAME(sys_tkill)
233                 /*
234                  * Please check 2.5 _before_ adding calls here,
235 --- linux-2.4.20/arch/i386/defconfig~linux-2.4.20-xattr-0.8.54  2002-11-29 07:53:09.000000000 +0800
236 +++ linux-2.4.20-root/arch/i386/defconfig       2003-05-07 18:08:03.000000000 +0800
237 @@ -1,6 +1,13 @@
238  #
239  # Automatically generated make config: don't edit
240  #
241 +CONFIG_EXT3_FS_XATTR=y
242 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
243 +# CONFIG_EXT3_FS_XATTR_USER is not set
244 +# CONFIG_EXT2_FS_XATTR is not set
245 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
246 +# CONFIG_EXT2_FS_XATTR_USER is not set
247 +# CONFIG_FS_MBCACHE is not set
248  CONFIG_X86=y
249  CONFIG_ISA=y
250  # CONFIG_SBUS is not set
251 --- linux-2.4.20/arch/ia64/defconfig~linux-2.4.20-xattr-0.8.54  2002-11-29 07:53:09.000000000 +0800
252 +++ linux-2.4.20-root/arch/ia64/defconfig       2003-05-07 18:08:03.000000000 +0800
253 @@ -1,6 +1,13 @@
254  #
255  # Automatically generated make config: don't edit
256  #
257 +CONFIG_EXT3_FS_XATTR=y
258 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
259 +# CONFIG_EXT3_FS_XATTR_USER is not set
260 +# CONFIG_EXT2_FS_XATTR is not set
261 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
262 +# CONFIG_EXT2_FS_XATTR_USER is not set
263 +# CONFIG_FS_MBCACHE is not set
264  
265  #
266  # Code maturity level options
267 --- linux-2.4.20/arch/m68k/defconfig~linux-2.4.20-xattr-0.8.54  2000-06-20 03:56:08.000000000 +0800
268 +++ linux-2.4.20-root/arch/m68k/defconfig       2003-05-07 18:08:03.000000000 +0800
269 @@ -1,6 +1,13 @@
270  #
271  # Automatically generated make config: don't edit
272  #
273 +CONFIG_EXT3_FS_XATTR=y
274 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
275 +# CONFIG_EXT3_FS_XATTR_USER is not set
276 +# CONFIG_EXT2_FS_XATTR is not set
277 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
278 +# CONFIG_EXT2_FS_XATTR_USER is not set
279 +# CONFIG_FS_MBCACHE is not set
280  CONFIG_UID16=y
281  
282  #
283 --- linux-2.4.20/arch/mips/defconfig~linux-2.4.20-xattr-0.8.54  2002-11-29 07:53:10.000000000 +0800
284 +++ linux-2.4.20-root/arch/mips/defconfig       2003-05-07 18:08:03.000000000 +0800
285 @@ -1,6 +1,13 @@
286  #
287  # Automatically generated make config: don't edit
288  #
289 +CONFIG_EXT3_FS_XATTR=y
290 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
291 +# CONFIG_EXT3_FS_XATTR_USER is not set
292 +# CONFIG_EXT2_FS_XATTR is not set
293 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
294 +# CONFIG_EXT2_FS_XATTR_USER is not set
295 +# CONFIG_FS_MBCACHE is not set
296  CONFIG_MIPS=y
297  CONFIG_MIPS32=y
298  # CONFIG_MIPS64 is not set
299 --- linux-2.4.20/arch/mips64/defconfig~linux-2.4.20-xattr-0.8.54        2002-11-29 07:53:10.000000000 +0800
300 +++ linux-2.4.20-root/arch/mips64/defconfig     2003-05-07 18:08:03.000000000 +0800
301 @@ -1,6 +1,13 @@
302  #
303  # Automatically generated make config: don't edit
304  #
305 +CONFIG_EXT3_FS_XATTR=y
306 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
307 +# CONFIG_EXT3_FS_XATTR_USER is not set
308 +# CONFIG_EXT2_FS_XATTR is not set
309 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
310 +# CONFIG_EXT2_FS_XATTR_USER is not set
311 +# CONFIG_FS_MBCACHE is not set
312  CONFIG_MIPS=y
313  # CONFIG_MIPS32 is not set
314  CONFIG_MIPS64=y
315 --- linux-2.4.20/arch/s390/defconfig~linux-2.4.20-xattr-0.8.54  2002-11-29 07:53:11.000000000 +0800
316 +++ linux-2.4.20-root/arch/s390/defconfig       2003-05-07 18:08:03.000000000 +0800
317 @@ -1,6 +1,13 @@
318  #
319  # Automatically generated make config: don't edit
320  #
321 +CONFIG_EXT3_FS_XATTR=y
322 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
323 +# CONFIG_EXT3_FS_XATTR_USER is not set
324 +# CONFIG_EXT2_FS_XATTR is not set
325 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
326 +# CONFIG_EXT2_FS_XATTR_USER is not set
327 +# CONFIG_FS_MBCACHE is not set
328  # CONFIG_ISA is not set
329  # CONFIG_EISA is not set
330  # CONFIG_MCA is not set
331 --- linux-2.4.20/arch/s390/kernel/entry.S~linux-2.4.20-xattr-0.8.54     2002-11-29 07:53:11.000000000 +0800
332 +++ linux-2.4.20-root/arch/s390/kernel/entry.S  2003-05-07 18:08:03.000000000 +0800
333 @@ -558,18 +558,18 @@ sys_call_table:
334          .long  sys_fcntl64 
335         .long  sys_ni_syscall
336         .long  sys_ni_syscall
337 -       .long  sys_ni_syscall            /* 224 - reserved for setxattr  */
338 -       .long  sys_ni_syscall            /* 225 - reserved for lsetxattr */
339 -       .long  sys_ni_syscall            /* 226 - reserved for fsetxattr */
340 -       .long  sys_ni_syscall            /* 227 - reserved for getxattr  */
341 -       .long  sys_ni_syscall            /* 228 - reserved for lgetxattr */
342 -       .long  sys_ni_syscall            /* 229 - reserved for fgetxattr */
343 -       .long  sys_ni_syscall            /* 230 - reserved for listxattr */
344 -       .long  sys_ni_syscall            /* 231 - reserved for llistxattr */
345 -       .long  sys_ni_syscall            /* 232 - reserved for flistxattr */
346 -       .long  sys_ni_syscall            /* 233 - reserved for removexattr */
347 -       .long  sys_ni_syscall            /* 234 - reserved for lremovexattr */
348 -       .long  sys_ni_syscall            /* 235 - reserved for fremovexattr */
349 +       .long  sys_setxattr
350 +       .long  sys_lsetxattr            /* 225 */
351 +       .long  sys_fsetxattr
352 +       .long  sys_getxattr
353 +       .long  sys_lgetxattr
354 +       .long  sys_fgetxattr
355 +       .long  sys_listxattr            /* 230 */
356 +       .long  sys_llistxattr
357 +       .long  sys_flistxattr
358 +       .long  sys_removexattr
359 +       .long  sys_lremovexattr
360 +       .long  sys_fremovexattr         /* 235 */
361         .long  sys_gettid
362         .long  sys_tkill
363         .rept  255-237
364 --- linux-2.4.20/arch/s390x/defconfig~linux-2.4.20-xattr-0.8.54 2002-11-29 07:53:11.000000000 +0800
365 +++ linux-2.4.20-root/arch/s390x/defconfig      2003-05-07 18:08:03.000000000 +0800
366 @@ -1,6 +1,13 @@
367  #
368  # Automatically generated make config: don't edit
369  #
370 +CONFIG_EXT3_FS_XATTR=y
371 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
372 +# CONFIG_EXT3_FS_XATTR_USER is not set
373 +# CONFIG_EXT2_FS_XATTR is not set
374 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
375 +# CONFIG_EXT2_FS_XATTR_USER is not set
376 +# CONFIG_FS_MBCACHE is not set
377  # CONFIG_ISA is not set
378  # CONFIG_EISA is not set
379  # CONFIG_MCA is not set
380 --- linux-2.4.20/arch/s390x/kernel/entry.S~linux-2.4.20-xattr-0.8.54    2002-11-29 07:53:11.000000000 +0800
381 +++ linux-2.4.20-root/arch/s390x/kernel/entry.S 2003-05-07 18:08:03.000000000 +0800
382 @@ -591,18 +591,18 @@ sys_call_table:
383         .long  SYSCALL(sys_ni_syscall,sys32_fcntl64_wrapper)
384         .long  SYSCALL(sys_ni_syscall,sys_ni_syscall)
385         .long  SYSCALL(sys_ni_syscall,sys_ni_syscall)
386 -       .long  SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 224 - reserved for setxattr  */
387 -       .long  SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 225 - reserved for lsetxattr */
388 -       .long  SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 226 - reserved for fsetxattr */
389 -       .long  SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 227 - reserved for getxattr  */
390 -       .long  SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 228 - reserved for lgetxattr */
391 -       .long  SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 229 - reserved for fgetxattr */
392 -       .long  SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 230 - reserved for listxattr */
393 -       .long  SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 231 - reserved for llistxattr */
394 -       .long  SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 232 - reserved for flistxattr */
395 -       .long  SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 233 - reserved for removexattr */
396 -       .long  SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 234 - reserved for lremovexattr */
397 -       .long  SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 235 - reserved for fremovexattr */
398 +       .long  SYSCALL(sys_setxattr,sys32_setxattr_wrapper)
399 +       .long  SYSCALL(sys_lsetxattr,sys32_lsetxattr_wrapper)   /* 225 */
400 +       .long  SYSCALL(sys_fsetxattr,sys32_fsetxattr_wrapper)
401 +       .long  SYSCALL(sys_getxattr,sys32_getxattr_wrapper)
402 +       .long  SYSCALL(sys_lgetxattr,sys32_lgetxattr_wrapper)
403 +       .long  SYSCALL(sys_fgetxattr,sys32_fgetxattr_wrapper)
404 +       .long  SYSCALL(sys_listxattr,sys32_listxattr_wrapper)   /* 230 */
405 +       .long  SYSCALL(sys_llistxattr,sys32_llistxattr_wrapper)
406 +       .long  SYSCALL(sys_flistxattr,sys32_flistxattr_wrapper)
407 +       .long  SYSCALL(sys_removexattr,sys32_removexattr_wrapper)
408 +       .long  SYSCALL(sys_lremovexattr,sys32_lremovexattr_wrapper)
409 +       .long  SYSCALL(sys_fremovexattr,sys32_fremovexattr_wrapper)/* 235 */
410         .long  SYSCALL(sys_gettid,sys_gettid)
411         .long  SYSCALL(sys_tkill,sys_tkill)
412         .rept  255-237
413 --- linux-2.4.20/arch/s390x/kernel/wrapper32.S~linux-2.4.20-xattr-0.8.54        2002-02-26 03:37:56.000000000 +0800
414 +++ linux-2.4.20-root/arch/s390x/kernel/wrapper32.S     2003-05-07 18:08:03.000000000 +0800
415 @@ -1091,3 +1091,95 @@ sys32_fstat64_wrapper:
416         llgtr   %r3,%r3                 # struct stat64 *
417         llgfr   %r4,%r4                 # long
418         jg      sys32_fstat64           # branch to system call
419 +
420 +       .globl  sys32_setxattr_wrapper
421 +sys32_setxattr_wrapper:
422 +       llgtr   %r2,%r2                 # char *
423 +       llgtr   %r3,%r3                 # char *
424 +       llgtr   %r4,%r4                 # void *
425 +       llgfr   %r5,%r5                 # size_t
426 +       lgfr    %r6,%r6                 # int
427 +       jg      sys_setxattr
428 +
429 +       .globl  sys32_lsetxattr_wrapper
430 +sys32_lsetxattr_wrapper:
431 +       llgtr   %r2,%r2                 # char *
432 +       llgtr   %r3,%r3                 # char *
433 +       llgtr   %r4,%r4                 # void *
434 +       llgfr   %r5,%r5                 # size_t
435 +       lgfr    %r6,%r6                 # int
436 +       jg      sys_lsetxattr
437 +
438 +       .globl  sys32_fsetxattr_wrapper
439 +sys32_fsetxattr_wrapper:
440 +       lgfr    %r2,%r2                 # int
441 +       llgtr   %r3,%r3                 # char *
442 +       llgtr   %r4,%r4                 # void *
443 +       llgfr   %r5,%r5                 # size_t
444 +       lgfr    %r6,%r6                 # int
445 +       jg      sys_fsetxattr
446 +
447 +       .globl  sys32_getxattr_wrapper
448 +sys32_getxattr_wrapper:
449 +       llgtr   %r2,%r2                 # char *
450 +       llgtr   %r3,%r3                 # char *
451 +       llgtr   %r4,%r4                 # void *
452 +       llgfr   %r5,%r5                 # size_t
453 +       jg      sys_getxattr
454 +
455 +       .globl  sys32_lgetxattr_wrapper
456 +sys32_lgetxattr_wrapper:
457 +       llgtr   %r2,%r2                 # char *
458 +       llgtr   %r3,%r3                 # char *
459 +       llgtr   %r4,%r4                 # void *
460 +       llgfr   %r5,%r5                 # size_t
461 +       jg      sys_lgetxattr
462 +
463 +       .globl  sys32_fgetxattr_wrapper
464 +sys32_fgetxattr_wrapper:
465 +       lgfr    %r2,%r2                 # int
466 +       llgtr   %r3,%r3                 # char *
467 +       llgtr   %r4,%r4                 # void *
468 +       llgfr   %r5,%r5                 # size_t
469 +       jg      sys_fgetxattr
470 +
471 +       .globl  sys32_listxattr_wrapper
472 +sys32_listxattr_wrapper:
473 +       llgtr   %r2,%r2                 # char *
474 +       llgtr   %r3,%r3                 # char *
475 +       llgfr   %r4,%r4                 # size_t
476 +       jg      sys_listxattr
477 +
478 +       .globl  sys32_llistxattr_wrapper
479 +sys32_llistxattr_wrapper:
480 +       llgtr   %r2,%r2                 # char *
481 +       llgtr   %r3,%r3                 # char *
482 +       llgfr   %r4,%r4                 # size_t
483 +       jg      sys_llistxattr
484 +
485 +       .globl  sys32_flistxattr_wrapper
486 +sys32_flistxattr_wrapper:
487 +       lgfr    %r2,%r2                 # int
488 +       llgtr   %r3,%r3                 # char *
489 +       llgfr   %r4,%r4                 # size_t
490 +       jg      sys_flistxattr
491 +
492 +       .globl  sys32_removexattr_wrapper
493 +sys32_removexattr_wrapper:
494 +       llgtr   %r2,%r2                 # char *
495 +       llgtr   %r3,%r3                 # char *
496 +       jg      sys_removexattr
497 +
498 +       .globl  sys32_lremovexattr_wrapper
499 +sys32_lremovexattr_wrapper:
500 +       llgtr   %r2,%r2                 # char *
501 +       llgtr   %r3,%r3                 # char *
502 +       jg      sys_lremovexattr
503 +
504 +       .globl  sys32_fremovexattr_wrapper
505 +sys32_fremovexattr_wrapper:
506 +       lgfr    %r2,%r2                 # int
507 +       llgtr   %r3,%r3                 # char *
508 +       jg      sys_fremovexattr
509 +
510 +
511 --- linux-2.4.20/arch/sparc64/defconfig~linux-2.4.20-xattr-0.8.54       2002-11-29 07:53:12.000000000 +0800
512 +++ linux-2.4.20-root/arch/sparc64/defconfig    2003-05-07 18:08:03.000000000 +0800
513 @@ -1,6 +1,13 @@
514  #
515  # Automatically generated make config: don't edit
516  #
517 +CONFIG_EXT3_FS_XATTR=y
518 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
519 +# CONFIG_EXT3_FS_XATTR_USER is not set
520 +# CONFIG_EXT2_FS_XATTR is not set
521 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
522 +# CONFIG_EXT2_FS_XATTR_USER is not set
523 +# CONFIG_FS_MBCACHE is not set
524  
525  #
526  # Code maturity level options
527 --- linux-2.4.20/fs/Config.in~linux-2.4.20-xattr-0.8.54 2002-11-29 07:53:15.000000000 +0800
528 +++ linux-2.4.20-root/fs/Config.in      2003-05-07 18:08:03.000000000 +0800
529 @@ -25,6 +25,11 @@ dep_mbool '  Debug Befs' CONFIG_BEFS_DEB
530  dep_tristate 'BFS file system support (EXPERIMENTAL)' CONFIG_BFS_FS $CONFIG_EXPERIMENTAL
531  
532  tristate 'Ext3 journalling file system support' CONFIG_EXT3_FS
533 +dep_mbool '  Ext3 extended attributes' CONFIG_EXT3_FS_XATTR $CONFIG_EXT3_FS
534 +dep_bool '    Ext3 extended attribute block sharing' \
535 +    CONFIG_EXT3_FS_XATTR_SHARING $CONFIG_EXT3_FS_XATTR
536 +dep_bool '    Ext3 extended user attributes' \
537 +    CONFIG_EXT3_FS_XATTR_USER $CONFIG_EXT3_FS_XATTR
538  # CONFIG_JBD could be its own option (even modular), but until there are
539  # other users than ext3, we will simply make it be the same as CONFIG_EXT3_FS
540  # dep_tristate '  Journal Block Device support (JBD for ext3)' CONFIG_JBD $CONFIG_EXT3_FS
541 @@ -84,6 +89,11 @@ dep_mbool '  QNX4FS write support (DANGE
542  tristate 'ROM file system support' CONFIG_ROMFS_FS
543  
544  tristate 'Second extended fs support' CONFIG_EXT2_FS
545 +dep_mbool '  Ext2 extended attributes' CONFIG_EXT2_FS_XATTR $CONFIG_EXT2_FS
546 +dep_bool '    Ext2 extended attribute block sharing' \
547 +    CONFIG_EXT2_FS_XATTR_SHARING $CONFIG_EXT2_FS_XATTR
548 +dep_bool '    Ext2 extended user attributes' \
549 +    CONFIG_EXT2_FS_XATTR_USER $CONFIG_EXT2_FS_XATTR
550  
551  tristate 'System V/Xenix/V7/Coherent file system support' CONFIG_SYSV_FS
552  
553 @@ -155,6 +165,10 @@ else
554     define_tristate CONFIG_ZISOFS_FS n
555  fi
556  
557 +# Meta block cache for Extended Attributes (ext2/ext3)
558 +#tristate 'Meta block cache' CONFIG_FS_MBCACHE
559 +define_tristate CONFIG_FS_MBCACHE y 
560 +
561  mainmenu_option next_comment
562  comment 'Partition Types'
563  source fs/partitions/Config.in
564 --- linux-2.4.20/fs/Makefile~linux-2.4.20-xattr-0.8.54  2003-05-05 19:00:58.000000000 +0800
565 +++ linux-2.4.20-root/fs/Makefile       2003-05-07 18:08:03.000000000 +0800
566 @@ -79,6 +79,9 @@ obj-y                         += binfmt_script.o
567  
568  obj-$(CONFIG_BINFMT_ELF)       += binfmt_elf.o
569  
570 +export-objs += mbcache.o
571 +obj-$(CONFIG_FS_MBCACHE)       += mbcache.o
572 +
573  # persistent filesystems
574  obj-y += $(join $(subdir-y),$(subdir-y:%=/%.o))
575  
576 --- linux-2.4.20/fs/ext2/Makefile~linux-2.4.20-xattr-0.8.54     2001-10-11 23:05:18.000000000 +0800
577 +++ linux-2.4.20-root/fs/ext2/Makefile  2003-05-07 18:08:03.000000000 +0800
578 @@ -13,4 +13,8 @@ obj-y    := balloc.o bitmap.o dir.o file
579                 ioctl.o namei.o super.o symlink.o
580  obj-m    := $(O_TARGET)
581  
582 +export-objs += xattr.o
583 +obj-$(CONFIG_EXT2_FS_XATTR) += xattr.o
584 +obj-$(CONFIG_EXT2_FS_XATTR_USER) += xattr_user.o
585 +
586  include $(TOPDIR)/Rules.make
587 --- linux-2.4.20/fs/ext2/file.c~linux-2.4.20-xattr-0.8.54       2001-10-11 23:05:18.000000000 +0800
588 +++ linux-2.4.20-root/fs/ext2/file.c    2003-05-07 18:08:03.000000000 +0800
589 @@ -20,6 +20,7 @@
590  
591  #include <linux/fs.h>
592  #include <linux/ext2_fs.h>
593 +#include <linux/ext2_xattr.h>
594  #include <linux/sched.h>
595  
596  /*
597 @@ -51,4 +52,8 @@ struct file_operations ext2_file_operati
598  
599  struct inode_operations ext2_file_inode_operations = {
600         truncate:       ext2_truncate,
601 +       setxattr:       ext2_setxattr,
602 +       getxattr:       ext2_getxattr,
603 +       listxattr:      ext2_listxattr,
604 +       removexattr:    ext2_removexattr,
605  };
606 --- linux-2.4.20/fs/ext2/ialloc.c~linux-2.4.20-xattr-0.8.54     2002-11-29 07:53:15.000000000 +0800
607 +++ linux-2.4.20-root/fs/ext2/ialloc.c  2003-05-07 18:08:03.000000000 +0800
608 @@ -15,6 +15,7 @@
609  #include <linux/config.h>
610  #include <linux/fs.h>
611  #include <linux/ext2_fs.h>
612 +#include <linux/ext2_xattr.h>
613  #include <linux/locks.h>
614  #include <linux/quotaops.h>
615  
616 @@ -167,6 +168,7 @@ void ext2_free_inode (struct inode * ino
617          */
618         if (!is_bad_inode(inode)) {
619                 /* Quota is already initialized in iput() */
620 +               ext2_xattr_delete_inode(inode);
621                 DQUOT_FREE_INODE(inode);
622                 DQUOT_DROP(inode);
623         }
624 --- linux-2.4.20/fs/ext2/inode.c~linux-2.4.20-xattr-0.8.54      2002-11-29 07:53:15.000000000 +0800
625 +++ linux-2.4.20-root/fs/ext2/inode.c   2003-05-07 18:08:03.000000000 +0800
626 @@ -39,6 +39,18 @@ MODULE_LICENSE("GPL");
627  static int ext2_update_inode(struct inode * inode, int do_sync);
628  
629  /*
630 + * Test whether an inode is a fast symlink.
631 + */
632 +static inline int ext2_inode_is_fast_symlink(struct inode *inode)
633 +{
634 +       int ea_blocks = inode->u.ext2_i.i_file_acl ?
635 +               (inode->i_sb->s_blocksize >> 9) : 0;
636 +
637 +       return (S_ISLNK(inode->i_mode) &&
638 +               inode->i_blocks - ea_blocks == 0);
639 +}
640 +
641 +/*
642   * Called at each iput()
643   */
644  void ext2_put_inode (struct inode * inode)
645 @@ -53,9 +65,7 @@ void ext2_delete_inode (struct inode * i
646  {
647         lock_kernel();
648  
649 -       if (is_bad_inode(inode) ||
650 -           inode->i_ino == EXT2_ACL_IDX_INO ||
651 -           inode->i_ino == EXT2_ACL_DATA_INO)
652 +       if (is_bad_inode(inode))
653                 goto no_delete;
654         inode->u.ext2_i.i_dtime = CURRENT_TIME;
655         mark_inode_dirty(inode);
656 @@ -801,6 +811,8 @@ void ext2_truncate (struct inode * inode
657         if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
658             S_ISLNK(inode->i_mode)))
659                 return;
660 +       if (ext2_inode_is_fast_symlink(inode))
661 +               return;
662         if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
663                 return;
664  
665 @@ -888,8 +900,7 @@ void ext2_read_inode (struct inode * ino
666         unsigned long offset;
667         struct ext2_group_desc * gdp;
668  
669 -       if ((inode->i_ino != EXT2_ROOT_INO && inode->i_ino != EXT2_ACL_IDX_INO &&
670 -            inode->i_ino != EXT2_ACL_DATA_INO &&
671 +       if ((inode->i_ino != EXT2_ROOT_INO &&
672              inode->i_ino < EXT2_FIRST_INO(inode->i_sb)) ||
673             inode->i_ino > le32_to_cpu(inode->i_sb->u.ext2_sb.s_es->s_inodes_count)) {
674                 ext2_error (inode->i_sb, "ext2_read_inode",
675 @@ -974,10 +985,7 @@ void ext2_read_inode (struct inode * ino
676         for (block = 0; block < EXT2_N_BLOCKS; block++)
677                 inode->u.ext2_i.i_data[block] = raw_inode->i_block[block];
678  
679 -       if (inode->i_ino == EXT2_ACL_IDX_INO ||
680 -           inode->i_ino == EXT2_ACL_DATA_INO)
681 -               /* Nothing to do */ ;
682 -       else if (S_ISREG(inode->i_mode)) {
683 +       if (S_ISREG(inode->i_mode)) {
684                 inode->i_op = &ext2_file_inode_operations;
685                 inode->i_fop = &ext2_file_operations;
686                 inode->i_mapping->a_ops = &ext2_aops;
687 @@ -986,15 +994,17 @@ void ext2_read_inode (struct inode * ino
688                 inode->i_fop = &ext2_dir_operations;
689                 inode->i_mapping->a_ops = &ext2_aops;
690         } else if (S_ISLNK(inode->i_mode)) {
691 -               if (!inode->i_blocks)
692 +               if (ext2_inode_is_fast_symlink(inode))
693                         inode->i_op = &ext2_fast_symlink_inode_operations;
694                 else {
695 -                       inode->i_op = &page_symlink_inode_operations;
696 +                       inode->i_op = &ext2_symlink_inode_operations;
697                         inode->i_mapping->a_ops = &ext2_aops;
698                 }
699 -       } else 
700 +       } else {
701 +               inode->i_op = &ext2_special_inode_operations;
702                 init_special_inode(inode, inode->i_mode,
703                                    le32_to_cpu(raw_inode->i_block[0]));
704 +       }
705         brelse (bh);
706         inode->i_attr_flags = 0;
707         if (inode->u.ext2_i.i_flags & EXT2_SYNC_FL) {
708 --- linux-2.4.20/fs/ext2/namei.c~linux-2.4.20-xattr-0.8.54      2001-10-04 13:57:36.000000000 +0800
709 +++ linux-2.4.20-root/fs/ext2/namei.c   2003-05-07 18:08:03.000000000 +0800
710 @@ -31,6 +31,7 @@
711  
712  #include <linux/fs.h>
713  #include <linux/ext2_fs.h>
714 +#include <linux/ext2_xattr.h>
715  #include <linux/pagemap.h>
716  
717  /*
718 @@ -136,7 +137,7 @@ static int ext2_symlink (struct inode * 
719  
720         if (l > sizeof (inode->u.ext2_i.i_data)) {
721                 /* slow symlink */
722 -               inode->i_op = &page_symlink_inode_operations;
723 +               inode->i_op = &ext2_symlink_inode_operations;
724                 inode->i_mapping->a_ops = &ext2_aops;
725                 err = block_symlink(inode, symname, l);
726                 if (err)
727 @@ -345,4 +346,15 @@ struct inode_operations ext2_dir_inode_o
728         rmdir:          ext2_rmdir,
729         mknod:          ext2_mknod,
730         rename:         ext2_rename,
731 +       setxattr:       ext2_setxattr,
732 +       getxattr:       ext2_getxattr,
733 +       listxattr:      ext2_listxattr,
734 +       removexattr:    ext2_removexattr,
735 +};
736 +
737 +struct inode_operations ext2_special_inode_operations = {
738 +       setxattr:       ext2_setxattr,
739 +       getxattr:       ext2_getxattr,
740 +       listxattr:      ext2_listxattr,
741 +       removexattr:    ext2_removexattr,
742  };
743 --- linux-2.4.20/fs/ext2/super.c~linux-2.4.20-xattr-0.8.54      2002-11-29 07:53:15.000000000 +0800
744 +++ linux-2.4.20-root/fs/ext2/super.c   2003-05-07 18:08:03.000000000 +0800
745 @@ -21,6 +21,7 @@
746  #include <linux/string.h>
747  #include <linux/fs.h>
748  #include <linux/ext2_fs.h>
749 +#include <linux/ext2_xattr.h>
750  #include <linux/slab.h>
751  #include <linux/init.h>
752  #include <linux/locks.h>
753 @@ -125,6 +126,7 @@ void ext2_put_super (struct super_block 
754         int db_count;
755         int i;
756  
757 +       ext2_xattr_put_super(sb);
758         if (!(sb->s_flags & MS_RDONLY)) {
759                 struct ext2_super_block *es = EXT2_SB(sb)->s_es;
760  
761 @@ -175,6 +177,13 @@ static int parse_options (char * options
762              this_char = strtok (NULL, ",")) {
763                 if ((value = strchr (this_char, '=')) != NULL)
764                         *value++ = 0;
765 +#ifdef CONFIG_EXT2_FS_XATTR_USER
766 +               if (!strcmp (this_char, "user_xattr"))
767 +                       set_opt (*mount_options, XATTR_USER);
768 +               else if (!strcmp (this_char, "nouser_xattr"))
769 +                       clear_opt (*mount_options, XATTR_USER);
770 +               else
771 +#endif
772                 if (!strcmp (this_char, "bsddf"))
773                         clear_opt (*mount_options, MINIX_DF);
774                 else if (!strcmp (this_char, "nouid32")) {
775 @@ -424,6 +433,9 @@ struct super_block * ext2_read_super (st
776             blocksize = BLOCK_SIZE;
777  
778         sb->u.ext2_sb.s_mount_opt = 0;
779 +#ifdef CONFIG_EXT2_FS_XATTR_USER
780 +       /* set_opt (sb->u.ext2_sb.s_mount_opt, XATTR_USER); */
781 +#endif
782         if (!parse_options ((char *) data, &sb_block, &resuid, &resgid,
783             &sb->u.ext2_sb.s_mount_opt)) {
784                 return NULL;
785 @@ -813,12 +825,27 @@ static DECLARE_FSTYPE_DEV(ext2_fs_type, 
786  
787  static int __init init_ext2_fs(void)
788  {
789 -        return register_filesystem(&ext2_fs_type);
790 +       int error = init_ext2_xattr();
791 +       if (error)
792 +               return error;
793 +       error = init_ext2_xattr_user();
794 +       if (error)
795 +               goto fail;
796 +       error = register_filesystem(&ext2_fs_type);
797 +       if (!error)
798 +               return 0;
799 +
800 +       exit_ext2_xattr_user();
801 +fail:
802 +       exit_ext2_xattr();
803 +       return error;
804  }
805  
806  static void __exit exit_ext2_fs(void)
807  {
808         unregister_filesystem(&ext2_fs_type);
809 +       exit_ext2_xattr_user();
810 +       exit_ext2_xattr();
811  }
812  
813  EXPORT_NO_SYMBOLS;
814 --- linux-2.4.20/fs/ext2/symlink.c~linux-2.4.20-xattr-0.8.54    2000-09-28 04:41:33.000000000 +0800
815 +++ linux-2.4.20-root/fs/ext2/symlink.c 2003-05-07 18:08:03.000000000 +0800
816 @@ -19,6 +19,7 @@
817  
818  #include <linux/fs.h>
819  #include <linux/ext2_fs.h>
820 +#include <linux/ext2_xattr.h>
821  
822  static int ext2_readlink(struct dentry *dentry, char *buffer, int buflen)
823  {
824 @@ -32,7 +33,20 @@ static int ext2_follow_link(struct dentr
825         return vfs_follow_link(nd, s);
826  }
827  
828 +struct inode_operations ext2_symlink_inode_operations = {
829 +       readlink:       page_readlink,
830 +       follow_link:    page_follow_link,
831 +       setxattr:       ext2_setxattr,
832 +       getxattr:       ext2_getxattr,
833 +       listxattr:      ext2_listxattr,
834 +       removexattr:    ext2_removexattr,
835 +};
836 +
837  struct inode_operations ext2_fast_symlink_inode_operations = {
838         readlink:       ext2_readlink,
839         follow_link:    ext2_follow_link,
840 +       setxattr:       ext2_setxattr,
841 +       getxattr:       ext2_getxattr,
842 +       listxattr:      ext2_listxattr,
843 +       removexattr:    ext2_removexattr,
844  };
845 --- /dev/null   2003-01-30 18:24:37.000000000 +0800
846 +++ linux-2.4.20-root/fs/ext2/xattr.c   2003-05-07 18:08:03.000000000 +0800
847 @@ -0,0 +1,1212 @@
848 +/*
849 + * linux/fs/ext2/xattr.c
850 + *
851 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
852 + *
853 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
854 + * Extended attributes for symlinks and special files added per
855 + *  suggestion of Luka Renko <luka.renko@hermes.si>.
856 + */
857 +
858 +/*
859 + * Extended attributes are stored on disk blocks allocated outside of
860 + * any inode. The i_file_acl field is then made to point to this allocated
861 + * block. If all extended attributes of an inode are identical, these
862 + * inodes may share the same extended attribute block. Such situations
863 + * are automatically detected by keeping a cache of recent attribute block
864 + * numbers and hashes over the block's contents in memory.
865 + *
866 + *
867 + * Extended attribute block layout:
868 + *
869 + *   +------------------+
870 + *   | header           |
871 + *   | entry 1          | |
872 + *   | entry 2          | | growing downwards
873 + *   | entry 3          | v
874 + *   | four null bytes  |
875 + *   | . . .            |
876 + *   | value 1          | ^
877 + *   | value 3          | | growing upwards
878 + *   | value 2          | |
879 + *   +------------------+
880 + *
881 + * The block header is followed by multiple entry descriptors. These entry
882 + * descriptors are variable in size, and alligned to EXT2_XATTR_PAD
883 + * byte boundaries. The entry descriptors are sorted by attribute name,
884 + * so that two extended attribute blocks can be compared efficiently.
885 + *
886 + * Attribute values are aligned to the end of the block, stored in
887 + * no specific order. They are also padded to EXT2_XATTR_PAD byte
888 + * boundaries. No additional gaps are left between them.
889 + *
890 + * Locking strategy
891 + * ----------------
892 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
893 + * the xattr inode operations are called, so we are guaranteed that only one
894 + * processes accesses extended attributes of an inode at any time.
895 + *
896 + * For writing we also grab the ext2_xattr_sem semaphore. This ensures that
897 + * only a single process is modifying an extended attribute block, even
898 + * if the block is shared among inodes.
899 + *
900 + * Note for porting to 2.5
901 + * -----------------------
902 + * The BKL will no longer be held in the xattr inode operations.
903 + */
904 +
905 +#include <linux/module.h>
906 +#include <linux/locks.h>
907 +#include <linux/slab.h>
908 +#include <linux/fs.h>
909 +#include <linux/ext2_fs.h>
910 +#include <linux/ext2_xattr.h>
911 +#include <linux/mbcache.h>
912 +#include <linux/quotaops.h>
913 +#include <asm/semaphore.h>
914 +#include <linux/compatmac.h>
915 +
916 +/* These symbols may be needed by a module. */
917 +EXPORT_SYMBOL(ext2_xattr_register);
918 +EXPORT_SYMBOL(ext2_xattr_unregister);
919 +EXPORT_SYMBOL(ext2_xattr_get);
920 +EXPORT_SYMBOL(ext2_xattr_list);
921 +EXPORT_SYMBOL(ext2_xattr_set);
922 +
923 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
924 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
925 +#endif
926 +
927 +#define HDR(bh) ((struct ext2_xattr_header *)((bh)->b_data))
928 +#define ENTRY(ptr) ((struct ext2_xattr_entry *)(ptr))
929 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
930 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
931 +
932 +#ifdef EXT2_XATTR_DEBUG
933 +# define ea_idebug(inode, f...) do { \
934 +               printk(KERN_DEBUG "inode %s:%ld: ", \
935 +                       kdevname(inode->i_dev), inode->i_ino); \
936 +               printk(f); \
937 +               printk("\n"); \
938 +       } while (0)
939 +# define ea_bdebug(bh, f...) do { \
940 +               printk(KERN_DEBUG "block %s:%ld: ", \
941 +                       kdevname(bh->b_dev), bh->b_blocknr); \
942 +               printk(f); \
943 +               printk("\n"); \
944 +       } while (0)
945 +#else
946 +# define ea_idebug(f...)
947 +# define ea_bdebug(f...)
948 +#endif
949 +
950 +static int ext2_xattr_set2(struct inode *, struct buffer_head *,
951 +                          struct ext2_xattr_header *);
952 +
953 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
954 +
955 +static int ext2_xattr_cache_insert(struct buffer_head *);
956 +static struct buffer_head *ext2_xattr_cache_find(struct inode *,
957 +                                                struct ext2_xattr_header *);
958 +static void ext2_xattr_cache_remove(struct buffer_head *);
959 +static void ext2_xattr_rehash(struct ext2_xattr_header *,
960 +                             struct ext2_xattr_entry *);
961 +
962 +static struct mb_cache *ext2_xattr_cache;
963 +
964 +#else
965 +# define ext2_xattr_cache_insert(bh) 0
966 +# define ext2_xattr_cache_find(inode, header) NULL
967 +# define ext2_xattr_cache_remove(bh) while(0) {}
968 +# define ext2_xattr_rehash(header, entry) while(0) {}
969 +#endif
970 +
971 +/*
972 + * If a file system does not share extended attributes among inodes,
973 + * we should not need the ext2_xattr_sem semaphore. However, the
974 + * filesystem may still contain shared blocks, so we always take
975 + * the lock.
976 + */
977 +
978 +DECLARE_MUTEX(ext2_xattr_sem);
979 +
980 +static inline int
981 +ext2_xattr_new_block(struct inode *inode, int * errp, int force)
982 +{
983 +       struct super_block *sb = inode->i_sb;
984 +       int goal = le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block) +
985 +               EXT2_I(inode)->i_block_group * EXT2_BLOCKS_PER_GROUP(sb);
986 +
987 +       /* How can we enforce the allocation? */
988 +       int block = ext2_new_block(inode, goal, 0, 0, errp);
989 +#ifdef OLD_QUOTAS
990 +       if (!*errp)
991 +               inode->i_blocks += inode->i_sb->s_blocksize >> 9;
992 +#endif
993 +       return block;
994 +}
995 +
996 +static inline int
997 +ext2_xattr_quota_alloc(struct inode *inode, int force)
998 +{
999 +       /* How can we enforce the allocation? */
1000 +#ifdef OLD_QUOTAS
1001 +       int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
1002 +       if (!error)
1003 +               inode->i_blocks += inode->i_sb->s_blocksize >> 9;
1004 +#else
1005 +       int error = DQUOT_ALLOC_BLOCK(inode, 1);
1006 +#endif
1007 +       return error;
1008 +}
1009 +
1010 +#ifdef OLD_QUOTAS
1011 +
1012 +static inline void
1013 +ext2_xattr_quota_free(struct inode *inode)
1014 +{
1015 +       DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
1016 +       inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
1017 +}
1018 +
1019 +static inline void
1020 +ext2_xattr_free_block(struct inode * inode, unsigned long block)
1021 +{
1022 +       ext2_free_blocks(inode, block, 1);
1023 +       inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
1024 +}
1025 +
1026 +#else
1027 +# define ext2_xattr_quota_free(inode) \
1028 +       DQUOT_FREE_BLOCK(inode, 1)
1029 +# define ext2_xattr_free_block(inode, block) \
1030 +       ext2_free_blocks(inode, block, 1)
1031 +#endif
1032 +
1033 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
1034 +
1035 +static inline struct buffer_head *
1036 +sb_bread(struct super_block *sb, int block)
1037 +{
1038 +       return bread(sb->s_dev, block, sb->s_blocksize);
1039 +}
1040 +
1041 +static inline struct buffer_head *
1042 +sb_getblk(struct super_block *sb, int block)
1043 +{
1044 +       return getblk(sb->s_dev, block, sb->s_blocksize);
1045 +}
1046 +
1047 +#endif
1048 +
1049 +struct ext2_xattr_handler *ext2_xattr_handlers[EXT2_XATTR_INDEX_MAX];
1050 +rwlock_t ext2_handler_lock = RW_LOCK_UNLOCKED;
1051 +
1052 +int
1053 +ext2_xattr_register(int name_index, struct ext2_xattr_handler *handler)
1054 +{
1055 +       int error = -EINVAL;
1056 +
1057 +       if (name_index > 0 && name_index <= EXT2_XATTR_INDEX_MAX) {
1058 +               write_lock(&ext2_handler_lock);
1059 +               if (!ext2_xattr_handlers[name_index-1]) {
1060 +                       ext2_xattr_handlers[name_index-1] = handler;
1061 +                       error = 0;
1062 +               }
1063 +               write_unlock(&ext2_handler_lock);
1064 +       }
1065 +       return error;
1066 +}
1067 +
1068 +void
1069 +ext2_xattr_unregister(int name_index, struct ext2_xattr_handler *handler)
1070 +{
1071 +       if (name_index > 0 || name_index <= EXT2_XATTR_INDEX_MAX) {
1072 +               write_lock(&ext2_handler_lock);
1073 +               ext2_xattr_handlers[name_index-1] = NULL;
1074 +               write_unlock(&ext2_handler_lock);
1075 +       }
1076 +}
1077 +
1078 +static inline const char *
1079 +strcmp_prefix(const char *a, const char *a_prefix)
1080 +{
1081 +       while (*a_prefix && *a == *a_prefix) {
1082 +               a++;
1083 +               a_prefix++;
1084 +       }
1085 +       return *a_prefix ? NULL : a;
1086 +}
1087 +
1088 +/*
1089 + * Decode the extended attribute name, and translate it into
1090 + * the name_index and name suffix.
1091 + */
1092 +static struct ext2_xattr_handler *
1093 +ext2_xattr_resolve_name(const char **name)
1094 +{
1095 +       struct ext2_xattr_handler *handler = NULL;
1096 +       int i;
1097 +
1098 +       if (!*name)
1099 +               return NULL;
1100 +       read_lock(&ext2_handler_lock);
1101 +       for (i=0; i<EXT2_XATTR_INDEX_MAX; i++) {
1102 +               if (ext2_xattr_handlers[i]) {
1103 +                       const char *n = strcmp_prefix(*name,
1104 +                               ext2_xattr_handlers[i]->prefix);
1105 +                       if (n) {
1106 +                               handler = ext2_xattr_handlers[i];
1107 +                               *name = n;
1108 +                               break;
1109 +                       }
1110 +               }
1111 +       }
1112 +       read_unlock(&ext2_handler_lock);
1113 +       return handler;
1114 +}
1115 +
1116 +static inline struct ext2_xattr_handler *
1117 +ext2_xattr_handler(int name_index)
1118 +{
1119 +       struct ext2_xattr_handler *handler = NULL;
1120 +       if (name_index > 0 && name_index <= EXT2_XATTR_INDEX_MAX) {
1121 +               read_lock(&ext2_handler_lock);
1122 +               handler = ext2_xattr_handlers[name_index-1];
1123 +               read_unlock(&ext2_handler_lock);
1124 +       }
1125 +       return handler;
1126 +}
1127 +
1128 +/*
1129 + * Inode operation getxattr()
1130 + *
1131 + * dentry->d_inode->i_sem down
1132 + * BKL held [before 2.5.x]
1133 + */
1134 +ssize_t
1135 +ext2_getxattr(struct dentry *dentry, const char *name,
1136 +             void *buffer, size_t size)
1137 +{
1138 +       struct ext2_xattr_handler *handler;
1139 +       struct inode *inode = dentry->d_inode;
1140 +
1141 +       handler = ext2_xattr_resolve_name(&name);
1142 +       if (!handler)
1143 +               return -ENOTSUP;
1144 +       return handler->get(inode, name, buffer, size);
1145 +}
1146 +
1147 +/*
1148 + * Inode operation listxattr()
1149 + *
1150 + * dentry->d_inode->i_sem down
1151 + * BKL held [before 2.5.x]
1152 + */
1153 +ssize_t
1154 +ext2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1155 +{
1156 +       return ext2_xattr_list(dentry->d_inode, buffer, size);
1157 +}
1158 +
1159 +/*
1160 + * Inode operation setxattr()
1161 + *
1162 + * dentry->d_inode->i_sem down
1163 + * BKL held [before 2.5.x]
1164 + */
1165 +int
1166 +ext2_setxattr(struct dentry *dentry, const char *name,
1167 +             const void *value, size_t size, int flags)
1168 +{
1169 +       struct ext2_xattr_handler *handler;
1170 +       struct inode *inode = dentry->d_inode;
1171 +
1172 +       if (size == 0)
1173 +               value = "";  /* empty EA, do not remove */
1174 +       handler = ext2_xattr_resolve_name(&name);
1175 +       if (!handler)
1176 +               return -ENOTSUP;
1177 +       return handler->set(inode, name, value, size, flags);
1178 +}
1179 +
1180 +/*
1181 + * Inode operation removexattr()
1182 + *
1183 + * dentry->d_inode->i_sem down
1184 + * BKL held [before 2.5.x]
1185 + */
1186 +int
1187 +ext2_removexattr(struct dentry *dentry, const char *name)
1188 +{
1189 +       struct ext2_xattr_handler *handler;
1190 +       struct inode *inode = dentry->d_inode;
1191 +
1192 +       handler = ext2_xattr_resolve_name(&name);
1193 +       if (!handler)
1194 +               return -ENOTSUP;
1195 +       return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
1196 +}
1197 +
1198 +/*
1199 + * ext2_xattr_get()
1200 + *
1201 + * Copy an extended attribute into the buffer
1202 + * provided, or compute the buffer size required.
1203 + * Buffer is NULL to compute the size of the buffer required.
1204 + *
1205 + * Returns a negative error number on failure, or the number of bytes
1206 + * used / required on success.
1207 + */
1208 +int
1209 +ext2_xattr_get(struct inode *inode, int name_index, const char *name,
1210 +              void *buffer, size_t buffer_size)
1211 +{
1212 +       struct buffer_head *bh = NULL;
1213 +       struct ext2_xattr_entry *entry;
1214 +       unsigned int block, size;
1215 +       char *end;
1216 +       int name_len, error;
1217 +
1218 +       ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
1219 +                 name_index, name, buffer, (long)buffer_size);
1220 +
1221 +       if (name == NULL)
1222 +               return -EINVAL;
1223 +       if (!EXT2_I(inode)->i_file_acl)
1224 +               return -ENOATTR;
1225 +       block = EXT2_I(inode)->i_file_acl;
1226 +       ea_idebug(inode, "reading block %d", block);
1227 +       bh = sb_bread(inode->i_sb, block);
1228 +       if (!bh)
1229 +               return -EIO;
1230 +       ea_bdebug(bh, "b_count=%d, refcount=%d",
1231 +               atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
1232 +       end = bh->b_data + bh->b_size;
1233 +       if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1234 +           HDR(bh)->h_blocks != cpu_to_le32(1)) {
1235 +bad_block:     ext2_error(inode->i_sb, "ext2_xattr_get",
1236 +                       "inode %ld: bad block %d", inode->i_ino, block);
1237 +               error = -EIO;
1238 +               goto cleanup;
1239 +       }
1240 +       /* find named attribute */
1241 +       name_len = strlen(name);
1242 +
1243 +       error = -ERANGE;
1244 +       if (name_len > 255)
1245 +               goto cleanup;
1246 +       entry = FIRST_ENTRY(bh);
1247 +       while (!IS_LAST_ENTRY(entry)) {
1248 +               struct ext2_xattr_entry *next =
1249 +                       EXT2_XATTR_NEXT(entry);
1250 +               if ((char *)next >= end)
1251 +                       goto bad_block;
1252 +               if (name_index == entry->e_name_index &&
1253 +                   name_len == entry->e_name_len &&
1254 +                   memcmp(name, entry->e_name, name_len) == 0)
1255 +                       goto found;
1256 +               entry = next;
1257 +       }
1258 +       /* Check the remaining name entries */
1259 +       while (!IS_LAST_ENTRY(entry)) {
1260 +               struct ext2_xattr_entry *next =
1261 +                       EXT2_XATTR_NEXT(entry);
1262 +               if ((char *)next >= end)
1263 +                       goto bad_block;
1264 +               entry = next;
1265 +       }
1266 +       if (ext2_xattr_cache_insert(bh))
1267 +               ea_idebug(inode, "cache insert failed");
1268 +       error = -ENOATTR;
1269 +       goto cleanup;
1270 +found:
1271 +       /* check the buffer size */
1272 +       if (entry->e_value_block != 0)
1273 +               goto bad_block;
1274 +       size = le32_to_cpu(entry->e_value_size);
1275 +       if (size > inode->i_sb->s_blocksize ||
1276 +           le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
1277 +               goto bad_block;
1278 +
1279 +       if (ext2_xattr_cache_insert(bh))
1280 +               ea_idebug(inode, "cache insert failed");
1281 +       if (buffer) {
1282 +               error = -ERANGE;
1283 +               if (size > buffer_size)
1284 +                       goto cleanup;
1285 +               /* return value of attribute */
1286 +               memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
1287 +                       size);
1288 +       }
1289 +       error = size;
1290 +
1291 +cleanup:
1292 +       brelse(bh);
1293 +
1294 +       return error;
1295 +}
1296 +
1297 +/*
1298 + * ext2_xattr_list()
1299 + *
1300 + * Copy a list of attribute names into the buffer
1301 + * provided, or compute the buffer size required.
1302 + * Buffer is NULL to compute the size of the buffer required.
1303 + *
1304 + * Returns a negative error number on failure, or the number of bytes
1305 + * used / required on success.
1306 + */
1307 +int
1308 +ext2_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
1309 +{
1310 +       struct buffer_head *bh = NULL;
1311 +       struct ext2_xattr_entry *entry;
1312 +       unsigned int block, size = 0;
1313 +       char *buf, *end;
1314 +       int error;
1315 +
1316 +       ea_idebug(inode, "buffer=%p, buffer_size=%ld",
1317 +                 buffer, (long)buffer_size);
1318 +
1319 +       if (!EXT2_I(inode)->i_file_acl)
1320 +               return 0;
1321 +       block = EXT2_I(inode)->i_file_acl;
1322 +       ea_idebug(inode, "reading block %d", block);
1323 +       bh = sb_bread(inode->i_sb, block);
1324 +       if (!bh)
1325 +               return -EIO;
1326 +       ea_bdebug(bh, "b_count=%d, refcount=%d",
1327 +               atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
1328 +       end = bh->b_data + bh->b_size;
1329 +       if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1330 +           HDR(bh)->h_blocks != cpu_to_le32(1)) {
1331 +bad_block:     ext2_error(inode->i_sb, "ext2_xattr_list",
1332 +                       "inode %ld: bad block %d", inode->i_ino, block);
1333 +               error = -EIO;
1334 +               goto cleanup;
1335 +       }
1336 +       /* compute the size required for the list of attribute names */
1337 +       for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
1338 +            entry = EXT2_XATTR_NEXT(entry)) {
1339 +               struct ext2_xattr_handler *handler;
1340 +               struct ext2_xattr_entry *next =
1341 +                       EXT2_XATTR_NEXT(entry);
1342 +               if ((char *)next >= end)
1343 +                       goto bad_block;
1344 +
1345 +               handler = ext2_xattr_handler(entry->e_name_index);
1346 +               if (handler)
1347 +                       size += handler->list(NULL, inode, entry->e_name,
1348 +                                             entry->e_name_len);
1349 +       }
1350 +
1351 +       if (ext2_xattr_cache_insert(bh))
1352 +               ea_idebug(inode, "cache insert failed");
1353 +       if (!buffer) {
1354 +               error = size;
1355 +               goto cleanup;
1356 +       } else {
1357 +               error = -ERANGE;
1358 +               if (size > buffer_size)
1359 +                       goto cleanup;
1360 +       }
1361 +
1362 +       /* list the attribute names */
1363 +       buf = buffer;
1364 +       for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
1365 +            entry = EXT2_XATTR_NEXT(entry)) {
1366 +               struct ext2_xattr_handler *handler;
1367 +               
1368 +               handler = ext2_xattr_handler(entry->e_name_index);
1369 +               if (handler)
1370 +                       buf += handler->list(buf, inode, entry->e_name,
1371 +                                            entry->e_name_len);
1372 +       }
1373 +       error = size;
1374 +
1375 +cleanup:
1376 +       brelse(bh);
1377 +
1378 +       return error;
1379 +}
1380 +
1381 +/*
1382 + * If the EXT2_FEATURE_COMPAT_EXT_ATTR feature of this file system is
1383 + * not set, set it.
1384 + */
1385 +static void ext2_xattr_update_super_block(struct super_block *sb)
1386 +{
1387 +       if (EXT2_HAS_COMPAT_FEATURE(sb, EXT2_FEATURE_COMPAT_EXT_ATTR))
1388 +               return;
1389 +
1390 +       lock_super(sb);
1391 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
1392 +       EXT2_SB(sb)->s_feature_compat |= EXT2_FEATURE_COMPAT_EXT_ATTR;
1393 +#endif
1394 +       EXT2_SB(sb)->s_es->s_feature_compat |=
1395 +               cpu_to_le32(EXT2_FEATURE_COMPAT_EXT_ATTR);
1396 +       sb->s_dirt = 1;
1397 +       mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
1398 +       unlock_super(sb);
1399 +}
1400 +
1401 +/*
1402 + * ext2_xattr_set()
1403 + *
1404 + * Create, replace or remove an extended attribute for this inode. Buffer
1405 + * is NULL to remove an existing extended attribute, and non-NULL to
1406 + * either replace an existing extended attribute, or create a new extended
1407 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
1408 + * specify that an extended attribute must exist and must not exist
1409 + * previous to the call, respectively.
1410 + *
1411 + * Returns 0, or a negative error number on failure.
1412 + */
1413 +int
1414 +ext2_xattr_set(struct inode *inode, int name_index, const char *name,
1415 +              const void *value, size_t value_len, int flags)
1416 +{
1417 +       struct super_block *sb = inode->i_sb;
1418 +       struct buffer_head *bh = NULL;
1419 +       struct ext2_xattr_header *header = NULL;
1420 +       struct ext2_xattr_entry *here, *last;
1421 +       unsigned int name_len;
1422 +       int block = EXT2_I(inode)->i_file_acl;
1423 +       int min_offs = sb->s_blocksize, not_found = 1, free, error;
1424 +       char *end;
1425 +       
1426 +       /*
1427 +        * header -- Points either into bh, or to a temporarily
1428 +        *           allocated buffer.
1429 +        * here -- The named entry found, or the place for inserting, within
1430 +        *         the block pointed to by header.
1431 +        * last -- Points right after the last named entry within the block
1432 +        *         pointed to by header.
1433 +        * min_offs -- The offset of the first value (values are aligned
1434 +        *             towards the end of the block).
1435 +        * end -- Points right after the block pointed to by header.
1436 +        */
1437 +       
1438 +       ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
1439 +                 name_index, name, value, (long)value_len);
1440 +
1441 +       if (IS_RDONLY(inode))
1442 +               return -EROFS;
1443 +       if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1444 +               return -EPERM;
1445 +       if (value == NULL)
1446 +               value_len = 0;
1447 +       if (name == NULL)
1448 +               return -EINVAL;
1449 +       name_len = strlen(name);
1450 +       if (name_len > 255 || value_len > sb->s_blocksize)
1451 +               return -ERANGE;
1452 +       down(&ext2_xattr_sem);
1453 +
1454 +       if (block) {
1455 +               /* The inode already has an extended attribute block. */
1456 +
1457 +               bh = sb_bread(sb, block);
1458 +               error = -EIO;
1459 +               if (!bh)
1460 +                       goto cleanup;
1461 +               ea_bdebug(bh, "b_count=%d, refcount=%d",
1462 +                       atomic_read(&(bh->b_count)),
1463 +                       le32_to_cpu(HDR(bh)->h_refcount));
1464 +               header = HDR(bh);
1465 +               end = bh->b_data + bh->b_size;
1466 +               if (header->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1467 +                   header->h_blocks != cpu_to_le32(1)) {
1468 +bad_block:             ext2_error(sb, "ext2_xattr_set",
1469 +                               "inode %ld: bad block %d", inode->i_ino, block);
1470 +                       error = -EIO;
1471 +                       goto cleanup;
1472 +               }
1473 +               /* Find the named attribute. */
1474 +               here = FIRST_ENTRY(bh);
1475 +               while (!IS_LAST_ENTRY(here)) {
1476 +                       struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(here);
1477 +                       if ((char *)next >= end)
1478 +                               goto bad_block;
1479 +                       if (!here->e_value_block && here->e_value_size) {
1480 +                               int offs = le16_to_cpu(here->e_value_offs);
1481 +                               if (offs < min_offs)
1482 +                                       min_offs = offs;
1483 +                       }
1484 +                       not_found = name_index - here->e_name_index;
1485 +                       if (!not_found)
1486 +                               not_found = name_len - here->e_name_len;
1487 +                       if (!not_found)
1488 +                               not_found = memcmp(name, here->e_name,name_len);
1489 +                       if (not_found <= 0)
1490 +                               break;
1491 +                       here = next;
1492 +               }
1493 +               last = here;
1494 +               /* We still need to compute min_offs and last. */
1495 +               while (!IS_LAST_ENTRY(last)) {
1496 +                       struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(last);
1497 +                       if ((char *)next >= end)
1498 +                               goto bad_block;
1499 +                       if (!last->e_value_block && last->e_value_size) {
1500 +                               int offs = le16_to_cpu(last->e_value_offs);
1501 +                               if (offs < min_offs)
1502 +                                       min_offs = offs;
1503 +                       }
1504 +                       last = next;
1505 +               }
1506 +
1507 +               /* Check whether we have enough space left. */
1508 +               free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
1509 +       } else {
1510 +               /* We will use a new extended attribute block. */
1511 +               free = sb->s_blocksize -
1512 +                       sizeof(struct ext2_xattr_header) - sizeof(__u32);
1513 +               here = last = NULL;  /* avoid gcc uninitialized warning. */
1514 +       }
1515 +
1516 +       if (not_found) {
1517 +               /* Request to remove a nonexistent attribute? */
1518 +               error = -ENOATTR;
1519 +               if (flags & XATTR_REPLACE)
1520 +                       goto cleanup;
1521 +               error = 0;
1522 +               if (value == NULL)
1523 +                       goto cleanup;
1524 +               else
1525 +                       free -= EXT2_XATTR_LEN(name_len);
1526 +       } else {
1527 +               /* Request to create an existing attribute? */
1528 +               error = -EEXIST;
1529 +               if (flags & XATTR_CREATE)
1530 +                       goto cleanup;
1531 +               if (!here->e_value_block && here->e_value_size) {
1532 +                       unsigned int size = le32_to_cpu(here->e_value_size);
1533 +
1534 +                       if (le16_to_cpu(here->e_value_offs) + size > 
1535 +                           sb->s_blocksize || size > sb->s_blocksize)
1536 +                               goto bad_block;
1537 +                       free += EXT2_XATTR_SIZE(size);
1538 +               }
1539 +       }
1540 +       free -= EXT2_XATTR_SIZE(value_len);
1541 +       error = -ENOSPC;
1542 +       if (free < 0)
1543 +               goto cleanup;
1544 +
1545 +       /* Here we know that we can set the new attribute. */
1546 +
1547 +       if (header) {
1548 +               if (header->h_refcount == cpu_to_le32(1)) {
1549 +                       ea_bdebug(bh, "modifying in-place");
1550 +                       ext2_xattr_cache_remove(bh);
1551 +               } else {
1552 +                       int offset;
1553 +
1554 +                       ea_bdebug(bh, "cloning");
1555 +                       header = kmalloc(bh->b_size, GFP_KERNEL);
1556 +                       error = -ENOMEM;
1557 +                       if (header == NULL)
1558 +                               goto cleanup;
1559 +                       memcpy(header, HDR(bh), bh->b_size);
1560 +                       header->h_refcount = cpu_to_le32(1);
1561 +                       offset = (char *)header - bh->b_data;
1562 +                       here = ENTRY((char *)here + offset);
1563 +                       last = ENTRY((char *)last + offset);
1564 +               }
1565 +       } else {
1566 +               /* Allocate a buffer where we construct the new block. */
1567 +               header = kmalloc(sb->s_blocksize, GFP_KERNEL);
1568 +               error = -ENOMEM;
1569 +               if (header == NULL)
1570 +                       goto cleanup;
1571 +               memset(header, 0, sb->s_blocksize);
1572 +               end = (char *)header + sb->s_blocksize;
1573 +               header->h_magic = cpu_to_le32(EXT2_XATTR_MAGIC);
1574 +               header->h_blocks = header->h_refcount = cpu_to_le32(1);
1575 +               last = here = ENTRY(header+1);
1576 +       }
1577 +
1578 +       if (not_found) {
1579 +               /* Insert the new name. */
1580 +               int size = EXT2_XATTR_LEN(name_len);
1581 +               int rest = (char *)last - (char *)here;
1582 +               memmove((char *)here + size, here, rest);
1583 +               memset(here, 0, size);
1584 +               here->e_name_index = name_index;
1585 +               here->e_name_len = name_len;
1586 +               memcpy(here->e_name, name, name_len);
1587 +       } else {
1588 +               /* Remove the old value. */
1589 +               if (!here->e_value_block && here->e_value_size) {
1590 +                       char *first_val = (char *)header + min_offs;
1591 +                       int offs = le16_to_cpu(here->e_value_offs);
1592 +                       char *val = (char *)header + offs;
1593 +                       size_t size = EXT2_XATTR_SIZE(
1594 +                               le32_to_cpu(here->e_value_size));
1595 +                       memmove(first_val + size, first_val, val - first_val);
1596 +                       memset(first_val, 0, size);
1597 +                       here->e_value_offs = 0;
1598 +                       min_offs += size;
1599 +
1600 +                       /* Adjust all value offsets. */
1601 +                       last = ENTRY(header+1);
1602 +                       while (!IS_LAST_ENTRY(last)) {
1603 +                               int o = le16_to_cpu(last->e_value_offs);
1604 +                               if (!last->e_value_block && o < offs)
1605 +                                       last->e_value_offs =
1606 +                                               cpu_to_le16(o + size);
1607 +                               last = EXT2_XATTR_NEXT(last);
1608 +                       }
1609 +               }
1610 +               if (value == NULL) {
1611 +                       /* Remove this attribute. */
1612 +                       if (EXT2_XATTR_NEXT(ENTRY(header+1)) == last) {
1613 +                               /* This block is now empty. */
1614 +                               error = ext2_xattr_set2(inode, bh, NULL);
1615 +                               goto cleanup;
1616 +                       } else {
1617 +                               /* Remove the old name. */
1618 +                               int size = EXT2_XATTR_LEN(name_len);
1619 +                               last = ENTRY((char *)last - size);
1620 +                               memmove(here, (char*)here + size,
1621 +                                       (char*)last - (char*)here);
1622 +                               memset(last, 0, size);
1623 +                       }
1624 +               }
1625 +       }
1626 +
1627 +       if (value != NULL) {
1628 +               /* Insert the new value. */
1629 +               here->e_value_size = cpu_to_le32(value_len);
1630 +               if (value_len) {
1631 +                       size_t size = EXT2_XATTR_SIZE(value_len);
1632 +                       char *val = (char *)header + min_offs - size;
1633 +                       here->e_value_offs =
1634 +                               cpu_to_le16((char *)val - (char *)header);
1635 +                       memset(val + size - EXT2_XATTR_PAD, 0,
1636 +                              EXT2_XATTR_PAD); /* Clear the pad bytes. */
1637 +                       memcpy(val, value, value_len);
1638 +               }
1639 +       }
1640 +       ext2_xattr_rehash(header, here);
1641 +
1642 +       error = ext2_xattr_set2(inode, bh, header);
1643 +
1644 +cleanup:
1645 +       brelse(bh);
1646 +       if (!(bh && header == HDR(bh)))
1647 +               kfree(header);
1648 +       up(&ext2_xattr_sem);
1649 +
1650 +       return error;
1651 +}
1652 +
1653 +/*
1654 + * Second half of ext2_xattr_set(): Update the file system.
1655 + */
1656 +static int
1657 +ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
1658 +               struct ext2_xattr_header *header)
1659 +{
1660 +       struct super_block *sb = inode->i_sb;
1661 +       struct buffer_head *new_bh = NULL;
1662 +       int error;
1663 +
1664 +       if (header) {
1665 +               new_bh = ext2_xattr_cache_find(inode, header);
1666 +               if (new_bh) {
1667 +                       /*
1668 +                        * We found an identical block in the cache.
1669 +                        * The old block will be released after updating
1670 +                        * the inode.
1671 +                        */
1672 +                       ea_bdebug(old_bh, "reusing block %ld",
1673 +                               new_bh->b_blocknr);
1674 +                       
1675 +                       error = -EDQUOT;
1676 +                       if (ext2_xattr_quota_alloc(inode, 1))
1677 +                               goto cleanup;
1678 +                       
1679 +                       HDR(new_bh)->h_refcount = cpu_to_le32(
1680 +                               le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
1681 +                       ea_bdebug(new_bh, "refcount now=%d",
1682 +                               le32_to_cpu(HDR(new_bh)->h_refcount));
1683 +               } else if (old_bh && header == HDR(old_bh)) {
1684 +                       /* Keep this block. */
1685 +                       new_bh = old_bh;
1686 +                       ext2_xattr_cache_insert(new_bh);
1687 +               } else {
1688 +                       /* We need to allocate a new block */
1689 +                       int force = EXT2_I(inode)->i_file_acl != 0;
1690 +                       int block = ext2_xattr_new_block(inode, &error, force);
1691 +                       if (error)
1692 +                               goto cleanup;
1693 +                       ea_idebug(inode, "creating block %d", block);
1694 +
1695 +                       new_bh = sb_getblk(sb, block);
1696 +                       if (!new_bh) {
1697 +                               ext2_xattr_free_block(inode, block);
1698 +                               error = -EIO;
1699 +                               goto cleanup;
1700 +                       }
1701 +                       lock_buffer(new_bh);
1702 +                       memcpy(new_bh->b_data, header, new_bh->b_size);
1703 +                       mark_buffer_uptodate(new_bh, 1);
1704 +                       unlock_buffer(new_bh);
1705 +                       ext2_xattr_cache_insert(new_bh);
1706 +                       
1707 +                       ext2_xattr_update_super_block(sb);
1708 +               }
1709 +               mark_buffer_dirty(new_bh);
1710 +               if (IS_SYNC(inode)) {
1711 +                       ll_rw_block(WRITE, 1, &new_bh);
1712 +                       wait_on_buffer(new_bh); 
1713 +                       error = -EIO;
1714 +                       if (buffer_req(new_bh) && !buffer_uptodate(new_bh))
1715 +                               goto cleanup;
1716 +               }
1717 +       }
1718 +
1719 +       /* Update the inode. */
1720 +       EXT2_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
1721 +       inode->i_ctime = CURRENT_TIME;
1722 +       if (IS_SYNC(inode)) {
1723 +               error = ext2_sync_inode (inode);
1724 +               if (error)
1725 +                       goto cleanup;
1726 +       } else
1727 +               mark_inode_dirty(inode);
1728 +
1729 +       error = 0;
1730 +       if (old_bh && old_bh != new_bh) {
1731 +               /*
1732 +                * If there was an old block, and we are not still using it,
1733 +                * we now release the old block.
1734 +               */
1735 +               unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
1736 +
1737 +               if (refcount == 1) {
1738 +                       /* Free the old block. */
1739 +                       ea_bdebug(old_bh, "freeing");
1740 +                       ext2_xattr_free_block(inode, old_bh->b_blocknr);
1741 +                       mark_buffer_clean(old_bh);
1742 +               } else {
1743 +                       /* Decrement the refcount only. */
1744 +                       refcount--;
1745 +                       HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
1746 +                       ext2_xattr_quota_free(inode);
1747 +                       mark_buffer_dirty(old_bh);
1748 +                       ea_bdebug(old_bh, "refcount now=%d", refcount);
1749 +               }
1750 +       }
1751 +
1752 +cleanup:
1753 +       if (old_bh != new_bh)
1754 +               brelse(new_bh);
1755 +
1756 +       return error;
1757 +}
1758 +
1759 +/*
1760 + * ext2_xattr_delete_inode()
1761 + *
1762 + * Free extended attribute resources associated with this inode. This
1763 + * is called immediately before an inode is freed.
1764 + */
1765 +void
1766 +ext2_xattr_delete_inode(struct inode *inode)
1767 +{
1768 +       struct buffer_head *bh;
1769 +       unsigned int block = EXT2_I(inode)->i_file_acl;
1770 +
1771 +       if (!block)
1772 +               return;
1773 +       down(&ext2_xattr_sem);
1774 +
1775 +       bh = sb_bread(inode->i_sb, block);
1776 +       if (!bh) {
1777 +               ext2_error(inode->i_sb, "ext2_xattr_delete_inode",
1778 +                       "inode %ld: block %d read error", inode->i_ino, block);
1779 +               goto cleanup;
1780 +       }
1781 +       ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
1782 +       if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1783 +           HDR(bh)->h_blocks != cpu_to_le32(1)) {
1784 +               ext2_error(inode->i_sb, "ext2_xattr_delete_inode",
1785 +                       "inode %ld: bad block %d", inode->i_ino, block);
1786 +               goto cleanup;
1787 +       }
1788 +       ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
1789 +       if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
1790 +               ext2_xattr_cache_remove(bh);
1791 +               ext2_xattr_free_block(inode, block);
1792 +               bforget(bh);
1793 +               bh = NULL;
1794 +       } else {
1795 +               HDR(bh)->h_refcount = cpu_to_le32(
1796 +                       le32_to_cpu(HDR(bh)->h_refcount) - 1);
1797 +               mark_buffer_dirty(bh);
1798 +               if (IS_SYNC(inode)) {
1799 +                       ll_rw_block(WRITE, 1, &bh);
1800 +                       wait_on_buffer(bh);
1801 +               }
1802 +               ext2_xattr_quota_free(inode);
1803 +       }
1804 +       EXT2_I(inode)->i_file_acl = 0;
1805 +
1806 +cleanup:
1807 +       brelse(bh);
1808 +       up(&ext2_xattr_sem);
1809 +}
1810 +
1811 +/*
1812 + * ext2_xattr_put_super()
1813 + *
1814 + * This is called when a file system is unmounted.
1815 + */
1816 +void
1817 +ext2_xattr_put_super(struct super_block *sb)
1818 +{
1819 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
1820 +       mb_cache_shrink(ext2_xattr_cache, sb->s_dev);
1821 +#endif
1822 +}
1823 +
1824 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
1825 +
1826 +/*
1827 + * ext2_xattr_cache_insert()
1828 + *
1829 + * Create a new entry in the extended attribute cache, and insert
1830 + * it unless such an entry is already in the cache.
1831 + *
1832 + * Returns 0, or a negative error number on failure.
1833 + */
1834 +static int
1835 +ext2_xattr_cache_insert(struct buffer_head *bh)
1836 +{
1837 +       __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
1838 +       struct mb_cache_entry *ce;
1839 +       int error;
1840 +
1841 +       ce = mb_cache_entry_alloc(ext2_xattr_cache);
1842 +       if (!ce)
1843 +               return -ENOMEM;
1844 +       error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
1845 +       if (error) {
1846 +               mb_cache_entry_free(ce);
1847 +               if (error == -EBUSY) {
1848 +                       ea_bdebug(bh, "already in cache (%d cache entries)",
1849 +                               atomic_read(&ext2_xattr_cache->c_entry_count));
1850 +                       error = 0;
1851 +               }
1852 +       } else {
1853 +               ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
1854 +                         atomic_read(&ext2_xattr_cache->c_entry_count));
1855 +               mb_cache_entry_release(ce);
1856 +       }
1857 +       return error;
1858 +}
1859 +
1860 +/*
1861 + * ext2_xattr_cmp()
1862 + *
1863 + * Compare two extended attribute blocks for equality.
1864 + *
1865 + * Returns 0 if the blocks are equal, 1 if they differ, and
1866 + * a negative error number on errors.
1867 + */
1868 +static int
1869 +ext2_xattr_cmp(struct ext2_xattr_header *header1,
1870 +              struct ext2_xattr_header *header2)
1871 +{
1872 +       struct ext2_xattr_entry *entry1, *entry2;
1873 +
1874 +       entry1 = ENTRY(header1+1);
1875 +       entry2 = ENTRY(header2+1);
1876 +       while (!IS_LAST_ENTRY(entry1)) {
1877 +               if (IS_LAST_ENTRY(entry2))
1878 +                       return 1;
1879 +               if (entry1->e_hash != entry2->e_hash ||
1880 +                   entry1->e_name_len != entry2->e_name_len ||
1881 +                   entry1->e_value_size != entry2->e_value_size ||
1882 +                   memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
1883 +                       return 1;
1884 +               if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
1885 +                       return -EIO;
1886 +               if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
1887 +                          (char *)header2 + le16_to_cpu(entry2->e_value_offs),
1888 +                          le32_to_cpu(entry1->e_value_size)))
1889 +                       return 1;
1890 +
1891 +               entry1 = EXT2_XATTR_NEXT(entry1);
1892 +               entry2 = EXT2_XATTR_NEXT(entry2);
1893 +       }
1894 +       if (!IS_LAST_ENTRY(entry2))
1895 +               return 1;
1896 +       return 0;
1897 +}
1898 +
1899 +/*
1900 + * ext2_xattr_cache_find()
1901 + *
1902 + * Find an identical extended attribute block.
1903 + *
1904 + * Returns a pointer to the block found, or NULL if such a block was
1905 + * not found or an error occurred.
1906 + */
1907 +static struct buffer_head *
1908 +ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header)
1909 +{
1910 +       __u32 hash = le32_to_cpu(header->h_hash);
1911 +       struct mb_cache_entry *ce;
1912 +
1913 +       if (!header->h_hash)
1914 +               return NULL;  /* never share */
1915 +       ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
1916 +       ce = mb_cache_entry_find_first(ext2_xattr_cache, 0, inode->i_dev, hash);
1917 +       while (ce) {
1918 +               struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
1919 +
1920 +               if (!bh) {
1921 +                       ext2_error(inode->i_sb, "ext2_xattr_cache_find",
1922 +                               "inode %ld: block %ld read error",
1923 +                               inode->i_ino, ce->e_block);
1924 +               } else if (le32_to_cpu(HDR(bh)->h_refcount) >
1925 +                          EXT2_XATTR_REFCOUNT_MAX) {
1926 +                       ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
1927 +                               le32_to_cpu(HDR(bh)->h_refcount),
1928 +                               EXT2_XATTR_REFCOUNT_MAX);
1929 +               } else if (!ext2_xattr_cmp(header, HDR(bh))) {
1930 +                       ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
1931 +                       mb_cache_entry_release(ce);
1932 +                       return bh;
1933 +               }
1934 +               brelse(bh);
1935 +               ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
1936 +       }
1937 +       return NULL;
1938 +}
1939 +
1940 +/*
1941 + * ext2_xattr_cache_remove()
1942 + *
1943 + * Remove the cache entry of a block from the cache. Called when a
1944 + * block becomes invalid.
1945 + */
1946 +static void
1947 +ext2_xattr_cache_remove(struct buffer_head *bh)
1948 +{
1949 +       struct mb_cache_entry *ce;
1950 +
1951 +       ce = mb_cache_entry_get(ext2_xattr_cache, bh->b_dev, bh->b_blocknr);
1952 +       if (ce) {
1953 +               ea_bdebug(bh, "removing (%d cache entries remaining)",
1954 +                         atomic_read(&ext2_xattr_cache->c_entry_count)-1);
1955 +               mb_cache_entry_free(ce);
1956 +       } else 
1957 +               ea_bdebug(bh, "no cache entry");
1958 +}
1959 +
1960 +#define NAME_HASH_SHIFT 5
1961 +#define VALUE_HASH_SHIFT 16
1962 +
1963 +/*
1964 + * ext2_xattr_hash_entry()
1965 + *
1966 + * Compute the hash of an extended attribute.
1967 + */
1968 +static inline void ext2_xattr_hash_entry(struct ext2_xattr_header *header,
1969 +                                        struct ext2_xattr_entry *entry)
1970 +{
1971 +       __u32 hash = 0;
1972 +       char *name = entry->e_name;
1973 +       int n;
1974 +
1975 +       for (n=0; n < entry->e_name_len; n++) {
1976 +               hash = (hash << NAME_HASH_SHIFT) ^
1977 +                      (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
1978 +                      *name++;
1979 +       }
1980 +
1981 +       if (entry->e_value_block == 0 && entry->e_value_size != 0) {
1982 +               __u32 *value = (__u32 *)((char *)header +
1983 +                       le16_to_cpu(entry->e_value_offs));
1984 +               for (n = (le32_to_cpu(entry->e_value_size) +
1985 +                    EXT2_XATTR_ROUND) >> EXT2_XATTR_PAD_BITS; n; n--) {
1986 +                       hash = (hash << VALUE_HASH_SHIFT) ^
1987 +                              (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
1988 +                              le32_to_cpu(*value++);
1989 +               }
1990 +       }
1991 +       entry->e_hash = cpu_to_le32(hash);
1992 +}
1993 +
1994 +#undef NAME_HASH_SHIFT
1995 +#undef VALUE_HASH_SHIFT
1996 +
1997 +#define BLOCK_HASH_SHIFT 16
1998 +
1999 +/*
2000 + * ext2_xattr_rehash()
2001 + *
2002 + * Re-compute the extended attribute hash value after an entry has changed.
2003 + */
2004 +static void ext2_xattr_rehash(struct ext2_xattr_header *header,
2005 +                             struct ext2_xattr_entry *entry)
2006 +{
2007 +       struct ext2_xattr_entry *here;
2008 +       __u32 hash = 0;
2009 +       
2010 +       ext2_xattr_hash_entry(header, entry);
2011 +       here = ENTRY(header+1);
2012 +       while (!IS_LAST_ENTRY(here)) {
2013 +               if (!here->e_hash) {
2014 +                       /* Block is not shared if an entry's hash value == 0 */
2015 +                       hash = 0;
2016 +                       break;
2017 +               }
2018 +               hash = (hash << BLOCK_HASH_SHIFT) ^
2019 +                      (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
2020 +                      le32_to_cpu(here->e_hash);
2021 +               here = EXT2_XATTR_NEXT(here);
2022 +       }
2023 +       header->h_hash = cpu_to_le32(hash);
2024 +}
2025 +
2026 +#undef BLOCK_HASH_SHIFT
2027 +
2028 +int __init
2029 +init_ext2_xattr(void)
2030 +{
2031 +       ext2_xattr_cache = mb_cache_create("ext2_xattr", NULL,
2032 +               sizeof(struct mb_cache_entry) +
2033 +               sizeof(struct mb_cache_entry_index), 1, 61);
2034 +       if (!ext2_xattr_cache)
2035 +               return -ENOMEM;
2036 +
2037 +       return 0;
2038 +}
2039 +
2040 +void
2041 +exit_ext2_xattr(void)
2042 +{
2043 +       mb_cache_destroy(ext2_xattr_cache);
2044 +}
2045 +
2046 +#else  /* CONFIG_EXT2_FS_XATTR_SHARING */
2047 +
2048 +int __init
2049 +init_ext2_xattr(void)
2050 +{
2051 +       return 0;
2052 +}
2053 +
2054 +void
2055 +exit_ext2_xattr(void)
2056 +{
2057 +}
2058 +
2059 +#endif  /* CONFIG_EXT2_FS_XATTR_SHARING */
2060 --- /dev/null   2003-01-30 18:24:37.000000000 +0800
2061 +++ linux-2.4.20-root/fs/ext2/xattr_user.c      2003-05-07 18:08:03.000000000 +0800
2062 @@ -0,0 +1,103 @@
2063 +/*
2064 + * linux/fs/ext2/xattr_user.c
2065 + * Handler for extended user attributes.
2066 + *
2067 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
2068 + */
2069 +
2070 +#include <linux/module.h>
2071 +#include <linux/string.h>
2072 +#include <linux/fs.h>
2073 +#include <linux/ext2_fs.h>
2074 +#include <linux/ext2_xattr.h>
2075 +
2076 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
2077 +# include <linux/ext2_acl.h>
2078 +#endif
2079 +
2080 +#define XATTR_USER_PREFIX "user."
2081 +
2082 +static size_t
2083 +ext2_xattr_user_list(char *list, struct inode *inode,
2084 +                    const char *name, int name_len)
2085 +{
2086 +       const int prefix_len = sizeof(XATTR_USER_PREFIX)-1;
2087 +
2088 +       if (!test_opt(inode->i_sb, XATTR_USER))
2089 +               return 0;
2090 +
2091 +       if (list) {
2092 +               memcpy(list, XATTR_USER_PREFIX, prefix_len);
2093 +               memcpy(list+prefix_len, name, name_len);
2094 +               list[prefix_len + name_len] = '\0';
2095 +       }
2096 +       return prefix_len + name_len + 1;
2097 +}
2098 +
2099 +static int
2100 +ext2_xattr_user_get(struct inode *inode, const char *name,
2101 +                   void *buffer, size_t size)
2102 +{
2103 +       int error;
2104 +
2105 +       if (strcmp(name, "") == 0)
2106 +               return -EINVAL;
2107 +       if (!test_opt(inode->i_sb, XATTR_USER))
2108 +               return -ENOTSUP;
2109 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
2110 +       error = ext2_permission_locked(inode, MAY_READ);
2111 +#else
2112 +       error = permission(inode, MAY_READ);
2113 +#endif
2114 +       if (error)
2115 +               return error;
2116 +
2117 +       return ext2_xattr_get(inode, EXT2_XATTR_INDEX_USER, name,
2118 +                             buffer, size);
2119 +}
2120 +
2121 +static int
2122 +ext2_xattr_user_set(struct inode *inode, const char *name,
2123 +                   const void *value, size_t size, int flags)
2124 +{
2125 +       int error;
2126 +
2127 +       if (strcmp(name, "") == 0)
2128 +               return -EINVAL;
2129 +       if (!test_opt(inode->i_sb, XATTR_USER))
2130 +               return -ENOTSUP;
2131 +       if ( !S_ISREG(inode->i_mode) &&
2132 +           (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
2133 +               return -EPERM;
2134 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
2135 +       error = ext2_permission_locked(inode, MAY_WRITE);
2136 +#else
2137 +       error = permission(inode, MAY_WRITE);
2138 +#endif
2139 +       if (error)
2140 +               return error;
2141 +
2142 +       return ext2_xattr_set(inode, EXT2_XATTR_INDEX_USER, name,
2143 +                             value, size, flags);
2144 +}
2145 +
2146 +struct ext2_xattr_handler ext2_xattr_user_handler = {
2147 +       prefix: XATTR_USER_PREFIX,
2148 +       list:   ext2_xattr_user_list,
2149 +       get:    ext2_xattr_user_get,
2150 +       set:    ext2_xattr_user_set,
2151 +};
2152 +
2153 +int __init
2154 +init_ext2_xattr_user(void)
2155 +{
2156 +       return ext2_xattr_register(EXT2_XATTR_INDEX_USER,
2157 +                                  &ext2_xattr_user_handler);
2158 +}
2159 +
2160 +void
2161 +exit_ext2_xattr_user(void)
2162 +{
2163 +       ext2_xattr_unregister(EXT2_XATTR_INDEX_USER,
2164 +                             &ext2_xattr_user_handler);
2165 +}
2166 --- linux-2.4.20/fs/ext3/Makefile~linux-2.4.20-xattr-0.8.54     2003-05-05 19:01:02.000000000 +0800
2167 +++ linux-2.4.20-root/fs/ext3/Makefile  2003-05-07 18:10:33.000000000 +0800
2168 @@ -1,5 +1,5 @@
2169  #
2170 -# Makefile for the linux ext2-filesystem routines.
2171 +# Makefile for the linux ext3-filesystem routines.
2172  #
2173  # Note! Dependencies are done automagically by 'make dep', which also
2174  # removes any old dependencies. DON'T put your own dependencies here
2175 @@ -9,10 +9,14 @@
2176  
2177  O_TARGET := ext3.o
2178  
2179 -export-objs := super.o inode.o
2180 +export-objs := ext3-exports.o
2181  
2182  obj-y    := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
2183 -               ioctl.o namei.o super.o symlink.o hash.o
2184 +               ioctl.o namei.o super.o symlink.o hash.o ext3-exports.o
2185  obj-m    := $(O_TARGET)
2186  
2187 +export-objs += xattr.o
2188 +obj-$(CONFIG_EXT3_FS_XATTR) += xattr.o
2189 +obj-$(CONFIG_EXT3_FS_XATTR_USER) += xattr_user.o
2190 +
2191  include $(TOPDIR)/Rules.make
2192 --- linux-2.4.20/fs/ext3/file.c~linux-2.4.20-xattr-0.8.54       2003-05-05 19:01:02.000000000 +0800
2193 +++ linux-2.4.20-root/fs/ext3/file.c    2003-05-07 18:08:03.000000000 +0800
2194 @@ -23,6 +23,7 @@
2195  #include <linux/locks.h>
2196  #include <linux/jbd.h>
2197  #include <linux/ext3_fs.h>
2198 +#include <linux/ext3_xattr.h>
2199  #include <linux/ext3_jbd.h>
2200  #include <linux/smp_lock.h>
2201  
2202 @@ -126,5 +127,9 @@ struct file_operations ext3_file_operati
2203  struct inode_operations ext3_file_inode_operations = {
2204         truncate:       ext3_truncate,          /* BKL held */
2205         setattr:        ext3_setattr,           /* BKL held */
2206 +       setxattr:       ext3_setxattr,          /* BKL held */
2207 +       getxattr:       ext3_getxattr,          /* BKL held */
2208 +       listxattr:      ext3_listxattr,         /* BKL held */
2209 +       removexattr:    ext3_removexattr,       /* BKL held */
2210  };
2211  
2212 --- linux-2.4.20/fs/ext3/ialloc.c~linux-2.4.20-xattr-0.8.54     2002-11-29 07:53:15.000000000 +0800
2213 +++ linux-2.4.20-root/fs/ext3/ialloc.c  2003-05-07 18:08:03.000000000 +0800
2214 @@ -17,6 +17,7 @@
2215  #include <linux/jbd.h>
2216  #include <linux/ext3_fs.h>
2217  #include <linux/ext3_jbd.h>
2218 +#include <linux/ext3_xattr.h>
2219  #include <linux/stat.h>
2220  #include <linux/string.h>
2221  #include <linux/locks.h>
2222 @@ -216,6 +217,7 @@ void ext3_free_inode (handle_t *handle, 
2223          * as writing the quota to disk may need the lock as well.
2224          */
2225         DQUOT_INIT(inode);
2226 +       ext3_xattr_delete_inode(handle, inode);
2227         DQUOT_FREE_INODE(inode);
2228         DQUOT_DROP(inode);
2229  
2230 --- linux-2.4.20/fs/ext3/inode.c~linux-2.4.20-xattr-0.8.54      2002-11-29 07:53:15.000000000 +0800
2231 +++ linux-2.4.20-root/fs/ext3/inode.c   2003-05-07 18:08:03.000000000 +0800
2232 @@ -39,6 +39,18 @@
2233   */
2234  #undef SEARCH_FROM_ZERO
2235  
2236 +/*
2237 + * Test whether an inode is a fast symlink.
2238 + */
2239 +static inline int ext3_inode_is_fast_symlink(struct inode *inode)
2240 +{
2241 +       int ea_blocks = inode->u.ext3_i.i_file_acl ?
2242 +               (inode->i_sb->s_blocksize >> 9) : 0;
2243 +
2244 +       return (S_ISLNK(inode->i_mode) &&
2245 +               inode->i_blocks - ea_blocks == 0);
2246 +}
2247 +
2248  /* The ext3 forget function must perform a revoke if we are freeing data
2249   * which has been journaled.  Metadata (eg. indirect blocks) must be
2250   * revoked in all cases. 
2251 @@ -48,7 +60,7 @@
2252   * still needs to be revoked.
2253   */
2254  
2255 -static int ext3_forget(handle_t *handle, int is_metadata,
2256 +int ext3_forget(handle_t *handle, int is_metadata,
2257                        struct inode *inode, struct buffer_head *bh,
2258                        int blocknr)
2259  {
2260 @@ -164,9 +176,7 @@ void ext3_delete_inode (struct inode * i
2261  {
2262         handle_t *handle;
2263         
2264 -       if (is_bad_inode(inode) ||
2265 -           inode->i_ino == EXT3_ACL_IDX_INO ||
2266 -           inode->i_ino == EXT3_ACL_DATA_INO)
2267 +       if (is_bad_inode(inode))
2268                 goto no_delete;
2269  
2270         lock_kernel();
2271 @@ -1855,6 +1865,8 @@ void ext3_truncate(struct inode * inode)
2272         if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
2273             S_ISLNK(inode->i_mode)))
2274                 return;
2275 +       if (ext3_inode_is_fast_symlink(inode))
2276 +               return;
2277         if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2278                 return;
2279  
2280 @@ -2002,8 +2014,6 @@ int ext3_get_inode_loc (struct inode *in
2281         struct ext3_group_desc * gdp;
2282                 
2283         if ((inode->i_ino != EXT3_ROOT_INO &&
2284 -               inode->i_ino != EXT3_ACL_IDX_INO &&
2285 -               inode->i_ino != EXT3_ACL_DATA_INO &&
2286                 inode->i_ino != EXT3_JOURNAL_INO &&
2287                 inode->i_ino < EXT3_FIRST_INO(inode->i_sb)) ||
2288                 inode->i_ino > le32_to_cpu(
2289 @@ -2130,10 +2140,7 @@ void ext3_read_inode(struct inode * inod
2290  
2291         brelse (iloc.bh);
2292  
2293 -       if (inode->i_ino == EXT3_ACL_IDX_INO ||
2294 -           inode->i_ino == EXT3_ACL_DATA_INO)
2295 -               /* Nothing to do */ ;
2296 -       else if (S_ISREG(inode->i_mode)) {
2297 +       if (S_ISREG(inode->i_mode)) {
2298                 inode->i_op = &ext3_file_inode_operations;
2299                 inode->i_fop = &ext3_file_operations;
2300                 inode->i_mapping->a_ops = &ext3_aops;
2301 @@ -2141,15 +2148,17 @@ void ext3_read_inode(struct inode * inod
2302                 inode->i_op = &ext3_dir_inode_operations;
2303                 inode->i_fop = &ext3_dir_operations;
2304         } else if (S_ISLNK(inode->i_mode)) {
2305 -               if (!inode->i_blocks)
2306 +               if (ext3_inode_is_fast_symlink(inode))
2307                         inode->i_op = &ext3_fast_symlink_inode_operations;
2308                 else {
2309 -                       inode->i_op = &page_symlink_inode_operations;
2310 +                       inode->i_op = &ext3_symlink_inode_operations;
2311                         inode->i_mapping->a_ops = &ext3_aops;
2312                 }
2313 -       } else 
2314 +       } else {
2315 +               inode->i_op = &ext3_special_inode_operations;
2316                 init_special_inode(inode, inode->i_mode,
2317                                    le32_to_cpu(iloc.raw_inode->i_block[0]));
2318 +       }
2319         ext3_set_inode_flags(inode);
2320         return;
2321         
2322 --- linux-2.4.20/fs/ext3/namei.c~linux-2.4.20-xattr-0.8.54      2003-05-05 19:01:05.000000000 +0800
2323 +++ linux-2.4.20-root/fs/ext3/namei.c   2003-05-07 18:08:03.000000000 +0800
2324 @@ -29,6 +29,7 @@
2325  #include <linux/sched.h>
2326  #include <linux/ext3_fs.h>
2327  #include <linux/ext3_jbd.h>
2328 +#include <linux/ext3_xattr.h>
2329  #include <linux/fcntl.h>
2330  #include <linux/stat.h>
2331  #include <linux/string.h>
2332 @@ -1611,7 +1612,7 @@ static int ext3_mkdir(struct inode * dir
2333         if (IS_SYNC(dir))
2334                 handle->h_sync = 1;
2335  
2336 -       inode = ext3_new_inode (handle, dir, S_IFDIR);
2337 +       inode = ext3_new_inode (handle, dir, S_IFDIR | mode);
2338         err = PTR_ERR(inode);
2339         if (IS_ERR(inode))
2340                 goto out_stop;
2341 @@ -1619,7 +1620,6 @@ static int ext3_mkdir(struct inode * dir
2342         inode->i_op = &ext3_dir_inode_operations;
2343         inode->i_fop = &ext3_dir_operations;
2344         inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
2345 -       inode->i_blocks = 0;    
2346         dir_block = ext3_bread (handle, inode, 0, 1, &err);
2347         if (!dir_block) {
2348                 inode->i_nlink--; /* is this nlink == 0? */
2349 @@ -1646,9 +1646,6 @@ static int ext3_mkdir(struct inode * dir
2350         BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata");
2351         ext3_journal_dirty_metadata(handle, dir_block);
2352         brelse (dir_block);
2353 -       inode->i_mode = S_IFDIR | mode;
2354 -       if (dir->i_mode & S_ISGID)
2355 -               inode->i_mode |= S_ISGID;
2356         ext3_mark_inode_dirty(handle, inode);
2357         err = ext3_add_entry (handle, dentry, inode);
2358         if (err) {
2359 @@ -2017,7 +2014,7 @@ static int ext3_symlink (struct inode * 
2360                 goto out_stop;
2361  
2362         if (l > sizeof (EXT3_I(inode)->i_data)) {
2363 -               inode->i_op = &page_symlink_inode_operations;
2364 +               inode->i_op = &ext3_symlink_inode_operations;
2365                 inode->i_mapping->a_ops = &ext3_aops;
2366                 /*
2367                  * block_symlink() calls back into ext3_prepare/commit_write.
2368 @@ -2244,4 +2241,16 @@ struct inode_operations ext3_dir_inode_o
2369         rmdir:          ext3_rmdir,             /* BKL held */
2370         mknod:          ext3_mknod,             /* BKL held */
2371         rename:         ext3_rename,            /* BKL held */
2372 +       setxattr:       ext3_setxattr,          /* BKL held */
2373 +       getxattr:       ext3_getxattr,          /* BKL held */
2374 +       listxattr:      ext3_listxattr,         /* BKL held */
2375 +       removexattr:    ext3_removexattr,       /* BKL held */
2376  };
2377 +
2378 +struct inode_operations ext3_special_inode_operations = {
2379 +       setxattr:       ext3_setxattr,          /* BKL held */
2380 +       getxattr:       ext3_getxattr,          /* BKL held */
2381 +       listxattr:      ext3_listxattr,         /* BKL held */
2382 +       removexattr:    ext3_removexattr,       /* BKL held */
2383 +};
2384 +
2385 --- linux-2.4.20/fs/ext3/super.c~linux-2.4.20-xattr-0.8.54      2003-05-05 19:01:02.000000000 +0800
2386 +++ linux-2.4.20-root/fs/ext3/super.c   2003-05-07 18:08:39.000000000 +0800
2387 @@ -24,6 +24,7 @@
2388  #include <linux/jbd.h>
2389  #include <linux/ext3_fs.h>
2390  #include <linux/ext3_jbd.h>
2391 +#include <linux/ext3_xattr.h>
2392  #include <linux/slab.h>
2393  #include <linux/init.h>
2394  #include <linux/locks.h>
2395 @@ -404,6 +405,7 @@ void ext3_put_super (struct super_block 
2396         kdev_t j_dev = sbi->s_journal->j_dev;
2397         int i;
2398  
2399 +       ext3_xattr_put_super(sb);
2400         journal_destroy(sbi->s_journal);
2401         if (!(sb->s_flags & MS_RDONLY)) {
2402                 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
2403 @@ -499,6 +501,7 @@ static int parse_options (char * options
2404                           int is_remount)
2405  {
2406         unsigned long *mount_options = &sbi->s_mount_opt;
2407 +       
2408         uid_t *resuid = &sbi->s_resuid;
2409         gid_t *resgid = &sbi->s_resgid;
2410         char * this_char;
2411 @@ -511,6 +514,13 @@ static int parse_options (char * options
2412              this_char = strtok (NULL, ",")) {
2413                 if ((value = strchr (this_char, '=')) != NULL)
2414                         *value++ = 0;
2415 +#ifdef CONFIG_EXT3_FS_XATTR_USER
2416 +               if (!strcmp (this_char, "user_xattr"))
2417 +                       set_opt (*mount_options, XATTR_USER);
2418 +               else if (!strcmp (this_char, "nouser_xattr"))
2419 +                       clear_opt (*mount_options, XATTR_USER);
2420 +               else
2421 +#endif
2422                 if (!strcmp (this_char, "bsddf"))
2423                         clear_opt (*mount_options, MINIX_DF);
2424                 else if (!strcmp (this_char, "nouid32")) {
2425 @@ -928,6 +938,12 @@ struct super_block * ext3_read_super (st
2426         sbi->s_mount_opt = 0;
2427         sbi->s_resuid = EXT3_DEF_RESUID;
2428         sbi->s_resgid = EXT3_DEF_RESGID;
2429 +
2430 +       /* Default extended attribute flags */
2431 +#ifdef CONFIG_EXT3_FS_XATTR_USER
2432 +       /* set_opt(sbi->s_mount_opt, XATTR_USER); */
2433 +#endif
2434 +
2435         if (!parse_options ((char *) data, &sb_block, sbi, &journal_inum, 0)) {
2436                 sb->s_dev = 0;
2437                 goto out_fail;
2438 @@ -1767,17 +1783,29 @@ static DECLARE_FSTYPE_DEV(ext3_fs_type, 
2439  
2440  static int __init init_ext3_fs(void)
2441  {
2442 -        return register_filesystem(&ext3_fs_type);
2443 +       int error = init_ext3_xattr();
2444 +       if (error)
2445 +               return error;
2446 +       error = init_ext3_xattr_user();
2447 +       if (error)
2448 +               goto fail;
2449 +       error = register_filesystem(&ext3_fs_type);
2450 +       if (!error)
2451 +               return 0;
2452 +       
2453 +       exit_ext3_xattr_user();
2454 +fail:
2455 +       exit_ext3_xattr();
2456 +       return error;
2457  }
2458  
2459  static void __exit exit_ext3_fs(void)
2460  {
2461         unregister_filesystem(&ext3_fs_type);
2462 +       exit_ext3_xattr_user();
2463 +       exit_ext3_xattr();
2464  }
2465  
2466 -EXPORT_SYMBOL(ext3_force_commit);
2467 -EXPORT_SYMBOL(ext3_bread);
2468 -
2469  MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
2470  MODULE_DESCRIPTION("Second Extended Filesystem with journaling extensions");
2471  MODULE_LICENSE("GPL");
2472 --- linux-2.4.20/fs/ext3/symlink.c~linux-2.4.20-xattr-0.8.54    2001-11-10 06:25:04.000000000 +0800
2473 +++ linux-2.4.20-root/fs/ext3/symlink.c 2003-05-07 18:08:03.000000000 +0800
2474 @@ -20,6 +20,7 @@
2475  #include <linux/fs.h>
2476  #include <linux/jbd.h>
2477  #include <linux/ext3_fs.h>
2478 +#include <linux/ext3_xattr.h>
2479  
2480  static int ext3_readlink(struct dentry *dentry, char *buffer, int buflen)
2481  {
2482 @@ -33,7 +34,20 @@ static int ext3_follow_link(struct dentr
2483         return vfs_follow_link(nd, s);
2484  }
2485  
2486 +struct inode_operations ext3_symlink_inode_operations = {
2487 +       readlink:       page_readlink,          /* BKL not held.  Don't need */
2488 +       follow_link:    page_follow_link,       /* BKL not held.  Don't need */
2489 +       setxattr:       ext3_setxattr,          /* BKL held */
2490 +       getxattr:       ext3_getxattr,          /* BKL held */
2491 +       listxattr:      ext3_listxattr,         /* BKL held */
2492 +       removexattr:    ext3_removexattr,       /* BKL held */
2493 +};
2494 +
2495  struct inode_operations ext3_fast_symlink_inode_operations = {
2496         readlink:       ext3_readlink,          /* BKL not held.  Don't need */
2497         follow_link:    ext3_follow_link,       /* BKL not held.  Don't need */
2498 +       setxattr:       ext3_setxattr,          /* BKL held */
2499 +       getxattr:       ext3_getxattr,          /* BKL held */
2500 +       listxattr:      ext3_listxattr,         /* BKL held */
2501 +       removexattr:    ext3_removexattr,       /* BKL held */
2502  };
2503 --- /dev/null   2003-01-30 18:24:37.000000000 +0800
2504 +++ linux-2.4.20-root/fs/ext3/xattr.c   2003-05-07 18:09:23.000000000 +0800
2505 @@ -0,0 +1,1225 @@
2506 +/*
2507 + * linux/fs/ext3/xattr.c
2508 + *
2509 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
2510 + *
2511 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
2512 + * Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>.
2513 + * Extended attributes for symlinks and special files added per
2514 + *  suggestion of Luka Renko <luka.renko@hermes.si>.
2515 + */
2516 +
2517 +/*
2518 + * Extended attributes are stored on disk blocks allocated outside of
2519 + * any inode. The i_file_acl field is then made to point to this allocated
2520 + * block. If all extended attributes of an inode are identical, these
2521 + * inodes may share the same extended attribute block. Such situations
2522 + * are automatically detected by keeping a cache of recent attribute block
2523 + * numbers and hashes over the block's contents in memory.
2524 + *
2525 + *
2526 + * Extended attribute block layout:
2527 + *
2528 + *   +------------------+
2529 + *   | header           |
2530 + *   | entry 1          | |
2531 + *   | entry 2          | | growing downwards
2532 + *   | entry 3          | v
2533 + *   | four null bytes  |
2534 + *   | . . .            |
2535 + *   | value 1          | ^
2536 + *   | value 3          | | growing upwards
2537 + *   | value 2          | |
2538 + *   +------------------+
2539 + *
2540 + * The block header is followed by multiple entry descriptors. These entry
2541 + * descriptors are variable in size, and alligned to EXT3_XATTR_PAD
2542 + * byte boundaries. The entry descriptors are sorted by attribute name,
2543 + * so that two extended attribute blocks can be compared efficiently.
2544 + *
2545 + * Attribute values are aligned to the end of the block, stored in
2546 + * no specific order. They are also padded to EXT3_XATTR_PAD byte
2547 + * boundaries. No additional gaps are left between them.
2548 + *
2549 + * Locking strategy
2550 + * ----------------
2551 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
2552 + * the xattr inode operations are called, so we are guaranteed that only one
2553 + * processes accesses extended attributes of an inode at any time.
2554 + *
2555 + * For writing we also grab the ext3_xattr_sem semaphore. This ensures that
2556 + * only a single process is modifying an extended attribute block, even
2557 + * if the block is shared among inodes.
2558 + *
2559 + * Note for porting to 2.5
2560 + * -----------------------
2561 + * The BKL will no longer be held in the xattr inode operations.
2562 + */
2563 +
2564 +#include <linux/module.h>
2565 +#include <linux/fs.h>
2566 +#include <linux/locks.h>
2567 +#include <linux/slab.h>
2568 +#include <linux/ext3_jbd.h>
2569 +#include <linux/ext3_fs.h>
2570 +#include <linux/ext3_xattr.h>
2571 +#include <linux/mbcache.h>
2572 +#include <linux/quotaops.h>
2573 +#include <asm/semaphore.h>
2574 +#include <linux/compatmac.h>
2575 +
2576 +#define EXT3_EA_USER "user."
2577 +
2578 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
2579 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
2580 +#endif
2581 +
2582 +#define HDR(bh) ((struct ext3_xattr_header *)((bh)->b_data))
2583 +#define ENTRY(ptr) ((struct ext3_xattr_entry *)(ptr))
2584 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
2585 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
2586 +
2587 +#ifdef EXT3_XATTR_DEBUG
2588 +# define ea_idebug(inode, f...) do { \
2589 +               printk(KERN_DEBUG "inode %s:%ld: ", \
2590 +                       kdevname(inode->i_dev), inode->i_ino); \
2591 +               printk(f); \
2592 +               printk("\n"); \
2593 +       } while (0)
2594 +# define ea_bdebug(bh, f...) do { \
2595 +               printk(KERN_DEBUG "block %s:%ld: ", \
2596 +                       kdevname(bh->b_dev), bh->b_blocknr); \
2597 +               printk(f); \
2598 +               printk("\n"); \
2599 +       } while (0)
2600 +#else
2601 +# define ea_idebug(f...)
2602 +# define ea_bdebug(f...)
2603 +#endif
2604 +
2605 +static int ext3_xattr_set2(handle_t *, struct inode *, struct buffer_head *,
2606 +                          struct ext3_xattr_header *);
2607 +
2608 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
2609 +
2610 +static int ext3_xattr_cache_insert(struct buffer_head *);
2611 +static struct buffer_head *ext3_xattr_cache_find(struct inode *,
2612 +                                                struct ext3_xattr_header *);
2613 +static void ext3_xattr_cache_remove(struct buffer_head *);
2614 +static void ext3_xattr_rehash(struct ext3_xattr_header *,
2615 +                             struct ext3_xattr_entry *);
2616 +
2617 +static struct mb_cache *ext3_xattr_cache;
2618 +
2619 +#else
2620 +# define ext3_xattr_cache_insert(bh) 0
2621 +# define ext3_xattr_cache_find(inode, header) NULL
2622 +# define ext3_xattr_cache_remove(bh) while(0) {}
2623 +# define ext3_xattr_rehash(header, entry) while(0) {}
2624 +#endif
2625 +
2626 +/*
2627 + * If a file system does not share extended attributes among inodes,
2628 + * we should not need the ext3_xattr_sem semaphore. However, the
2629 + * filesystem may still contain shared blocks, so we always take
2630 + * the lock.
2631 + */
2632 +
2633 +DECLARE_MUTEX(ext3_xattr_sem);
2634 +
2635 +static inline int
2636 +ext3_xattr_new_block(handle_t *handle, struct inode *inode,
2637 +                    int * errp, int force)
2638 +{
2639 +       struct super_block *sb = inode->i_sb;
2640 +       int goal = le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block) +
2641 +               EXT3_I(inode)->i_block_group * EXT3_BLOCKS_PER_GROUP(sb);
2642 +
2643 +       /* How can we enforce the allocation? */
2644 +       int block = ext3_new_block(handle, inode, goal, 0, 0, errp);
2645 +#ifdef OLD_QUOTAS
2646 +       if (!*errp)
2647 +               inode->i_blocks += inode->i_sb->s_blocksize >> 9;
2648 +#endif
2649 +       return block;
2650 +}
2651 +
2652 +static inline int
2653 +ext3_xattr_quota_alloc(struct inode *inode, int force)
2654 +{
2655 +       /* How can we enforce the allocation? */
2656 +#ifdef OLD_QUOTAS
2657 +       int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
2658 +       if (!error)
2659 +               inode->i_blocks += inode->i_sb->s_blocksize >> 9;
2660 +#else
2661 +       int error = DQUOT_ALLOC_BLOCK(inode, 1);
2662 +#endif
2663 +       return error;
2664 +}
2665 +
2666 +#ifdef OLD_QUOTAS
2667 +
2668 +static inline void
2669 +ext3_xattr_quota_free(struct inode *inode)
2670 +{
2671 +       DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
2672 +       inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
2673 +}
2674 +
2675 +static inline void
2676 +ext3_xattr_free_block(handle_t *handle, struct inode * inode,
2677 +                     unsigned long block)
2678 +{
2679 +       ext3_free_blocks(handle, inode, block, 1);
2680 +       inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
2681 +}
2682 +
2683 +#else
2684 +# define ext3_xattr_quota_free(inode) \
2685 +       DQUOT_FREE_BLOCK(inode, 1)
2686 +# define ext3_xattr_free_block(handle, inode, block) \
2687 +       ext3_free_blocks(handle, inode, block, 1)
2688 +#endif
2689 +
2690 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
2691 +
2692 +static inline struct buffer_head *
2693 +sb_bread(struct super_block *sb, int block)
2694 +{
2695 +       return bread(sb->s_dev, block, sb->s_blocksize);
2696 +}
2697 +
2698 +static inline struct buffer_head *
2699 +sb_getblk(struct super_block *sb, int block)
2700 +{
2701 +       return getblk(sb->s_dev, block, sb->s_blocksize);
2702 +}
2703 +
2704 +#endif
2705 +
2706 +struct ext3_xattr_handler *ext3_xattr_handlers[EXT3_XATTR_INDEX_MAX];
2707 +rwlock_t ext3_handler_lock = RW_LOCK_UNLOCKED;
2708 +
2709 +int
2710 +ext3_xattr_register(int name_index, struct ext3_xattr_handler *handler)
2711 +{
2712 +       int error = -EINVAL;
2713 +
2714 +       if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
2715 +               write_lock(&ext3_handler_lock);
2716 +               if (!ext3_xattr_handlers[name_index-1]) {
2717 +                       ext3_xattr_handlers[name_index-1] = handler;
2718 +                       error = 0;
2719 +               }
2720 +               write_unlock(&ext3_handler_lock);
2721 +       }
2722 +       return error;
2723 +}
2724 +
2725 +void
2726 +ext3_xattr_unregister(int name_index, struct ext3_xattr_handler *handler)
2727 +{
2728 +       if (name_index > 0 || name_index <= EXT3_XATTR_INDEX_MAX) {
2729 +               write_lock(&ext3_handler_lock);
2730 +               ext3_xattr_handlers[name_index-1] = NULL;
2731 +               write_unlock(&ext3_handler_lock);
2732 +       }
2733 +}
2734 +
2735 +static inline const char *
2736 +strcmp_prefix(const char *a, const char *a_prefix)
2737 +{
2738 +       while (*a_prefix && *a == *a_prefix) {
2739 +               a++;
2740 +               a_prefix++;
2741 +       }
2742 +       return *a_prefix ? NULL : a;
2743 +}
2744 +
2745 +/*
2746 + * Decode the extended attribute name, and translate it into
2747 + * the name_index and name suffix.
2748 + */
2749 +static inline struct ext3_xattr_handler *
2750 +ext3_xattr_resolve_name(const char **name)
2751 +{
2752 +       struct ext3_xattr_handler *handler = NULL;
2753 +       int i;
2754 +
2755 +       if (!*name)
2756 +               return NULL;
2757 +       read_lock(&ext3_handler_lock);
2758 +       for (i=0; i<EXT3_XATTR_INDEX_MAX; i++) {
2759 +               if (ext3_xattr_handlers[i]) {
2760 +                       const char *n = strcmp_prefix(*name,
2761 +                               ext3_xattr_handlers[i]->prefix);
2762 +                       if (n) {
2763 +                               handler = ext3_xattr_handlers[i];
2764 +                               *name = n;
2765 +                               break;
2766 +                       }
2767 +               }
2768 +       }
2769 +       read_unlock(&ext3_handler_lock);
2770 +       return handler;
2771 +}
2772 +
2773 +static inline struct ext3_xattr_handler *
2774 +ext3_xattr_handler(int name_index)
2775 +{
2776 +       struct ext3_xattr_handler *handler = NULL;
2777 +       if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
2778 +               read_lock(&ext3_handler_lock);
2779 +               handler = ext3_xattr_handlers[name_index-1];
2780 +               read_unlock(&ext3_handler_lock);
2781 +       }
2782 +       return handler;
2783 +}
2784 +
2785 +/*
2786 + * Inode operation getxattr()
2787 + *
2788 + * dentry->d_inode->i_sem down
2789 + * BKL held [before 2.5.x]
2790 + */
2791 +ssize_t
2792 +ext3_getxattr(struct dentry *dentry, const char *name,
2793 +             void *buffer, size_t size)
2794 +{
2795 +       struct ext3_xattr_handler *handler;
2796 +       struct inode *inode = dentry->d_inode;
2797 +
2798 +       handler = ext3_xattr_resolve_name(&name);
2799 +       if (!handler)
2800 +               return -ENOTSUP;
2801 +       return handler->get(inode, name, buffer, size);
2802 +}
2803 +
2804 +/*
2805 + * Inode operation listxattr()
2806 + *
2807 + * dentry->d_inode->i_sem down
2808 + * BKL held [before 2.5.x]
2809 + */
2810 +ssize_t
2811 +ext3_listxattr(struct dentry *dentry, char *buffer, size_t size)
2812 +{
2813 +       return ext3_xattr_list(dentry->d_inode, buffer, size);
2814 +}
2815 +
2816 +/*
2817 + * Inode operation setxattr()
2818 + *
2819 + * dentry->d_inode->i_sem down
2820 + * BKL held [before 2.5.x]
2821 + */
2822 +int
2823 +ext3_setxattr(struct dentry *dentry, const char *name,
2824 +             const void *value, size_t size, int flags)
2825 +{
2826 +       struct ext3_xattr_handler *handler;
2827 +       struct inode *inode = dentry->d_inode;
2828 +
2829 +       if (size == 0)
2830 +               value = "";  /* empty EA, do not remove */
2831 +       handler = ext3_xattr_resolve_name(&name);
2832 +       if (!handler)
2833 +               return -ENOTSUP;
2834 +       return handler->set(inode, name, value, size, flags);
2835 +}
2836 +
2837 +/*
2838 + * Inode operation removexattr()
2839 + *
2840 + * dentry->d_inode->i_sem down
2841 + * BKL held [before 2.5.x]
2842 + */
2843 +int
2844 +ext3_removexattr(struct dentry *dentry, const char *name)
2845 +{
2846 +       struct ext3_xattr_handler *handler;
2847 +       struct inode *inode = dentry->d_inode;
2848 +
2849 +       handler = ext3_xattr_resolve_name(&name);
2850 +       if (!handler)
2851 +               return -ENOTSUP;
2852 +       return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
2853 +}
2854 +
2855 +/*
2856 + * ext3_xattr_get()
2857 + *
2858 + * Copy an extended attribute into the buffer
2859 + * provided, or compute the buffer size required.
2860 + * Buffer is NULL to compute the size of the buffer required.
2861 + *
2862 + * Returns a negative error number on failure, or the number of bytes
2863 + * used / required on success.
2864 + */
2865 +int
2866 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
2867 +              void *buffer, size_t buffer_size)
2868 +{
2869 +       struct buffer_head *bh = NULL;
2870 +       struct ext3_xattr_entry *entry;
2871 +       unsigned int block, size;
2872 +       char *end;
2873 +       int name_len, error;
2874 +
2875 +       ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
2876 +                 name_index, name, buffer, (long)buffer_size);
2877 +
2878 +       if (name == NULL)
2879 +               return -EINVAL;
2880 +       if (!EXT3_I(inode)->i_file_acl)
2881 +               return -ENOATTR;
2882 +       block = EXT3_I(inode)->i_file_acl;
2883 +       ea_idebug(inode, "reading block %d", block);
2884 +       bh = sb_bread(inode->i_sb, block);
2885 +       if (!bh)
2886 +               return -EIO;
2887 +       ea_bdebug(bh, "b_count=%d, refcount=%d",
2888 +               atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
2889 +       end = bh->b_data + bh->b_size;
2890 +       if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
2891 +           HDR(bh)->h_blocks != cpu_to_le32(1)) {
2892 +bad_block:     ext3_error(inode->i_sb, "ext3_xattr_get",
2893 +                       "inode %ld: bad block %d", inode->i_ino, block);
2894 +               error = -EIO;
2895 +               goto cleanup;
2896 +       }
2897 +       /* find named attribute */
2898 +       name_len = strlen(name);
2899 +
2900 +       error = -ERANGE;
2901 +       if (name_len > 255)
2902 +               goto cleanup;
2903 +       entry = FIRST_ENTRY(bh);
2904 +       while (!IS_LAST_ENTRY(entry)) {
2905 +               struct ext3_xattr_entry *next =
2906 +                       EXT3_XATTR_NEXT(entry);
2907 +               if ((char *)next >= end)
2908 +                       goto bad_block;
2909 +               if (name_index == entry->e_name_index &&
2910 +                   name_len == entry->e_name_len &&
2911 +                   memcmp(name, entry->e_name, name_len) == 0)
2912 +                       goto found;
2913 +               entry = next;
2914 +       }
2915 +       /* Check the remaining name entries */
2916 +       while (!IS_LAST_ENTRY(entry)) {
2917 +               struct ext3_xattr_entry *next =
2918 +                       EXT3_XATTR_NEXT(entry);
2919 +               if ((char *)next >= end)
2920 +                       goto bad_block;
2921 +               entry = next;
2922 +       }
2923 +       if (ext3_xattr_cache_insert(bh))
2924 +               ea_idebug(inode, "cache insert failed");
2925 +       error = -ENOATTR;
2926 +       goto cleanup;
2927 +found:
2928 +       /* check the buffer size */
2929 +       if (entry->e_value_block != 0)
2930 +               goto bad_block;
2931 +       size = le32_to_cpu(entry->e_value_size);
2932 +       if (size > inode->i_sb->s_blocksize ||
2933 +           le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
2934 +               goto bad_block;
2935 +
2936 +       if (ext3_xattr_cache_insert(bh))
2937 +               ea_idebug(inode, "cache insert failed");
2938 +       if (buffer) {
2939 +               error = -ERANGE;
2940 +               if (size > buffer_size)
2941 +                       goto cleanup;
2942 +               /* return value of attribute */
2943 +               memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
2944 +                       size);
2945 +       }
2946 +       error = size;
2947 +
2948 +cleanup:
2949 +       brelse(bh);
2950 +
2951 +       return error;
2952 +}
2953 +
2954 +/*
2955 + * ext3_xattr_list()
2956 + *
2957 + * Copy a list of attribute names into the buffer
2958 + * provided, or compute the buffer size required.
2959 + * Buffer is NULL to compute the size of the buffer required.
2960 + *
2961 + * Returns a negative error number on failure, or the number of bytes
2962 + * used / required on success.
2963 + */
2964 +int
2965 +ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
2966 +{
2967 +       struct buffer_head *bh = NULL;
2968 +       struct ext3_xattr_entry *entry;
2969 +       unsigned int block, size = 0;
2970 +       char *buf, *end;
2971 +       int error;
2972 +
2973 +       ea_idebug(inode, "buffer=%p, buffer_size=%ld",
2974 +                 buffer, (long)buffer_size);
2975 +
2976 +       if (!EXT3_I(inode)->i_file_acl)
2977 +               return 0;
2978 +       block = EXT3_I(inode)->i_file_acl;
2979 +       ea_idebug(inode, "reading block %d", block);
2980 +       bh = sb_bread(inode->i_sb, block);
2981 +       if (!bh)
2982 +               return -EIO;
2983 +       ea_bdebug(bh, "b_count=%d, refcount=%d",
2984 +               atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
2985 +       end = bh->b_data + bh->b_size;
2986 +       if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
2987 +           HDR(bh)->h_blocks != cpu_to_le32(1)) {
2988 +bad_block:     ext3_error(inode->i_sb, "ext3_xattr_list",
2989 +                       "inode %ld: bad block %d", inode->i_ino, block);
2990 +               error = -EIO;
2991 +               goto cleanup;
2992 +       }
2993 +       /* compute the size required for the list of attribute names */
2994 +       for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
2995 +            entry = EXT3_XATTR_NEXT(entry)) {
2996 +               struct ext3_xattr_handler *handler;
2997 +               struct ext3_xattr_entry *next =
2998 +                       EXT3_XATTR_NEXT(entry);
2999 +               if ((char *)next >= end)
3000 +                       goto bad_block;
3001 +
3002 +               handler = ext3_xattr_handler(entry->e_name_index);
3003 +               if (handler)
3004 +                       size += handler->list(NULL, inode, entry->e_name,
3005 +                                             entry->e_name_len);
3006 +       }
3007 +
3008 +       if (ext3_xattr_cache_insert(bh))
3009 +               ea_idebug(inode, "cache insert failed");
3010 +       if (!buffer) {
3011 +               error = size;
3012 +               goto cleanup;
3013 +       } else {
3014 +               error = -ERANGE;
3015 +               if (size > buffer_size)
3016 +                       goto cleanup;
3017 +       }
3018 +
3019 +       /* list the attribute names */
3020 +       buf = buffer;
3021 +       for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
3022 +            entry = EXT3_XATTR_NEXT(entry)) {
3023 +               struct ext3_xattr_handler *handler;
3024 +
3025 +               handler = ext3_xattr_handler(entry->e_name_index);
3026 +               if (handler)
3027 +                       buf += handler->list(buf, inode, entry->e_name,
3028 +                                            entry->e_name_len);
3029 +       }
3030 +       error = size;
3031 +
3032 +cleanup:
3033 +       brelse(bh);
3034 +
3035 +       return error;
3036 +}
3037 +
3038 +/*
3039 + * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is
3040 + * not set, set it.
3041 + */
3042 +static void ext3_xattr_update_super_block(handle_t *handle,
3043 +                                         struct super_block *sb)
3044 +{
3045 +       if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR))
3046 +               return;
3047 +
3048 +       lock_super(sb);
3049 +       ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh);
3050 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
3051 +       EXT3_SB(sb)->s_feature_compat |= EXT3_FEATURE_COMPAT_EXT_ATTR;
3052 +#endif
3053 +       EXT3_SB(sb)->s_es->s_feature_compat |=
3054 +               cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR);
3055 +       sb->s_dirt = 1;
3056 +       ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
3057 +       unlock_super(sb);
3058 +}
3059 +
3060 +/*
3061 + * ext3_xattr_set()
3062 + *
3063 + * Create, replace or remove an extended attribute for this inode. Buffer
3064 + * is NULL to remove an existing extended attribute, and non-NULL to
3065 + * either replace an existing extended attribute, or create a new extended
3066 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
3067 + * specify that an extended attribute must exist and must not exist
3068 + * previous to the call, respectively.
3069 + *
3070 + * Returns 0, or a negative error number on failure.
3071 + */
3072 +int
3073 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
3074 +              const char *name, const void *value, size_t value_len, int flags)
3075 +{
3076 +       struct super_block *sb = inode->i_sb;
3077 +       struct buffer_head *bh = NULL;
3078 +       struct ext3_xattr_header *header = NULL;
3079 +       struct ext3_xattr_entry *here, *last;
3080 +       unsigned int name_len;
3081 +       int block = EXT3_I(inode)->i_file_acl;
3082 +       int min_offs = sb->s_blocksize, not_found = 1, free, error;
3083 +       char *end;
3084 +       
3085 +       /*
3086 +        * header -- Points either into bh, or to a temporarily
3087 +        *           allocated buffer.
3088 +        * here -- The named entry found, or the place for inserting, within
3089 +        *         the block pointed to by header.
3090 +        * last -- Points right after the last named entry within the block
3091 +        *         pointed to by header.
3092 +        * min_offs -- The offset of the first value (values are aligned
3093 +        *             towards the end of the block).
3094 +        * end -- Points right after the block pointed to by header.
3095 +        */
3096 +       
3097 +       ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
3098 +                 name_index, name, value, (long)value_len);
3099 +
3100 +       if (IS_RDONLY(inode))
3101 +               return -EROFS;
3102 +       if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
3103 +               return -EPERM;
3104 +       if (value == NULL)
3105 +               value_len = 0;
3106 +       if (name == NULL)
3107 +               return -EINVAL;
3108 +       name_len = strlen(name);
3109 +       if (name_len > 255 || value_len > sb->s_blocksize)
3110 +               return -ERANGE;
3111 +       down(&ext3_xattr_sem);
3112 +
3113 +       if (block) {
3114 +               /* The inode already has an extended attribute block. */
3115 +               bh = sb_bread(sb, block);
3116 +               error = -EIO;
3117 +               if (!bh)
3118 +                       goto cleanup;
3119 +               ea_bdebug(bh, "b_count=%d, refcount=%d",
3120 +                       atomic_read(&(bh->b_count)),
3121 +                       le32_to_cpu(HDR(bh)->h_refcount));
3122 +               header = HDR(bh);
3123 +               end = bh->b_data + bh->b_size;
3124 +               if (header->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
3125 +                   header->h_blocks != cpu_to_le32(1)) {
3126 +bad_block:             ext3_error(sb, "ext3_xattr_set",
3127 +                               "inode %ld: bad block %d", inode->i_ino, block);
3128 +                       error = -EIO;
3129 +                       goto cleanup;
3130 +               }
3131 +               /* Find the named attribute. */
3132 +               here = FIRST_ENTRY(bh);
3133 +               while (!IS_LAST_ENTRY(here)) {
3134 +                       struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(here);
3135 +                       if ((char *)next >= end)
3136 +                               goto bad_block;
3137 +                       if (!here->e_value_block && here->e_value_size) {
3138 +                               int offs = le16_to_cpu(here->e_value_offs);
3139 +                               if (offs < min_offs)
3140 +                                       min_offs = offs;
3141 +                       }
3142 +                       not_found = name_index - here->e_name_index;
3143 +                       if (!not_found)
3144 +                               not_found = name_len - here->e_name_len;
3145 +                       if (!not_found)
3146 +                               not_found = memcmp(name, here->e_name,name_len);
3147 +                       if (not_found <= 0)
3148 +                               break;
3149 +                       here = next;
3150 +               }
3151 +               last = here;
3152 +               /* We still need to compute min_offs and last. */
3153 +               while (!IS_LAST_ENTRY(last)) {
3154 +                       struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
3155 +                       if ((char *)next >= end)
3156 +                               goto bad_block;
3157 +                       if (!last->e_value_block && last->e_value_size) {
3158 +                               int offs = le16_to_cpu(last->e_value_offs);
3159 +                               if (offs < min_offs)
3160 +                                       min_offs = offs;
3161 +                       }
3162 +                       last = next;
3163 +               }
3164 +
3165 +               /* Check whether we have enough space left. */
3166 +               free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
3167 +       } else {
3168 +               /* We will use a new extended attribute block. */
3169 +               free = sb->s_blocksize -
3170 +                       sizeof(struct ext3_xattr_header) - sizeof(__u32);
3171 +               here = last = NULL;  /* avoid gcc uninitialized warning. */
3172 +       }
3173 +
3174 +       if (not_found) {
3175 +               /* Request to remove a nonexistent attribute? */
3176 +               error = -ENOATTR;
3177 +               if (flags & XATTR_REPLACE)
3178 +                       goto cleanup;
3179 +               error = 0;
3180 +               if (value == NULL)
3181 +                       goto cleanup;
3182 +               else
3183 +                       free -= EXT3_XATTR_LEN(name_len);
3184 +       } else {
3185 +               /* Request to create an existing attribute? */
3186 +               error = -EEXIST;
3187 +               if (flags & XATTR_CREATE)
3188 +                       goto cleanup;
3189 +               if (!here->e_value_block && here->e_value_size) {
3190 +                       unsigned int size = le32_to_cpu(here->e_value_size);
3191 +
3192 +                       if (le16_to_cpu(here->e_value_offs) + size > 
3193 +                           sb->s_blocksize || size > sb->s_blocksize)
3194 +                               goto bad_block;
3195 +                       free += EXT3_XATTR_SIZE(size);
3196 +               }
3197 +       }
3198 +       free -= EXT3_XATTR_SIZE(value_len);
3199 +       error = -ENOSPC;
3200 +       if (free < 0)
3201 +               goto cleanup;
3202 +
3203 +       /* Here we know that we can set the new attribute. */
3204 +
3205 +       if (header) {
3206 +               if (header->h_refcount == cpu_to_le32(1)) {
3207 +                       ea_bdebug(bh, "modifying in-place");
3208 +                       ext3_xattr_cache_remove(bh);
3209 +                       error = ext3_journal_get_write_access(handle, bh);
3210 +                       if (error)
3211 +                               goto cleanup;
3212 +               } else {
3213 +                       int offset;
3214 +
3215 +                       ea_bdebug(bh, "cloning");
3216 +                       header = kmalloc(bh->b_size, GFP_KERNEL);
3217 +                       error = -ENOMEM;
3218 +                       if (header == NULL)
3219 +                               goto cleanup;
3220 +                       memcpy(header, HDR(bh), bh->b_size);
3221 +                       header->h_refcount = cpu_to_le32(1);
3222 +                       offset = (char *)header - bh->b_data;
3223 +                       here = ENTRY((char *)here + offset);
3224 +                       last = ENTRY((char *)last + offset);
3225 +               }
3226 +       } else {
3227 +               /* Allocate a buffer where we construct the new block. */
3228 +               header = kmalloc(sb->s_blocksize, GFP_KERNEL);
3229 +               error = -ENOMEM;
3230 +               if (header == NULL)
3231 +                       goto cleanup;
3232 +               memset(header, 0, sb->s_blocksize);
3233 +               end = (char *)header + sb->s_blocksize;
3234 +               header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC);
3235 +               header->h_blocks = header->h_refcount = cpu_to_le32(1);
3236 +               last = here = ENTRY(header+1);
3237 +       }
3238 +
3239 +       if (not_found) {
3240 +               /* Insert the new name. */
3241 +               int size = EXT3_XATTR_LEN(name_len);
3242 +               int rest = (char *)last - (char *)here;
3243 +               memmove((char *)here + size, here, rest);
3244 +               memset(here, 0, size);
3245 +               here->e_name_index = name_index;
3246 +               here->e_name_len = name_len;
3247 +               memcpy(here->e_name, name, name_len);
3248 +       } else {
3249 +               /* Remove the old value. */
3250 +               if (!here->e_value_block && here->e_value_size) {
3251 +                       char *first_val = (char *)header + min_offs;
3252 +                       int offs = le16_to_cpu(here->e_value_offs);
3253 +                       char *val = (char *)header + offs;
3254 +                       size_t size = EXT3_XATTR_SIZE(
3255 +                               le32_to_cpu(here->e_value_size));
3256 +                       memmove(first_val + size, first_val, val - first_val);
3257 +                       memset(first_val, 0, size);
3258 +                       here->e_value_offs = 0;
3259 +                       min_offs += size;
3260 +
3261 +                       /* Adjust all value offsets. */
3262 +                       last = ENTRY(header+1);
3263 +                       while (!IS_LAST_ENTRY(last)) {
3264 +                               int o = le16_to_cpu(last->e_value_offs);
3265 +                               if (!last->e_value_block && o < offs)
3266 +                                       last->e_value_offs =
3267 +                                               cpu_to_le16(o + size);
3268 +                               last = EXT3_XATTR_NEXT(last);
3269 +                       }
3270 +               }
3271 +               if (value == NULL) {
3272 +                       /* Remove this attribute. */
3273 +                       if (EXT3_XATTR_NEXT(ENTRY(header+1)) == last) {
3274 +                               /* This block is now empty. */
3275 +                               error = ext3_xattr_set2(handle, inode, bh,NULL);
3276 +                               goto cleanup;
3277 +                       } else {
3278 +                               /* Remove the old name. */
3279 +                               int size = EXT3_XATTR_LEN(name_len);
3280 +                               last = ENTRY((char *)last - size);
3281 +                               memmove(here, (char*)here + size,
3282 +                                       (char*)last - (char*)here);
3283 +                               memset(last, 0, size);
3284 +                       }
3285 +               }
3286 +       }
3287 +
3288 +       if (value != NULL) {
3289 +               /* Insert the new value. */
3290 +               here->e_value_size = cpu_to_le32(value_len);
3291 +               if (value_len) {
3292 +                       size_t size = EXT3_XATTR_SIZE(value_len);
3293 +                       char *val = (char *)header + min_offs - size;
3294 +                       here->e_value_offs =
3295 +                               cpu_to_le16((char *)val - (char *)header);
3296 +                       memset(val + size - EXT3_XATTR_PAD, 0,
3297 +                              EXT3_XATTR_PAD); /* Clear the pad bytes. */
3298 +                       memcpy(val, value, value_len);
3299 +               }
3300 +       }
3301 +       ext3_xattr_rehash(header, here);
3302 +
3303 +       error = ext3_xattr_set2(handle, inode, bh, header);
3304 +
3305 +cleanup:
3306 +       brelse(bh);
3307 +       if (!(bh && header == HDR(bh)))
3308 +               kfree(header);
3309 +       up(&ext3_xattr_sem);
3310 +
3311 +       return error;
3312 +}
3313 +
3314 +/*
3315 + * Second half of ext3_xattr_set(): Update the file system.
3316 + */
3317 +static int
3318 +ext3_xattr_set2(handle_t *handle, struct inode *inode,
3319 +               struct buffer_head *old_bh, struct ext3_xattr_header *header)
3320 +{
3321 +       struct super_block *sb = inode->i_sb;
3322 +       struct buffer_head *new_bh = NULL;
3323 +       int error;
3324 +
3325 +       if (header) {
3326 +               new_bh = ext3_xattr_cache_find(inode, header);
3327 +               if (new_bh) {
3328 +                       /*
3329 +                        * We found an identical block in the cache.
3330 +                        * The old block will be released after updating
3331 +                        * the inode.
3332 +                        */
3333 +                       ea_bdebug(old_bh, "reusing block %ld",
3334 +                               new_bh->b_blocknr);
3335 +                       
3336 +                       error = -EDQUOT;
3337 +                       if (ext3_xattr_quota_alloc(inode, 1))
3338 +                               goto cleanup;
3339 +                       
3340 +                       error = ext3_journal_get_write_access(handle, new_bh);
3341 +                       if (error)
3342 +                               goto cleanup;
3343 +                       HDR(new_bh)->h_refcount = cpu_to_le32(
3344 +                               le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
3345 +                       ea_bdebug(new_bh, "refcount now=%d",
3346 +                               le32_to_cpu(HDR(new_bh)->h_refcount));
3347 +               } else if (old_bh && header == HDR(old_bh)) {
3348 +                       /* Keep this block. */
3349 +                       new_bh = old_bh;
3350 +                       ext3_xattr_cache_insert(new_bh);
3351 +               } else {
3352 +                       /* We need to allocate a new block */
3353 +                       int force = EXT3_I(inode)->i_file_acl != 0;
3354 +                       int block = ext3_xattr_new_block(handle, inode,
3355 +                                                        &error, force);
3356 +                       if (error)
3357 +                               goto cleanup;
3358 +                       ea_idebug(inode, "creating block %d", block);
3359 +
3360 +                       new_bh = sb_getblk(sb, block);
3361 +                       if (!new_bh) {
3362 +getblk_failed:                 ext3_xattr_free_block(handle, inode, block);
3363 +                               error = -EIO;
3364 +                               goto cleanup;
3365 +                       }
3366 +                       lock_buffer(new_bh);
3367 +                       error = ext3_journal_get_create_access(handle, new_bh);
3368 +                       if (error) {
3369 +                               unlock_buffer(new_bh);
3370 +                               goto getblk_failed;
3371 +                       }
3372 +                       memcpy(new_bh->b_data, header, new_bh->b_size);
3373 +                       mark_buffer_uptodate(new_bh, 1);
3374 +                       unlock_buffer(new_bh);
3375 +                       ext3_xattr_cache_insert(new_bh);
3376 +                       
3377 +                       ext3_xattr_update_super_block(handle, sb);
3378 +               }
3379 +               error = ext3_journal_dirty_metadata(handle, new_bh);
3380 +               if (error)
3381 +                       goto cleanup;
3382 +       }
3383 +
3384 +       /* Update the inode. */
3385 +       EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
3386 +       inode->i_ctime = CURRENT_TIME;
3387 +       ext3_mark_inode_dirty(handle, inode);
3388 +       if (IS_SYNC(inode))
3389 +               handle->h_sync = 1;
3390 +
3391 +       error = 0;
3392 +       if (old_bh && old_bh != new_bh) {
3393 +               /*
3394 +                * If there was an old block, and we are not still using it,
3395 +                * we now release the old block.
3396 +               */
3397 +               unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
3398 +
3399 +               error = ext3_journal_get_write_access(handle, old_bh);
3400 +               if (error)
3401 +                       goto cleanup;
3402 +               if (refcount == 1) {
3403 +                       /* Free the old block. */
3404 +                       ea_bdebug(old_bh, "freeing");
3405 +                       ext3_xattr_free_block(handle, inode, old_bh->b_blocknr);
3406 +
3407 +                       /* ext3_forget() calls bforget() for us, but we
3408 +                          let our caller release old_bh, so we need to
3409 +                          duplicate the handle before. */
3410 +                       get_bh(old_bh);
3411 +                       ext3_forget(handle, 1, inode, old_bh,old_bh->b_blocknr);
3412 +               } else {
3413 +                       /* Decrement the refcount only. */
3414 +                       refcount--;
3415 +                       HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
3416 +                       ext3_xattr_quota_free(inode);
3417 +                       ext3_journal_dirty_metadata(handle, old_bh);
3418 +                       ea_bdebug(old_bh, "refcount now=%d", refcount);
3419 +               }
3420 +       }
3421 +
3422 +cleanup:
3423 +       if (old_bh != new_bh)
3424 +               brelse(new_bh);
3425 +
3426 +       return error;
3427 +}
3428 +
3429 +/*
3430 + * ext3_xattr_delete_inode()
3431 + *
3432 + * Free extended attribute resources associated with this inode. This
3433 + * is called immediately before an inode is freed.
3434 + */
3435 +void
3436 +ext3_xattr_delete_inode(handle_t *handle, struct inode *inode)
3437 +{
3438 +       struct buffer_head *bh;
3439 +       unsigned int block = EXT3_I(inode)->i_file_acl;
3440 +
3441 +       if (!block)
3442 +               return;
3443 +       down(&ext3_xattr_sem);
3444 +
3445 +       bh = sb_bread(inode->i_sb, block);
3446 +       if (!bh) {
3447 +               ext3_error(inode->i_sb, "ext3_xattr_delete_inode",
3448 +                       "inode %ld: block %d read error", inode->i_ino, block);
3449 +               goto cleanup;
3450 +       }
3451 +       ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
3452 +       if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
3453 +           HDR(bh)->h_blocks != cpu_to_le32(1)) {
3454 +               ext3_error(inode->i_sb, "ext3_xattr_delete_inode",
3455 +                       "inode %ld: bad block %d", inode->i_ino, block);
3456 +               goto cleanup;
3457 +       }
3458 +       ext3_journal_get_write_access(handle, bh);
3459 +       ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
3460 +       if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
3461 +               ext3_xattr_cache_remove(bh);
3462 +               ext3_xattr_free_block(handle, inode, block);
3463 +               ext3_forget(handle, 1, inode, bh, block);
3464 +               bh = NULL;
3465 +       } else {
3466 +               HDR(bh)->h_refcount = cpu_to_le32(
3467 +                       le32_to_cpu(HDR(bh)->h_refcount) - 1);
3468 +               ext3_journal_dirty_metadata(handle, bh);
3469 +               if (IS_SYNC(inode))
3470 +                       handle->h_sync = 1;
3471 +               ext3_xattr_quota_free(inode);
3472 +       }
3473 +       EXT3_I(inode)->i_file_acl = 0;
3474 +
3475 +cleanup:
3476 +       brelse(bh);
3477 +       up(&ext3_xattr_sem);
3478 +}
3479 +
3480 +/*
3481 + * ext3_xattr_put_super()
3482 + *
3483 + * This is called when a file system is unmounted.
3484 + */
3485 +void
3486 +ext3_xattr_put_super(struct super_block *sb)
3487 +{
3488 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
3489 +       mb_cache_shrink(ext3_xattr_cache, sb->s_dev);
3490 +#endif
3491 +}
3492 +
3493 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
3494 +
3495 +/*
3496 + * ext3_xattr_cache_insert()
3497 + *
3498 + * Create a new entry in the extended attribute cache, and insert
3499 + * it unless such an entry is already in the cache.
3500 + *
3501 + * Returns 0, or a negative error number on failure.
3502 + */
3503 +static int
3504 +ext3_xattr_cache_insert(struct buffer_head *bh)
3505 +{
3506 +       __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
3507 +       struct mb_cache_entry *ce;
3508 +       int error;
3509 +
3510 +       ce = mb_cache_entry_alloc(ext3_xattr_cache);
3511 +       if (!ce)
3512 +               return -ENOMEM;
3513 +       error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
3514 +       if (error) {
3515 +               mb_cache_entry_free(ce);
3516 +               if (error == -EBUSY) {
3517 +                       ea_bdebug(bh, "already in cache (%d cache entries)",
3518 +                               atomic_read(&ext3_xattr_cache->c_entry_count));
3519 +                       error = 0;
3520 +               }
3521 +       } else {
3522 +               ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
3523 +                         atomic_read(&ext3_xattr_cache->c_entry_count));
3524 +               mb_cache_entry_release(ce);
3525 +       }
3526 +       return error;
3527 +}
3528 +
3529 +/*
3530 + * ext3_xattr_cmp()
3531 + *
3532 + * Compare two extended attribute blocks for equality.
3533 + *
3534 + * Returns 0 if the blocks are equal, 1 if they differ, and
3535 + * a negative error number on errors.
3536 + */
3537 +static int
3538 +ext3_xattr_cmp(struct ext3_xattr_header *header1,
3539 +              struct ext3_xattr_header *header2)
3540 +{
3541 +       struct ext3_xattr_entry *entry1, *entry2;
3542 +
3543 +       entry1 = ENTRY(header1+1);
3544 +       entry2 = ENTRY(header2+1);
3545 +       while (!IS_LAST_ENTRY(entry1)) {
3546 +               if (IS_LAST_ENTRY(entry2))
3547 +                       return 1;
3548 +               if (entry1->e_hash != entry2->e_hash ||
3549 +                   entry1->e_name_len != entry2->e_name_len ||
3550 +                   entry1->e_value_size != entry2->e_value_size ||
3551 +                   memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
3552 +                       return 1;
3553 +               if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
3554 +                       return -EIO;
3555 +               if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
3556 +                          (char *)header2 + le16_to_cpu(entry2->e_value_offs),
3557 +                          le32_to_cpu(entry1->e_value_size)))
3558 +                       return 1;
3559 +
3560 +               entry1 = EXT3_XATTR_NEXT(entry1);
3561 +               entry2 = EXT3_XATTR_NEXT(entry2);
3562 +       }
3563 +       if (!IS_LAST_ENTRY(entry2))
3564 +               return 1;
3565 +       return 0;
3566 +}
3567 +
3568 +/*
3569 + * ext3_xattr_cache_find()
3570 + *
3571 + * Find an identical extended attribute block.
3572 + *
3573 + * Returns a pointer to the block found, or NULL if such a block was
3574 + * not found or an error occurred.
3575 + */
3576 +static struct buffer_head *
3577 +ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header)
3578 +{
3579 +       __u32 hash = le32_to_cpu(header->h_hash);
3580 +       struct mb_cache_entry *ce;
3581 +
3582 +       if (!header->h_hash)
3583 +               return NULL;  /* never share */
3584 +       ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
3585 +       ce = mb_cache_entry_find_first(ext3_xattr_cache, 0, inode->i_dev, hash);
3586 +       while (ce) {
3587 +               struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
3588 +
3589 +               if (!bh) {
3590 +                       ext3_error(inode->i_sb, "ext3_xattr_cache_find",
3591 +                               "inode %ld: block %ld read error",
3592 +                               inode->i_ino, ce->e_block);
3593 +               } else if (le32_to_cpu(HDR(bh)->h_refcount) >
3594 +                          EXT3_XATTR_REFCOUNT_MAX) {
3595 +                       ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
3596 +                               le32_to_cpu(HDR(bh)->h_refcount),
3597 +                               EXT3_XATTR_REFCOUNT_MAX);
3598 +               } else if (!ext3_xattr_cmp(header, HDR(bh))) {
3599 +                       ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
3600 +                       mb_cache_entry_release(ce);
3601 +                       return bh;
3602 +               }
3603 +               brelse(bh);
3604 +               ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
3605 +       }
3606 +       return NULL;
3607 +}
3608 +
3609 +/*
3610 + * ext3_xattr_cache_remove()
3611 + *
3612 + * Remove the cache entry of a block from the cache. Called when a
3613 + * block becomes invalid.
3614 + */
3615 +static void
3616 +ext3_xattr_cache_remove(struct buffer_head *bh)
3617 +{
3618 +       struct mb_cache_entry *ce;
3619 +
3620 +       ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_dev, bh->b_blocknr);
3621 +       if (ce) {
3622 +               ea_bdebug(bh, "removing (%d cache entries remaining)",
3623 +                         atomic_read(&ext3_xattr_cache->c_entry_count)-1);
3624 +               mb_cache_entry_free(ce);
3625 +       } else 
3626 +               ea_bdebug(bh, "no cache entry");
3627 +}
3628 +
3629 +#define NAME_HASH_SHIFT 5
3630 +#define VALUE_HASH_SHIFT 16
3631 +
3632 +/*
3633 + * ext3_xattr_hash_entry()
3634 + *
3635 + * Compute the hash of an extended attribute.
3636 + */
3637 +static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
3638 +                                        struct ext3_xattr_entry *entry)
3639 +{
3640 +       __u32 hash = 0;
3641 +       char *name = entry->e_name;
3642 +       int n;
3643 +
3644 +       for (n=0; n < entry->e_name_len; n++) {
3645 +               hash = (hash << NAME_HASH_SHIFT) ^
3646 +                      (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
3647 +                      *name++;
3648 +       }
3649 +
3650 +       if (entry->e_value_block == 0 && entry->e_value_size != 0) {
3651 +               __u32 *value = (__u32 *)((char *)header +
3652 +                       le16_to_cpu(entry->e_value_offs));
3653 +               for (n = (le32_to_cpu(entry->e_value_size) +
3654 +                    EXT3_XATTR_ROUND) >> EXT3_XATTR_PAD_BITS; n; n--) {
3655 +                       hash = (hash << VALUE_HASH_SHIFT) ^
3656 +                              (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
3657 +                              le32_to_cpu(*value++);
3658 +               }
3659 +       }
3660 +       entry->e_hash = cpu_to_le32(hash);
3661 +}
3662 +
3663 +#undef NAME_HASH_SHIFT
3664 +#undef VALUE_HASH_SHIFT
3665 +
3666 +#define BLOCK_HASH_SHIFT 16
3667 +
3668 +/*
3669 + * ext3_xattr_rehash()
3670 + *
3671 + * Re-compute the extended attribute hash value after an entry has changed.
3672 + */
3673 +static void ext3_xattr_rehash(struct ext3_xattr_header *header,
3674 +                             struct ext3_xattr_entry *entry)
3675 +{
3676 +       struct ext3_xattr_entry *here;
3677 +       __u32 hash = 0;
3678 +       
3679 +       ext3_xattr_hash_entry(header, entry);
3680 +       here = ENTRY(header+1);
3681 +       while (!IS_LAST_ENTRY(here)) {
3682 +               if (!here->e_hash) {
3683 +                       /* Block is not shared if an entry's hash value == 0 */
3684 +                       hash = 0;
3685 +                       break;
3686 +               }
3687 +               hash = (hash << BLOCK_HASH_SHIFT) ^
3688 +                      (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
3689 +                      le32_to_cpu(here->e_hash);
3690 +               here = EXT3_XATTR_NEXT(here);
3691 +       }
3692 +       header->h_hash = cpu_to_le32(hash);
3693 +}
3694 +
3695 +#undef BLOCK_HASH_SHIFT
3696 +
3697 +int __init
3698 +init_ext3_xattr(void)
3699 +{
3700 +       ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL,
3701 +               sizeof(struct mb_cache_entry) +
3702 +               sizeof(struct mb_cache_entry_index), 1, 61);
3703 +       if (!ext3_xattr_cache)
3704 +               return -ENOMEM;
3705 +
3706 +       return 0;
3707 +}
3708 +
3709 +void
3710 +exit_ext3_xattr(void)
3711 +{
3712 +       if (ext3_xattr_cache)
3713 +               mb_cache_destroy(ext3_xattr_cache);
3714 +       ext3_xattr_cache = NULL;
3715 +}
3716 +
3717 +#else  /* CONFIG_EXT3_FS_XATTR_SHARING */
3718 +
3719 +int __init
3720 +init_ext3_xattr(void)
3721 +{
3722 +       return 0;
3723 +}
3724 +
3725 +void
3726 +exit_ext3_xattr(void)
3727 +{
3728 +}
3729 +
3730 +#endif  /* CONFIG_EXT3_FS_XATTR_SHARING */
3731 --- /dev/null   2003-01-30 18:24:37.000000000 +0800
3732 +++ linux-2.4.20-root/fs/ext3/xattr_user.c      2003-05-07 18:08:03.000000000 +0800
3733 @@ -0,0 +1,111 @@
3734 +/*
3735 + * linux/fs/ext3/xattr_user.c
3736 + * Handler for extended user attributes.
3737 + *
3738 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
3739 + */
3740 +
3741 +#include <linux/module.h>
3742 +#include <linux/string.h>
3743 +#include <linux/fs.h>
3744 +#include <linux/ext3_jbd.h>
3745 +#include <linux/ext3_fs.h>
3746 +#include <linux/ext3_xattr.h>
3747 +
3748 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3749 +# include <linux/ext3_acl.h>
3750 +#endif
3751 +
3752 +#define XATTR_USER_PREFIX "user."
3753 +
3754 +static size_t
3755 +ext3_xattr_user_list(char *list, struct inode *inode,
3756 +                    const char *name, int name_len)
3757 +{
3758 +       const int prefix_len = sizeof(XATTR_USER_PREFIX)-1;
3759 +
3760 +       if (!test_opt(inode->i_sb, XATTR_USER))
3761 +               return 0;
3762 +
3763 +       if (list) {
3764 +               memcpy(list, XATTR_USER_PREFIX, prefix_len);
3765 +               memcpy(list+prefix_len, name, name_len);
3766 +               list[prefix_len + name_len] = '\0';
3767 +       }
3768 +       return prefix_len + name_len + 1;
3769 +}
3770 +
3771 +static int
3772 +ext3_xattr_user_get(struct inode *inode, const char *name,
3773 +                   void *buffer, size_t size)
3774 +{
3775 +       int error;
3776 +
3777 +       if (strcmp(name, "") == 0)
3778 +               return -EINVAL;
3779 +       if (!test_opt(inode->i_sb, XATTR_USER))
3780 +               return -ENOTSUP;
3781 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3782 +       error = ext3_permission_locked(inode, MAY_READ);
3783 +#else
3784 +       error = permission(inode, MAY_READ);
3785 +#endif
3786 +       if (error)
3787 +               return error;
3788 +
3789 +       return ext3_xattr_get(inode, EXT3_XATTR_INDEX_USER, name,
3790 +                             buffer, size);
3791 +}
3792 +
3793 +static int
3794 +ext3_xattr_user_set(struct inode *inode, const char *name,
3795 +                   const void *value, size_t size, int flags)
3796 +{
3797 +       handle_t *handle;
3798 +       int error;
3799 +
3800 +       if (strcmp(name, "") == 0)
3801 +               return -EINVAL;
3802 +       if (!test_opt(inode->i_sb, XATTR_USER))
3803 +               return -ENOTSUP;
3804 +       if ( !S_ISREG(inode->i_mode) &&
3805 +           (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
3806 +               return -EPERM;
3807 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3808 +       error = ext3_permission_locked(inode, MAY_WRITE);
3809 +#else
3810 +       error = permission(inode, MAY_WRITE);
3811 +#endif
3812 +       if (error)
3813 +               return error;
3814 +
3815 +       handle = ext3_journal_start(inode, EXT3_XATTR_TRANS_BLOCKS);
3816 +       if (IS_ERR(handle))
3817 +               return PTR_ERR(handle);
3818 +       error = ext3_xattr_set(handle, inode, EXT3_XATTR_INDEX_USER, name,
3819 +                              value, size, flags);
3820 +       ext3_journal_stop(handle, inode);
3821 +
3822 +       return error;
3823 +}
3824 +
3825 +struct ext3_xattr_handler ext3_xattr_user_handler = {
3826 +       prefix: XATTR_USER_PREFIX,
3827 +       list:   ext3_xattr_user_list,
3828 +       get:    ext3_xattr_user_get,
3829 +       set:    ext3_xattr_user_set,
3830 +};
3831 +
3832 +int __init
3833 +init_ext3_xattr_user(void)
3834 +{
3835 +       return ext3_xattr_register(EXT3_XATTR_INDEX_USER,
3836 +                                  &ext3_xattr_user_handler);
3837 +}
3838 +
3839 +void
3840 +exit_ext3_xattr_user(void)
3841 +{
3842 +       ext3_xattr_unregister(EXT3_XATTR_INDEX_USER,
3843 +                             &ext3_xattr_user_handler);
3844 +}
3845 --- linux-2.4.20/fs/jfs/jfs_xattr.h~linux-2.4.20-xattr-0.8.54   2002-11-29 07:53:15.000000000 +0800
3846 +++ linux-2.4.20-root/fs/jfs/jfs_xattr.h        2003-05-07 18:08:03.000000000 +0800
3847 @@ -52,8 +52,10 @@ struct jfs_ea_list {
3848  #define        END_EALIST(ealist) \
3849         ((struct jfs_ea *) (((char *) (ealist)) + EALIST_SIZE(ealist)))
3850  
3851 -extern int __jfs_setxattr(struct inode *, const char *, void *, size_t, int);
3852 -extern int jfs_setxattr(struct dentry *, const char *, void *, size_t, int);
3853 +extern int __jfs_setxattr(struct inode *, const char *, const void *, size_t,
3854 +                         int);
3855 +extern int jfs_setxattr(struct dentry *, const char *, const void *, size_t,
3856 +                       int);
3857  extern ssize_t __jfs_getxattr(struct inode *, const char *, void *, size_t);
3858  extern ssize_t jfs_getxattr(struct dentry *, const char *, void *, size_t);
3859  extern ssize_t jfs_listxattr(struct dentry *, char *, size_t);
3860 --- linux-2.4.20/fs/jfs/xattr.c~linux-2.4.20-xattr-0.8.54       2002-11-29 07:53:15.000000000 +0800
3861 +++ linux-2.4.20-root/fs/jfs/xattr.c    2003-05-07 18:08:03.000000000 +0800
3862 @@ -641,7 +641,7 @@ static int ea_put(struct inode *inode, s
3863  }
3864  
3865  static int can_set_xattr(struct inode *inode, const char *name,
3866 -                        void *value, size_t value_len)
3867 +                        const void *value, size_t value_len)
3868  {
3869         if (IS_RDONLY(inode))
3870                 return -EROFS;
3871 @@ -660,7 +660,7 @@ static int can_set_xattr(struct inode *i
3872         return permission(inode, MAY_WRITE);
3873  }
3874  
3875 -int __jfs_setxattr(struct inode *inode, const char *name, void *value,
3876 +int __jfs_setxattr(struct inode *inode, const char *name, const void *value,
3877                    size_t value_len, int flags)
3878  {
3879         struct jfs_ea_list *ealist;
3880 @@ -799,7 +799,7 @@ int __jfs_setxattr(struct inode *inode, 
3881         return rc;
3882  }
3883  
3884 -int jfs_setxattr(struct dentry *dentry, const char *name, void *value,
3885 +int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
3886                  size_t value_len, int flags)
3887  {
3888         if (value == NULL) {    /* empty EA, do not remove */
3889 --- /dev/null   2003-01-30 18:24:37.000000000 +0800
3890 +++ linux-2.4.20-root/fs/mbcache.c      2003-05-07 18:08:03.000000000 +0800
3891 @@ -0,0 +1,648 @@
3892 +/*
3893 + * linux/fs/mbcache.c
3894 + * (C) 2001-2002 Andreas Gruenbacher, <a.gruenbacher@computer.org>
3895 + */
3896 +
3897 +/*
3898 + * Filesystem Meta Information Block Cache (mbcache)
3899 + *
3900 + * The mbcache caches blocks of block devices that need to be located
3901 + * by their device/block number, as well as by other criteria (such
3902 + * as the block's contents).
3903 + *
3904 + * There can only be one cache entry in a cache per device and block number.
3905 + * Additional indexes need not be unique in this sense. The number of
3906 + * additional indexes (=other criteria) can be hardwired at compile time
3907 + * or specified at cache create time.
3908 + *
3909 + * Each cache entry is of fixed size. An entry may be `valid' or `invalid'
3910 + * in the cache. A valid entry is in the main hash tables of the cache,
3911 + * and may also be in the lru list. An invalid entry is not in any hashes
3912 + * or lists.
3913 + *
3914 + * A valid cache entry is only in the lru list if no handles refer to it.
3915 + * Invalid cache entries will be freed when the last handle to the cache
3916 + * entry is released. Entries that cannot be freed immediately are put
3917 + * back on the lru list.
3918 + */
3919 +
3920 +#include <linux/kernel.h>
3921 +#include <linux/module.h>
3922 +
3923 +#include <linux/fs.h>
3924 +#include <linux/slab.h>
3925 +#include <linux/sched.h>
3926 +#include <linux/cache_def.h>
3927 +#include <linux/version.h>
3928 +#include <linux/init.h>
3929 +#include <linux/mbcache.h>
3930 +
3931 +
3932 +#ifdef MB_CACHE_DEBUG
3933 +# define mb_debug(f...) do { \
3934 +               printk(KERN_DEBUG f); \
3935 +               printk("\n"); \
3936 +       } while (0)
3937 +#define mb_assert(c) do { if (!(c)) \
3938 +               printk(KERN_ERR "assertion " #c " failed\n"); \
3939 +       } while(0)
3940 +#else
3941 +# define mb_debug(f...) do { } while(0)
3942 +# define mb_assert(c) do { } while(0)
3943 +#endif
3944 +#define mb_error(f...) do { \
3945 +               printk(KERN_ERR f); \
3946 +               printk("\n"); \
3947 +       } while(0)
3948 +               
3949 +MODULE_AUTHOR("Andreas Gruenbacher <a.gruenbacher@computer.org>");
3950 +MODULE_DESCRIPTION("Meta block cache (for extended attributes)");
3951 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
3952 +MODULE_LICENSE("GPL");
3953 +#endif
3954 +
3955 +EXPORT_SYMBOL(mb_cache_create);
3956 +EXPORT_SYMBOL(mb_cache_shrink);
3957 +EXPORT_SYMBOL(mb_cache_destroy);
3958 +EXPORT_SYMBOL(mb_cache_entry_alloc);
3959 +EXPORT_SYMBOL(mb_cache_entry_insert);
3960 +EXPORT_SYMBOL(mb_cache_entry_release);
3961 +EXPORT_SYMBOL(mb_cache_entry_takeout);
3962 +EXPORT_SYMBOL(mb_cache_entry_free);
3963 +EXPORT_SYMBOL(mb_cache_entry_dup);
3964 +EXPORT_SYMBOL(mb_cache_entry_get);
3965 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
3966 +EXPORT_SYMBOL(mb_cache_entry_find_first);
3967 +EXPORT_SYMBOL(mb_cache_entry_find_next);
3968 +#endif
3969 +
3970 +
3971 +/*
3972 + * Global data: list of all mbcache's, lru list, and a spinlock for
3973 + * accessing cache data structures on SMP machines. The lru list is
3974 + * global across all mbcaches.
3975 + */
3976 +
3977 +static LIST_HEAD(mb_cache_list);
3978 +static LIST_HEAD(mb_cache_lru_list);
3979 +static spinlock_t mb_cache_spinlock = SPIN_LOCK_UNLOCKED;
3980 +
3981 +static inline int
3982 +mb_cache_indexes(struct mb_cache *cache)
3983 +{
3984 +#ifdef MB_CACHE_INDEXES_COUNT
3985 +       return MB_CACHE_INDEXES_COUNT;
3986 +#else
3987 +       return cache->c_indexes_count;
3988 +#endif
3989 +}
3990 +
3991 +/*
3992 + * What the mbcache registers as to get shrunk dynamically.
3993 + */
3994 +
3995 +static void
3996 +mb_cache_memory_pressure(int priority, unsigned int gfp_mask);
3997 +
3998 +static struct cache_definition mb_cache_definition = {
3999 +       "mb_cache",
4000 +       mb_cache_memory_pressure
4001 +};
4002 +
4003 +
4004 +static inline int
4005 +__mb_cache_entry_is_hashed(struct mb_cache_entry *ce)
4006 +{
4007 +       return !list_empty(&ce->e_block_list);
4008 +}
4009 +
4010 +
4011 +static inline void
4012 +__mb_cache_entry_unhash(struct mb_cache_entry *ce)
4013 +{
4014 +       int n;
4015 +
4016 +       if (__mb_cache_entry_is_hashed(ce)) {
4017 +               list_del_init(&ce->e_block_list);
4018 +               for (n=0; n<mb_cache_indexes(ce->e_cache); n++)
4019 +                       list_del(&ce->e_indexes[n].o_list);
4020 +       }
4021 +}
4022 +
4023 +
4024 +static inline void
4025 +__mb_cache_entry_forget(struct mb_cache_entry *ce, int gfp_mask)
4026 +{
4027 +       struct mb_cache *cache = ce->e_cache;
4028 +
4029 +       mb_assert(atomic_read(&ce->e_used) == 0);
4030 +       if (cache->c_op.free && cache->c_op.free(ce, gfp_mask)) {
4031 +               /* free failed -- put back on the lru list
4032 +                  for freeing later. */
4033 +               spin_lock(&mb_cache_spinlock);
4034 +               list_add(&ce->e_lru_list, &mb_cache_lru_list);
4035 +               spin_unlock(&mb_cache_spinlock);
4036 +       } else {
4037 +               kmem_cache_free(cache->c_entry_cache, ce);
4038 +               atomic_dec(&cache->c_entry_count);
4039 +       }
4040 +}
4041 +
4042 +
4043 +static inline void
4044 +__mb_cache_entry_release_unlock(struct mb_cache_entry *ce)
4045 +{
4046 +       if (atomic_dec_and_test(&ce->e_used)) {
4047 +               if (__mb_cache_entry_is_hashed(ce))
4048 +                       list_add_tail(&ce->e_lru_list, &mb_cache_lru_list);
4049 +               else {
4050 +                       spin_unlock(&mb_cache_spinlock);
4051 +                       __mb_cache_entry_forget(ce, GFP_KERNEL);
4052 +                       return;
4053 +               }
4054 +       }
4055 +       spin_unlock(&mb_cache_spinlock);
4056 +}
4057 +
4058 +
4059 +/*
4060 + * mb_cache_memory_pressure()  memory pressure callback
4061 + *
4062 + * This function is called by the kernel memory management when memory
4063 + * gets low.
4064 + *
4065 + * @priority: Amount by which to shrink the cache (0 = highes priority)
4066 + * @gfp_mask: (ignored)
4067 + */
4068 +static void
4069 +mb_cache_memory_pressure(int priority, unsigned int gfp_mask)
4070 +{
4071 +       LIST_HEAD(free_list);
4072 +       struct list_head *l, *ltmp;
4073 +       int count = 0;
4074 +
4075 +       spin_lock(&mb_cache_spinlock);
4076 +       list_for_each(l, &mb_cache_list) {
4077 +               struct mb_cache *cache =
4078 +                       list_entry(l, struct mb_cache, c_cache_list);
4079 +               mb_debug("cache %s (%d)", cache->c_name,
4080 +                         atomic_read(&cache->c_entry_count));
4081 +               count += atomic_read(&cache->c_entry_count);
4082 +       }
4083 +       mb_debug("trying to free %d of %d entries",
4084 +                 count / (priority ? priority : 1), count);
4085 +       if (priority)
4086 +               count /= priority;
4087 +       while (count-- && !list_empty(&mb_cache_lru_list)) {
4088 +               struct mb_cache_entry *ce =
4089 +                       list_entry(mb_cache_lru_list.next,
4090 +                                  struct mb_cache_entry, e_lru_list);
4091 +               list_del(&ce->e_lru_list);
4092 +               __mb_cache_entry_unhash(ce);
4093 +               list_add_tail(&ce->e_lru_list, &free_list);
4094 +       }
4095 +       spin_unlock(&mb_cache_spinlock);
4096 +       list_for_each_safe(l, ltmp, &free_list) {
4097 +               __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4098 +                                                  e_lru_list), gfp_mask);
4099 +       }
4100 +}
4101 +
4102 +
4103 +/*
4104 + * mb_cache_create()  create a new cache
4105 + *
4106 + * All entries in one cache are equal size. Cache entries may be from
4107 + * multiple devices. If this is the first mbcache created, registers
4108 + * the cache with kernel memory management. Returns NULL if no more
4109 + * memory was available.
4110 + *
4111 + * @name: name of the cache (informal)
4112 + * @cache_op: contains the callback called when freeing a cache entry
4113 + * @entry_size: The size of a cache entry, including
4114 + *              struct mb_cache_entry
4115 + * @indexes_count: number of additional indexes in the cache. Must equal
4116 + *                 MB_CACHE_INDEXES_COUNT if the number of indexes is
4117 + *                 hardwired.
4118 + * @bucket_count: number of hash buckets
4119 + */
4120 +struct mb_cache *
4121 +mb_cache_create(const char *name, struct mb_cache_op *cache_op,
4122 +               size_t entry_size, int indexes_count, int bucket_count)
4123 +{
4124 +       int m=0, n;
4125 +       struct mb_cache *cache = NULL;
4126 +
4127 +       if(entry_size < sizeof(struct mb_cache_entry) +
4128 +          indexes_count * sizeof(struct mb_cache_entry_index))
4129 +               return NULL;
4130 +
4131 +       MOD_INC_USE_COUNT;
4132 +       cache = kmalloc(sizeof(struct mb_cache) +
4133 +                       indexes_count * sizeof(struct list_head), GFP_KERNEL);
4134 +       if (!cache)
4135 +               goto fail;
4136 +       cache->c_name = name;
4137 +       cache->c_op.free = NULL;
4138 +       if (cache_op)
4139 +               cache->c_op.free = cache_op->free;
4140 +       atomic_set(&cache->c_entry_count, 0);
4141 +       cache->c_bucket_count = bucket_count;
4142 +#ifdef MB_CACHE_INDEXES_COUNT
4143 +       mb_assert(indexes_count == MB_CACHE_INDEXES_COUNT);
4144 +#else
4145 +       cache->c_indexes_count = indexes_count;
4146 +#endif
4147 +       cache->c_block_hash = kmalloc(bucket_count * sizeof(struct list_head),
4148 +                                     GFP_KERNEL);
4149 +       if (!cache->c_block_hash)
4150 +               goto fail;
4151 +       for (n=0; n<bucket_count; n++)
4152 +               INIT_LIST_HEAD(&cache->c_block_hash[n]);
4153 +       for (m=0; m<indexes_count; m++) {
4154 +               cache->c_indexes_hash[m] = kmalloc(bucket_count *
4155 +                                                sizeof(struct list_head),
4156 +                                                GFP_KERNEL);
4157 +               if (!cache->c_indexes_hash[m])
4158 +                       goto fail;
4159 +               for (n=0; n<bucket_count; n++)
4160 +                       INIT_LIST_HEAD(&cache->c_indexes_hash[m][n]);
4161 +       }
4162 +       cache->c_entry_cache = kmem_cache_create(name, entry_size, 0,
4163 +               0 /*SLAB_POISON | SLAB_RED_ZONE*/, NULL, NULL);
4164 +       if (!cache->c_entry_cache)
4165 +               goto fail;
4166 +
4167 +       spin_lock(&mb_cache_spinlock);
4168 +       list_add(&cache->c_cache_list, &mb_cache_list);
4169 +       spin_unlock(&mb_cache_spinlock);
4170 +       return cache;
4171 +
4172 +fail:
4173 +       if (cache) {
4174 +               while (--m >= 0)
4175 +                       kfree(cache->c_indexes_hash[m]);
4176 +               if (cache->c_block_hash)
4177 +                       kfree(cache->c_block_hash);
4178 +               kfree(cache);
4179 +       }
4180 +       MOD_DEC_USE_COUNT;
4181 +       return NULL;
4182 +}
4183 +
4184 +
4185 +/*
4186 + * mb_cache_shrink()
4187 + *
4188 + * Removes all cache entires of a device from the cache. All cache entries
4189 + * currently in use cannot be freed, and thus remain in the cache.
4190 + *
4191 + * @cache: which cache to shrink
4192 + * @dev: which device's cache entries to shrink
4193 + */
4194 +void
4195 +mb_cache_shrink(struct mb_cache *cache, kdev_t dev)
4196 +{
4197 +       LIST_HEAD(free_list);
4198 +       struct list_head *l, *ltmp;
4199 +
4200 +       spin_lock(&mb_cache_spinlock);
4201 +       list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
4202 +               struct mb_cache_entry *ce =
4203 +                       list_entry(l, struct mb_cache_entry, e_lru_list);
4204 +               if (ce->e_dev == dev) {
4205 +                       list_del(&ce->e_lru_list);
4206 +                       list_add_tail(&ce->e_lru_list, &free_list);
4207 +                       __mb_cache_entry_unhash(ce);
4208 +               }
4209 +       }
4210 +       spin_unlock(&mb_cache_spinlock);
4211 +       list_for_each_safe(l, ltmp, &free_list) {
4212 +               __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4213 +                                                  e_lru_list), GFP_KERNEL);
4214 +       }
4215 +}
4216 +
4217 +
4218 +/*
4219 + * mb_cache_destroy()
4220 + *
4221 + * Shrinks the cache to its minimum possible size (hopefully 0 entries),
4222 + * and then destroys it. If this was the last mbcache, un-registers the
4223 + * mbcache from kernel memory management.
4224 + */
4225 +void
4226 +mb_cache_destroy(struct mb_cache *cache)
4227 +{
4228 +       LIST_HEAD(free_list);
4229 +       struct list_head *l, *ltmp;
4230 +       int n;
4231 +
4232 +       spin_lock(&mb_cache_spinlock);
4233 +       list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
4234 +               struct mb_cache_entry *ce =
4235 +                       list_entry(l, struct mb_cache_entry, e_lru_list);
4236 +               if (ce->e_cache == cache) {
4237 +                       list_del(&ce->e_lru_list);
4238 +                       list_add_tail(&ce->e_lru_list, &free_list);
4239 +                       __mb_cache_entry_unhash(ce);
4240 +               }
4241 +       }
4242 +       list_del(&cache->c_cache_list);
4243 +       spin_unlock(&mb_cache_spinlock);
4244 +       list_for_each_safe(l, ltmp, &free_list) {
4245 +               __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4246 +                                                  e_lru_list), GFP_KERNEL);
4247 +       }
4248 +
4249 +       if (atomic_read(&cache->c_entry_count) > 0) {
4250 +               mb_error("cache %s: %d orphaned entries",
4251 +                         cache->c_name,
4252 +                         atomic_read(&cache->c_entry_count));
4253 +       }
4254 +
4255 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
4256 +       /* We don't have kmem_cache_destroy() in 2.2.x */
4257 +       kmem_cache_shrink(cache->c_entry_cache);
4258 +#else
4259 +       kmem_cache_destroy(cache->c_entry_cache);
4260 +#endif
4261 +       for (n=0; n < mb_cache_indexes(cache); n++)
4262 +               kfree(cache->c_indexes_hash[n]);
4263 +       kfree(cache->c_block_hash);
4264 +       kfree(cache);
4265 +
4266 +       MOD_DEC_USE_COUNT;
4267 +}
4268 +
4269 +
4270 +/*
4271 + * mb_cache_entry_alloc()
4272 + *
4273 + * Allocates a new cache entry. The new entry will not be valid initially,
4274 + * and thus cannot be looked up yet. It should be filled with data, and
4275 + * then inserted into the cache using mb_cache_entry_insert(). Returns NULL
4276 + * if no more memory was available.
4277 + */
4278 +struct mb_cache_entry *
4279 +mb_cache_entry_alloc(struct mb_cache *cache)
4280 +{
4281 +       struct mb_cache_entry *ce;
4282 +
4283 +       atomic_inc(&cache->c_entry_count);
4284 +       ce = kmem_cache_alloc(cache->c_entry_cache, GFP_KERNEL);
4285 +       if (ce) {
4286 +               INIT_LIST_HEAD(&ce->e_lru_list);
4287 +               INIT_LIST_HEAD(&ce->e_block_list);
4288 +               ce->e_cache = cache;
4289 +               atomic_set(&ce->e_used, 1);
4290 +       }
4291 +       return ce;
4292 +}
4293 +
4294 +
4295 +/*
4296 + * mb_cache_entry_insert()
4297 + *
4298 + * Inserts an entry that was allocated using mb_cache_entry_alloc() into
4299 + * the cache. After this, the cache entry can be looked up, but is not yet
4300 + * in the lru list as the caller still holds a handle to it. Returns 0 on
4301 + * success, or -EBUSY if a cache entry for that device + inode exists
4302 + * already (this may happen after a failed lookup, if another process has
4303 + * inserted the same cache entry in the meantime).
4304 + *
4305 + * @dev: device the cache entry belongs to
4306 + * @block: block number
4307 + * @keys: array of additional keys. There must be indexes_count entries
4308 + *        in the array (as specified when creating the cache).
4309 + */
4310 +int
4311 +mb_cache_entry_insert(struct mb_cache_entry *ce, kdev_t dev,
4312 +                     unsigned long block, unsigned int keys[])
4313 +{
4314 +       struct mb_cache *cache = ce->e_cache;
4315 +       unsigned int bucket = (HASHDEV(dev) + block) % cache->c_bucket_count;
4316 +       struct list_head *l;
4317 +       int error = -EBUSY, n;
4318 +
4319 +       spin_lock(&mb_cache_spinlock);
4320 +       list_for_each(l, &cache->c_block_hash[bucket]) {
4321 +               struct mb_cache_entry *ce =
4322 +                       list_entry(l, struct mb_cache_entry, e_block_list);
4323 +               if (ce->e_dev == dev && ce->e_block == block)
4324 +                       goto out;
4325 +       }
4326 +       __mb_cache_entry_unhash(ce);
4327 +       ce->e_dev = dev;
4328 +       ce->e_block = block;
4329 +       list_add(&ce->e_block_list, &cache->c_block_hash[bucket]);
4330 +       for (n=0; n<mb_cache_indexes(cache); n++) {
4331 +               ce->e_indexes[n].o_key = keys[n];
4332 +               bucket = keys[n] % cache->c_bucket_count;
4333 +               list_add(&ce->e_indexes[n].o_list,
4334 +                        &cache->c_indexes_hash[n][bucket]);
4335 +       }
4336 +out:
4337 +       spin_unlock(&mb_cache_spinlock);
4338 +       return error;
4339 +}
4340 +
4341 +
4342 +/*
4343 + * mb_cache_entry_release()
4344 + *
4345 + * Release a handle to a cache entry. When the last handle to a cache entry
4346 + * is released it is either freed (if it is invalid) or otherwise inserted
4347 + * in to the lru list.
4348 + */
4349 +void
4350 +mb_cache_entry_release(struct mb_cache_entry *ce)
4351 +{
4352 +       spin_lock(&mb_cache_spinlock);
4353 +       __mb_cache_entry_release_unlock(ce);
4354 +}
4355 +
4356 +
4357 +/*
4358 + * mb_cache_entry_takeout()
4359 + *
4360 + * Take a cache entry out of the cache, making it invalid. The entry can later
4361 + * be re-inserted using mb_cache_entry_insert(), or released using
4362 + * mb_cache_entry_release().
4363 + */
4364 +void
4365 +mb_cache_entry_takeout(struct mb_cache_entry *ce)
4366 +{
4367 +       spin_lock(&mb_cache_spinlock);
4368 +       mb_assert(list_empty(&ce->e_lru_list));
4369 +       __mb_cache_entry_unhash(ce);
4370 +       spin_unlock(&mb_cache_spinlock);
4371 +}
4372 +
4373 +
4374 +/*
4375 + * mb_cache_entry_free()
4376 + *
4377 + * This is equivalent to the sequence mb_cache_entry_takeout() --
4378 + * mb_cache_entry_release().
4379 + */
4380 +void
4381 +mb_cache_entry_free(struct mb_cache_entry *ce)
4382 +{
4383 +       spin_lock(&mb_cache_spinlock);
4384 +       mb_assert(list_empty(&ce->e_lru_list));
4385 +       __mb_cache_entry_unhash(ce);
4386 +       __mb_cache_entry_release_unlock(ce);
4387 +}
4388 +
4389 +
4390 +/*
4391 + * mb_cache_entry_dup()
4392 + *
4393 + * Duplicate a handle to a cache entry (does not duplicate the cache entry
4394 + * itself). After the call, both the old and the new handle must be released.
4395 + */
4396 +struct mb_cache_entry *
4397 +mb_cache_entry_dup(struct mb_cache_entry *ce)
4398 +{
4399 +       atomic_inc(&ce->e_used);
4400 +       return ce;
4401 +}
4402 +
4403 +
4404 +/*
4405 + * mb_cache_entry_get()
4406 + *
4407 + * Get a cache entry  by device / block number. (There can only be one entry
4408 + * in the cache per device and block.) Returns NULL if no such cache entry
4409 + * exists.
4410 + */
4411 +struct mb_cache_entry *
4412 +mb_cache_entry_get(struct mb_cache *cache, kdev_t dev, unsigned long block)
4413 +{
4414 +       unsigned int bucket = (HASHDEV(dev) + block) % cache->c_bucket_count;
4415 +       struct list_head *l;
4416 +       struct mb_cache_entry *ce;
4417 +
4418 +       spin_lock(&mb_cache_spinlock);
4419 +       list_for_each(l, &cache->c_block_hash[bucket]) {
4420 +               ce = list_entry(l, struct mb_cache_entry, e_block_list);
4421 +               if (ce->e_dev == dev && ce->e_block == block) {
4422 +                       if (!list_empty(&ce->e_lru_list))
4423 +                               list_del_init(&ce->e_lru_list);
4424 +                       atomic_inc(&ce->e_used);
4425 +                       goto cleanup;
4426 +               }
4427 +       }
4428 +       ce = NULL;
4429 +
4430 +cleanup:
4431 +       spin_unlock(&mb_cache_spinlock);
4432 +       return ce;
4433 +}
4434 +
4435 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
4436 +
4437 +static struct mb_cache_entry *
4438 +__mb_cache_entry_find(struct list_head *l, struct list_head *head,
4439 +                     int index, kdev_t dev, unsigned int key)
4440 +{
4441 +       while (l != head) {
4442 +               struct mb_cache_entry *ce =
4443 +                       list_entry(l, struct mb_cache_entry,
4444 +                                  e_indexes[index].o_list);
4445 +               if (ce->e_dev == dev && ce->e_indexes[index].o_key == key) {
4446 +                       if (!list_empty(&ce->e_lru_list))
4447 +                               list_del_init(&ce->e_lru_list);
4448 +                       atomic_inc(&ce->e_used);
4449 +                       return ce;
4450 +               }
4451 +               l = l->next;
4452 +       }
4453 +       return NULL;
4454 +}
4455 +
4456 +
4457 +/*
4458 + * mb_cache_entry_find_first()
4459 + *
4460 + * Find the first cache entry on a given device with a certain key in
4461 + * an additional index. Additonal matches can be found with
4462 + * mb_cache_entry_find_next(). Returns NULL if no match was found.
4463 + *
4464 + * @cache: the cache to search
4465 + * @index: the number of the additonal index to search (0<=index<indexes_count)
4466 + * @dev: the device the cache entry should belong to
4467 + * @key: the key in the index
4468 + */
4469 +struct mb_cache_entry *
4470 +mb_cache_entry_find_first(struct mb_cache *cache, int index, kdev_t dev,
4471 +                         unsigned int key)
4472 +{
4473 +       unsigned int bucket = key % cache->c_bucket_count;
4474 +       struct list_head *l;
4475 +       struct mb_cache_entry *ce;
4476 +
4477 +       mb_assert(index < mb_cache_indexes(cache));
4478 +       spin_lock(&mb_cache_spinlock);
4479 +       l = cache->c_indexes_hash[index][bucket].next;
4480 +       ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
4481 +                                  index, dev, key);
4482 +       spin_unlock(&mb_cache_spinlock);
4483 +       return ce;
4484 +}
4485 +
4486 +
4487 +/*
4488 + * mb_cache_entry_find_next()
4489 + *
4490 + * Find the next cache entry on a given device with a certain key in an
4491 + * additional index. Returns NULL if no match could be found. The previous
4492 + * entry is atomatically released, so that mb_cache_entry_find_next() can
4493 + * be called like this:
4494 + *
4495 + * entry = mb_cache_entry_find_first();
4496 + * while (entry) {
4497 + *     ...
4498 + *     entry = mb_cache_entry_find_next(entry, ...);
4499 + * }
4500 + *
4501 + * @prev: The previous match
4502 + * @index: the number of the additonal index to search (0<=index<indexes_count)
4503 + * @dev: the device the cache entry should belong to
4504 + * @key: the key in the index
4505 + */
4506 +struct mb_cache_entry *
4507 +mb_cache_entry_find_next(struct mb_cache_entry *prev, int index, kdev_t dev,
4508 +                        unsigned int key)
4509 +{
4510 +       struct mb_cache *cache = prev->e_cache;
4511 +       unsigned int bucket = key % cache->c_bucket_count;
4512 +       struct list_head *l;
4513 +       struct mb_cache_entry *ce;
4514 +
4515 +       mb_assert(index < mb_cache_indexes(cache));
4516 +       spin_lock(&mb_cache_spinlock);
4517 +       l = prev->e_indexes[index].o_list.next;
4518 +       ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
4519 +                                  index, dev, key);
4520 +       __mb_cache_entry_release_unlock(prev);
4521 +       return ce;
4522 +}
4523 +
4524 +#endif  /* !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0) */
4525 +
4526 +static int __init init_mbcache(void)
4527 +{
4528 +       register_cache(&mb_cache_definition);
4529 +       return 0;
4530 +}
4531 +
4532 +static void __exit exit_mbcache(void)
4533 +{
4534 +       unregister_cache(&mb_cache_definition);
4535 +}
4536 +
4537 +module_init(init_mbcache)
4538 +module_exit(exit_mbcache)
4539 +
4540 --- linux-2.4.20/include/asm-arm/unistd.h~linux-2.4.20-xattr-0.8.54     2002-08-03 08:39:45.000000000 +0800
4541 +++ linux-2.4.20-root/include/asm-arm/unistd.h  2003-05-07 18:08:03.000000000 +0800
4542 @@ -244,7 +244,6 @@
4543  #define __NR_security                  (__NR_SYSCALL_BASE+223)
4544  #define __NR_gettid                    (__NR_SYSCALL_BASE+224)
4545  #define __NR_readahead                 (__NR_SYSCALL_BASE+225)
4546 -#if 0 /* allocated in 2.5 */
4547  #define __NR_setxattr                  (__NR_SYSCALL_BASE+226)
4548  #define __NR_lsetxattr                 (__NR_SYSCALL_BASE+227)
4549  #define __NR_fsetxattr                 (__NR_SYSCALL_BASE+228)
4550 @@ -257,7 +256,6 @@
4551  #define __NR_removexattr               (__NR_SYSCALL_BASE+235)
4552  #define __NR_lremovexattr              (__NR_SYSCALL_BASE+236)
4553  #define __NR_fremovexattr              (__NR_SYSCALL_BASE+237)
4554 -#endif
4555  #define __NR_tkill                     (__NR_SYSCALL_BASE+238)
4556  /*
4557   * Please check 2.5 _before_ adding calls here,
4558 --- linux-2.4.20/include/asm-ppc64/unistd.h~linux-2.4.20-xattr-0.8.54   2002-08-03 08:39:45.000000000 +0800
4559 +++ linux-2.4.20-root/include/asm-ppc64/unistd.h        2003-05-07 18:08:03.000000000 +0800
4560 @@ -218,6 +218,7 @@
4561  #define __NR_gettid            207
4562  #if 0 /* Reserved syscalls */
4563  #define __NR_tkill             208
4564 +#endif
4565  #define __NR_setxattr          209
4566  #define __NR_lsetxattr         210
4567  #define __NR_fsetxattr         211
4568 @@ -230,6 +231,7 @@
4569  #define __NR_removexattr       218
4570  #define __NR_lremovexattr      219
4571  #define __NR_fremovexattr      220
4572 +#if 0 /* Reserved syscalls */
4573  #define __NR_futex             221
4574  #endif
4575  
4576 --- linux-2.4.20/include/asm-s390/unistd.h~linux-2.4.20-xattr-0.8.54    2002-08-03 08:39:45.000000000 +0800
4577 +++ linux-2.4.20-root/include/asm-s390/unistd.h 2003-05-07 18:08:03.000000000 +0800
4578 @@ -212,9 +212,18 @@
4579  #define __NR_getdents64                220
4580  #define __NR_fcntl64           221
4581  #define __NR_readahead         222
4582 -/*
4583 - * Numbers 224-235 are reserved for posix acl
4584 - */
4585 +#define __NR_setxattr          224
4586 +#define __NR_lsetxattr         225
4587 +#define __NR_fsetxattr         226
4588 +#define __NR_getxattr          227
4589 +#define __NR_lgetxattr         228
4590 +#define __NR_fgetxattr         229
4591 +#define __NR_listxattr         230
4592 +#define __NR_llistxattr                231
4593 +#define __NR_flistxattr                232
4594 +#define __NR_removexattr       233
4595 +#define __NR_lremovexattr      234
4596 +#define __NR_fremovexattr      235
4597  #define __NR_gettid            236
4598  #define __NR_tkill             237
4599  
4600 --- linux-2.4.20/include/asm-s390x/unistd.h~linux-2.4.20-xattr-0.8.54   2002-08-03 08:39:45.000000000 +0800
4601 +++ linux-2.4.20-root/include/asm-s390x/unistd.h        2003-05-07 18:08:03.000000000 +0800
4602 @@ -180,9 +180,18 @@
4603  #define __NR_mincore            218
4604  #define __NR_madvise            219
4605  #define __NR_readahead         222
4606 -/*
4607 - * Numbers 224-235 are reserved for posix acl
4608 - */
4609 +#define __NR_setxattr          224
4610 +#define __NR_lsetxattr         225
4611 +#define __NR_fsetxattr         226
4612 +#define __NR_getxattr          227
4613 +#define __NR_lgetxattr         228
4614 +#define __NR_fgetxattr         229
4615 +#define __NR_listxattr         230
4616 +#define __NR_llistxattr                231
4617 +#define __NR_flistxattr                232
4618 +#define __NR_removexattr       233
4619 +#define __NR_lremovexattr      234
4620 +#define __NR_fremovexattr      235
4621  #define __NR_gettid            236
4622  #define __NR_tkill             237
4623  
4624 --- /dev/null   2003-01-30 18:24:37.000000000 +0800
4625 +++ linux-2.4.20-root/include/linux/cache_def.h 2003-05-07 18:08:03.000000000 +0800
4626 @@ -0,0 +1,15 @@
4627 +/*
4628 + * linux/cache_def.h
4629 + * Handling of caches defined in drivers, filesystems, ...
4630 + *
4631 + * Copyright (C) 2002 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
4632 + */
4633 +
4634 +struct cache_definition {
4635 +       const char *name;
4636 +       void (*shrink)(int, unsigned int);
4637 +       struct list_head link;
4638 +};
4639 +
4640 +extern void register_cache(struct cache_definition *);
4641 +extern void unregister_cache(struct cache_definition *);
4642 --- linux-2.4.20/include/linux/errno.h~linux-2.4.20-xattr-0.8.54        2003-04-14 16:39:03.000000000 +0800
4643 +++ linux-2.4.20-root/include/linux/errno.h     2003-05-07 18:08:03.000000000 +0800
4644 @@ -23,4 +23,8 @@
4645  
4646  #endif
4647  
4648 +/* Defined for extended attributes */
4649 +#define ENOATTR ENODATA                /* No such attribute */
4650 +#define ENOTSUP EOPNOTSUPP     /* Operation not supported */
4651 +
4652  #endif
4653 --- linux-2.4.20/include/linux/ext2_fs.h~linux-2.4.20-xattr-0.8.54      2003-04-14 16:39:08.000000000 +0800
4654 +++ linux-2.4.20-root/include/linux/ext2_fs.h   2003-05-07 18:08:03.000000000 +0800
4655 @@ -57,8 +57,6 @@
4656   */
4657  #define        EXT2_BAD_INO             1      /* Bad blocks inode */
4658  #define EXT2_ROOT_INO           2      /* Root inode */
4659 -#define EXT2_ACL_IDX_INO        3      /* ACL inode */
4660 -#define EXT2_ACL_DATA_INO       4      /* ACL inode */
4661  #define EXT2_BOOT_LOADER_INO    5      /* Boot loader inode */
4662  #define EXT2_UNDEL_DIR_INO      6      /* Undelete directory inode */
4663  
4664 @@ -86,7 +84,6 @@
4665  #else
4666  # define EXT2_BLOCK_SIZE(s)            (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
4667  #endif
4668 -#define EXT2_ACLE_PER_BLOCK(s)         (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
4669  #define        EXT2_ADDR_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
4670  #ifdef __KERNEL__
4671  # define EXT2_BLOCK_SIZE_BITS(s)       ((s)->s_blocksize_bits)
4672 @@ -121,28 +118,6 @@
4673  #endif
4674  
4675  /*
4676 - * ACL structures
4677 - */
4678 -struct ext2_acl_header /* Header of Access Control Lists */
4679 -{
4680 -       __u32   aclh_size;
4681 -       __u32   aclh_file_count;
4682 -       __u32   aclh_acle_count;
4683 -       __u32   aclh_first_acle;
4684 -};
4685 -
4686 -struct ext2_acl_entry  /* Access Control List Entry */
4687 -{
4688 -       __u32   acle_size;
4689 -       __u16   acle_perms;     /* Access permissions */
4690 -       __u16   acle_type;      /* Type of entry */
4691 -       __u16   acle_tag;       /* User or group identity */
4692 -       __u16   acle_pad1;
4693 -       __u32   acle_next;      /* Pointer on next entry for the */
4694 -                                       /* same inode or on next free entry */
4695 -};
4696 -
4697 -/*
4698   * Structure of a blocks group descriptor
4699   */
4700  struct ext2_group_desc
4701 @@ -314,6 +289,7 @@ struct ext2_inode {
4702  #define EXT2_MOUNT_ERRORS_PANIC                0x0040  /* Panic on errors */
4703  #define EXT2_MOUNT_MINIX_DF            0x0080  /* Mimics the Minix statfs */
4704  #define EXT2_MOUNT_NO_UID32            0x0200  /* Disable 32-bit UIDs */
4705 +#define EXT2_MOUNT_XATTR_USER          0x4000  /* Extended user attributes */
4706  
4707  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
4708  #define set_opt(o, opt)                        o |= EXT2_MOUNT_##opt
4709 @@ -397,6 +373,7 @@ struct ext2_super_block {
4710  
4711  #ifdef __KERNEL__
4712  #define EXT2_SB(sb)    (&((sb)->u.ext2_sb))
4713 +#define EXT2_I(inode)  (&((inode)->u.ext2_i))
4714  #else
4715  /* Assume that user mode programs are passing in an ext2fs superblock, not
4716   * a kernel struct super_block.  This will allow us to call the feature-test
4717 @@ -466,7 +443,7 @@ struct ext2_super_block {
4718  #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV      0x0008
4719  #define EXT2_FEATURE_INCOMPAT_ANY              0xffffffff
4720  
4721 -#define EXT2_FEATURE_COMPAT_SUPP       0
4722 +#define EXT2_FEATURE_COMPAT_SUPP       EXT2_FEATURE_COMPAT_EXT_ATTR
4723  #define EXT2_FEATURE_INCOMPAT_SUPP     EXT2_FEATURE_INCOMPAT_FILETYPE
4724  #define EXT2_FEATURE_RO_COMPAT_SUPP    (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
4725                                          EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
4726 @@ -623,8 +600,10 @@ extern struct address_space_operations e
4727  
4728  /* namei.c */
4729  extern struct inode_operations ext2_dir_inode_operations;
4730 +extern struct inode_operations ext2_special_inode_operations;
4731  
4732  /* symlink.c */
4733 +extern struct inode_operations ext2_symlink_inode_operations;
4734  extern struct inode_operations ext2_fast_symlink_inode_operations;
4735  
4736  #endif /* __KERNEL__ */
4737 --- /dev/null   2003-01-30 18:24:37.000000000 +0800
4738 +++ linux-2.4.20-root/include/linux/ext2_xattr.h        2003-05-07 18:08:03.000000000 +0800
4739 @@ -0,0 +1,157 @@
4740 +/*
4741 +  File: linux/ext2_xattr.h
4742 +
4743 +  On-disk format of extended attributes for the ext2 filesystem.
4744 +
4745 +  (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
4746 +*/
4747 +
4748 +#include <linux/config.h>
4749 +#include <linux/init.h>
4750 +#include <linux/xattr.h>
4751 +
4752 +/* Magic value in attribute blocks */
4753 +#define EXT2_XATTR_MAGIC               0xEA020000
4754 +
4755 +/* Maximum number of references to one attribute block */
4756 +#define EXT2_XATTR_REFCOUNT_MAX                1024
4757 +
4758 +/* Name indexes */
4759 +#define EXT2_XATTR_INDEX_MAX                   10
4760 +#define EXT2_XATTR_INDEX_USER                  1
4761 +#define EXT2_XATTR_INDEX_POSIX_ACL_ACCESS      2
4762 +#define EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT     3
4763 +
4764 +struct ext2_xattr_header {
4765 +       __u32   h_magic;        /* magic number for identification */
4766 +       __u32   h_refcount;     /* reference count */
4767 +       __u32   h_blocks;       /* number of disk blocks used */
4768 +       __u32   h_hash;         /* hash value of all attributes */
4769 +       __u32   h_reserved[4];  /* zero right now */
4770 +};
4771 +
4772 +struct ext2_xattr_entry {
4773 +       __u8    e_name_len;     /* length of name */
4774 +       __u8    e_name_index;   /* attribute name index */
4775 +       __u16   e_value_offs;   /* offset in disk block of value */
4776 +       __u32   e_value_block;  /* disk block attribute is stored on (n/i) */
4777 +       __u32   e_value_size;   /* size of attribute value */
4778 +       __u32   e_hash;         /* hash value of name and value */
4779 +       char    e_name[0];      /* attribute name */
4780 +};
4781 +
4782 +#define EXT2_XATTR_PAD_BITS            2
4783 +#define EXT2_XATTR_PAD         (1<<EXT2_XATTR_PAD_BITS)
4784 +#define EXT2_XATTR_ROUND               (EXT2_XATTR_PAD-1)
4785 +#define EXT2_XATTR_LEN(name_len) \
4786 +       (((name_len) + EXT2_XATTR_ROUND + \
4787 +       sizeof(struct ext2_xattr_entry)) & ~EXT2_XATTR_ROUND)
4788 +#define EXT2_XATTR_NEXT(entry) \
4789 +       ( (struct ext2_xattr_entry *)( \
4790 +         (char *)(entry) + EXT2_XATTR_LEN((entry)->e_name_len)) )
4791 +#define EXT2_XATTR_SIZE(size) \
4792 +       (((size) + EXT2_XATTR_ROUND) & ~EXT2_XATTR_ROUND)
4793 +
4794 +#ifdef __KERNEL__
4795 +
4796 +# ifdef CONFIG_EXT2_FS_XATTR
4797 +
4798 +struct ext2_xattr_handler {
4799 +       char *prefix;
4800 +       size_t (*list)(char *list, struct inode *inode, const char *name,
4801 +                      int name_len);
4802 +       int (*get)(struct inode *inode, const char *name, void *buffer,
4803 +                  size_t size);
4804 +       int (*set)(struct inode *inode, const char *name, const void *buffer,
4805 +                  size_t size, int flags);
4806 +};
4807 +
4808 +extern int ext2_xattr_register(int, struct ext2_xattr_handler *);
4809 +extern void ext2_xattr_unregister(int, struct ext2_xattr_handler *);
4810 +
4811 +extern int ext2_setxattr(struct dentry *, const char *, const void *, size_t, int);
4812 +extern ssize_t ext2_getxattr(struct dentry *, const char *, void *, size_t);
4813 +extern ssize_t ext2_listxattr(struct dentry *, char *, size_t);
4814 +extern int ext2_removexattr(struct dentry *, const char *);
4815 +
4816 +extern int ext2_xattr_get(struct inode *, int, const char *, void *, size_t);
4817 +extern int ext2_xattr_list(struct inode *, char *, size_t);
4818 +extern int ext2_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
4819 +
4820 +extern void ext2_xattr_delete_inode(struct inode *);
4821 +extern void ext2_xattr_put_super(struct super_block *);
4822 +
4823 +extern int init_ext2_xattr(void) __init;
4824 +extern void exit_ext2_xattr(void);
4825 +
4826 +# else  /* CONFIG_EXT2_FS_XATTR */
4827 +#  define ext2_setxattr                NULL
4828 +#  define ext2_getxattr                NULL
4829 +#  define ext2_listxattr       NULL
4830 +#  define ext2_removexattr     NULL
4831 +
4832 +static inline int
4833 +ext2_xattr_get(struct inode *inode, int name_index,
4834 +              const char *name, void *buffer, size_t size)
4835 +{
4836 +       return -ENOTSUP;
4837 +}
4838 +
4839 +static inline int
4840 +ext2_xattr_list(struct inode *inode, char *buffer, size_t size)
4841 +{
4842 +       return -ENOTSUP;
4843 +}
4844 +
4845 +static inline int
4846 +ext2_xattr_set(struct inode *inode, int name_index, const char *name,
4847 +              const void *value, size_t size, int flags)
4848 +{
4849 +       return -ENOTSUP;
4850 +}
4851 +
4852 +static inline void
4853 +ext2_xattr_delete_inode(struct inode *inode)
4854 +{
4855 +}
4856 +
4857 +static inline void
4858 +ext2_xattr_put_super(struct super_block *sb)
4859 +{
4860 +}
4861 +
4862 +static inline int
4863 +init_ext2_xattr(void)
4864 +{
4865 +       return 0;
4866 +}
4867 +
4868 +static inline void
4869 +exit_ext2_xattr(void)
4870 +{
4871 +}
4872 +
4873 +# endif  /* CONFIG_EXT2_FS_XATTR */
4874 +
4875 +# ifdef CONFIG_EXT2_FS_XATTR_USER
4876 +
4877 +extern int init_ext2_xattr_user(void) __init;
4878 +extern void exit_ext2_xattr_user(void);
4879 +
4880 +# else  /* CONFIG_EXT2_FS_XATTR_USER */
4881 +
4882 +static inline int
4883 +init_ext2_xattr_user(void)
4884 +{
4885 +       return 0;
4886 +}
4887 +
4888 +static inline void
4889 +exit_ext2_xattr_user(void)
4890 +{
4891 +}
4892 +
4893 +# endif  /* CONFIG_EXT2_FS_XATTR_USER */
4894 +
4895 +#endif  /* __KERNEL__ */
4896 +
4897 --- linux-2.4.20/include/linux/ext3_fs.h~linux-2.4.20-xattr-0.8.54      2003-05-05 19:01:04.000000000 +0800
4898 +++ linux-2.4.20-root/include/linux/ext3_fs.h   2003-05-07 18:08:03.000000000 +0800
4899 @@ -63,8 +63,6 @@
4900   */
4901  #define        EXT3_BAD_INO             1      /* Bad blocks inode */
4902  #define EXT3_ROOT_INO           2      /* Root inode */
4903 -#define EXT3_ACL_IDX_INO        3      /* ACL inode */
4904 -#define EXT3_ACL_DATA_INO       4      /* ACL inode */
4905  #define EXT3_BOOT_LOADER_INO    5      /* Boot loader inode */
4906  #define EXT3_UNDEL_DIR_INO      6      /* Undelete directory inode */
4907  #define EXT3_RESIZE_INO                 7      /* Reserved group descriptors inode */
4908 @@ -94,7 +92,6 @@
4909  #else
4910  # define EXT3_BLOCK_SIZE(s)            (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
4911  #endif
4912 -#define EXT3_ACLE_PER_BLOCK(s)         (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_acl_entry))
4913  #define        EXT3_ADDR_PER_BLOCK(s)          (EXT3_BLOCK_SIZE(s) / sizeof (__u32))
4914  #ifdef __KERNEL__
4915  # define EXT3_BLOCK_SIZE_BITS(s)       ((s)->s_blocksize_bits)
4916 @@ -129,28 +126,6 @@
4917  #endif
4918  
4919  /*
4920 - * ACL structures
4921 - */
4922 -struct ext3_acl_header /* Header of Access Control Lists */
4923 -{
4924 -       __u32   aclh_size;
4925 -       __u32   aclh_file_count;
4926 -       __u32   aclh_acle_count;
4927 -       __u32   aclh_first_acle;
4928 -};
4929 -
4930 -struct ext3_acl_entry  /* Access Control List Entry */
4931 -{
4932 -       __u32   acle_size;
4933 -       __u16   acle_perms;     /* Access permissions */
4934 -       __u16   acle_type;      /* Type of entry */
4935 -       __u16   acle_tag;       /* User or group identity */
4936 -       __u16   acle_pad1;
4937 -       __u32   acle_next;      /* Pointer on next entry for the */
4938 -                                       /* same inode or on next free entry */
4939 -};
4940 -
4941 -/*
4942   * Structure of a blocks group descriptor
4943   */
4944  struct ext3_group_desc
4945 @@ -344,6 +319,7 @@ struct ext3_inode {
4946    #define EXT3_MOUNT_WRITEBACK_DATA    0x0C00  /* No data ordering */
4947  #define EXT3_MOUNT_UPDATE_JOURNAL      0x1000  /* Update the journal format */
4948  #define EXT3_MOUNT_NO_UID32            0x2000  /* Disable 32-bit UIDs */
4949 +#define EXT3_MOUNT_XATTR_USER          0x4000  /* Extended user attributes */
4950  
4951  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
4952  #ifndef _LINUX_EXT2_FS_H
4953 @@ -520,7 +496,7 @@ struct ext3_super_block {
4954  #define EXT3_FEATURE_INCOMPAT_RECOVER          0x0004 /* Needs recovery */
4955  #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV      0x0008 /* Journal device */
4956  
4957 -#define EXT3_FEATURE_COMPAT_SUPP       0
4958 +#define EXT3_FEATURE_COMPAT_SUPP       EXT2_FEATURE_COMPAT_EXT_ATTR
4959  #define EXT3_FEATURE_INCOMPAT_SUPP     (EXT3_FEATURE_INCOMPAT_FILETYPE| \
4960                                          EXT3_FEATURE_INCOMPAT_RECOVER)
4961  #define EXT3_FEATURE_RO_COMPAT_SUPP    (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
4962 @@ -703,6 +679,7 @@ extern void ext3_check_inodes_bitmap (st
4963  extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
4964  
4965  /* inode.c */
4966 +extern int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
4967  extern struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
4968  extern struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
4969  
4970 @@ -771,8 +748,10 @@ extern struct address_space_operations e
4971  
4972  /* namei.c */
4973  extern struct inode_operations ext3_dir_inode_operations;
4974 +extern struct inode_operations ext3_special_inode_operations;
4975  
4976  /* symlink.c */
4977 +extern struct inode_operations ext3_symlink_inode_operations;
4978  extern struct inode_operations ext3_fast_symlink_inode_operations;
4979  
4980  
4981 --- linux-2.4.20/include/linux/ext3_jbd.h~linux-2.4.20-xattr-0.8.54     2003-05-05 19:01:02.000000000 +0800
4982 +++ linux-2.4.20-root/include/linux/ext3_jbd.h  2003-05-07 18:08:03.000000000 +0800
4983 @@ -30,13 +30,19 @@
4984  
4985  #define EXT3_SINGLEDATA_TRANS_BLOCKS   8
4986  
4987 +/* Extended attributes may touch two data buffers, two bitmap buffers,
4988 + * and two group and summaries. */
4989 +
4990 +#define EXT3_XATTR_TRANS_BLOCKS                8
4991 +
4992  /* Define the minimum size for a transaction which modifies data.  This
4993   * needs to take into account the fact that we may end up modifying two
4994   * quota files too (one for the group, one for the user quota).  The
4995   * superblock only gets updated once, of course, so don't bother
4996   * counting that again for the quota updates. */
4997  
4998 -#define EXT3_DATA_TRANS_BLOCKS         (3 * EXT3_SINGLEDATA_TRANS_BLOCKS - 2)
4999 +#define EXT3_DATA_TRANS_BLOCKS         (3 * EXT3_SINGLEDATA_TRANS_BLOCKS + \
5000 +                                        EXT3_XATTR_TRANS_BLOCKS - 2)
5001  
5002  extern int ext3_writepage_trans_blocks(struct inode *inode);
5003  
5004 --- /dev/null   2003-01-30 18:24:37.000000000 +0800
5005 +++ linux-2.4.20-root/include/linux/ext3_xattr.h        2003-05-07 18:08:03.000000000 +0800
5006 @@ -0,0 +1,157 @@
5007 +/*
5008 +  File: linux/ext3_xattr.h
5009 +
5010 +  On-disk format of extended attributes for the ext3 filesystem.
5011 +
5012 +  (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
5013 +*/
5014 +
5015 +#include <linux/config.h>
5016 +#include <linux/init.h>
5017 +#include <linux/xattr.h>
5018 +
5019 +/* Magic value in attribute blocks */
5020 +#define EXT3_XATTR_MAGIC               0xEA020000
5021 +
5022 +/* Maximum number of references to one attribute block */
5023 +#define EXT3_XATTR_REFCOUNT_MAX                1024
5024 +
5025 +/* Name indexes */
5026 +#define EXT3_XATTR_INDEX_MAX                   10
5027 +#define EXT3_XATTR_INDEX_USER                  1
5028 +#define EXT3_XATTR_INDEX_POSIX_ACL_ACCESS      2
5029 +#define EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT     3
5030 +
5031 +struct ext3_xattr_header {
5032 +       __u32   h_magic;        /* magic number for identification */
5033 +       __u32   h_refcount;     /* reference count */
5034 +       __u32   h_blocks;       /* number of disk blocks used */
5035 +       __u32   h_hash;         /* hash value of all attributes */
5036 +       __u32   h_reserved[4];  /* zero right now */
5037 +};
5038 +
5039 +struct ext3_xattr_entry {
5040 +       __u8    e_name_len;     /* length of name */
5041 +       __u8    e_name_index;   /* attribute name index */
5042 +       __u16   e_value_offs;   /* offset in disk block of value */
5043 +       __u32   e_value_block;  /* disk block attribute is stored on (n/i) */
5044 +       __u32   e_value_size;   /* size of attribute value */
5045 +       __u32   e_hash;         /* hash value of name and value */
5046 +       char    e_name[0];      /* attribute name */
5047 +};
5048 +
5049 +#define EXT3_XATTR_PAD_BITS            2
5050 +#define EXT3_XATTR_PAD         (1<<EXT3_XATTR_PAD_BITS)
5051 +#define EXT3_XATTR_ROUND               (EXT3_XATTR_PAD-1)
5052 +#define EXT3_XATTR_LEN(name_len) \
5053 +       (((name_len) + EXT3_XATTR_ROUND + \
5054 +       sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND)
5055 +#define EXT3_XATTR_NEXT(entry) \
5056 +       ( (struct ext3_xattr_entry *)( \
5057 +         (char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) )
5058 +#define EXT3_XATTR_SIZE(size) \
5059 +       (((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND)
5060 +
5061 +#ifdef __KERNEL__
5062 +
5063 +# ifdef CONFIG_EXT3_FS_XATTR
5064 +
5065 +struct ext3_xattr_handler {
5066 +       char *prefix;
5067 +       size_t (*list)(char *list, struct inode *inode, const char *name,
5068 +                      int name_len);
5069 +       int (*get)(struct inode *inode, const char *name, void *buffer,
5070 +                  size_t size);
5071 +       int (*set)(struct inode *inode, const char *name, const void *buffer,
5072 +                  size_t size, int flags);
5073 +};
5074 +
5075 +extern int ext3_xattr_register(int, struct ext3_xattr_handler *);
5076 +extern void ext3_xattr_unregister(int, struct ext3_xattr_handler *);
5077 +
5078 +extern int ext3_setxattr(struct dentry *, const char *, const void *, size_t, int);
5079 +extern ssize_t ext3_getxattr(struct dentry *, const char *, void *, size_t);
5080 +extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
5081 +extern int ext3_removexattr(struct dentry *, const char *);
5082 +
5083 +extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
5084 +extern int ext3_xattr_list(struct inode *, char *, size_t);
5085 +extern int ext3_xattr_set(handle_t *handle, struct inode *, int, const char *, const void *, size_t, int);
5086 +
5087 +extern void ext3_xattr_delete_inode(handle_t *, struct inode *);
5088 +extern void ext3_xattr_put_super(struct super_block *);
5089 +
5090 +extern int init_ext3_xattr(void) __init;
5091 +extern void exit_ext3_xattr(void);
5092 +
5093 +# else  /* CONFIG_EXT3_FS_XATTR */
5094 +#  define ext3_setxattr                NULL
5095 +#  define ext3_getxattr                NULL
5096 +#  define ext3_listxattr       NULL
5097 +#  define ext3_removexattr     NULL
5098 +
5099 +static inline int
5100 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
5101 +              void *buffer, size_t size)
5102 +{
5103 +       return -ENOTSUP;
5104 +}
5105 +
5106 +static inline int
5107 +ext3_xattr_list(struct inode *inode, void *buffer, size_t size)
5108 +{
5109 +       return -ENOTSUP;
5110 +}
5111 +
5112 +static inline int
5113 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
5114 +              const char *name, const void *value, size_t size, int flags)
5115 +{
5116 +       return -ENOTSUP;
5117 +}
5118 +
5119 +static inline void
5120 +ext3_xattr_delete_inode(handle_t *handle, struct inode *inode)
5121 +{
5122 +}
5123 +
5124 +static inline void
5125 +ext3_xattr_put_super(struct super_block *sb)
5126 +{
5127 +}
5128 +
5129 +static inline int
5130 +init_ext3_xattr(void)
5131 +{
5132 +       return 0;
5133 +}
5134 +
5135 +static inline void
5136 +exit_ext3_xattr(void)
5137 +{
5138 +}
5139 +
5140 +# endif  /* CONFIG_EXT3_FS_XATTR */
5141 +
5142 +# ifdef CONFIG_EXT3_FS_XATTR_USER
5143 +
5144 +extern int init_ext3_xattr_user(void) __init;
5145 +extern void exit_ext3_xattr_user(void);
5146 +
5147 +# else  /* CONFIG_EXT3_FS_XATTR_USER */
5148 +
5149 +static inline int
5150 +init_ext3_xattr_user(void)
5151 +{
5152 +       return 0;
5153 +}
5154 +
5155 +static inline void
5156 +exit_ext3_xattr_user(void)
5157 +{
5158 +}
5159 +
5160 +#endif  /* CONFIG_EXT3_FS_XATTR_USER */
5161 +
5162 +#endif  /* __KERNEL__ */
5163 +
5164 --- linux-2.4.20/include/linux/fs.h~linux-2.4.20-xattr-0.8.54   2003-05-05 19:00:55.000000000 +0800
5165 +++ linux-2.4.20-root/include/linux/fs.h        2003-05-07 18:08:03.000000000 +0800
5166 @@ -888,7 +888,7 @@ struct inode_operations {
5167         int (*setattr) (struct dentry *, struct iattr *);
5168         int (*setattr_raw) (struct inode *, struct iattr *);
5169         int (*getattr) (struct dentry *, struct iattr *);
5170 -       int (*setxattr) (struct dentry *, const char *, void *, size_t, int);
5171 +       int (*setxattr) (struct dentry *, const char *, const void *, size_t, int);
5172         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
5173         ssize_t (*listxattr) (struct dentry *, char *, size_t);
5174         int (*removexattr) (struct dentry *, const char *);
5175 --- /dev/null   2003-01-30 18:24:37.000000000 +0800
5176 +++ linux-2.4.20-root/include/linux/mbcache.h   2003-05-07 18:08:03.000000000 +0800
5177 @@ -0,0 +1,69 @@
5178 +/*
5179 +  File: linux/mbcache.h
5180 +
5181 +  (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
5182 +*/
5183 +
5184 +/* Hardwire the number of additional indexes */
5185 +#define MB_CACHE_INDEXES_COUNT 1
5186 +
5187 +struct mb_cache_entry;
5188 +
5189 +struct mb_cache_op {
5190 +       int (*free)(struct mb_cache_entry *, int);
5191 +};
5192 +
5193 +struct mb_cache {
5194 +       struct list_head                c_cache_list;
5195 +       const char                      *c_name;
5196 +       struct mb_cache_op              c_op;
5197 +       atomic_t                        c_entry_count;
5198 +       int                             c_bucket_count;
5199 +#ifndef MB_CACHE_INDEXES_COUNT
5200 +       int                             c_indexes_count;
5201 +#endif
5202 +       kmem_cache_t                    *c_entry_cache;
5203 +       struct list_head                *c_block_hash;
5204 +       struct list_head                *c_indexes_hash[0];
5205 +};
5206 +
5207 +struct mb_cache_entry_index {
5208 +       struct list_head                o_list;
5209 +       unsigned int                    o_key;
5210 +};
5211 +
5212 +struct mb_cache_entry {
5213 +       struct list_head                e_lru_list;
5214 +       struct mb_cache                 *e_cache;
5215 +       atomic_t                        e_used;
5216 +       kdev_t                          e_dev;
5217 +       unsigned long                   e_block;
5218 +       struct list_head                e_block_list;
5219 +       struct mb_cache_entry_index     e_indexes[0];
5220 +};
5221 +
5222 +/* Functions on caches */
5223 +
5224 +struct mb_cache * mb_cache_create(const char *, struct mb_cache_op *, size_t,
5225 +                                 int, int);
5226 +void mb_cache_shrink(struct mb_cache *, kdev_t);
5227 +void mb_cache_destroy(struct mb_cache *);
5228 +
5229 +/* Functions on cache entries */
5230 +
5231 +struct mb_cache_entry *mb_cache_entry_alloc(struct mb_cache *);
5232 +int mb_cache_entry_insert(struct mb_cache_entry *, kdev_t, unsigned long,
5233 +                         unsigned int[]);
5234 +void mb_cache_entry_rehash(struct mb_cache_entry *, unsigned int[]);
5235 +void mb_cache_entry_release(struct mb_cache_entry *);
5236 +void mb_cache_entry_takeout(struct mb_cache_entry *);
5237 +void mb_cache_entry_free(struct mb_cache_entry *);
5238 +struct mb_cache_entry *mb_cache_entry_dup(struct mb_cache_entry *);
5239 +struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *, kdev_t,
5240 +                                         unsigned long);
5241 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
5242 +struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache, int,
5243 +                                                kdev_t, unsigned int);
5244 +struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache_entry *, int,
5245 +                                               kdev_t, unsigned int);
5246 +#endif
5247 --- linux-2.4.20/kernel/ksyms.c~linux-2.4.20-xattr-0.8.54       2003-05-05 17:43:15.000000000 +0800
5248 +++ linux-2.4.20-root/kernel/ksyms.c    2003-05-07 18:08:03.000000000 +0800
5249 @@ -11,6 +11,7 @@
5250  
5251  #include <linux/config.h>
5252  #include <linux/slab.h>
5253 +#include <linux/cache_def.h>
5254  #include <linux/module.h>
5255  #include <linux/blkdev.h>
5256  #include <linux/cdrom.h>
5257 @@ -89,6 +90,7 @@ EXPORT_SYMBOL(exit_mm);
5258  EXPORT_SYMBOL(exit_files);
5259  EXPORT_SYMBOL(exit_fs);
5260  EXPORT_SYMBOL(exit_sighand);
5261 +EXPORT_SYMBOL(copy_fs_struct);
5262  
5263  /* internal kernel memory management */
5264  EXPORT_SYMBOL(_alloc_pages);
5265 @@ -107,6 +109,8 @@ EXPORT_SYMBOL(kmem_cache_validate);
5266  EXPORT_SYMBOL(kmem_cache_alloc);
5267  EXPORT_SYMBOL(kmem_cache_free);
5268  EXPORT_SYMBOL(kmem_cache_size);
5269 +EXPORT_SYMBOL(register_cache);
5270 +EXPORT_SYMBOL(unregister_cache);
5271  EXPORT_SYMBOL(kmalloc);
5272  EXPORT_SYMBOL(kfree);
5273  EXPORT_SYMBOL(vfree);
5274 --- linux-2.4.20/mm/vmscan.c~linux-2.4.20-xattr-0.8.54  2002-11-29 07:53:15.000000000 +0800
5275 +++ linux-2.4.20-root/mm/vmscan.c       2003-05-07 18:08:03.000000000 +0800
5276 @@ -18,6 +18,7 @@
5277  #include <linux/kernel_stat.h>
5278  #include <linux/swap.h>
5279  #include <linux/swapctl.h>
5280 +#include <linux/cache_def.h>
5281  #include <linux/smp_lock.h>
5282  #include <linux/pagemap.h>
5283  #include <linux/init.h>
5284 @@ -34,6 +35,39 @@
5285   */
5286  #define DEF_PRIORITY (6)
5287  
5288 +static DECLARE_MUTEX(other_caches_sem);
5289 +static LIST_HEAD(cache_definitions);
5290 +
5291 +void register_cache(struct cache_definition *cache)
5292 +{
5293 +       down(&other_caches_sem);
5294 +       list_add(&cache->link, &cache_definitions);
5295 +       up(&other_caches_sem);
5296 +}
5297 +
5298 +void unregister_cache(struct cache_definition *cache)
5299 +{
5300 +       down(&other_caches_sem);
5301 +       list_del(&cache->link);
5302 +       up(&other_caches_sem);
5303 +}
5304 +
5305 +static void shrink_other_caches(unsigned int priority, int gfp_mask)
5306 +{
5307 +       struct list_head *p;
5308 +
5309 +       if (down_trylock(&other_caches_sem))
5310 +               return;
5311 +
5312 +       list_for_each_prev(p, &cache_definitions) {
5313 +               struct cache_definition *cache =
5314 +                       list_entry(p, struct cache_definition, link);
5315 +
5316 +               cache->shrink(priority, gfp_mask);
5317 +       }
5318 +       up(&other_caches_sem);
5319 +}
5320 +
5321  /*
5322   * The swap-out function returns 1 if it successfully
5323   * scanned all the pages it was asked to (`count').
5324 @@ -577,6 +611,7 @@ static int shrink_caches(zone_t * classz
5325  
5326         shrink_dcache_memory(priority, gfp_mask);
5327         shrink_icache_memory(priority, gfp_mask);
5328 +       shrink_other_caches(priority, gfp_mask);
5329  #ifdef CONFIG_QUOTA
5330         shrink_dqcache_memory(DEF_PRIORITY, gfp_mask);
5331  #endif
5332 --- /dev/null   2003-01-30 18:24:37.000000000 +0800
5333 +++ linux-root/fs/ext3/ext3-exports.c   2003-05-05 18:19:11.000000000 +0800
5334 @@ -0,0 +1,13 @@
5335 +#include <linux/config.h>
5336 +#include <linux/module.h>
5337 +#include <linux/ext3_fs.h>
5338 +#include <linux/ext3_jbd.h>
5339 +#include <linux/ext3_xattr.h>
5340 +
5341 +EXPORT_SYMBOL(ext3_force_commit);
5342 +EXPORT_SYMBOL(ext3_bread);
5343 +EXPORT_SYMBOL(ext3_xattr_register);
5344 +EXPORT_SYMBOL(ext3_xattr_unregister);
5345 +EXPORT_SYMBOL(ext3_xattr_get);
5346 +EXPORT_SYMBOL(ext3_xattr_list);
5347 +EXPORT_SYMBOL(ext3_xattr_set);
5348
5349 _