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