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/ia64/kernel/entry.S | 24
9 arch/m68k/defconfig | 7
10 arch/mips/defconfig | 7
11 arch/mips64/defconfig | 7
12 arch/ppc/defconfig | 14
13 arch/ppc64/kernel/misc.S | 2
14 arch/s390/defconfig | 7
15 arch/s390/kernel/entry.S | 24
16 arch/s390x/defconfig | 7
17 arch/s390x/kernel/entry.S | 24
18 arch/s390x/kernel/wrapper32.S | 92 +++
19 arch/sparc/defconfig | 7
20 arch/sparc/kernel/systbls.S | 10
21 arch/sparc64/defconfig | 7
22 arch/sparc64/kernel/systbls.S | 20
28 fs/ext2/inode.c | 34 -
31 fs/ext2/symlink.c | 14
32 fs/ext2/xattr.c | 1212 +++++++++++++++++++++++++++++++++++++++++
33 fs/ext2/xattr_user.c | 103 +++
37 fs/ext3/inode.c | 35 -
39 fs/ext3/super.c | 36 +
40 fs/ext3/symlink.c | 14
41 fs/ext3/xattr.c | 1225 ++++++++++++++++++++++++++++++++++++++++++
42 fs/ext3/xattr_user.c | 111 +++
43 fs/jfs/jfs_xattr.h | 6
45 fs/mbcache.c | 648 ++++++++++++++++++++++
46 include/asm-arm/unistd.h | 2
47 include/asm-ia64/unistd.h | 13
48 include/asm-ppc64/unistd.h | 2
49 include/asm-s390/unistd.h | 15
50 include/asm-s390x/unistd.h | 15
51 include/asm-sparc/unistd.h | 24
52 include/asm-sparc64/unistd.h | 24
53 include/linux/cache_def.h | 15
54 include/linux/errno.h | 4
55 include/linux/ext2_fs.h | 31 -
56 include/linux/ext2_xattr.h | 157 +++++
57 include/linux/ext3_fs.h | 31 -
58 include/linux/ext3_jbd.h | 8
59 include/linux/ext3_xattr.h | 157 +++++
60 include/linux/fs.h | 2
61 include/linux/mbcache.h | 69 ++
64 fs/ext3/ext3-exports.c | 14 +
65 64 files changed, 4355 insertions(+), 195 deletions(-)
67 Index: linux-2.4.24-vanilla/Documentation/Configure.help
68 ===================================================================
69 --- linux-2.4.24-vanilla.orig/Documentation/Configure.help 2004-01-10 17:05:37.000000000 +0300
70 +++ linux-2.4.24-vanilla/Documentation/Configure.help 2004-01-10 17:20:28.000000000 +0300
71 @@ -16295,6 +16295,39 @@
72 be compiled as a module, and so this could be dangerous. Most
73 everyone wants to say Y here.
75 +Ext2 extended attributes
77 + Extended attributes are name:value pairs associated with inodes by
78 + the kernel or by users (see the attr(5) manual page, or visit
79 + <http://acl.bestbits.at/> for details).
83 +Ext2 extended attribute block sharing
84 +CONFIG_EXT2_FS_XATTR_SHARING
85 + This options enables code for sharing identical extended attribute
86 + blocks among multiple inodes.
90 +Ext2 extended user attributes
91 +CONFIG_EXT2_FS_XATTR_USER
92 + This option enables extended user attributes on ext2. Processes can
93 + associate extended user attributes with inodes to store additional
94 + information such as the character encoding of files, etc. (see the
95 + attr(5) manual page, or visit <http://acl.bestbits.at/> for details).
99 +Ext2 trusted extended attributes
100 +CONFIG_EXT2_FS_XATTR_TRUSTED
101 + This option enables extended attributes on ext2 that are accessible
102 + (and visible) only to users capable of CAP_SYS_ADMIN. Usually this
103 + is only the super user. Trusted extended attributes are meant for
104 + implementing system/security services.
108 Ext3 journalling file system support (EXPERIMENTAL)
110 This is the journalling version of the Second extended file system
111 @@ -16327,6 +16360,39 @@
112 of your root partition (the one containing the directory /) cannot
113 be compiled as a module, and so this may be dangerous.
115 +Ext3 extended attributes
116 +CONFIG_EXT3_FS_XATTR
117 + Extended attributes are name:value pairs associated with inodes by
118 + the kernel or by users (see the attr(5) manual page, or visit
119 + <http://acl.bestbits.at/> for details).
123 +Ext3 extended attribute block sharing
124 +CONFIG_EXT3_FS_XATTR_SHARING
125 + This options enables code for sharing identical extended attribute
126 + blocks among multiple inodes.
130 +Ext3 extended user attributes
131 +CONFIG_EXT3_FS_XATTR_USER
132 + This option enables extended user attributes on ext3. Processes can
133 + associate extended user attributes with inodes to store additional
134 + information such as the character encoding of files, etc. (see the
135 + attr(5) manual page, or visit <http://acl.bestbits.at/> for details).
139 +Ext3 trusted extended attributes
140 +CONFIG_EXT3_FS_XATTR_TRUSTED
141 + This option enables extended attributes on ext3 that are accessible
142 + (and visible) only to users capable of CAP_SYS_ADMIN. Usually this
143 + is only the super user. Trusted extended attributes are meant for
144 + implementing system/security services.
148 Journal Block Device support (JBD for ext3) (EXPERIMENTAL)
150 This is a generic journalling layer for block devices. It is
151 Index: linux-2.4.24-vanilla/arch/alpha/defconfig
152 ===================================================================
153 --- linux-2.4.24-vanilla.orig/arch/alpha/defconfig 2004-01-10 17:04:37.000000000 +0300
154 +++ linux-2.4.24-vanilla/arch/alpha/defconfig 2004-01-10 17:20:28.000000000 +0300
157 # Automatically generated make config: don't edit
159 +CONFIG_EXT3_FS_XATTR=y
160 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
161 +# CONFIG_EXT3_FS_XATTR_USER is not set
162 +# CONFIG_EXT2_FS_XATTR is not set
163 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
164 +# CONFIG_EXT2_FS_XATTR_USER is not set
165 +# CONFIG_FS_MBCACHE is not set
167 # CONFIG_UID16 is not set
168 # CONFIG_RWSEM_GENERIC_SPINLOCK is not set
169 Index: linux-2.4.24-vanilla/arch/alpha/kernel/entry.S
170 ===================================================================
171 --- linux-2.4.24-vanilla.orig/arch/alpha/kernel/entry.S 2004-01-10 17:04:37.000000000 +0300
172 +++ linux-2.4.24-vanilla/arch/alpha/kernel/entry.S 2004-01-10 17:20:28.000000000 +0300
173 @@ -1154,6 +1154,18 @@
175 .quad sys_ni_syscall /* 380, sys_security */
178 + .quad sys_lsetxattr
179 + .quad sys_fsetxattr
180 + .quad sys_getxattr /* 385 */
181 + .quad sys_lgetxattr
182 + .quad sys_fgetxattr
183 + .quad sys_listxattr
184 + .quad sys_llistxattr
185 + .quad sys_flistxattr /* 390 */
186 + .quad sys_removexattr
187 + .quad sys_lremovexattr
188 + .quad sys_fremovexattr
190 /* Remember to update everything, kids. */
191 .ifne (. - sys_call_table) - (NR_SYSCALLS * 8)
192 Index: linux-2.4.24-vanilla/arch/arm/defconfig
193 ===================================================================
194 --- linux-2.4.24-vanilla.orig/arch/arm/defconfig 2001-05-20 04:43:05.000000000 +0400
195 +++ linux-2.4.24-vanilla/arch/arm/defconfig 2004-01-10 17:20:28.000000000 +0300
198 # Automatically generated make config: don't edit
200 +CONFIG_EXT3_FS_XATTR=y
201 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
202 +# CONFIG_EXT3_FS_XATTR_USER is not set
203 +# CONFIG_EXT2_FS_XATTR is not set
204 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
205 +# CONFIG_EXT2_FS_XATTR_USER is not set
206 +# CONFIG_FS_MBCACHE is not set
208 # CONFIG_EISA is not set
209 # CONFIG_SBUS is not set
210 Index: linux-2.4.24-vanilla/arch/arm/kernel/calls.S
211 ===================================================================
212 --- linux-2.4.24-vanilla.orig/arch/arm/kernel/calls.S 2004-01-10 17:04:58.000000000 +0300
213 +++ linux-2.4.24-vanilla/arch/arm/kernel/calls.S 2004-01-10 17:20:28.000000000 +0300
214 @@ -240,18 +240,18 @@
215 .long SYMBOL_NAME(sys_ni_syscall) /* Security */
216 .long SYMBOL_NAME(sys_gettid)
217 /* 225 */ .long SYMBOL_NAME(sys_readahead)
218 - .long SYMBOL_NAME(sys_ni_syscall) /* setxattr */
219 - .long SYMBOL_NAME(sys_ni_syscall) /* lsetxattr */
220 - .long SYMBOL_NAME(sys_ni_syscall) /* fsetxattr */
221 - .long SYMBOL_NAME(sys_ni_syscall) /* getxattr */
222 -/* 230 */ .long SYMBOL_NAME(sys_ni_syscall) /* lgetxattr */
223 - .long SYMBOL_NAME(sys_ni_syscall) /* fgetxattr */
224 - .long SYMBOL_NAME(sys_ni_syscall) /* listxattr */
225 - .long SYMBOL_NAME(sys_ni_syscall) /* llistxattr */
226 - .long SYMBOL_NAME(sys_ni_syscall) /* flistxattr */
227 -/* 235 */ .long SYMBOL_NAME(sys_ni_syscall) /* removexattr */
228 - .long SYMBOL_NAME(sys_ni_syscall) /* lremovexattr */
229 - .long SYMBOL_NAME(sys_ni_syscall) /* fremovexattr */
230 + .long SYMBOL_NAME(sys_setxattr)
231 + .long SYMBOL_NAME(sys_lsetxattr)
232 + .long SYMBOL_NAME(sys_fsetxattr)
233 + .long SYMBOL_NAME(sys_getxattr)
234 +/* 230 */ .long SYMBOL_NAME(sys_lgetxattr)
235 + .long SYMBOL_NAME(sys_fgetxattr)
236 + .long SYMBOL_NAME(sys_listxattr)
237 + .long SYMBOL_NAME(sys_llistxattr)
238 + .long SYMBOL_NAME(sys_flistxattr)
239 +/* 235 */ .long SYMBOL_NAME(sys_removexattr)
240 + .long SYMBOL_NAME(sys_lremovexattr)
241 + .long SYMBOL_NAME(sys_fremovexattr)
242 .long SYMBOL_NAME(sys_tkill)
243 .long SYMBOL_NAME(sys_ni_syscall) /* sendfile64 */
244 /* 240 */ .long SYMBOL_NAME(sys_ni_syscall) /* futex */
245 Index: linux-2.4.24-vanilla/arch/i386/defconfig
246 ===================================================================
247 --- linux-2.4.24-vanilla.orig/arch/i386/defconfig 2004-01-10 17:05:45.000000000 +0300
248 +++ linux-2.4.24-vanilla/arch/i386/defconfig 2004-01-10 17:20:28.000000000 +0300
251 # Automatically generated make config: don't edit
253 +CONFIG_EXT3_FS_XATTR=y
254 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
255 +# CONFIG_EXT3_FS_XATTR_USER is not set
256 +# CONFIG_EXT2_FS_XATTR is not set
257 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
258 +# CONFIG_EXT2_FS_XATTR_USER is not set
259 +# CONFIG_FS_MBCACHE is not set
262 # CONFIG_SBUS is not set
263 Index: linux-2.4.24-vanilla/arch/ia64/defconfig
264 ===================================================================
265 --- linux-2.4.24-vanilla.orig/arch/ia64/defconfig 2004-01-10 17:05:52.000000000 +0300
266 +++ linux-2.4.24-vanilla/arch/ia64/defconfig 2004-01-10 17:20:28.000000000 +0300
269 # Automatically generated make config: don't edit
271 +CONFIG_EXT3_FS_XATTR=y
272 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
273 +# CONFIG_EXT3_FS_XATTR_USER is not set
274 +# CONFIG_EXT2_FS_XATTR is not set
275 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
276 +# CONFIG_EXT2_FS_XATTR_USER is not set
277 +# CONFIG_FS_MBCACHE is not set
280 # Code maturity level options
281 Index: linux-2.4.24-vanilla/arch/m68k/defconfig
282 ===================================================================
283 --- linux-2.4.24-vanilla.orig/arch/m68k/defconfig 2004-01-10 17:05:52.000000000 +0300
284 +++ linux-2.4.24-vanilla/arch/m68k/defconfig 2004-01-10 17:20:28.000000000 +0300
287 # Automatically generated make config: don't edit
289 +CONFIG_EXT3_FS_XATTR=y
290 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
291 +# CONFIG_EXT3_FS_XATTR_USER is not set
292 +# CONFIG_EXT2_FS_XATTR is not set
293 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
294 +# CONFIG_EXT2_FS_XATTR_USER is not set
295 +# CONFIG_FS_MBCACHE is not set
299 Index: linux-2.4.24-vanilla/arch/mips/defconfig
300 ===================================================================
301 --- linux-2.4.24-vanilla.orig/arch/mips/defconfig 2004-01-10 17:04:59.000000000 +0300
302 +++ linux-2.4.24-vanilla/arch/mips/defconfig 2004-01-10 17:20:28.000000000 +0300
305 # Automatically generated make config: don't edit
307 +CONFIG_EXT3_FS_XATTR=y
308 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
309 +# CONFIG_EXT3_FS_XATTR_USER is not set
310 +# CONFIG_EXT2_FS_XATTR is not set
311 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
312 +# CONFIG_EXT2_FS_XATTR_USER is not set
313 +# CONFIG_FS_MBCACHE is not set
316 # CONFIG_MIPS64 is not set
317 Index: linux-2.4.24-vanilla/arch/mips64/defconfig
318 ===================================================================
319 --- linux-2.4.24-vanilla.orig/arch/mips64/defconfig 2004-01-10 17:05:52.000000000 +0300
320 +++ linux-2.4.24-vanilla/arch/mips64/defconfig 2004-01-10 17:20:28.000000000 +0300
323 # Automatically generated make config: don't edit
325 +CONFIG_EXT3_FS_XATTR=y
326 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
327 +# CONFIG_EXT3_FS_XATTR_USER is not set
328 +# CONFIG_EXT2_FS_XATTR is not set
329 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
330 +# CONFIG_EXT2_FS_XATTR_USER is not set
331 +# CONFIG_FS_MBCACHE is not set
333 # CONFIG_MIPS32 is not set
335 Index: linux-2.4.24-vanilla/arch/s390/defconfig
336 ===================================================================
337 --- linux-2.4.24-vanilla.orig/arch/s390/defconfig 2004-01-10 17:05:52.000000000 +0300
338 +++ linux-2.4.24-vanilla/arch/s390/defconfig 2004-01-10 17:20:28.000000000 +0300
341 # Automatically generated make config: don't edit
343 +CONFIG_EXT3_FS_XATTR=y
344 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
345 +# CONFIG_EXT3_FS_XATTR_USER is not set
346 +# CONFIG_EXT2_FS_XATTR is not set
347 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
348 +# CONFIG_EXT2_FS_XATTR_USER is not set
349 +# CONFIG_FS_MBCACHE is not set
350 # CONFIG_ISA is not set
351 # CONFIG_EISA is not set
352 # CONFIG_MCA is not set
353 Index: linux-2.4.24-vanilla/arch/s390/kernel/entry.S
354 ===================================================================
355 --- linux-2.4.24-vanilla.orig/arch/s390/kernel/entry.S 2004-01-10 17:04:39.000000000 +0300
356 +++ linux-2.4.24-vanilla/arch/s390/kernel/entry.S 2004-01-10 17:20:28.000000000 +0300
357 @@ -558,18 +558,18 @@
361 - .long sys_ni_syscall /* 224 - reserved for setxattr */
362 - .long sys_ni_syscall /* 225 - reserved for lsetxattr */
363 - .long sys_ni_syscall /* 226 - reserved for fsetxattr */
364 - .long sys_ni_syscall /* 227 - reserved for getxattr */
365 - .long sys_ni_syscall /* 228 - reserved for lgetxattr */
366 - .long sys_ni_syscall /* 229 - reserved for fgetxattr */
367 - .long sys_ni_syscall /* 230 - reserved for listxattr */
368 - .long sys_ni_syscall /* 231 - reserved for llistxattr */
369 - .long sys_ni_syscall /* 232 - reserved for flistxattr */
370 - .long sys_ni_syscall /* 233 - reserved for removexattr */
371 - .long sys_ni_syscall /* 234 - reserved for lremovexattr */
372 - .long sys_ni_syscall /* 235 - reserved for fremovexattr */
374 + .long sys_lsetxattr /* 225 */
375 + .long sys_fsetxattr
377 + .long sys_lgetxattr
378 + .long sys_fgetxattr
379 + .long sys_listxattr /* 230 */
380 + .long sys_llistxattr
381 + .long sys_flistxattr
382 + .long sys_removexattr
383 + .long sys_lremovexattr
384 + .long sys_fremovexattr /* 235 */
388 Index: linux-2.4.24-vanilla/arch/s390x/defconfig
389 ===================================================================
390 --- linux-2.4.24-vanilla.orig/arch/s390x/defconfig 2004-01-10 17:05:52.000000000 +0300
391 +++ linux-2.4.24-vanilla/arch/s390x/defconfig 2004-01-10 17:20:28.000000000 +0300
394 # Automatically generated make config: don't edit
396 +CONFIG_EXT3_FS_XATTR=y
397 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
398 +# CONFIG_EXT3_FS_XATTR_USER is not set
399 +# CONFIG_EXT2_FS_XATTR is not set
400 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
401 +# CONFIG_EXT2_FS_XATTR_USER is not set
402 +# CONFIG_FS_MBCACHE is not set
403 # CONFIG_ISA is not set
404 # CONFIG_EISA is not set
405 # CONFIG_MCA is not set
406 Index: linux-2.4.24-vanilla/arch/s390x/kernel/entry.S
407 ===================================================================
408 --- linux-2.4.24-vanilla.orig/arch/s390x/kernel/entry.S 2004-01-10 17:05:00.000000000 +0300
409 +++ linux-2.4.24-vanilla/arch/s390x/kernel/entry.S 2004-01-10 17:20:28.000000000 +0300
410 @@ -591,18 +591,18 @@
411 .long SYSCALL(sys_ni_syscall,sys32_fcntl64_wrapper)
412 .long SYSCALL(sys_readahead,sys32_readahead)
413 .long SYSCALL(sys_ni_syscall,sys_ni_syscall)
414 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 224 - reserved for setxattr */
415 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 225 - reserved for lsetxattr */
416 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 226 - reserved for fsetxattr */
417 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 227 - reserved for getxattr */
418 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 228 - reserved for lgetxattr */
419 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 229 - reserved for fgetxattr */
420 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 230 - reserved for listxattr */
421 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 231 - reserved for llistxattr */
422 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 232 - reserved for flistxattr */
423 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 233 - reserved for removexattr */
424 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 234 - reserved for lremovexattr */
425 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 235 - reserved for fremovexattr */
426 + .long SYSCALL(sys_setxattr,sys32_setxattr_wrapper)
427 + .long SYSCALL(sys_lsetxattr,sys32_lsetxattr_wrapper) /* 225 */
428 + .long SYSCALL(sys_fsetxattr,sys32_fsetxattr_wrapper)
429 + .long SYSCALL(sys_getxattr,sys32_getxattr_wrapper)
430 + .long SYSCALL(sys_lgetxattr,sys32_lgetxattr_wrapper)
431 + .long SYSCALL(sys_fgetxattr,sys32_fgetxattr_wrapper)
432 + .long SYSCALL(sys_listxattr,sys32_listxattr_wrapper) /* 230 */
433 + .long SYSCALL(sys_llistxattr,sys32_llistxattr_wrapper)
434 + .long SYSCALL(sys_flistxattr,sys32_flistxattr_wrapper)
435 + .long SYSCALL(sys_removexattr,sys32_removexattr_wrapper)
436 + .long SYSCALL(sys_lremovexattr,sys32_lremovexattr_wrapper)
437 + .long SYSCALL(sys_fremovexattr,sys32_fremovexattr_wrapper)/* 235 */
438 .long SYSCALL(sys_gettid,sys_gettid)
439 .long SYSCALL(sys_tkill,sys_tkill)
441 Index: linux-2.4.24-vanilla/arch/s390x/kernel/wrapper32.S
442 ===================================================================
443 --- linux-2.4.24-vanilla.orig/arch/s390x/kernel/wrapper32.S 2004-01-10 17:05:00.000000000 +0300
444 +++ linux-2.4.24-vanilla/arch/s390x/kernel/wrapper32.S 2004-01-10 17:20:28.000000000 +0300
445 @@ -1098,6 +1098,98 @@
447 jg sys32_fstat64 # branch to system call
449 + .globl sys32_setxattr_wrapper
450 +sys32_setxattr_wrapper:
451 + llgtr %r2,%r2 # char *
452 + llgtr %r3,%r3 # char *
453 + llgtr %r4,%r4 # void *
454 + llgfr %r5,%r5 # size_t
458 + .globl sys32_lsetxattr_wrapper
459 +sys32_lsetxattr_wrapper:
460 + llgtr %r2,%r2 # char *
461 + llgtr %r3,%r3 # char *
462 + llgtr %r4,%r4 # void *
463 + llgfr %r5,%r5 # size_t
467 + .globl sys32_fsetxattr_wrapper
468 +sys32_fsetxattr_wrapper:
470 + llgtr %r3,%r3 # char *
471 + llgtr %r4,%r4 # void *
472 + llgfr %r5,%r5 # size_t
476 + .globl sys32_getxattr_wrapper
477 +sys32_getxattr_wrapper:
478 + llgtr %r2,%r2 # char *
479 + llgtr %r3,%r3 # char *
480 + llgtr %r4,%r4 # void *
481 + llgfr %r5,%r5 # size_t
484 + .globl sys32_lgetxattr_wrapper
485 +sys32_lgetxattr_wrapper:
486 + llgtr %r2,%r2 # char *
487 + llgtr %r3,%r3 # char *
488 + llgtr %r4,%r4 # void *
489 + llgfr %r5,%r5 # size_t
492 + .globl sys32_fgetxattr_wrapper
493 +sys32_fgetxattr_wrapper:
495 + llgtr %r3,%r3 # char *
496 + llgtr %r4,%r4 # void *
497 + llgfr %r5,%r5 # size_t
500 + .globl sys32_listxattr_wrapper
501 +sys32_listxattr_wrapper:
502 + llgtr %r2,%r2 # char *
503 + llgtr %r3,%r3 # char *
504 + llgfr %r4,%r4 # size_t
507 + .globl sys32_llistxattr_wrapper
508 +sys32_llistxattr_wrapper:
509 + llgtr %r2,%r2 # char *
510 + llgtr %r3,%r3 # char *
511 + llgfr %r4,%r4 # size_t
514 + .globl sys32_flistxattr_wrapper
515 +sys32_flistxattr_wrapper:
517 + llgtr %r3,%r3 # char *
518 + llgfr %r4,%r4 # size_t
521 + .globl sys32_removexattr_wrapper
522 +sys32_removexattr_wrapper:
523 + llgtr %r2,%r2 # char *
524 + llgtr %r3,%r3 # char *
527 + .globl sys32_lremovexattr_wrapper
528 +sys32_lremovexattr_wrapper:
529 + llgtr %r2,%r2 # char *
530 + llgtr %r3,%r3 # char *
531 + jg sys_lremovexattr
533 + .globl sys32_fremovexattr_wrapper
534 +sys32_fremovexattr_wrapper:
536 + llgtr %r3,%r3 # char *
537 + jg sys_fremovexattr
541 .globl sys32_stime_wrapper
543 llgtr %r2,%r2 # int *
544 Index: linux-2.4.24-vanilla/arch/sparc64/defconfig
545 ===================================================================
546 --- linux-2.4.24-vanilla.orig/arch/sparc64/defconfig 2004-01-10 17:05:52.000000000 +0300
547 +++ linux-2.4.24-vanilla/arch/sparc64/defconfig 2004-01-10 17:20:28.000000000 +0300
550 # Automatically generated make config: don't edit
552 +CONFIG_EXT3_FS_XATTR=y
553 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
554 +# CONFIG_EXT3_FS_XATTR_USER is not set
555 +# CONFIG_EXT2_FS_XATTR is not set
556 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
557 +# CONFIG_EXT2_FS_XATTR_USER is not set
558 +# CONFIG_FS_MBCACHE is not set
561 # Code maturity level options
562 Index: linux-2.4.24-vanilla/fs/Config.in
563 ===================================================================
564 --- linux-2.4.24-vanilla.orig/fs/Config.in 2004-01-10 17:05:55.000000000 +0300
565 +++ linux-2.4.24-vanilla/fs/Config.in 2004-01-10 17:20:28.000000000 +0300
567 dep_tristate 'BFS file system support (EXPERIMENTAL)' CONFIG_BFS_FS $CONFIG_EXPERIMENTAL
569 tristate 'Ext3 journalling file system support' CONFIG_EXT3_FS
570 +dep_mbool ' Ext3 extended attributes' CONFIG_EXT3_FS_XATTR $CONFIG_EXT3_FS
571 +dep_bool ' Ext3 extended attribute block sharing' \
572 + CONFIG_EXT3_FS_XATTR_SHARING $CONFIG_EXT3_FS_XATTR
573 +dep_bool ' Ext3 extended user attributes' \
574 + CONFIG_EXT3_FS_XATTR_USER $CONFIG_EXT3_FS_XATTR
575 # CONFIG_JBD could be its own option (even modular), but until there are
576 # other users than ext3, we will simply make it be the same as CONFIG_EXT3_FS
577 # dep_tristate ' Journal Block Device support (JBD for ext3)' CONFIG_JBD $CONFIG_EXT3_FS
579 tristate 'ROM file system support' CONFIG_ROMFS_FS
581 tristate 'Second extended fs support' CONFIG_EXT2_FS
582 +dep_mbool ' Ext2 extended attributes' CONFIG_EXT2_FS_XATTR $CONFIG_EXT2_FS
583 +dep_bool ' Ext2 extended attribute block sharing' \
584 + CONFIG_EXT2_FS_XATTR_SHARING $CONFIG_EXT2_FS_XATTR
585 +dep_bool ' Ext2 extended user attributes' \
586 + CONFIG_EXT2_FS_XATTR_USER $CONFIG_EXT2_FS_XATTR
588 tristate 'System V/Xenix/V7/Coherent file system support' CONFIG_SYSV_FS
591 define_tristate CONFIG_ZISOFS_FS n
594 +# Meta block cache for Extended Attributes (ext2/ext3)
595 +#tristate 'Meta block cache' CONFIG_FS_MBCACHE
596 +define_tristate CONFIG_FS_MBCACHE y
598 mainmenu_option next_comment
599 comment 'Partition Types'
600 source fs/partitions/Config.in
601 Index: linux-2.4.24-vanilla/fs/Makefile
602 ===================================================================
603 --- linux-2.4.24-vanilla.orig/fs/Makefile 2004-01-10 17:11:48.000000000 +0300
604 +++ linux-2.4.24-vanilla/fs/Makefile 2004-01-10 17:20:28.000000000 +0300
607 obj-$(CONFIG_BINFMT_ELF) += binfmt_elf.o
609 +export-objs += mbcache.o
610 +obj-$(CONFIG_FS_MBCACHE) += mbcache.o
612 # persistent filesystems
613 obj-y += $(join $(subdir-y),$(subdir-y:%=/%.o))
615 Index: linux-2.4.24-vanilla/fs/ext2/Makefile
616 ===================================================================
617 --- linux-2.4.24-vanilla.orig/fs/ext2/Makefile 2001-10-11 19:05:18.000000000 +0400
618 +++ linux-2.4.24-vanilla/fs/ext2/Makefile 2004-01-10 17:20:28.000000000 +0300
620 ioctl.o namei.o super.o symlink.o
623 +export-objs += xattr.o
624 +obj-$(CONFIG_EXT2_FS_XATTR) += xattr.o
625 +obj-$(CONFIG_EXT2_FS_XATTR_USER) += xattr_user.o
627 include $(TOPDIR)/Rules.make
628 Index: linux-2.4.24-vanilla/fs/ext2/file.c
629 ===================================================================
630 --- linux-2.4.24-vanilla.orig/fs/ext2/file.c 2001-10-11 19:05:18.000000000 +0400
631 +++ linux-2.4.24-vanilla/fs/ext2/file.c 2004-01-10 17:20:28.000000000 +0300
634 #include <linux/fs.h>
635 #include <linux/ext2_fs.h>
636 +#include <linux/ext2_xattr.h>
637 #include <linux/sched.h>
642 struct inode_operations ext2_file_inode_operations = {
643 truncate: ext2_truncate,
644 + setxattr: ext2_setxattr,
645 + getxattr: ext2_getxattr,
646 + listxattr: ext2_listxattr,
647 + removexattr: ext2_removexattr,
649 Index: linux-2.4.24-vanilla/fs/ext2/ialloc.c
650 ===================================================================
651 --- linux-2.4.24-vanilla.orig/fs/ext2/ialloc.c 2004-01-10 17:04:42.000000000 +0300
652 +++ linux-2.4.24-vanilla/fs/ext2/ialloc.c 2004-01-10 17:20:28.000000000 +0300
654 #include <linux/config.h>
655 #include <linux/fs.h>
656 #include <linux/ext2_fs.h>
657 +#include <linux/ext2_xattr.h>
658 #include <linux/locks.h>
659 #include <linux/quotaops.h>
663 if (!is_bad_inode(inode)) {
664 /* Quota is already initialized in iput() */
665 + ext2_xattr_delete_inode(inode);
666 DQUOT_FREE_INODE(inode);
669 Index: linux-2.4.24-vanilla/fs/ext2/inode.c
670 ===================================================================
671 --- linux-2.4.24-vanilla.orig/fs/ext2/inode.c 2004-01-10 17:04:42.000000000 +0300
672 +++ linux-2.4.24-vanilla/fs/ext2/inode.c 2004-01-10 17:20:28.000000000 +0300
674 static int ext2_update_inode(struct inode * inode, int do_sync);
677 + * Test whether an inode is a fast symlink.
679 +static inline int ext2_inode_is_fast_symlink(struct inode *inode)
681 + int ea_blocks = inode->u.ext2_i.i_file_acl ?
682 + (inode->i_sb->s_blocksize >> 9) : 0;
684 + return (S_ISLNK(inode->i_mode) &&
685 + inode->i_blocks - ea_blocks == 0);
689 * Called at each iput()
691 void ext2_put_inode (struct inode * inode)
696 - if (is_bad_inode(inode) ||
697 - inode->i_ino == EXT2_ACL_IDX_INO ||
698 - inode->i_ino == EXT2_ACL_DATA_INO)
699 + if (is_bad_inode(inode))
701 inode->u.ext2_i.i_dtime = CURRENT_TIME;
702 mark_inode_dirty(inode);
704 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
705 S_ISLNK(inode->i_mode)))
707 + if (ext2_inode_is_fast_symlink(inode))
709 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
713 unsigned long offset;
714 struct ext2_group_desc * gdp;
716 - if ((inode->i_ino != EXT2_ROOT_INO && inode->i_ino != EXT2_ACL_IDX_INO &&
717 - inode->i_ino != EXT2_ACL_DATA_INO &&
718 + if ((inode->i_ino != EXT2_ROOT_INO &&
719 inode->i_ino < EXT2_FIRST_INO(inode->i_sb)) ||
720 inode->i_ino > le32_to_cpu(inode->i_sb->u.ext2_sb.s_es->s_inodes_count)) {
721 ext2_error (inode->i_sb, "ext2_read_inode",
722 @@ -989,10 +1000,7 @@
723 for (block = 0; block < EXT2_N_BLOCKS; block++)
724 inode->u.ext2_i.i_data[block] = raw_inode->i_block[block];
726 - if (inode->i_ino == EXT2_ACL_IDX_INO ||
727 - inode->i_ino == EXT2_ACL_DATA_INO)
728 - /* Nothing to do */ ;
729 - else if (S_ISREG(inode->i_mode)) {
730 + if (S_ISREG(inode->i_mode)) {
731 inode->i_op = &ext2_file_inode_operations;
732 inode->i_fop = &ext2_file_operations;
733 inode->i_mapping->a_ops = &ext2_aops;
734 @@ -1001,15 +1009,17 @@
735 inode->i_fop = &ext2_dir_operations;
736 inode->i_mapping->a_ops = &ext2_aops;
737 } else if (S_ISLNK(inode->i_mode)) {
738 - if (!inode->i_blocks)
739 + if (ext2_inode_is_fast_symlink(inode))
740 inode->i_op = &ext2_fast_symlink_inode_operations;
742 - inode->i_op = &page_symlink_inode_operations;
743 + inode->i_op = &ext2_symlink_inode_operations;
744 inode->i_mapping->a_ops = &ext2_aops;
748 + inode->i_op = &ext2_special_inode_operations;
749 init_special_inode(inode, inode->i_mode,
750 le32_to_cpu(raw_inode->i_block[0]));
753 inode->i_attr_flags = 0;
754 ext2_set_inode_flags(inode);
755 Index: linux-2.4.24-vanilla/fs/ext2/namei.c
756 ===================================================================
757 --- linux-2.4.24-vanilla.orig/fs/ext2/namei.c 2001-10-04 09:57:36.000000000 +0400
758 +++ linux-2.4.24-vanilla/fs/ext2/namei.c 2004-01-10 17:20:28.000000000 +0300
761 #include <linux/fs.h>
762 #include <linux/ext2_fs.h>
763 +#include <linux/ext2_xattr.h>
764 #include <linux/pagemap.h>
769 if (l > sizeof (inode->u.ext2_i.i_data)) {
771 - inode->i_op = &page_symlink_inode_operations;
772 + inode->i_op = &ext2_symlink_inode_operations;
773 inode->i_mapping->a_ops = &ext2_aops;
774 err = block_symlink(inode, symname, l);
780 + setxattr: ext2_setxattr,
781 + getxattr: ext2_getxattr,
782 + listxattr: ext2_listxattr,
783 + removexattr: ext2_removexattr,
786 +struct inode_operations ext2_special_inode_operations = {
787 + setxattr: ext2_setxattr,
788 + getxattr: ext2_getxattr,
789 + listxattr: ext2_listxattr,
790 + removexattr: ext2_removexattr,
792 Index: linux-2.4.24-vanilla/fs/ext2/super.c
793 ===================================================================
794 --- linux-2.4.24-vanilla.orig/fs/ext2/super.c 2003-05-16 05:29:12.000000000 +0400
795 +++ linux-2.4.24-vanilla/fs/ext2/super.c 2004-01-10 17:20:28.000000000 +0300
797 #include <linux/string.h>
798 #include <linux/fs.h>
799 #include <linux/ext2_fs.h>
800 +#include <linux/ext2_xattr.h>
801 #include <linux/slab.h>
802 #include <linux/init.h>
803 #include <linux/locks.h>
808 + ext2_xattr_put_super(sb);
809 if (!(sb->s_flags & MS_RDONLY)) {
810 struct ext2_super_block *es = EXT2_SB(sb)->s_es;
813 this_char = strtok (NULL, ",")) {
814 if ((value = strchr (this_char, '=')) != NULL)
816 +#ifdef CONFIG_EXT2_FS_XATTR_USER
817 + if (!strcmp (this_char, "user_xattr"))
818 + set_opt (*mount_options, XATTR_USER);
819 + else if (!strcmp (this_char, "nouser_xattr"))
820 + clear_opt (*mount_options, XATTR_USER);
823 if (!strcmp (this_char, "bsddf"))
824 clear_opt (*mount_options, MINIX_DF);
825 else if (!strcmp (this_char, "nouid32")) {
827 blocksize = BLOCK_SIZE;
829 sb->u.ext2_sb.s_mount_opt = 0;
830 +#ifdef CONFIG_EXT2_FS_XATTR_USER
831 + /* set_opt (sb->u.ext2_sb.s_mount_opt, XATTR_USER); */
833 if (!parse_options ((char *) data, &sb_block, &resuid, &resgid,
834 &sb->u.ext2_sb.s_mount_opt)) {
836 @@ -813,12 +825,27 @@
838 static int __init init_ext2_fs(void)
840 - return register_filesystem(&ext2_fs_type);
841 + int error = init_ext2_xattr();
844 + error = init_ext2_xattr_user();
847 + error = register_filesystem(&ext2_fs_type);
851 + exit_ext2_xattr_user();
857 static void __exit exit_ext2_fs(void)
859 unregister_filesystem(&ext2_fs_type);
860 + exit_ext2_xattr_user();
865 Index: linux-2.4.24-vanilla/fs/ext2/symlink.c
866 ===================================================================
867 --- linux-2.4.24-vanilla.orig/fs/ext2/symlink.c 2000-09-28 00:41:33.000000000 +0400
868 +++ linux-2.4.24-vanilla/fs/ext2/symlink.c 2004-01-10 17:20:28.000000000 +0300
871 #include <linux/fs.h>
872 #include <linux/ext2_fs.h>
873 +#include <linux/ext2_xattr.h>
875 static int ext2_readlink(struct dentry *dentry, char *buffer, int buflen)
878 return vfs_follow_link(nd, s);
881 +struct inode_operations ext2_symlink_inode_operations = {
882 + readlink: page_readlink,
883 + follow_link: page_follow_link,
884 + setxattr: ext2_setxattr,
885 + getxattr: ext2_getxattr,
886 + listxattr: ext2_listxattr,
887 + removexattr: ext2_removexattr,
890 struct inode_operations ext2_fast_symlink_inode_operations = {
891 readlink: ext2_readlink,
892 follow_link: ext2_follow_link,
893 + setxattr: ext2_setxattr,
894 + getxattr: ext2_getxattr,
895 + listxattr: ext2_listxattr,
896 + removexattr: ext2_removexattr,
898 Index: linux-2.4.24-vanilla/fs/ext2/xattr.c
899 ===================================================================
900 --- linux-2.4.24-vanilla.orig/fs/ext2/xattr.c 2003-01-30 13:24:37.000000000 +0300
901 +++ linux-2.4.24-vanilla/fs/ext2/xattr.c 2004-01-10 17:20:28.000000000 +0300
904 + * linux/fs/ext2/xattr.c
906 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
908 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
909 + * Extended attributes for symlinks and special files added per
910 + * suggestion of Luka Renko <luka.renko@hermes.si>.
914 + * Extended attributes are stored on disk blocks allocated outside of
915 + * any inode. The i_file_acl field is then made to point to this allocated
916 + * block. If all extended attributes of an inode are identical, these
917 + * inodes may share the same extended attribute block. Such situations
918 + * are automatically detected by keeping a cache of recent attribute block
919 + * numbers and hashes over the block's contents in memory.
922 + * Extended attribute block layout:
924 + * +------------------+
927 + * | entry 2 | | growing downwards
929 + * | four null bytes |
932 + * | value 3 | | growing upwards
934 + * +------------------+
936 + * The block header is followed by multiple entry descriptors. These entry
937 + * descriptors are variable in size, and alligned to EXT2_XATTR_PAD
938 + * byte boundaries. The entry descriptors are sorted by attribute name,
939 + * so that two extended attribute blocks can be compared efficiently.
941 + * Attribute values are aligned to the end of the block, stored in
942 + * no specific order. They are also padded to EXT2_XATTR_PAD byte
943 + * boundaries. No additional gaps are left between them.
947 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
948 + * the xattr inode operations are called, so we are guaranteed that only one
949 + * processes accesses extended attributes of an inode at any time.
951 + * For writing we also grab the ext2_xattr_sem semaphore. This ensures that
952 + * only a single process is modifying an extended attribute block, even
953 + * if the block is shared among inodes.
955 + * Note for porting to 2.5
956 + * -----------------------
957 + * The BKL will no longer be held in the xattr inode operations.
960 +#include <linux/module.h>
961 +#include <linux/locks.h>
962 +#include <linux/slab.h>
963 +#include <linux/fs.h>
964 +#include <linux/ext2_fs.h>
965 +#include <linux/ext2_xattr.h>
966 +#include <linux/mbcache.h>
967 +#include <linux/quotaops.h>
968 +#include <asm/semaphore.h>
969 +#include <linux/compatmac.h>
971 +/* These symbols may be needed by a module. */
972 +EXPORT_SYMBOL(ext2_xattr_register);
973 +EXPORT_SYMBOL(ext2_xattr_unregister);
974 +EXPORT_SYMBOL(ext2_xattr_get);
975 +EXPORT_SYMBOL(ext2_xattr_list);
976 +EXPORT_SYMBOL(ext2_xattr_set);
978 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
979 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
982 +#define HDR(bh) ((struct ext2_xattr_header *)((bh)->b_data))
983 +#define ENTRY(ptr) ((struct ext2_xattr_entry *)(ptr))
984 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
985 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
987 +#ifdef EXT2_XATTR_DEBUG
988 +# define ea_idebug(inode, f...) do { \
989 + printk(KERN_DEBUG "inode %s:%ld: ", \
990 + kdevname(inode->i_dev), inode->i_ino); \
994 +# define ea_bdebug(bh, f...) do { \
995 + printk(KERN_DEBUG "block %s:%ld: ", \
996 + kdevname(bh->b_dev), bh->b_blocknr); \
1001 +# define ea_idebug(f...)
1002 +# define ea_bdebug(f...)
1005 +static int ext2_xattr_set2(struct inode *, struct buffer_head *,
1006 + struct ext2_xattr_header *);
1008 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
1010 +static int ext2_xattr_cache_insert(struct buffer_head *);
1011 +static struct buffer_head *ext2_xattr_cache_find(struct inode *,
1012 + struct ext2_xattr_header *);
1013 +static void ext2_xattr_cache_remove(struct buffer_head *);
1014 +static void ext2_xattr_rehash(struct ext2_xattr_header *,
1015 + struct ext2_xattr_entry *);
1017 +static struct mb_cache *ext2_xattr_cache;
1020 +# define ext2_xattr_cache_insert(bh) 0
1021 +# define ext2_xattr_cache_find(inode, header) NULL
1022 +# define ext2_xattr_cache_remove(bh) while(0) {}
1023 +# define ext2_xattr_rehash(header, entry) while(0) {}
1027 + * If a file system does not share extended attributes among inodes,
1028 + * we should not need the ext2_xattr_sem semaphore. However, the
1029 + * filesystem may still contain shared blocks, so we always take
1033 +DECLARE_MUTEX(ext2_xattr_sem);
1036 +ext2_xattr_new_block(struct inode *inode, int * errp, int force)
1038 + struct super_block *sb = inode->i_sb;
1039 + int goal = le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block) +
1040 + EXT2_I(inode)->i_block_group * EXT2_BLOCKS_PER_GROUP(sb);
1042 + /* How can we enforce the allocation? */
1043 + int block = ext2_new_block(inode, goal, 0, 0, errp);
1046 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
1052 +ext2_xattr_quota_alloc(struct inode *inode, int force)
1054 + /* How can we enforce the allocation? */
1056 + int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
1058 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
1060 + int error = DQUOT_ALLOC_BLOCK(inode, 1);
1068 +ext2_xattr_quota_free(struct inode *inode)
1070 + DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
1071 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
1075 +ext2_xattr_free_block(struct inode * inode, unsigned long block)
1077 + ext2_free_blocks(inode, block, 1);
1078 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
1082 +# define ext2_xattr_quota_free(inode) \
1083 + DQUOT_FREE_BLOCK(inode, 1)
1084 +# define ext2_xattr_free_block(inode, block) \
1085 + ext2_free_blocks(inode, block, 1)
1088 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
1090 +static inline struct buffer_head *
1091 +sb_bread(struct super_block *sb, int block)
1093 + return bread(sb->s_dev, block, sb->s_blocksize);
1096 +static inline struct buffer_head *
1097 +sb_getblk(struct super_block *sb, int block)
1099 + return getblk(sb->s_dev, block, sb->s_blocksize);
1104 +struct ext2_xattr_handler *ext2_xattr_handlers[EXT2_XATTR_INDEX_MAX];
1105 +rwlock_t ext2_handler_lock = RW_LOCK_UNLOCKED;
1108 +ext2_xattr_register(int name_index, struct ext2_xattr_handler *handler)
1110 + int error = -EINVAL;
1112 + if (name_index > 0 && name_index <= EXT2_XATTR_INDEX_MAX) {
1113 + write_lock(&ext2_handler_lock);
1114 + if (!ext2_xattr_handlers[name_index-1]) {
1115 + ext2_xattr_handlers[name_index-1] = handler;
1118 + write_unlock(&ext2_handler_lock);
1124 +ext2_xattr_unregister(int name_index, struct ext2_xattr_handler *handler)
1126 + if (name_index > 0 || name_index <= EXT2_XATTR_INDEX_MAX) {
1127 + write_lock(&ext2_handler_lock);
1128 + ext2_xattr_handlers[name_index-1] = NULL;
1129 + write_unlock(&ext2_handler_lock);
1133 +static inline const char *
1134 +strcmp_prefix(const char *a, const char *a_prefix)
1136 + while (*a_prefix && *a == *a_prefix) {
1140 + return *a_prefix ? NULL : a;
1144 + * Decode the extended attribute name, and translate it into
1145 + * the name_index and name suffix.
1147 +static struct ext2_xattr_handler *
1148 +ext2_xattr_resolve_name(const char **name)
1150 + struct ext2_xattr_handler *handler = NULL;
1155 + read_lock(&ext2_handler_lock);
1156 + for (i=0; i<EXT2_XATTR_INDEX_MAX; i++) {
1157 + if (ext2_xattr_handlers[i]) {
1158 + const char *n = strcmp_prefix(*name,
1159 + ext2_xattr_handlers[i]->prefix);
1161 + handler = ext2_xattr_handlers[i];
1167 + read_unlock(&ext2_handler_lock);
1171 +static inline struct ext2_xattr_handler *
1172 +ext2_xattr_handler(int name_index)
1174 + struct ext2_xattr_handler *handler = NULL;
1175 + if (name_index > 0 && name_index <= EXT2_XATTR_INDEX_MAX) {
1176 + read_lock(&ext2_handler_lock);
1177 + handler = ext2_xattr_handlers[name_index-1];
1178 + read_unlock(&ext2_handler_lock);
1184 + * Inode operation getxattr()
1186 + * dentry->d_inode->i_sem down
1187 + * BKL held [before 2.5.x]
1190 +ext2_getxattr(struct dentry *dentry, const char *name,
1191 + void *buffer, size_t size)
1193 + struct ext2_xattr_handler *handler;
1194 + struct inode *inode = dentry->d_inode;
1196 + handler = ext2_xattr_resolve_name(&name);
1199 + return handler->get(inode, name, buffer, size);
1203 + * Inode operation listxattr()
1205 + * dentry->d_inode->i_sem down
1206 + * BKL held [before 2.5.x]
1209 +ext2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1211 + return ext2_xattr_list(dentry->d_inode, buffer, size);
1215 + * Inode operation setxattr()
1217 + * dentry->d_inode->i_sem down
1218 + * BKL held [before 2.5.x]
1221 +ext2_setxattr(struct dentry *dentry, const char *name,
1222 + const void *value, size_t size, int flags)
1224 + struct ext2_xattr_handler *handler;
1225 + struct inode *inode = dentry->d_inode;
1228 + value = ""; /* empty EA, do not remove */
1229 + handler = ext2_xattr_resolve_name(&name);
1232 + return handler->set(inode, name, value, size, flags);
1236 + * Inode operation removexattr()
1238 + * dentry->d_inode->i_sem down
1239 + * BKL held [before 2.5.x]
1242 +ext2_removexattr(struct dentry *dentry, const char *name)
1244 + struct ext2_xattr_handler *handler;
1245 + struct inode *inode = dentry->d_inode;
1247 + handler = ext2_xattr_resolve_name(&name);
1250 + return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
1254 + * ext2_xattr_get()
1256 + * Copy an extended attribute into the buffer
1257 + * provided, or compute the buffer size required.
1258 + * Buffer is NULL to compute the size of the buffer required.
1260 + * Returns a negative error number on failure, or the number of bytes
1261 + * used / required on success.
1264 +ext2_xattr_get(struct inode *inode, int name_index, const char *name,
1265 + void *buffer, size_t buffer_size)
1267 + struct buffer_head *bh = NULL;
1268 + struct ext2_xattr_entry *entry;
1269 + unsigned int block, size;
1271 + int name_len, error;
1273 + ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
1274 + name_index, name, buffer, (long)buffer_size);
1278 + if (!EXT2_I(inode)->i_file_acl)
1280 + block = EXT2_I(inode)->i_file_acl;
1281 + ea_idebug(inode, "reading block %d", block);
1282 + bh = sb_bread(inode->i_sb, block);
1285 + ea_bdebug(bh, "b_count=%d, refcount=%d",
1286 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
1287 + end = bh->b_data + bh->b_size;
1288 + if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1289 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1290 +bad_block: ext2_error(inode->i_sb, "ext2_xattr_get",
1291 + "inode %ld: bad block %d", inode->i_ino, block);
1295 + /* find named attribute */
1296 + name_len = strlen(name);
1299 + if (name_len > 255)
1301 + entry = FIRST_ENTRY(bh);
1302 + while (!IS_LAST_ENTRY(entry)) {
1303 + struct ext2_xattr_entry *next =
1304 + EXT2_XATTR_NEXT(entry);
1305 + if ((char *)next >= end)
1307 + if (name_index == entry->e_name_index &&
1308 + name_len == entry->e_name_len &&
1309 + memcmp(name, entry->e_name, name_len) == 0)
1313 + /* Check the remaining name entries */
1314 + while (!IS_LAST_ENTRY(entry)) {
1315 + struct ext2_xattr_entry *next =
1316 + EXT2_XATTR_NEXT(entry);
1317 + if ((char *)next >= end)
1321 + if (ext2_xattr_cache_insert(bh))
1322 + ea_idebug(inode, "cache insert failed");
1326 + /* check the buffer size */
1327 + if (entry->e_value_block != 0)
1329 + size = le32_to_cpu(entry->e_value_size);
1330 + if (size > inode->i_sb->s_blocksize ||
1331 + le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
1334 + if (ext2_xattr_cache_insert(bh))
1335 + ea_idebug(inode, "cache insert failed");
1338 + if (size > buffer_size)
1340 + /* return value of attribute */
1341 + memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
1353 + * ext2_xattr_list()
1355 + * Copy a list of attribute names into the buffer
1356 + * provided, or compute the buffer size required.
1357 + * Buffer is NULL to compute the size of the buffer required.
1359 + * Returns a negative error number on failure, or the number of bytes
1360 + * used / required on success.
1363 +ext2_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
1365 + struct buffer_head *bh = NULL;
1366 + struct ext2_xattr_entry *entry;
1367 + unsigned int block, size = 0;
1371 + ea_idebug(inode, "buffer=%p, buffer_size=%ld",
1372 + buffer, (long)buffer_size);
1374 + if (!EXT2_I(inode)->i_file_acl)
1376 + block = EXT2_I(inode)->i_file_acl;
1377 + ea_idebug(inode, "reading block %d", block);
1378 + bh = sb_bread(inode->i_sb, block);
1381 + ea_bdebug(bh, "b_count=%d, refcount=%d",
1382 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
1383 + end = bh->b_data + bh->b_size;
1384 + if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1385 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1386 +bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
1387 + "inode %ld: bad block %d", inode->i_ino, block);
1391 + /* compute the size required for the list of attribute names */
1392 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
1393 + entry = EXT2_XATTR_NEXT(entry)) {
1394 + struct ext2_xattr_handler *handler;
1395 + struct ext2_xattr_entry *next =
1396 + EXT2_XATTR_NEXT(entry);
1397 + if ((char *)next >= end)
1400 + handler = ext2_xattr_handler(entry->e_name_index);
1402 + size += handler->list(NULL, inode, entry->e_name,
1403 + entry->e_name_len);
1406 + if (ext2_xattr_cache_insert(bh))
1407 + ea_idebug(inode, "cache insert failed");
1413 + if (size > buffer_size)
1417 + /* list the attribute names */
1419 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
1420 + entry = EXT2_XATTR_NEXT(entry)) {
1421 + struct ext2_xattr_handler *handler;
1423 + handler = ext2_xattr_handler(entry->e_name_index);
1425 + buf += handler->list(buf, inode, entry->e_name,
1426 + entry->e_name_len);
1437 + * If the EXT2_FEATURE_COMPAT_EXT_ATTR feature of this file system is
1438 + * not set, set it.
1440 +static void ext2_xattr_update_super_block(struct super_block *sb)
1442 + if (EXT2_HAS_COMPAT_FEATURE(sb, EXT2_FEATURE_COMPAT_EXT_ATTR))
1446 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
1447 + EXT2_SB(sb)->s_feature_compat |= EXT2_FEATURE_COMPAT_EXT_ATTR;
1449 + EXT2_SB(sb)->s_es->s_feature_compat |=
1450 + cpu_to_le32(EXT2_FEATURE_COMPAT_EXT_ATTR);
1452 + mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
1457 + * ext2_xattr_set()
1459 + * Create, replace or remove an extended attribute for this inode. Buffer
1460 + * is NULL to remove an existing extended attribute, and non-NULL to
1461 + * either replace an existing extended attribute, or create a new extended
1462 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
1463 + * specify that an extended attribute must exist and must not exist
1464 + * previous to the call, respectively.
1466 + * Returns 0, or a negative error number on failure.
1469 +ext2_xattr_set(struct inode *inode, int name_index, const char *name,
1470 + const void *value, size_t value_len, int flags)
1472 + struct super_block *sb = inode->i_sb;
1473 + struct buffer_head *bh = NULL;
1474 + struct ext2_xattr_header *header = NULL;
1475 + struct ext2_xattr_entry *here, *last;
1476 + unsigned int name_len;
1477 + int block = EXT2_I(inode)->i_file_acl;
1478 + int min_offs = sb->s_blocksize, not_found = 1, free, error;
1482 + * header -- Points either into bh, or to a temporarily
1483 + * allocated buffer.
1484 + * here -- The named entry found, or the place for inserting, within
1485 + * the block pointed to by header.
1486 + * last -- Points right after the last named entry within the block
1487 + * pointed to by header.
1488 + * min_offs -- The offset of the first value (values are aligned
1489 + * towards the end of the block).
1490 + * end -- Points right after the block pointed to by header.
1493 + ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
1494 + name_index, name, value, (long)value_len);
1496 + if (IS_RDONLY(inode))
1498 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1500 + if (value == NULL)
1504 + name_len = strlen(name);
1505 + if (name_len > 255 || value_len > sb->s_blocksize)
1507 + down(&ext2_xattr_sem);
1510 + /* The inode already has an extended attribute block. */
1512 + bh = sb_bread(sb, block);
1516 + ea_bdebug(bh, "b_count=%d, refcount=%d",
1517 + atomic_read(&(bh->b_count)),
1518 + le32_to_cpu(HDR(bh)->h_refcount));
1520 + end = bh->b_data + bh->b_size;
1521 + if (header->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1522 + header->h_blocks != cpu_to_le32(1)) {
1523 +bad_block: ext2_error(sb, "ext2_xattr_set",
1524 + "inode %ld: bad block %d", inode->i_ino, block);
1528 + /* Find the named attribute. */
1529 + here = FIRST_ENTRY(bh);
1530 + while (!IS_LAST_ENTRY(here)) {
1531 + struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(here);
1532 + if ((char *)next >= end)
1534 + if (!here->e_value_block && here->e_value_size) {
1535 + int offs = le16_to_cpu(here->e_value_offs);
1536 + if (offs < min_offs)
1539 + not_found = name_index - here->e_name_index;
1541 + not_found = name_len - here->e_name_len;
1543 + not_found = memcmp(name, here->e_name,name_len);
1544 + if (not_found <= 0)
1549 + /* We still need to compute min_offs and last. */
1550 + while (!IS_LAST_ENTRY(last)) {
1551 + struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(last);
1552 + if ((char *)next >= end)
1554 + if (!last->e_value_block && last->e_value_size) {
1555 + int offs = le16_to_cpu(last->e_value_offs);
1556 + if (offs < min_offs)
1562 + /* Check whether we have enough space left. */
1563 + free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
1565 + /* We will use a new extended attribute block. */
1566 + free = sb->s_blocksize -
1567 + sizeof(struct ext2_xattr_header) - sizeof(__u32);
1568 + here = last = NULL; /* avoid gcc uninitialized warning. */
1572 + /* Request to remove a nonexistent attribute? */
1574 + if (flags & XATTR_REPLACE)
1577 + if (value == NULL)
1580 + free -= EXT2_XATTR_LEN(name_len);
1582 + /* Request to create an existing attribute? */
1584 + if (flags & XATTR_CREATE)
1586 + if (!here->e_value_block && here->e_value_size) {
1587 + unsigned int size = le32_to_cpu(here->e_value_size);
1589 + if (le16_to_cpu(here->e_value_offs) + size >
1590 + sb->s_blocksize || size > sb->s_blocksize)
1592 + free += EXT2_XATTR_SIZE(size);
1595 + free -= EXT2_XATTR_SIZE(value_len);
1600 + /* Here we know that we can set the new attribute. */
1603 + if (header->h_refcount == cpu_to_le32(1)) {
1604 + ea_bdebug(bh, "modifying in-place");
1605 + ext2_xattr_cache_remove(bh);
1609 + ea_bdebug(bh, "cloning");
1610 + header = kmalloc(bh->b_size, GFP_KERNEL);
1612 + if (header == NULL)
1614 + memcpy(header, HDR(bh), bh->b_size);
1615 + header->h_refcount = cpu_to_le32(1);
1616 + offset = (char *)header - bh->b_data;
1617 + here = ENTRY((char *)here + offset);
1618 + last = ENTRY((char *)last + offset);
1621 + /* Allocate a buffer where we construct the new block. */
1622 + header = kmalloc(sb->s_blocksize, GFP_KERNEL);
1624 + if (header == NULL)
1626 + memset(header, 0, sb->s_blocksize);
1627 + end = (char *)header + sb->s_blocksize;
1628 + header->h_magic = cpu_to_le32(EXT2_XATTR_MAGIC);
1629 + header->h_blocks = header->h_refcount = cpu_to_le32(1);
1630 + last = here = ENTRY(header+1);
1634 + /* Insert the new name. */
1635 + int size = EXT2_XATTR_LEN(name_len);
1636 + int rest = (char *)last - (char *)here;
1637 + memmove((char *)here + size, here, rest);
1638 + memset(here, 0, size);
1639 + here->e_name_index = name_index;
1640 + here->e_name_len = name_len;
1641 + memcpy(here->e_name, name, name_len);
1643 + /* Remove the old value. */
1644 + if (!here->e_value_block && here->e_value_size) {
1645 + char *first_val = (char *)header + min_offs;
1646 + int offs = le16_to_cpu(here->e_value_offs);
1647 + char *val = (char *)header + offs;
1648 + size_t size = EXT2_XATTR_SIZE(
1649 + le32_to_cpu(here->e_value_size));
1650 + memmove(first_val + size, first_val, val - first_val);
1651 + memset(first_val, 0, size);
1652 + here->e_value_offs = 0;
1655 + /* Adjust all value offsets. */
1656 + last = ENTRY(header+1);
1657 + while (!IS_LAST_ENTRY(last)) {
1658 + int o = le16_to_cpu(last->e_value_offs);
1659 + if (!last->e_value_block && o < offs)
1660 + last->e_value_offs =
1661 + cpu_to_le16(o + size);
1662 + last = EXT2_XATTR_NEXT(last);
1665 + if (value == NULL) {
1666 + /* Remove this attribute. */
1667 + if (EXT2_XATTR_NEXT(ENTRY(header+1)) == last) {
1668 + /* This block is now empty. */
1669 + error = ext2_xattr_set2(inode, bh, NULL);
1672 + /* Remove the old name. */
1673 + int size = EXT2_XATTR_LEN(name_len);
1674 + last = ENTRY((char *)last - size);
1675 + memmove(here, (char*)here + size,
1676 + (char*)last - (char*)here);
1677 + memset(last, 0, size);
1682 + if (value != NULL) {
1683 + /* Insert the new value. */
1684 + here->e_value_size = cpu_to_le32(value_len);
1686 + size_t size = EXT2_XATTR_SIZE(value_len);
1687 + char *val = (char *)header + min_offs - size;
1688 + here->e_value_offs =
1689 + cpu_to_le16((char *)val - (char *)header);
1690 + memset(val + size - EXT2_XATTR_PAD, 0,
1691 + EXT2_XATTR_PAD); /* Clear the pad bytes. */
1692 + memcpy(val, value, value_len);
1695 + ext2_xattr_rehash(header, here);
1697 + error = ext2_xattr_set2(inode, bh, header);
1701 + if (!(bh && header == HDR(bh)))
1703 + up(&ext2_xattr_sem);
1709 + * Second half of ext2_xattr_set(): Update the file system.
1712 +ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
1713 + struct ext2_xattr_header *header)
1715 + struct super_block *sb = inode->i_sb;
1716 + struct buffer_head *new_bh = NULL;
1720 + new_bh = ext2_xattr_cache_find(inode, header);
1723 + * We found an identical block in the cache.
1724 + * The old block will be released after updating
1727 + ea_bdebug(old_bh, "reusing block %ld",
1728 + new_bh->b_blocknr);
1731 + if (ext2_xattr_quota_alloc(inode, 1))
1734 + HDR(new_bh)->h_refcount = cpu_to_le32(
1735 + le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
1736 + ea_bdebug(new_bh, "refcount now=%d",
1737 + le32_to_cpu(HDR(new_bh)->h_refcount));
1738 + } else if (old_bh && header == HDR(old_bh)) {
1739 + /* Keep this block. */
1741 + (void)ext2_xattr_cache_insert(new_bh);
1743 + /* We need to allocate a new block */
1744 + int force = EXT2_I(inode)->i_file_acl != 0;
1745 + int block = ext2_xattr_new_block(inode, &error, force);
1748 + ea_idebug(inode, "creating block %d", block);
1750 + new_bh = sb_getblk(sb, block);
1752 + ext2_xattr_free_block(inode, block);
1756 + lock_buffer(new_bh);
1757 + memcpy(new_bh->b_data, header, new_bh->b_size);
1758 + mark_buffer_uptodate(new_bh, 1);
1759 + unlock_buffer(new_bh);
1760 + (void)ext2_xattr_cache_insert(new_bh);
1762 + ext2_xattr_update_super_block(sb);
1764 + mark_buffer_dirty(new_bh);
1765 + if (IS_SYNC(inode)) {
1766 + ll_rw_block(WRITE, 1, &new_bh);
1767 + wait_on_buffer(new_bh);
1769 + if (buffer_req(new_bh) && !buffer_uptodate(new_bh))
1774 + /* Update the inode. */
1775 + EXT2_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
1776 + inode->i_ctime = CURRENT_TIME;
1777 + if (IS_SYNC(inode)) {
1778 + error = ext2_sync_inode (inode);
1782 + mark_inode_dirty(inode);
1785 + if (old_bh && old_bh != new_bh) {
1787 + * If there was an old block, and we are not still using it,
1788 + * we now release the old block.
1790 + unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
1792 + if (refcount == 1) {
1793 + /* Free the old block. */
1794 + ea_bdebug(old_bh, "freeing");
1795 + ext2_xattr_free_block(inode, old_bh->b_blocknr);
1796 + mark_buffer_clean(old_bh);
1798 + /* Decrement the refcount only. */
1800 + HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
1801 + ext2_xattr_quota_free(inode);
1802 + mark_buffer_dirty(old_bh);
1803 + ea_bdebug(old_bh, "refcount now=%d", refcount);
1808 + if (old_bh != new_bh)
1815 + * ext2_xattr_delete_inode()
1817 + * Free extended attribute resources associated with this inode. This
1818 + * is called immediately before an inode is freed.
1821 +ext2_xattr_delete_inode(struct inode *inode)
1823 + struct buffer_head *bh;
1824 + unsigned int block = EXT2_I(inode)->i_file_acl;
1828 + down(&ext2_xattr_sem);
1830 + bh = sb_bread(inode->i_sb, block);
1832 + ext2_error(inode->i_sb, "ext2_xattr_delete_inode",
1833 + "inode %ld: block %d read error", inode->i_ino, block);
1836 + ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
1837 + if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1838 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1839 + ext2_error(inode->i_sb, "ext2_xattr_delete_inode",
1840 + "inode %ld: bad block %d", inode->i_ino, block);
1843 + ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
1844 + if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
1845 + ext2_xattr_cache_remove(bh);
1846 + ext2_xattr_free_block(inode, block);
1850 + HDR(bh)->h_refcount = cpu_to_le32(
1851 + le32_to_cpu(HDR(bh)->h_refcount) - 1);
1852 + mark_buffer_dirty(bh);
1853 + if (IS_SYNC(inode)) {
1854 + ll_rw_block(WRITE, 1, &bh);
1855 + wait_on_buffer(bh);
1857 + ext2_xattr_quota_free(inode);
1859 + EXT2_I(inode)->i_file_acl = 0;
1863 + up(&ext2_xattr_sem);
1867 + * ext2_xattr_put_super()
1869 + * This is called when a file system is unmounted.
1872 +ext2_xattr_put_super(struct super_block *sb)
1874 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
1875 + mb_cache_shrink(ext2_xattr_cache, sb->s_dev);
1879 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
1882 + * ext2_xattr_cache_insert()
1884 + * Create a new entry in the extended attribute cache, and insert
1885 + * it unless such an entry is already in the cache.
1887 + * Returns 0, or a negative error number on failure.
1890 +ext2_xattr_cache_insert(struct buffer_head *bh)
1892 + __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
1893 + struct mb_cache_entry *ce;
1896 + ce = mb_cache_entry_alloc(ext2_xattr_cache);
1899 + error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
1901 + mb_cache_entry_free(ce);
1902 + if (error == -EBUSY) {
1903 + ea_bdebug(bh, "already in cache (%d cache entries)",
1904 + atomic_read(&ext2_xattr_cache->c_entry_count));
1908 + ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
1909 + atomic_read(&ext2_xattr_cache->c_entry_count));
1910 + mb_cache_entry_release(ce);
1916 + * ext2_xattr_cmp()
1918 + * Compare two extended attribute blocks for equality.
1920 + * Returns 0 if the blocks are equal, 1 if they differ, and
1921 + * a negative error number on errors.
1924 +ext2_xattr_cmp(struct ext2_xattr_header *header1,
1925 + struct ext2_xattr_header *header2)
1927 + struct ext2_xattr_entry *entry1, *entry2;
1929 + entry1 = ENTRY(header1+1);
1930 + entry2 = ENTRY(header2+1);
1931 + while (!IS_LAST_ENTRY(entry1)) {
1932 + if (IS_LAST_ENTRY(entry2))
1934 + if (entry1->e_hash != entry2->e_hash ||
1935 + entry1->e_name_len != entry2->e_name_len ||
1936 + entry1->e_value_size != entry2->e_value_size ||
1937 + memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
1939 + if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
1941 + if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
1942 + (char *)header2 + le16_to_cpu(entry2->e_value_offs),
1943 + le32_to_cpu(entry1->e_value_size)))
1946 + entry1 = EXT2_XATTR_NEXT(entry1);
1947 + entry2 = EXT2_XATTR_NEXT(entry2);
1949 + if (!IS_LAST_ENTRY(entry2))
1955 + * ext2_xattr_cache_find()
1957 + * Find an identical extended attribute block.
1959 + * Returns a pointer to the block found, or NULL if such a block was
1960 + * not found or an error occurred.
1962 +static struct buffer_head *
1963 +ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header)
1965 + __u32 hash = le32_to_cpu(header->h_hash);
1966 + struct mb_cache_entry *ce;
1968 + if (!header->h_hash)
1969 + return NULL; /* never share */
1970 + ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
1971 + ce = mb_cache_entry_find_first(ext2_xattr_cache, 0, inode->i_dev, hash);
1973 + struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
1976 + ext2_error(inode->i_sb, "ext2_xattr_cache_find",
1977 + "inode %ld: block %ld read error",
1978 + inode->i_ino, ce->e_block);
1979 + } else if (le32_to_cpu(HDR(bh)->h_refcount) >
1980 + EXT2_XATTR_REFCOUNT_MAX) {
1981 + ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
1982 + le32_to_cpu(HDR(bh)->h_refcount),
1983 + EXT2_XATTR_REFCOUNT_MAX);
1984 + } else if (!ext2_xattr_cmp(header, HDR(bh))) {
1985 + ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
1986 + mb_cache_entry_release(ce);
1990 + ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
1996 + * ext2_xattr_cache_remove()
1998 + * Remove the cache entry of a block from the cache. Called when a
1999 + * block becomes invalid.
2002 +ext2_xattr_cache_remove(struct buffer_head *bh)
2004 + struct mb_cache_entry *ce;
2006 + ce = mb_cache_entry_get(ext2_xattr_cache, bh->b_dev, bh->b_blocknr);
2008 + ea_bdebug(bh, "removing (%d cache entries remaining)",
2009 + atomic_read(&ext2_xattr_cache->c_entry_count)-1);
2010 + mb_cache_entry_free(ce);
2012 + ea_bdebug(bh, "no cache entry");
2015 +#define NAME_HASH_SHIFT 5
2016 +#define VALUE_HASH_SHIFT 16
2019 + * ext2_xattr_hash_entry()
2021 + * Compute the hash of an extended attribute.
2023 +static inline void ext2_xattr_hash_entry(struct ext2_xattr_header *header,
2024 + struct ext2_xattr_entry *entry)
2027 + char *name = entry->e_name;
2030 + for (n=0; n < entry->e_name_len; n++) {
2031 + hash = (hash << NAME_HASH_SHIFT) ^
2032 + (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
2036 + if (entry->e_value_block == 0 && entry->e_value_size != 0) {
2037 + __u32 *value = (__u32 *)((char *)header +
2038 + le16_to_cpu(entry->e_value_offs));
2039 + for (n = (le32_to_cpu(entry->e_value_size) +
2040 + EXT2_XATTR_ROUND) >> EXT2_XATTR_PAD_BITS; n; n--) {
2041 + hash = (hash << VALUE_HASH_SHIFT) ^
2042 + (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
2043 + le32_to_cpu(*value++);
2046 + entry->e_hash = cpu_to_le32(hash);
2049 +#undef NAME_HASH_SHIFT
2050 +#undef VALUE_HASH_SHIFT
2052 +#define BLOCK_HASH_SHIFT 16
2055 + * ext2_xattr_rehash()
2057 + * Re-compute the extended attribute hash value after an entry has changed.
2059 +static void ext2_xattr_rehash(struct ext2_xattr_header *header,
2060 + struct ext2_xattr_entry *entry)
2062 + struct ext2_xattr_entry *here;
2065 + ext2_xattr_hash_entry(header, entry);
2066 + here = ENTRY(header+1);
2067 + while (!IS_LAST_ENTRY(here)) {
2068 + if (!here->e_hash) {
2069 + /* Block is not shared if an entry's hash value == 0 */
2073 + hash = (hash << BLOCK_HASH_SHIFT) ^
2074 + (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
2075 + le32_to_cpu(here->e_hash);
2076 + here = EXT2_XATTR_NEXT(here);
2078 + header->h_hash = cpu_to_le32(hash);
2081 +#undef BLOCK_HASH_SHIFT
2084 +init_ext2_xattr(void)
2086 + ext2_xattr_cache = mb_cache_create("ext2_xattr", NULL,
2087 + sizeof(struct mb_cache_entry) +
2088 + sizeof(struct mb_cache_entry_index), 1, 61);
2089 + if (!ext2_xattr_cache)
2096 +exit_ext2_xattr(void)
2098 + mb_cache_destroy(ext2_xattr_cache);
2101 +#else /* CONFIG_EXT2_FS_XATTR_SHARING */
2104 +init_ext2_xattr(void)
2110 +exit_ext2_xattr(void)
2114 +#endif /* CONFIG_EXT2_FS_XATTR_SHARING */
2115 Index: linux-2.4.24-vanilla/fs/ext2/xattr_user.c
2116 ===================================================================
2117 --- linux-2.4.24-vanilla.orig/fs/ext2/xattr_user.c 2003-01-30 13:24:37.000000000 +0300
2118 +++ linux-2.4.24-vanilla/fs/ext2/xattr_user.c 2004-01-10 17:20:28.000000000 +0300
2121 + * linux/fs/ext2/xattr_user.c
2122 + * Handler for extended user attributes.
2124 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
2127 +#include <linux/module.h>
2128 +#include <linux/string.h>
2129 +#include <linux/fs.h>
2130 +#include <linux/ext2_fs.h>
2131 +#include <linux/ext2_xattr.h>
2133 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
2134 +# include <linux/ext2_acl.h>
2137 +#define XATTR_USER_PREFIX "user."
2140 +ext2_xattr_user_list(char *list, struct inode *inode,
2141 + const char *name, int name_len)
2143 + const int prefix_len = sizeof(XATTR_USER_PREFIX)-1;
2145 + if (!test_opt(inode->i_sb, XATTR_USER))
2149 + memcpy(list, XATTR_USER_PREFIX, prefix_len);
2150 + memcpy(list+prefix_len, name, name_len);
2151 + list[prefix_len + name_len] = '\0';
2153 + return prefix_len + name_len + 1;
2157 +ext2_xattr_user_get(struct inode *inode, const char *name,
2158 + void *buffer, size_t size)
2162 + if (strcmp(name, "") == 0)
2164 + if (!test_opt(inode->i_sb, XATTR_USER))
2166 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
2167 + error = ext2_permission_locked(inode, MAY_READ);
2169 + error = permission(inode, MAY_READ);
2174 + return ext2_xattr_get(inode, EXT2_XATTR_INDEX_USER, name,
2179 +ext2_xattr_user_set(struct inode *inode, const char *name,
2180 + const void *value, size_t size, int flags)
2184 + if (strcmp(name, "") == 0)
2186 + if (!test_opt(inode->i_sb, XATTR_USER))
2188 + if ( !S_ISREG(inode->i_mode) &&
2189 + (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
2191 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
2192 + error = ext2_permission_locked(inode, MAY_WRITE);
2194 + error = permission(inode, MAY_WRITE);
2199 + return ext2_xattr_set(inode, EXT2_XATTR_INDEX_USER, name,
2200 + value, size, flags);
2203 +struct ext2_xattr_handler ext2_xattr_user_handler = {
2204 + prefix: XATTR_USER_PREFIX,
2205 + list: ext2_xattr_user_list,
2206 + get: ext2_xattr_user_get,
2207 + set: ext2_xattr_user_set,
2211 +init_ext2_xattr_user(void)
2213 + return ext2_xattr_register(EXT2_XATTR_INDEX_USER,
2214 + &ext2_xattr_user_handler);
2218 +exit_ext2_xattr_user(void)
2220 + ext2_xattr_unregister(EXT2_XATTR_INDEX_USER,
2221 + &ext2_xattr_user_handler);
2223 Index: linux-2.4.24-vanilla/fs/ext3/Makefile
2224 ===================================================================
2225 --- linux-2.4.24-vanilla.orig/fs/ext3/Makefile 2004-01-10 17:11:50.000000000 +0300
2226 +++ linux-2.4.24-vanilla/fs/ext3/Makefile 2004-01-10 17:20:28.000000000 +0300
2229 -# Makefile for the linux ext2-filesystem routines.
2230 +# Makefile for the linux ext3-filesystem routines.
2232 # Note! Dependencies are done automagically by 'make dep', which also
2233 # removes any old dependencies. DON'T put your own dependencies here
2238 -export-objs := super.o inode.o
2239 +export-objs := ext3-exports.o
2241 obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
2242 - ioctl.o namei.o super.o symlink.o hash.o
2243 + ioctl.o namei.o super.o symlink.o hash.o ext3-exports.o
2244 obj-m := $(O_TARGET)
2246 +export-objs += xattr.o
2247 +obj-$(CONFIG_EXT3_FS_XATTR) += xattr.o
2248 +obj-$(CONFIG_EXT3_FS_XATTR_USER) += xattr_user.o
2250 include $(TOPDIR)/Rules.make
2251 Index: linux-2.4.24-vanilla/fs/ext3/file.c
2252 ===================================================================
2253 --- linux-2.4.24-vanilla.orig/fs/ext3/file.c 2004-01-10 17:11:50.000000000 +0300
2254 +++ linux-2.4.24-vanilla/fs/ext3/file.c 2004-01-10 17:20:28.000000000 +0300
2256 #include <linux/locks.h>
2257 #include <linux/jbd.h>
2258 #include <linux/ext3_fs.h>
2259 +#include <linux/ext3_xattr.h>
2260 #include <linux/ext3_jbd.h>
2261 #include <linux/smp_lock.h>
2264 struct inode_operations ext3_file_inode_operations = {
2265 truncate: ext3_truncate, /* BKL held */
2266 setattr: ext3_setattr, /* BKL held */
2267 + setxattr: ext3_setxattr, /* BKL held */
2268 + getxattr: ext3_getxattr, /* BKL held */
2269 + listxattr: ext3_listxattr, /* BKL held */
2270 + removexattr: ext3_removexattr, /* BKL held */
2273 Index: linux-2.4.24-vanilla/fs/ext3/ialloc.c
2274 ===================================================================
2275 --- linux-2.4.24-vanilla.orig/fs/ext3/ialloc.c 2004-01-10 17:04:42.000000000 +0300
2276 +++ linux-2.4.24-vanilla/fs/ext3/ialloc.c 2004-01-10 17:20:28.000000000 +0300
2278 #include <linux/jbd.h>
2279 #include <linux/ext3_fs.h>
2280 #include <linux/ext3_jbd.h>
2281 +#include <linux/ext3_xattr.h>
2282 #include <linux/stat.h>
2283 #include <linux/string.h>
2284 #include <linux/locks.h>
2286 * as writing the quota to disk may need the lock as well.
2289 + ext3_xattr_delete_inode(handle, inode);
2290 DQUOT_FREE_INODE(inode);
2293 Index: linux-2.4.24-vanilla/fs/ext3/inode.c
2294 ===================================================================
2295 --- linux-2.4.24-vanilla.orig/fs/ext3/inode.c 2004-01-10 17:05:05.000000000 +0300
2296 +++ linux-2.4.24-vanilla/fs/ext3/inode.c 2004-01-10 17:20:28.000000000 +0300
2299 #undef SEARCH_FROM_ZERO
2302 + * Test whether an inode is a fast symlink.
2304 +static inline int ext3_inode_is_fast_symlink(struct inode *inode)
2306 + int ea_blocks = inode->u.ext3_i.i_file_acl ?
2307 + (inode->i_sb->s_blocksize >> 9) : 0;
2309 + return (S_ISLNK(inode->i_mode) &&
2310 + inode->i_blocks - ea_blocks == 0);
2313 /* The ext3 forget function must perform a revoke if we are freeing data
2314 * which has been journaled. Metadata (eg. indirect blocks) must be
2315 * revoked in all cases.
2317 * still needs to be revoked.
2320 -static int ext3_forget(handle_t *handle, int is_metadata,
2321 +int ext3_forget(handle_t *handle, int is_metadata,
2322 struct inode *inode, struct buffer_head *bh,
2329 - if (is_bad_inode(inode) ||
2330 - inode->i_ino == EXT3_ACL_IDX_INO ||
2331 - inode->i_ino == EXT3_ACL_DATA_INO)
2332 + if (is_bad_inode(inode))
2336 @@ -1870,6 +1880,8 @@
2337 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
2338 S_ISLNK(inode->i_mode)))
2340 + if (ext3_inode_is_fast_symlink(inode))
2342 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2345 @@ -2017,8 +2029,6 @@
2346 struct ext3_group_desc * gdp;
2348 if ((inode->i_ino != EXT3_ROOT_INO &&
2349 - inode->i_ino != EXT3_ACL_IDX_INO &&
2350 - inode->i_ino != EXT3_ACL_DATA_INO &&
2351 inode->i_ino != EXT3_JOURNAL_INO &&
2352 inode->i_ino < EXT3_FIRST_INO(inode->i_sb)) ||
2353 inode->i_ino > le32_to_cpu(
2354 @@ -2159,10 +2169,7 @@
2355 inode->u.ext3_i.i_data[block] = iloc.raw_inode->i_block[block];
2356 INIT_LIST_HEAD(&inode->u.ext3_i.i_orphan);
2358 - if (inode->i_ino == EXT3_ACL_IDX_INO ||
2359 - inode->i_ino == EXT3_ACL_DATA_INO)
2360 - /* Nothing to do */ ;
2361 - else if (S_ISREG(inode->i_mode)) {
2362 + if (S_ISREG(inode->i_mode)) {
2363 inode->i_op = &ext3_file_inode_operations;
2364 inode->i_fop = &ext3_file_operations;
2365 inode->i_mapping->a_ops = &ext3_aops;
2366 @@ -2170,15 +2177,17 @@
2367 inode->i_op = &ext3_dir_inode_operations;
2368 inode->i_fop = &ext3_dir_operations;
2369 } else if (S_ISLNK(inode->i_mode)) {
2370 - if (!inode->i_blocks)
2371 + if (ext3_inode_is_fast_symlink(inode))
2372 inode->i_op = &ext3_fast_symlink_inode_operations;
2374 - inode->i_op = &page_symlink_inode_operations;
2375 + inode->i_op = &ext3_symlink_inode_operations;
2376 inode->i_mapping->a_ops = &ext3_aops;
2380 + inode->i_op = &ext3_special_inode_operations;
2381 init_special_inode(inode, inode->i_mode,
2382 le32_to_cpu(iloc.raw_inode->i_block[0]));
2385 ext3_set_inode_flags(inode);
2387 Index: linux-2.4.24-vanilla/fs/ext3/namei.c
2388 ===================================================================
2389 --- linux-2.4.24-vanilla.orig/fs/ext3/namei.c 2004-01-10 17:11:50.000000000 +0300
2390 +++ linux-2.4.24-vanilla/fs/ext3/namei.c 2004-01-10 17:20:28.000000000 +0300
2392 #include <linux/sched.h>
2393 #include <linux/ext3_fs.h>
2394 #include <linux/ext3_jbd.h>
2395 +#include <linux/ext3_xattr.h>
2396 #include <linux/fcntl.h>
2397 #include <linux/stat.h>
2398 #include <linux/string.h>
2399 @@ -1613,7 +1614,7 @@
2403 - inode = ext3_new_inode (handle, dir, S_IFDIR);
2404 + inode = ext3_new_inode (handle, dir, S_IFDIR | mode);
2405 err = PTR_ERR(inode);
2408 @@ -1621,7 +1622,6 @@
2409 inode->i_op = &ext3_dir_inode_operations;
2410 inode->i_fop = &ext3_dir_operations;
2411 inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
2412 - inode->i_blocks = 0;
2413 dir_block = ext3_bread (handle, inode, 0, 1, &err);
2415 inode->i_nlink--; /* is this nlink == 0? */
2416 @@ -1648,9 +1648,6 @@
2417 BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata");
2418 ext3_journal_dirty_metadata(handle, dir_block);
2420 - inode->i_mode = S_IFDIR | mode;
2421 - if (dir->i_mode & S_ISGID)
2422 - inode->i_mode |= S_ISGID;
2423 ext3_mark_inode_dirty(handle, inode);
2424 err = ext3_add_entry (handle, dentry, inode);
2426 @@ -2019,7 +2016,7 @@
2429 if (l > sizeof (EXT3_I(inode)->i_data)) {
2430 - inode->i_op = &page_symlink_inode_operations;
2431 + inode->i_op = &ext3_symlink_inode_operations;
2432 inode->i_mapping->a_ops = &ext3_aops;
2434 * block_symlink() calls back into ext3_prepare/commit_write.
2435 @@ -2244,4 +2241,16 @@
2436 rmdir: ext3_rmdir, /* BKL held */
2437 mknod: ext3_mknod, /* BKL held */
2438 rename: ext3_rename, /* BKL held */
2439 + setxattr: ext3_setxattr, /* BKL held */
2440 + getxattr: ext3_getxattr, /* BKL held */
2441 + listxattr: ext3_listxattr, /* BKL held */
2442 + removexattr: ext3_removexattr, /* BKL held */
2445 +struct inode_operations ext3_special_inode_operations = {
2446 + setxattr: ext3_setxattr, /* BKL held */
2447 + getxattr: ext3_getxattr, /* BKL held */
2448 + listxattr: ext3_listxattr, /* BKL held */
2449 + removexattr: ext3_removexattr, /* BKL held */
2452 Index: linux-2.4.24-vanilla/fs/ext3/super.c
2453 ===================================================================
2454 --- linux-2.4.24-vanilla.orig/fs/ext3/super.c 2004-01-10 17:11:50.000000000 +0300
2455 +++ linux-2.4.24-vanilla/fs/ext3/super.c 2004-01-10 17:20:28.000000000 +0300
2457 #include <linux/jbd.h>
2458 #include <linux/ext3_fs.h>
2459 #include <linux/ext3_jbd.h>
2460 +#include <linux/ext3_xattr.h>
2461 #include <linux/slab.h>
2462 #include <linux/init.h>
2463 #include <linux/locks.h>
2465 kdev_t j_dev = sbi->s_journal->j_dev;
2468 + ext3_xattr_put_super(sb);
2469 journal_destroy(sbi->s_journal);
2470 if (!(sb->s_flags & MS_RDONLY)) {
2471 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
2475 unsigned long *mount_options = &sbi->s_mount_opt;
2477 uid_t *resuid = &sbi->s_resuid;
2478 gid_t *resgid = &sbi->s_resgid;
2480 @@ -517,6 +520,13 @@
2481 this_char = strtok (NULL, ",")) {
2482 if ((value = strchr (this_char, '=')) != NULL)
2484 +#ifdef CONFIG_EXT3_FS_XATTR_USER
2485 + if (!strcmp (this_char, "user_xattr"))
2486 + set_opt (*mount_options, XATTR_USER);
2487 + else if (!strcmp (this_char, "nouser_xattr"))
2488 + clear_opt (*mount_options, XATTR_USER);
2491 if (!strcmp (this_char, "bsddf"))
2492 clear_opt (*mount_options, MINIX_DF);
2493 else if (!strcmp (this_char, "nouid32")) {
2494 @@ -934,6 +944,12 @@
2495 sbi->s_mount_opt = 0;
2496 sbi->s_resuid = EXT3_DEF_RESUID;
2497 sbi->s_resgid = EXT3_DEF_RESGID;
2499 + /* Default extended attribute flags */
2500 +#ifdef CONFIG_EXT3_FS_XATTR_USER
2501 + /* set_opt(sbi->s_mount_opt, XATTR_USER); */
2504 if (!parse_options ((char *) data, &sb_block, sbi, &journal_inum, 0)) {
2507 @@ -1822,22 +1838,35 @@
2509 static int __init init_ext3_fs(void)
2513 init_dquot_operations(&ext3_qops);
2514 old_sync_dquot = ext3_qops.sync_dquot;
2515 ext3_qops.sync_dquot = ext3_sync_dquot;
2517 - return register_filesystem(&ext3_fs_type);
2518 + error = init_ext3_xattr();
2521 + error = init_ext3_xattr_user();
2524 + error = register_filesystem(&ext3_fs_type);
2528 + exit_ext3_xattr_user();
2530 + exit_ext3_xattr();
2534 static void __exit exit_ext3_fs(void)
2536 unregister_filesystem(&ext3_fs_type);
2537 + exit_ext3_xattr_user();
2538 + exit_ext3_xattr();
2541 -EXPORT_SYMBOL(ext3_force_commit);
2542 -EXPORT_SYMBOL(ext3_bread);
2544 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
2545 MODULE_DESCRIPTION("Second Extended Filesystem with journaling extensions");
2546 MODULE_LICENSE("GPL");
2547 Index: linux-2.4.24-vanilla/fs/ext3/symlink.c
2548 ===================================================================
2549 --- linux-2.4.24-vanilla.orig/fs/ext3/symlink.c 2001-11-10 01:25:04.000000000 +0300
2550 +++ linux-2.4.24-vanilla/fs/ext3/symlink.c 2004-01-10 17:20:28.000000000 +0300
2552 #include <linux/fs.h>
2553 #include <linux/jbd.h>
2554 #include <linux/ext3_fs.h>
2555 +#include <linux/ext3_xattr.h>
2557 static int ext3_readlink(struct dentry *dentry, char *buffer, int buflen)
2560 return vfs_follow_link(nd, s);
2563 +struct inode_operations ext3_symlink_inode_operations = {
2564 + readlink: page_readlink, /* BKL not held. Don't need */
2565 + follow_link: page_follow_link, /* BKL not held. Don't need */
2566 + setxattr: ext3_setxattr, /* BKL held */
2567 + getxattr: ext3_getxattr, /* BKL held */
2568 + listxattr: ext3_listxattr, /* BKL held */
2569 + removexattr: ext3_removexattr, /* BKL held */
2572 struct inode_operations ext3_fast_symlink_inode_operations = {
2573 readlink: ext3_readlink, /* BKL not held. Don't need */
2574 follow_link: ext3_follow_link, /* BKL not held. Don't need */
2575 + setxattr: ext3_setxattr, /* BKL held */
2576 + getxattr: ext3_getxattr, /* BKL held */
2577 + listxattr: ext3_listxattr, /* BKL held */
2578 + removexattr: ext3_removexattr, /* BKL held */
2580 Index: linux-2.4.24-vanilla/fs/ext3/xattr.c
2581 ===================================================================
2582 --- linux-2.4.24-vanilla.orig/fs/ext3/xattr.c 2003-01-30 13:24:37.000000000 +0300
2583 +++ linux-2.4.24-vanilla/fs/ext3/xattr.c 2004-01-10 17:20:28.000000000 +0300
2586 + * linux/fs/ext3/xattr.c
2588 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
2590 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
2591 + * Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>.
2592 + * Extended attributes for symlinks and special files added per
2593 + * suggestion of Luka Renko <luka.renko@hermes.si>.
2597 + * Extended attributes are stored on disk blocks allocated outside of
2598 + * any inode. The i_file_acl field is then made to point to this allocated
2599 + * block. If all extended attributes of an inode are identical, these
2600 + * inodes may share the same extended attribute block. Such situations
2601 + * are automatically detected by keeping a cache of recent attribute block
2602 + * numbers and hashes over the block's contents in memory.
2605 + * Extended attribute block layout:
2607 + * +------------------+
2610 + * | entry 2 | | growing downwards
2612 + * | four null bytes |
2615 + * | value 3 | | growing upwards
2617 + * +------------------+
2619 + * The block header is followed by multiple entry descriptors. These entry
2620 + * descriptors are variable in size, and alligned to EXT3_XATTR_PAD
2621 + * byte boundaries. The entry descriptors are sorted by attribute name,
2622 + * so that two extended attribute blocks can be compared efficiently.
2624 + * Attribute values are aligned to the end of the block, stored in
2625 + * no specific order. They are also padded to EXT3_XATTR_PAD byte
2626 + * boundaries. No additional gaps are left between them.
2628 + * Locking strategy
2629 + * ----------------
2630 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
2631 + * the xattr inode operations are called, so we are guaranteed that only one
2632 + * processes accesses extended attributes of an inode at any time.
2634 + * For writing we also grab the ext3_xattr_sem semaphore. This ensures that
2635 + * only a single process is modifying an extended attribute block, even
2636 + * if the block is shared among inodes.
2638 + * Note for porting to 2.5
2639 + * -----------------------
2640 + * The BKL will no longer be held in the xattr inode operations.
2643 +#include <linux/module.h>
2644 +#include <linux/fs.h>
2645 +#include <linux/locks.h>
2646 +#include <linux/slab.h>
2647 +#include <linux/ext3_jbd.h>
2648 +#include <linux/ext3_fs.h>
2649 +#include <linux/ext3_xattr.h>
2650 +#include <linux/mbcache.h>
2651 +#include <linux/quotaops.h>
2652 +#include <asm/semaphore.h>
2653 +#include <linux/compatmac.h>
2655 +#define EXT3_EA_USER "user."
2657 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
2658 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
2661 +#define HDR(bh) ((struct ext3_xattr_header *)((bh)->b_data))
2662 +#define ENTRY(ptr) ((struct ext3_xattr_entry *)(ptr))
2663 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
2664 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
2666 +#ifdef EXT3_XATTR_DEBUG
2667 +# define ea_idebug(inode, f...) do { \
2668 + printk(KERN_DEBUG "inode %s:%ld: ", \
2669 + kdevname(inode->i_dev), inode->i_ino); \
2673 +# define ea_bdebug(bh, f...) do { \
2674 + printk(KERN_DEBUG "block %s:%ld: ", \
2675 + kdevname(bh->b_dev), bh->b_blocknr); \
2680 +# define ea_idebug(f...)
2681 +# define ea_bdebug(f...)
2684 +static int ext3_xattr_set2(handle_t *, struct inode *, struct buffer_head *,
2685 + struct ext3_xattr_header *);
2687 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
2689 +static int ext3_xattr_cache_insert(struct buffer_head *);
2690 +static struct buffer_head *ext3_xattr_cache_find(struct inode *,
2691 + struct ext3_xattr_header *);
2692 +static void ext3_xattr_cache_remove(struct buffer_head *);
2693 +static void ext3_xattr_rehash(struct ext3_xattr_header *,
2694 + struct ext3_xattr_entry *);
2696 +static struct mb_cache *ext3_xattr_cache;
2699 +# define ext3_xattr_cache_insert(bh) 0
2700 +# define ext3_xattr_cache_find(inode, header) NULL
2701 +# define ext3_xattr_cache_remove(bh) while(0) {}
2702 +# define ext3_xattr_rehash(header, entry) while(0) {}
2706 + * If a file system does not share extended attributes among inodes,
2707 + * we should not need the ext3_xattr_sem semaphore. However, the
2708 + * filesystem may still contain shared blocks, so we always take
2712 +DECLARE_MUTEX(ext3_xattr_sem);
2715 +ext3_xattr_new_block(handle_t *handle, struct inode *inode,
2716 + int * errp, int force)
2718 + struct super_block *sb = inode->i_sb;
2719 + int goal = le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block) +
2720 + EXT3_I(inode)->i_block_group * EXT3_BLOCKS_PER_GROUP(sb);
2722 + /* How can we enforce the allocation? */
2723 + int block = ext3_new_block(handle, inode, goal, 0, 0, errp);
2726 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
2732 +ext3_xattr_quota_alloc(struct inode *inode, int force)
2734 + /* How can we enforce the allocation? */
2736 + int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
2738 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
2740 + int error = DQUOT_ALLOC_BLOCK(inode, 1);
2748 +ext3_xattr_quota_free(struct inode *inode)
2750 + DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
2751 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
2755 +ext3_xattr_free_block(handle_t *handle, struct inode * inode,
2756 + unsigned long block)
2758 + ext3_free_blocks(handle, inode, block, 1);
2759 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
2763 +# define ext3_xattr_quota_free(inode) \
2764 + DQUOT_FREE_BLOCK(inode, 1)
2765 +# define ext3_xattr_free_block(handle, inode, block) \
2766 + ext3_free_blocks(handle, inode, block, 1)
2769 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
2771 +static inline struct buffer_head *
2772 +sb_bread(struct super_block *sb, int block)
2774 + return bread(sb->s_dev, block, sb->s_blocksize);
2777 +static inline struct buffer_head *
2778 +sb_getblk(struct super_block *sb, int block)
2780 + return getblk(sb->s_dev, block, sb->s_blocksize);
2785 +struct ext3_xattr_handler *ext3_xattr_handlers[EXT3_XATTR_INDEX_MAX];
2786 +rwlock_t ext3_handler_lock = RW_LOCK_UNLOCKED;
2789 +ext3_xattr_register(int name_index, struct ext3_xattr_handler *handler)
2791 + int error = -EINVAL;
2793 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
2794 + write_lock(&ext3_handler_lock);
2795 + if (!ext3_xattr_handlers[name_index-1]) {
2796 + ext3_xattr_handlers[name_index-1] = handler;
2799 + write_unlock(&ext3_handler_lock);
2805 +ext3_xattr_unregister(int name_index, struct ext3_xattr_handler *handler)
2807 + if (name_index > 0 || name_index <= EXT3_XATTR_INDEX_MAX) {
2808 + write_lock(&ext3_handler_lock);
2809 + ext3_xattr_handlers[name_index-1] = NULL;
2810 + write_unlock(&ext3_handler_lock);
2814 +static inline const char *
2815 +strcmp_prefix(const char *a, const char *a_prefix)
2817 + while (*a_prefix && *a == *a_prefix) {
2821 + return *a_prefix ? NULL : a;
2825 + * Decode the extended attribute name, and translate it into
2826 + * the name_index and name suffix.
2828 +static inline struct ext3_xattr_handler *
2829 +ext3_xattr_resolve_name(const char **name)
2831 + struct ext3_xattr_handler *handler = NULL;
2836 + read_lock(&ext3_handler_lock);
2837 + for (i=0; i<EXT3_XATTR_INDEX_MAX; i++) {
2838 + if (ext3_xattr_handlers[i]) {
2839 + const char *n = strcmp_prefix(*name,
2840 + ext3_xattr_handlers[i]->prefix);
2842 + handler = ext3_xattr_handlers[i];
2848 + read_unlock(&ext3_handler_lock);
2852 +static inline struct ext3_xattr_handler *
2853 +ext3_xattr_handler(int name_index)
2855 + struct ext3_xattr_handler *handler = NULL;
2856 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
2857 + read_lock(&ext3_handler_lock);
2858 + handler = ext3_xattr_handlers[name_index-1];
2859 + read_unlock(&ext3_handler_lock);
2865 + * Inode operation getxattr()
2867 + * dentry->d_inode->i_sem down
2868 + * BKL held [before 2.5.x]
2871 +ext3_getxattr(struct dentry *dentry, const char *name,
2872 + void *buffer, size_t size)
2874 + struct ext3_xattr_handler *handler;
2875 + struct inode *inode = dentry->d_inode;
2877 + handler = ext3_xattr_resolve_name(&name);
2880 + return handler->get(inode, name, buffer, size);
2884 + * Inode operation listxattr()
2886 + * dentry->d_inode->i_sem down
2887 + * BKL held [before 2.5.x]
2890 +ext3_listxattr(struct dentry *dentry, char *buffer, size_t size)
2892 + return ext3_xattr_list(dentry->d_inode, buffer, size);
2896 + * Inode operation setxattr()
2898 + * dentry->d_inode->i_sem down
2899 + * BKL held [before 2.5.x]
2902 +ext3_setxattr(struct dentry *dentry, const char *name,
2903 + const void *value, size_t size, int flags)
2905 + struct ext3_xattr_handler *handler;
2906 + struct inode *inode = dentry->d_inode;
2909 + value = ""; /* empty EA, do not remove */
2910 + handler = ext3_xattr_resolve_name(&name);
2913 + return handler->set(inode, name, value, size, flags);
2917 + * Inode operation removexattr()
2919 + * dentry->d_inode->i_sem down
2920 + * BKL held [before 2.5.x]
2923 +ext3_removexattr(struct dentry *dentry, const char *name)
2925 + struct ext3_xattr_handler *handler;
2926 + struct inode *inode = dentry->d_inode;
2928 + handler = ext3_xattr_resolve_name(&name);
2931 + return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
2935 + * ext3_xattr_get()
2937 + * Copy an extended attribute into the buffer
2938 + * provided, or compute the buffer size required.
2939 + * Buffer is NULL to compute the size of the buffer required.
2941 + * Returns a negative error number on failure, or the number of bytes
2942 + * used / required on success.
2945 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
2946 + void *buffer, size_t buffer_size)
2948 + struct buffer_head *bh = NULL;
2949 + struct ext3_xattr_entry *entry;
2950 + unsigned int block, size;
2952 + int name_len, error;
2954 + ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
2955 + name_index, name, buffer, (long)buffer_size);
2959 + if (!EXT3_I(inode)->i_file_acl)
2961 + block = EXT3_I(inode)->i_file_acl;
2962 + ea_idebug(inode, "reading block %d", block);
2963 + bh = sb_bread(inode->i_sb, block);
2966 + ea_bdebug(bh, "b_count=%d, refcount=%d",
2967 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
2968 + end = bh->b_data + bh->b_size;
2969 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
2970 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
2971 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_get",
2972 + "inode %ld: bad block %d", inode->i_ino, block);
2976 + /* find named attribute */
2977 + name_len = strlen(name);
2980 + if (name_len > 255)
2982 + entry = FIRST_ENTRY(bh);
2983 + while (!IS_LAST_ENTRY(entry)) {
2984 + struct ext3_xattr_entry *next =
2985 + EXT3_XATTR_NEXT(entry);
2986 + if ((char *)next >= end)
2988 + if (name_index == entry->e_name_index &&
2989 + name_len == entry->e_name_len &&
2990 + memcmp(name, entry->e_name, name_len) == 0)
2994 + /* Check the remaining name entries */
2995 + while (!IS_LAST_ENTRY(entry)) {
2996 + struct ext3_xattr_entry *next =
2997 + EXT3_XATTR_NEXT(entry);
2998 + if ((char *)next >= end)
3002 + if (ext3_xattr_cache_insert(bh))
3003 + ea_idebug(inode, "cache insert failed");
3007 + /* check the buffer size */
3008 + if (entry->e_value_block != 0)
3010 + size = le32_to_cpu(entry->e_value_size);
3011 + if (size > inode->i_sb->s_blocksize ||
3012 + le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
3015 + if (ext3_xattr_cache_insert(bh))
3016 + ea_idebug(inode, "cache insert failed");
3019 + if (size > buffer_size)
3021 + /* return value of attribute */
3022 + memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
3034 + * ext3_xattr_list()
3036 + * Copy a list of attribute names into the buffer
3037 + * provided, or compute the buffer size required.
3038 + * Buffer is NULL to compute the size of the buffer required.
3040 + * Returns a negative error number on failure, or the number of bytes
3041 + * used / required on success.
3044 +ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
3046 + struct buffer_head *bh = NULL;
3047 + struct ext3_xattr_entry *entry;
3048 + unsigned int block, size = 0;
3052 + ea_idebug(inode, "buffer=%p, buffer_size=%ld",
3053 + buffer, (long)buffer_size);
3055 + if (!EXT3_I(inode)->i_file_acl)
3057 + block = EXT3_I(inode)->i_file_acl;
3058 + ea_idebug(inode, "reading block %d", block);
3059 + bh = sb_bread(inode->i_sb, block);
3062 + ea_bdebug(bh, "b_count=%d, refcount=%d",
3063 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
3064 + end = bh->b_data + bh->b_size;
3065 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
3066 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
3067 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_list",
3068 + "inode %ld: bad block %d", inode->i_ino, block);
3072 + /* compute the size required for the list of attribute names */
3073 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
3074 + entry = EXT3_XATTR_NEXT(entry)) {
3075 + struct ext3_xattr_handler *handler;
3076 + struct ext3_xattr_entry *next =
3077 + EXT3_XATTR_NEXT(entry);
3078 + if ((char *)next >= end)
3081 + handler = ext3_xattr_handler(entry->e_name_index);
3083 + size += handler->list(NULL, inode, entry->e_name,
3084 + entry->e_name_len);
3087 + if (ext3_xattr_cache_insert(bh))
3088 + ea_idebug(inode, "cache insert failed");
3094 + if (size > buffer_size)
3098 + /* list the attribute names */
3100 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
3101 + entry = EXT3_XATTR_NEXT(entry)) {
3102 + struct ext3_xattr_handler *handler;
3104 + handler = ext3_xattr_handler(entry->e_name_index);
3106 + buf += handler->list(buf, inode, entry->e_name,
3107 + entry->e_name_len);
3118 + * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is
3119 + * not set, set it.
3121 +static void ext3_xattr_update_super_block(handle_t *handle,
3122 + struct super_block *sb)
3124 + if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR))
3128 + ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh);
3129 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
3130 + EXT3_SB(sb)->s_feature_compat |= EXT3_FEATURE_COMPAT_EXT_ATTR;
3132 + EXT3_SB(sb)->s_es->s_feature_compat |=
3133 + cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR);
3135 + ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
3140 + * ext3_xattr_set()
3142 + * Create, replace or remove an extended attribute for this inode. Buffer
3143 + * is NULL to remove an existing extended attribute, and non-NULL to
3144 + * either replace an existing extended attribute, or create a new extended
3145 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
3146 + * specify that an extended attribute must exist and must not exist
3147 + * previous to the call, respectively.
3149 + * Returns 0, or a negative error number on failure.
3152 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
3153 + const char *name, const void *value, size_t value_len, int flags)
3155 + struct super_block *sb = inode->i_sb;
3156 + struct buffer_head *bh = NULL;
3157 + struct ext3_xattr_header *header = NULL;
3158 + struct ext3_xattr_entry *here, *last;
3159 + unsigned int name_len;
3160 + int block = EXT3_I(inode)->i_file_acl;
3161 + int min_offs = sb->s_blocksize, not_found = 1, free, error;
3165 + * header -- Points either into bh, or to a temporarily
3166 + * allocated buffer.
3167 + * here -- The named entry found, or the place for inserting, within
3168 + * the block pointed to by header.
3169 + * last -- Points right after the last named entry within the block
3170 + * pointed to by header.
3171 + * min_offs -- The offset of the first value (values are aligned
3172 + * towards the end of the block).
3173 + * end -- Points right after the block pointed to by header.
3176 + ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
3177 + name_index, name, value, (long)value_len);
3179 + if (IS_RDONLY(inode))
3181 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
3183 + if (value == NULL)
3187 + name_len = strlen(name);
3188 + if (name_len > 255 || value_len > sb->s_blocksize)
3190 + down(&ext3_xattr_sem);
3193 + /* The inode already has an extended attribute block. */
3194 + bh = sb_bread(sb, block);
3198 + ea_bdebug(bh, "b_count=%d, refcount=%d",
3199 + atomic_read(&(bh->b_count)),
3200 + le32_to_cpu(HDR(bh)->h_refcount));
3202 + end = bh->b_data + bh->b_size;
3203 + if (header->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
3204 + header->h_blocks != cpu_to_le32(1)) {
3205 +bad_block: ext3_error(sb, "ext3_xattr_set",
3206 + "inode %ld: bad block %d", inode->i_ino, block);
3210 + /* Find the named attribute. */
3211 + here = FIRST_ENTRY(bh);
3212 + while (!IS_LAST_ENTRY(here)) {
3213 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(here);
3214 + if ((char *)next >= end)
3216 + if (!here->e_value_block && here->e_value_size) {
3217 + int offs = le16_to_cpu(here->e_value_offs);
3218 + if (offs < min_offs)
3221 + not_found = name_index - here->e_name_index;
3223 + not_found = name_len - here->e_name_len;
3225 + not_found = memcmp(name, here->e_name,name_len);
3226 + if (not_found <= 0)
3231 + /* We still need to compute min_offs and last. */
3232 + while (!IS_LAST_ENTRY(last)) {
3233 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
3234 + if ((char *)next >= end)
3236 + if (!last->e_value_block && last->e_value_size) {
3237 + int offs = le16_to_cpu(last->e_value_offs);
3238 + if (offs < min_offs)
3244 + /* Check whether we have enough space left. */
3245 + free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
3247 + /* We will use a new extended attribute block. */
3248 + free = sb->s_blocksize -
3249 + sizeof(struct ext3_xattr_header) - sizeof(__u32);
3250 + here = last = NULL; /* avoid gcc uninitialized warning. */
3254 + /* Request to remove a nonexistent attribute? */
3256 + if (flags & XATTR_REPLACE)
3259 + if (value == NULL)
3262 + free -= EXT3_XATTR_LEN(name_len);
3264 + /* Request to create an existing attribute? */
3266 + if (flags & XATTR_CREATE)
3268 + if (!here->e_value_block && here->e_value_size) {
3269 + unsigned int size = le32_to_cpu(here->e_value_size);
3271 + if (le16_to_cpu(here->e_value_offs) + size >
3272 + sb->s_blocksize || size > sb->s_blocksize)
3274 + free += EXT3_XATTR_SIZE(size);
3277 + free -= EXT3_XATTR_SIZE(value_len);
3282 + /* Here we know that we can set the new attribute. */
3285 + if (header->h_refcount == cpu_to_le32(1)) {
3286 + ea_bdebug(bh, "modifying in-place");
3287 + ext3_xattr_cache_remove(bh);
3288 + error = ext3_journal_get_write_access(handle, bh);
3294 + ea_bdebug(bh, "cloning");
3295 + header = kmalloc(bh->b_size, GFP_KERNEL);
3297 + if (header == NULL)
3299 + memcpy(header, HDR(bh), bh->b_size);
3300 + header->h_refcount = cpu_to_le32(1);
3301 + offset = (char *)header - bh->b_data;
3302 + here = ENTRY((char *)here + offset);
3303 + last = ENTRY((char *)last + offset);
3306 + /* Allocate a buffer where we construct the new block. */
3307 + header = kmalloc(sb->s_blocksize, GFP_KERNEL);
3309 + if (header == NULL)
3311 + memset(header, 0, sb->s_blocksize);
3312 + end = (char *)header + sb->s_blocksize;
3313 + header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC);
3314 + header->h_blocks = header->h_refcount = cpu_to_le32(1);
3315 + last = here = ENTRY(header+1);
3319 + /* Insert the new name. */
3320 + int size = EXT3_XATTR_LEN(name_len);
3321 + int rest = (char *)last - (char *)here;
3322 + memmove((char *)here + size, here, rest);
3323 + memset(here, 0, size);
3324 + here->e_name_index = name_index;
3325 + here->e_name_len = name_len;
3326 + memcpy(here->e_name, name, name_len);
3328 + /* Remove the old value. */
3329 + if (!here->e_value_block && here->e_value_size) {
3330 + char *first_val = (char *)header + min_offs;
3331 + int offs = le16_to_cpu(here->e_value_offs);
3332 + char *val = (char *)header + offs;
3333 + size_t size = EXT3_XATTR_SIZE(
3334 + le32_to_cpu(here->e_value_size));
3335 + memmove(first_val + size, first_val, val - first_val);
3336 + memset(first_val, 0, size);
3337 + here->e_value_offs = 0;
3340 + /* Adjust all value offsets. */
3341 + last = ENTRY(header+1);
3342 + while (!IS_LAST_ENTRY(last)) {
3343 + int o = le16_to_cpu(last->e_value_offs);
3344 + if (!last->e_value_block && o < offs)
3345 + last->e_value_offs =
3346 + cpu_to_le16(o + size);
3347 + last = EXT3_XATTR_NEXT(last);
3350 + if (value == NULL) {
3351 + /* Remove this attribute. */
3352 + if (EXT3_XATTR_NEXT(ENTRY(header+1)) == last) {
3353 + /* This block is now empty. */
3354 + error = ext3_xattr_set2(handle, inode, bh,NULL);
3357 + /* Remove the old name. */
3358 + int size = EXT3_XATTR_LEN(name_len);
3359 + last = ENTRY((char *)last - size);
3360 + memmove(here, (char*)here + size,
3361 + (char*)last - (char*)here);
3362 + memset(last, 0, size);
3367 + if (value != NULL) {
3368 + /* Insert the new value. */
3369 + here->e_value_size = cpu_to_le32(value_len);
3371 + size_t size = EXT3_XATTR_SIZE(value_len);
3372 + char *val = (char *)header + min_offs - size;
3373 + here->e_value_offs =
3374 + cpu_to_le16((char *)val - (char *)header);
3375 + memset(val + size - EXT3_XATTR_PAD, 0,
3376 + EXT3_XATTR_PAD); /* Clear the pad bytes. */
3377 + memcpy(val, value, value_len);
3380 + ext3_xattr_rehash(header, here);
3382 + error = ext3_xattr_set2(handle, inode, bh, header);
3386 + if (!(bh && header == HDR(bh)))
3388 + up(&ext3_xattr_sem);
3394 + * Second half of ext3_xattr_set(): Update the file system.
3397 +ext3_xattr_set2(handle_t *handle, struct inode *inode,
3398 + struct buffer_head *old_bh, struct ext3_xattr_header *header)
3400 + struct super_block *sb = inode->i_sb;
3401 + struct buffer_head *new_bh = NULL;
3405 + new_bh = ext3_xattr_cache_find(inode, header);
3408 + * We found an identical block in the cache.
3409 + * The old block will be released after updating
3412 + ea_bdebug(old_bh, "reusing block %ld",
3413 + new_bh->b_blocknr);
3416 + if (ext3_xattr_quota_alloc(inode, 1))
3419 + error = ext3_journal_get_write_access(handle, new_bh);
3422 + HDR(new_bh)->h_refcount = cpu_to_le32(
3423 + le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
3424 + ea_bdebug(new_bh, "refcount now=%d",
3425 + le32_to_cpu(HDR(new_bh)->h_refcount));
3426 + } else if (old_bh && header == HDR(old_bh)) {
3427 + /* Keep this block. */
3429 + (void)ext3_xattr_cache_insert(new_bh);
3431 + /* We need to allocate a new block */
3432 + int force = EXT3_I(inode)->i_file_acl != 0;
3433 + int block = ext3_xattr_new_block(handle, inode,
3437 + ea_idebug(inode, "creating block %d", block);
3439 + new_bh = sb_getblk(sb, block);
3441 +getblk_failed: ext3_xattr_free_block(handle, inode, block);
3445 + lock_buffer(new_bh);
3446 + error = ext3_journal_get_create_access(handle, new_bh);
3448 + unlock_buffer(new_bh);
3449 + goto getblk_failed;
3451 + memcpy(new_bh->b_data, header, new_bh->b_size);
3452 + mark_buffer_uptodate(new_bh, 1);
3453 + unlock_buffer(new_bh);
3454 + (void)ext3_xattr_cache_insert(new_bh);
3456 + ext3_xattr_update_super_block(handle, sb);
3458 + error = ext3_journal_dirty_metadata(handle, new_bh);
3463 + /* Update the inode. */
3464 + EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
3465 + inode->i_ctime = CURRENT_TIME;
3466 + ext3_mark_inode_dirty(handle, inode);
3467 + if (IS_SYNC(inode))
3468 + handle->h_sync = 1;
3471 + if (old_bh && old_bh != new_bh) {
3473 + * If there was an old block, and we are not still using it,
3474 + * we now release the old block.
3476 + unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
3478 + error = ext3_journal_get_write_access(handle, old_bh);
3481 + if (refcount == 1) {
3482 + /* Free the old block. */
3483 + ea_bdebug(old_bh, "freeing");
3484 + ext3_xattr_free_block(handle, inode, old_bh->b_blocknr);
3486 + /* ext3_forget() calls bforget() for us, but we
3487 + let our caller release old_bh, so we need to
3488 + duplicate the handle before. */
3490 + ext3_forget(handle, 1, inode, old_bh,old_bh->b_blocknr);
3492 + /* Decrement the refcount only. */
3494 + HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
3495 + ext3_xattr_quota_free(inode);
3496 + ext3_journal_dirty_metadata(handle, old_bh);
3497 + ea_bdebug(old_bh, "refcount now=%d", refcount);
3502 + if (old_bh != new_bh)
3509 + * ext3_xattr_delete_inode()
3511 + * Free extended attribute resources associated with this inode. This
3512 + * is called immediately before an inode is freed.
3515 +ext3_xattr_delete_inode(handle_t *handle, struct inode *inode)
3517 + struct buffer_head *bh;
3518 + unsigned int block = EXT3_I(inode)->i_file_acl;
3522 + down(&ext3_xattr_sem);
3524 + bh = sb_bread(inode->i_sb, block);
3526 + ext3_error(inode->i_sb, "ext3_xattr_delete_inode",
3527 + "inode %ld: block %d read error", inode->i_ino, block);
3530 + ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
3531 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
3532 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
3533 + ext3_error(inode->i_sb, "ext3_xattr_delete_inode",
3534 + "inode %ld: bad block %d", inode->i_ino, block);
3537 + ext3_journal_get_write_access(handle, bh);
3538 + ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
3539 + if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
3540 + ext3_xattr_cache_remove(bh);
3541 + ext3_xattr_free_block(handle, inode, block);
3542 + ext3_forget(handle, 1, inode, bh, block);
3545 + HDR(bh)->h_refcount = cpu_to_le32(
3546 + le32_to_cpu(HDR(bh)->h_refcount) - 1);
3547 + ext3_journal_dirty_metadata(handle, bh);
3548 + if (IS_SYNC(inode))
3549 + handle->h_sync = 1;
3550 + ext3_xattr_quota_free(inode);
3552 + EXT3_I(inode)->i_file_acl = 0;
3556 + up(&ext3_xattr_sem);
3560 + * ext3_xattr_put_super()
3562 + * This is called when a file system is unmounted.
3565 +ext3_xattr_put_super(struct super_block *sb)
3567 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
3568 + mb_cache_shrink(ext3_xattr_cache, sb->s_dev);
3572 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
3575 + * ext3_xattr_cache_insert()
3577 + * Create a new entry in the extended attribute cache, and insert
3578 + * it unless such an entry is already in the cache.
3580 + * Returns 0, or a negative error number on failure.
3583 +ext3_xattr_cache_insert(struct buffer_head *bh)
3585 + __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
3586 + struct mb_cache_entry *ce;
3589 + ce = mb_cache_entry_alloc(ext3_xattr_cache);
3592 + error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
3594 + mb_cache_entry_free(ce);
3595 + if (error == -EBUSY) {
3596 + ea_bdebug(bh, "already in cache (%d cache entries)",
3597 + atomic_read(&ext3_xattr_cache->c_entry_count));
3601 + ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
3602 + atomic_read(&ext3_xattr_cache->c_entry_count));
3603 + mb_cache_entry_release(ce);
3609 + * ext3_xattr_cmp()
3611 + * Compare two extended attribute blocks for equality.
3613 + * Returns 0 if the blocks are equal, 1 if they differ, and
3614 + * a negative error number on errors.
3617 +ext3_xattr_cmp(struct ext3_xattr_header *header1,
3618 + struct ext3_xattr_header *header2)
3620 + struct ext3_xattr_entry *entry1, *entry2;
3622 + entry1 = ENTRY(header1+1);
3623 + entry2 = ENTRY(header2+1);
3624 + while (!IS_LAST_ENTRY(entry1)) {
3625 + if (IS_LAST_ENTRY(entry2))
3627 + if (entry1->e_hash != entry2->e_hash ||
3628 + entry1->e_name_len != entry2->e_name_len ||
3629 + entry1->e_value_size != entry2->e_value_size ||
3630 + memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
3632 + if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
3634 + if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
3635 + (char *)header2 + le16_to_cpu(entry2->e_value_offs),
3636 + le32_to_cpu(entry1->e_value_size)))
3639 + entry1 = EXT3_XATTR_NEXT(entry1);
3640 + entry2 = EXT3_XATTR_NEXT(entry2);
3642 + if (!IS_LAST_ENTRY(entry2))
3648 + * ext3_xattr_cache_find()
3650 + * Find an identical extended attribute block.
3652 + * Returns a pointer to the block found, or NULL if such a block was
3653 + * not found or an error occurred.
3655 +static struct buffer_head *
3656 +ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header)
3658 + __u32 hash = le32_to_cpu(header->h_hash);
3659 + struct mb_cache_entry *ce;
3661 + if (!header->h_hash)
3662 + return NULL; /* never share */
3663 + ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
3664 + ce = mb_cache_entry_find_first(ext3_xattr_cache, 0, inode->i_dev, hash);
3666 + struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
3669 + ext3_error(inode->i_sb, "ext3_xattr_cache_find",
3670 + "inode %ld: block %ld read error",
3671 + inode->i_ino, ce->e_block);
3672 + } else if (le32_to_cpu(HDR(bh)->h_refcount) >
3673 + EXT3_XATTR_REFCOUNT_MAX) {
3674 + ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
3675 + le32_to_cpu(HDR(bh)->h_refcount),
3676 + EXT3_XATTR_REFCOUNT_MAX);
3677 + } else if (!ext3_xattr_cmp(header, HDR(bh))) {
3678 + ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
3679 + mb_cache_entry_release(ce);
3683 + ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
3689 + * ext3_xattr_cache_remove()
3691 + * Remove the cache entry of a block from the cache. Called when a
3692 + * block becomes invalid.
3695 +ext3_xattr_cache_remove(struct buffer_head *bh)
3697 + struct mb_cache_entry *ce;
3699 + ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_dev, bh->b_blocknr);
3701 + ea_bdebug(bh, "removing (%d cache entries remaining)",
3702 + atomic_read(&ext3_xattr_cache->c_entry_count)-1);
3703 + mb_cache_entry_free(ce);
3705 + ea_bdebug(bh, "no cache entry");
3708 +#define NAME_HASH_SHIFT 5
3709 +#define VALUE_HASH_SHIFT 16
3712 + * ext3_xattr_hash_entry()
3714 + * Compute the hash of an extended attribute.
3716 +static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
3717 + struct ext3_xattr_entry *entry)
3720 + char *name = entry->e_name;
3723 + for (n=0; n < entry->e_name_len; n++) {
3724 + hash = (hash << NAME_HASH_SHIFT) ^
3725 + (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
3729 + if (entry->e_value_block == 0 && entry->e_value_size != 0) {
3730 + __u32 *value = (__u32 *)((char *)header +
3731 + le16_to_cpu(entry->e_value_offs));
3732 + for (n = (le32_to_cpu(entry->e_value_size) +
3733 + EXT3_XATTR_ROUND) >> EXT3_XATTR_PAD_BITS; n; n--) {
3734 + hash = (hash << VALUE_HASH_SHIFT) ^
3735 + (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
3736 + le32_to_cpu(*value++);
3739 + entry->e_hash = cpu_to_le32(hash);
3742 +#undef NAME_HASH_SHIFT
3743 +#undef VALUE_HASH_SHIFT
3745 +#define BLOCK_HASH_SHIFT 16
3748 + * ext3_xattr_rehash()
3750 + * Re-compute the extended attribute hash value after an entry has changed.
3752 +static void ext3_xattr_rehash(struct ext3_xattr_header *header,
3753 + struct ext3_xattr_entry *entry)
3755 + struct ext3_xattr_entry *here;
3758 + ext3_xattr_hash_entry(header, entry);
3759 + here = ENTRY(header+1);
3760 + while (!IS_LAST_ENTRY(here)) {
3761 + if (!here->e_hash) {
3762 + /* Block is not shared if an entry's hash value == 0 */
3766 + hash = (hash << BLOCK_HASH_SHIFT) ^
3767 + (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
3768 + le32_to_cpu(here->e_hash);
3769 + here = EXT3_XATTR_NEXT(here);
3771 + header->h_hash = cpu_to_le32(hash);
3774 +#undef BLOCK_HASH_SHIFT
3777 +init_ext3_xattr(void)
3779 + ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL,
3780 + sizeof(struct mb_cache_entry) +
3781 + sizeof(struct mb_cache_entry_index), 1, 61);
3782 + if (!ext3_xattr_cache)
3789 +exit_ext3_xattr(void)
3791 + if (ext3_xattr_cache)
3792 + mb_cache_destroy(ext3_xattr_cache);
3793 + ext3_xattr_cache = NULL;
3796 +#else /* CONFIG_EXT3_FS_XATTR_SHARING */
3799 +init_ext3_xattr(void)
3805 +exit_ext3_xattr(void)
3809 +#endif /* CONFIG_EXT3_FS_XATTR_SHARING */
3810 Index: linux-2.4.24-vanilla/fs/ext3/xattr_user.c
3811 ===================================================================
3812 --- linux-2.4.24-vanilla.orig/fs/ext3/xattr_user.c 2003-01-30 13:24:37.000000000 +0300
3813 +++ linux-2.4.24-vanilla/fs/ext3/xattr_user.c 2004-01-10 17:20:28.000000000 +0300
3816 + * linux/fs/ext3/xattr_user.c
3817 + * Handler for extended user attributes.
3819 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
3822 +#include <linux/module.h>
3823 +#include <linux/string.h>
3824 +#include <linux/fs.h>
3825 +#include <linux/ext3_jbd.h>
3826 +#include <linux/ext3_fs.h>
3827 +#include <linux/ext3_xattr.h>
3829 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3830 +# include <linux/ext3_acl.h>
3833 +#define XATTR_USER_PREFIX "user."
3836 +ext3_xattr_user_list(char *list, struct inode *inode,
3837 + const char *name, int name_len)
3839 + const int prefix_len = sizeof(XATTR_USER_PREFIX)-1;
3841 + if (!test_opt(inode->i_sb, XATTR_USER))
3845 + memcpy(list, XATTR_USER_PREFIX, prefix_len);
3846 + memcpy(list+prefix_len, name, name_len);
3847 + list[prefix_len + name_len] = '\0';
3849 + return prefix_len + name_len + 1;
3853 +ext3_xattr_user_get(struct inode *inode, const char *name,
3854 + void *buffer, size_t size)
3858 + if (strcmp(name, "") == 0)
3860 + if (!test_opt(inode->i_sb, XATTR_USER))
3862 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3863 + error = ext3_permission_locked(inode, MAY_READ);
3865 + error = permission(inode, MAY_READ);
3870 + return ext3_xattr_get(inode, EXT3_XATTR_INDEX_USER, name,
3875 +ext3_xattr_user_set(struct inode *inode, const char *name,
3876 + const void *value, size_t size, int flags)
3881 + if (strcmp(name, "") == 0)
3883 + if (!test_opt(inode->i_sb, XATTR_USER))
3885 + if ( !S_ISREG(inode->i_mode) &&
3886 + (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
3888 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3889 + error = ext3_permission_locked(inode, MAY_WRITE);
3891 + error = permission(inode, MAY_WRITE);
3896 + handle = ext3_journal_start(inode, EXT3_XATTR_TRANS_BLOCKS);
3897 + if (IS_ERR(handle))
3898 + return PTR_ERR(handle);
3899 + error = ext3_xattr_set(handle, inode, EXT3_XATTR_INDEX_USER, name,
3900 + value, size, flags);
3901 + ext3_journal_stop(handle, inode);
3906 +struct ext3_xattr_handler ext3_xattr_user_handler = {
3907 + prefix: XATTR_USER_PREFIX,
3908 + list: ext3_xattr_user_list,
3909 + get: ext3_xattr_user_get,
3910 + set: ext3_xattr_user_set,
3914 +init_ext3_xattr_user(void)
3916 + return ext3_xattr_register(EXT3_XATTR_INDEX_USER,
3917 + &ext3_xattr_user_handler);
3921 +exit_ext3_xattr_user(void)
3923 + ext3_xattr_unregister(EXT3_XATTR_INDEX_USER,
3924 + &ext3_xattr_user_handler);
3926 Index: linux-2.4.24-vanilla/fs/ext3/ext3-exports.c
3927 ===================================================================
3928 --- linux-2.4.24-vanilla.orig/fs/ext3/ext3-exports.c 2003-01-30 13:24:37.000000000 +0300
3929 +++ linux-2.4.24-vanilla/fs/ext3/ext3-exports.c 2004-01-10 17:20:28.000000000 +0300
3931 +#include <linux/config.h>
3932 +#include <linux/module.h>
3933 +#include <linux/ext3_fs.h>
3934 +#include <linux/ext3_jbd.h>
3935 +#include <linux/ext3_xattr.h>
3937 +EXPORT_SYMBOL(ext3_force_commit);
3938 +EXPORT_SYMBOL(ext3_bread);
3939 +EXPORT_SYMBOL(ext3_xattr_register);
3940 +EXPORT_SYMBOL(ext3_xattr_unregister);
3941 +EXPORT_SYMBOL(ext3_xattr_get);
3942 +EXPORT_SYMBOL(ext3_xattr_list);
3943 +EXPORT_SYMBOL(ext3_xattr_set);
3944 Index: linux-2.4.24-vanilla/fs/jfs/jfs_xattr.h
3945 ===================================================================
3946 --- linux-2.4.24-vanilla.orig/fs/jfs/jfs_xattr.h 2003-05-16 05:29:12.000000000 +0400
3947 +++ linux-2.4.24-vanilla/fs/jfs/jfs_xattr.h 2004-01-10 17:20:28.000000000 +0300
3949 #define END_EALIST(ealist) \
3950 ((struct jfs_ea *) (((char *) (ealist)) + EALIST_SIZE(ealist)))
3952 -extern int __jfs_setxattr(struct inode *, const char *, void *, size_t, int);
3953 -extern int jfs_setxattr(struct dentry *, const char *, void *, size_t, int);
3954 +extern int __jfs_setxattr(struct inode *, const char *, const void *, size_t,
3956 +extern int jfs_setxattr(struct dentry *, const char *, const void *, size_t,
3958 extern ssize_t __jfs_getxattr(struct inode *, const char *, void *, size_t);
3959 extern ssize_t jfs_getxattr(struct dentry *, const char *, void *, size_t);
3960 extern ssize_t jfs_listxattr(struct dentry *, char *, size_t);
3961 Index: linux-2.4.24-vanilla/fs/jfs/xattr.c
3962 ===================================================================
3963 --- linux-2.4.24-vanilla.orig/fs/jfs/xattr.c 2004-01-10 17:05:55.000000000 +0300
3964 +++ linux-2.4.24-vanilla/fs/jfs/xattr.c 2004-01-10 17:20:28.000000000 +0300
3968 static int can_set_xattr(struct inode *inode, const char *name,
3969 - void *value, size_t value_len)
3970 + const void *value, size_t value_len)
3972 if (IS_RDONLY(inode))
3975 return permission(inode, MAY_WRITE);
3978 -int __jfs_setxattr(struct inode *inode, const char *name, void *value,
3979 +int __jfs_setxattr(struct inode *inode, const char *name, const void *value,
3980 size_t value_len, int flags)
3982 struct jfs_ea_list *ealist;
3987 -int jfs_setxattr(struct dentry *dentry, const char *name, void *value,
3988 +int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
3989 size_t value_len, int flags)
3991 if (value == NULL) { /* empty EA, do not remove */
3992 Index: linux-2.4.24-vanilla/fs/mbcache.c
3993 ===================================================================
3994 --- linux-2.4.24-vanilla.orig/fs/mbcache.c 2003-01-30 13:24:37.000000000 +0300
3995 +++ linux-2.4.24-vanilla/fs/mbcache.c 2004-01-10 17:20:28.000000000 +0300
3998 + * linux/fs/mbcache.c
3999 + * (C) 2001-2002 Andreas Gruenbacher, <a.gruenbacher@computer.org>
4003 + * Filesystem Meta Information Block Cache (mbcache)
4005 + * The mbcache caches blocks of block devices that need to be located
4006 + * by their device/block number, as well as by other criteria (such
4007 + * as the block's contents).
4009 + * There can only be one cache entry in a cache per device and block number.
4010 + * Additional indexes need not be unique in this sense. The number of
4011 + * additional indexes (=other criteria) can be hardwired at compile time
4012 + * or specified at cache create time.
4014 + * Each cache entry is of fixed size. An entry may be `valid' or `invalid'
4015 + * in the cache. A valid entry is in the main hash tables of the cache,
4016 + * and may also be in the lru list. An invalid entry is not in any hashes
4019 + * A valid cache entry is only in the lru list if no handles refer to it.
4020 + * Invalid cache entries will be freed when the last handle to the cache
4021 + * entry is released. Entries that cannot be freed immediately are put
4022 + * back on the lru list.
4025 +#include <linux/kernel.h>
4026 +#include <linux/module.h>
4028 +#include <linux/fs.h>
4029 +#include <linux/slab.h>
4030 +#include <linux/sched.h>
4031 +#include <linux/cache_def.h>
4032 +#include <linux/version.h>
4033 +#include <linux/init.h>
4034 +#include <linux/mbcache.h>
4037 +#ifdef MB_CACHE_DEBUG
4038 +# define mb_debug(f...) do { \
4039 + printk(KERN_DEBUG f); \
4042 +#define mb_assert(c) do { if (!(c)) \
4043 + printk(KERN_ERR "assertion " #c " failed\n"); \
4046 +# define mb_debug(f...) do { } while(0)
4047 +# define mb_assert(c) do { } while(0)
4049 +#define mb_error(f...) do { \
4050 + printk(KERN_ERR f); \
4054 +MODULE_AUTHOR("Andreas Gruenbacher <a.gruenbacher@computer.org>");
4055 +MODULE_DESCRIPTION("Meta block cache (for extended attributes)");
4056 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4057 +MODULE_LICENSE("GPL");
4060 +EXPORT_SYMBOL(mb_cache_create);
4061 +EXPORT_SYMBOL(mb_cache_shrink);
4062 +EXPORT_SYMBOL(mb_cache_destroy);
4063 +EXPORT_SYMBOL(mb_cache_entry_alloc);
4064 +EXPORT_SYMBOL(mb_cache_entry_insert);
4065 +EXPORT_SYMBOL(mb_cache_entry_release);
4066 +EXPORT_SYMBOL(mb_cache_entry_takeout);
4067 +EXPORT_SYMBOL(mb_cache_entry_free);
4068 +EXPORT_SYMBOL(mb_cache_entry_dup);
4069 +EXPORT_SYMBOL(mb_cache_entry_get);
4070 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
4071 +EXPORT_SYMBOL(mb_cache_entry_find_first);
4072 +EXPORT_SYMBOL(mb_cache_entry_find_next);
4077 + * Global data: list of all mbcache's, lru list, and a spinlock for
4078 + * accessing cache data structures on SMP machines. The lru list is
4079 + * global across all mbcaches.
4082 +static LIST_HEAD(mb_cache_list);
4083 +static LIST_HEAD(mb_cache_lru_list);
4084 +static spinlock_t mb_cache_spinlock = SPIN_LOCK_UNLOCKED;
4087 +mb_cache_indexes(struct mb_cache *cache)
4089 +#ifdef MB_CACHE_INDEXES_COUNT
4090 + return MB_CACHE_INDEXES_COUNT;
4092 + return cache->c_indexes_count;
4097 + * What the mbcache registers as to get shrunk dynamically.
4101 +mb_cache_memory_pressure(int priority, unsigned int gfp_mask);
4103 +static struct cache_definition mb_cache_definition = {
4105 + mb_cache_memory_pressure
4110 +__mb_cache_entry_is_hashed(struct mb_cache_entry *ce)
4112 + return !list_empty(&ce->e_block_list);
4117 +__mb_cache_entry_unhash(struct mb_cache_entry *ce)
4121 + if (__mb_cache_entry_is_hashed(ce)) {
4122 + list_del_init(&ce->e_block_list);
4123 + for (n=0; n<mb_cache_indexes(ce->e_cache); n++)
4124 + list_del(&ce->e_indexes[n].o_list);
4130 +__mb_cache_entry_forget(struct mb_cache_entry *ce, int gfp_mask)
4132 + struct mb_cache *cache = ce->e_cache;
4134 + mb_assert(atomic_read(&ce->e_used) == 0);
4135 + if (cache->c_op.free && cache->c_op.free(ce, gfp_mask)) {
4136 + /* free failed -- put back on the lru list
4137 + for freeing later. */
4138 + spin_lock(&mb_cache_spinlock);
4139 + list_add(&ce->e_lru_list, &mb_cache_lru_list);
4140 + spin_unlock(&mb_cache_spinlock);
4142 + kmem_cache_free(cache->c_entry_cache, ce);
4143 + atomic_dec(&cache->c_entry_count);
4149 +__mb_cache_entry_release_unlock(struct mb_cache_entry *ce)
4151 + if (atomic_dec_and_test(&ce->e_used)) {
4152 + if (__mb_cache_entry_is_hashed(ce))
4153 + list_add_tail(&ce->e_lru_list, &mb_cache_lru_list);
4155 + spin_unlock(&mb_cache_spinlock);
4156 + __mb_cache_entry_forget(ce, GFP_KERNEL);
4160 + spin_unlock(&mb_cache_spinlock);
4165 + * mb_cache_memory_pressure() memory pressure callback
4167 + * This function is called by the kernel memory management when memory
4170 + * @priority: Amount by which to shrink the cache (0 = highes priority)
4171 + * @gfp_mask: (ignored)
4174 +mb_cache_memory_pressure(int priority, unsigned int gfp_mask)
4176 + LIST_HEAD(free_list);
4177 + struct list_head *l, *ltmp;
4180 + spin_lock(&mb_cache_spinlock);
4181 + list_for_each(l, &mb_cache_list) {
4182 + struct mb_cache *cache =
4183 + list_entry(l, struct mb_cache, c_cache_list);
4184 + mb_debug("cache %s (%d)", cache->c_name,
4185 + atomic_read(&cache->c_entry_count));
4186 + count += atomic_read(&cache->c_entry_count);
4188 + mb_debug("trying to free %d of %d entries",
4189 + count / (priority ? priority : 1), count);
4191 + count /= priority;
4192 + while (count-- && !list_empty(&mb_cache_lru_list)) {
4193 + struct mb_cache_entry *ce =
4194 + list_entry(mb_cache_lru_list.next,
4195 + struct mb_cache_entry, e_lru_list);
4196 + list_del(&ce->e_lru_list);
4197 + __mb_cache_entry_unhash(ce);
4198 + list_add_tail(&ce->e_lru_list, &free_list);
4200 + spin_unlock(&mb_cache_spinlock);
4201 + list_for_each_safe(l, ltmp, &free_list) {
4202 + __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4203 + e_lru_list), gfp_mask);
4209 + * mb_cache_create() create a new cache
4211 + * All entries in one cache are equal size. Cache entries may be from
4212 + * multiple devices. If this is the first mbcache created, registers
4213 + * the cache with kernel memory management. Returns NULL if no more
4214 + * memory was available.
4216 + * @name: name of the cache (informal)
4217 + * @cache_op: contains the callback called when freeing a cache entry
4218 + * @entry_size: The size of a cache entry, including
4219 + * struct mb_cache_entry
4220 + * @indexes_count: number of additional indexes in the cache. Must equal
4221 + * MB_CACHE_INDEXES_COUNT if the number of indexes is
4223 + * @bucket_count: number of hash buckets
4226 +mb_cache_create(const char *name, struct mb_cache_op *cache_op,
4227 + size_t entry_size, int indexes_count, int bucket_count)
4230 + struct mb_cache *cache = NULL;
4232 + if(entry_size < sizeof(struct mb_cache_entry) +
4233 + indexes_count * sizeof(struct mb_cache_entry_index))
4236 + MOD_INC_USE_COUNT;
4237 + cache = kmalloc(sizeof(struct mb_cache) +
4238 + indexes_count * sizeof(struct list_head), GFP_KERNEL);
4241 + cache->c_name = name;
4242 + cache->c_op.free = NULL;
4244 + cache->c_op.free = cache_op->free;
4245 + atomic_set(&cache->c_entry_count, 0);
4246 + cache->c_bucket_count = bucket_count;
4247 +#ifdef MB_CACHE_INDEXES_COUNT
4248 + mb_assert(indexes_count == MB_CACHE_INDEXES_COUNT);
4250 + cache->c_indexes_count = indexes_count;
4252 + cache->c_block_hash = kmalloc(bucket_count * sizeof(struct list_head),
4254 + if (!cache->c_block_hash)
4256 + for (n=0; n<bucket_count; n++)
4257 + INIT_LIST_HEAD(&cache->c_block_hash[n]);
4258 + for (m=0; m<indexes_count; m++) {
4259 + cache->c_indexes_hash[m] = kmalloc(bucket_count *
4260 + sizeof(struct list_head),
4262 + if (!cache->c_indexes_hash[m])
4264 + for (n=0; n<bucket_count; n++)
4265 + INIT_LIST_HEAD(&cache->c_indexes_hash[m][n]);
4267 + cache->c_entry_cache = kmem_cache_create(name, entry_size, 0,
4268 + 0 /*SLAB_POISON | SLAB_RED_ZONE*/, NULL, NULL);
4269 + if (!cache->c_entry_cache)
4272 + spin_lock(&mb_cache_spinlock);
4273 + list_add(&cache->c_cache_list, &mb_cache_list);
4274 + spin_unlock(&mb_cache_spinlock);
4280 + kfree(cache->c_indexes_hash[m]);
4281 + if (cache->c_block_hash)
4282 + kfree(cache->c_block_hash);
4285 + MOD_DEC_USE_COUNT;
4291 + * mb_cache_shrink()
4293 + * Removes all cache entires of a device from the cache. All cache entries
4294 + * currently in use cannot be freed, and thus remain in the cache.
4296 + * @cache: which cache to shrink
4297 + * @dev: which device's cache entries to shrink
4300 +mb_cache_shrink(struct mb_cache *cache, kdev_t dev)
4302 + LIST_HEAD(free_list);
4303 + struct list_head *l, *ltmp;
4305 + spin_lock(&mb_cache_spinlock);
4306 + list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
4307 + struct mb_cache_entry *ce =
4308 + list_entry(l, struct mb_cache_entry, e_lru_list);
4309 + if (ce->e_dev == dev) {
4310 + list_del(&ce->e_lru_list);
4311 + list_add_tail(&ce->e_lru_list, &free_list);
4312 + __mb_cache_entry_unhash(ce);
4315 + spin_unlock(&mb_cache_spinlock);
4316 + list_for_each_safe(l, ltmp, &free_list) {
4317 + __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4318 + e_lru_list), GFP_KERNEL);
4324 + * mb_cache_destroy()
4326 + * Shrinks the cache to its minimum possible size (hopefully 0 entries),
4327 + * and then destroys it. If this was the last mbcache, un-registers the
4328 + * mbcache from kernel memory management.
4331 +mb_cache_destroy(struct mb_cache *cache)
4333 + LIST_HEAD(free_list);
4334 + struct list_head *l, *ltmp;
4337 + spin_lock(&mb_cache_spinlock);
4338 + list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
4339 + struct mb_cache_entry *ce =
4340 + list_entry(l, struct mb_cache_entry, e_lru_list);
4341 + if (ce->e_cache == cache) {
4342 + list_del(&ce->e_lru_list);
4343 + list_add_tail(&ce->e_lru_list, &free_list);
4344 + __mb_cache_entry_unhash(ce);
4347 + list_del(&cache->c_cache_list);
4348 + spin_unlock(&mb_cache_spinlock);
4349 + list_for_each_safe(l, ltmp, &free_list) {
4350 + __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4351 + e_lru_list), GFP_KERNEL);
4354 + if (atomic_read(&cache->c_entry_count) > 0) {
4355 + mb_error("cache %s: %d orphaned entries",
4357 + atomic_read(&cache->c_entry_count));
4360 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
4361 + /* We don't have kmem_cache_destroy() in 2.2.x */
4362 + kmem_cache_shrink(cache->c_entry_cache);
4364 + kmem_cache_destroy(cache->c_entry_cache);
4366 + for (n=0; n < mb_cache_indexes(cache); n++)
4367 + kfree(cache->c_indexes_hash[n]);
4368 + kfree(cache->c_block_hash);
4371 + MOD_DEC_USE_COUNT;
4376 + * mb_cache_entry_alloc()
4378 + * Allocates a new cache entry. The new entry will not be valid initially,
4379 + * and thus cannot be looked up yet. It should be filled with data, and
4380 + * then inserted into the cache using mb_cache_entry_insert(). Returns NULL
4381 + * if no more memory was available.
4383 +struct mb_cache_entry *
4384 +mb_cache_entry_alloc(struct mb_cache *cache)
4386 + struct mb_cache_entry *ce;
4388 + atomic_inc(&cache->c_entry_count);
4389 + ce = kmem_cache_alloc(cache->c_entry_cache, GFP_KERNEL);
4391 + INIT_LIST_HEAD(&ce->e_lru_list);
4392 + INIT_LIST_HEAD(&ce->e_block_list);
4393 + ce->e_cache = cache;
4394 + atomic_set(&ce->e_used, 1);
4401 + * mb_cache_entry_insert()
4403 + * Inserts an entry that was allocated using mb_cache_entry_alloc() into
4404 + * the cache. After this, the cache entry can be looked up, but is not yet
4405 + * in the lru list as the caller still holds a handle to it. Returns 0 on
4406 + * success, or -EBUSY if a cache entry for that device + inode exists
4407 + * already (this may happen after a failed lookup, if another process has
4408 + * inserted the same cache entry in the meantime).
4410 + * @dev: device the cache entry belongs to
4411 + * @block: block number
4412 + * @keys: array of additional keys. There must be indexes_count entries
4413 + * in the array (as specified when creating the cache).
4416 +mb_cache_entry_insert(struct mb_cache_entry *ce, kdev_t dev,
4417 + unsigned long block, unsigned int keys[])
4419 + struct mb_cache *cache = ce->e_cache;
4420 + unsigned int bucket = (HASHDEV(dev) + block) % cache->c_bucket_count;
4421 + struct list_head *l;
4422 + int error = -EBUSY, n;
4424 + spin_lock(&mb_cache_spinlock);
4425 + list_for_each(l, &cache->c_block_hash[bucket]) {
4426 + struct mb_cache_entry *ce =
4427 + list_entry(l, struct mb_cache_entry, e_block_list);
4428 + if (ce->e_dev == dev && ce->e_block == block)
4431 + __mb_cache_entry_unhash(ce);
4433 + ce->e_block = block;
4434 + list_add(&ce->e_block_list, &cache->c_block_hash[bucket]);
4435 + for (n=0; n<mb_cache_indexes(cache); n++) {
4436 + ce->e_indexes[n].o_key = keys[n];
4437 + bucket = keys[n] % cache->c_bucket_count;
4438 + list_add(&ce->e_indexes[n].o_list,
4439 + &cache->c_indexes_hash[n][bucket]);
4442 + spin_unlock(&mb_cache_spinlock);
4448 + * mb_cache_entry_release()
4450 + * Release a handle to a cache entry. When the last handle to a cache entry
4451 + * is released it is either freed (if it is invalid) or otherwise inserted
4452 + * in to the lru list.
4455 +mb_cache_entry_release(struct mb_cache_entry *ce)
4457 + spin_lock(&mb_cache_spinlock);
4458 + __mb_cache_entry_release_unlock(ce);
4463 + * mb_cache_entry_takeout()
4465 + * Take a cache entry out of the cache, making it invalid. The entry can later
4466 + * be re-inserted using mb_cache_entry_insert(), or released using
4467 + * mb_cache_entry_release().
4470 +mb_cache_entry_takeout(struct mb_cache_entry *ce)
4472 + spin_lock(&mb_cache_spinlock);
4473 + mb_assert(list_empty(&ce->e_lru_list));
4474 + __mb_cache_entry_unhash(ce);
4475 + spin_unlock(&mb_cache_spinlock);
4480 + * mb_cache_entry_free()
4482 + * This is equivalent to the sequence mb_cache_entry_takeout() --
4483 + * mb_cache_entry_release().
4486 +mb_cache_entry_free(struct mb_cache_entry *ce)
4488 + spin_lock(&mb_cache_spinlock);
4489 + mb_assert(list_empty(&ce->e_lru_list));
4490 + __mb_cache_entry_unhash(ce);
4491 + __mb_cache_entry_release_unlock(ce);
4496 + * mb_cache_entry_dup()
4498 + * Duplicate a handle to a cache entry (does not duplicate the cache entry
4499 + * itself). After the call, both the old and the new handle must be released.
4501 +struct mb_cache_entry *
4502 +mb_cache_entry_dup(struct mb_cache_entry *ce)
4504 + atomic_inc(&ce->e_used);
4510 + * mb_cache_entry_get()
4512 + * Get a cache entry by device / block number. (There can only be one entry
4513 + * in the cache per device and block.) Returns NULL if no such cache entry
4516 +struct mb_cache_entry *
4517 +mb_cache_entry_get(struct mb_cache *cache, kdev_t dev, unsigned long block)
4519 + unsigned int bucket = (HASHDEV(dev) + block) % cache->c_bucket_count;
4520 + struct list_head *l;
4521 + struct mb_cache_entry *ce;
4523 + spin_lock(&mb_cache_spinlock);
4524 + list_for_each(l, &cache->c_block_hash[bucket]) {
4525 + ce = list_entry(l, struct mb_cache_entry, e_block_list);
4526 + if (ce->e_dev == dev && ce->e_block == block) {
4527 + if (!list_empty(&ce->e_lru_list))
4528 + list_del_init(&ce->e_lru_list);
4529 + atomic_inc(&ce->e_used);
4536 + spin_unlock(&mb_cache_spinlock);
4540 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
4542 +static struct mb_cache_entry *
4543 +__mb_cache_entry_find(struct list_head *l, struct list_head *head,
4544 + int index, kdev_t dev, unsigned int key)
4546 + while (l != head) {
4547 + struct mb_cache_entry *ce =
4548 + list_entry(l, struct mb_cache_entry,
4549 + e_indexes[index].o_list);
4550 + if (ce->e_dev == dev && ce->e_indexes[index].o_key == key) {
4551 + if (!list_empty(&ce->e_lru_list))
4552 + list_del_init(&ce->e_lru_list);
4553 + atomic_inc(&ce->e_used);
4563 + * mb_cache_entry_find_first()
4565 + * Find the first cache entry on a given device with a certain key in
4566 + * an additional index. Additonal matches can be found with
4567 + * mb_cache_entry_find_next(). Returns NULL if no match was found.
4569 + * @cache: the cache to search
4570 + * @index: the number of the additonal index to search (0<=index<indexes_count)
4571 + * @dev: the device the cache entry should belong to
4572 + * @key: the key in the index
4574 +struct mb_cache_entry *
4575 +mb_cache_entry_find_first(struct mb_cache *cache, int index, kdev_t dev,
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 = cache->c_indexes_hash[index][bucket].next;
4585 + ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
4587 + spin_unlock(&mb_cache_spinlock);
4593 + * mb_cache_entry_find_next()
4595 + * Find the next cache entry on a given device with a certain key in an
4596 + * additional index. Returns NULL if no match could be found. The previous
4597 + * entry is atomatically released, so that mb_cache_entry_find_next() can
4598 + * be called like this:
4600 + * entry = mb_cache_entry_find_first();
4603 + * entry = mb_cache_entry_find_next(entry, ...);
4606 + * @prev: The previous match
4607 + * @index: the number of the additonal index to search (0<=index<indexes_count)
4608 + * @dev: the device the cache entry should belong to
4609 + * @key: the key in the index
4611 +struct mb_cache_entry *
4612 +mb_cache_entry_find_next(struct mb_cache_entry *prev, int index, kdev_t dev,
4615 + struct mb_cache *cache = prev->e_cache;
4616 + unsigned int bucket = key % cache->c_bucket_count;
4617 + struct list_head *l;
4618 + struct mb_cache_entry *ce;
4620 + mb_assert(index < mb_cache_indexes(cache));
4621 + spin_lock(&mb_cache_spinlock);
4622 + l = prev->e_indexes[index].o_list.next;
4623 + ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
4625 + __mb_cache_entry_release_unlock(prev);
4629 +#endif /* !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0) */
4631 +static int __init init_mbcache(void)
4633 + register_cache(&mb_cache_definition);
4637 +static void __exit exit_mbcache(void)
4639 + unregister_cache(&mb_cache_definition);
4642 +module_init(init_mbcache)
4643 +module_exit(exit_mbcache)
4645 Index: linux-2.4.24-vanilla/include/asm-arm/unistd.h
4646 ===================================================================
4647 --- linux-2.4.24-vanilla.orig/include/asm-arm/unistd.h 2004-01-10 17:05:06.000000000 +0300
4648 +++ linux-2.4.24-vanilla/include/asm-arm/unistd.h 2004-01-10 17:20:28.000000000 +0300
4650 #define __NR_security (__NR_SYSCALL_BASE+223)
4651 #define __NR_gettid (__NR_SYSCALL_BASE+224)
4652 #define __NR_readahead (__NR_SYSCALL_BASE+225)
4653 -#if 0 /* allocated in 2.5 */
4654 #define __NR_setxattr (__NR_SYSCALL_BASE+226)
4655 #define __NR_lsetxattr (__NR_SYSCALL_BASE+227)
4656 #define __NR_fsetxattr (__NR_SYSCALL_BASE+228)
4658 #define __NR_removexattr (__NR_SYSCALL_BASE+235)
4659 #define __NR_lremovexattr (__NR_SYSCALL_BASE+236)
4660 #define __NR_fremovexattr (__NR_SYSCALL_BASE+237)
4662 #define __NR_tkill (__NR_SYSCALL_BASE+238)
4663 #if 0 /* allocated in 2.5 */
4664 #define __NR_sendfile64 (__NR_SYSCALL_BASE+239)
4665 Index: linux-2.4.24-vanilla/include/asm-ppc64/unistd.h
4666 ===================================================================
4667 --- linux-2.4.24-vanilla.orig/include/asm-ppc64/unistd.h 2004-01-10 17:05:59.000000000 +0300
4668 +++ linux-2.4.24-vanilla/include/asm-ppc64/unistd.h 2004-01-10 17:20:28.000000000 +0300
4670 #define __NR_mincore 206
4671 #define __NR_gettid 207
4672 #define __NR_tkill 208
4674 #define __NR_setxattr 209
4675 #define __NR_lsetxattr 210
4676 #define __NR_fsetxattr 211
4678 #define __NR_removexattr 218
4679 #define __NR_lremovexattr 219
4680 #define __NR_fremovexattr 220
4681 +#if 0 /* Reserved syscalls */
4682 #define __NR_futex 221
4683 #define __NR_sched_setaffinity 222
4684 #define __NR_sched_getaffinity 223
4685 Index: linux-2.4.24-vanilla/include/asm-s390/unistd.h
4686 ===================================================================
4687 --- linux-2.4.24-vanilla.orig/include/asm-s390/unistd.h 2004-01-10 17:04:42.000000000 +0300
4688 +++ linux-2.4.24-vanilla/include/asm-s390/unistd.h 2004-01-10 17:20:28.000000000 +0300
4689 @@ -213,9 +213,18 @@
4690 #define __NR_getdents64 220
4691 #define __NR_fcntl64 221
4692 #define __NR_readahead 222
4694 - * Numbers 224-235 are reserved for posix acl
4696 +#define __NR_setxattr 224
4697 +#define __NR_lsetxattr 225
4698 +#define __NR_fsetxattr 226
4699 +#define __NR_getxattr 227
4700 +#define __NR_lgetxattr 228
4701 +#define __NR_fgetxattr 229
4702 +#define __NR_listxattr 230
4703 +#define __NR_llistxattr 231
4704 +#define __NR_flistxattr 232
4705 +#define __NR_removexattr 233
4706 +#define __NR_lremovexattr 234
4707 +#define __NR_fremovexattr 235
4708 #define __NR_gettid 236
4709 #define __NR_tkill 237
4711 Index: linux-2.4.24-vanilla/include/asm-s390x/unistd.h
4712 ===================================================================
4713 --- linux-2.4.24-vanilla.orig/include/asm-s390x/unistd.h 2004-01-10 17:04:42.000000000 +0300
4714 +++ linux-2.4.24-vanilla/include/asm-s390x/unistd.h 2004-01-10 17:20:28.000000000 +0300
4715 @@ -181,9 +181,18 @@
4716 #define __NR_mincore 218
4717 #define __NR_madvise 219
4718 #define __NR_readahead 222
4720 - * Numbers 224-235 are reserved for posix acl
4722 +#define __NR_setxattr 224
4723 +#define __NR_lsetxattr 225
4724 +#define __NR_fsetxattr 226
4725 +#define __NR_getxattr 227
4726 +#define __NR_lgetxattr 228
4727 +#define __NR_fgetxattr 229
4728 +#define __NR_listxattr 230
4729 +#define __NR_llistxattr 231
4730 +#define __NR_flistxattr 232
4731 +#define __NR_removexattr 233
4732 +#define __NR_lremovexattr 234
4733 +#define __NR_fremovexattr 235
4734 #define __NR_gettid 236
4735 #define __NR_tkill 237
4737 Index: linux-2.4.24-vanilla/include/linux/cache_def.h
4738 ===================================================================
4739 --- linux-2.4.24-vanilla.orig/include/linux/cache_def.h 2003-01-30 13:24:37.000000000 +0300
4740 +++ linux-2.4.24-vanilla/include/linux/cache_def.h 2004-01-10 17:20:28.000000000 +0300
4743 + * linux/cache_def.h
4744 + * Handling of caches defined in drivers, filesystems, ...
4746 + * Copyright (C) 2002 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
4749 +struct cache_definition {
4751 + void (*shrink)(int, unsigned int);
4752 + struct list_head link;
4755 +extern void register_cache(struct cache_definition *);
4756 +extern void unregister_cache(struct cache_definition *);
4757 Index: linux-2.4.24-vanilla/include/linux/errno.h
4758 ===================================================================
4759 --- linux-2.4.24-vanilla.orig/include/linux/errno.h 2001-02-10 01:46:13.000000000 +0300
4760 +++ linux-2.4.24-vanilla/include/linux/errno.h 2004-01-10 17:20:28.000000000 +0300
4765 +/* Defined for extended attributes */
4766 +#define ENOATTR ENODATA /* No such attribute */
4767 +#define ENOTSUP EOPNOTSUPP /* Operation not supported */
4770 Index: linux-2.4.24-vanilla/include/linux/ext2_fs.h
4771 ===================================================================
4772 --- linux-2.4.24-vanilla.orig/include/linux/ext2_fs.h 2004-01-10 17:04:42.000000000 +0300
4773 +++ linux-2.4.24-vanilla/include/linux/ext2_fs.h 2004-01-10 17:20:28.000000000 +0300
4776 #define EXT2_BAD_INO 1 /* Bad blocks inode */
4777 #define EXT2_ROOT_INO 2 /* Root inode */
4778 -#define EXT2_ACL_IDX_INO 3 /* ACL inode */
4779 -#define EXT2_ACL_DATA_INO 4 /* ACL inode */
4780 #define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
4781 #define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
4785 # define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
4787 -#define EXT2_ACLE_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
4788 #define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
4790 # define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
4791 @@ -121,28 +118,6 @@
4797 -struct ext2_acl_header /* Header of Access Control Lists */
4800 - __u32 aclh_file_count;
4801 - __u32 aclh_acle_count;
4802 - __u32 aclh_first_acle;
4805 -struct ext2_acl_entry /* Access Control List Entry */
4808 - __u16 acle_perms; /* Access permissions */
4809 - __u16 acle_type; /* Type of entry */
4810 - __u16 acle_tag; /* User or group identity */
4812 - __u32 acle_next; /* Pointer on next entry for the */
4813 - /* same inode or on next free entry */
4817 * Structure of a blocks group descriptor
4819 struct ext2_group_desc
4821 #define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
4822 #define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
4823 #define EXT2_MOUNT_NO_UID32 0x0200 /* Disable 32-bit UIDs */
4824 +#define EXT2_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
4826 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
4827 #define set_opt(o, opt) o |= EXT2_MOUNT_##opt
4831 #define EXT2_SB(sb) (&((sb)->u.ext2_sb))
4832 +#define EXT2_I(inode) (&((inode)->u.ext2_i))
4834 /* Assume that user mode programs are passing in an ext2fs superblock, not
4835 * a kernel struct super_block. This will allow us to call the feature-test
4837 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
4838 #define EXT2_FEATURE_INCOMPAT_ANY 0xffffffff
4840 -#define EXT2_FEATURE_COMPAT_SUPP 0
4841 +#define EXT2_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
4842 #define EXT2_FEATURE_INCOMPAT_SUPP EXT2_FEATURE_INCOMPAT_FILETYPE
4843 #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
4844 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
4845 @@ -624,8 +601,10 @@
4848 extern struct inode_operations ext2_dir_inode_operations;
4849 +extern struct inode_operations ext2_special_inode_operations;
4852 +extern struct inode_operations ext2_symlink_inode_operations;
4853 extern struct inode_operations ext2_fast_symlink_inode_operations;
4855 #endif /* __KERNEL__ */
4856 Index: linux-2.4.24-vanilla/include/linux/ext2_xattr.h
4857 ===================================================================
4858 --- linux-2.4.24-vanilla.orig/include/linux/ext2_xattr.h 2003-01-30 13:24:37.000000000 +0300
4859 +++ linux-2.4.24-vanilla/include/linux/ext2_xattr.h 2004-01-10 17:20:28.000000000 +0300
4862 + File: linux/ext2_xattr.h
4864 + On-disk format of extended attributes for the ext2 filesystem.
4866 + (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
4869 +#include <linux/config.h>
4870 +#include <linux/init.h>
4871 +#include <linux/xattr.h>
4873 +/* Magic value in attribute blocks */
4874 +#define EXT2_XATTR_MAGIC 0xEA020000
4876 +/* Maximum number of references to one attribute block */
4877 +#define EXT2_XATTR_REFCOUNT_MAX 1024
4880 +#define EXT2_XATTR_INDEX_MAX 10
4881 +#define EXT2_XATTR_INDEX_USER 1
4882 +#define EXT2_XATTR_INDEX_POSIX_ACL_ACCESS 2
4883 +#define EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT 3
4885 +struct ext2_xattr_header {
4886 + __u32 h_magic; /* magic number for identification */
4887 + __u32 h_refcount; /* reference count */
4888 + __u32 h_blocks; /* number of disk blocks used */
4889 + __u32 h_hash; /* hash value of all attributes */
4890 + __u32 h_reserved[4]; /* zero right now */
4893 +struct ext2_xattr_entry {
4894 + __u8 e_name_len; /* length of name */
4895 + __u8 e_name_index; /* attribute name index */
4896 + __u16 e_value_offs; /* offset in disk block of value */
4897 + __u32 e_value_block; /* disk block attribute is stored on (n/i) */
4898 + __u32 e_value_size; /* size of attribute value */
4899 + __u32 e_hash; /* hash value of name and value */
4900 + char e_name[0]; /* attribute name */
4903 +#define EXT2_XATTR_PAD_BITS 2
4904 +#define EXT2_XATTR_PAD (1<<EXT2_XATTR_PAD_BITS)
4905 +#define EXT2_XATTR_ROUND (EXT2_XATTR_PAD-1)
4906 +#define EXT2_XATTR_LEN(name_len) \
4907 + (((name_len) + EXT2_XATTR_ROUND + \
4908 + sizeof(struct ext2_xattr_entry)) & ~EXT2_XATTR_ROUND)
4909 +#define EXT2_XATTR_NEXT(entry) \
4910 + ( (struct ext2_xattr_entry *)( \
4911 + (char *)(entry) + EXT2_XATTR_LEN((entry)->e_name_len)) )
4912 +#define EXT2_XATTR_SIZE(size) \
4913 + (((size) + EXT2_XATTR_ROUND) & ~EXT2_XATTR_ROUND)
4917 +# ifdef CONFIG_EXT2_FS_XATTR
4919 +struct ext2_xattr_handler {
4921 + size_t (*list)(char *list, struct inode *inode, const char *name,
4923 + int (*get)(struct inode *inode, const char *name, void *buffer,
4925 + int (*set)(struct inode *inode, const char *name, const void *buffer,
4926 + size_t size, int flags);
4929 +extern int ext2_xattr_register(int, struct ext2_xattr_handler *);
4930 +extern void ext2_xattr_unregister(int, struct ext2_xattr_handler *);
4932 +extern int ext2_setxattr(struct dentry *, const char *, const void *, size_t, int);
4933 +extern ssize_t ext2_getxattr(struct dentry *, const char *, void *, size_t);
4934 +extern ssize_t ext2_listxattr(struct dentry *, char *, size_t);
4935 +extern int ext2_removexattr(struct dentry *, const char *);
4937 +extern int ext2_xattr_get(struct inode *, int, const char *, void *, size_t);
4938 +extern int ext2_xattr_list(struct inode *, char *, size_t);
4939 +extern int ext2_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
4941 +extern void ext2_xattr_delete_inode(struct inode *);
4942 +extern void ext2_xattr_put_super(struct super_block *);
4944 +extern int init_ext2_xattr(void) __init;
4945 +extern void exit_ext2_xattr(void);
4947 +# else /* CONFIG_EXT2_FS_XATTR */
4948 +# define ext2_setxattr NULL
4949 +# define ext2_getxattr NULL
4950 +# define ext2_listxattr NULL
4951 +# define ext2_removexattr NULL
4954 +ext2_xattr_get(struct inode *inode, int name_index,
4955 + const char *name, void *buffer, size_t size)
4961 +ext2_xattr_list(struct inode *inode, char *buffer, size_t size)
4967 +ext2_xattr_set(struct inode *inode, int name_index, const char *name,
4968 + const void *value, size_t size, int flags)
4974 +ext2_xattr_delete_inode(struct inode *inode)
4979 +ext2_xattr_put_super(struct super_block *sb)
4984 +init_ext2_xattr(void)
4990 +exit_ext2_xattr(void)
4994 +# endif /* CONFIG_EXT2_FS_XATTR */
4996 +# ifdef CONFIG_EXT2_FS_XATTR_USER
4998 +extern int init_ext2_xattr_user(void) __init;
4999 +extern void exit_ext2_xattr_user(void);
5001 +# else /* CONFIG_EXT2_FS_XATTR_USER */
5004 +init_ext2_xattr_user(void)
5010 +exit_ext2_xattr_user(void)
5014 +# endif /* CONFIG_EXT2_FS_XATTR_USER */
5016 +#endif /* __KERNEL__ */
5018 Index: linux-2.4.24-vanilla/include/linux/ext3_fs.h
5019 ===================================================================
5020 --- linux-2.4.24-vanilla.orig/include/linux/ext3_fs.h 2004-01-10 17:11:50.000000000 +0300
5021 +++ linux-2.4.24-vanilla/include/linux/ext3_fs.h 2004-01-10 17:20:28.000000000 +0300
5024 #define EXT3_BAD_INO 1 /* Bad blocks inode */
5025 #define EXT3_ROOT_INO 2 /* Root inode */
5026 -#define EXT3_ACL_IDX_INO 3 /* ACL inode */
5027 -#define EXT3_ACL_DATA_INO 4 /* ACL inode */
5028 #define EXT3_BOOT_LOADER_INO 5 /* Boot loader inode */
5029 #define EXT3_UNDEL_DIR_INO 6 /* Undelete directory inode */
5030 #define EXT3_RESIZE_INO 7 /* Reserved group descriptors inode */
5033 # define EXT3_BLOCK_SIZE(s) (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
5035 -#define EXT3_ACLE_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_acl_entry))
5036 #define EXT3_ADDR_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (__u32))
5038 # define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
5039 @@ -129,28 +126,6 @@
5045 -struct ext3_acl_header /* Header of Access Control Lists */
5048 - __u32 aclh_file_count;
5049 - __u32 aclh_acle_count;
5050 - __u32 aclh_first_acle;
5053 -struct ext3_acl_entry /* Access Control List Entry */
5056 - __u16 acle_perms; /* Access permissions */
5057 - __u16 acle_type; /* Type of entry */
5058 - __u16 acle_tag; /* User or group identity */
5060 - __u32 acle_next; /* Pointer on next entry for the */
5061 - /* same inode or on next free entry */
5065 * Structure of a blocks group descriptor
5067 struct ext3_group_desc
5069 #define EXT3_MOUNT_WRITEBACK_DATA 0x0C00 /* No data ordering */
5070 #define EXT3_MOUNT_UPDATE_JOURNAL 0x1000 /* Update the journal format */
5071 #define EXT3_MOUNT_NO_UID32 0x2000 /* Disable 32-bit UIDs */
5072 +#define EXT3_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
5074 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
5075 #ifndef _LINUX_EXT2_FS_H
5077 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
5078 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
5080 -#define EXT3_FEATURE_COMPAT_SUPP 0
5081 +#define EXT3_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
5082 #define EXT3_FEATURE_INCOMPAT_SUPP (EXT3_FEATURE_INCOMPAT_FILETYPE| \
5083 EXT3_FEATURE_INCOMPAT_RECOVER)
5084 #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
5086 extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
5089 +extern int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
5090 extern struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
5091 extern struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
5093 @@ -773,8 +750,10 @@
5096 extern struct inode_operations ext3_dir_inode_operations;
5097 +extern struct inode_operations ext3_special_inode_operations;
5100 +extern struct inode_operations ext3_symlink_inode_operations;
5101 extern struct inode_operations ext3_fast_symlink_inode_operations;
5104 Index: linux-2.4.24-vanilla/include/linux/ext3_jbd.h
5105 ===================================================================
5106 --- linux-2.4.24-vanilla.orig/include/linux/ext3_jbd.h 2004-01-10 17:11:50.000000000 +0300
5107 +++ linux-2.4.24-vanilla/include/linux/ext3_jbd.h 2004-01-10 17:20:28.000000000 +0300
5110 #define EXT3_SINGLEDATA_TRANS_BLOCKS 8U
5112 +/* Extended attributes may touch two data buffers, two bitmap buffers,
5113 + * and two group and summaries. */
5115 +#define EXT3_XATTR_TRANS_BLOCKS 8
5117 /* Define the minimum size for a transaction which modifies data. This
5118 * needs to take into account the fact that we may end up modifying two
5119 * quota files too (one for the group, one for the user quota). The
5120 * superblock only gets updated once, of course, so don't bother
5121 * counting that again for the quota updates. */
5123 -#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS - 2)
5124 +#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS + \
5125 + EXT3_XATTR_TRANS_BLOCKS - 2)
5127 extern int ext3_writepage_trans_blocks(struct inode *inode);
5129 Index: linux-2.4.24-vanilla/include/linux/ext3_xattr.h
5130 ===================================================================
5131 --- linux-2.4.24-vanilla.orig/include/linux/ext3_xattr.h 2003-01-30 13:24:37.000000000 +0300
5132 +++ linux-2.4.24-vanilla/include/linux/ext3_xattr.h 2004-01-10 17:20:28.000000000 +0300
5135 + File: linux/ext3_xattr.h
5137 + On-disk format of extended attributes for the ext3 filesystem.
5139 + (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
5142 +#include <linux/config.h>
5143 +#include <linux/init.h>
5144 +#include <linux/xattr.h>
5146 +/* Magic value in attribute blocks */
5147 +#define EXT3_XATTR_MAGIC 0xEA020000
5149 +/* Maximum number of references to one attribute block */
5150 +#define EXT3_XATTR_REFCOUNT_MAX 1024
5153 +#define EXT3_XATTR_INDEX_MAX 10
5154 +#define EXT3_XATTR_INDEX_USER 1
5155 +#define EXT3_XATTR_INDEX_POSIX_ACL_ACCESS 2
5156 +#define EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT 3
5158 +struct ext3_xattr_header {
5159 + __u32 h_magic; /* magic number for identification */
5160 + __u32 h_refcount; /* reference count */
5161 + __u32 h_blocks; /* number of disk blocks used */
5162 + __u32 h_hash; /* hash value of all attributes */
5163 + __u32 h_reserved[4]; /* zero right now */
5166 +struct ext3_xattr_entry {
5167 + __u8 e_name_len; /* length of name */
5168 + __u8 e_name_index; /* attribute name index */
5169 + __u16 e_value_offs; /* offset in disk block of value */
5170 + __u32 e_value_block; /* disk block attribute is stored on (n/i) */
5171 + __u32 e_value_size; /* size of attribute value */
5172 + __u32 e_hash; /* hash value of name and value */
5173 + char e_name[0]; /* attribute name */
5176 +#define EXT3_XATTR_PAD_BITS 2
5177 +#define EXT3_XATTR_PAD (1<<EXT3_XATTR_PAD_BITS)
5178 +#define EXT3_XATTR_ROUND (EXT3_XATTR_PAD-1)
5179 +#define EXT3_XATTR_LEN(name_len) \
5180 + (((name_len) + EXT3_XATTR_ROUND + \
5181 + sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND)
5182 +#define EXT3_XATTR_NEXT(entry) \
5183 + ( (struct ext3_xattr_entry *)( \
5184 + (char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) )
5185 +#define EXT3_XATTR_SIZE(size) \
5186 + (((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND)
5190 +# ifdef CONFIG_EXT3_FS_XATTR
5192 +struct ext3_xattr_handler {
5194 + size_t (*list)(char *list, struct inode *inode, const char *name,
5196 + int (*get)(struct inode *inode, const char *name, void *buffer,
5198 + int (*set)(struct inode *inode, const char *name, const void *buffer,
5199 + size_t size, int flags);
5202 +extern int ext3_xattr_register(int, struct ext3_xattr_handler *);
5203 +extern void ext3_xattr_unregister(int, struct ext3_xattr_handler *);
5205 +extern int ext3_setxattr(struct dentry *, const char *, const void *, size_t, int);
5206 +extern ssize_t ext3_getxattr(struct dentry *, const char *, void *, size_t);
5207 +extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
5208 +extern int ext3_removexattr(struct dentry *, const char *);
5210 +extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
5211 +extern int ext3_xattr_list(struct inode *, char *, size_t);
5212 +extern int ext3_xattr_set(handle_t *handle, struct inode *, int, const char *, const void *, size_t, int);
5214 +extern void ext3_xattr_delete_inode(handle_t *, struct inode *);
5215 +extern void ext3_xattr_put_super(struct super_block *);
5217 +extern int init_ext3_xattr(void) __init;
5218 +extern void exit_ext3_xattr(void);
5220 +# else /* CONFIG_EXT3_FS_XATTR */
5221 +# define ext3_setxattr NULL
5222 +# define ext3_getxattr NULL
5223 +# define ext3_listxattr NULL
5224 +# define ext3_removexattr NULL
5227 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
5228 + void *buffer, size_t size)
5234 +ext3_xattr_list(struct inode *inode, void *buffer, size_t size)
5240 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
5241 + const char *name, const void *value, size_t size, int flags)
5247 +ext3_xattr_delete_inode(handle_t *handle, struct inode *inode)
5252 +ext3_xattr_put_super(struct super_block *sb)
5257 +init_ext3_xattr(void)
5263 +exit_ext3_xattr(void)
5267 +# endif /* CONFIG_EXT3_FS_XATTR */
5269 +# ifdef CONFIG_EXT3_FS_XATTR_USER
5271 +extern int init_ext3_xattr_user(void) __init;
5272 +extern void exit_ext3_xattr_user(void);
5274 +# else /* CONFIG_EXT3_FS_XATTR_USER */
5277 +init_ext3_xattr_user(void)
5283 +exit_ext3_xattr_user(void)
5287 +#endif /* CONFIG_EXT3_FS_XATTR_USER */
5289 +#endif /* __KERNEL__ */
5291 Index: linux-2.4.24-vanilla/include/linux/fs.h
5292 ===================================================================
5293 --- linux-2.4.24-vanilla.orig/include/linux/fs.h 2004-01-10 17:11:45.000000000 +0300
5294 +++ linux-2.4.24-vanilla/include/linux/fs.h 2004-01-10 17:20:28.000000000 +0300
5296 int (*setattr) (struct dentry *, struct iattr *);
5297 int (*setattr_raw) (struct inode *, struct iattr *);
5298 int (*getattr) (struct dentry *, struct iattr *);
5299 - int (*setxattr) (struct dentry *, const char *, void *, size_t, int);
5300 + int (*setxattr) (struct dentry *, const char *, const void *, size_t, int);
5301 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
5302 ssize_t (*listxattr) (struct dentry *, char *, size_t);
5303 int (*removexattr) (struct dentry *, const char *);
5304 Index: linux-2.4.24-vanilla/include/linux/mbcache.h
5305 ===================================================================
5306 --- linux-2.4.24-vanilla.orig/include/linux/mbcache.h 2003-01-30 13:24:37.000000000 +0300
5307 +++ linux-2.4.24-vanilla/include/linux/mbcache.h 2004-01-10 17:20:28.000000000 +0300
5310 + File: linux/mbcache.h
5312 + (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
5315 +/* Hardwire the number of additional indexes */
5316 +#define MB_CACHE_INDEXES_COUNT 1
5318 +struct mb_cache_entry;
5320 +struct mb_cache_op {
5321 + int (*free)(struct mb_cache_entry *, int);
5325 + struct list_head c_cache_list;
5326 + const char *c_name;
5327 + struct mb_cache_op c_op;
5328 + atomic_t c_entry_count;
5329 + int c_bucket_count;
5330 +#ifndef MB_CACHE_INDEXES_COUNT
5331 + int c_indexes_count;
5333 + kmem_cache_t *c_entry_cache;
5334 + struct list_head *c_block_hash;
5335 + struct list_head *c_indexes_hash[0];
5338 +struct mb_cache_entry_index {
5339 + struct list_head o_list;
5340 + unsigned int o_key;
5343 +struct mb_cache_entry {
5344 + struct list_head e_lru_list;
5345 + struct mb_cache *e_cache;
5348 + unsigned long e_block;
5349 + struct list_head e_block_list;
5350 + struct mb_cache_entry_index e_indexes[0];
5353 +/* Functions on caches */
5355 +struct mb_cache * mb_cache_create(const char *, struct mb_cache_op *, size_t,
5357 +void mb_cache_shrink(struct mb_cache *, kdev_t);
5358 +void mb_cache_destroy(struct mb_cache *);
5360 +/* Functions on cache entries */
5362 +struct mb_cache_entry *mb_cache_entry_alloc(struct mb_cache *);
5363 +int mb_cache_entry_insert(struct mb_cache_entry *, kdev_t, unsigned long,
5365 +void mb_cache_entry_rehash(struct mb_cache_entry *, unsigned int[]);
5366 +void mb_cache_entry_release(struct mb_cache_entry *);
5367 +void mb_cache_entry_takeout(struct mb_cache_entry *);
5368 +void mb_cache_entry_free(struct mb_cache_entry *);
5369 +struct mb_cache_entry *mb_cache_entry_dup(struct mb_cache_entry *);
5370 +struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *, kdev_t,
5372 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
5373 +struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache, int,
5374 + kdev_t, unsigned int);
5375 +struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache_entry *, int,
5376 + kdev_t, unsigned int);
5378 Index: linux-2.4.24-vanilla/kernel/ksyms.c
5379 ===================================================================
5380 --- linux-2.4.24-vanilla.orig/kernel/ksyms.c 2004-01-10 17:11:43.000000000 +0300
5381 +++ linux-2.4.24-vanilla/kernel/ksyms.c 2004-01-10 17:20:28.000000000 +0300
5384 #include <linux/config.h>
5385 #include <linux/slab.h>
5386 +#include <linux/cache_def.h>
5387 #include <linux/module.h>
5388 #include <linux/blkdev.h>
5389 #include <linux/cdrom.h>
5391 EXPORT_SYMBOL(exit_files);
5392 EXPORT_SYMBOL(exit_fs);
5393 EXPORT_SYMBOL(exit_sighand);
5394 +EXPORT_SYMBOL(copy_fs_struct);
5396 /* internal kernel memory management */
5397 EXPORT_SYMBOL(_alloc_pages);
5399 EXPORT_SYMBOL(kmem_cache_alloc);
5400 EXPORT_SYMBOL(kmem_cache_free);
5401 EXPORT_SYMBOL(kmem_cache_size);
5402 +EXPORT_SYMBOL(register_cache);
5403 +EXPORT_SYMBOL(unregister_cache);
5404 EXPORT_SYMBOL(kmalloc);
5405 EXPORT_SYMBOL(kfree);
5406 EXPORT_SYMBOL(vfree);
5407 Index: linux-2.4.24-vanilla/mm/vmscan.c
5408 ===================================================================
5409 --- linux-2.4.24-vanilla.orig/mm/vmscan.c 2004-01-10 17:06:00.000000000 +0300
5410 +++ linux-2.4.24-vanilla/mm/vmscan.c 2004-01-10 17:21:00.000000000 +0300
5412 #include <linux/kernel_stat.h>
5413 #include <linux/swap.h>
5414 #include <linux/swapctl.h>
5415 +#include <linux/cache_def.h>
5416 #include <linux/smp_lock.h>
5417 #include <linux/pagemap.h>
5418 #include <linux/init.h>
5423 +static DECLARE_MUTEX(other_caches_sem);
5424 +static LIST_HEAD(cache_definitions);
5426 +void register_cache(struct cache_definition *cache)
5428 + down(&other_caches_sem);
5429 + list_add(&cache->link, &cache_definitions);
5430 + up(&other_caches_sem);
5433 +void unregister_cache(struct cache_definition *cache)
5435 + down(&other_caches_sem);
5436 + list_del(&cache->link);
5437 + up(&other_caches_sem);
5440 +static void shrink_other_caches(unsigned int priority, int gfp_mask)
5442 + struct list_head *p;
5444 + if (down_trylock(&other_caches_sem))
5447 + list_for_each_prev(p, &cache_definitions) {
5448 + struct cache_definition *cache =
5449 + list_entry(p, struct cache_definition, link);
5451 + cache->shrink(priority, gfp_mask);
5453 + up(&other_caches_sem);
5457 * "vm_cache_scan_ratio" is how much of the inactive LRU queue we will scan
5458 * in one go. A value of 6 for vm_cache_scan_ratio implies that we'll
5461 shrink_dqcache_memory(vm_vfs_scan_ratio, gfp_mask);
5463 + shrink_other_caches(vm_vfs_scan_ratio, gfp_mask);
5465 if (!*failed_swapout)
5466 *failed_swapout = !swap_out(classzone);
5469 shrink_dqcache_memory(vm_vfs_scan_ratio, gfp_mask);
5471 + shrink_other_caches(vm_vfs_scan_ratio, gfp_mask);
5472 if (!failed_swapout)
5473 failed_swapout = !swap_out(classzone);