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