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