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