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