Whamcloud - gitweb
b=10651
[fs/lustre-release.git] / lustre / kernel_patches / patches / linux-2.4.24-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.24-vanilla/Documentation/Configure.help
68 ===================================================================
69 --- linux-2.4.24-vanilla.orig/Documentation/Configure.help      2004-01-10 17:05:37.000000000 +0300
70 +++ linux-2.4.24-vanilla/Documentation/Configure.help   2004-01-10 17:20:28.000000000 +0300
71 @@ -16295,6 +16295,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 @@ -16327,6 +16360,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.24-vanilla/arch/alpha/defconfig
152 ===================================================================
153 --- linux-2.4.24-vanilla.orig/arch/alpha/defconfig      2004-01-10 17:04:37.000000000 +0300
154 +++ linux-2.4.24-vanilla/arch/alpha/defconfig   2004-01-10 17:20:28.000000000 +0300
155 @@ -1,6 +1,13 @@
156  #
157  # Automatically generated make config: don't edit
158  #
159 +CONFIG_EXT3_FS_XATTR=y
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.24-vanilla/arch/alpha/kernel/entry.S
170 ===================================================================
171 --- linux-2.4.24-vanilla.orig/arch/alpha/kernel/entry.S 2004-01-10 17:04:37.000000000 +0300
172 +++ linux-2.4.24-vanilla/arch/alpha/kernel/entry.S      2004-01-10 17:20:28.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.24-vanilla/arch/arm/defconfig
193 ===================================================================
194 --- linux-2.4.24-vanilla.orig/arch/arm/defconfig        2001-05-20 04:43:05.000000000 +0400
195 +++ linux-2.4.24-vanilla/arch/arm/defconfig     2004-01-10 17:20:28.000000000 +0300
196 @@ -1,6 +1,13 @@
197  #
198  # Automatically generated make config: don't edit
199  #
200 +CONFIG_EXT3_FS_XATTR=y
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.24-vanilla/arch/arm/kernel/calls.S
211 ===================================================================
212 --- linux-2.4.24-vanilla.orig/arch/arm/kernel/calls.S   2004-01-10 17:04:58.000000000 +0300
213 +++ linux-2.4.24-vanilla/arch/arm/kernel/calls.S        2004-01-10 17:20:28.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.24-vanilla/arch/i386/defconfig
246 ===================================================================
247 --- linux-2.4.24-vanilla.orig/arch/i386/defconfig       2004-01-10 17:05:45.000000000 +0300
248 +++ linux-2.4.24-vanilla/arch/i386/defconfig    2004-01-10 17:20:28.000000000 +0300
249 @@ -1,6 +1,13 @@
250  #
251  # Automatically generated make config: don't edit
252  #
253 +CONFIG_EXT3_FS_XATTR=y
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.24-vanilla/arch/ia64/defconfig
264 ===================================================================
265 --- linux-2.4.24-vanilla.orig/arch/ia64/defconfig       2004-01-10 17:05:52.000000000 +0300
266 +++ linux-2.4.24-vanilla/arch/ia64/defconfig    2004-01-10 17:20:28.000000000 +0300
267 @@ -1,6 +1,13 @@
268  #
269  # Automatically generated make config: don't edit
270  #
271 +CONFIG_EXT3_FS_XATTR=y
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.24-vanilla/arch/m68k/defconfig
282 ===================================================================
283 --- linux-2.4.24-vanilla.orig/arch/m68k/defconfig       2004-01-10 17:05:52.000000000 +0300
284 +++ linux-2.4.24-vanilla/arch/m68k/defconfig    2004-01-10 17:20:28.000000000 +0300
285 @@ -1,6 +1,13 @@
286  #
287  # Automatically generated make config: don't edit
288  #
289 +CONFIG_EXT3_FS_XATTR=y
290 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
291 +# CONFIG_EXT3_FS_XATTR_USER is not set
292 +# CONFIG_EXT2_FS_XATTR is not set
293 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
294 +# CONFIG_EXT2_FS_XATTR_USER is not set
295 +# CONFIG_FS_MBCACHE is not set
296  CONFIG_UID16=y
297  
298  #
299 Index: linux-2.4.24-vanilla/arch/mips/defconfig
300 ===================================================================
301 --- linux-2.4.24-vanilla.orig/arch/mips/defconfig       2004-01-10 17:04:59.000000000 +0300
302 +++ linux-2.4.24-vanilla/arch/mips/defconfig    2004-01-10 17:20:28.000000000 +0300
303 @@ -1,6 +1,13 @@
304  #
305  # Automatically generated make config: don't edit
306  #
307 +CONFIG_EXT3_FS_XATTR=y
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.24-vanilla/arch/mips64/defconfig
318 ===================================================================
319 --- linux-2.4.24-vanilla.orig/arch/mips64/defconfig     2004-01-10 17:05:52.000000000 +0300
320 +++ linux-2.4.24-vanilla/arch/mips64/defconfig  2004-01-10 17:20:28.000000000 +0300
321 @@ -1,6 +1,13 @@
322  #
323  # Automatically generated make config: don't edit
324  #
325 +CONFIG_EXT3_FS_XATTR=y
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.24-vanilla/arch/s390/defconfig
336 ===================================================================
337 --- linux-2.4.24-vanilla.orig/arch/s390/defconfig       2004-01-10 17:05:52.000000000 +0300
338 +++ linux-2.4.24-vanilla/arch/s390/defconfig    2004-01-10 17:20:28.000000000 +0300
339 @@ -1,6 +1,13 @@
340  #
341  # Automatically generated make config: don't edit
342  #
343 +CONFIG_EXT3_FS_XATTR=y
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.24-vanilla/arch/s390/kernel/entry.S
354 ===================================================================
355 --- linux-2.4.24-vanilla.orig/arch/s390/kernel/entry.S  2004-01-10 17:04:39.000000000 +0300
356 +++ linux-2.4.24-vanilla/arch/s390/kernel/entry.S       2004-01-10 17:20:28.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.24-vanilla/arch/s390x/defconfig
389 ===================================================================
390 --- linux-2.4.24-vanilla.orig/arch/s390x/defconfig      2004-01-10 17:05:52.000000000 +0300
391 +++ linux-2.4.24-vanilla/arch/s390x/defconfig   2004-01-10 17:20:28.000000000 +0300
392 @@ -1,6 +1,13 @@
393  #
394  # Automatically generated make config: don't edit
395  #
396 +CONFIG_EXT3_FS_XATTR=y
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.24-vanilla/arch/s390x/kernel/entry.S
407 ===================================================================
408 --- linux-2.4.24-vanilla.orig/arch/s390x/kernel/entry.S 2004-01-10 17:05:00.000000000 +0300
409 +++ linux-2.4.24-vanilla/arch/s390x/kernel/entry.S      2004-01-10 17:20:28.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.24-vanilla/arch/s390x/kernel/wrapper32.S
442 ===================================================================
443 --- linux-2.4.24-vanilla.orig/arch/s390x/kernel/wrapper32.S     2004-01-10 17:05:00.000000000 +0300
444 +++ linux-2.4.24-vanilla/arch/s390x/kernel/wrapper32.S  2004-01-10 17:20:28.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.24-vanilla/arch/sparc64/defconfig
545 ===================================================================
546 --- linux-2.4.24-vanilla.orig/arch/sparc64/defconfig    2004-01-10 17:05:52.000000000 +0300
547 +++ linux-2.4.24-vanilla/arch/sparc64/defconfig 2004-01-10 17:20:28.000000000 +0300
548 @@ -1,6 +1,13 @@
549  #
550  # Automatically generated make config: don't edit
551  #
552 +CONFIG_EXT3_FS_XATTR=y
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.24-vanilla/fs/Config.in
563 ===================================================================
564 --- linux-2.4.24-vanilla.orig/fs/Config.in      2004-01-10 17:05:55.000000000 +0300
565 +++ linux-2.4.24-vanilla/fs/Config.in   2004-01-10 17:20:28.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 @@ -92,6 +97,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 @@ -164,6 +174,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.24-vanilla/fs/Makefile
602 ===================================================================
603 --- linux-2.4.24-vanilla.orig/fs/Makefile       2004-01-10 17:11:48.000000000 +0300
604 +++ linux-2.4.24-vanilla/fs/Makefile    2004-01-10 17:20:28.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.24-vanilla/fs/ext2/Makefile
616 ===================================================================
617 --- linux-2.4.24-vanilla.orig/fs/ext2/Makefile  2001-10-11 19:05:18.000000000 +0400
618 +++ linux-2.4.24-vanilla/fs/ext2/Makefile       2004-01-10 17:20:28.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.24-vanilla/fs/ext2/file.c
629 ===================================================================
630 --- linux-2.4.24-vanilla.orig/fs/ext2/file.c    2001-10-11 19:05:18.000000000 +0400
631 +++ linux-2.4.24-vanilla/fs/ext2/file.c 2004-01-10 17:20:28.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.24-vanilla/fs/ext2/ialloc.c
650 ===================================================================
651 --- linux-2.4.24-vanilla.orig/fs/ext2/ialloc.c  2004-01-10 17:04:42.000000000 +0300
652 +++ linux-2.4.24-vanilla/fs/ext2/ialloc.c       2004-01-10 17:20:28.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.24-vanilla/fs/ext2/inode.c
670 ===================================================================
671 --- linux-2.4.24-vanilla.orig/fs/ext2/inode.c   2004-01-10 17:04:42.000000000 +0300
672 +++ linux-2.4.24-vanilla/fs/ext2/inode.c        2004-01-10 17:20:28.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.24-vanilla/fs/ext2/namei.c
756 ===================================================================
757 --- linux-2.4.24-vanilla.orig/fs/ext2/namei.c   2001-10-04 09:57:36.000000000 +0400
758 +++ linux-2.4.24-vanilla/fs/ext2/namei.c        2004-01-10 17:20:28.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.24-vanilla/fs/ext2/super.c
793 ===================================================================
794 --- linux-2.4.24-vanilla.orig/fs/ext2/super.c   2003-05-16 05:29:12.000000000 +0400
795 +++ linux-2.4.24-vanilla/fs/ext2/super.c        2004-01-10 17:20:28.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.24-vanilla/fs/ext2/symlink.c
866 ===================================================================
867 --- linux-2.4.24-vanilla.orig/fs/ext2/symlink.c 2000-09-28 00:41:33.000000000 +0400
868 +++ linux-2.4.24-vanilla/fs/ext2/symlink.c      2004-01-10 17:20:28.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.24-vanilla/fs/ext2/xattr.c
899 ===================================================================
900 --- linux-2.4.24-vanilla.orig/fs/ext2/xattr.c   2003-01-30 13:24:37.000000000 +0300
901 +++ linux-2.4.24-vanilla/fs/ext2/xattr.c        2004-01-10 17:20:28.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 +                       (void)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 +                       (void)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.24-vanilla/fs/ext2/xattr_user.c
2116 ===================================================================
2117 --- linux-2.4.24-vanilla.orig/fs/ext2/xattr_user.c      2003-01-30 13:24:37.000000000 +0300
2118 +++ linux-2.4.24-vanilla/fs/ext2/xattr_user.c   2004-01-10 17:20:28.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.24-vanilla/fs/ext3/Makefile
2224 ===================================================================
2225 --- linux-2.4.24-vanilla.orig/fs/ext3/Makefile  2004-01-10 17:11:50.000000000 +0300
2226 +++ linux-2.4.24-vanilla/fs/ext3/Makefile       2004-01-10 17:20:28.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.24-vanilla/fs/ext3/file.c
2252 ===================================================================
2253 --- linux-2.4.24-vanilla.orig/fs/ext3/file.c    2004-01-10 17:11:50.000000000 +0300
2254 +++ linux-2.4.24-vanilla/fs/ext3/file.c 2004-01-10 17:20:28.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.24-vanilla/fs/ext3/ialloc.c
2274 ===================================================================
2275 --- linux-2.4.24-vanilla.orig/fs/ext3/ialloc.c  2004-01-10 17:04:42.000000000 +0300
2276 +++ linux-2.4.24-vanilla/fs/ext3/ialloc.c       2004-01-10 17:20:28.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.24-vanilla/fs/ext3/inode.c
2294 ===================================================================
2295 --- linux-2.4.24-vanilla.orig/fs/ext3/inode.c   2004-01-10 17:05:05.000000000 +0300
2296 +++ linux-2.4.24-vanilla/fs/ext3/inode.c        2004-01-10 17:20:28.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.24-vanilla/fs/ext3/namei.c
2388 ===================================================================
2389 --- linux-2.4.24-vanilla.orig/fs/ext3/namei.c   2004-01-10 17:11:50.000000000 +0300
2390 +++ linux-2.4.24-vanilla/fs/ext3/namei.c        2004-01-10 17:20:28.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.24-vanilla/fs/ext3/super.c
2453 ===================================================================
2454 --- linux-2.4.24-vanilla.orig/fs/ext3/super.c   2004-01-10 17:11:50.000000000 +0300
2455 +++ linux-2.4.24-vanilla/fs/ext3/super.c        2004-01-10 17:20:28.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.24-vanilla/fs/ext3/symlink.c
2548 ===================================================================
2549 --- linux-2.4.24-vanilla.orig/fs/ext3/symlink.c 2001-11-10 01:25:04.000000000 +0300
2550 +++ linux-2.4.24-vanilla/fs/ext3/symlink.c      2004-01-10 17:20:28.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.24-vanilla/fs/ext3/xattr.c
2581 ===================================================================
2582 --- linux-2.4.24-vanilla.orig/fs/ext3/xattr.c   2003-01-30 13:24:37.000000000 +0300
2583 +++ linux-2.4.24-vanilla/fs/ext3/xattr.c        2004-01-10 17:20:28.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 +                       (void)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 +                       (void)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.24-vanilla/fs/ext3/xattr_user.c
3811 ===================================================================
3812 --- linux-2.4.24-vanilla.orig/fs/ext3/xattr_user.c      2003-01-30 13:24:37.000000000 +0300
3813 +++ linux-2.4.24-vanilla/fs/ext3/xattr_user.c   2004-01-10 17:20:28.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.24-vanilla/fs/ext3/ext3-exports.c
3927 ===================================================================
3928 --- linux-2.4.24-vanilla.orig/fs/ext3/ext3-exports.c    2003-01-30 13:24:37.000000000 +0300
3929 +++ linux-2.4.24-vanilla/fs/ext3/ext3-exports.c 2004-01-10 17:20:28.000000000 +0300
3930 @@ -0,0 +1,13 @@
3931 +#include <linux/config.h>
3932 +#include <linux/module.h>
3933 +#include <linux/ext3_fs.h>
3934 +#include <linux/ext3_jbd.h>
3935 +#include <linux/ext3_xattr.h>
3936 +
3937 +EXPORT_SYMBOL(ext3_force_commit);
3938 +EXPORT_SYMBOL(ext3_bread);
3939 +EXPORT_SYMBOL(ext3_xattr_register);
3940 +EXPORT_SYMBOL(ext3_xattr_unregister);
3941 +EXPORT_SYMBOL(ext3_xattr_get);
3942 +EXPORT_SYMBOL(ext3_xattr_list);
3943 +EXPORT_SYMBOL(ext3_xattr_set);
3944 Index: linux-2.4.24-vanilla/fs/jfs/jfs_xattr.h
3945 ===================================================================
3946 --- linux-2.4.24-vanilla.orig/fs/jfs/jfs_xattr.h        2003-05-16 05:29:12.000000000 +0400
3947 +++ linux-2.4.24-vanilla/fs/jfs/jfs_xattr.h     2004-01-10 17:20:28.000000000 +0300
3948 @@ -52,8 +52,10 @@
3949  #define        END_EALIST(ealist) \
3950         ((struct jfs_ea *) (((char *) (ealist)) + EALIST_SIZE(ealist)))
3951  
3952 -extern int __jfs_setxattr(struct inode *, const char *, void *, size_t, int);
3953 -extern int jfs_setxattr(struct dentry *, const char *, void *, size_t, int);
3954 +extern int __jfs_setxattr(struct inode *, const char *, const void *, size_t,
3955 +                         int);
3956 +extern int jfs_setxattr(struct dentry *, const char *, const void *, size_t,
3957 +                       int);
3958  extern ssize_t __jfs_getxattr(struct inode *, const char *, void *, size_t);
3959  extern ssize_t jfs_getxattr(struct dentry *, const char *, void *, size_t);
3960  extern ssize_t jfs_listxattr(struct dentry *, char *, size_t);
3961 Index: linux-2.4.24-vanilla/fs/jfs/xattr.c
3962 ===================================================================
3963 --- linux-2.4.24-vanilla.orig/fs/jfs/xattr.c    2004-01-10 17:05:55.000000000 +0300
3964 +++ linux-2.4.24-vanilla/fs/jfs/xattr.c 2004-01-10 17:20:28.000000000 +0300
3965 @@ -648,7 +648,7 @@
3966  }
3967  
3968  static int can_set_xattr(struct inode *inode, const char *name,
3969 -                        void *value, size_t value_len)
3970 +                        const void *value, size_t value_len)
3971  {
3972         if (IS_RDONLY(inode))
3973                 return -EROFS;
3974 @@ -667,7 +667,7 @@
3975         return permission(inode, MAY_WRITE);
3976  }
3977  
3978 -int __jfs_setxattr(struct inode *inode, const char *name, void *value,
3979 +int __jfs_setxattr(struct inode *inode, const char *name, const void *value,
3980                    size_t value_len, int flags)
3981  {
3982         struct jfs_ea_list *ealist;
3983 @@ -806,7 +806,7 @@
3984         return rc;
3985  }
3986  
3987 -int jfs_setxattr(struct dentry *dentry, const char *name, void *value,
3988 +int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
3989                  size_t value_len, int flags)
3990  {
3991         if (value == NULL) {    /* empty EA, do not remove */
3992 Index: linux-2.4.24-vanilla/fs/mbcache.c
3993 ===================================================================
3994 --- linux-2.4.24-vanilla.orig/fs/mbcache.c      2003-01-30 13:24:37.000000000 +0300
3995 +++ linux-2.4.24-vanilla/fs/mbcache.c   2004-01-10 17:20:28.000000000 +0300
3996 @@ -0,0 +1,648 @@
3997 +/*
3998 + * linux/fs/mbcache.c
3999 + * (C) 2001-2002 Andreas Gruenbacher, <a.gruenbacher@computer.org>
4000 + */
4001 +
4002 +/*
4003 + * Filesystem Meta Information Block Cache (mbcache)
4004 + *
4005 + * The mbcache caches blocks of block devices that need to be located
4006 + * by their device/block number, as well as by other criteria (such
4007 + * as the block's contents).
4008 + *
4009 + * There can only be one cache entry in a cache per device and block number.
4010 + * Additional indexes need not be unique in this sense. The number of
4011 + * additional indexes (=other criteria) can be hardwired at compile time
4012 + * or specified at cache create time.
4013 + *
4014 + * Each cache entry is of fixed size. An entry may be `valid' or `invalid'
4015 + * in the cache. A valid entry is in the main hash tables of the cache,
4016 + * and may also be in the lru list. An invalid entry is not in any hashes
4017 + * or lists.
4018 + *
4019 + * A valid cache entry is only in the lru list if no handles refer to it.
4020 + * Invalid cache entries will be freed when the last handle to the cache
4021 + * entry is released. Entries that cannot be freed immediately are put
4022 + * back on the lru list.
4023 + */
4024 +
4025 +#include <linux/kernel.h>
4026 +#include <linux/module.h>
4027 +
4028 +#include <linux/fs.h>
4029 +#include <linux/slab.h>
4030 +#include <linux/sched.h>
4031 +#include <linux/cache_def.h>
4032 +#include <linux/version.h>
4033 +#include <linux/init.h>
4034 +#include <linux/mbcache.h>
4035 +
4036 +
4037 +#ifdef MB_CACHE_DEBUG
4038 +# define mb_debug(f...) do { \
4039 +               printk(KERN_DEBUG f); \
4040 +               printk("\n"); \
4041 +       } while (0)
4042 +#define mb_assert(c) do { if (!(c)) \
4043 +               printk(KERN_ERR "assertion " #c " failed\n"); \
4044 +       } while(0)
4045 +#else
4046 +# define mb_debug(f...) do { } while(0)
4047 +# define mb_assert(c) do { } while(0)
4048 +#endif
4049 +#define mb_error(f...) do { \
4050 +               printk(KERN_ERR f); \
4051 +               printk("\n"); \
4052 +       } while(0)
4053 +               
4054 +MODULE_AUTHOR("Andreas Gruenbacher <a.gruenbacher@computer.org>");
4055 +MODULE_DESCRIPTION("Meta block cache (for extended attributes)");
4056 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4057 +MODULE_LICENSE("GPL");
4058 +#endif
4059 +
4060 +EXPORT_SYMBOL(mb_cache_create);
4061 +EXPORT_SYMBOL(mb_cache_shrink);
4062 +EXPORT_SYMBOL(mb_cache_destroy);
4063 +EXPORT_SYMBOL(mb_cache_entry_alloc);
4064 +EXPORT_SYMBOL(mb_cache_entry_insert);
4065 +EXPORT_SYMBOL(mb_cache_entry_release);
4066 +EXPORT_SYMBOL(mb_cache_entry_takeout);
4067 +EXPORT_SYMBOL(mb_cache_entry_free);
4068 +EXPORT_SYMBOL(mb_cache_entry_dup);
4069 +EXPORT_SYMBOL(mb_cache_entry_get);
4070 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
4071 +EXPORT_SYMBOL(mb_cache_entry_find_first);
4072 +EXPORT_SYMBOL(mb_cache_entry_find_next);
4073 +#endif
4074 +
4075 +
4076 +/*
4077 + * Global data: list of all mbcache's, lru list, and a spinlock for
4078 + * accessing cache data structures on SMP machines. The lru list is
4079 + * global across all mbcaches.
4080 + */
4081 +
4082 +static LIST_HEAD(mb_cache_list);
4083 +static LIST_HEAD(mb_cache_lru_list);
4084 +static spinlock_t mb_cache_spinlock = SPIN_LOCK_UNLOCKED;
4085 +
4086 +static inline int
4087 +mb_cache_indexes(struct mb_cache *cache)
4088 +{
4089 +#ifdef MB_CACHE_INDEXES_COUNT
4090 +       return MB_CACHE_INDEXES_COUNT;
4091 +#else
4092 +       return cache->c_indexes_count;
4093 +#endif
4094 +}
4095 +
4096 +/*
4097 + * What the mbcache registers as to get shrunk dynamically.
4098 + */
4099 +
4100 +static void
4101 +mb_cache_memory_pressure(int priority, unsigned int gfp_mask);
4102 +
4103 +static struct cache_definition mb_cache_definition = {
4104 +       "mb_cache",
4105 +       mb_cache_memory_pressure
4106 +};
4107 +
4108 +
4109 +static inline int
4110 +__mb_cache_entry_is_hashed(struct mb_cache_entry *ce)
4111 +{
4112 +       return !list_empty(&ce->e_block_list);
4113 +}
4114 +
4115 +
4116 +static inline void
4117 +__mb_cache_entry_unhash(struct mb_cache_entry *ce)
4118 +{
4119 +       int n;
4120 +
4121 +       if (__mb_cache_entry_is_hashed(ce)) {
4122 +               list_del_init(&ce->e_block_list);
4123 +               for (n=0; n<mb_cache_indexes(ce->e_cache); n++)
4124 +                       list_del(&ce->e_indexes[n].o_list);
4125 +       }
4126 +}
4127 +
4128 +
4129 +static inline void
4130 +__mb_cache_entry_forget(struct mb_cache_entry *ce, int gfp_mask)
4131 +{
4132 +       struct mb_cache *cache = ce->e_cache;
4133 +
4134 +       mb_assert(atomic_read(&ce->e_used) == 0);
4135 +       if (cache->c_op.free && cache->c_op.free(ce, gfp_mask)) {
4136 +               /* free failed -- put back on the lru list
4137 +                  for freeing later. */
4138 +               spin_lock(&mb_cache_spinlock);
4139 +               list_add(&ce->e_lru_list, &mb_cache_lru_list);
4140 +               spin_unlock(&mb_cache_spinlock);
4141 +       } else {
4142 +               kmem_cache_free(cache->c_entry_cache, ce);
4143 +               atomic_dec(&cache->c_entry_count);
4144 +       }
4145 +}
4146 +
4147 +
4148 +static inline void
4149 +__mb_cache_entry_release_unlock(struct mb_cache_entry *ce)
4150 +{
4151 +       if (atomic_dec_and_test(&ce->e_used)) {
4152 +               if (__mb_cache_entry_is_hashed(ce))
4153 +                       list_add_tail(&ce->e_lru_list, &mb_cache_lru_list);
4154 +               else {
4155 +                       spin_unlock(&mb_cache_spinlock);
4156 +                       __mb_cache_entry_forget(ce, GFP_KERNEL);
4157 +                       return;
4158 +               }
4159 +       }
4160 +       spin_unlock(&mb_cache_spinlock);
4161 +}
4162 +
4163 +
4164 +/*
4165 + * mb_cache_memory_pressure()  memory pressure callback
4166 + *
4167 + * This function is called by the kernel memory management when memory
4168 + * gets low.
4169 + *
4170 + * @priority: Amount by which to shrink the cache (0 = highes priority)
4171 + * @gfp_mask: (ignored)
4172 + */
4173 +static void
4174 +mb_cache_memory_pressure(int priority, unsigned int gfp_mask)
4175 +{
4176 +       LIST_HEAD(free_list);
4177 +       struct list_head *l, *ltmp;
4178 +       int count = 0;
4179 +
4180 +       spin_lock(&mb_cache_spinlock);
4181 +       list_for_each(l, &mb_cache_list) {
4182 +               struct mb_cache *cache =
4183 +                       list_entry(l, struct mb_cache, c_cache_list);
4184 +               mb_debug("cache %s (%d)", cache->c_name,
4185 +                         atomic_read(&cache->c_entry_count));
4186 +               count += atomic_read(&cache->c_entry_count);
4187 +       }
4188 +       mb_debug("trying to free %d of %d entries",
4189 +                 count / (priority ? priority : 1), count);
4190 +       if (priority)
4191 +               count /= priority;
4192 +       while (count-- && !list_empty(&mb_cache_lru_list)) {
4193 +               struct mb_cache_entry *ce =
4194 +                       list_entry(mb_cache_lru_list.next,
4195 +                                  struct mb_cache_entry, e_lru_list);
4196 +               list_del(&ce->e_lru_list);
4197 +               __mb_cache_entry_unhash(ce);
4198 +               list_add_tail(&ce->e_lru_list, &free_list);
4199 +       }
4200 +       spin_unlock(&mb_cache_spinlock);
4201 +       list_for_each_safe(l, ltmp, &free_list) {
4202 +               __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4203 +                                                  e_lru_list), gfp_mask);
4204 +       }
4205 +}
4206 +
4207 +
4208 +/*
4209 + * mb_cache_create()  create a new cache
4210 + *
4211 + * All entries in one cache are equal size. Cache entries may be from
4212 + * multiple devices. If this is the first mbcache created, registers
4213 + * the cache with kernel memory management. Returns NULL if no more
4214 + * memory was available.
4215 + *
4216 + * @name: name of the cache (informal)
4217 + * @cache_op: contains the callback called when freeing a cache entry
4218 + * @entry_size: The size of a cache entry, including
4219 + *              struct mb_cache_entry
4220 + * @indexes_count: number of additional indexes in the cache. Must equal
4221 + *                 MB_CACHE_INDEXES_COUNT if the number of indexes is
4222 + *                 hardwired.
4223 + * @bucket_count: number of hash buckets
4224 + */
4225 +struct mb_cache *
4226 +mb_cache_create(const char *name, struct mb_cache_op *cache_op,
4227 +               size_t entry_size, int indexes_count, int bucket_count)
4228 +{
4229 +       int m=0, n;
4230 +       struct mb_cache *cache = NULL;
4231 +
4232 +       if(entry_size < sizeof(struct mb_cache_entry) +
4233 +          indexes_count * sizeof(struct mb_cache_entry_index))
4234 +               return NULL;
4235 +
4236 +       MOD_INC_USE_COUNT;
4237 +       cache = kmalloc(sizeof(struct mb_cache) +
4238 +                       indexes_count * sizeof(struct list_head), GFP_KERNEL);
4239 +       if (!cache)
4240 +               goto fail;
4241 +       cache->c_name = name;
4242 +       cache->c_op.free = NULL;
4243 +       if (cache_op)
4244 +               cache->c_op.free = cache_op->free;
4245 +       atomic_set(&cache->c_entry_count, 0);
4246 +       cache->c_bucket_count = bucket_count;
4247 +#ifdef MB_CACHE_INDEXES_COUNT
4248 +       mb_assert(indexes_count == MB_CACHE_INDEXES_COUNT);
4249 +#else
4250 +       cache->c_indexes_count = indexes_count;
4251 +#endif
4252 +       cache->c_block_hash = kmalloc(bucket_count * sizeof(struct list_head),
4253 +                                     GFP_KERNEL);
4254 +       if (!cache->c_block_hash)
4255 +               goto fail;
4256 +       for (n=0; n<bucket_count; n++)
4257 +               INIT_LIST_HEAD(&cache->c_block_hash[n]);
4258 +       for (m=0; m<indexes_count; m++) {
4259 +               cache->c_indexes_hash[m] = kmalloc(bucket_count *
4260 +                                                sizeof(struct list_head),
4261 +                                                GFP_KERNEL);
4262 +               if (!cache->c_indexes_hash[m])
4263 +                       goto fail;
4264 +               for (n=0; n<bucket_count; n++)
4265 +                       INIT_LIST_HEAD(&cache->c_indexes_hash[m][n]);
4266 +       }
4267 +       cache->c_entry_cache = kmem_cache_create(name, entry_size, 0,
4268 +               0 /*SLAB_POISON | SLAB_RED_ZONE*/, NULL, NULL);
4269 +       if (!cache->c_entry_cache)
4270 +               goto fail;
4271 +
4272 +       spin_lock(&mb_cache_spinlock);
4273 +       list_add(&cache->c_cache_list, &mb_cache_list);
4274 +       spin_unlock(&mb_cache_spinlock);
4275 +       return cache;
4276 +
4277 +fail:
4278 +       if (cache) {
4279 +               while (--m >= 0)
4280 +                       kfree(cache->c_indexes_hash[m]);
4281 +               if (cache->c_block_hash)
4282 +                       kfree(cache->c_block_hash);
4283 +               kfree(cache);
4284 +       }
4285 +       MOD_DEC_USE_COUNT;
4286 +       return NULL;
4287 +}
4288 +
4289 +
4290 +/*
4291 + * mb_cache_shrink()
4292 + *
4293 + * Removes all cache entires of a device from the cache. All cache entries
4294 + * currently in use cannot be freed, and thus remain in the cache.
4295 + *
4296 + * @cache: which cache to shrink
4297 + * @dev: which device's cache entries to shrink
4298 + */
4299 +void
4300 +mb_cache_shrink(struct mb_cache *cache, kdev_t dev)
4301 +{
4302 +       LIST_HEAD(free_list);
4303 +       struct list_head *l, *ltmp;
4304 +
4305 +       spin_lock(&mb_cache_spinlock);
4306 +       list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
4307 +               struct mb_cache_entry *ce =
4308 +                       list_entry(l, struct mb_cache_entry, e_lru_list);
4309 +               if (ce->e_dev == dev) {
4310 +                       list_del(&ce->e_lru_list);
4311 +                       list_add_tail(&ce->e_lru_list, &free_list);
4312 +                       __mb_cache_entry_unhash(ce);
4313 +               }
4314 +       }
4315 +       spin_unlock(&mb_cache_spinlock);
4316 +       list_for_each_safe(l, ltmp, &free_list) {
4317 +               __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4318 +                                                  e_lru_list), GFP_KERNEL);
4319 +       }
4320 +}
4321 +
4322 +
4323 +/*
4324 + * mb_cache_destroy()
4325 + *
4326 + * Shrinks the cache to its minimum possible size (hopefully 0 entries),
4327 + * and then destroys it. If this was the last mbcache, un-registers the
4328 + * mbcache from kernel memory management.
4329 + */
4330 +void
4331 +mb_cache_destroy(struct mb_cache *cache)
4332 +{
4333 +       LIST_HEAD(free_list);
4334 +       struct list_head *l, *ltmp;
4335 +       int n;
4336 +
4337 +       spin_lock(&mb_cache_spinlock);
4338 +       list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
4339 +               struct mb_cache_entry *ce =
4340 +                       list_entry(l, struct mb_cache_entry, e_lru_list);
4341 +               if (ce->e_cache == cache) {
4342 +                       list_del(&ce->e_lru_list);
4343 +                       list_add_tail(&ce->e_lru_list, &free_list);
4344 +                       __mb_cache_entry_unhash(ce);
4345 +               }
4346 +       }
4347 +       list_del(&cache->c_cache_list);
4348 +       spin_unlock(&mb_cache_spinlock);
4349 +       list_for_each_safe(l, ltmp, &free_list) {
4350 +               __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4351 +                                                  e_lru_list), GFP_KERNEL);
4352 +       }
4353 +
4354 +       if (atomic_read(&cache->c_entry_count) > 0) {
4355 +               mb_error("cache %s: %d orphaned entries",
4356 +                         cache->c_name,
4357 +                         atomic_read(&cache->c_entry_count));
4358 +       }
4359 +
4360 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
4361 +       /* We don't have kmem_cache_destroy() in 2.2.x */
4362 +       kmem_cache_shrink(cache->c_entry_cache);
4363 +#else
4364 +       kmem_cache_destroy(cache->c_entry_cache);
4365 +#endif
4366 +       for (n=0; n < mb_cache_indexes(cache); n++)
4367 +               kfree(cache->c_indexes_hash[n]);
4368 +       kfree(cache->c_block_hash);
4369 +       kfree(cache);
4370 +
4371 +       MOD_DEC_USE_COUNT;
4372 +}
4373 +
4374 +
4375 +/*
4376 + * mb_cache_entry_alloc()
4377 + *
4378 + * Allocates a new cache entry. The new entry will not be valid initially,
4379 + * and thus cannot be looked up yet. It should be filled with data, and
4380 + * then inserted into the cache using mb_cache_entry_insert(). Returns NULL
4381 + * if no more memory was available.
4382 + */
4383 +struct mb_cache_entry *
4384 +mb_cache_entry_alloc(struct mb_cache *cache)
4385 +{
4386 +       struct mb_cache_entry *ce;
4387 +
4388 +       atomic_inc(&cache->c_entry_count);
4389 +       ce = kmem_cache_alloc(cache->c_entry_cache, GFP_KERNEL);
4390 +       if (ce) {
4391 +               INIT_LIST_HEAD(&ce->e_lru_list);
4392 +               INIT_LIST_HEAD(&ce->e_block_list);
4393 +               ce->e_cache = cache;
4394 +               atomic_set(&ce->e_used, 1);
4395 +       }
4396 +       return ce;
4397 +}
4398 +
4399 +
4400 +/*
4401 + * mb_cache_entry_insert()
4402 + *
4403 + * Inserts an entry that was allocated using mb_cache_entry_alloc() into
4404 + * the cache. After this, the cache entry can be looked up, but is not yet
4405 + * in the lru list as the caller still holds a handle to it. Returns 0 on
4406 + * success, or -EBUSY if a cache entry for that device + inode exists
4407 + * already (this may happen after a failed lookup, if another process has
4408 + * inserted the same cache entry in the meantime).
4409 + *
4410 + * @dev: device the cache entry belongs to
4411 + * @block: block number
4412 + * @keys: array of additional keys. There must be indexes_count entries
4413 + *        in the array (as specified when creating the cache).
4414 + */
4415 +int
4416 +mb_cache_entry_insert(struct mb_cache_entry *ce, kdev_t dev,
4417 +                     unsigned long block, unsigned int keys[])
4418 +{
4419 +       struct mb_cache *cache = ce->e_cache;
4420 +       unsigned int bucket = (HASHDEV(dev) + block) % cache->c_bucket_count;
4421 +       struct list_head *l;
4422 +       int error = -EBUSY, n;
4423 +
4424 +       spin_lock(&mb_cache_spinlock);
4425 +       list_for_each(l, &cache->c_block_hash[bucket]) {
4426 +               struct mb_cache_entry *ce =
4427 +                       list_entry(l, struct mb_cache_entry, e_block_list);
4428 +               if (ce->e_dev == dev && ce->e_block == block)
4429 +                       goto out;
4430 +       }
4431 +       __mb_cache_entry_unhash(ce);
4432 +       ce->e_dev = dev;
4433 +       ce->e_block = block;
4434 +       list_add(&ce->e_block_list, &cache->c_block_hash[bucket]);
4435 +       for (n=0; n<mb_cache_indexes(cache); n++) {
4436 +               ce->e_indexes[n].o_key = keys[n];
4437 +               bucket = keys[n] % cache->c_bucket_count;
4438 +               list_add(&ce->e_indexes[n].o_list,
4439 +                        &cache->c_indexes_hash[n][bucket]);
4440 +       }
4441 +out:
4442 +       spin_unlock(&mb_cache_spinlock);
4443 +       return error;
4444 +}
4445 +
4446 +
4447 +/*
4448 + * mb_cache_entry_release()
4449 + *
4450 + * Release a handle to a cache entry. When the last handle to a cache entry
4451 + * is released it is either freed (if it is invalid) or otherwise inserted
4452 + * in to the lru list.
4453 + */
4454 +void
4455 +mb_cache_entry_release(struct mb_cache_entry *ce)
4456 +{
4457 +       spin_lock(&mb_cache_spinlock);
4458 +       __mb_cache_entry_release_unlock(ce);
4459 +}
4460 +
4461 +
4462 +/*
4463 + * mb_cache_entry_takeout()
4464 + *
4465 + * Take a cache entry out of the cache, making it invalid. The entry can later
4466 + * be re-inserted using mb_cache_entry_insert(), or released using
4467 + * mb_cache_entry_release().
4468 + */
4469 +void
4470 +mb_cache_entry_takeout(struct mb_cache_entry *ce)
4471 +{
4472 +       spin_lock(&mb_cache_spinlock);
4473 +       mb_assert(list_empty(&ce->e_lru_list));
4474 +       __mb_cache_entry_unhash(ce);
4475 +       spin_unlock(&mb_cache_spinlock);
4476 +}
4477 +
4478 +
4479 +/*
4480 + * mb_cache_entry_free()
4481 + *
4482 + * This is equivalent to the sequence mb_cache_entry_takeout() --
4483 + * mb_cache_entry_release().
4484 + */
4485 +void
4486 +mb_cache_entry_free(struct mb_cache_entry *ce)
4487 +{
4488 +       spin_lock(&mb_cache_spinlock);
4489 +       mb_assert(list_empty(&ce->e_lru_list));
4490 +       __mb_cache_entry_unhash(ce);
4491 +       __mb_cache_entry_release_unlock(ce);
4492 +}
4493 +
4494 +
4495 +/*
4496 + * mb_cache_entry_dup()
4497 + *
4498 + * Duplicate a handle to a cache entry (does not duplicate the cache entry
4499 + * itself). After the call, both the old and the new handle must be released.
4500 + */
4501 +struct mb_cache_entry *
4502 +mb_cache_entry_dup(struct mb_cache_entry *ce)
4503 +{
4504 +       atomic_inc(&ce->e_used);
4505 +       return ce;
4506 +}
4507 +
4508 +
4509 +/*
4510 + * mb_cache_entry_get()
4511 + *
4512 + * Get a cache entry  by device / block number. (There can only be one entry
4513 + * in the cache per device and block.) Returns NULL if no such cache entry
4514 + * exists.
4515 + */
4516 +struct mb_cache_entry *
4517 +mb_cache_entry_get(struct mb_cache *cache, kdev_t dev, unsigned long block)
4518 +{
4519 +       unsigned int bucket = (HASHDEV(dev) + block) % cache->c_bucket_count;
4520 +       struct list_head *l;
4521 +       struct mb_cache_entry *ce;
4522 +
4523 +       spin_lock(&mb_cache_spinlock);
4524 +       list_for_each(l, &cache->c_block_hash[bucket]) {
4525 +               ce = list_entry(l, struct mb_cache_entry, e_block_list);
4526 +               if (ce->e_dev == dev && ce->e_block == block) {
4527 +                       if (!list_empty(&ce->e_lru_list))
4528 +                               list_del_init(&ce->e_lru_list);
4529 +                       atomic_inc(&ce->e_used);
4530 +                       goto cleanup;
4531 +               }
4532 +       }
4533 +       ce = NULL;
4534 +
4535 +cleanup:
4536 +       spin_unlock(&mb_cache_spinlock);
4537 +       return ce;
4538 +}
4539 +
4540 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
4541 +
4542 +static struct mb_cache_entry *
4543 +__mb_cache_entry_find(struct list_head *l, struct list_head *head,
4544 +                     int index, kdev_t dev, unsigned int key)
4545 +{
4546 +       while (l != head) {
4547 +               struct mb_cache_entry *ce =
4548 +                       list_entry(l, struct mb_cache_entry,
4549 +                                  e_indexes[index].o_list);
4550 +               if (ce->e_dev == dev && ce->e_indexes[index].o_key == key) {
4551 +                       if (!list_empty(&ce->e_lru_list))
4552 +                               list_del_init(&ce->e_lru_list);
4553 +                       atomic_inc(&ce->e_used);
4554 +                       return ce;
4555 +               }
4556 +               l = l->next;
4557 +       }
4558 +       return NULL;
4559 +}
4560 +
4561 +
4562 +/*
4563 + * mb_cache_entry_find_first()
4564 + *
4565 + * Find the first cache entry on a given device with a certain key in
4566 + * an additional index. Additonal matches can be found with
4567 + * mb_cache_entry_find_next(). Returns NULL if no match was found.
4568 + *
4569 + * @cache: the cache to search
4570 + * @index: the number of the additonal index to search (0<=index<indexes_count)
4571 + * @dev: the device the cache entry should belong to
4572 + * @key: the key in the index
4573 + */
4574 +struct mb_cache_entry *
4575 +mb_cache_entry_find_first(struct mb_cache *cache, int index, kdev_t dev,
4576 +                         unsigned int key)
4577 +{
4578 +       unsigned int bucket = key % cache->c_bucket_count;
4579 +       struct list_head *l;
4580 +       struct mb_cache_entry *ce;
4581 +
4582 +       mb_assert(index < mb_cache_indexes(cache));
4583 +       spin_lock(&mb_cache_spinlock);
4584 +       l = cache->c_indexes_hash[index][bucket].next;
4585 +       ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
4586 +                                  index, dev, key);
4587 +       spin_unlock(&mb_cache_spinlock);
4588 +       return ce;
4589 +}
4590 +
4591 +
4592 +/*
4593 + * mb_cache_entry_find_next()
4594 + *
4595 + * Find the next cache entry on a given device with a certain key in an
4596 + * additional index. Returns NULL if no match could be found. The previous
4597 + * entry is atomatically released, so that mb_cache_entry_find_next() can
4598 + * be called like this:
4599 + *
4600 + * entry = mb_cache_entry_find_first();
4601 + * while (entry) {
4602 + *     ...
4603 + *     entry = mb_cache_entry_find_next(entry, ...);
4604 + * }
4605 + *
4606 + * @prev: The previous match
4607 + * @index: the number of the additonal index to search (0<=index<indexes_count)
4608 + * @dev: the device the cache entry should belong to
4609 + * @key: the key in the index
4610 + */
4611 +struct mb_cache_entry *
4612 +mb_cache_entry_find_next(struct mb_cache_entry *prev, int index, kdev_t dev,
4613 +                        unsigned int key)
4614 +{
4615 +       struct mb_cache *cache = prev->e_cache;
4616 +       unsigned int bucket = key % cache->c_bucket_count;
4617 +       struct list_head *l;
4618 +       struct mb_cache_entry *ce;
4619 +
4620 +       mb_assert(index < mb_cache_indexes(cache));
4621 +       spin_lock(&mb_cache_spinlock);
4622 +       l = prev->e_indexes[index].o_list.next;
4623 +       ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
4624 +                                  index, dev, key);
4625 +       __mb_cache_entry_release_unlock(prev);
4626 +       return ce;
4627 +}
4628 +
4629 +#endif  /* !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0) */
4630 +
4631 +static int __init init_mbcache(void)
4632 +{
4633 +       register_cache(&mb_cache_definition);
4634 +       return 0;
4635 +}
4636 +
4637 +static void __exit exit_mbcache(void)
4638 +{
4639 +       unregister_cache(&mb_cache_definition);
4640 +}
4641 +
4642 +module_init(init_mbcache)
4643 +module_exit(exit_mbcache)
4644 +
4645 Index: linux-2.4.24-vanilla/include/asm-arm/unistd.h
4646 ===================================================================
4647 --- linux-2.4.24-vanilla.orig/include/asm-arm/unistd.h  2004-01-10 17:05:06.000000000 +0300
4648 +++ linux-2.4.24-vanilla/include/asm-arm/unistd.h       2004-01-10 17:20:28.000000000 +0300
4649 @@ -250,7 +250,6 @@
4650  #define __NR_security                  (__NR_SYSCALL_BASE+223)
4651  #define __NR_gettid                    (__NR_SYSCALL_BASE+224)
4652  #define __NR_readahead                 (__NR_SYSCALL_BASE+225)
4653 -#if 0 /* allocated in 2.5 */
4654  #define __NR_setxattr                  (__NR_SYSCALL_BASE+226)
4655  #define __NR_lsetxattr                 (__NR_SYSCALL_BASE+227)
4656  #define __NR_fsetxattr                 (__NR_SYSCALL_BASE+228)
4657 @@ -263,7 +262,6 @@
4658  #define __NR_removexattr               (__NR_SYSCALL_BASE+235)
4659  #define __NR_lremovexattr              (__NR_SYSCALL_BASE+236)
4660  #define __NR_fremovexattr              (__NR_SYSCALL_BASE+237)
4661 -#endif
4662  #define __NR_tkill                     (__NR_SYSCALL_BASE+238)
4663  #if 0 /* allocated in 2.5 */
4664  #define __NR_sendfile64                 (__NR_SYSCALL_BASE+239)
4665 Index: linux-2.4.24-vanilla/include/asm-ppc64/unistd.h
4666 ===================================================================
4667 --- linux-2.4.24-vanilla.orig/include/asm-ppc64/unistd.h        2004-01-10 17:05:59.000000000 +0300
4668 +++ linux-2.4.24-vanilla/include/asm-ppc64/unistd.h     2004-01-10 17:20:28.000000000 +0300
4669 @@ -218,6 +218,7 @@
4670  #define __NR_mincore           206
4671  #define __NR_gettid            207
4672  #define __NR_tkill             208
4673 +#endif
4674  #define __NR_setxattr          209
4675  #define __NR_lsetxattr         210
4676  #define __NR_fsetxattr         211
4677 @@ -230,6 +231,7 @@
4678  #define __NR_removexattr       218
4679  #define __NR_lremovexattr      219
4680  #define __NR_fremovexattr      220
4681 +#if 0 /* Reserved syscalls */
4682  #define __NR_futex             221
4683  #define __NR_sched_setaffinity 222     
4684  #define __NR_sched_getaffinity 223
4685 Index: linux-2.4.24-vanilla/include/asm-s390/unistd.h
4686 ===================================================================
4687 --- linux-2.4.24-vanilla.orig/include/asm-s390/unistd.h 2004-01-10 17:04:42.000000000 +0300
4688 +++ linux-2.4.24-vanilla/include/asm-s390/unistd.h      2004-01-10 17:20:28.000000000 +0300
4689 @@ -213,9 +213,18 @@
4690  #define __NR_getdents64                220
4691  #define __NR_fcntl64           221
4692  #define __NR_readahead         222
4693 -/*
4694 - * Numbers 224-235 are reserved for posix acl
4695 - */
4696 +#define __NR_setxattr          224
4697 +#define __NR_lsetxattr         225
4698 +#define __NR_fsetxattr         226
4699 +#define __NR_getxattr          227
4700 +#define __NR_lgetxattr         228
4701 +#define __NR_fgetxattr         229
4702 +#define __NR_listxattr         230
4703 +#define __NR_llistxattr                231
4704 +#define __NR_flistxattr                232
4705 +#define __NR_removexattr       233
4706 +#define __NR_lremovexattr      234
4707 +#define __NR_fremovexattr      235
4708  #define __NR_gettid            236
4709  #define __NR_tkill             237
4710  
4711 Index: linux-2.4.24-vanilla/include/asm-s390x/unistd.h
4712 ===================================================================
4713 --- linux-2.4.24-vanilla.orig/include/asm-s390x/unistd.h        2004-01-10 17:04:42.000000000 +0300
4714 +++ linux-2.4.24-vanilla/include/asm-s390x/unistd.h     2004-01-10 17:20:28.000000000 +0300
4715 @@ -181,9 +181,18 @@
4716  #define __NR_mincore            218
4717  #define __NR_madvise            219
4718  #define __NR_readahead         222
4719 -/*
4720 - * Numbers 224-235 are reserved for posix acl
4721 - */
4722 +#define __NR_setxattr          224
4723 +#define __NR_lsetxattr         225
4724 +#define __NR_fsetxattr         226
4725 +#define __NR_getxattr          227
4726 +#define __NR_lgetxattr         228
4727 +#define __NR_fgetxattr         229
4728 +#define __NR_listxattr         230
4729 +#define __NR_llistxattr                231
4730 +#define __NR_flistxattr                232
4731 +#define __NR_removexattr       233
4732 +#define __NR_lremovexattr      234
4733 +#define __NR_fremovexattr      235
4734  #define __NR_gettid            236
4735  #define __NR_tkill             237
4736  
4737 Index: linux-2.4.24-vanilla/include/linux/cache_def.h
4738 ===================================================================
4739 --- linux-2.4.24-vanilla.orig/include/linux/cache_def.h 2003-01-30 13:24:37.000000000 +0300
4740 +++ linux-2.4.24-vanilla/include/linux/cache_def.h      2004-01-10 17:20:28.000000000 +0300
4741 @@ -0,0 +1,15 @@
4742 +/*
4743 + * linux/cache_def.h
4744 + * Handling of caches defined in drivers, filesystems, ...
4745 + *
4746 + * Copyright (C) 2002 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
4747 + */
4748 +
4749 +struct cache_definition {
4750 +       const char *name;
4751 +       void (*shrink)(int, unsigned int);
4752 +       struct list_head link;
4753 +};
4754 +
4755 +extern void register_cache(struct cache_definition *);
4756 +extern void unregister_cache(struct cache_definition *);
4757 Index: linux-2.4.24-vanilla/include/linux/errno.h
4758 ===================================================================
4759 --- linux-2.4.24-vanilla.orig/include/linux/errno.h     2001-02-10 01:46:13.000000000 +0300
4760 +++ linux-2.4.24-vanilla/include/linux/errno.h  2004-01-10 17:20:28.000000000 +0300
4761 @@ -23,4 +23,8 @@
4762  
4763  #endif
4764  
4765 +/* Defined for extended attributes */
4766 +#define ENOATTR ENODATA                /* No such attribute */
4767 +#define ENOTSUP EOPNOTSUPP     /* Operation not supported */
4768 +
4769  #endif
4770 Index: linux-2.4.24-vanilla/include/linux/ext2_fs.h
4771 ===================================================================
4772 --- linux-2.4.24-vanilla.orig/include/linux/ext2_fs.h   2004-01-10 17:04:42.000000000 +0300
4773 +++ linux-2.4.24-vanilla/include/linux/ext2_fs.h        2004-01-10 17:20:28.000000000 +0300
4774 @@ -57,8 +57,6 @@
4775   */
4776  #define        EXT2_BAD_INO             1      /* Bad blocks inode */
4777  #define EXT2_ROOT_INO           2      /* Root inode */
4778 -#define EXT2_ACL_IDX_INO        3      /* ACL inode */
4779 -#define EXT2_ACL_DATA_INO       4      /* ACL inode */
4780  #define EXT2_BOOT_LOADER_INO    5      /* Boot loader inode */
4781  #define EXT2_UNDEL_DIR_INO      6      /* Undelete directory inode */
4782  
4783 @@ -86,7 +84,6 @@
4784  #else
4785  # define EXT2_BLOCK_SIZE(s)            (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
4786  #endif
4787 -#define EXT2_ACLE_PER_BLOCK(s)         (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
4788  #define        EXT2_ADDR_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
4789  #ifdef __KERNEL__
4790  # define EXT2_BLOCK_SIZE_BITS(s)       ((s)->s_blocksize_bits)
4791 @@ -121,28 +118,6 @@
4792  #endif
4793  
4794  /*
4795 - * ACL structures
4796 - */
4797 -struct ext2_acl_header /* Header of Access Control Lists */
4798 -{
4799 -       __u32   aclh_size;
4800 -       __u32   aclh_file_count;
4801 -       __u32   aclh_acle_count;
4802 -       __u32   aclh_first_acle;
4803 -};
4804 -
4805 -struct ext2_acl_entry  /* Access Control List Entry */
4806 -{
4807 -       __u32   acle_size;
4808 -       __u16   acle_perms;     /* Access permissions */
4809 -       __u16   acle_type;      /* Type of entry */
4810 -       __u16   acle_tag;       /* User or group identity */
4811 -       __u16   acle_pad1;
4812 -       __u32   acle_next;      /* Pointer on next entry for the */
4813 -                                       /* same inode or on next free entry */
4814 -};
4815 -
4816 -/*
4817   * Structure of a blocks group descriptor
4818   */
4819  struct ext2_group_desc
4820 @@ -314,6 +289,7 @@
4821  #define EXT2_MOUNT_ERRORS_PANIC                0x0040  /* Panic on errors */
4822  #define EXT2_MOUNT_MINIX_DF            0x0080  /* Mimics the Minix statfs */
4823  #define EXT2_MOUNT_NO_UID32            0x0200  /* Disable 32-bit UIDs */
4824 +#define EXT2_MOUNT_XATTR_USER          0x4000  /* Extended user attributes */
4825  
4826  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
4827  #define set_opt(o, opt)                        o |= EXT2_MOUNT_##opt
4828 @@ -397,6 +373,7 @@
4829  
4830  #ifdef __KERNEL__
4831  #define EXT2_SB(sb)    (&((sb)->u.ext2_sb))
4832 +#define EXT2_I(inode)  (&((inode)->u.ext2_i))
4833  #else
4834  /* Assume that user mode programs are passing in an ext2fs superblock, not
4835   * a kernel struct super_block.  This will allow us to call the feature-test
4836 @@ -466,7 +443,7 @@
4837  #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV      0x0008
4838  #define EXT2_FEATURE_INCOMPAT_ANY              0xffffffff
4839  
4840 -#define EXT2_FEATURE_COMPAT_SUPP       0
4841 +#define EXT2_FEATURE_COMPAT_SUPP       EXT2_FEATURE_COMPAT_EXT_ATTR
4842  #define EXT2_FEATURE_INCOMPAT_SUPP     EXT2_FEATURE_INCOMPAT_FILETYPE
4843  #define EXT2_FEATURE_RO_COMPAT_SUPP    (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
4844                                          EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
4845 @@ -624,8 +601,10 @@
4846  
4847  /* namei.c */
4848  extern struct inode_operations ext2_dir_inode_operations;
4849 +extern struct inode_operations ext2_special_inode_operations;
4850  
4851  /* symlink.c */
4852 +extern struct inode_operations ext2_symlink_inode_operations;
4853  extern struct inode_operations ext2_fast_symlink_inode_operations;
4854  
4855  #endif /* __KERNEL__ */
4856 Index: linux-2.4.24-vanilla/include/linux/ext2_xattr.h
4857 ===================================================================
4858 --- linux-2.4.24-vanilla.orig/include/linux/ext2_xattr.h        2003-01-30 13:24:37.000000000 +0300
4859 +++ linux-2.4.24-vanilla/include/linux/ext2_xattr.h     2004-01-10 17:20:28.000000000 +0300
4860 @@ -0,0 +1,157 @@
4861 +/*
4862 +  File: linux/ext2_xattr.h
4863 +
4864 +  On-disk format of extended attributes for the ext2 filesystem.
4865 +
4866 +  (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
4867 +*/
4868 +
4869 +#include <linux/config.h>
4870 +#include <linux/init.h>
4871 +#include <linux/xattr.h>
4872 +
4873 +/* Magic value in attribute blocks */
4874 +#define EXT2_XATTR_MAGIC               0xEA020000
4875 +
4876 +/* Maximum number of references to one attribute block */
4877 +#define EXT2_XATTR_REFCOUNT_MAX                1024
4878 +
4879 +/* Name indexes */
4880 +#define EXT2_XATTR_INDEX_MAX                   10
4881 +#define EXT2_XATTR_INDEX_USER                  1
4882 +#define EXT2_XATTR_INDEX_POSIX_ACL_ACCESS      2
4883 +#define EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT     3
4884 +
4885 +struct ext2_xattr_header {
4886 +       __u32   h_magic;        /* magic number for identification */
4887 +       __u32   h_refcount;     /* reference count */
4888 +       __u32   h_blocks;       /* number of disk blocks used */
4889 +       __u32   h_hash;         /* hash value of all attributes */
4890 +       __u32   h_reserved[4];  /* zero right now */
4891 +};
4892 +
4893 +struct ext2_xattr_entry {
4894 +       __u8    e_name_len;     /* length of name */
4895 +       __u8    e_name_index;   /* attribute name index */
4896 +       __u16   e_value_offs;   /* offset in disk block of value */
4897 +       __u32   e_value_block;  /* disk block attribute is stored on (n/i) */
4898 +       __u32   e_value_size;   /* size of attribute value */
4899 +       __u32   e_hash;         /* hash value of name and value */
4900 +       char    e_name[0];      /* attribute name */
4901 +};
4902 +
4903 +#define EXT2_XATTR_PAD_BITS            2
4904 +#define EXT2_XATTR_PAD         (1<<EXT2_XATTR_PAD_BITS)
4905 +#define EXT2_XATTR_ROUND               (EXT2_XATTR_PAD-1)
4906 +#define EXT2_XATTR_LEN(name_len) \
4907 +       (((name_len) + EXT2_XATTR_ROUND + \
4908 +       sizeof(struct ext2_xattr_entry)) & ~EXT2_XATTR_ROUND)
4909 +#define EXT2_XATTR_NEXT(entry) \
4910 +       ( (struct ext2_xattr_entry *)( \
4911 +         (char *)(entry) + EXT2_XATTR_LEN((entry)->e_name_len)) )
4912 +#define EXT2_XATTR_SIZE(size) \
4913 +       (((size) + EXT2_XATTR_ROUND) & ~EXT2_XATTR_ROUND)
4914 +
4915 +#ifdef __KERNEL__
4916 +
4917 +# ifdef CONFIG_EXT2_FS_XATTR
4918 +
4919 +struct ext2_xattr_handler {
4920 +       char *prefix;
4921 +       size_t (*list)(char *list, struct inode *inode, const char *name,
4922 +                      int name_len);
4923 +       int (*get)(struct inode *inode, const char *name, void *buffer,
4924 +                  size_t size);
4925 +       int (*set)(struct inode *inode, const char *name, const void *buffer,
4926 +                  size_t size, int flags);
4927 +};
4928 +
4929 +extern int ext2_xattr_register(int, struct ext2_xattr_handler *);
4930 +extern void ext2_xattr_unregister(int, struct ext2_xattr_handler *);
4931 +
4932 +extern int ext2_setxattr(struct dentry *, const char *, const void *, size_t, int);
4933 +extern ssize_t ext2_getxattr(struct dentry *, const char *, void *, size_t);
4934 +extern ssize_t ext2_listxattr(struct dentry *, char *, size_t);
4935 +extern int ext2_removexattr(struct dentry *, const char *);
4936 +
4937 +extern int ext2_xattr_get(struct inode *, int, const char *, void *, size_t);
4938 +extern int ext2_xattr_list(struct inode *, char *, size_t);
4939 +extern int ext2_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
4940 +
4941 +extern void ext2_xattr_delete_inode(struct inode *);
4942 +extern void ext2_xattr_put_super(struct super_block *);
4943 +
4944 +extern int init_ext2_xattr(void) __init;
4945 +extern void exit_ext2_xattr(void);
4946 +
4947 +# else  /* CONFIG_EXT2_FS_XATTR */
4948 +#  define ext2_setxattr                NULL
4949 +#  define ext2_getxattr                NULL
4950 +#  define ext2_listxattr       NULL
4951 +#  define ext2_removexattr     NULL
4952 +
4953 +static inline int
4954 +ext2_xattr_get(struct inode *inode, int name_index,
4955 +              const char *name, void *buffer, size_t size)
4956 +{
4957 +       return -ENOTSUP;
4958 +}
4959 +
4960 +static inline int
4961 +ext2_xattr_list(struct inode *inode, char *buffer, size_t size)
4962 +{
4963 +       return -ENOTSUP;
4964 +}
4965 +
4966 +static inline int
4967 +ext2_xattr_set(struct inode *inode, int name_index, const char *name,
4968 +              const void *value, size_t size, int flags)
4969 +{
4970 +       return -ENOTSUP;
4971 +}
4972 +
4973 +static inline void
4974 +ext2_xattr_delete_inode(struct inode *inode)
4975 +{
4976 +}
4977 +
4978 +static inline void
4979 +ext2_xattr_put_super(struct super_block *sb)
4980 +{
4981 +}
4982 +
4983 +static inline int
4984 +init_ext2_xattr(void)
4985 +{
4986 +       return 0;
4987 +}
4988 +
4989 +static inline void
4990 +exit_ext2_xattr(void)
4991 +{
4992 +}
4993 +
4994 +# endif  /* CONFIG_EXT2_FS_XATTR */
4995 +
4996 +# ifdef CONFIG_EXT2_FS_XATTR_USER
4997 +
4998 +extern int init_ext2_xattr_user(void) __init;
4999 +extern void exit_ext2_xattr_user(void);
5000 +
5001 +# else  /* CONFIG_EXT2_FS_XATTR_USER */
5002 +
5003 +static inline int
5004 +init_ext2_xattr_user(void)
5005 +{
5006 +       return 0;
5007 +}
5008 +
5009 +static inline void
5010 +exit_ext2_xattr_user(void)
5011 +{
5012 +}
5013 +
5014 +# endif  /* CONFIG_EXT2_FS_XATTR_USER */
5015 +
5016 +#endif  /* __KERNEL__ */
5017 +
5018 Index: linux-2.4.24-vanilla/include/linux/ext3_fs.h
5019 ===================================================================
5020 --- linux-2.4.24-vanilla.orig/include/linux/ext3_fs.h   2004-01-10 17:11:50.000000000 +0300
5021 +++ linux-2.4.24-vanilla/include/linux/ext3_fs.h        2004-01-10 17:20:28.000000000 +0300
5022 @@ -63,8 +63,6 @@
5023   */
5024  #define        EXT3_BAD_INO             1      /* Bad blocks inode */
5025  #define EXT3_ROOT_INO           2      /* Root inode */
5026 -#define EXT3_ACL_IDX_INO        3      /* ACL inode */
5027 -#define EXT3_ACL_DATA_INO       4      /* ACL inode */
5028  #define EXT3_BOOT_LOADER_INO    5      /* Boot loader inode */
5029  #define EXT3_UNDEL_DIR_INO      6      /* Undelete directory inode */
5030  #define EXT3_RESIZE_INO                 7      /* Reserved group descriptors inode */
5031 @@ -94,7 +92,6 @@
5032  #else
5033  # define EXT3_BLOCK_SIZE(s)            (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
5034  #endif
5035 -#define EXT3_ACLE_PER_BLOCK(s)         (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_acl_entry))
5036  #define        EXT3_ADDR_PER_BLOCK(s)          (EXT3_BLOCK_SIZE(s) / sizeof (__u32))
5037  #ifdef __KERNEL__
5038  # define EXT3_BLOCK_SIZE_BITS(s)       ((s)->s_blocksize_bits)
5039 @@ -129,28 +126,6 @@
5040  #endif
5041  
5042  /*
5043 - * ACL structures
5044 - */
5045 -struct ext3_acl_header /* Header of Access Control Lists */
5046 -{
5047 -       __u32   aclh_size;
5048 -       __u32   aclh_file_count;
5049 -       __u32   aclh_acle_count;
5050 -       __u32   aclh_first_acle;
5051 -};
5052 -
5053 -struct ext3_acl_entry  /* Access Control List Entry */
5054 -{
5055 -       __u32   acle_size;
5056 -       __u16   acle_perms;     /* Access permissions */
5057 -       __u16   acle_type;      /* Type of entry */
5058 -       __u16   acle_tag;       /* User or group identity */
5059 -       __u16   acle_pad1;
5060 -       __u32   acle_next;      /* Pointer on next entry for the */
5061 -                                       /* same inode or on next free entry */
5062 -};
5063 -
5064 -/*
5065   * Structure of a blocks group descriptor
5066   */
5067  struct ext3_group_desc
5068 @@ -344,6 +319,7 @@
5069    #define EXT3_MOUNT_WRITEBACK_DATA    0x0C00  /* No data ordering */
5070  #define EXT3_MOUNT_UPDATE_JOURNAL      0x1000  /* Update the journal format */
5071  #define EXT3_MOUNT_NO_UID32            0x2000  /* Disable 32-bit UIDs */
5072 +#define EXT3_MOUNT_XATTR_USER          0x4000  /* Extended user attributes */
5073  
5074  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
5075  #ifndef _LINUX_EXT2_FS_H
5076 @@ -521,7 +497,7 @@
5077  #define EXT3_FEATURE_INCOMPAT_RECOVER          0x0004 /* Needs recovery */
5078  #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV      0x0008 /* Journal device */
5079  
5080 -#define EXT3_FEATURE_COMPAT_SUPP       0
5081 +#define EXT3_FEATURE_COMPAT_SUPP       EXT2_FEATURE_COMPAT_EXT_ATTR
5082  #define EXT3_FEATURE_INCOMPAT_SUPP     (EXT3_FEATURE_INCOMPAT_FILETYPE| \
5083                                          EXT3_FEATURE_INCOMPAT_RECOVER)
5084  #define EXT3_FEATURE_RO_COMPAT_SUPP    (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
5085 @@ -704,6 +680,7 @@
5086  extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
5087  
5088  /* inode.c */
5089 +extern int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
5090  extern struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
5091  extern struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
5092  
5093 @@ -773,8 +750,10 @@
5094  
5095  /* namei.c */
5096  extern struct inode_operations ext3_dir_inode_operations;
5097 +extern struct inode_operations ext3_special_inode_operations;
5098  
5099  /* symlink.c */
5100 +extern struct inode_operations ext3_symlink_inode_operations;
5101  extern struct inode_operations ext3_fast_symlink_inode_operations;
5102  
5103  
5104 Index: linux-2.4.24-vanilla/include/linux/ext3_jbd.h
5105 ===================================================================
5106 --- linux-2.4.24-vanilla.orig/include/linux/ext3_jbd.h  2004-01-10 17:11:50.000000000 +0300
5107 +++ linux-2.4.24-vanilla/include/linux/ext3_jbd.h       2004-01-10 17:20:28.000000000 +0300
5108 @@ -30,13 +30,19 @@
5109  
5110  #define EXT3_SINGLEDATA_TRANS_BLOCKS   8U
5111  
5112 +/* Extended attributes may touch two data buffers, two bitmap buffers,
5113 + * and two group and summaries. */
5114 +
5115 +#define EXT3_XATTR_TRANS_BLOCKS                8
5116 +
5117  /* Define the minimum size for a transaction which modifies data.  This
5118   * needs to take into account the fact that we may end up modifying two
5119   * quota files too (one for the group, one for the user quota).  The
5120   * superblock only gets updated once, of course, so don't bother
5121   * counting that again for the quota updates. */
5122  
5123 -#define EXT3_DATA_TRANS_BLOCKS         (3 * EXT3_SINGLEDATA_TRANS_BLOCKS - 2)
5124 +#define EXT3_DATA_TRANS_BLOCKS         (3 * EXT3_SINGLEDATA_TRANS_BLOCKS + \
5125 +                                        EXT3_XATTR_TRANS_BLOCKS - 2)
5126  
5127  extern int ext3_writepage_trans_blocks(struct inode *inode);
5128  
5129 Index: linux-2.4.24-vanilla/include/linux/ext3_xattr.h
5130 ===================================================================
5131 --- linux-2.4.24-vanilla.orig/include/linux/ext3_xattr.h        2003-01-30 13:24:37.000000000 +0300
5132 +++ linux-2.4.24-vanilla/include/linux/ext3_xattr.h     2004-01-10 17:20:28.000000000 +0300
5133 @@ -0,0 +1,157 @@
5134 +/*
5135 +  File: linux/ext3_xattr.h
5136 +
5137 +  On-disk format of extended attributes for the ext3 filesystem.
5138 +
5139 +  (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
5140 +*/
5141 +
5142 +#include <linux/config.h>
5143 +#include <linux/init.h>
5144 +#include <linux/xattr.h>
5145 +
5146 +/* Magic value in attribute blocks */
5147 +#define EXT3_XATTR_MAGIC               0xEA020000
5148 +
5149 +/* Maximum number of references to one attribute block */
5150 +#define EXT3_XATTR_REFCOUNT_MAX                1024
5151 +
5152 +/* Name indexes */
5153 +#define EXT3_XATTR_INDEX_MAX                   10
5154 +#define EXT3_XATTR_INDEX_USER                  1
5155 +#define EXT3_XATTR_INDEX_POSIX_ACL_ACCESS      2
5156 +#define EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT     3
5157 +
5158 +struct ext3_xattr_header {
5159 +       __u32   h_magic;        /* magic number for identification */
5160 +       __u32   h_refcount;     /* reference count */
5161 +       __u32   h_blocks;       /* number of disk blocks used */
5162 +       __u32   h_hash;         /* hash value of all attributes */
5163 +       __u32   h_reserved[4];  /* zero right now */
5164 +};
5165 +
5166 +struct ext3_xattr_entry {
5167 +       __u8    e_name_len;     /* length of name */
5168 +       __u8    e_name_index;   /* attribute name index */
5169 +       __u16   e_value_offs;   /* offset in disk block of value */
5170 +       __u32   e_value_block;  /* disk block attribute is stored on (n/i) */
5171 +       __u32   e_value_size;   /* size of attribute value */
5172 +       __u32   e_hash;         /* hash value of name and value */
5173 +       char    e_name[0];      /* attribute name */
5174 +};
5175 +
5176 +#define EXT3_XATTR_PAD_BITS            2
5177 +#define EXT3_XATTR_PAD         (1<<EXT3_XATTR_PAD_BITS)
5178 +#define EXT3_XATTR_ROUND               (EXT3_XATTR_PAD-1)
5179 +#define EXT3_XATTR_LEN(name_len) \
5180 +       (((name_len) + EXT3_XATTR_ROUND + \
5181 +       sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND)
5182 +#define EXT3_XATTR_NEXT(entry) \
5183 +       ( (struct ext3_xattr_entry *)( \
5184 +         (char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) )
5185 +#define EXT3_XATTR_SIZE(size) \
5186 +       (((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND)
5187 +
5188 +#ifdef __KERNEL__
5189 +
5190 +# ifdef CONFIG_EXT3_FS_XATTR
5191 +
5192 +struct ext3_xattr_handler {
5193 +       char *prefix;
5194 +       size_t (*list)(char *list, struct inode *inode, const char *name,
5195 +                      int name_len);
5196 +       int (*get)(struct inode *inode, const char *name, void *buffer,
5197 +                  size_t size);
5198 +       int (*set)(struct inode *inode, const char *name, const void *buffer,
5199 +                  size_t size, int flags);
5200 +};
5201 +
5202 +extern int ext3_xattr_register(int, struct ext3_xattr_handler *);
5203 +extern void ext3_xattr_unregister(int, struct ext3_xattr_handler *);
5204 +
5205 +extern int ext3_setxattr(struct dentry *, const char *, const void *, size_t, int);
5206 +extern ssize_t ext3_getxattr(struct dentry *, const char *, void *, size_t);
5207 +extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
5208 +extern int ext3_removexattr(struct dentry *, const char *);
5209 +
5210 +extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
5211 +extern int ext3_xattr_list(struct inode *, char *, size_t);
5212 +extern int ext3_xattr_set(handle_t *handle, struct inode *, int, const char *, const void *, size_t, int);
5213 +
5214 +extern void ext3_xattr_delete_inode(handle_t *, struct inode *);
5215 +extern void ext3_xattr_put_super(struct super_block *);
5216 +
5217 +extern int init_ext3_xattr(void) __init;
5218 +extern void exit_ext3_xattr(void);
5219 +
5220 +# else  /* CONFIG_EXT3_FS_XATTR */
5221 +#  define ext3_setxattr                NULL
5222 +#  define ext3_getxattr                NULL
5223 +#  define ext3_listxattr       NULL
5224 +#  define ext3_removexattr     NULL
5225 +
5226 +static inline int
5227 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
5228 +              void *buffer, size_t size)
5229 +{
5230 +       return -ENOTSUP;
5231 +}
5232 +
5233 +static inline int
5234 +ext3_xattr_list(struct inode *inode, void *buffer, size_t size)
5235 +{
5236 +       return -ENOTSUP;
5237 +}
5238 +
5239 +static inline int
5240 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
5241 +              const char *name, const void *value, size_t size, int flags)
5242 +{
5243 +       return -ENOTSUP;
5244 +}
5245 +
5246 +static inline void
5247 +ext3_xattr_delete_inode(handle_t *handle, struct inode *inode)
5248 +{
5249 +}
5250 +
5251 +static inline void
5252 +ext3_xattr_put_super(struct super_block *sb)
5253 +{
5254 +}
5255 +
5256 +static inline int
5257 +init_ext3_xattr(void)
5258 +{
5259 +       return 0;
5260 +}
5261 +
5262 +static inline void
5263 +exit_ext3_xattr(void)
5264 +{
5265 +}
5266 +
5267 +# endif  /* CONFIG_EXT3_FS_XATTR */
5268 +
5269 +# ifdef CONFIG_EXT3_FS_XATTR_USER
5270 +
5271 +extern int init_ext3_xattr_user(void) __init;
5272 +extern void exit_ext3_xattr_user(void);
5273 +
5274 +# else  /* CONFIG_EXT3_FS_XATTR_USER */
5275 +
5276 +static inline int
5277 +init_ext3_xattr_user(void)
5278 +{
5279 +       return 0;
5280 +}
5281 +
5282 +static inline void
5283 +exit_ext3_xattr_user(void)
5284 +{
5285 +}
5286 +
5287 +#endif  /* CONFIG_EXT3_FS_XATTR_USER */
5288 +
5289 +#endif  /* __KERNEL__ */
5290 +
5291 Index: linux-2.4.24-vanilla/include/linux/fs.h
5292 ===================================================================
5293 --- linux-2.4.24-vanilla.orig/include/linux/fs.h        2004-01-10 17:11:45.000000000 +0300
5294 +++ linux-2.4.24-vanilla/include/linux/fs.h     2004-01-10 17:20:28.000000000 +0300
5295 @@ -913,7 +913,7 @@
5296         int (*setattr) (struct dentry *, struct iattr *);
5297         int (*setattr_raw) (struct inode *, struct iattr *);
5298         int (*getattr) (struct dentry *, struct iattr *);
5299 -       int (*setxattr) (struct dentry *, const char *, void *, size_t, int);
5300 +       int (*setxattr) (struct dentry *, const char *, const void *, size_t, int);
5301         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
5302         ssize_t (*listxattr) (struct dentry *, char *, size_t);
5303         int (*removexattr) (struct dentry *, const char *);
5304 Index: linux-2.4.24-vanilla/include/linux/mbcache.h
5305 ===================================================================
5306 --- linux-2.4.24-vanilla.orig/include/linux/mbcache.h   2003-01-30 13:24:37.000000000 +0300
5307 +++ linux-2.4.24-vanilla/include/linux/mbcache.h        2004-01-10 17:20:28.000000000 +0300
5308 @@ -0,0 +1,69 @@
5309 +/*
5310 +  File: linux/mbcache.h
5311 +
5312 +  (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
5313 +*/
5314 +
5315 +/* Hardwire the number of additional indexes */
5316 +#define MB_CACHE_INDEXES_COUNT 1
5317 +
5318 +struct mb_cache_entry;
5319 +
5320 +struct mb_cache_op {
5321 +       int (*free)(struct mb_cache_entry *, int);
5322 +};
5323 +
5324 +struct mb_cache {
5325 +       struct list_head                c_cache_list;
5326 +       const char                      *c_name;
5327 +       struct mb_cache_op              c_op;
5328 +       atomic_t                        c_entry_count;
5329 +       int                             c_bucket_count;
5330 +#ifndef MB_CACHE_INDEXES_COUNT
5331 +       int                             c_indexes_count;
5332 +#endif
5333 +       kmem_cache_t                    *c_entry_cache;
5334 +       struct list_head                *c_block_hash;
5335 +       struct list_head                *c_indexes_hash[0];
5336 +};
5337 +
5338 +struct mb_cache_entry_index {
5339 +       struct list_head                o_list;
5340 +       unsigned int                    o_key;
5341 +};
5342 +
5343 +struct mb_cache_entry {
5344 +       struct list_head                e_lru_list;
5345 +       struct mb_cache                 *e_cache;
5346 +       atomic_t                        e_used;
5347 +       kdev_t                          e_dev;
5348 +       unsigned long                   e_block;
5349 +       struct list_head                e_block_list;
5350 +       struct mb_cache_entry_index     e_indexes[0];
5351 +};
5352 +
5353 +/* Functions on caches */
5354 +
5355 +struct mb_cache * mb_cache_create(const char *, struct mb_cache_op *, size_t,
5356 +                                 int, int);
5357 +void mb_cache_shrink(struct mb_cache *, kdev_t);
5358 +void mb_cache_destroy(struct mb_cache *);
5359 +
5360 +/* Functions on cache entries */
5361 +
5362 +struct mb_cache_entry *mb_cache_entry_alloc(struct mb_cache *);
5363 +int mb_cache_entry_insert(struct mb_cache_entry *, kdev_t, unsigned long,
5364 +                         unsigned int[]);
5365 +void mb_cache_entry_rehash(struct mb_cache_entry *, unsigned int[]);
5366 +void mb_cache_entry_release(struct mb_cache_entry *);
5367 +void mb_cache_entry_takeout(struct mb_cache_entry *);
5368 +void mb_cache_entry_free(struct mb_cache_entry *);
5369 +struct mb_cache_entry *mb_cache_entry_dup(struct mb_cache_entry *);
5370 +struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *, kdev_t,
5371 +                                         unsigned long);
5372 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
5373 +struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache, int,
5374 +                                                kdev_t, unsigned int);
5375 +struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache_entry *, int,
5376 +                                               kdev_t, unsigned int);
5377 +#endif
5378 Index: linux-2.4.24-vanilla/kernel/ksyms.c
5379 ===================================================================
5380 --- linux-2.4.24-vanilla.orig/kernel/ksyms.c    2004-01-10 17:11:43.000000000 +0300
5381 +++ linux-2.4.24-vanilla/kernel/ksyms.c 2004-01-10 17:20:28.000000000 +0300
5382 @@ -11,6 +11,7 @@
5383  
5384  #include <linux/config.h>
5385  #include <linux/slab.h>
5386 +#include <linux/cache_def.h>
5387  #include <linux/module.h>
5388  #include <linux/blkdev.h>
5389  #include <linux/cdrom.h>
5390 @@ -92,6 +93,7 @@
5391  EXPORT_SYMBOL(exit_files);
5392  EXPORT_SYMBOL(exit_fs);
5393  EXPORT_SYMBOL(exit_sighand);
5394 +EXPORT_SYMBOL(copy_fs_struct);
5395  
5396  /* internal kernel memory management */
5397  EXPORT_SYMBOL(_alloc_pages);
5398 @@ -109,6 +111,8 @@
5399  EXPORT_SYMBOL(kmem_cache_alloc);
5400  EXPORT_SYMBOL(kmem_cache_free);
5401  EXPORT_SYMBOL(kmem_cache_size);
5402 +EXPORT_SYMBOL(register_cache);
5403 +EXPORT_SYMBOL(unregister_cache);
5404  EXPORT_SYMBOL(kmalloc);
5405  EXPORT_SYMBOL(kfree);
5406  EXPORT_SYMBOL(vfree);
5407 Index: linux-2.4.24-vanilla/mm/vmscan.c
5408 ===================================================================
5409 --- linux-2.4.24-vanilla.orig/mm/vmscan.c       2004-01-10 17:06:00.000000000 +0300
5410 +++ linux-2.4.24-vanilla/mm/vmscan.c    2004-01-10 17:21:00.000000000 +0300
5411 @@ -18,6 +18,7 @@
5412  #include <linux/kernel_stat.h>
5413  #include <linux/swap.h>
5414  #include <linux/swapctl.h>
5415 +#include <linux/cache_def.h>
5416  #include <linux/smp_lock.h>
5417  #include <linux/pagemap.h>
5418  #include <linux/init.h>
5419 @@ -34,6 +35,39 @@
5420   */
5421  int vm_passes = 60;
5422  
5423 +static DECLARE_MUTEX(other_caches_sem);
5424 +static LIST_HEAD(cache_definitions);
5425 +
5426 +void register_cache(struct cache_definition *cache)
5427 +{
5428 +       down(&other_caches_sem);
5429 +       list_add(&cache->link, &cache_definitions);
5430 +       up(&other_caches_sem);
5431 +}
5432 +
5433 +void unregister_cache(struct cache_definition *cache)
5434 +{
5435 +       down(&other_caches_sem);
5436 +       list_del(&cache->link);
5437 +       up(&other_caches_sem);
5438 +}
5439 +
5440 +static void shrink_other_caches(unsigned int priority, int gfp_mask)
5441 +{
5442 +       struct list_head *p;
5443 +
5444 +       if (down_trylock(&other_caches_sem))
5445 +               return;
5446 +
5447 +       list_for_each_prev(p, &cache_definitions) {
5448 +               struct cache_definition *cache =
5449 +                       list_entry(p, struct cache_definition, link);
5450 +
5451 +               cache->shrink(priority, gfp_mask);
5452 +       }
5453 +       up(&other_caches_sem);
5454 +}
5455 +
5456  /*
5457   * "vm_cache_scan_ratio" is how much of the inactive LRU queue we will scan
5458   * in one go. A value of 6 for vm_cache_scan_ratio implies that we'll
5459 @@ -523,6 +557,7 @@
5460  #ifdef CONFIG_QUOTA
5461                                 shrink_dqcache_memory(vm_vfs_scan_ratio, gfp_mask);
5462  #endif
5463 +                               shrink_other_caches(vm_vfs_scan_ratio, gfp_mask);
5464  
5465                                 if (!*failed_swapout)
5466                                         *failed_swapout = !swap_out(classzone);
5467 @@ -645,6 +680,7 @@
5468  #ifdef CONFIG_QUOTA
5469                         shrink_dqcache_memory(vm_vfs_scan_ratio, gfp_mask);
5470  #endif
5471 +                       shrink_other_caches(vm_vfs_scan_ratio, gfp_mask);
5472                         if (!failed_swapout)
5473                                 failed_swapout = !swap_out(classzone);
5474                 } while (--tries);