1 Documentation/Configure.help | 66 ++
2 arch/alpha/defconfig | 7
3 arch/alpha/kernel/entry.S | 12
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
25 fs/ext2/inode.c | 34 -
28 fs/ext2/symlink.c | 14
29 fs/ext2/xattr.c | 1212 +++++++++++++++++++++++++++++++++++++++++
30 fs/ext2/xattr_user.c | 103 +++
32 fs/ext3/ext3-exports.c | 13
35 fs/ext3/inode.c | 35 -
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
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 ++
59 58 files changed, 4306 insertions(+), 137 deletions(-)
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
65 # Automatically generated make config: don't edit
67 +CONFIG_EXT3_FS_XATTR=y
68 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
69 +# CONFIG_EXT3_FS_XATTR_USER is not set
70 +# CONFIG_EXT2_FS_XATTR is not set
71 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
72 +# CONFIG_EXT2_FS_XATTR_USER is not set
73 +# CONFIG_FS_MBCACHE is not set
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:
81 .quad sys_ni_syscall /* 380, sys_security */
86 + .quad sys_getxattr /* 385 */
90 + .quad sys_llistxattr
91 + .quad sys_flistxattr /* 390 */
92 + .quad sys_removexattr
93 + .quad sys_lremovexattr
94 + .quad sys_fremovexattr
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
102 # Automatically generated make config: don't edit
104 +CONFIG_EXT3_FS_XATTR=y
105 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
106 +# CONFIG_EXT3_FS_XATTR_USER is not set
107 +# CONFIG_EXT2_FS_XATTR is not set
108 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
109 +# CONFIG_EXT2_FS_XATTR_USER is not set
110 +# CONFIG_FS_MBCACHE is not set
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
151 # Automatically generated make config: don't edit
153 +CONFIG_EXT3_FS_XATTR=y
154 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
155 +# CONFIG_EXT3_FS_XATTR_USER is not set
156 +# CONFIG_EXT2_FS_XATTR is not set
157 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
158 +# CONFIG_EXT2_FS_XATTR_USER is not set
159 +# CONFIG_FS_MBCACHE is not set
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
167 # Automatically generated make config: don't edit
169 +CONFIG_EXT3_FS_XATTR=y
170 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
171 +# CONFIG_EXT3_FS_XATTR_USER is not set
172 +# CONFIG_EXT2_FS_XATTR is not set
173 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
174 +# CONFIG_EXT2_FS_XATTR_USER is not set
175 +# CONFIG_FS_MBCACHE is not set
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
183 # Automatically generated make config: don't edit
185 +CONFIG_EXT3_FS_XATTR=y
186 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
187 +# CONFIG_EXT3_FS_XATTR_USER is not set
188 +# CONFIG_EXT2_FS_XATTR is not set
189 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
190 +# CONFIG_EXT2_FS_XATTR_USER is not set
191 +# CONFIG_FS_MBCACHE is not set
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
199 # Automatically generated make config: don't edit
201 +CONFIG_EXT3_FS_XATTR=y
202 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
203 +# CONFIG_EXT3_FS_XATTR_USER is not set
204 +# CONFIG_EXT2_FS_XATTR is not set
205 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
206 +# CONFIG_EXT2_FS_XATTR_USER is not set
207 +# CONFIG_FS_MBCACHE is not set
209 # CONFIG_MIPS32 is not set
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
215 # Automatically generated make config: don't edit
217 +CONFIG_EXT3_FS_XATTR=y
218 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
219 +# CONFIG_EXT3_FS_XATTR_USER is not set
220 +# CONFIG_EXT2_FS_XATTR is not set
221 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
222 +# CONFIG_EXT2_FS_XATTR_USER is not set
223 +# CONFIG_FS_MBCACHE is not set
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 */
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 */
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
249 # Automatically generated make config: don't edit
251 +CONFIG_EXT3_FS_XATTR=y
252 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
253 +# CONFIG_EXT3_FS_XATTR_USER is not set
254 +# CONFIG_EXT2_FS_XATTR is not set
255 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
256 +# CONFIG_EXT2_FS_XATTR_USER is not set
257 +# CONFIG_FS_MBCACHE is not set
258 # CONFIG_UID16 is not set
259 # CONFIG_RWSEM_GENERIC_SPINLOCK is not set
260 CONFIG_RWSEM_XCHGADD_ALGORITHM=y
261 --- linux-2.4.22-ac1/arch/s390/defconfig~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:18.000000000 +0400
262 +++ linux-2.4.22-ac1-alexey/arch/s390/defconfig 2003-09-25 23:57:02.000000000 +0400
265 # Automatically generated make config: don't edit
267 +CONFIG_EXT3_FS_XATTR=y
268 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
269 +# CONFIG_EXT3_FS_XATTR_USER is not set
270 +# CONFIG_EXT2_FS_XATTR is not set
271 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
272 +# CONFIG_EXT2_FS_XATTR_USER is not set
273 +# CONFIG_FS_MBCACHE is not set
274 # CONFIG_ISA is not set
275 # CONFIG_EISA is not set
276 # CONFIG_MCA is not set
277 --- linux-2.4.22-ac1/arch/s390/kernel/entry.S~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:18.000000000 +0400
278 +++ linux-2.4.22-ac1-alexey/arch/s390/kernel/entry.S 2003-09-25 23:57:02.000000000 +0400
279 @@ -559,18 +559,18 @@ sys_call_table:
283 - .long sys_ni_syscall /* 224 - reserved for setxattr */
284 - .long sys_ni_syscall /* 225 - reserved for lsetxattr */
285 - .long sys_ni_syscall /* 226 - reserved for fsetxattr */
286 - .long sys_ni_syscall /* 227 - reserved for getxattr */
287 - .long sys_ni_syscall /* 228 - reserved for lgetxattr */
288 - .long sys_ni_syscall /* 229 - reserved for fgetxattr */
289 - .long sys_ni_syscall /* 230 - reserved for listxattr */
290 - .long sys_ni_syscall /* 231 - reserved for llistxattr */
291 - .long sys_ni_syscall /* 232 - reserved for flistxattr */
292 - .long sys_ni_syscall /* 233 - reserved for removexattr */
293 - .long sys_ni_syscall /* 234 - reserved for lremovexattr */
294 - .long sys_ni_syscall /* 235 - reserved for fremovexattr */
296 + .long sys_lsetxattr /* 225 */
297 + .long sys_fsetxattr
299 + .long sys_lgetxattr
300 + .long sys_fgetxattr
301 + .long sys_listxattr /* 230 */
302 + .long sys_llistxattr
303 + .long sys_flistxattr
304 + .long sys_removexattr
305 + .long sys_lremovexattr
306 + .long sys_fremovexattr /* 235 */
310 --- linux-2.4.22-ac1/arch/s390x/defconfig~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:18.000000000 +0400
311 +++ linux-2.4.22-ac1-alexey/arch/s390x/defconfig 2003-09-25 23:57:02.000000000 +0400
314 # Automatically generated make config: don't edit
316 +CONFIG_EXT3_FS_XATTR=y
317 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
318 +# CONFIG_EXT3_FS_XATTR_USER is not set
319 +# CONFIG_EXT2_FS_XATTR is not set
320 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
321 +# CONFIG_EXT2_FS_XATTR_USER is not set
322 +# CONFIG_FS_MBCACHE is not set
323 # CONFIG_ISA is not set
324 # CONFIG_EISA is not set
325 # CONFIG_MCA is not set
326 --- linux-2.4.22-ac1/arch/s390x/kernel/entry.S~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:18.000000000 +0400
327 +++ linux-2.4.22-ac1-alexey/arch/s390x/kernel/entry.S 2003-09-25 23:57:02.000000000 +0400
328 @@ -591,18 +591,18 @@ sys_call_table:
329 .long SYSCALL(sys_ni_syscall,sys32_fcntl64_wrapper)
330 .long SYSCALL(sys_readahead,sys32_readahead)
331 .long SYSCALL(sys_ni_syscall,sys_ni_syscall)
332 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 224 - reserved for setxattr */
333 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 225 - reserved for lsetxattr */
334 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 226 - reserved for fsetxattr */
335 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 227 - reserved for getxattr */
336 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 228 - reserved for lgetxattr */
337 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 229 - reserved for fgetxattr */
338 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 230 - reserved for listxattr */
339 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 231 - reserved for llistxattr */
340 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 232 - reserved for flistxattr */
341 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 233 - reserved for removexattr */
342 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 234 - reserved for lremovexattr */
343 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 235 - reserved for fremovexattr */
344 + .long SYSCALL(sys_setxattr,sys32_setxattr_wrapper)
345 + .long SYSCALL(sys_lsetxattr,sys32_lsetxattr_wrapper) /* 225 */
346 + .long SYSCALL(sys_fsetxattr,sys32_fsetxattr_wrapper)
347 + .long SYSCALL(sys_getxattr,sys32_getxattr_wrapper)
348 + .long SYSCALL(sys_lgetxattr,sys32_lgetxattr_wrapper)
349 + .long SYSCALL(sys_fgetxattr,sys32_fgetxattr_wrapper)
350 + .long SYSCALL(sys_listxattr,sys32_listxattr_wrapper) /* 230 */
351 + .long SYSCALL(sys_llistxattr,sys32_llistxattr_wrapper)
352 + .long SYSCALL(sys_flistxattr,sys32_flistxattr_wrapper)
353 + .long SYSCALL(sys_removexattr,sys32_removexattr_wrapper)
354 + .long SYSCALL(sys_lremovexattr,sys32_lremovexattr_wrapper)
355 + .long SYSCALL(sys_fremovexattr,sys32_fremovexattr_wrapper)/* 235 */
356 .long SYSCALL(sys_gettid,sys_gettid)
357 .long SYSCALL(sys_tkill,sys_tkill)
359 --- linux-2.4.22-ac1/arch/s390x/kernel/wrapper32.S~xattr-0.8.54-2.4.22-rh 2003-08-25 15:44:40.000000000 +0400
360 +++ linux-2.4.22-ac1-alexey/arch/s390x/kernel/wrapper32.S 2003-09-26 00:05:14.000000000 +0400
361 @@ -1097,6 +1097,96 @@ sys32_fstat64_wrapper:
362 llgtr %r3,%r3 # struct stat64 *
364 jg sys32_fstat64 # branch to system call
366 + .globl sys32_setxattr_wrapper
367 +sys32_setxattr_wrapper:
368 + llgtr %r2,%r2 # char *
369 + llgtr %r3,%r3 # char *
370 + llgtr %r4,%r4 # void *
371 + llgfr %r5,%r5 # size_t
375 + .globl sys32_lsetxattr_wrapper
376 +sys32_lsetxattr_wrapper:
377 + llgtr %r2,%r2 # char *
378 + llgtr %r3,%r3 # char *
379 + llgtr %r4,%r4 # void *
380 + llgfr %r5,%r5 # size_t
384 + .globl sys32_fsetxattr_wrapper
385 +sys32_fsetxattr_wrapper:
387 + llgtr %r3,%r3 # char *
388 + llgtr %r4,%r4 # void *
389 + llgfr %r5,%r5 # size_t
393 + .globl sys32_getxattr_wrapper
394 +sys32_getxattr_wrapper:
395 + llgtr %r2,%r2 # char *
396 + llgtr %r3,%r3 # char *
397 + llgtr %r4,%r4 # void *
398 + llgfr %r5,%r5 # size_t
401 + .globl sys32_lgetxattr_wrapper
402 +sys32_lgetxattr_wrapper:
403 + llgtr %r2,%r2 # char *
404 + llgtr %r3,%r3 # char *
405 + llgtr %r4,%r4 # void *
406 + llgfr %r5,%r5 # size_t
409 + .globl sys32_fgetxattr_wrapper
410 +sys32_fgetxattr_wrapper:
412 + llgtr %r3,%r3 # char *
413 + llgtr %r4,%r4 # void *
414 + llgfr %r5,%r5 # size_t
417 + .globl sys32_listxattr_wrapper
418 +sys32_listxattr_wrapper:
419 + llgtr %r2,%r2 # char *
420 + llgtr %r3,%r3 # char *
421 + llgfr %r4,%r4 # size_t
424 + .globl sys32_llistxattr_wrapper
425 +sys32_llistxattr_wrapper:
426 + llgtr %r2,%r2 # char *
427 + llgtr %r3,%r3 # char *
428 + llgfr %r4,%r4 # size_t
431 + .globl sys32_flistxattr_wrapper
432 +sys32_flistxattr_wrapper:
434 + llgtr %r3,%r3 # char *
435 + llgfr %r4,%r4 # size_t
438 + .globl sys32_removexattr_wrapper
439 +sys32_removexattr_wrapper:
440 + llgtr %r2,%r2 # char *
441 + llgtr %r3,%r3 # char *
444 + .globl sys32_lremovexattr_wrapper
445 +sys32_lremovexattr_wrapper:
446 + llgtr %r2,%r2 # char *
447 + llgtr %r3,%r3 # char *
448 + jg sys_lremovexattr
450 + .globl sys32_fremovexattr_wrapper
451 +sys32_fremovexattr_wrapper:
453 + llgtr %r3,%r3 # char *
454 + jg sys_fremovexattr
456 .globl sys32_stime_wrapper
458 --- linux-2.4.22-ac1/arch/sparc64/defconfig~xattr-0.8.54-2.4.22-rh 2003-08-25 15:44:40.000000000 +0400
459 +++ linux-2.4.22-ac1-alexey/arch/sparc64/defconfig 2003-09-25 23:57:02.000000000 +0400
462 # Automatically generated make config: don't edit
464 +CONFIG_EXT3_FS_XATTR=y
465 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
466 +# CONFIG_EXT3_FS_XATTR_USER is not set
467 +# CONFIG_EXT2_FS_XATTR is not set
468 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
469 +# CONFIG_EXT2_FS_XATTR_USER is not set
470 +# CONFIG_FS_MBCACHE is not set
473 # Code maturity level options
474 --- linux-2.4.22-ac1/arch/sparc/defconfig~xattr-0.8.54-2.4.22-rh 2002-08-03 04:39:43.000000000 +0400
475 +++ linux-2.4.22-ac1-alexey/arch/sparc/defconfig 2003-09-25 23:57:02.000000000 +0400
478 # Automatically generated make config: don't edit
480 +CONFIG_EXT3_FS_XATTR=y
481 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
482 +# CONFIG_EXT3_FS_XATTR_USER is not set
483 +# CONFIG_EXT2_FS_XATTR is not set
484 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
485 +# CONFIG_EXT2_FS_XATTR_USER is not set
486 +# CONFIG_FS_MBCACHE is not set
490 --- linux-2.4.22-ac1/Documentation/Configure.help~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:30.000000000 +0400
491 +++ linux-2.4.22-ac1-alexey/Documentation/Configure.help 2003-09-25 23:57:02.000000000 +0400
492 @@ -16145,6 +16145,39 @@ CONFIG_EXT2_FS
493 be compiled as a module, and so this could be dangerous. Most
494 everyone wants to say Y here.
496 +Ext2 extended attributes
497 +CONFIG_EXT2_FS_XATTR
498 + Extended attributes are name:value pairs associated with inodes by
499 + the kernel or by users (see the attr(5) manual page, or visit
500 + <http://acl.bestbits.at/> for details).
504 +Ext2 extended attribute block sharing
505 +CONFIG_EXT2_FS_XATTR_SHARING
506 + This options enables code for sharing identical extended attribute
507 + blocks among multiple inodes.
511 +Ext2 extended user attributes
512 +CONFIG_EXT2_FS_XATTR_USER
513 + This option enables extended user attributes on ext2. Processes can
514 + associate extended user attributes with inodes to store additional
515 + information such as the character encoding of files, etc. (see the
516 + attr(5) manual page, or visit <http://acl.bestbits.at/> for details).
520 +Ext2 trusted extended attributes
521 +CONFIG_EXT2_FS_XATTR_TRUSTED
522 + This option enables extended attributes on ext2 that are accessible
523 + (and visible) only to users capable of CAP_SYS_ADMIN. Usually this
524 + is only the super user. Trusted extended attributes are meant for
525 + implementing system/security services.
529 Ext3 journalling file system support (EXPERIMENTAL)
531 This is the journalling version of the Second extended file system
532 @@ -16177,6 +16210,39 @@ CONFIG_EXT3_FS
533 of your root partition (the one containing the directory /) cannot
534 be compiled as a module, and so this may be dangerous.
536 +Ext3 extended attributes
537 +CONFIG_EXT3_FS_XATTR
538 + Extended attributes are name:value pairs associated with inodes by
539 + the kernel or by users (see the attr(5) manual page, or visit
540 + <http://acl.bestbits.at/> for details).
544 +Ext3 extended attribute block sharing
545 +CONFIG_EXT3_FS_XATTR_SHARING
546 + This options enables code for sharing identical extended attribute
547 + blocks among multiple inodes.
551 +Ext3 extended user attributes
552 +CONFIG_EXT3_FS_XATTR_USER
553 + This option enables extended user attributes on ext3. Processes can
554 + associate extended user attributes with inodes to store additional
555 + information such as the character encoding of files, etc. (see the
556 + attr(5) manual page, or visit <http://acl.bestbits.at/> for details).
560 +Ext3 trusted extended attributes
561 +CONFIG_EXT3_FS_XATTR_TRUSTED
562 + This option enables extended attributes on ext3 that are accessible
563 + (and visible) only to users capable of CAP_SYS_ADMIN. Usually this
564 + is only the super user. Trusted extended attributes are meant for
565 + implementing system/security services.
569 Journal Block Device support (JBD for ext3) (EXPERIMENTAL)
571 This is a generic journalling layer for block devices. It is
572 --- linux-2.4.22-ac1/fs/Config.in~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:23.000000000 +0400
573 +++ linux-2.4.22-ac1-alexey/fs/Config.in 2003-09-25 23:57:02.000000000 +0400
574 @@ -29,6 +29,11 @@ dep_mbool ' Debug Befs' CONFIG_BEFS_DEB
575 dep_tristate 'BFS file system support (EXPERIMENTAL)' CONFIG_BFS_FS $CONFIG_EXPERIMENTAL
577 tristate 'Ext3 journalling file system support' CONFIG_EXT3_FS
578 +dep_mbool ' Ext3 extended attributes' CONFIG_EXT3_FS_XATTR $CONFIG_EXT3_FS
579 +dep_bool ' Ext3 extended attribute block sharing' \
580 + CONFIG_EXT3_FS_XATTR_SHARING $CONFIG_EXT3_FS_XATTR
581 +dep_bool ' Ext3 extended user attributes' \
582 + CONFIG_EXT3_FS_XATTR_USER $CONFIG_EXT3_FS_XATTR
583 # CONFIG_JBD could be its own option (even modular), but until there are
584 # other users than ext3, we will simply make it be the same as CONFIG_EXT3_FS
585 # dep_tristate ' Journal Block Device support (JBD for ext3)' CONFIG_JBD $CONFIG_EXT3_FS
586 @@ -88,6 +93,11 @@ dep_mbool ' QNX4FS write support (DANGE
587 tristate 'ROM file system support' CONFIG_ROMFS_FS
589 tristate 'Second extended fs support' CONFIG_EXT2_FS
590 +dep_mbool ' Ext2 extended attributes' CONFIG_EXT2_FS_XATTR $CONFIG_EXT2_FS
591 +dep_bool ' Ext2 extended attribute block sharing' \
592 + CONFIG_EXT2_FS_XATTR_SHARING $CONFIG_EXT2_FS_XATTR
593 +dep_bool ' Ext2 extended user attributes' \
594 + CONFIG_EXT2_FS_XATTR_USER $CONFIG_EXT2_FS_XATTR
596 tristate 'System V/Xenix/V7/Coherent file system support' CONFIG_SYSV_FS
598 @@ -164,6 +174,10 @@ else
599 define_tristate CONFIG_ZISOFS_FS n
602 +# Meta block cache for Extended Attributes (ext2/ext3)
603 +#tristate 'Meta block cache' CONFIG_FS_MBCACHE
604 +define_tristate CONFIG_FS_MBCACHE y
606 mainmenu_option next_comment
607 comment 'Partition Types'
608 source fs/partitions/Config.in
609 --- linux-2.4.22-ac1/fs/ext2/file.c~xattr-0.8.54-2.4.22-rh 2001-10-11 19:05:18.000000000 +0400
610 +++ linux-2.4.22-ac1-alexey/fs/ext2/file.c 2003-09-25 23:57:02.000000000 +0400
613 #include <linux/fs.h>
614 #include <linux/ext2_fs.h>
615 +#include <linux/ext2_xattr.h>
616 #include <linux/sched.h>
619 @@ -51,4 +52,8 @@ struct file_operations ext2_file_operati
621 struct inode_operations ext2_file_inode_operations = {
622 truncate: ext2_truncate,
623 + setxattr: ext2_setxattr,
624 + getxattr: ext2_getxattr,
625 + listxattr: ext2_listxattr,
626 + removexattr: ext2_removexattr,
628 --- linux-2.4.22-ac1/fs/ext2/ialloc.c~xattr-0.8.54-2.4.22-rh 2003-06-13 18:51:37.000000000 +0400
629 +++ linux-2.4.22-ac1-alexey/fs/ext2/ialloc.c 2003-09-25 23:57:02.000000000 +0400
631 #include <linux/config.h>
632 #include <linux/fs.h>
633 #include <linux/ext2_fs.h>
634 +#include <linux/ext2_xattr.h>
635 #include <linux/locks.h>
636 #include <linux/quotaops.h>
638 @@ -167,6 +168,7 @@ void ext2_free_inode (struct inode * ino
640 if (!is_bad_inode(inode)) {
641 /* Quota is already initialized in iput() */
642 + ext2_xattr_delete_inode(inode);
643 DQUOT_FREE_INODE(inode);
646 --- linux-2.4.22-ac1/fs/ext2/inode.c~xattr-0.8.54-2.4.22-rh 2003-06-13 18:51:37.000000000 +0400
647 +++ linux-2.4.22-ac1-alexey/fs/ext2/inode.c 2003-09-25 23:57:02.000000000 +0400
648 @@ -39,6 +39,18 @@ MODULE_LICENSE("GPL");
649 static int ext2_update_inode(struct inode * inode, int do_sync);
652 + * Test whether an inode is a fast symlink.
654 +static inline int ext2_inode_is_fast_symlink(struct inode *inode)
656 + int ea_blocks = inode->u.ext2_i.i_file_acl ?
657 + (inode->i_sb->s_blocksize >> 9) : 0;
659 + return (S_ISLNK(inode->i_mode) &&
660 + inode->i_blocks - ea_blocks == 0);
664 * Called at each iput()
666 void ext2_put_inode (struct inode * inode)
667 @@ -53,9 +65,7 @@ void ext2_delete_inode (struct inode * i
671 - if (is_bad_inode(inode) ||
672 - inode->i_ino == EXT2_ACL_IDX_INO ||
673 - inode->i_ino == EXT2_ACL_DATA_INO)
674 + if (is_bad_inode(inode))
676 inode->u.ext2_i.i_dtime = CURRENT_TIME;
677 mark_inode_dirty(inode);
678 @@ -801,6 +811,8 @@ void ext2_truncate (struct inode * inode
679 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
680 S_ISLNK(inode->i_mode)))
682 + if (ext2_inode_is_fast_symlink(inode))
684 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
687 @@ -903,8 +915,7 @@ void ext2_read_inode (struct inode * ino
688 unsigned long offset;
689 struct ext2_group_desc * gdp;
691 - if ((inode->i_ino != EXT2_ROOT_INO && inode->i_ino != EXT2_ACL_IDX_INO &&
692 - inode->i_ino != EXT2_ACL_DATA_INO &&
693 + if ((inode->i_ino != EXT2_ROOT_INO &&
694 inode->i_ino < EXT2_FIRST_INO(inode->i_sb)) ||
695 inode->i_ino > le32_to_cpu(inode->i_sb->u.ext2_sb.s_es->s_inodes_count)) {
696 ext2_error (inode->i_sb, "ext2_read_inode",
697 @@ -989,10 +1000,7 @@ void ext2_read_inode (struct inode * ino
698 for (block = 0; block < EXT2_N_BLOCKS; block++)
699 inode->u.ext2_i.i_data[block] = raw_inode->i_block[block];
701 - if (inode->i_ino == EXT2_ACL_IDX_INO ||
702 - inode->i_ino == EXT2_ACL_DATA_INO)
703 - /* Nothing to do */ ;
704 - else if (S_ISREG(inode->i_mode)) {
705 + if (S_ISREG(inode->i_mode)) {
706 inode->i_op = &ext2_file_inode_operations;
707 inode->i_fop = &ext2_file_operations;
708 inode->i_mapping->a_ops = &ext2_aops;
709 @@ -1001,15 +1009,17 @@ void ext2_read_inode (struct inode * ino
710 inode->i_fop = &ext2_dir_operations;
711 inode->i_mapping->a_ops = &ext2_aops;
712 } else if (S_ISLNK(inode->i_mode)) {
713 - if (!inode->i_blocks)
714 + if (ext2_inode_is_fast_symlink(inode))
715 inode->i_op = &ext2_fast_symlink_inode_operations;
717 - inode->i_op = &page_symlink_inode_operations;
718 + inode->i_op = &ext2_symlink_inode_operations;
719 inode->i_mapping->a_ops = &ext2_aops;
723 + inode->i_op = &ext2_special_inode_operations;
724 init_special_inode(inode, inode->i_mode,
725 le32_to_cpu(raw_inode->i_block[0]));
728 inode->i_attr_flags = 0;
729 ext2_set_inode_flags(inode);
730 --- linux-2.4.22-ac1/fs/ext2/Makefile~xattr-0.8.54-2.4.22-rh 2001-10-11 19:05:18.000000000 +0400
731 +++ linux-2.4.22-ac1-alexey/fs/ext2/Makefile 2003-09-25 23:57:02.000000000 +0400
732 @@ -13,4 +13,8 @@ obj-y := balloc.o bitmap.o dir.o file
733 ioctl.o namei.o super.o symlink.o
736 +export-objs += xattr.o
737 +obj-$(CONFIG_EXT2_FS_XATTR) += xattr.o
738 +obj-$(CONFIG_EXT2_FS_XATTR_USER) += xattr_user.o
740 include $(TOPDIR)/Rules.make
741 --- linux-2.4.22-ac1/fs/ext2/namei.c~xattr-0.8.54-2.4.22-rh 2001-10-04 09:57:36.000000000 +0400
742 +++ linux-2.4.22-ac1-alexey/fs/ext2/namei.c 2003-09-25 23:57:02.000000000 +0400
745 #include <linux/fs.h>
746 #include <linux/ext2_fs.h>
747 +#include <linux/ext2_xattr.h>
748 #include <linux/pagemap.h>
751 @@ -136,7 +137,7 @@ static int ext2_symlink (struct inode *
753 if (l > sizeof (inode->u.ext2_i.i_data)) {
755 - inode->i_op = &page_symlink_inode_operations;
756 + inode->i_op = &ext2_symlink_inode_operations;
757 inode->i_mapping->a_ops = &ext2_aops;
758 err = block_symlink(inode, symname, l);
760 @@ -345,4 +346,15 @@ struct inode_operations ext2_dir_inode_o
764 + setxattr: ext2_setxattr,
765 + getxattr: ext2_getxattr,
766 + listxattr: ext2_listxattr,
767 + removexattr: ext2_removexattr,
770 +struct inode_operations ext2_special_inode_operations = {
771 + setxattr: ext2_setxattr,
772 + getxattr: ext2_getxattr,
773 + listxattr: ext2_listxattr,
774 + removexattr: ext2_removexattr,
776 --- linux-2.4.22-ac1/fs/ext2/super.c~xattr-0.8.54-2.4.22-rh 2002-11-29 02:53:15.000000000 +0300
777 +++ linux-2.4.22-ac1-alexey/fs/ext2/super.c 2003-09-25 23:57:02.000000000 +0400
779 #include <linux/string.h>
780 #include <linux/fs.h>
781 #include <linux/ext2_fs.h>
782 +#include <linux/ext2_xattr.h>
783 #include <linux/slab.h>
784 #include <linux/init.h>
785 #include <linux/locks.h>
786 @@ -125,6 +126,7 @@ void ext2_put_super (struct super_block
790 + ext2_xattr_put_super(sb);
791 if (!(sb->s_flags & MS_RDONLY)) {
792 struct ext2_super_block *es = EXT2_SB(sb)->s_es;
794 @@ -175,6 +177,13 @@ static int parse_options (char * options
795 this_char = strtok (NULL, ",")) {
796 if ((value = strchr (this_char, '=')) != NULL)
798 +#ifdef CONFIG_EXT2_FS_XATTR_USER
799 + if (!strcmp (this_char, "user_xattr"))
800 + set_opt (*mount_options, XATTR_USER);
801 + else if (!strcmp (this_char, "nouser_xattr"))
802 + clear_opt (*mount_options, XATTR_USER);
805 if (!strcmp (this_char, "bsddf"))
806 clear_opt (*mount_options, MINIX_DF);
807 else if (!strcmp (this_char, "nouid32")) {
808 @@ -424,6 +433,9 @@ struct super_block * ext2_read_super (st
809 blocksize = BLOCK_SIZE;
811 sb->u.ext2_sb.s_mount_opt = 0;
812 +#ifdef CONFIG_EXT2_FS_XATTR_USER
813 + /* set_opt (sb->u.ext2_sb.s_mount_opt, XATTR_USER); */
815 if (!parse_options ((char *) data, &sb_block, &resuid, &resgid,
816 &sb->u.ext2_sb.s_mount_opt)) {
818 @@ -813,12 +825,27 @@ static DECLARE_FSTYPE_DEV(ext2_fs_type,
820 static int __init init_ext2_fs(void)
822 - return register_filesystem(&ext2_fs_type);
823 + int error = init_ext2_xattr();
826 + error = init_ext2_xattr_user();
829 + error = register_filesystem(&ext2_fs_type);
833 + exit_ext2_xattr_user();
839 static void __exit exit_ext2_fs(void)
841 unregister_filesystem(&ext2_fs_type);
842 + exit_ext2_xattr_user();
847 --- linux-2.4.22-ac1/fs/ext2/symlink.c~xattr-0.8.54-2.4.22-rh 2000-09-28 00:41:33.000000000 +0400
848 +++ linux-2.4.22-ac1-alexey/fs/ext2/symlink.c 2003-09-25 23:57:02.000000000 +0400
851 #include <linux/fs.h>
852 #include <linux/ext2_fs.h>
853 +#include <linux/ext2_xattr.h>
855 static int ext2_readlink(struct dentry *dentry, char *buffer, int buflen)
857 @@ -32,7 +33,20 @@ static int ext2_follow_link(struct dentr
858 return vfs_follow_link(nd, s);
861 +struct inode_operations ext2_symlink_inode_operations = {
862 + readlink: page_readlink,
863 + follow_link: page_follow_link,
864 + setxattr: ext2_setxattr,
865 + getxattr: ext2_getxattr,
866 + listxattr: ext2_listxattr,
867 + removexattr: ext2_removexattr,
870 struct inode_operations ext2_fast_symlink_inode_operations = {
871 readlink: ext2_readlink,
872 follow_link: ext2_follow_link,
873 + setxattr: ext2_setxattr,
874 + getxattr: ext2_getxattr,
875 + listxattr: ext2_listxattr,
876 + removexattr: ext2_removexattr,
878 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
879 +++ linux-2.4.22-ac1-alexey/fs/ext2/xattr.c 2003-09-25 23:57:02.000000000 +0400
882 + * linux/fs/ext2/xattr.c
884 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
886 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
887 + * Extended attributes for symlinks and special files added per
888 + * suggestion of Luka Renko <luka.renko@hermes.si>.
892 + * Extended attributes are stored on disk blocks allocated outside of
893 + * any inode. The i_file_acl field is then made to point to this allocated
894 + * block. If all extended attributes of an inode are identical, these
895 + * inodes may share the same extended attribute block. Such situations
896 + * are automatically detected by keeping a cache of recent attribute block
897 + * numbers and hashes over the block's contents in memory.
900 + * Extended attribute block layout:
902 + * +------------------+
905 + * | entry 2 | | growing downwards
907 + * | four null bytes |
910 + * | value 3 | | growing upwards
912 + * +------------------+
914 + * The block header is followed by multiple entry descriptors. These entry
915 + * descriptors are variable in size, and alligned to EXT2_XATTR_PAD
916 + * byte boundaries. The entry descriptors are sorted by attribute name,
917 + * so that two extended attribute blocks can be compared efficiently.
919 + * Attribute values are aligned to the end of the block, stored in
920 + * no specific order. They are also padded to EXT2_XATTR_PAD byte
921 + * boundaries. No additional gaps are left between them.
925 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
926 + * the xattr inode operations are called, so we are guaranteed that only one
927 + * processes accesses extended attributes of an inode at any time.
929 + * For writing we also grab the ext2_xattr_sem semaphore. This ensures that
930 + * only a single process is modifying an extended attribute block, even
931 + * if the block is shared among inodes.
933 + * Note for porting to 2.5
934 + * -----------------------
935 + * The BKL will no longer be held in the xattr inode operations.
938 +#include <linux/module.h>
939 +#include <linux/locks.h>
940 +#include <linux/slab.h>
941 +#include <linux/fs.h>
942 +#include <linux/ext2_fs.h>
943 +#include <linux/ext2_xattr.h>
944 +#include <linux/mbcache.h>
945 +#include <linux/quotaops.h>
946 +#include <asm/semaphore.h>
947 +#include <linux/compatmac.h>
949 +/* These symbols may be needed by a module. */
950 +EXPORT_SYMBOL(ext2_xattr_register);
951 +EXPORT_SYMBOL(ext2_xattr_unregister);
952 +EXPORT_SYMBOL(ext2_xattr_get);
953 +EXPORT_SYMBOL(ext2_xattr_list);
954 +EXPORT_SYMBOL(ext2_xattr_set);
956 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
957 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
960 +#define HDR(bh) ((struct ext2_xattr_header *)((bh)->b_data))
961 +#define ENTRY(ptr) ((struct ext2_xattr_entry *)(ptr))
962 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
963 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
965 +#ifdef EXT2_XATTR_DEBUG
966 +# define ea_idebug(inode, f...) do { \
967 + printk(KERN_DEBUG "inode %s:%ld: ", \
968 + kdevname(inode->i_dev), inode->i_ino); \
972 +# define ea_bdebug(bh, f...) do { \
973 + printk(KERN_DEBUG "block %s:%ld: ", \
974 + kdevname(bh->b_dev), bh->b_blocknr); \
979 +# define ea_idebug(f...)
980 +# define ea_bdebug(f...)
983 +static int ext2_xattr_set2(struct inode *, struct buffer_head *,
984 + struct ext2_xattr_header *);
986 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
988 +static int ext2_xattr_cache_insert(struct buffer_head *);
989 +static struct buffer_head *ext2_xattr_cache_find(struct inode *,
990 + struct ext2_xattr_header *);
991 +static void ext2_xattr_cache_remove(struct buffer_head *);
992 +static void ext2_xattr_rehash(struct ext2_xattr_header *,
993 + struct ext2_xattr_entry *);
995 +static struct mb_cache *ext2_xattr_cache;
998 +# define ext2_xattr_cache_insert(bh) 0
999 +# define ext2_xattr_cache_find(inode, header) NULL
1000 +# define ext2_xattr_cache_remove(bh) while(0) {}
1001 +# define ext2_xattr_rehash(header, entry) while(0) {}
1005 + * If a file system does not share extended attributes among inodes,
1006 + * we should not need the ext2_xattr_sem semaphore. However, the
1007 + * filesystem may still contain shared blocks, so we always take
1011 +DECLARE_MUTEX(ext2_xattr_sem);
1014 +ext2_xattr_new_block(struct inode *inode, int * errp, int force)
1016 + struct super_block *sb = inode->i_sb;
1017 + int goal = le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block) +
1018 + EXT2_I(inode)->i_block_group * EXT2_BLOCKS_PER_GROUP(sb);
1020 + /* How can we enforce the allocation? */
1021 + int block = ext2_new_block(inode, goal, 0, 0, errp);
1024 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
1030 +ext2_xattr_quota_alloc(struct inode *inode, int force)
1032 + /* How can we enforce the allocation? */
1034 + int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
1036 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
1038 + int error = DQUOT_ALLOC_BLOCK(inode, 1);
1046 +ext2_xattr_quota_free(struct inode *inode)
1048 + DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
1049 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
1053 +ext2_xattr_free_block(struct inode * inode, unsigned long block)
1055 + ext2_free_blocks(inode, block, 1);
1056 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
1060 +# define ext2_xattr_quota_free(inode) \
1061 + DQUOT_FREE_BLOCK(inode, 1)
1062 +# define ext2_xattr_free_block(inode, block) \
1063 + ext2_free_blocks(inode, block, 1)
1066 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
1068 +static inline struct buffer_head *
1069 +sb_bread(struct super_block *sb, int block)
1071 + return bread(sb->s_dev, block, sb->s_blocksize);
1074 +static inline struct buffer_head *
1075 +sb_getblk(struct super_block *sb, int block)
1077 + return getblk(sb->s_dev, block, sb->s_blocksize);
1082 +struct ext2_xattr_handler *ext2_xattr_handlers[EXT2_XATTR_INDEX_MAX];
1083 +rwlock_t ext2_handler_lock = RW_LOCK_UNLOCKED;
1086 +ext2_xattr_register(int name_index, struct ext2_xattr_handler *handler)
1088 + int error = -EINVAL;
1090 + if (name_index > 0 && name_index <= EXT2_XATTR_INDEX_MAX) {
1091 + write_lock(&ext2_handler_lock);
1092 + if (!ext2_xattr_handlers[name_index-1]) {
1093 + ext2_xattr_handlers[name_index-1] = handler;
1096 + write_unlock(&ext2_handler_lock);
1102 +ext2_xattr_unregister(int name_index, struct ext2_xattr_handler *handler)
1104 + if (name_index > 0 || name_index <= EXT2_XATTR_INDEX_MAX) {
1105 + write_lock(&ext2_handler_lock);
1106 + ext2_xattr_handlers[name_index-1] = NULL;
1107 + write_unlock(&ext2_handler_lock);
1111 +static inline const char *
1112 +strcmp_prefix(const char *a, const char *a_prefix)
1114 + while (*a_prefix && *a == *a_prefix) {
1118 + return *a_prefix ? NULL : a;
1122 + * Decode the extended attribute name, and translate it into
1123 + * the name_index and name suffix.
1125 +static struct ext2_xattr_handler *
1126 +ext2_xattr_resolve_name(const char **name)
1128 + struct ext2_xattr_handler *handler = NULL;
1133 + read_lock(&ext2_handler_lock);
1134 + for (i=0; i<EXT2_XATTR_INDEX_MAX; i++) {
1135 + if (ext2_xattr_handlers[i]) {
1136 + const char *n = strcmp_prefix(*name,
1137 + ext2_xattr_handlers[i]->prefix);
1139 + handler = ext2_xattr_handlers[i];
1145 + read_unlock(&ext2_handler_lock);
1149 +static inline struct ext2_xattr_handler *
1150 +ext2_xattr_handler(int name_index)
1152 + struct ext2_xattr_handler *handler = NULL;
1153 + if (name_index > 0 && name_index <= EXT2_XATTR_INDEX_MAX) {
1154 + read_lock(&ext2_handler_lock);
1155 + handler = ext2_xattr_handlers[name_index-1];
1156 + read_unlock(&ext2_handler_lock);
1162 + * Inode operation getxattr()
1164 + * dentry->d_inode->i_sem down
1165 + * BKL held [before 2.5.x]
1168 +ext2_getxattr(struct dentry *dentry, const char *name,
1169 + void *buffer, size_t size)
1171 + struct ext2_xattr_handler *handler;
1172 + struct inode *inode = dentry->d_inode;
1174 + handler = ext2_xattr_resolve_name(&name);
1177 + return handler->get(inode, name, buffer, size);
1181 + * Inode operation listxattr()
1183 + * dentry->d_inode->i_sem down
1184 + * BKL held [before 2.5.x]
1187 +ext2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1189 + return ext2_xattr_list(dentry->d_inode, buffer, size);
1193 + * Inode operation setxattr()
1195 + * dentry->d_inode->i_sem down
1196 + * BKL held [before 2.5.x]
1199 +ext2_setxattr(struct dentry *dentry, const char *name,
1200 + const void *value, size_t size, int flags)
1202 + struct ext2_xattr_handler *handler;
1203 + struct inode *inode = dentry->d_inode;
1206 + value = ""; /* empty EA, do not remove */
1207 + handler = ext2_xattr_resolve_name(&name);
1210 + return handler->set(inode, name, value, size, flags);
1214 + * Inode operation removexattr()
1216 + * dentry->d_inode->i_sem down
1217 + * BKL held [before 2.5.x]
1220 +ext2_removexattr(struct dentry *dentry, const char *name)
1222 + struct ext2_xattr_handler *handler;
1223 + struct inode *inode = dentry->d_inode;
1225 + handler = ext2_xattr_resolve_name(&name);
1228 + return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
1232 + * ext2_xattr_get()
1234 + * Copy an extended attribute into the buffer
1235 + * provided, or compute the buffer size required.
1236 + * Buffer is NULL to compute the size of the buffer required.
1238 + * Returns a negative error number on failure, or the number of bytes
1239 + * used / required on success.
1242 +ext2_xattr_get(struct inode *inode, int name_index, const char *name,
1243 + void *buffer, size_t buffer_size)
1245 + struct buffer_head *bh = NULL;
1246 + struct ext2_xattr_entry *entry;
1247 + unsigned int block, size;
1249 + int name_len, error;
1251 + ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
1252 + name_index, name, buffer, (long)buffer_size);
1256 + if (!EXT2_I(inode)->i_file_acl)
1258 + block = EXT2_I(inode)->i_file_acl;
1259 + ea_idebug(inode, "reading block %d", block);
1260 + bh = sb_bread(inode->i_sb, block);
1263 + ea_bdebug(bh, "b_count=%d, refcount=%d",
1264 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
1265 + end = bh->b_data + bh->b_size;
1266 + if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1267 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1268 +bad_block: ext2_error(inode->i_sb, "ext2_xattr_get",
1269 + "inode %ld: bad block %d", inode->i_ino, block);
1273 + /* find named attribute */
1274 + name_len = strlen(name);
1277 + if (name_len > 255)
1279 + entry = FIRST_ENTRY(bh);
1280 + while (!IS_LAST_ENTRY(entry)) {
1281 + struct ext2_xattr_entry *next =
1282 + EXT2_XATTR_NEXT(entry);
1283 + if ((char *)next >= end)
1285 + if (name_index == entry->e_name_index &&
1286 + name_len == entry->e_name_len &&
1287 + memcmp(name, entry->e_name, name_len) == 0)
1291 + /* Check the remaining name entries */
1292 + while (!IS_LAST_ENTRY(entry)) {
1293 + struct ext2_xattr_entry *next =
1294 + EXT2_XATTR_NEXT(entry);
1295 + if ((char *)next >= end)
1299 + if (ext2_xattr_cache_insert(bh))
1300 + ea_idebug(inode, "cache insert failed");
1304 + /* check the buffer size */
1305 + if (entry->e_value_block != 0)
1307 + size = le32_to_cpu(entry->e_value_size);
1308 + if (size > inode->i_sb->s_blocksize ||
1309 + le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
1312 + if (ext2_xattr_cache_insert(bh))
1313 + ea_idebug(inode, "cache insert failed");
1316 + if (size > buffer_size)
1318 + /* return value of attribute */
1319 + memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
1331 + * ext2_xattr_list()
1333 + * Copy a list of attribute names into the buffer
1334 + * provided, or compute the buffer size required.
1335 + * Buffer is NULL to compute the size of the buffer required.
1337 + * Returns a negative error number on failure, or the number of bytes
1338 + * used / required on success.
1341 +ext2_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
1343 + struct buffer_head *bh = NULL;
1344 + struct ext2_xattr_entry *entry;
1345 + unsigned int block, size = 0;
1349 + ea_idebug(inode, "buffer=%p, buffer_size=%ld",
1350 + buffer, (long)buffer_size);
1352 + if (!EXT2_I(inode)->i_file_acl)
1354 + block = EXT2_I(inode)->i_file_acl;
1355 + ea_idebug(inode, "reading block %d", block);
1356 + bh = sb_bread(inode->i_sb, block);
1359 + ea_bdebug(bh, "b_count=%d, refcount=%d",
1360 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
1361 + end = bh->b_data + bh->b_size;
1362 + if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1363 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1364 +bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
1365 + "inode %ld: bad block %d", inode->i_ino, block);
1369 + /* compute the size required for the list of attribute names */
1370 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
1371 + entry = EXT2_XATTR_NEXT(entry)) {
1372 + struct ext2_xattr_handler *handler;
1373 + struct ext2_xattr_entry *next =
1374 + EXT2_XATTR_NEXT(entry);
1375 + if ((char *)next >= end)
1378 + handler = ext2_xattr_handler(entry->e_name_index);
1380 + size += handler->list(NULL, inode, entry->e_name,
1381 + entry->e_name_len);
1384 + if (ext2_xattr_cache_insert(bh))
1385 + ea_idebug(inode, "cache insert failed");
1391 + if (size > buffer_size)
1395 + /* list the attribute names */
1397 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
1398 + entry = EXT2_XATTR_NEXT(entry)) {
1399 + struct ext2_xattr_handler *handler;
1401 + handler = ext2_xattr_handler(entry->e_name_index);
1403 + buf += handler->list(buf, inode, entry->e_name,
1404 + entry->e_name_len);
1415 + * If the EXT2_FEATURE_COMPAT_EXT_ATTR feature of this file system is
1416 + * not set, set it.
1418 +static void ext2_xattr_update_super_block(struct super_block *sb)
1420 + if (EXT2_HAS_COMPAT_FEATURE(sb, EXT2_FEATURE_COMPAT_EXT_ATTR))
1424 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
1425 + EXT2_SB(sb)->s_feature_compat |= EXT2_FEATURE_COMPAT_EXT_ATTR;
1427 + EXT2_SB(sb)->s_es->s_feature_compat |=
1428 + cpu_to_le32(EXT2_FEATURE_COMPAT_EXT_ATTR);
1430 + mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
1435 + * ext2_xattr_set()
1437 + * Create, replace or remove an extended attribute for this inode. Buffer
1438 + * is NULL to remove an existing extended attribute, and non-NULL to
1439 + * either replace an existing extended attribute, or create a new extended
1440 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
1441 + * specify that an extended attribute must exist and must not exist
1442 + * previous to the call, respectively.
1444 + * Returns 0, or a negative error number on failure.
1447 +ext2_xattr_set(struct inode *inode, int name_index, const char *name,
1448 + const void *value, size_t value_len, int flags)
1450 + struct super_block *sb = inode->i_sb;
1451 + struct buffer_head *bh = NULL;
1452 + struct ext2_xattr_header *header = NULL;
1453 + struct ext2_xattr_entry *here, *last;
1454 + unsigned int name_len;
1455 + int block = EXT2_I(inode)->i_file_acl;
1456 + int min_offs = sb->s_blocksize, not_found = 1, free, error;
1460 + * header -- Points either into bh, or to a temporarily
1461 + * allocated buffer.
1462 + * here -- The named entry found, or the place for inserting, within
1463 + * the block pointed to by header.
1464 + * last -- Points right after the last named entry within the block
1465 + * pointed to by header.
1466 + * min_offs -- The offset of the first value (values are aligned
1467 + * towards the end of the block).
1468 + * end -- Points right after the block pointed to by header.
1471 + ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
1472 + name_index, name, value, (long)value_len);
1474 + if (IS_RDONLY(inode))
1476 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1478 + if (value == NULL)
1482 + name_len = strlen(name);
1483 + if (name_len > 255 || value_len > sb->s_blocksize)
1485 + down(&ext2_xattr_sem);
1488 + /* The inode already has an extended attribute block. */
1490 + bh = sb_bread(sb, block);
1494 + ea_bdebug(bh, "b_count=%d, refcount=%d",
1495 + atomic_read(&(bh->b_count)),
1496 + le32_to_cpu(HDR(bh)->h_refcount));
1498 + end = bh->b_data + bh->b_size;
1499 + if (header->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1500 + header->h_blocks != cpu_to_le32(1)) {
1501 +bad_block: ext2_error(sb, "ext2_xattr_set",
1502 + "inode %ld: bad block %d", inode->i_ino, block);
1506 + /* Find the named attribute. */
1507 + here = FIRST_ENTRY(bh);
1508 + while (!IS_LAST_ENTRY(here)) {
1509 + struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(here);
1510 + if ((char *)next >= end)
1512 + if (!here->e_value_block && here->e_value_size) {
1513 + int offs = le16_to_cpu(here->e_value_offs);
1514 + if (offs < min_offs)
1517 + not_found = name_index - here->e_name_index;
1519 + not_found = name_len - here->e_name_len;
1521 + not_found = memcmp(name, here->e_name,name_len);
1522 + if (not_found <= 0)
1527 + /* We still need to compute min_offs and last. */
1528 + while (!IS_LAST_ENTRY(last)) {
1529 + struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(last);
1530 + if ((char *)next >= end)
1532 + if (!last->e_value_block && last->e_value_size) {
1533 + int offs = le16_to_cpu(last->e_value_offs);
1534 + if (offs < min_offs)
1540 + /* Check whether we have enough space left. */
1541 + free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
1543 + /* We will use a new extended attribute block. */
1544 + free = sb->s_blocksize -
1545 + sizeof(struct ext2_xattr_header) - sizeof(__u32);
1546 + here = last = NULL; /* avoid gcc uninitialized warning. */
1550 + /* Request to remove a nonexistent attribute? */
1552 + if (flags & XATTR_REPLACE)
1555 + if (value == NULL)
1558 + free -= EXT2_XATTR_LEN(name_len);
1560 + /* Request to create an existing attribute? */
1562 + if (flags & XATTR_CREATE)
1564 + if (!here->e_value_block && here->e_value_size) {
1565 + unsigned int size = le32_to_cpu(here->e_value_size);
1567 + if (le16_to_cpu(here->e_value_offs) + size >
1568 + sb->s_blocksize || size > sb->s_blocksize)
1570 + free += EXT2_XATTR_SIZE(size);
1573 + free -= EXT2_XATTR_SIZE(value_len);
1578 + /* Here we know that we can set the new attribute. */
1581 + if (header->h_refcount == cpu_to_le32(1)) {
1582 + ea_bdebug(bh, "modifying in-place");
1583 + ext2_xattr_cache_remove(bh);
1587 + ea_bdebug(bh, "cloning");
1588 + header = kmalloc(bh->b_size, GFP_KERNEL);
1590 + if (header == NULL)
1592 + memcpy(header, HDR(bh), bh->b_size);
1593 + header->h_refcount = cpu_to_le32(1);
1594 + offset = (char *)header - bh->b_data;
1595 + here = ENTRY((char *)here + offset);
1596 + last = ENTRY((char *)last + offset);
1599 + /* Allocate a buffer where we construct the new block. */
1600 + header = kmalloc(sb->s_blocksize, GFP_KERNEL);
1602 + if (header == NULL)
1604 + memset(header, 0, sb->s_blocksize);
1605 + end = (char *)header + sb->s_blocksize;
1606 + header->h_magic = cpu_to_le32(EXT2_XATTR_MAGIC);
1607 + header->h_blocks = header->h_refcount = cpu_to_le32(1);
1608 + last = here = ENTRY(header+1);
1612 + /* Insert the new name. */
1613 + int size = EXT2_XATTR_LEN(name_len);
1614 + int rest = (char *)last - (char *)here;
1615 + memmove((char *)here + size, here, rest);
1616 + memset(here, 0, size);
1617 + here->e_name_index = name_index;
1618 + here->e_name_len = name_len;
1619 + memcpy(here->e_name, name, name_len);
1621 + /* Remove the old value. */
1622 + if (!here->e_value_block && here->e_value_size) {
1623 + char *first_val = (char *)header + min_offs;
1624 + int offs = le16_to_cpu(here->e_value_offs);
1625 + char *val = (char *)header + offs;
1626 + size_t size = EXT2_XATTR_SIZE(
1627 + le32_to_cpu(here->e_value_size));
1628 + memmove(first_val + size, first_val, val - first_val);
1629 + memset(first_val, 0, size);
1630 + here->e_value_offs = 0;
1633 + /* Adjust all value offsets. */
1634 + last = ENTRY(header+1);
1635 + while (!IS_LAST_ENTRY(last)) {
1636 + int o = le16_to_cpu(last->e_value_offs);
1637 + if (!last->e_value_block && o < offs)
1638 + last->e_value_offs =
1639 + cpu_to_le16(o + size);
1640 + last = EXT2_XATTR_NEXT(last);
1643 + if (value == NULL) {
1644 + /* Remove this attribute. */
1645 + if (EXT2_XATTR_NEXT(ENTRY(header+1)) == last) {
1646 + /* This block is now empty. */
1647 + error = ext2_xattr_set2(inode, bh, NULL);
1650 + /* Remove the old name. */
1651 + int size = EXT2_XATTR_LEN(name_len);
1652 + last = ENTRY((char *)last - size);
1653 + memmove(here, (char*)here + size,
1654 + (char*)last - (char*)here);
1655 + memset(last, 0, size);
1660 + if (value != NULL) {
1661 + /* Insert the new value. */
1662 + here->e_value_size = cpu_to_le32(value_len);
1664 + size_t size = EXT2_XATTR_SIZE(value_len);
1665 + char *val = (char *)header + min_offs - size;
1666 + here->e_value_offs =
1667 + cpu_to_le16((char *)val - (char *)header);
1668 + memset(val + size - EXT2_XATTR_PAD, 0,
1669 + EXT2_XATTR_PAD); /* Clear the pad bytes. */
1670 + memcpy(val, value, value_len);
1673 + ext2_xattr_rehash(header, here);
1675 + error = ext2_xattr_set2(inode, bh, header);
1679 + if (!(bh && header == HDR(bh)))
1681 + up(&ext2_xattr_sem);
1687 + * Second half of ext2_xattr_set(): Update the file system.
1690 +ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
1691 + struct ext2_xattr_header *header)
1693 + struct super_block *sb = inode->i_sb;
1694 + struct buffer_head *new_bh = NULL;
1698 + new_bh = ext2_xattr_cache_find(inode, header);
1701 + * We found an identical block in the cache.
1702 + * The old block will be released after updating
1705 + ea_bdebug(old_bh, "reusing block %ld",
1706 + new_bh->b_blocknr);
1709 + if (ext2_xattr_quota_alloc(inode, 1))
1712 + HDR(new_bh)->h_refcount = cpu_to_le32(
1713 + le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
1714 + ea_bdebug(new_bh, "refcount now=%d",
1715 + le32_to_cpu(HDR(new_bh)->h_refcount));
1716 + } else if (old_bh && header == HDR(old_bh)) {
1717 + /* Keep this block. */
1719 + (void)ext2_xattr_cache_insert(new_bh);
1721 + /* We need to allocate a new block */
1722 + int force = EXT2_I(inode)->i_file_acl != 0;
1723 + int block = ext2_xattr_new_block(inode, &error, force);
1726 + ea_idebug(inode, "creating block %d", block);
1728 + new_bh = sb_getblk(sb, block);
1730 + ext2_xattr_free_block(inode, block);
1734 + lock_buffer(new_bh);
1735 + memcpy(new_bh->b_data, header, new_bh->b_size);
1736 + mark_buffer_uptodate(new_bh, 1);
1737 + unlock_buffer(new_bh);
1738 + (void)ext2_xattr_cache_insert(new_bh);
1740 + ext2_xattr_update_super_block(sb);
1742 + mark_buffer_dirty(new_bh);
1743 + if (IS_SYNC(inode)) {
1744 + ll_rw_block(WRITE, 1, &new_bh);
1745 + wait_on_buffer(new_bh);
1747 + if (buffer_req(new_bh) && !buffer_uptodate(new_bh))
1752 + /* Update the inode. */
1753 + EXT2_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
1754 + inode->i_ctime = CURRENT_TIME;
1755 + if (IS_SYNC(inode)) {
1756 + error = ext2_sync_inode (inode);
1760 + mark_inode_dirty(inode);
1763 + if (old_bh && old_bh != new_bh) {
1765 + * If there was an old block, and we are not still using it,
1766 + * we now release the old block.
1768 + unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
1770 + if (refcount == 1) {
1771 + /* Free the old block. */
1772 + ea_bdebug(old_bh, "freeing");
1773 + ext2_xattr_free_block(inode, old_bh->b_blocknr);
1774 + mark_buffer_clean(old_bh);
1776 + /* Decrement the refcount only. */
1778 + HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
1779 + ext2_xattr_quota_free(inode);
1780 + mark_buffer_dirty(old_bh);
1781 + ea_bdebug(old_bh, "refcount now=%d", refcount);
1786 + if (old_bh != new_bh)
1793 + * ext2_xattr_delete_inode()
1795 + * Free extended attribute resources associated with this inode. This
1796 + * is called immediately before an inode is freed.
1799 +ext2_xattr_delete_inode(struct inode *inode)
1801 + struct buffer_head *bh;
1802 + unsigned int block = EXT2_I(inode)->i_file_acl;
1806 + down(&ext2_xattr_sem);
1808 + bh = sb_bread(inode->i_sb, block);
1810 + ext2_error(inode->i_sb, "ext2_xattr_delete_inode",
1811 + "inode %ld: block %d read error", inode->i_ino, block);
1814 + ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
1815 + if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1816 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1817 + ext2_error(inode->i_sb, "ext2_xattr_delete_inode",
1818 + "inode %ld: bad block %d", inode->i_ino, block);
1821 + ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
1822 + if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
1823 + ext2_xattr_cache_remove(bh);
1824 + ext2_xattr_free_block(inode, block);
1828 + HDR(bh)->h_refcount = cpu_to_le32(
1829 + le32_to_cpu(HDR(bh)->h_refcount) - 1);
1830 + mark_buffer_dirty(bh);
1831 + if (IS_SYNC(inode)) {
1832 + ll_rw_block(WRITE, 1, &bh);
1833 + wait_on_buffer(bh);
1835 + ext2_xattr_quota_free(inode);
1837 + EXT2_I(inode)->i_file_acl = 0;
1841 + up(&ext2_xattr_sem);
1845 + * ext2_xattr_put_super()
1847 + * This is called when a file system is unmounted.
1850 +ext2_xattr_put_super(struct super_block *sb)
1852 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
1853 + mb_cache_shrink(ext2_xattr_cache, sb->s_dev);
1857 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
1860 + * ext2_xattr_cache_insert()
1862 + * Create a new entry in the extended attribute cache, and insert
1863 + * it unless such an entry is already in the cache.
1865 + * Returns 0, or a negative error number on failure.
1868 +ext2_xattr_cache_insert(struct buffer_head *bh)
1870 + __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
1871 + struct mb_cache_entry *ce;
1874 + ce = mb_cache_entry_alloc(ext2_xattr_cache);
1877 + error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
1879 + mb_cache_entry_free(ce);
1880 + if (error == -EBUSY) {
1881 + ea_bdebug(bh, "already in cache (%d cache entries)",
1882 + atomic_read(&ext2_xattr_cache->c_entry_count));
1886 + ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
1887 + atomic_read(&ext2_xattr_cache->c_entry_count));
1888 + mb_cache_entry_release(ce);
1894 + * ext2_xattr_cmp()
1896 + * Compare two extended attribute blocks for equality.
1898 + * Returns 0 if the blocks are equal, 1 if they differ, and
1899 + * a negative error number on errors.
1902 +ext2_xattr_cmp(struct ext2_xattr_header *header1,
1903 + struct ext2_xattr_header *header2)
1905 + struct ext2_xattr_entry *entry1, *entry2;
1907 + entry1 = ENTRY(header1+1);
1908 + entry2 = ENTRY(header2+1);
1909 + while (!IS_LAST_ENTRY(entry1)) {
1910 + if (IS_LAST_ENTRY(entry2))
1912 + if (entry1->e_hash != entry2->e_hash ||
1913 + entry1->e_name_len != entry2->e_name_len ||
1914 + entry1->e_value_size != entry2->e_value_size ||
1915 + memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
1917 + if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
1919 + if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
1920 + (char *)header2 + le16_to_cpu(entry2->e_value_offs),
1921 + le32_to_cpu(entry1->e_value_size)))
1924 + entry1 = EXT2_XATTR_NEXT(entry1);
1925 + entry2 = EXT2_XATTR_NEXT(entry2);
1927 + if (!IS_LAST_ENTRY(entry2))
1933 + * ext2_xattr_cache_find()
1935 + * Find an identical extended attribute block.
1937 + * Returns a pointer to the block found, or NULL if such a block was
1938 + * not found or an error occurred.
1940 +static struct buffer_head *
1941 +ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header)
1943 + __u32 hash = le32_to_cpu(header->h_hash);
1944 + struct mb_cache_entry *ce;
1946 + if (!header->h_hash)
1947 + return NULL; /* never share */
1948 + ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
1949 + ce = mb_cache_entry_find_first(ext2_xattr_cache, 0, inode->i_dev, hash);
1951 + struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
1954 + ext2_error(inode->i_sb, "ext2_xattr_cache_find",
1955 + "inode %ld: block %ld read error",
1956 + inode->i_ino, ce->e_block);
1957 + } else if (le32_to_cpu(HDR(bh)->h_refcount) >
1958 + EXT2_XATTR_REFCOUNT_MAX) {
1959 + ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
1960 + le32_to_cpu(HDR(bh)->h_refcount),
1961 + EXT2_XATTR_REFCOUNT_MAX);
1962 + } else if (!ext2_xattr_cmp(header, HDR(bh))) {
1963 + ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
1964 + mb_cache_entry_release(ce);
1968 + ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
1974 + * ext2_xattr_cache_remove()
1976 + * Remove the cache entry of a block from the cache. Called when a
1977 + * block becomes invalid.
1980 +ext2_xattr_cache_remove(struct buffer_head *bh)
1982 + struct mb_cache_entry *ce;
1984 + ce = mb_cache_entry_get(ext2_xattr_cache, bh->b_dev, bh->b_blocknr);
1986 + ea_bdebug(bh, "removing (%d cache entries remaining)",
1987 + atomic_read(&ext2_xattr_cache->c_entry_count)-1);
1988 + mb_cache_entry_free(ce);
1990 + ea_bdebug(bh, "no cache entry");
1993 +#define NAME_HASH_SHIFT 5
1994 +#define VALUE_HASH_SHIFT 16
1997 + * ext2_xattr_hash_entry()
1999 + * Compute the hash of an extended attribute.
2001 +static inline void ext2_xattr_hash_entry(struct ext2_xattr_header *header,
2002 + struct ext2_xattr_entry *entry)
2005 + char *name = entry->e_name;
2008 + for (n=0; n < entry->e_name_len; n++) {
2009 + hash = (hash << NAME_HASH_SHIFT) ^
2010 + (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
2014 + if (entry->e_value_block == 0 && entry->e_value_size != 0) {
2015 + __u32 *value = (__u32 *)((char *)header +
2016 + le16_to_cpu(entry->e_value_offs));
2017 + for (n = (le32_to_cpu(entry->e_value_size) +
2018 + EXT2_XATTR_ROUND) >> EXT2_XATTR_PAD_BITS; n; n--) {
2019 + hash = (hash << VALUE_HASH_SHIFT) ^
2020 + (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
2021 + le32_to_cpu(*value++);
2024 + entry->e_hash = cpu_to_le32(hash);
2027 +#undef NAME_HASH_SHIFT
2028 +#undef VALUE_HASH_SHIFT
2030 +#define BLOCK_HASH_SHIFT 16
2033 + * ext2_xattr_rehash()
2035 + * Re-compute the extended attribute hash value after an entry has changed.
2037 +static void ext2_xattr_rehash(struct ext2_xattr_header *header,
2038 + struct ext2_xattr_entry *entry)
2040 + struct ext2_xattr_entry *here;
2043 + ext2_xattr_hash_entry(header, entry);
2044 + here = ENTRY(header+1);
2045 + while (!IS_LAST_ENTRY(here)) {
2046 + if (!here->e_hash) {
2047 + /* Block is not shared if an entry's hash value == 0 */
2051 + hash = (hash << BLOCK_HASH_SHIFT) ^
2052 + (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
2053 + le32_to_cpu(here->e_hash);
2054 + here = EXT2_XATTR_NEXT(here);
2056 + header->h_hash = cpu_to_le32(hash);
2059 +#undef BLOCK_HASH_SHIFT
2062 +init_ext2_xattr(void)
2064 + ext2_xattr_cache = mb_cache_create("ext2_xattr", NULL,
2065 + sizeof(struct mb_cache_entry) +
2066 + sizeof(struct mb_cache_entry_index), 1, 61);
2067 + if (!ext2_xattr_cache)
2074 +exit_ext2_xattr(void)
2076 + mb_cache_destroy(ext2_xattr_cache);
2079 +#else /* CONFIG_EXT2_FS_XATTR_SHARING */
2082 +init_ext2_xattr(void)
2088 +exit_ext2_xattr(void)
2092 +#endif /* CONFIG_EXT2_FS_XATTR_SHARING */
2093 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
2094 +++ linux-2.4.22-ac1-alexey/fs/ext2/xattr_user.c 2003-09-25 23:57:02.000000000 +0400
2097 + * linux/fs/ext2/xattr_user.c
2098 + * Handler for extended user attributes.
2100 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
2103 +#include <linux/module.h>
2104 +#include <linux/string.h>
2105 +#include <linux/fs.h>
2106 +#include <linux/ext2_fs.h>
2107 +#include <linux/ext2_xattr.h>
2109 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
2110 +# include <linux/ext2_acl.h>
2113 +#define XATTR_USER_PREFIX "user."
2116 +ext2_xattr_user_list(char *list, struct inode *inode,
2117 + const char *name, int name_len)
2119 + const int prefix_len = sizeof(XATTR_USER_PREFIX)-1;
2121 + if (!test_opt(inode->i_sb, XATTR_USER))
2125 + memcpy(list, XATTR_USER_PREFIX, prefix_len);
2126 + memcpy(list+prefix_len, name, name_len);
2127 + list[prefix_len + name_len] = '\0';
2129 + return prefix_len + name_len + 1;
2133 +ext2_xattr_user_get(struct inode *inode, const char *name,
2134 + void *buffer, size_t size)
2138 + if (strcmp(name, "") == 0)
2140 + if (!test_opt(inode->i_sb, XATTR_USER))
2142 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
2143 + error = ext2_permission_locked(inode, MAY_READ);
2145 + error = permission(inode, MAY_READ);
2150 + return ext2_xattr_get(inode, EXT2_XATTR_INDEX_USER, name,
2155 +ext2_xattr_user_set(struct inode *inode, const char *name,
2156 + const void *value, size_t size, int flags)
2160 + if (strcmp(name, "") == 0)
2162 + if (!test_opt(inode->i_sb, XATTR_USER))
2164 + if ( !S_ISREG(inode->i_mode) &&
2165 + (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
2167 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
2168 + error = ext2_permission_locked(inode, MAY_WRITE);
2170 + error = permission(inode, MAY_WRITE);
2175 + return ext2_xattr_set(inode, EXT2_XATTR_INDEX_USER, name,
2176 + value, size, flags);
2179 +struct ext2_xattr_handler ext2_xattr_user_handler = {
2180 + prefix: XATTR_USER_PREFIX,
2181 + list: ext2_xattr_user_list,
2182 + get: ext2_xattr_user_get,
2183 + set: ext2_xattr_user_set,
2187 +init_ext2_xattr_user(void)
2189 + return ext2_xattr_register(EXT2_XATTR_INDEX_USER,
2190 + &ext2_xattr_user_handler);
2194 +exit_ext2_xattr_user(void)
2196 + ext2_xattr_unregister(EXT2_XATTR_INDEX_USER,
2197 + &ext2_xattr_user_handler);
2199 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
2200 +++ linux-2.4.22-ac1-alexey/fs/ext3/ext3-exports.c 2003-09-25 23:57:02.000000000 +0400
2202 +#include <linux/config.h>
2203 +#include <linux/module.h>
2204 +#include <linux/ext3_fs.h>
2205 +#include <linux/ext3_jbd.h>
2206 +#include <linux/ext3_xattr.h>
2208 +EXPORT_SYMBOL(ext3_force_commit);
2209 +EXPORT_SYMBOL(ext3_bread);
2210 +EXPORT_SYMBOL(ext3_xattr_register);
2211 +EXPORT_SYMBOL(ext3_xattr_unregister);
2212 +EXPORT_SYMBOL(ext3_xattr_get);
2213 +EXPORT_SYMBOL(ext3_xattr_list);
2214 +EXPORT_SYMBOL(ext3_xattr_set);
2215 --- linux-2.4.22-ac1/fs/ext3/file.c~xattr-0.8.54-2.4.22-rh 2003-09-25 14:55:12.000000000 +0400
2216 +++ linux-2.4.22-ac1-alexey/fs/ext3/file.c 2003-09-25 23:57:02.000000000 +0400
2218 #include <linux/locks.h>
2219 #include <linux/jbd.h>
2220 #include <linux/ext3_fs.h>
2221 +#include <linux/ext3_xattr.h>
2222 #include <linux/ext3_jbd.h>
2223 #include <linux/smp_lock.h>
2225 @@ -127,5 +128,9 @@ struct file_operations ext3_file_operati
2226 struct inode_operations ext3_file_inode_operations = {
2227 truncate: ext3_truncate, /* BKL held */
2228 setattr: ext3_setattr, /* BKL held */
2229 + setxattr: ext3_setxattr, /* BKL held */
2230 + getxattr: ext3_getxattr, /* BKL held */
2231 + listxattr: ext3_listxattr, /* BKL held */
2232 + removexattr: ext3_removexattr, /* BKL held */
2235 --- linux-2.4.22-ac1/fs/ext3/ialloc.c~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:29.000000000 +0400
2236 +++ linux-2.4.22-ac1-alexey/fs/ext3/ialloc.c 2003-09-25 23:57:02.000000000 +0400
2238 #include <linux/jbd.h>
2239 #include <linux/ext3_fs.h>
2240 #include <linux/ext3_jbd.h>
2241 +#include <linux/ext3_xattr.h>
2242 #include <linux/stat.h>
2243 #include <linux/string.h>
2244 #include <linux/locks.h>
2245 @@ -217,6 +218,7 @@ void ext3_free_inode (handle_t *handle,
2246 * as writing the quota to disk may need the lock as well.
2249 + ext3_xattr_delete_inode(handle, inode);
2250 DQUOT_FREE_INODE(inode);
2253 --- linux-2.4.22-ac1/fs/ext3/inode.c~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:29.000000000 +0400
2254 +++ linux-2.4.22-ac1-alexey/fs/ext3/inode.c 2003-09-26 00:10:09.000000000 +0400
2257 #undef SEARCH_FROM_ZERO
2260 + * Test whether an inode is a fast symlink.
2262 +static inline int ext3_inode_is_fast_symlink(struct inode *inode)
2264 + int ea_blocks = inode->u.ext3_i.i_file_acl ?
2265 + (inode->i_sb->s_blocksize >> 9) : 0;
2267 + return (S_ISLNK(inode->i_mode) &&
2268 + inode->i_blocks - ea_blocks == 0);
2271 /* The ext3 forget function must perform a revoke if we are freeing data
2272 * which has been journaled. Metadata (eg. indirect blocks) must be
2273 * revoked in all cases.
2275 * still needs to be revoked.
2278 -static int ext3_forget(handle_t *handle, int is_metadata,
2279 +int ext3_forget(handle_t *handle, int is_metadata,
2280 struct inode *inode, struct buffer_head *bh,
2283 @@ -179,9 +191,7 @@ void ext3_delete_inode (struct inode * i
2287 - if (is_bad_inode(inode) ||
2288 - inode->i_ino == EXT3_ACL_IDX_INO ||
2289 - inode->i_ino == EXT3_ACL_DATA_INO)
2290 + if (is_bad_inode(inode))
2294 @@ -1874,6 +1884,8 @@ void ext3_truncate(struct inode * inode)
2295 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
2296 S_ISLNK(inode->i_mode)))
2298 + if (ext3_inode_is_fast_symlink(inode))
2300 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2303 @@ -2021,8 +2033,6 @@ int ext3_get_inode_loc (struct inode *in
2304 struct ext3_group_desc * gdp;
2306 if ((inode->i_ino != EXT3_ROOT_INO &&
2307 - inode->i_ino != EXT3_ACL_IDX_INO &&
2308 - inode->i_ino != EXT3_ACL_DATA_INO &&
2309 inode->i_ino != EXT3_JOURNAL_INO &&
2310 inode->i_ino < EXT3_FIRST_INO(inode->i_sb)) ||
2311 inode->i_ino > le32_to_cpu(
2312 @@ -2163,10 +2173,7 @@ void ext3_read_inode(struct inode * inod
2313 inode->u.ext3_i.i_data[block] = iloc.raw_inode->i_block[block];
2314 INIT_LIST_HEAD(&inode->u.ext3_i.i_orphan);
2316 - if (inode->i_ino == EXT3_ACL_IDX_INO ||
2317 - inode->i_ino == EXT3_ACL_DATA_INO)
2318 - /* Nothing to do */ ;
2319 - else if (S_ISREG(inode->i_mode)) {
2320 + if (S_ISREG(inode->i_mode)) {
2321 inode->i_op = &ext3_file_inode_operations;
2322 inode->i_fop = &ext3_file_operations;
2323 inode->i_mapping->a_ops = &ext3_aops;
2324 @@ -2174,15 +2181,17 @@ void ext3_read_inode(struct inode * inod
2325 inode->i_op = &ext3_dir_inode_operations;
2326 inode->i_fop = &ext3_dir_operations;
2327 } else if (S_ISLNK(inode->i_mode)) {
2328 - if (!inode->i_blocks)
2329 + if (ext3_inode_is_fast_symlink(inode))
2330 inode->i_op = &ext3_fast_symlink_inode_operations;
2332 - inode->i_op = &page_symlink_inode_operations;
2333 + inode->i_op = &ext3_symlink_inode_operations;
2334 inode->i_mapping->a_ops = &ext3_aops;
2338 + inode->i_op = &ext3_special_inode_operations;
2339 init_special_inode(inode, inode->i_mode,
2340 le32_to_cpu(iloc.raw_inode->i_block[0]));
2343 ext3_set_inode_flags(inode);
2345 --- linux-2.4.22-ac1/fs/ext3/Makefile~xattr-0.8.54-2.4.22-rh 2003-09-25 14:55:12.000000000 +0400
2346 +++ linux-2.4.22-ac1-alexey/fs/ext3/Makefile 2003-09-25 23:57:02.000000000 +0400
2349 -# Makefile for the linux ext2-filesystem routines.
2350 +# Makefile for the linux ext3-filesystem routines.
2352 # Note! Dependencies are done automagically by 'make dep', which also
2353 # removes any old dependencies. DON'T put your own dependencies here
2358 -export-objs := super.o inode.o
2359 +export-objs := ext3-exports.o
2361 obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
2362 - ioctl.o namei.o super.o symlink.o hash.o
2363 + ioctl.o namei.o super.o symlink.o hash.o ext3-exports.o
2364 obj-m := $(O_TARGET)
2366 +export-objs += xattr.o
2367 +obj-$(CONFIG_EXT3_FS_XATTR) += xattr.o
2368 +obj-$(CONFIG_EXT3_FS_XATTR_USER) += xattr_user.o
2370 include $(TOPDIR)/Rules.make
2371 --- linux-2.4.22-ac1/fs/ext3/namei.c~xattr-0.8.54-2.4.22-rh 2003-09-25 14:58:37.000000000 +0400
2372 +++ linux-2.4.22-ac1-alexey/fs/ext3/namei.c 2003-09-25 23:57:02.000000000 +0400
2374 #include <linux/sched.h>
2375 #include <linux/ext3_fs.h>
2376 #include <linux/ext3_jbd.h>
2377 +#include <linux/ext3_xattr.h>
2378 #include <linux/fcntl.h>
2379 #include <linux/stat.h>
2380 #include <linux/string.h>
2381 @@ -1614,7 +1615,7 @@ static int ext3_mkdir(struct inode * dir
2385 - inode = ext3_new_inode (handle, dir, S_IFDIR);
2386 + inode = ext3_new_inode (handle, dir, S_IFDIR | mode);
2387 err = PTR_ERR(inode);
2390 @@ -1622,7 +1623,6 @@ static int ext3_mkdir(struct inode * dir
2391 inode->i_op = &ext3_dir_inode_operations;
2392 inode->i_fop = &ext3_dir_operations;
2393 inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
2394 - inode->i_blocks = 0;
2395 dir_block = ext3_bread (handle, inode, 0, 1, &err);
2397 inode->i_nlink--; /* is this nlink == 0? */
2398 @@ -1649,9 +1649,6 @@ static int ext3_mkdir(struct inode * dir
2399 BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata");
2400 ext3_journal_dirty_metadata(handle, dir_block);
2402 - inode->i_mode = S_IFDIR | mode;
2403 - if (dir->i_mode & S_ISGID)
2404 - inode->i_mode |= S_ISGID;
2405 ext3_mark_inode_dirty(handle, inode);
2406 err = ext3_add_entry (handle, dentry, inode);
2408 @@ -2020,7 +2017,7 @@ static int ext3_symlink (struct inode *
2411 if (l > sizeof (EXT3_I(inode)->i_data)) {
2412 - inode->i_op = &page_symlink_inode_operations;
2413 + inode->i_op = &ext3_symlink_inode_operations;
2414 inode->i_mapping->a_ops = &ext3_aops;
2416 * block_symlink() calls back into ext3_prepare/commit_write.
2417 @@ -2245,4 +2242,16 @@ struct inode_operations ext3_dir_inode_o
2418 rmdir: ext3_rmdir, /* BKL held */
2419 mknod: ext3_mknod, /* BKL held */
2420 rename: ext3_rename, /* BKL held */
2421 + setxattr: ext3_setxattr, /* BKL held */
2422 + getxattr: ext3_getxattr, /* BKL held */
2423 + listxattr: ext3_listxattr, /* BKL held */
2424 + removexattr: ext3_removexattr, /* BKL held */
2427 +struct inode_operations ext3_special_inode_operations = {
2428 + setxattr: ext3_setxattr, /* BKL held */
2429 + getxattr: ext3_getxattr, /* BKL held */
2430 + listxattr: ext3_listxattr, /* BKL held */
2431 + removexattr: ext3_removexattr, /* BKL held */
2434 --- linux-2.4.22-ac1/fs/ext3/super.c~xattr-0.8.54-2.4.22-rh 2003-09-25 14:55:12.000000000 +0400
2435 +++ linux-2.4.22-ac1-alexey/fs/ext3/super.c 2003-09-26 00:12:23.000000000 +0400
2437 #include <linux/jbd.h>
2438 #include <linux/ext3_fs.h>
2439 #include <linux/ext3_jbd.h>
2440 +#include <linux/ext3_xattr.h>
2441 #include <linux/slab.h>
2442 #include <linux/init.h>
2443 #include <linux/locks.h>
2444 @@ -406,6 +407,7 @@ void ext3_put_super (struct super_block
2445 kdev_t j_dev = sbi->s_journal->j_dev;
2448 + ext3_xattr_put_super(sb);
2449 journal_destroy(sbi->s_journal);
2450 if (!(sb->s_flags & MS_RDONLY)) {
2451 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
2452 @@ -506,6 +508,7 @@ static int parse_options (char * options
2455 unsigned long *mount_options = &sbi->s_mount_opt;
2457 uid_t *resuid = &sbi->s_resuid;
2458 gid_t *resgid = &sbi->s_resgid;
2460 @@ -518,6 +521,13 @@ static int parse_options (char * options
2461 this_char = strtok (NULL, ",")) {
2462 if ((value = strchr (this_char, '=')) != NULL)
2464 +#ifdef CONFIG_EXT3_FS_XATTR_USER
2465 + if (!strcmp (this_char, "user_xattr"))
2466 + set_opt (*mount_options, XATTR_USER);
2467 + else if (!strcmp (this_char, "nouser_xattr"))
2468 + clear_opt (*mount_options, XATTR_USER);
2471 if (!strcmp (this_char, "bsddf"))
2472 clear_opt (*mount_options, MINIX_DF);
2473 else if (!strcmp (this_char, "nouid32")) {
2474 @@ -935,6 +945,12 @@ struct super_block * ext3_read_super (st
2475 sbi->s_mount_opt = 0;
2476 sbi->s_resuid = EXT3_DEF_RESUID;
2477 sbi->s_resgid = EXT3_DEF_RESGID;
2479 + /* Default extended attribute flags */
2480 +#ifdef CONFIG_EXT3_FS_XATTR_USER
2481 + /* set_opt(sbi->s_mount_opt, XATTR_USER); */
2484 if (!parse_options ((char *) data, &sb_block, sbi, &journal_inum, 0)) {
2487 @@ -1839,22 +1855,35 @@ static DECLARE_FSTYPE_DEV(ext3_fs_type,
2489 static int __init init_ext3_fs(void)
2493 init_dquot_operations(&ext3_qops);
2494 old_sync_dquot = ext3_qops.sync_dquot;
2495 ext3_qops.sync_dquot = ext3_sync_dquot;
2497 - return register_filesystem(&ext3_fs_type);
2498 + error = init_ext3_xattr();
2501 + error = init_ext3_xattr_user();
2504 + error = register_filesystem(&ext3_fs_type);
2508 + exit_ext3_xattr_user();
2510 + exit_ext3_xattr();
2514 static void __exit exit_ext3_fs(void)
2516 unregister_filesystem(&ext3_fs_type);
2517 + exit_ext3_xattr_user();
2518 + exit_ext3_xattr();
2521 -EXPORT_SYMBOL(ext3_force_commit);
2522 -EXPORT_SYMBOL(ext3_bread);
2524 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
2525 MODULE_DESCRIPTION("Second Extended Filesystem with journaling extensions");
2526 MODULE_LICENSE("GPL");
2527 --- linux-2.4.22-ac1/fs/ext3/symlink.c~xattr-0.8.54-2.4.22-rh 2001-11-10 01:25:04.000000000 +0300
2528 +++ linux-2.4.22-ac1-alexey/fs/ext3/symlink.c 2003-09-25 23:57:02.000000000 +0400
2530 #include <linux/fs.h>
2531 #include <linux/jbd.h>
2532 #include <linux/ext3_fs.h>
2533 +#include <linux/ext3_xattr.h>
2535 static int ext3_readlink(struct dentry *dentry, char *buffer, int buflen)
2537 @@ -33,7 +34,20 @@ static int ext3_follow_link(struct dentr
2538 return vfs_follow_link(nd, s);
2541 +struct inode_operations ext3_symlink_inode_operations = {
2542 + readlink: page_readlink, /* BKL not held. Don't need */
2543 + follow_link: page_follow_link, /* BKL not held. Don't need */
2544 + setxattr: ext3_setxattr, /* BKL held */
2545 + getxattr: ext3_getxattr, /* BKL held */
2546 + listxattr: ext3_listxattr, /* BKL held */
2547 + removexattr: ext3_removexattr, /* BKL held */
2550 struct inode_operations ext3_fast_symlink_inode_operations = {
2551 readlink: ext3_readlink, /* BKL not held. Don't need */
2552 follow_link: ext3_follow_link, /* BKL not held. Don't need */
2553 + setxattr: ext3_setxattr, /* BKL held */
2554 + getxattr: ext3_getxattr, /* BKL held */
2555 + listxattr: ext3_listxattr, /* BKL held */
2556 + removexattr: ext3_removexattr, /* BKL held */
2558 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
2559 +++ linux-2.4.22-ac1-alexey/fs/ext3/xattr.c 2003-09-25 23:57:02.000000000 +0400
2562 + * linux/fs/ext3/xattr.c
2564 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
2566 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
2567 + * Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>.
2568 + * Extended attributes for symlinks and special files added per
2569 + * suggestion of Luka Renko <luka.renko@hermes.si>.
2573 + * Extended attributes are stored on disk blocks allocated outside of
2574 + * any inode. The i_file_acl field is then made to point to this allocated
2575 + * block. If all extended attributes of an inode are identical, these
2576 + * inodes may share the same extended attribute block. Such situations
2577 + * are automatically detected by keeping a cache of recent attribute block
2578 + * numbers and hashes over the block's contents in memory.
2581 + * Extended attribute block layout:
2583 + * +------------------+
2586 + * | entry 2 | | growing downwards
2588 + * | four null bytes |
2591 + * | value 3 | | growing upwards
2593 + * +------------------+
2595 + * The block header is followed by multiple entry descriptors. These entry
2596 + * descriptors are variable in size, and alligned to EXT3_XATTR_PAD
2597 + * byte boundaries. The entry descriptors are sorted by attribute name,
2598 + * so that two extended attribute blocks can be compared efficiently.
2600 + * Attribute values are aligned to the end of the block, stored in
2601 + * no specific order. They are also padded to EXT3_XATTR_PAD byte
2602 + * boundaries. No additional gaps are left between them.
2604 + * Locking strategy
2605 + * ----------------
2606 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
2607 + * the xattr inode operations are called, so we are guaranteed that only one
2608 + * processes accesses extended attributes of an inode at any time.
2610 + * For writing we also grab the ext3_xattr_sem semaphore. This ensures that
2611 + * only a single process is modifying an extended attribute block, even
2612 + * if the block is shared among inodes.
2614 + * Note for porting to 2.5
2615 + * -----------------------
2616 + * The BKL will no longer be held in the xattr inode operations.
2619 +#include <linux/module.h>
2620 +#include <linux/fs.h>
2621 +#include <linux/locks.h>
2622 +#include <linux/slab.h>
2623 +#include <linux/ext3_jbd.h>
2624 +#include <linux/ext3_fs.h>
2625 +#include <linux/ext3_xattr.h>
2626 +#include <linux/mbcache.h>
2627 +#include <linux/quotaops.h>
2628 +#include <asm/semaphore.h>
2629 +#include <linux/compatmac.h>
2631 +#define EXT3_EA_USER "user."
2633 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
2634 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
2637 +#define HDR(bh) ((struct ext3_xattr_header *)((bh)->b_data))
2638 +#define ENTRY(ptr) ((struct ext3_xattr_entry *)(ptr))
2639 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
2640 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
2642 +#ifdef EXT3_XATTR_DEBUG
2643 +# define ea_idebug(inode, f...) do { \
2644 + printk(KERN_DEBUG "inode %s:%ld: ", \
2645 + kdevname(inode->i_dev), inode->i_ino); \
2649 +# define ea_bdebug(bh, f...) do { \
2650 + printk(KERN_DEBUG "block %s:%ld: ", \
2651 + kdevname(bh->b_dev), bh->b_blocknr); \
2656 +# define ea_idebug(f...)
2657 +# define ea_bdebug(f...)
2660 +static int ext3_xattr_set2(handle_t *, struct inode *, struct buffer_head *,
2661 + struct ext3_xattr_header *);
2663 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
2665 +static int ext3_xattr_cache_insert(struct buffer_head *);
2666 +static struct buffer_head *ext3_xattr_cache_find(struct inode *,
2667 + struct ext3_xattr_header *);
2668 +static void ext3_xattr_cache_remove(struct buffer_head *);
2669 +static void ext3_xattr_rehash(struct ext3_xattr_header *,
2670 + struct ext3_xattr_entry *);
2672 +static struct mb_cache *ext3_xattr_cache;
2675 +# define ext3_xattr_cache_insert(bh) 0
2676 +# define ext3_xattr_cache_find(inode, header) NULL
2677 +# define ext3_xattr_cache_remove(bh) while(0) {}
2678 +# define ext3_xattr_rehash(header, entry) while(0) {}
2682 + * If a file system does not share extended attributes among inodes,
2683 + * we should not need the ext3_xattr_sem semaphore. However, the
2684 + * filesystem may still contain shared blocks, so we always take
2688 +DECLARE_MUTEX(ext3_xattr_sem);
2691 +ext3_xattr_new_block(handle_t *handle, struct inode *inode,
2692 + int * errp, int force)
2694 + struct super_block *sb = inode->i_sb;
2695 + int goal = le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block) +
2696 + EXT3_I(inode)->i_block_group * EXT3_BLOCKS_PER_GROUP(sb);
2698 + /* How can we enforce the allocation? */
2699 + int block = ext3_new_block(handle, inode, goal, 0, 0, errp);
2702 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
2708 +ext3_xattr_quota_alloc(struct inode *inode, int force)
2710 + /* How can we enforce the allocation? */
2712 + int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
2714 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
2716 + int error = DQUOT_ALLOC_BLOCK(inode, 1);
2724 +ext3_xattr_quota_free(struct inode *inode)
2726 + DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
2727 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
2731 +ext3_xattr_free_block(handle_t *handle, struct inode * inode,
2732 + unsigned long block)
2734 + ext3_free_blocks(handle, inode, block, 1);
2735 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
2739 +# define ext3_xattr_quota_free(inode) \
2740 + DQUOT_FREE_BLOCK(inode, 1)
2741 +# define ext3_xattr_free_block(handle, inode, block) \
2742 + ext3_free_blocks(handle, inode, block, 1)
2745 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
2747 +static inline struct buffer_head *
2748 +sb_bread(struct super_block *sb, int block)
2750 + return bread(sb->s_dev, block, sb->s_blocksize);
2753 +static inline struct buffer_head *
2754 +sb_getblk(struct super_block *sb, int block)
2756 + return getblk(sb->s_dev, block, sb->s_blocksize);
2761 +struct ext3_xattr_handler *ext3_xattr_handlers[EXT3_XATTR_INDEX_MAX];
2762 +rwlock_t ext3_handler_lock = RW_LOCK_UNLOCKED;
2765 +ext3_xattr_register(int name_index, struct ext3_xattr_handler *handler)
2767 + int error = -EINVAL;
2769 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
2770 + write_lock(&ext3_handler_lock);
2771 + if (!ext3_xattr_handlers[name_index-1]) {
2772 + ext3_xattr_handlers[name_index-1] = handler;
2775 + write_unlock(&ext3_handler_lock);
2781 +ext3_xattr_unregister(int name_index, struct ext3_xattr_handler *handler)
2783 + if (name_index > 0 || name_index <= EXT3_XATTR_INDEX_MAX) {
2784 + write_lock(&ext3_handler_lock);
2785 + ext3_xattr_handlers[name_index-1] = NULL;
2786 + write_unlock(&ext3_handler_lock);
2790 +static inline const char *
2791 +strcmp_prefix(const char *a, const char *a_prefix)
2793 + while (*a_prefix && *a == *a_prefix) {
2797 + return *a_prefix ? NULL : a;
2801 + * Decode the extended attribute name, and translate it into
2802 + * the name_index and name suffix.
2804 +static inline struct ext3_xattr_handler *
2805 +ext3_xattr_resolve_name(const char **name)
2807 + struct ext3_xattr_handler *handler = NULL;
2812 + read_lock(&ext3_handler_lock);
2813 + for (i=0; i<EXT3_XATTR_INDEX_MAX; i++) {
2814 + if (ext3_xattr_handlers[i]) {
2815 + const char *n = strcmp_prefix(*name,
2816 + ext3_xattr_handlers[i]->prefix);
2818 + handler = ext3_xattr_handlers[i];
2824 + read_unlock(&ext3_handler_lock);
2828 +static inline struct ext3_xattr_handler *
2829 +ext3_xattr_handler(int name_index)
2831 + struct ext3_xattr_handler *handler = NULL;
2832 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
2833 + read_lock(&ext3_handler_lock);
2834 + handler = ext3_xattr_handlers[name_index-1];
2835 + read_unlock(&ext3_handler_lock);
2841 + * Inode operation getxattr()
2843 + * dentry->d_inode->i_sem down
2844 + * BKL held [before 2.5.x]
2847 +ext3_getxattr(struct dentry *dentry, const char *name,
2848 + void *buffer, size_t size)
2850 + struct ext3_xattr_handler *handler;
2851 + struct inode *inode = dentry->d_inode;
2853 + handler = ext3_xattr_resolve_name(&name);
2856 + return handler->get(inode, name, buffer, size);
2860 + * Inode operation listxattr()
2862 + * dentry->d_inode->i_sem down
2863 + * BKL held [before 2.5.x]
2866 +ext3_listxattr(struct dentry *dentry, char *buffer, size_t size)
2868 + return ext3_xattr_list(dentry->d_inode, buffer, size);
2872 + * Inode operation setxattr()
2874 + * dentry->d_inode->i_sem down
2875 + * BKL held [before 2.5.x]
2878 +ext3_setxattr(struct dentry *dentry, const char *name,
2879 + const void *value, size_t size, int flags)
2881 + struct ext3_xattr_handler *handler;
2882 + struct inode *inode = dentry->d_inode;
2885 + value = ""; /* empty EA, do not remove */
2886 + handler = ext3_xattr_resolve_name(&name);
2889 + return handler->set(inode, name, value, size, flags);
2893 + * Inode operation removexattr()
2895 + * dentry->d_inode->i_sem down
2896 + * BKL held [before 2.5.x]
2899 +ext3_removexattr(struct dentry *dentry, const char *name)
2901 + struct ext3_xattr_handler *handler;
2902 + struct inode *inode = dentry->d_inode;
2904 + handler = ext3_xattr_resolve_name(&name);
2907 + return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
2911 + * ext3_xattr_get()
2913 + * Copy an extended attribute into the buffer
2914 + * provided, or compute the buffer size required.
2915 + * Buffer is NULL to compute the size of the buffer required.
2917 + * Returns a negative error number on failure, or the number of bytes
2918 + * used / required on success.
2921 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
2922 + void *buffer, size_t buffer_size)
2924 + struct buffer_head *bh = NULL;
2925 + struct ext3_xattr_entry *entry;
2926 + unsigned int block, size;
2928 + int name_len, error;
2930 + ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
2931 + name_index, name, buffer, (long)buffer_size);
2935 + if (!EXT3_I(inode)->i_file_acl)
2937 + block = EXT3_I(inode)->i_file_acl;
2938 + ea_idebug(inode, "reading block %d", block);
2939 + bh = sb_bread(inode->i_sb, block);
2942 + ea_bdebug(bh, "b_count=%d, refcount=%d",
2943 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
2944 + end = bh->b_data + bh->b_size;
2945 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
2946 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
2947 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_get",
2948 + "inode %ld: bad block %d", inode->i_ino, block);
2952 + /* find named attribute */
2953 + name_len = strlen(name);
2956 + if (name_len > 255)
2958 + entry = FIRST_ENTRY(bh);
2959 + while (!IS_LAST_ENTRY(entry)) {
2960 + struct ext3_xattr_entry *next =
2961 + EXT3_XATTR_NEXT(entry);
2962 + if ((char *)next >= end)
2964 + if (name_index == entry->e_name_index &&
2965 + name_len == entry->e_name_len &&
2966 + memcmp(name, entry->e_name, name_len) == 0)
2970 + /* Check the remaining name entries */
2971 + while (!IS_LAST_ENTRY(entry)) {
2972 + struct ext3_xattr_entry *next =
2973 + EXT3_XATTR_NEXT(entry);
2974 + if ((char *)next >= end)
2978 + if (ext3_xattr_cache_insert(bh))
2979 + ea_idebug(inode, "cache insert failed");
2983 + /* check the buffer size */
2984 + if (entry->e_value_block != 0)
2986 + size = le32_to_cpu(entry->e_value_size);
2987 + if (size > inode->i_sb->s_blocksize ||
2988 + le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
2991 + if (ext3_xattr_cache_insert(bh))
2992 + ea_idebug(inode, "cache insert failed");
2995 + if (size > buffer_size)
2997 + /* return value of attribute */
2998 + memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
3010 + * ext3_xattr_list()
3012 + * Copy a list of attribute names into the buffer
3013 + * provided, or compute the buffer size required.
3014 + * Buffer is NULL to compute the size of the buffer required.
3016 + * Returns a negative error number on failure, or the number of bytes
3017 + * used / required on success.
3020 +ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
3022 + struct buffer_head *bh = NULL;
3023 + struct ext3_xattr_entry *entry;
3024 + unsigned int block, size = 0;
3028 + ea_idebug(inode, "buffer=%p, buffer_size=%ld",
3029 + buffer, (long)buffer_size);
3031 + if (!EXT3_I(inode)->i_file_acl)
3033 + block = EXT3_I(inode)->i_file_acl;
3034 + ea_idebug(inode, "reading block %d", block);
3035 + bh = sb_bread(inode->i_sb, block);
3038 + ea_bdebug(bh, "b_count=%d, refcount=%d",
3039 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
3040 + end = bh->b_data + bh->b_size;
3041 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
3042 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
3043 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_list",
3044 + "inode %ld: bad block %d", inode->i_ino, block);
3048 + /* compute the size required for the list of attribute names */
3049 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
3050 + entry = EXT3_XATTR_NEXT(entry)) {
3051 + struct ext3_xattr_handler *handler;
3052 + struct ext3_xattr_entry *next =
3053 + EXT3_XATTR_NEXT(entry);
3054 + if ((char *)next >= end)
3057 + handler = ext3_xattr_handler(entry->e_name_index);
3059 + size += handler->list(NULL, inode, entry->e_name,
3060 + entry->e_name_len);
3063 + if (ext3_xattr_cache_insert(bh))
3064 + ea_idebug(inode, "cache insert failed");
3070 + if (size > buffer_size)
3074 + /* list the attribute names */
3076 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
3077 + entry = EXT3_XATTR_NEXT(entry)) {
3078 + struct ext3_xattr_handler *handler;
3080 + handler = ext3_xattr_handler(entry->e_name_index);
3082 + buf += handler->list(buf, inode, entry->e_name,
3083 + entry->e_name_len);
3094 + * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is
3095 + * not set, set it.
3097 +static void ext3_xattr_update_super_block(handle_t *handle,
3098 + struct super_block *sb)
3100 + if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR))
3104 + ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh);
3105 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
3106 + EXT3_SB(sb)->s_feature_compat |= EXT3_FEATURE_COMPAT_EXT_ATTR;
3108 + EXT3_SB(sb)->s_es->s_feature_compat |=
3109 + cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR);
3111 + ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
3116 + * ext3_xattr_set()
3118 + * Create, replace or remove an extended attribute for this inode. Buffer
3119 + * is NULL to remove an existing extended attribute, and non-NULL to
3120 + * either replace an existing extended attribute, or create a new extended
3121 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
3122 + * specify that an extended attribute must exist and must not exist
3123 + * previous to the call, respectively.
3125 + * Returns 0, or a negative error number on failure.
3128 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
3129 + const char *name, const void *value, size_t value_len, int flags)
3131 + struct super_block *sb = inode->i_sb;
3132 + struct buffer_head *bh = NULL;
3133 + struct ext3_xattr_header *header = NULL;
3134 + struct ext3_xattr_entry *here, *last;
3135 + unsigned int name_len;
3136 + int block = EXT3_I(inode)->i_file_acl;
3137 + int min_offs = sb->s_blocksize, not_found = 1, free, error;
3141 + * header -- Points either into bh, or to a temporarily
3142 + * allocated buffer.
3143 + * here -- The named entry found, or the place for inserting, within
3144 + * the block pointed to by header.
3145 + * last -- Points right after the last named entry within the block
3146 + * pointed to by header.
3147 + * min_offs -- The offset of the first value (values are aligned
3148 + * towards the end of the block).
3149 + * end -- Points right after the block pointed to by header.
3152 + ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
3153 + name_index, name, value, (long)value_len);
3155 + if (IS_RDONLY(inode))
3157 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
3159 + if (value == NULL)
3163 + name_len = strlen(name);
3164 + if (name_len > 255 || value_len > sb->s_blocksize)
3166 + down(&ext3_xattr_sem);
3169 + /* The inode already has an extended attribute block. */
3170 + bh = sb_bread(sb, block);
3174 + ea_bdebug(bh, "b_count=%d, refcount=%d",
3175 + atomic_read(&(bh->b_count)),
3176 + le32_to_cpu(HDR(bh)->h_refcount));
3178 + end = bh->b_data + bh->b_size;
3179 + if (header->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
3180 + header->h_blocks != cpu_to_le32(1)) {
3181 +bad_block: ext3_error(sb, "ext3_xattr_set",
3182 + "inode %ld: bad block %d", inode->i_ino, block);
3186 + /* Find the named attribute. */
3187 + here = FIRST_ENTRY(bh);
3188 + while (!IS_LAST_ENTRY(here)) {
3189 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(here);
3190 + if ((char *)next >= end)
3192 + if (!here->e_value_block && here->e_value_size) {
3193 + int offs = le16_to_cpu(here->e_value_offs);
3194 + if (offs < min_offs)
3197 + not_found = name_index - here->e_name_index;
3199 + not_found = name_len - here->e_name_len;
3201 + not_found = memcmp(name, here->e_name,name_len);
3202 + if (not_found <= 0)
3207 + /* We still need to compute min_offs and last. */
3208 + while (!IS_LAST_ENTRY(last)) {
3209 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
3210 + if ((char *)next >= end)
3212 + if (!last->e_value_block && last->e_value_size) {
3213 + int offs = le16_to_cpu(last->e_value_offs);
3214 + if (offs < min_offs)
3220 + /* Check whether we have enough space left. */
3221 + free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
3223 + /* We will use a new extended attribute block. */
3224 + free = sb->s_blocksize -
3225 + sizeof(struct ext3_xattr_header) - sizeof(__u32);
3226 + here = last = NULL; /* avoid gcc uninitialized warning. */
3230 + /* Request to remove a nonexistent attribute? */
3232 + if (flags & XATTR_REPLACE)
3235 + if (value == NULL)
3238 + free -= EXT3_XATTR_LEN(name_len);
3240 + /* Request to create an existing attribute? */
3242 + if (flags & XATTR_CREATE)
3244 + if (!here->e_value_block && here->e_value_size) {
3245 + unsigned int size = le32_to_cpu(here->e_value_size);
3247 + if (le16_to_cpu(here->e_value_offs) + size >
3248 + sb->s_blocksize || size > sb->s_blocksize)
3250 + free += EXT3_XATTR_SIZE(size);
3253 + free -= EXT3_XATTR_SIZE(value_len);
3258 + /* Here we know that we can set the new attribute. */
3261 + if (header->h_refcount == cpu_to_le32(1)) {
3262 + ea_bdebug(bh, "modifying in-place");
3263 + ext3_xattr_cache_remove(bh);
3264 + error = ext3_journal_get_write_access(handle, bh);
3270 + ea_bdebug(bh, "cloning");
3271 + header = kmalloc(bh->b_size, GFP_KERNEL);
3273 + if (header == NULL)
3275 + memcpy(header, HDR(bh), bh->b_size);
3276 + header->h_refcount = cpu_to_le32(1);
3277 + offset = (char *)header - bh->b_data;
3278 + here = ENTRY((char *)here + offset);
3279 + last = ENTRY((char *)last + offset);
3282 + /* Allocate a buffer where we construct the new block. */
3283 + header = kmalloc(sb->s_blocksize, GFP_KERNEL);
3285 + if (header == NULL)
3287 + memset(header, 0, sb->s_blocksize);
3288 + end = (char *)header + sb->s_blocksize;
3289 + header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC);
3290 + header->h_blocks = header->h_refcount = cpu_to_le32(1);
3291 + last = here = ENTRY(header+1);
3295 + /* Insert the new name. */
3296 + int size = EXT3_XATTR_LEN(name_len);
3297 + int rest = (char *)last - (char *)here;
3298 + memmove((char *)here + size, here, rest);
3299 + memset(here, 0, size);
3300 + here->e_name_index = name_index;
3301 + here->e_name_len = name_len;
3302 + memcpy(here->e_name, name, name_len);
3304 + /* Remove the old value. */
3305 + if (!here->e_value_block && here->e_value_size) {
3306 + char *first_val = (char *)header + min_offs;
3307 + int offs = le16_to_cpu(here->e_value_offs);
3308 + char *val = (char *)header + offs;
3309 + size_t size = EXT3_XATTR_SIZE(
3310 + le32_to_cpu(here->e_value_size));
3311 + memmove(first_val + size, first_val, val - first_val);
3312 + memset(first_val, 0, size);
3313 + here->e_value_offs = 0;
3316 + /* Adjust all value offsets. */
3317 + last = ENTRY(header+1);
3318 + while (!IS_LAST_ENTRY(last)) {
3319 + int o = le16_to_cpu(last->e_value_offs);
3320 + if (!last->e_value_block && o < offs)
3321 + last->e_value_offs =
3322 + cpu_to_le16(o + size);
3323 + last = EXT3_XATTR_NEXT(last);
3326 + if (value == NULL) {
3327 + /* Remove this attribute. */
3328 + if (EXT3_XATTR_NEXT(ENTRY(header+1)) == last) {
3329 + /* This block is now empty. */
3330 + error = ext3_xattr_set2(handle, inode, bh,NULL);
3333 + /* Remove the old name. */
3334 + int size = EXT3_XATTR_LEN(name_len);
3335 + last = ENTRY((char *)last - size);
3336 + memmove(here, (char*)here + size,
3337 + (char*)last - (char*)here);
3338 + memset(last, 0, size);
3343 + if (value != NULL) {
3344 + /* Insert the new value. */
3345 + here->e_value_size = cpu_to_le32(value_len);
3347 + size_t size = EXT3_XATTR_SIZE(value_len);
3348 + char *val = (char *)header + min_offs - size;
3349 + here->e_value_offs =
3350 + cpu_to_le16((char *)val - (char *)header);
3351 + memset(val + size - EXT3_XATTR_PAD, 0,
3352 + EXT3_XATTR_PAD); /* Clear the pad bytes. */
3353 + memcpy(val, value, value_len);
3356 + ext3_xattr_rehash(header, here);
3358 + error = ext3_xattr_set2(handle, inode, bh, header);
3362 + if (!(bh && header == HDR(bh)))
3364 + up(&ext3_xattr_sem);
3370 + * Second half of ext3_xattr_set(): Update the file system.
3373 +ext3_xattr_set2(handle_t *handle, struct inode *inode,
3374 + struct buffer_head *old_bh, struct ext3_xattr_header *header)
3376 + struct super_block *sb = inode->i_sb;
3377 + struct buffer_head *new_bh = NULL;
3381 + new_bh = ext3_xattr_cache_find(inode, header);
3384 + * We found an identical block in the cache.
3385 + * The old block will be released after updating
3388 + ea_bdebug(old_bh, "reusing block %ld",
3389 + new_bh->b_blocknr);
3392 + if (ext3_xattr_quota_alloc(inode, 1))
3395 + error = ext3_journal_get_write_access(handle, new_bh);
3398 + HDR(new_bh)->h_refcount = cpu_to_le32(
3399 + le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
3400 + ea_bdebug(new_bh, "refcount now=%d",
3401 + le32_to_cpu(HDR(new_bh)->h_refcount));
3402 + } else if (old_bh && header == HDR(old_bh)) {
3403 + /* Keep this block. */
3405 + (void)ext3_xattr_cache_insert(new_bh);
3407 + /* We need to allocate a new block */
3408 + int force = EXT3_I(inode)->i_file_acl != 0;
3409 + int block = ext3_xattr_new_block(handle, inode,
3413 + ea_idebug(inode, "creating block %d", block);
3415 + new_bh = sb_getblk(sb, block);
3417 +getblk_failed: ext3_xattr_free_block(handle, inode, block);
3421 + lock_buffer(new_bh);
3422 + error = ext3_journal_get_create_access(handle, new_bh);
3424 + unlock_buffer(new_bh);
3425 + goto getblk_failed;
3427 + memcpy(new_bh->b_data, header, new_bh->b_size);
3428 + mark_buffer_uptodate(new_bh, 1);
3429 + unlock_buffer(new_bh);
3430 + (void)ext3_xattr_cache_insert(new_bh);
3432 + ext3_xattr_update_super_block(handle, sb);
3434 + error = ext3_journal_dirty_metadata(handle, new_bh);
3439 + /* Update the inode. */
3440 + EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
3441 + inode->i_ctime = CURRENT_TIME;
3442 + ext3_mark_inode_dirty(handle, inode);
3443 + if (IS_SYNC(inode))
3444 + handle->h_sync = 1;
3447 + if (old_bh && old_bh != new_bh) {
3449 + * If there was an old block, and we are not still using it,
3450 + * we now release the old block.
3452 + unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
3454 + error = ext3_journal_get_write_access(handle, old_bh);
3457 + if (refcount == 1) {
3458 + /* Free the old block. */
3459 + ea_bdebug(old_bh, "freeing");
3460 + ext3_xattr_free_block(handle, inode, old_bh->b_blocknr);
3462 + /* ext3_forget() calls bforget() for us, but we
3463 + let our caller release old_bh, so we need to
3464 + duplicate the handle before. */
3466 + ext3_forget(handle, 1, inode, old_bh,old_bh->b_blocknr);
3468 + /* Decrement the refcount only. */
3470 + HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
3471 + ext3_xattr_quota_free(inode);
3472 + ext3_journal_dirty_metadata(handle, old_bh);
3473 + ea_bdebug(old_bh, "refcount now=%d", refcount);
3478 + if (old_bh != new_bh)
3485 + * ext3_xattr_delete_inode()
3487 + * Free extended attribute resources associated with this inode. This
3488 + * is called immediately before an inode is freed.
3491 +ext3_xattr_delete_inode(handle_t *handle, struct inode *inode)
3493 + struct buffer_head *bh;
3494 + unsigned int block = EXT3_I(inode)->i_file_acl;
3498 + down(&ext3_xattr_sem);
3500 + bh = sb_bread(inode->i_sb, block);
3502 + ext3_error(inode->i_sb, "ext3_xattr_delete_inode",
3503 + "inode %ld: block %d read error", inode->i_ino, block);
3506 + ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
3507 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
3508 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
3509 + ext3_error(inode->i_sb, "ext3_xattr_delete_inode",
3510 + "inode %ld: bad block %d", inode->i_ino, block);
3513 + ext3_journal_get_write_access(handle, bh);
3514 + ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
3515 + if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
3516 + ext3_xattr_cache_remove(bh);
3517 + ext3_xattr_free_block(handle, inode, block);
3518 + ext3_forget(handle, 1, inode, bh, block);
3521 + HDR(bh)->h_refcount = cpu_to_le32(
3522 + le32_to_cpu(HDR(bh)->h_refcount) - 1);
3523 + ext3_journal_dirty_metadata(handle, bh);
3524 + if (IS_SYNC(inode))
3525 + handle->h_sync = 1;
3526 + ext3_xattr_quota_free(inode);
3528 + EXT3_I(inode)->i_file_acl = 0;
3532 + up(&ext3_xattr_sem);
3536 + * ext3_xattr_put_super()
3538 + * This is called when a file system is unmounted.
3541 +ext3_xattr_put_super(struct super_block *sb)
3543 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
3544 + mb_cache_shrink(ext3_xattr_cache, sb->s_dev);
3548 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
3551 + * ext3_xattr_cache_insert()
3553 + * Create a new entry in the extended attribute cache, and insert
3554 + * it unless such an entry is already in the cache.
3556 + * Returns 0, or a negative error number on failure.
3559 +ext3_xattr_cache_insert(struct buffer_head *bh)
3561 + __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
3562 + struct mb_cache_entry *ce;
3565 + ce = mb_cache_entry_alloc(ext3_xattr_cache);
3568 + error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
3570 + mb_cache_entry_free(ce);
3571 + if (error == -EBUSY) {
3572 + ea_bdebug(bh, "already in cache (%d cache entries)",
3573 + atomic_read(&ext3_xattr_cache->c_entry_count));
3577 + ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
3578 + atomic_read(&ext3_xattr_cache->c_entry_count));
3579 + mb_cache_entry_release(ce);
3585 + * ext3_xattr_cmp()
3587 + * Compare two extended attribute blocks for equality.
3589 + * Returns 0 if the blocks are equal, 1 if they differ, and
3590 + * a negative error number on errors.
3593 +ext3_xattr_cmp(struct ext3_xattr_header *header1,
3594 + struct ext3_xattr_header *header2)
3596 + struct ext3_xattr_entry *entry1, *entry2;
3598 + entry1 = ENTRY(header1+1);
3599 + entry2 = ENTRY(header2+1);
3600 + while (!IS_LAST_ENTRY(entry1)) {
3601 + if (IS_LAST_ENTRY(entry2))
3603 + if (entry1->e_hash != entry2->e_hash ||
3604 + entry1->e_name_len != entry2->e_name_len ||
3605 + entry1->e_value_size != entry2->e_value_size ||
3606 + memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
3608 + if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
3610 + if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
3611 + (char *)header2 + le16_to_cpu(entry2->e_value_offs),
3612 + le32_to_cpu(entry1->e_value_size)))
3615 + entry1 = EXT3_XATTR_NEXT(entry1);
3616 + entry2 = EXT3_XATTR_NEXT(entry2);
3618 + if (!IS_LAST_ENTRY(entry2))
3624 + * ext3_xattr_cache_find()
3626 + * Find an identical extended attribute block.
3628 + * Returns a pointer to the block found, or NULL if such a block was
3629 + * not found or an error occurred.
3631 +static struct buffer_head *
3632 +ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header)
3634 + __u32 hash = le32_to_cpu(header->h_hash);
3635 + struct mb_cache_entry *ce;
3637 + if (!header->h_hash)
3638 + return NULL; /* never share */
3639 + ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
3640 + ce = mb_cache_entry_find_first(ext3_xattr_cache, 0, inode->i_dev, hash);
3642 + struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
3645 + ext3_error(inode->i_sb, "ext3_xattr_cache_find",
3646 + "inode %ld: block %ld read error",
3647 + inode->i_ino, ce->e_block);
3648 + } else if (le32_to_cpu(HDR(bh)->h_refcount) >
3649 + EXT3_XATTR_REFCOUNT_MAX) {
3650 + ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
3651 + le32_to_cpu(HDR(bh)->h_refcount),
3652 + EXT3_XATTR_REFCOUNT_MAX);
3653 + } else if (!ext3_xattr_cmp(header, HDR(bh))) {
3654 + ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
3655 + mb_cache_entry_release(ce);
3659 + ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
3665 + * ext3_xattr_cache_remove()
3667 + * Remove the cache entry of a block from the cache. Called when a
3668 + * block becomes invalid.
3671 +ext3_xattr_cache_remove(struct buffer_head *bh)
3673 + struct mb_cache_entry *ce;
3675 + ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_dev, bh->b_blocknr);
3677 + ea_bdebug(bh, "removing (%d cache entries remaining)",
3678 + atomic_read(&ext3_xattr_cache->c_entry_count)-1);
3679 + mb_cache_entry_free(ce);
3681 + ea_bdebug(bh, "no cache entry");
3684 +#define NAME_HASH_SHIFT 5
3685 +#define VALUE_HASH_SHIFT 16
3688 + * ext3_xattr_hash_entry()
3690 + * Compute the hash of an extended attribute.
3692 +static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
3693 + struct ext3_xattr_entry *entry)
3696 + char *name = entry->e_name;
3699 + for (n=0; n < entry->e_name_len; n++) {
3700 + hash = (hash << NAME_HASH_SHIFT) ^
3701 + (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
3705 + if (entry->e_value_block == 0 && entry->e_value_size != 0) {
3706 + __u32 *value = (__u32 *)((char *)header +
3707 + le16_to_cpu(entry->e_value_offs));
3708 + for (n = (le32_to_cpu(entry->e_value_size) +
3709 + EXT3_XATTR_ROUND) >> EXT3_XATTR_PAD_BITS; n; n--) {
3710 + hash = (hash << VALUE_HASH_SHIFT) ^
3711 + (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
3712 + le32_to_cpu(*value++);
3715 + entry->e_hash = cpu_to_le32(hash);
3718 +#undef NAME_HASH_SHIFT
3719 +#undef VALUE_HASH_SHIFT
3721 +#define BLOCK_HASH_SHIFT 16
3724 + * ext3_xattr_rehash()
3726 + * Re-compute the extended attribute hash value after an entry has changed.
3728 +static void ext3_xattr_rehash(struct ext3_xattr_header *header,
3729 + struct ext3_xattr_entry *entry)
3731 + struct ext3_xattr_entry *here;
3734 + ext3_xattr_hash_entry(header, entry);
3735 + here = ENTRY(header+1);
3736 + while (!IS_LAST_ENTRY(here)) {
3737 + if (!here->e_hash) {
3738 + /* Block is not shared if an entry's hash value == 0 */
3742 + hash = (hash << BLOCK_HASH_SHIFT) ^
3743 + (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
3744 + le32_to_cpu(here->e_hash);
3745 + here = EXT3_XATTR_NEXT(here);
3747 + header->h_hash = cpu_to_le32(hash);
3750 +#undef BLOCK_HASH_SHIFT
3753 +init_ext3_xattr(void)
3755 + ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL,
3756 + sizeof(struct mb_cache_entry) +
3757 + sizeof(struct mb_cache_entry_index), 1, 61);
3758 + if (!ext3_xattr_cache)
3765 +exit_ext3_xattr(void)
3767 + if (ext3_xattr_cache)
3768 + mb_cache_destroy(ext3_xattr_cache);
3769 + ext3_xattr_cache = NULL;
3772 +#else /* CONFIG_EXT3_FS_XATTR_SHARING */
3775 +init_ext3_xattr(void)
3781 +exit_ext3_xattr(void)
3785 +#endif /* CONFIG_EXT3_FS_XATTR_SHARING */
3786 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
3787 +++ linux-2.4.22-ac1-alexey/fs/ext3/xattr_user.c 2003-09-25 23:57:02.000000000 +0400
3790 + * linux/fs/ext3/xattr_user.c
3791 + * Handler for extended user attributes.
3793 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
3796 +#include <linux/module.h>
3797 +#include <linux/string.h>
3798 +#include <linux/fs.h>
3799 +#include <linux/ext3_jbd.h>
3800 +#include <linux/ext3_fs.h>
3801 +#include <linux/ext3_xattr.h>
3803 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3804 +# include <linux/ext3_acl.h>
3807 +#define XATTR_USER_PREFIX "user."
3810 +ext3_xattr_user_list(char *list, struct inode *inode,
3811 + const char *name, int name_len)
3813 + const int prefix_len = sizeof(XATTR_USER_PREFIX)-1;
3815 + if (!test_opt(inode->i_sb, XATTR_USER))
3819 + memcpy(list, XATTR_USER_PREFIX, prefix_len);
3820 + memcpy(list+prefix_len, name, name_len);
3821 + list[prefix_len + name_len] = '\0';
3823 + return prefix_len + name_len + 1;
3827 +ext3_xattr_user_get(struct inode *inode, const char *name,
3828 + void *buffer, size_t size)
3832 + if (strcmp(name, "") == 0)
3834 + if (!test_opt(inode->i_sb, XATTR_USER))
3836 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3837 + error = ext3_permission_locked(inode, MAY_READ);
3839 + error = permission(inode, MAY_READ);
3844 + return ext3_xattr_get(inode, EXT3_XATTR_INDEX_USER, name,
3849 +ext3_xattr_user_set(struct inode *inode, const char *name,
3850 + const void *value, size_t size, int flags)
3855 + if (strcmp(name, "") == 0)
3857 + if (!test_opt(inode->i_sb, XATTR_USER))
3859 + if ( !S_ISREG(inode->i_mode) &&
3860 + (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
3862 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3863 + error = ext3_permission_locked(inode, MAY_WRITE);
3865 + error = permission(inode, MAY_WRITE);
3870 + handle = ext3_journal_start(inode, EXT3_XATTR_TRANS_BLOCKS);
3871 + if (IS_ERR(handle))
3872 + return PTR_ERR(handle);
3873 + error = ext3_xattr_set(handle, inode, EXT3_XATTR_INDEX_USER, name,
3874 + value, size, flags);
3875 + ext3_journal_stop(handle, inode);
3880 +struct ext3_xattr_handler ext3_xattr_user_handler = {
3881 + prefix: XATTR_USER_PREFIX,
3882 + list: ext3_xattr_user_list,
3883 + get: ext3_xattr_user_get,
3884 + set: ext3_xattr_user_set,
3888 +init_ext3_xattr_user(void)
3890 + return ext3_xattr_register(EXT3_XATTR_INDEX_USER,
3891 + &ext3_xattr_user_handler);
3895 +exit_ext3_xattr_user(void)
3897 + ext3_xattr_unregister(EXT3_XATTR_INDEX_USER,
3898 + &ext3_xattr_user_handler);
3900 --- linux-2.4.22-ac1/fs/jfs/jfs_xattr.h~xattr-0.8.54-2.4.22-rh 2002-11-29 02:53:15.000000000 +0300
3901 +++ linux-2.4.22-ac1-alexey/fs/jfs/jfs_xattr.h 2003-09-25 23:57:02.000000000 +0400
3902 @@ -52,8 +52,10 @@ struct jfs_ea_list {
3903 #define END_EALIST(ealist) \
3904 ((struct jfs_ea *) (((char *) (ealist)) + EALIST_SIZE(ealist)))
3906 -extern int __jfs_setxattr(struct inode *, const char *, void *, size_t, int);
3907 -extern int jfs_setxattr(struct dentry *, const char *, void *, size_t, int);
3908 +extern int __jfs_setxattr(struct inode *, const char *, const void *, size_t,
3910 +extern int jfs_setxattr(struct dentry *, const char *, const void *, size_t,
3912 extern ssize_t __jfs_getxattr(struct inode *, const char *, void *, size_t);
3913 extern ssize_t jfs_getxattr(struct dentry *, const char *, void *, size_t);
3914 extern ssize_t jfs_listxattr(struct dentry *, char *, size_t);
3915 --- linux-2.4.22-ac1/fs/jfs/xattr.c~xattr-0.8.54-2.4.22-rh 2002-11-29 02:53:15.000000000 +0300
3916 +++ linux-2.4.22-ac1-alexey/fs/jfs/xattr.c 2003-09-25 23:57:02.000000000 +0400
3917 @@ -641,7 +641,7 @@ static int ea_put(struct inode *inode, s
3920 static int can_set_xattr(struct inode *inode, const char *name,
3921 - void *value, size_t value_len)
3922 + const void *value, size_t value_len)
3924 if (IS_RDONLY(inode))
3926 @@ -660,7 +660,7 @@ static int can_set_xattr(struct inode *i
3927 return permission(inode, MAY_WRITE);
3930 -int __jfs_setxattr(struct inode *inode, const char *name, void *value,
3931 +int __jfs_setxattr(struct inode *inode, const char *name, const void *value,
3932 size_t value_len, int flags)
3934 struct jfs_ea_list *ealist;
3935 @@ -799,7 +799,7 @@ int __jfs_setxattr(struct inode *inode,
3939 -int jfs_setxattr(struct dentry *dentry, const char *name, void *value,
3940 +int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
3941 size_t value_len, int flags)
3943 if (value == NULL) { /* empty EA, do not remove */
3944 --- linux-2.4.22-ac1/fs/Makefile~xattr-0.8.54-2.4.22-rh 2003-09-25 14:50:00.000000000 +0400
3945 +++ linux-2.4.22-ac1-alexey/fs/Makefile 2003-09-25 23:57:02.000000000 +0400
3946 @@ -82,6 +82,9 @@ obj-y += binfmt_script.o
3948 obj-$(CONFIG_BINFMT_ELF) += binfmt_elf.o
3950 +export-objs += mbcache.o
3951 +obj-$(CONFIG_FS_MBCACHE) += mbcache.o
3953 # persistent filesystems
3954 obj-y += $(join $(subdir-y),$(subdir-y:%=/%.o))
3956 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
3957 +++ linux-2.4.22-ac1-alexey/fs/mbcache.c 2003-09-25 23:57:02.000000000 +0400
3960 + * linux/fs/mbcache.c
3961 + * (C) 2001-2002 Andreas Gruenbacher, <a.gruenbacher@computer.org>
3965 + * Filesystem Meta Information Block Cache (mbcache)
3967 + * The mbcache caches blocks of block devices that need to be located
3968 + * by their device/block number, as well as by other criteria (such
3969 + * as the block's contents).
3971 + * There can only be one cache entry in a cache per device and block number.
3972 + * Additional indexes need not be unique in this sense. The number of
3973 + * additional indexes (=other criteria) can be hardwired at compile time
3974 + * or specified at cache create time.
3976 + * Each cache entry is of fixed size. An entry may be `valid' or `invalid'
3977 + * in the cache. A valid entry is in the main hash tables of the cache,
3978 + * and may also be in the lru list. An invalid entry is not in any hashes
3981 + * A valid cache entry is only in the lru list if no handles refer to it.
3982 + * Invalid cache entries will be freed when the last handle to the cache
3983 + * entry is released. Entries that cannot be freed immediately are put
3984 + * back on the lru list.
3987 +#include <linux/kernel.h>
3988 +#include <linux/module.h>
3990 +#include <linux/fs.h>
3991 +#include <linux/slab.h>
3992 +#include <linux/sched.h>
3993 +#include <linux/cache_def.h>
3994 +#include <linux/version.h>
3995 +#include <linux/init.h>
3996 +#include <linux/mbcache.h>
3999 +#ifdef MB_CACHE_DEBUG
4000 +# define mb_debug(f...) do { \
4001 + printk(KERN_DEBUG f); \
4004 +#define mb_assert(c) do { if (!(c)) \
4005 + printk(KERN_ERR "assertion " #c " failed\n"); \
4008 +# define mb_debug(f...) do { } while(0)
4009 +# define mb_assert(c) do { } while(0)
4011 +#define mb_error(f...) do { \
4012 + printk(KERN_ERR f); \
4016 +MODULE_AUTHOR("Andreas Gruenbacher <a.gruenbacher@computer.org>");
4017 +MODULE_DESCRIPTION("Meta block cache (for extended attributes)");
4018 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4019 +MODULE_LICENSE("GPL");
4022 +EXPORT_SYMBOL(mb_cache_create);
4023 +EXPORT_SYMBOL(mb_cache_shrink);
4024 +EXPORT_SYMBOL(mb_cache_destroy);
4025 +EXPORT_SYMBOL(mb_cache_entry_alloc);
4026 +EXPORT_SYMBOL(mb_cache_entry_insert);
4027 +EXPORT_SYMBOL(mb_cache_entry_release);
4028 +EXPORT_SYMBOL(mb_cache_entry_takeout);
4029 +EXPORT_SYMBOL(mb_cache_entry_free);
4030 +EXPORT_SYMBOL(mb_cache_entry_dup);
4031 +EXPORT_SYMBOL(mb_cache_entry_get);
4032 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
4033 +EXPORT_SYMBOL(mb_cache_entry_find_first);
4034 +EXPORT_SYMBOL(mb_cache_entry_find_next);
4039 + * Global data: list of all mbcache's, lru list, and a spinlock for
4040 + * accessing cache data structures on SMP machines. The lru list is
4041 + * global across all mbcaches.
4044 +static LIST_HEAD(mb_cache_list);
4045 +static LIST_HEAD(mb_cache_lru_list);
4046 +static spinlock_t mb_cache_spinlock = SPIN_LOCK_UNLOCKED;
4049 +mb_cache_indexes(struct mb_cache *cache)
4051 +#ifdef MB_CACHE_INDEXES_COUNT
4052 + return MB_CACHE_INDEXES_COUNT;
4054 + return cache->c_indexes_count;
4059 + * What the mbcache registers as to get shrunk dynamically.
4063 +mb_cache_memory_pressure(int priority, unsigned int gfp_mask);
4065 +static struct cache_definition mb_cache_definition = {
4067 + mb_cache_memory_pressure
4072 +__mb_cache_entry_is_hashed(struct mb_cache_entry *ce)
4074 + return !list_empty(&ce->e_block_list);
4079 +__mb_cache_entry_unhash(struct mb_cache_entry *ce)
4083 + if (__mb_cache_entry_is_hashed(ce)) {
4084 + list_del_init(&ce->e_block_list);
4085 + for (n=0; n<mb_cache_indexes(ce->e_cache); n++)
4086 + list_del(&ce->e_indexes[n].o_list);
4092 +__mb_cache_entry_forget(struct mb_cache_entry *ce, int gfp_mask)
4094 + struct mb_cache *cache = ce->e_cache;
4096 + mb_assert(atomic_read(&ce->e_used) == 0);
4097 + if (cache->c_op.free && cache->c_op.free(ce, gfp_mask)) {
4098 + /* free failed -- put back on the lru list
4099 + for freeing later. */
4100 + spin_lock(&mb_cache_spinlock);
4101 + list_add(&ce->e_lru_list, &mb_cache_lru_list);
4102 + spin_unlock(&mb_cache_spinlock);
4104 + kmem_cache_free(cache->c_entry_cache, ce);
4105 + atomic_dec(&cache->c_entry_count);
4111 +__mb_cache_entry_release_unlock(struct mb_cache_entry *ce)
4113 + if (atomic_dec_and_test(&ce->e_used)) {
4114 + if (__mb_cache_entry_is_hashed(ce))
4115 + list_add_tail(&ce->e_lru_list, &mb_cache_lru_list);
4117 + spin_unlock(&mb_cache_spinlock);
4118 + __mb_cache_entry_forget(ce, GFP_KERNEL);
4122 + spin_unlock(&mb_cache_spinlock);
4127 + * mb_cache_memory_pressure() memory pressure callback
4129 + * This function is called by the kernel memory management when memory
4132 + * @priority: Amount by which to shrink the cache (0 = highes priority)
4133 + * @gfp_mask: (ignored)
4136 +mb_cache_memory_pressure(int priority, unsigned int gfp_mask)
4138 + LIST_HEAD(free_list);
4139 + struct list_head *l, *ltmp;
4142 + spin_lock(&mb_cache_spinlock);
4143 + list_for_each(l, &mb_cache_list) {
4144 + struct mb_cache *cache =
4145 + list_entry(l, struct mb_cache, c_cache_list);
4146 + mb_debug("cache %s (%d)", cache->c_name,
4147 + atomic_read(&cache->c_entry_count));
4148 + count += atomic_read(&cache->c_entry_count);
4150 + mb_debug("trying to free %d of %d entries",
4151 + count / (priority ? priority : 1), count);
4153 + count /= priority;
4154 + while (count-- && !list_empty(&mb_cache_lru_list)) {
4155 + struct mb_cache_entry *ce =
4156 + list_entry(mb_cache_lru_list.next,
4157 + struct mb_cache_entry, e_lru_list);
4158 + list_del(&ce->e_lru_list);
4159 + __mb_cache_entry_unhash(ce);
4160 + list_add_tail(&ce->e_lru_list, &free_list);
4162 + spin_unlock(&mb_cache_spinlock);
4163 + list_for_each_safe(l, ltmp, &free_list) {
4164 + __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4165 + e_lru_list), gfp_mask);
4171 + * mb_cache_create() create a new cache
4173 + * All entries in one cache are equal size. Cache entries may be from
4174 + * multiple devices. If this is the first mbcache created, registers
4175 + * the cache with kernel memory management. Returns NULL if no more
4176 + * memory was available.
4178 + * @name: name of the cache (informal)
4179 + * @cache_op: contains the callback called when freeing a cache entry
4180 + * @entry_size: The size of a cache entry, including
4181 + * struct mb_cache_entry
4182 + * @indexes_count: number of additional indexes in the cache. Must equal
4183 + * MB_CACHE_INDEXES_COUNT if the number of indexes is
4185 + * @bucket_count: number of hash buckets
4188 +mb_cache_create(const char *name, struct mb_cache_op *cache_op,
4189 + size_t entry_size, int indexes_count, int bucket_count)
4192 + struct mb_cache *cache = NULL;
4194 + if(entry_size < sizeof(struct mb_cache_entry) +
4195 + indexes_count * sizeof(struct mb_cache_entry_index))
4198 + MOD_INC_USE_COUNT;
4199 + cache = kmalloc(sizeof(struct mb_cache) +
4200 + indexes_count * sizeof(struct list_head), GFP_KERNEL);
4203 + cache->c_name = name;
4204 + cache->c_op.free = NULL;
4206 + cache->c_op.free = cache_op->free;
4207 + atomic_set(&cache->c_entry_count, 0);
4208 + cache->c_bucket_count = bucket_count;
4209 +#ifdef MB_CACHE_INDEXES_COUNT
4210 + mb_assert(indexes_count == MB_CACHE_INDEXES_COUNT);
4212 + cache->c_indexes_count = indexes_count;
4214 + cache->c_block_hash = kmalloc(bucket_count * sizeof(struct list_head),
4216 + if (!cache->c_block_hash)
4218 + for (n=0; n<bucket_count; n++)
4219 + INIT_LIST_HEAD(&cache->c_block_hash[n]);
4220 + for (m=0; m<indexes_count; m++) {
4221 + cache->c_indexes_hash[m] = kmalloc(bucket_count *
4222 + sizeof(struct list_head),
4224 + if (!cache->c_indexes_hash[m])
4226 + for (n=0; n<bucket_count; n++)
4227 + INIT_LIST_HEAD(&cache->c_indexes_hash[m][n]);
4229 + cache->c_entry_cache = kmem_cache_create(name, entry_size, 0,
4230 + 0 /*SLAB_POISON | SLAB_RED_ZONE*/, NULL, NULL);
4231 + if (!cache->c_entry_cache)
4234 + spin_lock(&mb_cache_spinlock);
4235 + list_add(&cache->c_cache_list, &mb_cache_list);
4236 + spin_unlock(&mb_cache_spinlock);
4242 + kfree(cache->c_indexes_hash[m]);
4243 + if (cache->c_block_hash)
4244 + kfree(cache->c_block_hash);
4247 + MOD_DEC_USE_COUNT;
4253 + * mb_cache_shrink()
4255 + * Removes all cache entires of a device from the cache. All cache entries
4256 + * currently in use cannot be freed, and thus remain in the cache.
4258 + * @cache: which cache to shrink
4259 + * @dev: which device's cache entries to shrink
4262 +mb_cache_shrink(struct mb_cache *cache, kdev_t dev)
4264 + LIST_HEAD(free_list);
4265 + struct list_head *l, *ltmp;
4267 + spin_lock(&mb_cache_spinlock);
4268 + list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
4269 + struct mb_cache_entry *ce =
4270 + list_entry(l, struct mb_cache_entry, e_lru_list);
4271 + if (ce->e_dev == dev) {
4272 + list_del(&ce->e_lru_list);
4273 + list_add_tail(&ce->e_lru_list, &free_list);
4274 + __mb_cache_entry_unhash(ce);
4277 + spin_unlock(&mb_cache_spinlock);
4278 + list_for_each_safe(l, ltmp, &free_list) {
4279 + __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4280 + e_lru_list), GFP_KERNEL);
4286 + * mb_cache_destroy()
4288 + * Shrinks the cache to its minimum possible size (hopefully 0 entries),
4289 + * and then destroys it. If this was the last mbcache, un-registers the
4290 + * mbcache from kernel memory management.
4293 +mb_cache_destroy(struct mb_cache *cache)
4295 + LIST_HEAD(free_list);
4296 + struct list_head *l, *ltmp;
4299 + spin_lock(&mb_cache_spinlock);
4300 + list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
4301 + struct mb_cache_entry *ce =
4302 + list_entry(l, struct mb_cache_entry, e_lru_list);
4303 + if (ce->e_cache == cache) {
4304 + list_del(&ce->e_lru_list);
4305 + list_add_tail(&ce->e_lru_list, &free_list);
4306 + __mb_cache_entry_unhash(ce);
4309 + list_del(&cache->c_cache_list);
4310 + spin_unlock(&mb_cache_spinlock);
4311 + list_for_each_safe(l, ltmp, &free_list) {
4312 + __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4313 + e_lru_list), GFP_KERNEL);
4316 + if (atomic_read(&cache->c_entry_count) > 0) {
4317 + mb_error("cache %s: %d orphaned entries",
4319 + atomic_read(&cache->c_entry_count));
4322 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
4323 + /* We don't have kmem_cache_destroy() in 2.2.x */
4324 + kmem_cache_shrink(cache->c_entry_cache);
4326 + kmem_cache_destroy(cache->c_entry_cache);
4328 + for (n=0; n < mb_cache_indexes(cache); n++)
4329 + kfree(cache->c_indexes_hash[n]);
4330 + kfree(cache->c_block_hash);
4333 + MOD_DEC_USE_COUNT;
4338 + * mb_cache_entry_alloc()
4340 + * Allocates a new cache entry. The new entry will not be valid initially,
4341 + * and thus cannot be looked up yet. It should be filled with data, and
4342 + * then inserted into the cache using mb_cache_entry_insert(). Returns NULL
4343 + * if no more memory was available.
4345 +struct mb_cache_entry *
4346 +mb_cache_entry_alloc(struct mb_cache *cache)
4348 + struct mb_cache_entry *ce;
4350 + atomic_inc(&cache->c_entry_count);
4351 + ce = kmem_cache_alloc(cache->c_entry_cache, GFP_KERNEL);
4353 + INIT_LIST_HEAD(&ce->e_lru_list);
4354 + INIT_LIST_HEAD(&ce->e_block_list);
4355 + ce->e_cache = cache;
4356 + atomic_set(&ce->e_used, 1);
4363 + * mb_cache_entry_insert()
4365 + * Inserts an entry that was allocated using mb_cache_entry_alloc() into
4366 + * the cache. After this, the cache entry can be looked up, but is not yet
4367 + * in the lru list as the caller still holds a handle to it. Returns 0 on
4368 + * success, or -EBUSY if a cache entry for that device + inode exists
4369 + * already (this may happen after a failed lookup, if another process has
4370 + * inserted the same cache entry in the meantime).
4372 + * @dev: device the cache entry belongs to
4373 + * @block: block number
4374 + * @keys: array of additional keys. There must be indexes_count entries
4375 + * in the array (as specified when creating the cache).
4378 +mb_cache_entry_insert(struct mb_cache_entry *ce, kdev_t dev,
4379 + unsigned long block, unsigned int keys[])
4381 + struct mb_cache *cache = ce->e_cache;
4382 + unsigned int bucket = (HASHDEV(dev) + block) % cache->c_bucket_count;
4383 + struct list_head *l;
4384 + int error = -EBUSY, n;
4386 + spin_lock(&mb_cache_spinlock);
4387 + list_for_each(l, &cache->c_block_hash[bucket]) {
4388 + struct mb_cache_entry *ce =
4389 + list_entry(l, struct mb_cache_entry, e_block_list);
4390 + if (ce->e_dev == dev && ce->e_block == block)
4393 + __mb_cache_entry_unhash(ce);
4395 + ce->e_block = block;
4396 + list_add(&ce->e_block_list, &cache->c_block_hash[bucket]);
4397 + for (n=0; n<mb_cache_indexes(cache); n++) {
4398 + ce->e_indexes[n].o_key = keys[n];
4399 + bucket = keys[n] % cache->c_bucket_count;
4400 + list_add(&ce->e_indexes[n].o_list,
4401 + &cache->c_indexes_hash[n][bucket]);
4404 + spin_unlock(&mb_cache_spinlock);
4410 + * mb_cache_entry_release()
4412 + * Release a handle to a cache entry. When the last handle to a cache entry
4413 + * is released it is either freed (if it is invalid) or otherwise inserted
4414 + * in to the lru list.
4417 +mb_cache_entry_release(struct mb_cache_entry *ce)
4419 + spin_lock(&mb_cache_spinlock);
4420 + __mb_cache_entry_release_unlock(ce);
4425 + * mb_cache_entry_takeout()
4427 + * Take a cache entry out of the cache, making it invalid. The entry can later
4428 + * be re-inserted using mb_cache_entry_insert(), or released using
4429 + * mb_cache_entry_release().
4432 +mb_cache_entry_takeout(struct mb_cache_entry *ce)
4434 + spin_lock(&mb_cache_spinlock);
4435 + mb_assert(list_empty(&ce->e_lru_list));
4436 + __mb_cache_entry_unhash(ce);
4437 + spin_unlock(&mb_cache_spinlock);
4442 + * mb_cache_entry_free()
4444 + * This is equivalent to the sequence mb_cache_entry_takeout() --
4445 + * mb_cache_entry_release().
4448 +mb_cache_entry_free(struct mb_cache_entry *ce)
4450 + spin_lock(&mb_cache_spinlock);
4451 + mb_assert(list_empty(&ce->e_lru_list));
4452 + __mb_cache_entry_unhash(ce);
4453 + __mb_cache_entry_release_unlock(ce);
4458 + * mb_cache_entry_dup()
4460 + * Duplicate a handle to a cache entry (does not duplicate the cache entry
4461 + * itself). After the call, both the old and the new handle must be released.
4463 +struct mb_cache_entry *
4464 +mb_cache_entry_dup(struct mb_cache_entry *ce)
4466 + atomic_inc(&ce->e_used);
4472 + * mb_cache_entry_get()
4474 + * Get a cache entry by device / block number. (There can only be one entry
4475 + * in the cache per device and block.) Returns NULL if no such cache entry
4478 +struct mb_cache_entry *
4479 +mb_cache_entry_get(struct mb_cache *cache, kdev_t dev, unsigned long block)
4481 + unsigned int bucket = (HASHDEV(dev) + block) % cache->c_bucket_count;
4482 + struct list_head *l;
4483 + struct mb_cache_entry *ce;
4485 + spin_lock(&mb_cache_spinlock);
4486 + list_for_each(l, &cache->c_block_hash[bucket]) {
4487 + ce = list_entry(l, struct mb_cache_entry, e_block_list);
4488 + if (ce->e_dev == dev && ce->e_block == block) {
4489 + if (!list_empty(&ce->e_lru_list))
4490 + list_del_init(&ce->e_lru_list);
4491 + atomic_inc(&ce->e_used);
4498 + spin_unlock(&mb_cache_spinlock);
4502 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
4504 +static struct mb_cache_entry *
4505 +__mb_cache_entry_find(struct list_head *l, struct list_head *head,
4506 + int index, kdev_t dev, unsigned int key)
4508 + while (l != head) {
4509 + struct mb_cache_entry *ce =
4510 + list_entry(l, struct mb_cache_entry,
4511 + e_indexes[index].o_list);
4512 + if (ce->e_dev == dev && ce->e_indexes[index].o_key == key) {
4513 + if (!list_empty(&ce->e_lru_list))
4514 + list_del_init(&ce->e_lru_list);
4515 + atomic_inc(&ce->e_used);
4525 + * mb_cache_entry_find_first()
4527 + * Find the first cache entry on a given device with a certain key in
4528 + * an additional index. Additonal matches can be found with
4529 + * mb_cache_entry_find_next(). Returns NULL if no match was found.
4531 + * @cache: the cache to search
4532 + * @index: the number of the additonal index to search (0<=index<indexes_count)
4533 + * @dev: the device the cache entry should belong to
4534 + * @key: the key in the index
4536 +struct mb_cache_entry *
4537 +mb_cache_entry_find_first(struct mb_cache *cache, int index, kdev_t dev,
4540 + unsigned int bucket = key % cache->c_bucket_count;
4541 + struct list_head *l;
4542 + struct mb_cache_entry *ce;
4544 + mb_assert(index < mb_cache_indexes(cache));
4545 + spin_lock(&mb_cache_spinlock);
4546 + l = cache->c_indexes_hash[index][bucket].next;
4547 + ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
4549 + spin_unlock(&mb_cache_spinlock);
4555 + * mb_cache_entry_find_next()
4557 + * Find the next cache entry on a given device with a certain key in an
4558 + * additional index. Returns NULL if no match could be found. The previous
4559 + * entry is atomatically released, so that mb_cache_entry_find_next() can
4560 + * be called like this:
4562 + * entry = mb_cache_entry_find_first();
4565 + * entry = mb_cache_entry_find_next(entry, ...);
4568 + * @prev: The previous match
4569 + * @index: the number of the additonal index to search (0<=index<indexes_count)
4570 + * @dev: the device the cache entry should belong to
4571 + * @key: the key in the index
4573 +struct mb_cache_entry *
4574 +mb_cache_entry_find_next(struct mb_cache_entry *prev, int index, kdev_t dev,
4577 + struct mb_cache *cache = prev->e_cache;
4578 + unsigned int bucket = key % cache->c_bucket_count;
4579 + struct list_head *l;
4580 + struct mb_cache_entry *ce;
4582 + mb_assert(index < mb_cache_indexes(cache));
4583 + spin_lock(&mb_cache_spinlock);
4584 + l = prev->e_indexes[index].o_list.next;
4585 + ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
4587 + __mb_cache_entry_release_unlock(prev);
4591 +#endif /* !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0) */
4593 +static int __init init_mbcache(void)
4595 + register_cache(&mb_cache_definition);
4599 +static void __exit exit_mbcache(void)
4601 + unregister_cache(&mb_cache_definition);
4604 +module_init(init_mbcache)
4605 +module_exit(exit_mbcache)
4607 --- linux-2.4.22-ac1/include/asm-arm/unistd.h~xattr-0.8.54-2.4.22-rh 2003-08-25 15:44:43.000000000 +0400
4608 +++ linux-2.4.22-ac1-alexey/include/asm-arm/unistd.h 2003-09-25 23:57:02.000000000 +0400
4610 #define __NR_security (__NR_SYSCALL_BASE+223)
4611 #define __NR_gettid (__NR_SYSCALL_BASE+224)
4612 #define __NR_readahead (__NR_SYSCALL_BASE+225)
4613 -#if 0 /* allocated in 2.5 */
4614 #define __NR_setxattr (__NR_SYSCALL_BASE+226)
4615 #define __NR_lsetxattr (__NR_SYSCALL_BASE+227)
4616 #define __NR_fsetxattr (__NR_SYSCALL_BASE+228)
4618 #define __NR_removexattr (__NR_SYSCALL_BASE+235)
4619 #define __NR_lremovexattr (__NR_SYSCALL_BASE+236)
4620 #define __NR_fremovexattr (__NR_SYSCALL_BASE+237)
4622 #define __NR_tkill (__NR_SYSCALL_BASE+238)
4623 #if 0 /* allocated in 2.5 */
4624 #define __NR_sendfile64 (__NR_SYSCALL_BASE+239)
4625 --- linux-2.4.22-ac1/include/asm-ppc64/unistd.h~xattr-0.8.54-2.4.22-rh 2003-06-13 18:51:38.000000000 +0400
4626 +++ linux-2.4.22-ac1-alexey/include/asm-ppc64/unistd.h 2003-09-25 23:57:02.000000000 +0400
4628 #define __NR_mincore 206
4629 #define __NR_gettid 207
4630 #define __NR_tkill 208
4632 #define __NR_setxattr 209
4633 #define __NR_lsetxattr 210
4634 #define __NR_fsetxattr 211
4636 #define __NR_removexattr 218
4637 #define __NR_lremovexattr 219
4638 #define __NR_fremovexattr 220
4639 +#if 0 /* Reserved syscalls */
4640 #define __NR_futex 221
4641 #define __NR_sched_setaffinity 222
4642 #define __NR_sched_getaffinity 223
4643 --- linux-2.4.22-ac1/include/asm-s390/unistd.h~xattr-0.8.54-2.4.22-rh 2003-06-13 18:51:38.000000000 +0400
4644 +++ linux-2.4.22-ac1-alexey/include/asm-s390/unistd.h 2003-09-26 00:14:23.000000000 +0400
4645 @@ -213,6 +213,19 @@
4646 #define __NR_getdents64 220
4647 #define __NR_fcntl64 221
4648 #define __NR_readahead 222
4649 +#define __NR_setxattr 224
4650 +#define __NR_lsetxattr 225
4651 +#define __NR_fsetxattr 226
4652 +#define __NR_getxattr 227
4653 +#define __NR_lgetxattr 228
4654 +#define __NR_fgetxattr 229
4655 +#define __NR_listxattr 230
4656 +#define __NR_llistxattr 231
4657 +#define __NR_flistxattr 232
4658 +#define __NR_removexattr 233
4659 +#define __NR_lremovexattr 234
4660 +#define __NR_fremovexattr 235
4663 * Numbers 224-235 are reserved for posix acl
4665 --- linux-2.4.22-ac1/include/asm-s390x/unistd.h~xattr-0.8.54-2.4.22-rh 2003-06-13 18:51:38.000000000 +0400
4666 +++ linux-2.4.22-ac1-alexey/include/asm-s390x/unistd.h 2003-09-26 00:15:11.000000000 +0400
4667 @@ -181,6 +181,19 @@
4668 #define __NR_mincore 218
4669 #define __NR_madvise 219
4670 #define __NR_readahead 222
4671 +#define __NR_setxattr 224
4672 +#define __NR_lsetxattr 225
4673 +#define __NR_fsetxattr 226
4674 +#define __NR_getxattr 227
4675 +#define __NR_lgetxattr 228
4676 +#define __NR_fgetxattr 229
4677 +#define __NR_listxattr 230
4678 +#define __NR_llistxattr 231
4679 +#define __NR_flistxattr 232
4680 +#define __NR_removexattr 233
4681 +#define __NR_lremovexattr 234
4682 +#define __NR_fremovexattr 235
4685 * Numbers 224-235 are reserved for posix acl
4687 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
4688 +++ linux-2.4.22-ac1-alexey/include/linux/cache_def.h 2003-09-25 23:57:02.000000000 +0400
4691 + * linux/cache_def.h
4692 + * Handling of caches defined in drivers, filesystems, ...
4694 + * Copyright (C) 2002 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
4697 +struct cache_definition {
4699 + void (*shrink)(int, unsigned int);
4700 + struct list_head link;
4703 +extern void register_cache(struct cache_definition *);
4704 +extern void unregister_cache(struct cache_definition *);
4705 --- linux-2.4.22-ac1/include/linux/errno.h~xattr-0.8.54-2.4.22-rh 2001-02-10 01:46:13.000000000 +0300
4706 +++ linux-2.4.22-ac1-alexey/include/linux/errno.h 2003-09-25 23:57:02.000000000 +0400
4711 +/* Defined for extended attributes */
4712 +#define ENOATTR ENODATA /* No such attribute */
4713 +#define ENOTSUP EOPNOTSUPP /* Operation not supported */
4716 --- linux-2.4.22-ac1/include/linux/ext2_fs.h~xattr-0.8.54-2.4.22-rh 2003-06-13 18:51:38.000000000 +0400
4717 +++ linux-2.4.22-ac1-alexey/include/linux/ext2_fs.h 2003-09-25 23:57:02.000000000 +0400
4720 #define EXT2_BAD_INO 1 /* Bad blocks inode */
4721 #define EXT2_ROOT_INO 2 /* Root inode */
4722 -#define EXT2_ACL_IDX_INO 3 /* ACL inode */
4723 -#define EXT2_ACL_DATA_INO 4 /* ACL inode */
4724 #define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
4725 #define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
4729 # define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
4731 -#define EXT2_ACLE_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
4732 #define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
4734 # define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
4735 @@ -121,28 +118,6 @@
4741 -struct ext2_acl_header /* Header of Access Control Lists */
4744 - __u32 aclh_file_count;
4745 - __u32 aclh_acle_count;
4746 - __u32 aclh_first_acle;
4749 -struct ext2_acl_entry /* Access Control List Entry */
4752 - __u16 acle_perms; /* Access permissions */
4753 - __u16 acle_type; /* Type of entry */
4754 - __u16 acle_tag; /* User or group identity */
4756 - __u32 acle_next; /* Pointer on next entry for the */
4757 - /* same inode or on next free entry */
4761 * Structure of a blocks group descriptor
4763 struct ext2_group_desc
4764 @@ -314,6 +289,7 @@ struct ext2_inode {
4765 #define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
4766 #define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
4767 #define EXT2_MOUNT_NO_UID32 0x0200 /* Disable 32-bit UIDs */
4768 +#define EXT2_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
4770 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
4771 #define set_opt(o, opt) o |= EXT2_MOUNT_##opt
4772 @@ -397,6 +373,7 @@ struct ext2_super_block {
4775 #define EXT2_SB(sb) (&((sb)->u.ext2_sb))
4776 +#define EXT2_I(inode) (&((inode)->u.ext2_i))
4778 /* Assume that user mode programs are passing in an ext2fs superblock, not
4779 * a kernel struct super_block. This will allow us to call the feature-test
4780 @@ -466,7 +443,7 @@ struct ext2_super_block {
4781 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
4782 #define EXT2_FEATURE_INCOMPAT_ANY 0xffffffff
4784 -#define EXT2_FEATURE_COMPAT_SUPP 0
4785 +#define EXT2_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
4786 #define EXT2_FEATURE_INCOMPAT_SUPP EXT2_FEATURE_INCOMPAT_FILETYPE
4787 #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
4788 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
4789 @@ -624,8 +601,10 @@ extern struct address_space_operations e
4792 extern struct inode_operations ext2_dir_inode_operations;
4793 +extern struct inode_operations ext2_special_inode_operations;
4796 +extern struct inode_operations ext2_symlink_inode_operations;
4797 extern struct inode_operations ext2_fast_symlink_inode_operations;
4799 #endif /* __KERNEL__ */
4800 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
4801 +++ linux-2.4.22-ac1-alexey/include/linux/ext2_xattr.h 2003-09-25 23:57:02.000000000 +0400
4804 + File: linux/ext2_xattr.h
4806 + On-disk format of extended attributes for the ext2 filesystem.
4808 + (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
4811 +#include <linux/config.h>
4812 +#include <linux/init.h>
4813 +#include <linux/xattr.h>
4815 +/* Magic value in attribute blocks */
4816 +#define EXT2_XATTR_MAGIC 0xEA020000
4818 +/* Maximum number of references to one attribute block */
4819 +#define EXT2_XATTR_REFCOUNT_MAX 1024
4822 +#define EXT2_XATTR_INDEX_MAX 10
4823 +#define EXT2_XATTR_INDEX_USER 1
4824 +#define EXT2_XATTR_INDEX_POSIX_ACL_ACCESS 2
4825 +#define EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT 3
4827 +struct ext2_xattr_header {
4828 + __u32 h_magic; /* magic number for identification */
4829 + __u32 h_refcount; /* reference count */
4830 + __u32 h_blocks; /* number of disk blocks used */
4831 + __u32 h_hash; /* hash value of all attributes */
4832 + __u32 h_reserved[4]; /* zero right now */
4835 +struct ext2_xattr_entry {
4836 + __u8 e_name_len; /* length of name */
4837 + __u8 e_name_index; /* attribute name index */
4838 + __u16 e_value_offs; /* offset in disk block of value */
4839 + __u32 e_value_block; /* disk block attribute is stored on (n/i) */
4840 + __u32 e_value_size; /* size of attribute value */
4841 + __u32 e_hash; /* hash value of name and value */
4842 + char e_name[0]; /* attribute name */
4845 +#define EXT2_XATTR_PAD_BITS 2
4846 +#define EXT2_XATTR_PAD (1<<EXT2_XATTR_PAD_BITS)
4847 +#define EXT2_XATTR_ROUND (EXT2_XATTR_PAD-1)
4848 +#define EXT2_XATTR_LEN(name_len) \
4849 + (((name_len) + EXT2_XATTR_ROUND + \
4850 + sizeof(struct ext2_xattr_entry)) & ~EXT2_XATTR_ROUND)
4851 +#define EXT2_XATTR_NEXT(entry) \
4852 + ( (struct ext2_xattr_entry *)( \
4853 + (char *)(entry) + EXT2_XATTR_LEN((entry)->e_name_len)) )
4854 +#define EXT2_XATTR_SIZE(size) \
4855 + (((size) + EXT2_XATTR_ROUND) & ~EXT2_XATTR_ROUND)
4859 +# ifdef CONFIG_EXT2_FS_XATTR
4861 +struct ext2_xattr_handler {
4863 + size_t (*list)(char *list, struct inode *inode, const char *name,
4865 + int (*get)(struct inode *inode, const char *name, void *buffer,
4867 + int (*set)(struct inode *inode, const char *name, const void *buffer,
4868 + size_t size, int flags);
4871 +extern int ext2_xattr_register(int, struct ext2_xattr_handler *);
4872 +extern void ext2_xattr_unregister(int, struct ext2_xattr_handler *);
4874 +extern int ext2_setxattr(struct dentry *, const char *, const void *, size_t, int);
4875 +extern ssize_t ext2_getxattr(struct dentry *, const char *, void *, size_t);
4876 +extern ssize_t ext2_listxattr(struct dentry *, char *, size_t);
4877 +extern int ext2_removexattr(struct dentry *, const char *);
4879 +extern int ext2_xattr_get(struct inode *, int, const char *, void *, size_t);
4880 +extern int ext2_xattr_list(struct inode *, char *, size_t);
4881 +extern int ext2_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
4883 +extern void ext2_xattr_delete_inode(struct inode *);
4884 +extern void ext2_xattr_put_super(struct super_block *);
4886 +extern int init_ext2_xattr(void) __init;
4887 +extern void exit_ext2_xattr(void);
4889 +# else /* CONFIG_EXT2_FS_XATTR */
4890 +# define ext2_setxattr NULL
4891 +# define ext2_getxattr NULL
4892 +# define ext2_listxattr NULL
4893 +# define ext2_removexattr NULL
4896 +ext2_xattr_get(struct inode *inode, int name_index,
4897 + const char *name, void *buffer, size_t size)
4903 +ext2_xattr_list(struct inode *inode, char *buffer, size_t size)
4909 +ext2_xattr_set(struct inode *inode, int name_index, const char *name,
4910 + const void *value, size_t size, int flags)
4916 +ext2_xattr_delete_inode(struct inode *inode)
4921 +ext2_xattr_put_super(struct super_block *sb)
4926 +init_ext2_xattr(void)
4932 +exit_ext2_xattr(void)
4936 +# endif /* CONFIG_EXT2_FS_XATTR */
4938 +# ifdef CONFIG_EXT2_FS_XATTR_USER
4940 +extern int init_ext2_xattr_user(void) __init;
4941 +extern void exit_ext2_xattr_user(void);
4943 +# else /* CONFIG_EXT2_FS_XATTR_USER */
4946 +init_ext2_xattr_user(void)
4952 +exit_ext2_xattr_user(void)
4956 +# endif /* CONFIG_EXT2_FS_XATTR_USER */
4958 +#endif /* __KERNEL__ */
4960 --- linux-2.4.22-ac1/include/linux/ext3_fs.h~xattr-0.8.54-2.4.22-rh 2003-09-25 14:58:30.000000000 +0400
4961 +++ linux-2.4.22-ac1-alexey/include/linux/ext3_fs.h 2003-09-25 23:57:02.000000000 +0400
4964 #define EXT3_BAD_INO 1 /* Bad blocks inode */
4965 #define EXT3_ROOT_INO 2 /* Root inode */
4966 -#define EXT3_ACL_IDX_INO 3 /* ACL inode */
4967 -#define EXT3_ACL_DATA_INO 4 /* ACL inode */
4968 #define EXT3_BOOT_LOADER_INO 5 /* Boot loader inode */
4969 #define EXT3_UNDEL_DIR_INO 6 /* Undelete directory inode */
4970 #define EXT3_RESIZE_INO 7 /* Reserved group descriptors inode */
4973 # define EXT3_BLOCK_SIZE(s) (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
4975 -#define EXT3_ACLE_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_acl_entry))
4976 #define EXT3_ADDR_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (__u32))
4978 # define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
4979 @@ -129,28 +126,6 @@
4985 -struct ext3_acl_header /* Header of Access Control Lists */
4988 - __u32 aclh_file_count;
4989 - __u32 aclh_acle_count;
4990 - __u32 aclh_first_acle;
4993 -struct ext3_acl_entry /* Access Control List Entry */
4996 - __u16 acle_perms; /* Access permissions */
4997 - __u16 acle_type; /* Type of entry */
4998 - __u16 acle_tag; /* User or group identity */
5000 - __u32 acle_next; /* Pointer on next entry for the */
5001 - /* same inode or on next free entry */
5005 * Structure of a blocks group descriptor
5007 struct ext3_group_desc
5008 @@ -346,6 +321,7 @@ struct ext3_inode {
5009 #define EXT3_MOUNT_WRITEBACK_DATA 0x0C00 /* No data ordering */
5010 #define EXT3_MOUNT_UPDATE_JOURNAL 0x1000 /* Update the journal format */
5011 #define EXT3_MOUNT_NO_UID32 0x2000 /* Disable 32-bit UIDs */
5012 +#define EXT3_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
5014 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
5015 #ifndef _LINUX_EXT2_FS_H
5016 @@ -523,7 +499,7 @@ struct ext3_super_block {
5017 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
5018 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
5020 -#define EXT3_FEATURE_COMPAT_SUPP 0
5021 +#define EXT3_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
5022 #define EXT3_FEATURE_INCOMPAT_SUPP (EXT3_FEATURE_INCOMPAT_FILETYPE| \
5023 EXT3_FEATURE_INCOMPAT_RECOVER)
5024 #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
5025 @@ -707,6 +683,7 @@ extern void ext3_check_inodes_bitmap (st
5026 extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
5029 +extern int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
5030 extern struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
5031 extern struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
5033 @@ -776,8 +753,10 @@ extern struct address_space_operations e
5036 extern struct inode_operations ext3_dir_inode_operations;
5037 +extern struct inode_operations ext3_special_inode_operations;
5040 +extern struct inode_operations ext3_symlink_inode_operations;
5041 extern struct inode_operations ext3_fast_symlink_inode_operations;
5044 --- linux-2.4.22-ac1/include/linux/ext3_jbd.h~xattr-0.8.54-2.4.22-rh 2003-09-25 14:55:12.000000000 +0400
5045 +++ linux-2.4.22-ac1-alexey/include/linux/ext3_jbd.h 2003-09-25 23:57:02.000000000 +0400
5048 #define EXT3_SINGLEDATA_TRANS_BLOCKS 8U
5050 +/* Extended attributes may touch two data buffers, two bitmap buffers,
5051 + * and two group and summaries. */
5053 +#define EXT3_XATTR_TRANS_BLOCKS 8
5055 /* Define the minimum size for a transaction which modifies data. This
5056 * needs to take into account the fact that we may end up modifying two
5057 * quota files too (one for the group, one for the user quota). The
5058 * superblock only gets updated once, of course, so don't bother
5059 * counting that again for the quota updates. */
5061 -#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS - 2)
5062 +#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS + \
5063 + EXT3_XATTR_TRANS_BLOCKS - 2)
5065 extern int ext3_writepage_trans_blocks(struct inode *inode);
5067 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
5068 +++ linux-2.4.22-ac1-alexey/include/linux/ext3_xattr.h 2003-09-25 23:57:02.000000000 +0400
5071 + File: linux/ext3_xattr.h
5073 + On-disk format of extended attributes for the ext3 filesystem.
5075 + (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
5078 +#include <linux/config.h>
5079 +#include <linux/init.h>
5080 +#include <linux/xattr.h>
5082 +/* Magic value in attribute blocks */
5083 +#define EXT3_XATTR_MAGIC 0xEA020000
5085 +/* Maximum number of references to one attribute block */
5086 +#define EXT3_XATTR_REFCOUNT_MAX 1024
5089 +#define EXT3_XATTR_INDEX_MAX 10
5090 +#define EXT3_XATTR_INDEX_USER 1
5091 +#define EXT3_XATTR_INDEX_POSIX_ACL_ACCESS 2
5092 +#define EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT 3
5094 +struct ext3_xattr_header {
5095 + __u32 h_magic; /* magic number for identification */
5096 + __u32 h_refcount; /* reference count */
5097 + __u32 h_blocks; /* number of disk blocks used */
5098 + __u32 h_hash; /* hash value of all attributes */
5099 + __u32 h_reserved[4]; /* zero right now */
5102 +struct ext3_xattr_entry {
5103 + __u8 e_name_len; /* length of name */
5104 + __u8 e_name_index; /* attribute name index */
5105 + __u16 e_value_offs; /* offset in disk block of value */
5106 + __u32 e_value_block; /* disk block attribute is stored on (n/i) */
5107 + __u32 e_value_size; /* size of attribute value */
5108 + __u32 e_hash; /* hash value of name and value */
5109 + char e_name[0]; /* attribute name */
5112 +#define EXT3_XATTR_PAD_BITS 2
5113 +#define EXT3_XATTR_PAD (1<<EXT3_XATTR_PAD_BITS)
5114 +#define EXT3_XATTR_ROUND (EXT3_XATTR_PAD-1)
5115 +#define EXT3_XATTR_LEN(name_len) \
5116 + (((name_len) + EXT3_XATTR_ROUND + \
5117 + sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND)
5118 +#define EXT3_XATTR_NEXT(entry) \
5119 + ( (struct ext3_xattr_entry *)( \
5120 + (char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) )
5121 +#define EXT3_XATTR_SIZE(size) \
5122 + (((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND)
5126 +# ifdef CONFIG_EXT3_FS_XATTR
5128 +struct ext3_xattr_handler {
5130 + size_t (*list)(char *list, struct inode *inode, const char *name,
5132 + int (*get)(struct inode *inode, const char *name, void *buffer,
5134 + int (*set)(struct inode *inode, const char *name, const void *buffer,
5135 + size_t size, int flags);
5138 +extern int ext3_xattr_register(int, struct ext3_xattr_handler *);
5139 +extern void ext3_xattr_unregister(int, struct ext3_xattr_handler *);
5141 +extern int ext3_setxattr(struct dentry *, const char *, const void *, size_t, int);
5142 +extern ssize_t ext3_getxattr(struct dentry *, const char *, void *, size_t);
5143 +extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
5144 +extern int ext3_removexattr(struct dentry *, const char *);
5146 +extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
5147 +extern int ext3_xattr_list(struct inode *, char *, size_t);
5148 +extern int ext3_xattr_set(handle_t *handle, struct inode *, int, const char *, const void *, size_t, int);
5150 +extern void ext3_xattr_delete_inode(handle_t *, struct inode *);
5151 +extern void ext3_xattr_put_super(struct super_block *);
5153 +extern int init_ext3_xattr(void) __init;
5154 +extern void exit_ext3_xattr(void);
5156 +# else /* CONFIG_EXT3_FS_XATTR */
5157 +# define ext3_setxattr NULL
5158 +# define ext3_getxattr NULL
5159 +# define ext3_listxattr NULL
5160 +# define ext3_removexattr NULL
5163 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
5164 + void *buffer, size_t size)
5170 +ext3_xattr_list(struct inode *inode, void *buffer, size_t size)
5176 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
5177 + const char *name, const void *value, size_t size, int flags)
5183 +ext3_xattr_delete_inode(handle_t *handle, struct inode *inode)
5188 +ext3_xattr_put_super(struct super_block *sb)
5193 +init_ext3_xattr(void)
5199 +exit_ext3_xattr(void)
5203 +# endif /* CONFIG_EXT3_FS_XATTR */
5205 +# ifdef CONFIG_EXT3_FS_XATTR_USER
5207 +extern int init_ext3_xattr_user(void) __init;
5208 +extern void exit_ext3_xattr_user(void);
5210 +# else /* CONFIG_EXT3_FS_XATTR_USER */
5213 +init_ext3_xattr_user(void)
5219 +exit_ext3_xattr_user(void)
5223 +#endif /* CONFIG_EXT3_FS_XATTR_USER */
5225 +#endif /* __KERNEL__ */
5227 --- linux-2.4.22-ac1/include/linux/fs.h~xattr-0.8.54-2.4.22-rh 2003-09-25 14:45:32.000000000 +0400
5228 +++ linux-2.4.22-ac1-alexey/include/linux/fs.h 2003-09-25 23:57:02.000000000 +0400
5229 @@ -918,7 +918,7 @@ struct inode_operations {
5230 int (*setattr) (struct dentry *, struct iattr *);
5231 int (*setattr_raw) (struct inode *, struct iattr *);
5232 int (*getattr) (struct dentry *, struct iattr *);
5233 - int (*setxattr) (struct dentry *, const char *, void *, size_t, int);
5234 + int (*setxattr) (struct dentry *, const char *, const void *, size_t, int);
5235 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
5236 ssize_t (*listxattr) (struct dentry *, char *, size_t);
5237 int (*removexattr) (struct dentry *, const char *);
5238 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
5239 +++ linux-2.4.22-ac1-alexey/include/linux/mbcache.h 2003-09-25 23:57:02.000000000 +0400
5242 + File: linux/mbcache.h
5244 + (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
5247 +/* Hardwire the number of additional indexes */
5248 +#define MB_CACHE_INDEXES_COUNT 1
5250 +struct mb_cache_entry;
5252 +struct mb_cache_op {
5253 + int (*free)(struct mb_cache_entry *, int);
5257 + struct list_head c_cache_list;
5258 + const char *c_name;
5259 + struct mb_cache_op c_op;
5260 + atomic_t c_entry_count;
5261 + int c_bucket_count;
5262 +#ifndef MB_CACHE_INDEXES_COUNT
5263 + int c_indexes_count;
5265 + kmem_cache_t *c_entry_cache;
5266 + struct list_head *c_block_hash;
5267 + struct list_head *c_indexes_hash[0];
5270 +struct mb_cache_entry_index {
5271 + struct list_head o_list;
5272 + unsigned int o_key;
5275 +struct mb_cache_entry {
5276 + struct list_head e_lru_list;
5277 + struct mb_cache *e_cache;
5280 + unsigned long e_block;
5281 + struct list_head e_block_list;
5282 + struct mb_cache_entry_index e_indexes[0];
5285 +/* Functions on caches */
5287 +struct mb_cache * mb_cache_create(const char *, struct mb_cache_op *, size_t,
5289 +void mb_cache_shrink(struct mb_cache *, kdev_t);
5290 +void mb_cache_destroy(struct mb_cache *);
5292 +/* Functions on cache entries */
5294 +struct mb_cache_entry *mb_cache_entry_alloc(struct mb_cache *);
5295 +int mb_cache_entry_insert(struct mb_cache_entry *, kdev_t, unsigned long,
5297 +void mb_cache_entry_rehash(struct mb_cache_entry *, unsigned int[]);
5298 +void mb_cache_entry_release(struct mb_cache_entry *);
5299 +void mb_cache_entry_takeout(struct mb_cache_entry *);
5300 +void mb_cache_entry_free(struct mb_cache_entry *);
5301 +struct mb_cache_entry *mb_cache_entry_dup(struct mb_cache_entry *);
5302 +struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *, kdev_t,
5304 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
5305 +struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache, int,
5306 + kdev_t, unsigned int);
5307 +struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache_entry *, int,
5308 + kdev_t, unsigned int);
5310 --- linux-2.4.22-ac1/kernel/ksyms.c~xattr-0.8.54-2.4.22-rh 2003-09-25 14:42:46.000000000 +0400
5311 +++ linux-2.4.22-ac1-alexey/kernel/ksyms.c 2003-09-26 00:19:05.000000000 +0400
5314 #include <linux/config.h>
5315 #include <linux/slab.h>
5316 +#include <linux/cache_def.h>
5317 #include <linux/smp.h>
5318 #include <linux/module.h>
5319 #include <linux/blkdev.h>
5320 @@ -106,6 +107,7 @@ EXPORT_SYMBOL(exit_files);
5321 EXPORT_SYMBOL(exit_fs);
5322 EXPORT_SYMBOL(exit_sighand);
5323 EXPORT_SYMBOL(unshare_files);
5324 +EXPORT_SYMBOL(copy_fs_struct);
5326 /* internal kernel memory management */
5327 EXPORT_SYMBOL(_alloc_pages);
5328 @@ -124,6 +126,8 @@ EXPORT_SYMBOL(kmem_cache_validate);
5329 EXPORT_SYMBOL(kmem_cache_alloc);
5330 EXPORT_SYMBOL(kmem_cache_free);
5331 EXPORT_SYMBOL(kmem_cache_size);
5332 +EXPORT_SYMBOL(register_cache);
5333 +EXPORT_SYMBOL(unregister_cache);
5334 EXPORT_SYMBOL(kmalloc);
5335 EXPORT_SYMBOL(kfree);
5336 EXPORT_SYMBOL(vfree);
5337 --- linux-2.4.22-ac1/mm/vmscan.c~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:28.000000000 +0400
5338 +++ linux-2.4.22-ac1-alexey/mm/vmscan.c 2003-09-25 23:57:02.000000000 +0400
5340 #include <linux/kernel_stat.h>
5341 #include <linux/swap.h>
5342 #include <linux/swapctl.h>
5343 +#include <linux/cache_def.h>
5344 #include <linux/smp_lock.h>
5345 #include <linux/pagemap.h>
5346 #include <linux/init.h>
5349 #define DEF_PRIORITY (6)
5351 +static DECLARE_MUTEX(other_caches_sem);
5352 +static LIST_HEAD(cache_definitions);
5354 +void register_cache(struct cache_definition *cache)
5356 + down(&other_caches_sem);
5357 + list_add(&cache->link, &cache_definitions);
5358 + up(&other_caches_sem);
5361 +void unregister_cache(struct cache_definition *cache)
5363 + down(&other_caches_sem);
5364 + list_del(&cache->link);
5365 + up(&other_caches_sem);
5368 +static void shrink_other_caches(unsigned int priority, int gfp_mask)
5370 + struct list_head *p;
5372 + if (down_trylock(&other_caches_sem))
5375 + list_for_each_prev(p, &cache_definitions) {
5376 + struct cache_definition *cache =
5377 + list_entry(p, struct cache_definition, link);
5379 + cache->shrink(priority, gfp_mask);
5381 + up(&other_caches_sem);
5385 * The swap-out function returns 1 if it successfully
5386 * scanned all the pages it was asked to (`count').
5387 @@ -577,6 +611,7 @@ static int shrink_caches(zone_t * classz
5389 shrink_dcache_memory(priority, gfp_mask);
5390 shrink_icache_memory(priority, gfp_mask);
5391 + shrink_other_caches(priority, gfp_mask);
5393 shrink_dqcache_memory(DEF_PRIORITY, gfp_mask);