1 Documentation/Configure.help | 66 ++
2 arch/alpha/defconfig | 7
3 arch/alpha/kernel/entry.S | 12
5 arch/arm/kernel/calls.S | 24
6 arch/i386/defconfig | 7
7 arch/ia64/defconfig | 7
8 arch/m68k/defconfig | 7
9 arch/mips/defconfig | 7
10 arch/mips64/defconfig | 7
11 arch/ppc/defconfig | 14
12 arch/ppc64/kernel/misc.S | 2
13 arch/s390/defconfig | 7
14 arch/s390/kernel/entry.S | 24
15 arch/s390x/defconfig | 7
16 arch/s390x/kernel/entry.S | 24
17 arch/s390x/kernel/wrapper32.S | 90 +++
18 arch/sparc/defconfig | 7
19 arch/sparc64/defconfig | 7
25 fs/ext2/inode.c | 34 -
28 fs/ext2/symlink.c | 14
29 fs/ext2/xattr.c | 1212 +++++++++++++++++++++++++++++++++++++++++
30 fs/ext2/xattr_user.c | 103 +++
32 fs/ext3/ext3-exports.c | 13
35 fs/ext3/inode.c | 35 -
37 fs/ext3/super.c | 37 +
38 fs/ext3/symlink.c | 14
39 fs/ext3/xattr.c | 1225 ++++++++++++++++++++++++++++++++++++++++++
40 fs/ext3/xattr_user.c | 111 +++
41 fs/jfs/jfs_xattr.h | 6
43 fs/mbcache.c | 648 ++++++++++++++++++++++
44 include/asm-arm/unistd.h | 2
45 include/asm-ppc64/unistd.h | 2
46 include/asm-s390/unistd.h | 13
47 include/asm-s390x/unistd.h | 13
48 include/linux/cache_def.h | 15
49 include/linux/errno.h | 4
50 include/linux/ext2_fs.h | 31 -
51 include/linux/ext2_xattr.h | 157 +++++
52 include/linux/ext3_fs.h | 31 -
53 include/linux/ext3_jbd.h | 8
54 include/linux/ext3_xattr.h | 157 +++++
55 include/linux/fs.h | 2
56 include/linux/mbcache.h | 69 ++
59 58 files changed, 4306 insertions(+), 137 deletions(-)
61 --- linux-2.4.22-ac1/arch/alpha/defconfig~xattr-0.8.54-2.4.22-rh 2003-06-13 18:51:29.000000000 +0400
62 +++ linux-2.4.22-ac1-alexey/arch/alpha/defconfig 2003-09-25 23:57:02.000000000 +0400
65 # Automatically generated make config: don't edit
67 +# CONFIG_EXT3_FS_XATTR is not set
68 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
69 +# CONFIG_EXT3_FS_XATTR_USER is not set
70 +# CONFIG_EXT2_FS_XATTR is not set
71 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
72 +# CONFIG_EXT2_FS_XATTR_USER is not set
73 +# CONFIG_FS_MBCACHE is not set
75 # CONFIG_UID16 is not set
76 # CONFIG_RWSEM_GENERIC_SPINLOCK is not set
77 --- linux-2.4.22-ac1/arch/alpha/kernel/entry.S~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:18.000000000 +0400
78 +++ linux-2.4.22-ac1-alexey/arch/alpha/kernel/entry.S 2003-09-25 23:57:02.000000000 +0400
79 @@ -1158,6 +1158,18 @@ sys_call_table:
81 .quad sys_ni_syscall /* 380, sys_security */
86 + .quad sys_getxattr /* 385 */
90 + .quad sys_llistxattr
91 + .quad sys_flistxattr /* 390 */
92 + .quad sys_removexattr
93 + .quad sys_lremovexattr
94 + .quad sys_fremovexattr
96 /* Remember to update everything, kids. */
97 .ifne (. - sys_call_table) - (NR_SYSCALLS * 8)
98 --- linux-2.4.22-ac1/arch/arm/defconfig~xattr-0.8.54-2.4.22-rh 2001-05-20 04:43:05.000000000 +0400
99 +++ linux-2.4.22-ac1-alexey/arch/arm/defconfig 2003-09-25 23:57:02.000000000 +0400
102 # Automatically generated make config: don't edit
104 +# CONFIG_EXT3_FS_XATTR is not set
105 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
106 +# CONFIG_EXT3_FS_XATTR_USER is not set
107 +# CONFIG_EXT2_FS_XATTR is not set
108 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
109 +# CONFIG_EXT2_FS_XATTR_USER is not set
110 +# CONFIG_FS_MBCACHE is not set
112 # CONFIG_EISA is not set
113 # CONFIG_SBUS is not set
114 --- linux-2.4.22-ac1/arch/arm/kernel/calls.S~xattr-0.8.54-2.4.22-rh 2003-08-25 15:44:39.000000000 +0400
115 +++ linux-2.4.22-ac1-alexey/arch/arm/kernel/calls.S 2003-09-26 00:00:10.000000000 +0400
116 @@ -240,18 +240,18 @@ __syscall_start:
117 .long SYMBOL_NAME(sys_ni_syscall) /* Security */
118 .long SYMBOL_NAME(sys_gettid)
119 /* 225 */ .long SYMBOL_NAME(sys_readahead)
120 - .long SYMBOL_NAME(sys_ni_syscall) /* setxattr */
121 - .long SYMBOL_NAME(sys_ni_syscall) /* lsetxattr */
122 - .long SYMBOL_NAME(sys_ni_syscall) /* fsetxattr */
123 - .long SYMBOL_NAME(sys_ni_syscall) /* getxattr */
124 -/* 230 */ .long SYMBOL_NAME(sys_ni_syscall) /* lgetxattr */
125 - .long SYMBOL_NAME(sys_ni_syscall) /* fgetxattr */
126 - .long SYMBOL_NAME(sys_ni_syscall) /* listxattr */
127 - .long SYMBOL_NAME(sys_ni_syscall) /* llistxattr */
128 - .long SYMBOL_NAME(sys_ni_syscall) /* flistxattr */
129 -/* 235 */ .long SYMBOL_NAME(sys_ni_syscall) /* removexattr */
130 - .long SYMBOL_NAME(sys_ni_syscall) /* lremovexattr */
131 - .long SYMBOL_NAME(sys_ni_syscall) /* fremovexattr */
132 + .long SYMBOL_NAME(sys_setxattr)
133 + .long SYMBOL_NAME(sys_lsetxattr)
134 + .long SYMBOL_NAME(sys_fsetxattr)
135 + .long SYMBOL_NAME(sys_getxattr)
136 +/* 230 */ .long SYMBOL_NAME(sys_lgetxattr)
137 + .long SYMBOL_NAME(sys_fgetxattr)
138 + .long SYMBOL_NAME(sys_listxattr)
139 + .long SYMBOL_NAME(sys_llistxattr)
140 + .long SYMBOL_NAME(sys_flistxattr)
141 +/* 235 */ .long SYMBOL_NAME(sys_removexattr)
142 + .long SYMBOL_NAME(sys_lremovexattr)
143 + .long SYMBOL_NAME(sys_fremovexattr)
144 .long SYMBOL_NAME(sys_tkill)
145 .long SYMBOL_NAME(sys_ni_syscall) /* sendfile64 */
146 /* 240 */ .long SYMBOL_NAME(sys_ni_syscall) /* futex */
147 --- linux-2.4.22-ac1/arch/i386/defconfig~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:18.000000000 +0400
148 +++ linux-2.4.22-ac1-alexey/arch/i386/defconfig 2003-09-25 23:57:02.000000000 +0400
151 # Automatically generated make config: don't edit
153 +# CONFIG_EXT3_FS_XATTR is not set
154 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
155 +# CONFIG_EXT3_FS_XATTR_USER is not set
156 +# CONFIG_EXT2_FS_XATTR is not set
157 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
158 +# CONFIG_EXT2_FS_XATTR_USER is not set
159 +# CONFIG_FS_MBCACHE is not set
162 # CONFIG_SBUS is not set
163 --- linux-2.4.22-ac1/arch/ia64/defconfig~xattr-0.8.54-2.4.22-rh 2003-08-25 15:44:39.000000000 +0400
164 +++ linux-2.4.22-ac1-alexey/arch/ia64/defconfig 2003-09-25 23:57:02.000000000 +0400
167 # Automatically generated make config: don't edit
169 +# CONFIG_EXT3_FS_XATTR is not set
170 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
171 +# CONFIG_EXT3_FS_XATTR_USER is not set
172 +# CONFIG_EXT2_FS_XATTR is not set
173 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
174 +# CONFIG_EXT2_FS_XATTR_USER is not set
175 +# CONFIG_FS_MBCACHE is not set
178 # Code maturity level options
179 --- linux-2.4.22-ac1/arch/m68k/defconfig~xattr-0.8.54-2.4.22-rh 2000-06-19 23:56:08.000000000 +0400
180 +++ linux-2.4.22-ac1-alexey/arch/m68k/defconfig 2003-09-25 23:57:02.000000000 +0400
183 # Automatically generated make config: don't edit
185 +# CONFIG_EXT3_FS_XATTR is not set
186 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
187 +# CONFIG_EXT3_FS_XATTR_USER is not set
188 +# CONFIG_EXT2_FS_XATTR is not set
189 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
190 +# CONFIG_EXT2_FS_XATTR_USER is not set
191 +# CONFIG_FS_MBCACHE is not set
195 --- linux-2.4.22-ac1/arch/mips64/defconfig~xattr-0.8.54-2.4.22-rh 2003-08-25 15:44:40.000000000 +0400
196 +++ linux-2.4.22-ac1-alexey/arch/mips64/defconfig 2003-09-25 23:57:02.000000000 +0400
199 # Automatically generated make config: don't edit
201 +# CONFIG_EXT3_FS_XATTR is not set
202 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
203 +# CONFIG_EXT3_FS_XATTR_USER is not set
204 +# CONFIG_EXT2_FS_XATTR is not set
205 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
206 +# CONFIG_EXT2_FS_XATTR_USER is not set
207 +# CONFIG_FS_MBCACHE is not set
209 # CONFIG_MIPS32 is not set
211 --- linux-2.4.22-ac1/arch/mips/defconfig~xattr-0.8.54-2.4.22-rh 2003-08-25 15:44:39.000000000 +0400
212 +++ linux-2.4.22-ac1-alexey/arch/mips/defconfig 2003-09-25 23:57:02.000000000 +0400
215 # Automatically generated make config: don't edit
217 +# CONFIG_EXT3_FS_XATTR is not set
218 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
219 +# CONFIG_EXT3_FS_XATTR_USER is not set
220 +# CONFIG_EXT2_FS_XATTR is not set
221 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
222 +# CONFIG_EXT2_FS_XATTR_USER is not set
223 +# CONFIG_FS_MBCACHE is not set
226 # CONFIG_MIPS64 is not set
227 --- linux-2.4.22-ac1/arch/ppc64/kernel/misc.S~xattr-0.8.54-2.4.22-rh 2003-08-25 15:44:40.000000000 +0400
228 +++ linux-2.4.22-ac1-alexey/arch/ppc64/kernel/misc.S 2003-09-25 23:57:02.000000000 +0400
229 @@ -805,6 +805,7 @@ _GLOBAL(sys_call_table32)
230 .llong .sys_gettid /* 207 */
231 #if 0 /* Reserved syscalls */
232 .llong .sys_tkill /* 208 */
235 .llong .sys_lsetxattr /* 210 */
236 .llong .sys_fsetxattr
237 @@ -817,6 +818,7 @@ _GLOBAL(sys_call_table32)
238 .llong .sys_removexattr
239 .llong .sys_lremovexattr
240 .llong .sys_fremovexattr /* 220 */
241 +#if 0 /* Reserved syscalls */
244 .llong .sys_perfmonctl /* Put this here for now ... */
245 --- linux-2.4.22-ac1/arch/ppc/defconfig~xattr-0.8.54-2.4.22-rh 2003-06-13 18:51:31.000000000 +0400
246 +++ linux-2.4.22-ac1-alexey/arch/ppc/defconfig 2003-09-25 23:57:02.000000000 +0400
249 # Automatically generated make config: don't edit
251 +# CONFIG_EXT3_FS_XATTR is not set
252 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
253 +# CONFIG_EXT3_FS_XATTR_USER is not set
254 +# CONFIG_EXT2_FS_XATTR is not set
255 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
256 +# CONFIG_EXT2_FS_XATTR_USER is not set
257 +# CONFIG_FS_MBCACHE is not set
258 +# CONFIG_EXT3_FS_XATTR is not set
259 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
260 +# CONFIG_EXT3_FS_XATTR_USER is not set
261 +# CONFIG_EXT2_FS_XATTR is not set
262 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
263 +# CONFIG_EXT2_FS_XATTR_USER is not set
264 +# CONFIG_FS_MBCACHE is not set
265 # CONFIG_UID16 is not set
266 # CONFIG_RWSEM_GENERIC_SPINLOCK is not set
267 CONFIG_RWSEM_XCHGADD_ALGORITHM=y
268 --- linux-2.4.22-ac1/arch/s390/defconfig~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:18.000000000 +0400
269 +++ linux-2.4.22-ac1-alexey/arch/s390/defconfig 2003-09-25 23:57:02.000000000 +0400
272 # Automatically generated make config: don't edit
274 +# CONFIG_EXT3_FS_XATTR is not set
275 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
276 +# CONFIG_EXT3_FS_XATTR_USER is not set
277 +# CONFIG_EXT2_FS_XATTR is not set
278 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
279 +# CONFIG_EXT2_FS_XATTR_USER is not set
280 +# CONFIG_FS_MBCACHE is not set
281 # CONFIG_ISA is not set
282 # CONFIG_EISA is not set
283 # CONFIG_MCA is not set
284 --- linux-2.4.22-ac1/arch/s390/kernel/entry.S~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:18.000000000 +0400
285 +++ linux-2.4.22-ac1-alexey/arch/s390/kernel/entry.S 2003-09-25 23:57:02.000000000 +0400
286 @@ -559,18 +559,18 @@ sys_call_table:
290 - .long sys_ni_syscall /* 224 - reserved for setxattr */
291 - .long sys_ni_syscall /* 225 - reserved for lsetxattr */
292 - .long sys_ni_syscall /* 226 - reserved for fsetxattr */
293 - .long sys_ni_syscall /* 227 - reserved for getxattr */
294 - .long sys_ni_syscall /* 228 - reserved for lgetxattr */
295 - .long sys_ni_syscall /* 229 - reserved for fgetxattr */
296 - .long sys_ni_syscall /* 230 - reserved for listxattr */
297 - .long sys_ni_syscall /* 231 - reserved for llistxattr */
298 - .long sys_ni_syscall /* 232 - reserved for flistxattr */
299 - .long sys_ni_syscall /* 233 - reserved for removexattr */
300 - .long sys_ni_syscall /* 234 - reserved for lremovexattr */
301 - .long sys_ni_syscall /* 235 - reserved for fremovexattr */
303 + .long sys_lsetxattr /* 225 */
304 + .long sys_fsetxattr
306 + .long sys_lgetxattr
307 + .long sys_fgetxattr
308 + .long sys_listxattr /* 230 */
309 + .long sys_llistxattr
310 + .long sys_flistxattr
311 + .long sys_removexattr
312 + .long sys_lremovexattr
313 + .long sys_fremovexattr /* 235 */
317 --- linux-2.4.22-ac1/arch/s390x/defconfig~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:18.000000000 +0400
318 +++ linux-2.4.22-ac1-alexey/arch/s390x/defconfig 2003-09-25 23:57:02.000000000 +0400
321 # Automatically generated make config: don't edit
323 +# CONFIG_EXT3_FS_XATTR is not set
324 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
325 +# CONFIG_EXT3_FS_XATTR_USER is not set
326 +# CONFIG_EXT2_FS_XATTR is not set
327 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
328 +# CONFIG_EXT2_FS_XATTR_USER is not set
329 +# CONFIG_FS_MBCACHE is not set
330 # CONFIG_ISA is not set
331 # CONFIG_EISA is not set
332 # CONFIG_MCA is not set
333 --- linux-2.4.22-ac1/arch/s390x/kernel/entry.S~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:18.000000000 +0400
334 +++ linux-2.4.22-ac1-alexey/arch/s390x/kernel/entry.S 2003-09-25 23:57:02.000000000 +0400
335 @@ -591,18 +591,18 @@ sys_call_table:
336 .long SYSCALL(sys_ni_syscall,sys32_fcntl64_wrapper)
337 .long SYSCALL(sys_readahead,sys32_readahead)
338 .long SYSCALL(sys_ni_syscall,sys_ni_syscall)
339 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 224 - reserved for setxattr */
340 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 225 - reserved for lsetxattr */
341 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 226 - reserved for fsetxattr */
342 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 227 - reserved for getxattr */
343 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 228 - reserved for lgetxattr */
344 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 229 - reserved for fgetxattr */
345 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 230 - reserved for listxattr */
346 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 231 - reserved for llistxattr */
347 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 232 - reserved for flistxattr */
348 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 233 - reserved for removexattr */
349 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 234 - reserved for lremovexattr */
350 - .long SYSCALL(sys_ni_syscall,sys_ni_syscall) /* 235 - reserved for fremovexattr */
351 + .long SYSCALL(sys_setxattr,sys32_setxattr_wrapper)
352 + .long SYSCALL(sys_lsetxattr,sys32_lsetxattr_wrapper) /* 225 */
353 + .long SYSCALL(sys_fsetxattr,sys32_fsetxattr_wrapper)
354 + .long SYSCALL(sys_getxattr,sys32_getxattr_wrapper)
355 + .long SYSCALL(sys_lgetxattr,sys32_lgetxattr_wrapper)
356 + .long SYSCALL(sys_fgetxattr,sys32_fgetxattr_wrapper)
357 + .long SYSCALL(sys_listxattr,sys32_listxattr_wrapper) /* 230 */
358 + .long SYSCALL(sys_llistxattr,sys32_llistxattr_wrapper)
359 + .long SYSCALL(sys_flistxattr,sys32_flistxattr_wrapper)
360 + .long SYSCALL(sys_removexattr,sys32_removexattr_wrapper)
361 + .long SYSCALL(sys_lremovexattr,sys32_lremovexattr_wrapper)
362 + .long SYSCALL(sys_fremovexattr,sys32_fremovexattr_wrapper)/* 235 */
363 .long SYSCALL(sys_gettid,sys_gettid)
364 .long SYSCALL(sys_tkill,sys_tkill)
366 --- linux-2.4.22-ac1/arch/s390x/kernel/wrapper32.S~xattr-0.8.54-2.4.22-rh 2003-08-25 15:44:40.000000000 +0400
367 +++ linux-2.4.22-ac1-alexey/arch/s390x/kernel/wrapper32.S 2003-09-26 00:05:14.000000000 +0400
368 @@ -1097,6 +1097,96 @@ sys32_fstat64_wrapper:
369 llgtr %r3,%r3 # struct stat64 *
371 jg sys32_fstat64 # branch to system call
373 + .globl sys32_setxattr_wrapper
374 +sys32_setxattr_wrapper:
375 + llgtr %r2,%r2 # char *
376 + llgtr %r3,%r3 # char *
377 + llgtr %r4,%r4 # void *
378 + llgfr %r5,%r5 # size_t
382 + .globl sys32_lsetxattr_wrapper
383 +sys32_lsetxattr_wrapper:
384 + llgtr %r2,%r2 # char *
385 + llgtr %r3,%r3 # char *
386 + llgtr %r4,%r4 # void *
387 + llgfr %r5,%r5 # size_t
391 + .globl sys32_fsetxattr_wrapper
392 +sys32_fsetxattr_wrapper:
394 + llgtr %r3,%r3 # char *
395 + llgtr %r4,%r4 # void *
396 + llgfr %r5,%r5 # size_t
400 + .globl sys32_getxattr_wrapper
401 +sys32_getxattr_wrapper:
402 + llgtr %r2,%r2 # char *
403 + llgtr %r3,%r3 # char *
404 + llgtr %r4,%r4 # void *
405 + llgfr %r5,%r5 # size_t
408 + .globl sys32_lgetxattr_wrapper
409 +sys32_lgetxattr_wrapper:
410 + llgtr %r2,%r2 # char *
411 + llgtr %r3,%r3 # char *
412 + llgtr %r4,%r4 # void *
413 + llgfr %r5,%r5 # size_t
416 + .globl sys32_fgetxattr_wrapper
417 +sys32_fgetxattr_wrapper:
419 + llgtr %r3,%r3 # char *
420 + llgtr %r4,%r4 # void *
421 + llgfr %r5,%r5 # size_t
424 + .globl sys32_listxattr_wrapper
425 +sys32_listxattr_wrapper:
426 + llgtr %r2,%r2 # char *
427 + llgtr %r3,%r3 # char *
428 + llgfr %r4,%r4 # size_t
431 + .globl sys32_llistxattr_wrapper
432 +sys32_llistxattr_wrapper:
433 + llgtr %r2,%r2 # char *
434 + llgtr %r3,%r3 # char *
435 + llgfr %r4,%r4 # size_t
438 + .globl sys32_flistxattr_wrapper
439 +sys32_flistxattr_wrapper:
441 + llgtr %r3,%r3 # char *
442 + llgfr %r4,%r4 # size_t
445 + .globl sys32_removexattr_wrapper
446 +sys32_removexattr_wrapper:
447 + llgtr %r2,%r2 # char *
448 + llgtr %r3,%r3 # char *
451 + .globl sys32_lremovexattr_wrapper
452 +sys32_lremovexattr_wrapper:
453 + llgtr %r2,%r2 # char *
454 + llgtr %r3,%r3 # char *
455 + jg sys_lremovexattr
457 + .globl sys32_fremovexattr_wrapper
458 +sys32_fremovexattr_wrapper:
460 + llgtr %r3,%r3 # char *
461 + jg sys_fremovexattr
463 .globl sys32_stime_wrapper
465 --- linux-2.4.22-ac1/arch/sparc64/defconfig~xattr-0.8.54-2.4.22-rh 2003-08-25 15:44:40.000000000 +0400
466 +++ linux-2.4.22-ac1-alexey/arch/sparc64/defconfig 2003-09-25 23:57:02.000000000 +0400
469 # Automatically generated make config: don't edit
471 +# CONFIG_EXT3_FS_XATTR is not set
472 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
473 +# CONFIG_EXT3_FS_XATTR_USER is not set
474 +# CONFIG_EXT2_FS_XATTR is not set
475 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
476 +# CONFIG_EXT2_FS_XATTR_USER is not set
477 +# CONFIG_FS_MBCACHE is not set
480 # Code maturity level options
481 --- linux-2.4.22-ac1/arch/sparc/defconfig~xattr-0.8.54-2.4.22-rh 2002-08-03 04:39:43.000000000 +0400
482 +++ linux-2.4.22-ac1-alexey/arch/sparc/defconfig 2003-09-25 23:57:02.000000000 +0400
485 # Automatically generated make config: don't edit
487 +# CONFIG_EXT3_FS_XATTR is not set
488 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
489 +# CONFIG_EXT3_FS_XATTR_USER is not set
490 +# CONFIG_EXT2_FS_XATTR is not set
491 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
492 +# CONFIG_EXT2_FS_XATTR_USER is not set
493 +# CONFIG_FS_MBCACHE is not set
497 --- linux-2.4.22-ac1/Documentation/Configure.help~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:30.000000000 +0400
498 +++ linux-2.4.22-ac1-alexey/Documentation/Configure.help 2003-09-25 23:57:02.000000000 +0400
499 @@ -16145,6 +16145,39 @@ CONFIG_EXT2_FS
500 be compiled as a module, and so this could be dangerous. Most
501 everyone wants to say Y here.
503 +Ext2 extended attributes
504 +CONFIG_EXT2_FS_XATTR
505 + Extended attributes are name:value pairs associated with inodes by
506 + the kernel or by users (see the attr(5) manual page, or visit
507 + <http://acl.bestbits.at/> for details).
511 +Ext2 extended attribute block sharing
512 +CONFIG_EXT2_FS_XATTR_SHARING
513 + This options enables code for sharing identical extended attribute
514 + blocks among multiple inodes.
518 +Ext2 extended user attributes
519 +CONFIG_EXT2_FS_XATTR_USER
520 + This option enables extended user attributes on ext2. Processes can
521 + associate extended user attributes with inodes to store additional
522 + information such as the character encoding of files, etc. (see the
523 + attr(5) manual page, or visit <http://acl.bestbits.at/> for details).
527 +Ext2 trusted extended attributes
528 +CONFIG_EXT2_FS_XATTR_TRUSTED
529 + This option enables extended attributes on ext2 that are accessible
530 + (and visible) only to users capable of CAP_SYS_ADMIN. Usually this
531 + is only the super user. Trusted extended attributes are meant for
532 + implementing system/security services.
536 Ext3 journalling file system support (EXPERIMENTAL)
538 This is the journalling version of the Second extended file system
539 @@ -16177,6 +16210,39 @@ CONFIG_EXT3_FS
540 of your root partition (the one containing the directory /) cannot
541 be compiled as a module, and so this may be dangerous.
543 +Ext3 extended attributes
544 +CONFIG_EXT3_FS_XATTR
545 + Extended attributes are name:value pairs associated with inodes by
546 + the kernel or by users (see the attr(5) manual page, or visit
547 + <http://acl.bestbits.at/> for details).
551 +Ext3 extended attribute block sharing
552 +CONFIG_EXT3_FS_XATTR_SHARING
553 + This options enables code for sharing identical extended attribute
554 + blocks among multiple inodes.
558 +Ext3 extended user attributes
559 +CONFIG_EXT3_FS_XATTR_USER
560 + This option enables extended user attributes on ext3. Processes can
561 + associate extended user attributes with inodes to store additional
562 + information such as the character encoding of files, etc. (see the
563 + attr(5) manual page, or visit <http://acl.bestbits.at/> for details).
567 +Ext3 trusted extended attributes
568 +CONFIG_EXT3_FS_XATTR_TRUSTED
569 + This option enables extended attributes on ext3 that are accessible
570 + (and visible) only to users capable of CAP_SYS_ADMIN. Usually this
571 + is only the super user. Trusted extended attributes are meant for
572 + implementing system/security services.
576 Journal Block Device support (JBD for ext3) (EXPERIMENTAL)
578 This is a generic journalling layer for block devices. It is
579 --- linux-2.4.22-ac1/fs/Config.in~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:23.000000000 +0400
580 +++ linux-2.4.22-ac1-alexey/fs/Config.in 2003-09-25 23:57:02.000000000 +0400
581 @@ -29,6 +29,11 @@ dep_mbool ' Debug Befs' CONFIG_BEFS_DEB
582 dep_tristate 'BFS file system support (EXPERIMENTAL)' CONFIG_BFS_FS $CONFIG_EXPERIMENTAL
584 tristate 'Ext3 journalling file system support' CONFIG_EXT3_FS
585 +dep_mbool ' Ext3 extended attributes' CONFIG_EXT3_FS_XATTR $CONFIG_EXT3_FS
586 +dep_bool ' Ext3 extended attribute block sharing' \
587 + CONFIG_EXT3_FS_XATTR_SHARING $CONFIG_EXT3_FS_XATTR
588 +dep_bool ' Ext3 extended user attributes' \
589 + CONFIG_EXT3_FS_XATTR_USER $CONFIG_EXT3_FS_XATTR
590 # CONFIG_JBD could be its own option (even modular), but until there are
591 # other users than ext3, we will simply make it be the same as CONFIG_EXT3_FS
592 # dep_tristate ' Journal Block Device support (JBD for ext3)' CONFIG_JBD $CONFIG_EXT3_FS
593 @@ -88,6 +93,11 @@ dep_mbool ' QNX4FS write support (DANGE
594 tristate 'ROM file system support' CONFIG_ROMFS_FS
596 tristate 'Second extended fs support' CONFIG_EXT2_FS
597 +dep_mbool ' Ext2 extended attributes' CONFIG_EXT2_FS_XATTR $CONFIG_EXT2_FS
598 +dep_bool ' Ext2 extended attribute block sharing' \
599 + CONFIG_EXT2_FS_XATTR_SHARING $CONFIG_EXT2_FS_XATTR
600 +dep_bool ' Ext2 extended user attributes' \
601 + CONFIG_EXT2_FS_XATTR_USER $CONFIG_EXT2_FS_XATTR
603 tristate 'System V/Xenix/V7/Coherent file system support' CONFIG_SYSV_FS
605 @@ -164,6 +174,10 @@ else
606 define_tristate CONFIG_ZISOFS_FS n
609 +# Meta block cache for Extended Attributes (ext2/ext3)
610 +#tristate 'Meta block cache' CONFIG_FS_MBCACHE
611 +define_tristate CONFIG_FS_MBCACHE y
613 mainmenu_option next_comment
614 comment 'Partition Types'
615 source fs/partitions/Config.in
616 --- linux-2.4.22-ac1/fs/ext2/file.c~xattr-0.8.54-2.4.22-rh 2001-10-11 19:05:18.000000000 +0400
617 +++ linux-2.4.22-ac1-alexey/fs/ext2/file.c 2003-09-25 23:57:02.000000000 +0400
620 #include <linux/fs.h>
621 #include <linux/ext2_fs.h>
622 +#include <linux/ext2_xattr.h>
623 #include <linux/sched.h>
626 @@ -51,4 +52,8 @@ struct file_operations ext2_file_operati
628 struct inode_operations ext2_file_inode_operations = {
629 truncate: ext2_truncate,
630 + setxattr: ext2_setxattr,
631 + getxattr: ext2_getxattr,
632 + listxattr: ext2_listxattr,
633 + removexattr: ext2_removexattr,
635 --- linux-2.4.22-ac1/fs/ext2/ialloc.c~xattr-0.8.54-2.4.22-rh 2003-06-13 18:51:37.000000000 +0400
636 +++ linux-2.4.22-ac1-alexey/fs/ext2/ialloc.c 2003-09-25 23:57:02.000000000 +0400
638 #include <linux/config.h>
639 #include <linux/fs.h>
640 #include <linux/ext2_fs.h>
641 +#include <linux/ext2_xattr.h>
642 #include <linux/locks.h>
643 #include <linux/quotaops.h>
645 @@ -167,6 +168,7 @@ void ext2_free_inode (struct inode * ino
647 if (!is_bad_inode(inode)) {
648 /* Quota is already initialized in iput() */
649 + ext2_xattr_delete_inode(inode);
650 DQUOT_FREE_INODE(inode);
653 --- linux-2.4.22-ac1/fs/ext2/inode.c~xattr-0.8.54-2.4.22-rh 2003-06-13 18:51:37.000000000 +0400
654 +++ linux-2.4.22-ac1-alexey/fs/ext2/inode.c 2003-09-25 23:57:02.000000000 +0400
655 @@ -39,6 +39,18 @@ MODULE_LICENSE("GPL");
656 static int ext2_update_inode(struct inode * inode, int do_sync);
659 + * Test whether an inode is a fast symlink.
661 +static inline int ext2_inode_is_fast_symlink(struct inode *inode)
663 + int ea_blocks = inode->u.ext2_i.i_file_acl ?
664 + (inode->i_sb->s_blocksize >> 9) : 0;
666 + return (S_ISLNK(inode->i_mode) &&
667 + inode->i_blocks - ea_blocks == 0);
671 * Called at each iput()
673 void ext2_put_inode (struct inode * inode)
674 @@ -53,9 +65,7 @@ void ext2_delete_inode (struct inode * i
678 - if (is_bad_inode(inode) ||
679 - inode->i_ino == EXT2_ACL_IDX_INO ||
680 - inode->i_ino == EXT2_ACL_DATA_INO)
681 + if (is_bad_inode(inode))
683 inode->u.ext2_i.i_dtime = CURRENT_TIME;
684 mark_inode_dirty(inode);
685 @@ -801,6 +811,8 @@ void ext2_truncate (struct inode * inode
686 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
687 S_ISLNK(inode->i_mode)))
689 + if (ext2_inode_is_fast_symlink(inode))
691 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
694 @@ -903,8 +915,7 @@ void ext2_read_inode (struct inode * ino
695 unsigned long offset;
696 struct ext2_group_desc * gdp;
698 - if ((inode->i_ino != EXT2_ROOT_INO && inode->i_ino != EXT2_ACL_IDX_INO &&
699 - inode->i_ino != EXT2_ACL_DATA_INO &&
700 + if ((inode->i_ino != EXT2_ROOT_INO &&
701 inode->i_ino < EXT2_FIRST_INO(inode->i_sb)) ||
702 inode->i_ino > le32_to_cpu(inode->i_sb->u.ext2_sb.s_es->s_inodes_count)) {
703 ext2_error (inode->i_sb, "ext2_read_inode",
704 @@ -989,10 +1000,7 @@ void ext2_read_inode (struct inode * ino
705 for (block = 0; block < EXT2_N_BLOCKS; block++)
706 inode->u.ext2_i.i_data[block] = raw_inode->i_block[block];
708 - if (inode->i_ino == EXT2_ACL_IDX_INO ||
709 - inode->i_ino == EXT2_ACL_DATA_INO)
710 - /* Nothing to do */ ;
711 - else if (S_ISREG(inode->i_mode)) {
712 + if (S_ISREG(inode->i_mode)) {
713 inode->i_op = &ext2_file_inode_operations;
714 inode->i_fop = &ext2_file_operations;
715 inode->i_mapping->a_ops = &ext2_aops;
716 @@ -1001,15 +1009,17 @@ void ext2_read_inode (struct inode * ino
717 inode->i_fop = &ext2_dir_operations;
718 inode->i_mapping->a_ops = &ext2_aops;
719 } else if (S_ISLNK(inode->i_mode)) {
720 - if (!inode->i_blocks)
721 + if (ext2_inode_is_fast_symlink(inode))
722 inode->i_op = &ext2_fast_symlink_inode_operations;
724 - inode->i_op = &page_symlink_inode_operations;
725 + inode->i_op = &ext2_symlink_inode_operations;
726 inode->i_mapping->a_ops = &ext2_aops;
730 + inode->i_op = &ext2_special_inode_operations;
731 init_special_inode(inode, inode->i_mode,
732 le32_to_cpu(raw_inode->i_block[0]));
735 inode->i_attr_flags = 0;
736 ext2_set_inode_flags(inode);
737 --- linux-2.4.22-ac1/fs/ext2/Makefile~xattr-0.8.54-2.4.22-rh 2001-10-11 19:05:18.000000000 +0400
738 +++ linux-2.4.22-ac1-alexey/fs/ext2/Makefile 2003-09-25 23:57:02.000000000 +0400
739 @@ -13,4 +13,8 @@ obj-y := balloc.o bitmap.o dir.o file
740 ioctl.o namei.o super.o symlink.o
743 +export-objs += xattr.o
744 +obj-$(CONFIG_EXT2_FS_XATTR) += xattr.o
745 +obj-$(CONFIG_EXT2_FS_XATTR_USER) += xattr_user.o
747 include $(TOPDIR)/Rules.make
748 --- linux-2.4.22-ac1/fs/ext2/namei.c~xattr-0.8.54-2.4.22-rh 2001-10-04 09:57:36.000000000 +0400
749 +++ linux-2.4.22-ac1-alexey/fs/ext2/namei.c 2003-09-25 23:57:02.000000000 +0400
752 #include <linux/fs.h>
753 #include <linux/ext2_fs.h>
754 +#include <linux/ext2_xattr.h>
755 #include <linux/pagemap.h>
758 @@ -136,7 +137,7 @@ static int ext2_symlink (struct inode *
760 if (l > sizeof (inode->u.ext2_i.i_data)) {
762 - inode->i_op = &page_symlink_inode_operations;
763 + inode->i_op = &ext2_symlink_inode_operations;
764 inode->i_mapping->a_ops = &ext2_aops;
765 err = block_symlink(inode, symname, l);
767 @@ -345,4 +346,15 @@ struct inode_operations ext2_dir_inode_o
771 + setxattr: ext2_setxattr,
772 + getxattr: ext2_getxattr,
773 + listxattr: ext2_listxattr,
774 + removexattr: ext2_removexattr,
777 +struct inode_operations ext2_special_inode_operations = {
778 + setxattr: ext2_setxattr,
779 + getxattr: ext2_getxattr,
780 + listxattr: ext2_listxattr,
781 + removexattr: ext2_removexattr,
783 --- linux-2.4.22-ac1/fs/ext2/super.c~xattr-0.8.54-2.4.22-rh 2002-11-29 02:53:15.000000000 +0300
784 +++ linux-2.4.22-ac1-alexey/fs/ext2/super.c 2003-09-25 23:57:02.000000000 +0400
786 #include <linux/string.h>
787 #include <linux/fs.h>
788 #include <linux/ext2_fs.h>
789 +#include <linux/ext2_xattr.h>
790 #include <linux/slab.h>
791 #include <linux/init.h>
792 #include <linux/locks.h>
793 @@ -125,6 +126,7 @@ void ext2_put_super (struct super_block
797 + ext2_xattr_put_super(sb);
798 if (!(sb->s_flags & MS_RDONLY)) {
799 struct ext2_super_block *es = EXT2_SB(sb)->s_es;
801 @@ -175,6 +177,13 @@ static int parse_options (char * options
802 this_char = strtok (NULL, ",")) {
803 if ((value = strchr (this_char, '=')) != NULL)
805 +#ifdef CONFIG_EXT2_FS_XATTR_USER
806 + if (!strcmp (this_char, "user_xattr"))
807 + set_opt (*mount_options, XATTR_USER);
808 + else if (!strcmp (this_char, "nouser_xattr"))
809 + clear_opt (*mount_options, XATTR_USER);
812 if (!strcmp (this_char, "bsddf"))
813 clear_opt (*mount_options, MINIX_DF);
814 else if (!strcmp (this_char, "nouid32")) {
815 @@ -424,6 +433,9 @@ struct super_block * ext2_read_super (st
816 blocksize = BLOCK_SIZE;
818 sb->u.ext2_sb.s_mount_opt = 0;
819 +#ifdef CONFIG_EXT2_FS_XATTR_USER
820 + /* set_opt (sb->u.ext2_sb.s_mount_opt, XATTR_USER); */
822 if (!parse_options ((char *) data, &sb_block, &resuid, &resgid,
823 &sb->u.ext2_sb.s_mount_opt)) {
825 @@ -813,12 +825,27 @@ static DECLARE_FSTYPE_DEV(ext2_fs_type,
827 static int __init init_ext2_fs(void)
829 - return register_filesystem(&ext2_fs_type);
830 + int error = init_ext2_xattr();
833 + error = init_ext2_xattr_user();
836 + error = register_filesystem(&ext2_fs_type);
840 + exit_ext2_xattr_user();
846 static void __exit exit_ext2_fs(void)
848 unregister_filesystem(&ext2_fs_type);
849 + exit_ext2_xattr_user();
854 --- linux-2.4.22-ac1/fs/ext2/symlink.c~xattr-0.8.54-2.4.22-rh 2000-09-28 00:41:33.000000000 +0400
855 +++ linux-2.4.22-ac1-alexey/fs/ext2/symlink.c 2003-09-25 23:57:02.000000000 +0400
858 #include <linux/fs.h>
859 #include <linux/ext2_fs.h>
860 +#include <linux/ext2_xattr.h>
862 static int ext2_readlink(struct dentry *dentry, char *buffer, int buflen)
864 @@ -32,7 +33,20 @@ static int ext2_follow_link(struct dentr
865 return vfs_follow_link(nd, s);
868 +struct inode_operations ext2_symlink_inode_operations = {
869 + readlink: page_readlink,
870 + follow_link: page_follow_link,
871 + setxattr: ext2_setxattr,
872 + getxattr: ext2_getxattr,
873 + listxattr: ext2_listxattr,
874 + removexattr: ext2_removexattr,
877 struct inode_operations ext2_fast_symlink_inode_operations = {
878 readlink: ext2_readlink,
879 follow_link: ext2_follow_link,
880 + setxattr: ext2_setxattr,
881 + getxattr: ext2_getxattr,
882 + listxattr: ext2_listxattr,
883 + removexattr: ext2_removexattr,
885 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
886 +++ linux-2.4.22-ac1-alexey/fs/ext2/xattr.c 2003-09-25 23:57:02.000000000 +0400
889 + * linux/fs/ext2/xattr.c
891 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
893 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
894 + * Extended attributes for symlinks and special files added per
895 + * suggestion of Luka Renko <luka.renko@hermes.si>.
899 + * Extended attributes are stored on disk blocks allocated outside of
900 + * any inode. The i_file_acl field is then made to point to this allocated
901 + * block. If all extended attributes of an inode are identical, these
902 + * inodes may share the same extended attribute block. Such situations
903 + * are automatically detected by keeping a cache of recent attribute block
904 + * numbers and hashes over the block's contents in memory.
907 + * Extended attribute block layout:
909 + * +------------------+
912 + * | entry 2 | | growing downwards
914 + * | four null bytes |
917 + * | value 3 | | growing upwards
919 + * +------------------+
921 + * The block header is followed by multiple entry descriptors. These entry
922 + * descriptors are variable in size, and alligned to EXT2_XATTR_PAD
923 + * byte boundaries. The entry descriptors are sorted by attribute name,
924 + * so that two extended attribute blocks can be compared efficiently.
926 + * Attribute values are aligned to the end of the block, stored in
927 + * no specific order. They are also padded to EXT2_XATTR_PAD byte
928 + * boundaries. No additional gaps are left between them.
932 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
933 + * the xattr inode operations are called, so we are guaranteed that only one
934 + * processes accesses extended attributes of an inode at any time.
936 + * For writing we also grab the ext2_xattr_sem semaphore. This ensures that
937 + * only a single process is modifying an extended attribute block, even
938 + * if the block is shared among inodes.
940 + * Note for porting to 2.5
941 + * -----------------------
942 + * The BKL will no longer be held in the xattr inode operations.
945 +#include <linux/module.h>
946 +#include <linux/locks.h>
947 +#include <linux/slab.h>
948 +#include <linux/fs.h>
949 +#include <linux/ext2_fs.h>
950 +#include <linux/ext2_xattr.h>
951 +#include <linux/mbcache.h>
952 +#include <linux/quotaops.h>
953 +#include <asm/semaphore.h>
954 +#include <linux/compatmac.h>
956 +/* These symbols may be needed by a module. */
957 +EXPORT_SYMBOL(ext2_xattr_register);
958 +EXPORT_SYMBOL(ext2_xattr_unregister);
959 +EXPORT_SYMBOL(ext2_xattr_get);
960 +EXPORT_SYMBOL(ext2_xattr_list);
961 +EXPORT_SYMBOL(ext2_xattr_set);
963 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
964 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
967 +#define HDR(bh) ((struct ext2_xattr_header *)((bh)->b_data))
968 +#define ENTRY(ptr) ((struct ext2_xattr_entry *)(ptr))
969 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
970 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
972 +#ifdef EXT2_XATTR_DEBUG
973 +# define ea_idebug(inode, f...) do { \
974 + printk(KERN_DEBUG "inode %s:%ld: ", \
975 + kdevname(inode->i_dev), inode->i_ino); \
979 +# define ea_bdebug(bh, f...) do { \
980 + printk(KERN_DEBUG "block %s:%ld: ", \
981 + kdevname(bh->b_dev), bh->b_blocknr); \
986 +# define ea_idebug(f...)
987 +# define ea_bdebug(f...)
990 +static int ext2_xattr_set2(struct inode *, struct buffer_head *,
991 + struct ext2_xattr_header *);
993 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
995 +static int ext2_xattr_cache_insert(struct buffer_head *);
996 +static struct buffer_head *ext2_xattr_cache_find(struct inode *,
997 + struct ext2_xattr_header *);
998 +static void ext2_xattr_cache_remove(struct buffer_head *);
999 +static void ext2_xattr_rehash(struct ext2_xattr_header *,
1000 + struct ext2_xattr_entry *);
1002 +static struct mb_cache *ext2_xattr_cache;
1005 +# define ext2_xattr_cache_insert(bh) 0
1006 +# define ext2_xattr_cache_find(inode, header) NULL
1007 +# define ext2_xattr_cache_remove(bh) while(0) {}
1008 +# define ext2_xattr_rehash(header, entry) while(0) {}
1012 + * If a file system does not share extended attributes among inodes,
1013 + * we should not need the ext2_xattr_sem semaphore. However, the
1014 + * filesystem may still contain shared blocks, so we always take
1018 +DECLARE_MUTEX(ext2_xattr_sem);
1021 +ext2_xattr_new_block(struct inode *inode, int * errp, int force)
1023 + struct super_block *sb = inode->i_sb;
1024 + int goal = le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block) +
1025 + EXT2_I(inode)->i_block_group * EXT2_BLOCKS_PER_GROUP(sb);
1027 + /* How can we enforce the allocation? */
1028 + int block = ext2_new_block(inode, goal, 0, 0, errp);
1031 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
1037 +ext2_xattr_quota_alloc(struct inode *inode, int force)
1039 + /* How can we enforce the allocation? */
1041 + int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
1043 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
1045 + int error = DQUOT_ALLOC_BLOCK(inode, 1);
1053 +ext2_xattr_quota_free(struct inode *inode)
1055 + DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
1056 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
1060 +ext2_xattr_free_block(struct inode * inode, unsigned long block)
1062 + ext2_free_blocks(inode, block, 1);
1063 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
1067 +# define ext2_xattr_quota_free(inode) \
1068 + DQUOT_FREE_BLOCK(inode, 1)
1069 +# define ext2_xattr_free_block(inode, block) \
1070 + ext2_free_blocks(inode, block, 1)
1073 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
1075 +static inline struct buffer_head *
1076 +sb_bread(struct super_block *sb, int block)
1078 + return bread(sb->s_dev, block, sb->s_blocksize);
1081 +static inline struct buffer_head *
1082 +sb_getblk(struct super_block *sb, int block)
1084 + return getblk(sb->s_dev, block, sb->s_blocksize);
1089 +struct ext2_xattr_handler *ext2_xattr_handlers[EXT2_XATTR_INDEX_MAX];
1090 +rwlock_t ext2_handler_lock = RW_LOCK_UNLOCKED;
1093 +ext2_xattr_register(int name_index, struct ext2_xattr_handler *handler)
1095 + int error = -EINVAL;
1097 + if (name_index > 0 && name_index <= EXT2_XATTR_INDEX_MAX) {
1098 + write_lock(&ext2_handler_lock);
1099 + if (!ext2_xattr_handlers[name_index-1]) {
1100 + ext2_xattr_handlers[name_index-1] = handler;
1103 + write_unlock(&ext2_handler_lock);
1109 +ext2_xattr_unregister(int name_index, struct ext2_xattr_handler *handler)
1111 + if (name_index > 0 || name_index <= EXT2_XATTR_INDEX_MAX) {
1112 + write_lock(&ext2_handler_lock);
1113 + ext2_xattr_handlers[name_index-1] = NULL;
1114 + write_unlock(&ext2_handler_lock);
1118 +static inline const char *
1119 +strcmp_prefix(const char *a, const char *a_prefix)
1121 + while (*a_prefix && *a == *a_prefix) {
1125 + return *a_prefix ? NULL : a;
1129 + * Decode the extended attribute name, and translate it into
1130 + * the name_index and name suffix.
1132 +static struct ext2_xattr_handler *
1133 +ext2_xattr_resolve_name(const char **name)
1135 + struct ext2_xattr_handler *handler = NULL;
1140 + read_lock(&ext2_handler_lock);
1141 + for (i=0; i<EXT2_XATTR_INDEX_MAX; i++) {
1142 + if (ext2_xattr_handlers[i]) {
1143 + const char *n = strcmp_prefix(*name,
1144 + ext2_xattr_handlers[i]->prefix);
1146 + handler = ext2_xattr_handlers[i];
1152 + read_unlock(&ext2_handler_lock);
1156 +static inline struct ext2_xattr_handler *
1157 +ext2_xattr_handler(int name_index)
1159 + struct ext2_xattr_handler *handler = NULL;
1160 + if (name_index > 0 && name_index <= EXT2_XATTR_INDEX_MAX) {
1161 + read_lock(&ext2_handler_lock);
1162 + handler = ext2_xattr_handlers[name_index-1];
1163 + read_unlock(&ext2_handler_lock);
1169 + * Inode operation getxattr()
1171 + * dentry->d_inode->i_sem down
1172 + * BKL held [before 2.5.x]
1175 +ext2_getxattr(struct dentry *dentry, const char *name,
1176 + void *buffer, size_t size)
1178 + struct ext2_xattr_handler *handler;
1179 + struct inode *inode = dentry->d_inode;
1181 + handler = ext2_xattr_resolve_name(&name);
1184 + return handler->get(inode, name, buffer, size);
1188 + * Inode operation listxattr()
1190 + * dentry->d_inode->i_sem down
1191 + * BKL held [before 2.5.x]
1194 +ext2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1196 + return ext2_xattr_list(dentry->d_inode, buffer, size);
1200 + * Inode operation setxattr()
1202 + * dentry->d_inode->i_sem down
1203 + * BKL held [before 2.5.x]
1206 +ext2_setxattr(struct dentry *dentry, const char *name,
1207 + const void *value, size_t size, int flags)
1209 + struct ext2_xattr_handler *handler;
1210 + struct inode *inode = dentry->d_inode;
1213 + value = ""; /* empty EA, do not remove */
1214 + handler = ext2_xattr_resolve_name(&name);
1217 + return handler->set(inode, name, value, size, flags);
1221 + * Inode operation removexattr()
1223 + * dentry->d_inode->i_sem down
1224 + * BKL held [before 2.5.x]
1227 +ext2_removexattr(struct dentry *dentry, const char *name)
1229 + struct ext2_xattr_handler *handler;
1230 + struct inode *inode = dentry->d_inode;
1232 + handler = ext2_xattr_resolve_name(&name);
1235 + return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
1239 + * ext2_xattr_get()
1241 + * Copy an extended attribute into the buffer
1242 + * provided, or compute the buffer size required.
1243 + * Buffer is NULL to compute the size of the buffer required.
1245 + * Returns a negative error number on failure, or the number of bytes
1246 + * used / required on success.
1249 +ext2_xattr_get(struct inode *inode, int name_index, const char *name,
1250 + void *buffer, size_t buffer_size)
1252 + struct buffer_head *bh = NULL;
1253 + struct ext2_xattr_entry *entry;
1254 + unsigned int block, size;
1256 + int name_len, error;
1258 + ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
1259 + name_index, name, buffer, (long)buffer_size);
1263 + if (!EXT2_I(inode)->i_file_acl)
1265 + block = EXT2_I(inode)->i_file_acl;
1266 + ea_idebug(inode, "reading block %d", block);
1267 + bh = sb_bread(inode->i_sb, block);
1270 + ea_bdebug(bh, "b_count=%d, refcount=%d",
1271 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
1272 + end = bh->b_data + bh->b_size;
1273 + if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1274 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1275 +bad_block: ext2_error(inode->i_sb, "ext2_xattr_get",
1276 + "inode %ld: bad block %d", inode->i_ino, block);
1280 + /* find named attribute */
1281 + name_len = strlen(name);
1284 + if (name_len > 255)
1286 + entry = FIRST_ENTRY(bh);
1287 + while (!IS_LAST_ENTRY(entry)) {
1288 + struct ext2_xattr_entry *next =
1289 + EXT2_XATTR_NEXT(entry);
1290 + if ((char *)next >= end)
1292 + if (name_index == entry->e_name_index &&
1293 + name_len == entry->e_name_len &&
1294 + memcmp(name, entry->e_name, name_len) == 0)
1298 + /* Check the remaining name entries */
1299 + while (!IS_LAST_ENTRY(entry)) {
1300 + struct ext2_xattr_entry *next =
1301 + EXT2_XATTR_NEXT(entry);
1302 + if ((char *)next >= end)
1306 + if (ext2_xattr_cache_insert(bh))
1307 + ea_idebug(inode, "cache insert failed");
1311 + /* check the buffer size */
1312 + if (entry->e_value_block != 0)
1314 + size = le32_to_cpu(entry->e_value_size);
1315 + if (size > inode->i_sb->s_blocksize ||
1316 + le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
1319 + if (ext2_xattr_cache_insert(bh))
1320 + ea_idebug(inode, "cache insert failed");
1323 + if (size > buffer_size)
1325 + /* return value of attribute */
1326 + memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
1338 + * ext2_xattr_list()
1340 + * Copy a list of attribute names into the buffer
1341 + * provided, or compute the buffer size required.
1342 + * Buffer is NULL to compute the size of the buffer required.
1344 + * Returns a negative error number on failure, or the number of bytes
1345 + * used / required on success.
1348 +ext2_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
1350 + struct buffer_head *bh = NULL;
1351 + struct ext2_xattr_entry *entry;
1352 + unsigned int block, size = 0;
1356 + ea_idebug(inode, "buffer=%p, buffer_size=%ld",
1357 + buffer, (long)buffer_size);
1359 + if (!EXT2_I(inode)->i_file_acl)
1361 + block = EXT2_I(inode)->i_file_acl;
1362 + ea_idebug(inode, "reading block %d", block);
1363 + bh = sb_bread(inode->i_sb, block);
1366 + ea_bdebug(bh, "b_count=%d, refcount=%d",
1367 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
1368 + end = bh->b_data + bh->b_size;
1369 + if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1370 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1371 +bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
1372 + "inode %ld: bad block %d", inode->i_ino, block);
1376 + /* compute the size required for the list of attribute names */
1377 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
1378 + entry = EXT2_XATTR_NEXT(entry)) {
1379 + struct ext2_xattr_handler *handler;
1380 + struct ext2_xattr_entry *next =
1381 + EXT2_XATTR_NEXT(entry);
1382 + if ((char *)next >= end)
1385 + handler = ext2_xattr_handler(entry->e_name_index);
1387 + size += handler->list(NULL, inode, entry->e_name,
1388 + entry->e_name_len);
1391 + if (ext2_xattr_cache_insert(bh))
1392 + ea_idebug(inode, "cache insert failed");
1398 + if (size > buffer_size)
1402 + /* list the attribute names */
1404 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
1405 + entry = EXT2_XATTR_NEXT(entry)) {
1406 + struct ext2_xattr_handler *handler;
1408 + handler = ext2_xattr_handler(entry->e_name_index);
1410 + buf += handler->list(buf, inode, entry->e_name,
1411 + entry->e_name_len);
1422 + * If the EXT2_FEATURE_COMPAT_EXT_ATTR feature of this file system is
1423 + * not set, set it.
1425 +static void ext2_xattr_update_super_block(struct super_block *sb)
1427 + if (EXT2_HAS_COMPAT_FEATURE(sb, EXT2_FEATURE_COMPAT_EXT_ATTR))
1431 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
1432 + EXT2_SB(sb)->s_feature_compat |= EXT2_FEATURE_COMPAT_EXT_ATTR;
1434 + EXT2_SB(sb)->s_es->s_feature_compat |=
1435 + cpu_to_le32(EXT2_FEATURE_COMPAT_EXT_ATTR);
1437 + mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
1442 + * ext2_xattr_set()
1444 + * Create, replace or remove an extended attribute for this inode. Buffer
1445 + * is NULL to remove an existing extended attribute, and non-NULL to
1446 + * either replace an existing extended attribute, or create a new extended
1447 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
1448 + * specify that an extended attribute must exist and must not exist
1449 + * previous to the call, respectively.
1451 + * Returns 0, or a negative error number on failure.
1454 +ext2_xattr_set(struct inode *inode, int name_index, const char *name,
1455 + const void *value, size_t value_len, int flags)
1457 + struct super_block *sb = inode->i_sb;
1458 + struct buffer_head *bh = NULL;
1459 + struct ext2_xattr_header *header = NULL;
1460 + struct ext2_xattr_entry *here, *last;
1461 + unsigned int name_len;
1462 + int block = EXT2_I(inode)->i_file_acl;
1463 + int min_offs = sb->s_blocksize, not_found = 1, free, error;
1467 + * header -- Points either into bh, or to a temporarily
1468 + * allocated buffer.
1469 + * here -- The named entry found, or the place for inserting, within
1470 + * the block pointed to by header.
1471 + * last -- Points right after the last named entry within the block
1472 + * pointed to by header.
1473 + * min_offs -- The offset of the first value (values are aligned
1474 + * towards the end of the block).
1475 + * end -- Points right after the block pointed to by header.
1478 + ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
1479 + name_index, name, value, (long)value_len);
1481 + if (IS_RDONLY(inode))
1483 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1485 + if (value == NULL)
1489 + name_len = strlen(name);
1490 + if (name_len > 255 || value_len > sb->s_blocksize)
1492 + down(&ext2_xattr_sem);
1495 + /* The inode already has an extended attribute block. */
1497 + bh = sb_bread(sb, block);
1501 + ea_bdebug(bh, "b_count=%d, refcount=%d",
1502 + atomic_read(&(bh->b_count)),
1503 + le32_to_cpu(HDR(bh)->h_refcount));
1505 + end = bh->b_data + bh->b_size;
1506 + if (header->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1507 + header->h_blocks != cpu_to_le32(1)) {
1508 +bad_block: ext2_error(sb, "ext2_xattr_set",
1509 + "inode %ld: bad block %d", inode->i_ino, block);
1513 + /* Find the named attribute. */
1514 + here = FIRST_ENTRY(bh);
1515 + while (!IS_LAST_ENTRY(here)) {
1516 + struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(here);
1517 + if ((char *)next >= end)
1519 + if (!here->e_value_block && here->e_value_size) {
1520 + int offs = le16_to_cpu(here->e_value_offs);
1521 + if (offs < min_offs)
1524 + not_found = name_index - here->e_name_index;
1526 + not_found = name_len - here->e_name_len;
1528 + not_found = memcmp(name, here->e_name,name_len);
1529 + if (not_found <= 0)
1534 + /* We still need to compute min_offs and last. */
1535 + while (!IS_LAST_ENTRY(last)) {
1536 + struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(last);
1537 + if ((char *)next >= end)
1539 + if (!last->e_value_block && last->e_value_size) {
1540 + int offs = le16_to_cpu(last->e_value_offs);
1541 + if (offs < min_offs)
1547 + /* Check whether we have enough space left. */
1548 + free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
1550 + /* We will use a new extended attribute block. */
1551 + free = sb->s_blocksize -
1552 + sizeof(struct ext2_xattr_header) - sizeof(__u32);
1553 + here = last = NULL; /* avoid gcc uninitialized warning. */
1557 + /* Request to remove a nonexistent attribute? */
1559 + if (flags & XATTR_REPLACE)
1562 + if (value == NULL)
1565 + free -= EXT2_XATTR_LEN(name_len);
1567 + /* Request to create an existing attribute? */
1569 + if (flags & XATTR_CREATE)
1571 + if (!here->e_value_block && here->e_value_size) {
1572 + unsigned int size = le32_to_cpu(here->e_value_size);
1574 + if (le16_to_cpu(here->e_value_offs) + size >
1575 + sb->s_blocksize || size > sb->s_blocksize)
1577 + free += EXT2_XATTR_SIZE(size);
1580 + free -= EXT2_XATTR_SIZE(value_len);
1585 + /* Here we know that we can set the new attribute. */
1588 + if (header->h_refcount == cpu_to_le32(1)) {
1589 + ea_bdebug(bh, "modifying in-place");
1590 + ext2_xattr_cache_remove(bh);
1594 + ea_bdebug(bh, "cloning");
1595 + header = kmalloc(bh->b_size, GFP_KERNEL);
1597 + if (header == NULL)
1599 + memcpy(header, HDR(bh), bh->b_size);
1600 + header->h_refcount = cpu_to_le32(1);
1601 + offset = (char *)header - bh->b_data;
1602 + here = ENTRY((char *)here + offset);
1603 + last = ENTRY((char *)last + offset);
1606 + /* Allocate a buffer where we construct the new block. */
1607 + header = kmalloc(sb->s_blocksize, GFP_KERNEL);
1609 + if (header == NULL)
1611 + memset(header, 0, sb->s_blocksize);
1612 + end = (char *)header + sb->s_blocksize;
1613 + header->h_magic = cpu_to_le32(EXT2_XATTR_MAGIC);
1614 + header->h_blocks = header->h_refcount = cpu_to_le32(1);
1615 + last = here = ENTRY(header+1);
1619 + /* Insert the new name. */
1620 + int size = EXT2_XATTR_LEN(name_len);
1621 + int rest = (char *)last - (char *)here;
1622 + memmove((char *)here + size, here, rest);
1623 + memset(here, 0, size);
1624 + here->e_name_index = name_index;
1625 + here->e_name_len = name_len;
1626 + memcpy(here->e_name, name, name_len);
1628 + /* Remove the old value. */
1629 + if (!here->e_value_block && here->e_value_size) {
1630 + char *first_val = (char *)header + min_offs;
1631 + int offs = le16_to_cpu(here->e_value_offs);
1632 + char *val = (char *)header + offs;
1633 + size_t size = EXT2_XATTR_SIZE(
1634 + le32_to_cpu(here->e_value_size));
1635 + memmove(first_val + size, first_val, val - first_val);
1636 + memset(first_val, 0, size);
1637 + here->e_value_offs = 0;
1640 + /* Adjust all value offsets. */
1641 + last = ENTRY(header+1);
1642 + while (!IS_LAST_ENTRY(last)) {
1643 + int o = le16_to_cpu(last->e_value_offs);
1644 + if (!last->e_value_block && o < offs)
1645 + last->e_value_offs =
1646 + cpu_to_le16(o + size);
1647 + last = EXT2_XATTR_NEXT(last);
1650 + if (value == NULL) {
1651 + /* Remove this attribute. */
1652 + if (EXT2_XATTR_NEXT(ENTRY(header+1)) == last) {
1653 + /* This block is now empty. */
1654 + error = ext2_xattr_set2(inode, bh, NULL);
1657 + /* Remove the old name. */
1658 + int size = EXT2_XATTR_LEN(name_len);
1659 + last = ENTRY((char *)last - size);
1660 + memmove(here, (char*)here + size,
1661 + (char*)last - (char*)here);
1662 + memset(last, 0, size);
1667 + if (value != NULL) {
1668 + /* Insert the new value. */
1669 + here->e_value_size = cpu_to_le32(value_len);
1671 + size_t size = EXT2_XATTR_SIZE(value_len);
1672 + char *val = (char *)header + min_offs - size;
1673 + here->e_value_offs =
1674 + cpu_to_le16((char *)val - (char *)header);
1675 + memset(val + size - EXT2_XATTR_PAD, 0,
1676 + EXT2_XATTR_PAD); /* Clear the pad bytes. */
1677 + memcpy(val, value, value_len);
1680 + ext2_xattr_rehash(header, here);
1682 + error = ext2_xattr_set2(inode, bh, header);
1686 + if (!(bh && header == HDR(bh)))
1688 + up(&ext2_xattr_sem);
1694 + * Second half of ext2_xattr_set(): Update the file system.
1697 +ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
1698 + struct ext2_xattr_header *header)
1700 + struct super_block *sb = inode->i_sb;
1701 + struct buffer_head *new_bh = NULL;
1705 + new_bh = ext2_xattr_cache_find(inode, header);
1708 + * We found an identical block in the cache.
1709 + * The old block will be released after updating
1712 + ea_bdebug(old_bh, "reusing block %ld",
1713 + new_bh->b_blocknr);
1716 + if (ext2_xattr_quota_alloc(inode, 1))
1719 + HDR(new_bh)->h_refcount = cpu_to_le32(
1720 + le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
1721 + ea_bdebug(new_bh, "refcount now=%d",
1722 + le32_to_cpu(HDR(new_bh)->h_refcount));
1723 + } else if (old_bh && header == HDR(old_bh)) {
1724 + /* Keep this block. */
1726 + ext2_xattr_cache_insert(new_bh);
1728 + /* We need to allocate a new block */
1729 + int force = EXT2_I(inode)->i_file_acl != 0;
1730 + int block = ext2_xattr_new_block(inode, &error, force);
1733 + ea_idebug(inode, "creating block %d", block);
1735 + new_bh = sb_getblk(sb, block);
1737 + ext2_xattr_free_block(inode, block);
1741 + lock_buffer(new_bh);
1742 + memcpy(new_bh->b_data, header, new_bh->b_size);
1743 + mark_buffer_uptodate(new_bh, 1);
1744 + unlock_buffer(new_bh);
1745 + ext2_xattr_cache_insert(new_bh);
1747 + ext2_xattr_update_super_block(sb);
1749 + mark_buffer_dirty(new_bh);
1750 + if (IS_SYNC(inode)) {
1751 + ll_rw_block(WRITE, 1, &new_bh);
1752 + wait_on_buffer(new_bh);
1754 + if (buffer_req(new_bh) && !buffer_uptodate(new_bh))
1759 + /* Update the inode. */
1760 + EXT2_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
1761 + inode->i_ctime = CURRENT_TIME;
1762 + if (IS_SYNC(inode)) {
1763 + error = ext2_sync_inode (inode);
1767 + mark_inode_dirty(inode);
1770 + if (old_bh && old_bh != new_bh) {
1772 + * If there was an old block, and we are not still using it,
1773 + * we now release the old block.
1775 + unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
1777 + if (refcount == 1) {
1778 + /* Free the old block. */
1779 + ea_bdebug(old_bh, "freeing");
1780 + ext2_xattr_free_block(inode, old_bh->b_blocknr);
1781 + mark_buffer_clean(old_bh);
1783 + /* Decrement the refcount only. */
1785 + HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
1786 + ext2_xattr_quota_free(inode);
1787 + mark_buffer_dirty(old_bh);
1788 + ea_bdebug(old_bh, "refcount now=%d", refcount);
1793 + if (old_bh != new_bh)
1800 + * ext2_xattr_delete_inode()
1802 + * Free extended attribute resources associated with this inode. This
1803 + * is called immediately before an inode is freed.
1806 +ext2_xattr_delete_inode(struct inode *inode)
1808 + struct buffer_head *bh;
1809 + unsigned int block = EXT2_I(inode)->i_file_acl;
1813 + down(&ext2_xattr_sem);
1815 + bh = sb_bread(inode->i_sb, block);
1817 + ext2_error(inode->i_sb, "ext2_xattr_delete_inode",
1818 + "inode %ld: block %d read error", inode->i_ino, block);
1821 + ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
1822 + if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1823 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1824 + ext2_error(inode->i_sb, "ext2_xattr_delete_inode",
1825 + "inode %ld: bad block %d", inode->i_ino, block);
1828 + ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
1829 + if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
1830 + ext2_xattr_cache_remove(bh);
1831 + ext2_xattr_free_block(inode, block);
1835 + HDR(bh)->h_refcount = cpu_to_le32(
1836 + le32_to_cpu(HDR(bh)->h_refcount) - 1);
1837 + mark_buffer_dirty(bh);
1838 + if (IS_SYNC(inode)) {
1839 + ll_rw_block(WRITE, 1, &bh);
1840 + wait_on_buffer(bh);
1842 + ext2_xattr_quota_free(inode);
1844 + EXT2_I(inode)->i_file_acl = 0;
1848 + up(&ext2_xattr_sem);
1852 + * ext2_xattr_put_super()
1854 + * This is called when a file system is unmounted.
1857 +ext2_xattr_put_super(struct super_block *sb)
1859 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
1860 + mb_cache_shrink(ext2_xattr_cache, sb->s_dev);
1864 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
1867 + * ext2_xattr_cache_insert()
1869 + * Create a new entry in the extended attribute cache, and insert
1870 + * it unless such an entry is already in the cache.
1872 + * Returns 0, or a negative error number on failure.
1875 +ext2_xattr_cache_insert(struct buffer_head *bh)
1877 + __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
1878 + struct mb_cache_entry *ce;
1881 + ce = mb_cache_entry_alloc(ext2_xattr_cache);
1884 + error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
1886 + mb_cache_entry_free(ce);
1887 + if (error == -EBUSY) {
1888 + ea_bdebug(bh, "already in cache (%d cache entries)",
1889 + atomic_read(&ext2_xattr_cache->c_entry_count));
1893 + ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
1894 + atomic_read(&ext2_xattr_cache->c_entry_count));
1895 + mb_cache_entry_release(ce);
1901 + * ext2_xattr_cmp()
1903 + * Compare two extended attribute blocks for equality.
1905 + * Returns 0 if the blocks are equal, 1 if they differ, and
1906 + * a negative error number on errors.
1909 +ext2_xattr_cmp(struct ext2_xattr_header *header1,
1910 + struct ext2_xattr_header *header2)
1912 + struct ext2_xattr_entry *entry1, *entry2;
1914 + entry1 = ENTRY(header1+1);
1915 + entry2 = ENTRY(header2+1);
1916 + while (!IS_LAST_ENTRY(entry1)) {
1917 + if (IS_LAST_ENTRY(entry2))
1919 + if (entry1->e_hash != entry2->e_hash ||
1920 + entry1->e_name_len != entry2->e_name_len ||
1921 + entry1->e_value_size != entry2->e_value_size ||
1922 + memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
1924 + if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
1926 + if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
1927 + (char *)header2 + le16_to_cpu(entry2->e_value_offs),
1928 + le32_to_cpu(entry1->e_value_size)))
1931 + entry1 = EXT2_XATTR_NEXT(entry1);
1932 + entry2 = EXT2_XATTR_NEXT(entry2);
1934 + if (!IS_LAST_ENTRY(entry2))
1940 + * ext2_xattr_cache_find()
1942 + * Find an identical extended attribute block.
1944 + * Returns a pointer to the block found, or NULL if such a block was
1945 + * not found or an error occurred.
1947 +static struct buffer_head *
1948 +ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header)
1950 + __u32 hash = le32_to_cpu(header->h_hash);
1951 + struct mb_cache_entry *ce;
1953 + if (!header->h_hash)
1954 + return NULL; /* never share */
1955 + ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
1956 + ce = mb_cache_entry_find_first(ext2_xattr_cache, 0, inode->i_dev, hash);
1958 + struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
1961 + ext2_error(inode->i_sb, "ext2_xattr_cache_find",
1962 + "inode %ld: block %ld read error",
1963 + inode->i_ino, ce->e_block);
1964 + } else if (le32_to_cpu(HDR(bh)->h_refcount) >
1965 + EXT2_XATTR_REFCOUNT_MAX) {
1966 + ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
1967 + le32_to_cpu(HDR(bh)->h_refcount),
1968 + EXT2_XATTR_REFCOUNT_MAX);
1969 + } else if (!ext2_xattr_cmp(header, HDR(bh))) {
1970 + ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
1971 + mb_cache_entry_release(ce);
1975 + ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
1981 + * ext2_xattr_cache_remove()
1983 + * Remove the cache entry of a block from the cache. Called when a
1984 + * block becomes invalid.
1987 +ext2_xattr_cache_remove(struct buffer_head *bh)
1989 + struct mb_cache_entry *ce;
1991 + ce = mb_cache_entry_get(ext2_xattr_cache, bh->b_dev, bh->b_blocknr);
1993 + ea_bdebug(bh, "removing (%d cache entries remaining)",
1994 + atomic_read(&ext2_xattr_cache->c_entry_count)-1);
1995 + mb_cache_entry_free(ce);
1997 + ea_bdebug(bh, "no cache entry");
2000 +#define NAME_HASH_SHIFT 5
2001 +#define VALUE_HASH_SHIFT 16
2004 + * ext2_xattr_hash_entry()
2006 + * Compute the hash of an extended attribute.
2008 +static inline void ext2_xattr_hash_entry(struct ext2_xattr_header *header,
2009 + struct ext2_xattr_entry *entry)
2012 + char *name = entry->e_name;
2015 + for (n=0; n < entry->e_name_len; n++) {
2016 + hash = (hash << NAME_HASH_SHIFT) ^
2017 + (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
2021 + if (entry->e_value_block == 0 && entry->e_value_size != 0) {
2022 + __u32 *value = (__u32 *)((char *)header +
2023 + le16_to_cpu(entry->e_value_offs));
2024 + for (n = (le32_to_cpu(entry->e_value_size) +
2025 + EXT2_XATTR_ROUND) >> EXT2_XATTR_PAD_BITS; n; n--) {
2026 + hash = (hash << VALUE_HASH_SHIFT) ^
2027 + (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
2028 + le32_to_cpu(*value++);
2031 + entry->e_hash = cpu_to_le32(hash);
2034 +#undef NAME_HASH_SHIFT
2035 +#undef VALUE_HASH_SHIFT
2037 +#define BLOCK_HASH_SHIFT 16
2040 + * ext2_xattr_rehash()
2042 + * Re-compute the extended attribute hash value after an entry has changed.
2044 +static void ext2_xattr_rehash(struct ext2_xattr_header *header,
2045 + struct ext2_xattr_entry *entry)
2047 + struct ext2_xattr_entry *here;
2050 + ext2_xattr_hash_entry(header, entry);
2051 + here = ENTRY(header+1);
2052 + while (!IS_LAST_ENTRY(here)) {
2053 + if (!here->e_hash) {
2054 + /* Block is not shared if an entry's hash value == 0 */
2058 + hash = (hash << BLOCK_HASH_SHIFT) ^
2059 + (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
2060 + le32_to_cpu(here->e_hash);
2061 + here = EXT2_XATTR_NEXT(here);
2063 + header->h_hash = cpu_to_le32(hash);
2066 +#undef BLOCK_HASH_SHIFT
2069 +init_ext2_xattr(void)
2071 + ext2_xattr_cache = mb_cache_create("ext2_xattr", NULL,
2072 + sizeof(struct mb_cache_entry) +
2073 + sizeof(struct mb_cache_entry_index), 1, 61);
2074 + if (!ext2_xattr_cache)
2081 +exit_ext2_xattr(void)
2083 + mb_cache_destroy(ext2_xattr_cache);
2086 +#else /* CONFIG_EXT2_FS_XATTR_SHARING */
2089 +init_ext2_xattr(void)
2095 +exit_ext2_xattr(void)
2099 +#endif /* CONFIG_EXT2_FS_XATTR_SHARING */
2100 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
2101 +++ linux-2.4.22-ac1-alexey/fs/ext2/xattr_user.c 2003-09-25 23:57:02.000000000 +0400
2104 + * linux/fs/ext2/xattr_user.c
2105 + * Handler for extended user attributes.
2107 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
2110 +#include <linux/module.h>
2111 +#include <linux/string.h>
2112 +#include <linux/fs.h>
2113 +#include <linux/ext2_fs.h>
2114 +#include <linux/ext2_xattr.h>
2116 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
2117 +# include <linux/ext2_acl.h>
2120 +#define XATTR_USER_PREFIX "user."
2123 +ext2_xattr_user_list(char *list, struct inode *inode,
2124 + const char *name, int name_len)
2126 + const int prefix_len = sizeof(XATTR_USER_PREFIX)-1;
2128 + if (!test_opt(inode->i_sb, XATTR_USER))
2132 + memcpy(list, XATTR_USER_PREFIX, prefix_len);
2133 + memcpy(list+prefix_len, name, name_len);
2134 + list[prefix_len + name_len] = '\0';
2136 + return prefix_len + name_len + 1;
2140 +ext2_xattr_user_get(struct inode *inode, const char *name,
2141 + void *buffer, size_t size)
2145 + if (strcmp(name, "") == 0)
2147 + if (!test_opt(inode->i_sb, XATTR_USER))
2149 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
2150 + error = ext2_permission_locked(inode, MAY_READ);
2152 + error = permission(inode, MAY_READ);
2157 + return ext2_xattr_get(inode, EXT2_XATTR_INDEX_USER, name,
2162 +ext2_xattr_user_set(struct inode *inode, const char *name,
2163 + const void *value, size_t size, int flags)
2167 + if (strcmp(name, "") == 0)
2169 + if (!test_opt(inode->i_sb, XATTR_USER))
2171 + if ( !S_ISREG(inode->i_mode) &&
2172 + (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
2174 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
2175 + error = ext2_permission_locked(inode, MAY_WRITE);
2177 + error = permission(inode, MAY_WRITE);
2182 + return ext2_xattr_set(inode, EXT2_XATTR_INDEX_USER, name,
2183 + value, size, flags);
2186 +struct ext2_xattr_handler ext2_xattr_user_handler = {
2187 + prefix: XATTR_USER_PREFIX,
2188 + list: ext2_xattr_user_list,
2189 + get: ext2_xattr_user_get,
2190 + set: ext2_xattr_user_set,
2194 +init_ext2_xattr_user(void)
2196 + return ext2_xattr_register(EXT2_XATTR_INDEX_USER,
2197 + &ext2_xattr_user_handler);
2201 +exit_ext2_xattr_user(void)
2203 + ext2_xattr_unregister(EXT2_XATTR_INDEX_USER,
2204 + &ext2_xattr_user_handler);
2206 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
2207 +++ linux-2.4.22-ac1-alexey/fs/ext3/ext3-exports.c 2003-09-25 23:57:02.000000000 +0400
2209 +#include <linux/config.h>
2210 +#include <linux/module.h>
2211 +#include <linux/ext3_fs.h>
2212 +#include <linux/ext3_jbd.h>
2213 +#include <linux/ext3_xattr.h>
2215 +EXPORT_SYMBOL(ext3_force_commit);
2216 +EXPORT_SYMBOL(ext3_bread);
2217 +EXPORT_SYMBOL(ext3_xattr_register);
2218 +EXPORT_SYMBOL(ext3_xattr_unregister);
2219 +EXPORT_SYMBOL(ext3_xattr_get);
2220 +EXPORT_SYMBOL(ext3_xattr_list);
2221 +EXPORT_SYMBOL(ext3_xattr_set);
2222 --- linux-2.4.22-ac1/fs/ext3/file.c~xattr-0.8.54-2.4.22-rh 2003-09-25 14:55:12.000000000 +0400
2223 +++ linux-2.4.22-ac1-alexey/fs/ext3/file.c 2003-09-25 23:57:02.000000000 +0400
2225 #include <linux/locks.h>
2226 #include <linux/jbd.h>
2227 #include <linux/ext3_fs.h>
2228 +#include <linux/ext3_xattr.h>
2229 #include <linux/ext3_jbd.h>
2230 #include <linux/smp_lock.h>
2232 @@ -127,5 +128,9 @@ struct file_operations ext3_file_operati
2233 struct inode_operations ext3_file_inode_operations = {
2234 truncate: ext3_truncate, /* BKL held */
2235 setattr: ext3_setattr, /* BKL held */
2236 + setxattr: ext3_setxattr, /* BKL held */
2237 + getxattr: ext3_getxattr, /* BKL held */
2238 + listxattr: ext3_listxattr, /* BKL held */
2239 + removexattr: ext3_removexattr, /* BKL held */
2242 --- linux-2.4.22-ac1/fs/ext3/ialloc.c~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:29.000000000 +0400
2243 +++ linux-2.4.22-ac1-alexey/fs/ext3/ialloc.c 2003-09-25 23:57:02.000000000 +0400
2245 #include <linux/jbd.h>
2246 #include <linux/ext3_fs.h>
2247 #include <linux/ext3_jbd.h>
2248 +#include <linux/ext3_xattr.h>
2249 #include <linux/stat.h>
2250 #include <linux/string.h>
2251 #include <linux/locks.h>
2252 @@ -217,6 +218,7 @@ void ext3_free_inode (handle_t *handle,
2253 * as writing the quota to disk may need the lock as well.
2256 + ext3_xattr_delete_inode(handle, inode);
2257 DQUOT_FREE_INODE(inode);
2260 --- linux-2.4.22-ac1/fs/ext3/inode.c~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:29.000000000 +0400
2261 +++ linux-2.4.22-ac1-alexey/fs/ext3/inode.c 2003-09-26 00:10:09.000000000 +0400
2264 #undef SEARCH_FROM_ZERO
2267 + * Test whether an inode is a fast symlink.
2269 +static inline int ext3_inode_is_fast_symlink(struct inode *inode)
2271 + int ea_blocks = inode->u.ext3_i.i_file_acl ?
2272 + (inode->i_sb->s_blocksize >> 9) : 0;
2274 + return (S_ISLNK(inode->i_mode) &&
2275 + inode->i_blocks - ea_blocks == 0);
2278 /* The ext3 forget function must perform a revoke if we are freeing data
2279 * which has been journaled. Metadata (eg. indirect blocks) must be
2280 * revoked in all cases.
2282 * still needs to be revoked.
2285 -static int ext3_forget(handle_t *handle, int is_metadata,
2286 +int ext3_forget(handle_t *handle, int is_metadata,
2287 struct inode *inode, struct buffer_head *bh,
2290 @@ -179,9 +191,7 @@ void ext3_delete_inode (struct inode * i
2294 - if (is_bad_inode(inode) ||
2295 - inode->i_ino == EXT3_ACL_IDX_INO ||
2296 - inode->i_ino == EXT3_ACL_DATA_INO)
2297 + if (is_bad_inode(inode))
2301 @@ -1874,6 +1884,8 @@ void ext3_truncate(struct inode * inode)
2302 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
2303 S_ISLNK(inode->i_mode)))
2305 + if (ext3_inode_is_fast_symlink(inode))
2307 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2310 @@ -2021,8 +2033,6 @@ int ext3_get_inode_loc (struct inode *in
2311 struct ext3_group_desc * gdp;
2313 if ((inode->i_ino != EXT3_ROOT_INO &&
2314 - inode->i_ino != EXT3_ACL_IDX_INO &&
2315 - inode->i_ino != EXT3_ACL_DATA_INO &&
2316 inode->i_ino != EXT3_JOURNAL_INO &&
2317 inode->i_ino < EXT3_FIRST_INO(inode->i_sb)) ||
2318 inode->i_ino > le32_to_cpu(
2319 @@ -2163,10 +2173,7 @@ void ext3_read_inode(struct inode * inod
2320 inode->u.ext3_i.i_data[block] = iloc.raw_inode->i_block[block];
2321 INIT_LIST_HEAD(&inode->u.ext3_i.i_orphan);
2323 - if (inode->i_ino == EXT3_ACL_IDX_INO ||
2324 - inode->i_ino == EXT3_ACL_DATA_INO)
2325 - /* Nothing to do */ ;
2326 - else if (S_ISREG(inode->i_mode)) {
2327 + if (S_ISREG(inode->i_mode)) {
2328 inode->i_op = &ext3_file_inode_operations;
2329 inode->i_fop = &ext3_file_operations;
2330 inode->i_mapping->a_ops = &ext3_aops;
2331 @@ -2174,15 +2181,17 @@ void ext3_read_inode(struct inode * inod
2332 inode->i_op = &ext3_dir_inode_operations;
2333 inode->i_fop = &ext3_dir_operations;
2334 } else if (S_ISLNK(inode->i_mode)) {
2335 - if (!inode->i_blocks)
2336 + if (ext3_inode_is_fast_symlink(inode))
2337 inode->i_op = &ext3_fast_symlink_inode_operations;
2339 - inode->i_op = &page_symlink_inode_operations;
2340 + inode->i_op = &ext3_symlink_inode_operations;
2341 inode->i_mapping->a_ops = &ext3_aops;
2345 + inode->i_op = &ext3_special_inode_operations;
2346 init_special_inode(inode, inode->i_mode,
2347 le32_to_cpu(iloc.raw_inode->i_block[0]));
2350 ext3_set_inode_flags(inode);
2352 --- linux-2.4.22-ac1/fs/ext3/Makefile~xattr-0.8.54-2.4.22-rh 2003-09-25 14:55:12.000000000 +0400
2353 +++ linux-2.4.22-ac1-alexey/fs/ext3/Makefile 2003-09-25 23:57:02.000000000 +0400
2356 -# Makefile for the linux ext2-filesystem routines.
2357 +# Makefile for the linux ext3-filesystem routines.
2359 # Note! Dependencies are done automagically by 'make dep', which also
2360 # removes any old dependencies. DON'T put your own dependencies here
2365 -export-objs := super.o inode.o
2366 +export-objs := ext3-exports.o
2368 obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
2369 - ioctl.o namei.o super.o symlink.o hash.o
2370 + ioctl.o namei.o super.o symlink.o hash.o ext3-exports.o
2371 obj-m := $(O_TARGET)
2373 +export-objs += xattr.o
2374 +obj-$(CONFIG_EXT3_FS_XATTR) += xattr.o
2375 +obj-$(CONFIG_EXT3_FS_XATTR_USER) += xattr_user.o
2377 include $(TOPDIR)/Rules.make
2378 --- linux-2.4.22-ac1/fs/ext3/namei.c~xattr-0.8.54-2.4.22-rh 2003-09-25 14:58:37.000000000 +0400
2379 +++ linux-2.4.22-ac1-alexey/fs/ext3/namei.c 2003-09-25 23:57:02.000000000 +0400
2381 #include <linux/sched.h>
2382 #include <linux/ext3_fs.h>
2383 #include <linux/ext3_jbd.h>
2384 +#include <linux/ext3_xattr.h>
2385 #include <linux/fcntl.h>
2386 #include <linux/stat.h>
2387 #include <linux/string.h>
2388 @@ -1614,7 +1615,7 @@ static int ext3_mkdir(struct inode * dir
2392 - inode = ext3_new_inode (handle, dir, S_IFDIR);
2393 + inode = ext3_new_inode (handle, dir, S_IFDIR | mode);
2394 err = PTR_ERR(inode);
2397 @@ -1622,7 +1623,6 @@ static int ext3_mkdir(struct inode * dir
2398 inode->i_op = &ext3_dir_inode_operations;
2399 inode->i_fop = &ext3_dir_operations;
2400 inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
2401 - inode->i_blocks = 0;
2402 dir_block = ext3_bread (handle, inode, 0, 1, &err);
2404 inode->i_nlink--; /* is this nlink == 0? */
2405 @@ -1649,9 +1649,6 @@ static int ext3_mkdir(struct inode * dir
2406 BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata");
2407 ext3_journal_dirty_metadata(handle, dir_block);
2409 - inode->i_mode = S_IFDIR | mode;
2410 - if (dir->i_mode & S_ISGID)
2411 - inode->i_mode |= S_ISGID;
2412 ext3_mark_inode_dirty(handle, inode);
2413 err = ext3_add_entry (handle, dentry, inode);
2415 @@ -2020,7 +2017,7 @@ static int ext3_symlink (struct inode *
2418 if (l > sizeof (EXT3_I(inode)->i_data)) {
2419 - inode->i_op = &page_symlink_inode_operations;
2420 + inode->i_op = &ext3_symlink_inode_operations;
2421 inode->i_mapping->a_ops = &ext3_aops;
2423 * block_symlink() calls back into ext3_prepare/commit_write.
2424 @@ -2245,4 +2242,16 @@ struct inode_operations ext3_dir_inode_o
2425 rmdir: ext3_rmdir, /* BKL held */
2426 mknod: ext3_mknod, /* BKL held */
2427 rename: ext3_rename, /* BKL held */
2428 + setxattr: ext3_setxattr, /* BKL held */
2429 + getxattr: ext3_getxattr, /* BKL held */
2430 + listxattr: ext3_listxattr, /* BKL held */
2431 + removexattr: ext3_removexattr, /* BKL held */
2434 +struct inode_operations ext3_special_inode_operations = {
2435 + setxattr: ext3_setxattr, /* BKL held */
2436 + getxattr: ext3_getxattr, /* BKL held */
2437 + listxattr: ext3_listxattr, /* BKL held */
2438 + removexattr: ext3_removexattr, /* BKL held */
2441 --- linux-2.4.22-ac1/fs/ext3/super.c~xattr-0.8.54-2.4.22-rh 2003-09-25 14:55:12.000000000 +0400
2442 +++ linux-2.4.22-ac1-alexey/fs/ext3/super.c 2003-09-26 00:12:23.000000000 +0400
2444 #include <linux/jbd.h>
2445 #include <linux/ext3_fs.h>
2446 #include <linux/ext3_jbd.h>
2447 +#include <linux/ext3_xattr.h>
2448 #include <linux/slab.h>
2449 #include <linux/init.h>
2450 #include <linux/locks.h>
2451 @@ -406,6 +407,7 @@ void ext3_put_super (struct super_block
2452 kdev_t j_dev = sbi->s_journal->j_dev;
2455 + ext3_xattr_put_super(sb);
2456 journal_destroy(sbi->s_journal);
2457 if (!(sb->s_flags & MS_RDONLY)) {
2458 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
2459 @@ -506,6 +508,7 @@ static int parse_options (char * options
2462 unsigned long *mount_options = &sbi->s_mount_opt;
2464 uid_t *resuid = &sbi->s_resuid;
2465 gid_t *resgid = &sbi->s_resgid;
2467 @@ -518,6 +521,13 @@ static int parse_options (char * options
2468 this_char = strtok (NULL, ",")) {
2469 if ((value = strchr (this_char, '=')) != NULL)
2471 +#ifdef CONFIG_EXT3_FS_XATTR_USER
2472 + if (!strcmp (this_char, "user_xattr"))
2473 + set_opt (*mount_options, XATTR_USER);
2474 + else if (!strcmp (this_char, "nouser_xattr"))
2475 + clear_opt (*mount_options, XATTR_USER);
2478 if (!strcmp (this_char, "bsddf"))
2479 clear_opt (*mount_options, MINIX_DF);
2480 else if (!strcmp (this_char, "nouid32")) {
2481 @@ -935,6 +945,12 @@ struct super_block * ext3_read_super (st
2482 sbi->s_mount_opt = 0;
2483 sbi->s_resuid = EXT3_DEF_RESUID;
2484 sbi->s_resgid = EXT3_DEF_RESGID;
2486 + /* Default extended attribute flags */
2487 +#ifdef CONFIG_EXT3_FS_XATTR_USER
2488 + /* set_opt(sbi->s_mount_opt, XATTR_USER); */
2491 if (!parse_options ((char *) data, &sb_block, sbi, &journal_inum, 0)) {
2494 @@ -1839,22 +1855,35 @@ static DECLARE_FSTYPE_DEV(ext3_fs_type,
2496 static int __init init_ext3_fs(void)
2500 init_dquot_operations(&ext3_qops);
2501 old_sync_dquot = ext3_qops.sync_dquot;
2502 ext3_qops.sync_dquot = ext3_sync_dquot;
2504 - return register_filesystem(&ext3_fs_type);
2505 + error = init_ext3_xattr();
2508 + error = init_ext3_xattr_user();
2511 + error = register_filesystem(&ext3_fs_type);
2515 + exit_ext3_xattr_user();
2517 + exit_ext3_xattr();
2521 static void __exit exit_ext3_fs(void)
2523 unregister_filesystem(&ext3_fs_type);
2524 + exit_ext3_xattr_user();
2525 + exit_ext3_xattr();
2528 -EXPORT_SYMBOL(ext3_force_commit);
2529 -EXPORT_SYMBOL(ext3_bread);
2531 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
2532 MODULE_DESCRIPTION("Second Extended Filesystem with journaling extensions");
2533 MODULE_LICENSE("GPL");
2534 --- linux-2.4.22-ac1/fs/ext3/symlink.c~xattr-0.8.54-2.4.22-rh 2001-11-10 01:25:04.000000000 +0300
2535 +++ linux-2.4.22-ac1-alexey/fs/ext3/symlink.c 2003-09-25 23:57:02.000000000 +0400
2537 #include <linux/fs.h>
2538 #include <linux/jbd.h>
2539 #include <linux/ext3_fs.h>
2540 +#include <linux/ext3_xattr.h>
2542 static int ext3_readlink(struct dentry *dentry, char *buffer, int buflen)
2544 @@ -33,7 +34,20 @@ static int ext3_follow_link(struct dentr
2545 return vfs_follow_link(nd, s);
2548 +struct inode_operations ext3_symlink_inode_operations = {
2549 + readlink: page_readlink, /* BKL not held. Don't need */
2550 + follow_link: page_follow_link, /* BKL not held. Don't need */
2551 + setxattr: ext3_setxattr, /* BKL held */
2552 + getxattr: ext3_getxattr, /* BKL held */
2553 + listxattr: ext3_listxattr, /* BKL held */
2554 + removexattr: ext3_removexattr, /* BKL held */
2557 struct inode_operations ext3_fast_symlink_inode_operations = {
2558 readlink: ext3_readlink, /* BKL not held. Don't need */
2559 follow_link: ext3_follow_link, /* BKL not held. Don't need */
2560 + setxattr: ext3_setxattr, /* BKL held */
2561 + getxattr: ext3_getxattr, /* BKL held */
2562 + listxattr: ext3_listxattr, /* BKL held */
2563 + removexattr: ext3_removexattr, /* BKL held */
2565 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
2566 +++ linux-2.4.22-ac1-alexey/fs/ext3/xattr.c 2003-09-25 23:57:02.000000000 +0400
2569 + * linux/fs/ext3/xattr.c
2571 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
2573 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
2574 + * Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>.
2575 + * Extended attributes for symlinks and special files added per
2576 + * suggestion of Luka Renko <luka.renko@hermes.si>.
2580 + * Extended attributes are stored on disk blocks allocated outside of
2581 + * any inode. The i_file_acl field is then made to point to this allocated
2582 + * block. If all extended attributes of an inode are identical, these
2583 + * inodes may share the same extended attribute block. Such situations
2584 + * are automatically detected by keeping a cache of recent attribute block
2585 + * numbers and hashes over the block's contents in memory.
2588 + * Extended attribute block layout:
2590 + * +------------------+
2593 + * | entry 2 | | growing downwards
2595 + * | four null bytes |
2598 + * | value 3 | | growing upwards
2600 + * +------------------+
2602 + * The block header is followed by multiple entry descriptors. These entry
2603 + * descriptors are variable in size, and alligned to EXT3_XATTR_PAD
2604 + * byte boundaries. The entry descriptors are sorted by attribute name,
2605 + * so that two extended attribute blocks can be compared efficiently.
2607 + * Attribute values are aligned to the end of the block, stored in
2608 + * no specific order. They are also padded to EXT3_XATTR_PAD byte
2609 + * boundaries. No additional gaps are left between them.
2611 + * Locking strategy
2612 + * ----------------
2613 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
2614 + * the xattr inode operations are called, so we are guaranteed that only one
2615 + * processes accesses extended attributes of an inode at any time.
2617 + * For writing we also grab the ext3_xattr_sem semaphore. This ensures that
2618 + * only a single process is modifying an extended attribute block, even
2619 + * if the block is shared among inodes.
2621 + * Note for porting to 2.5
2622 + * -----------------------
2623 + * The BKL will no longer be held in the xattr inode operations.
2626 +#include <linux/module.h>
2627 +#include <linux/fs.h>
2628 +#include <linux/locks.h>
2629 +#include <linux/slab.h>
2630 +#include <linux/ext3_jbd.h>
2631 +#include <linux/ext3_fs.h>
2632 +#include <linux/ext3_xattr.h>
2633 +#include <linux/mbcache.h>
2634 +#include <linux/quotaops.h>
2635 +#include <asm/semaphore.h>
2636 +#include <linux/compatmac.h>
2638 +#define EXT3_EA_USER "user."
2640 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
2641 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
2644 +#define HDR(bh) ((struct ext3_xattr_header *)((bh)->b_data))
2645 +#define ENTRY(ptr) ((struct ext3_xattr_entry *)(ptr))
2646 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
2647 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
2649 +#ifdef EXT3_XATTR_DEBUG
2650 +# define ea_idebug(inode, f...) do { \
2651 + printk(KERN_DEBUG "inode %s:%ld: ", \
2652 + kdevname(inode->i_dev), inode->i_ino); \
2656 +# define ea_bdebug(bh, f...) do { \
2657 + printk(KERN_DEBUG "block %s:%ld: ", \
2658 + kdevname(bh->b_dev), bh->b_blocknr); \
2663 +# define ea_idebug(f...)
2664 +# define ea_bdebug(f...)
2667 +static int ext3_xattr_set2(handle_t *, struct inode *, struct buffer_head *,
2668 + struct ext3_xattr_header *);
2670 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
2672 +static int ext3_xattr_cache_insert(struct buffer_head *);
2673 +static struct buffer_head *ext3_xattr_cache_find(struct inode *,
2674 + struct ext3_xattr_header *);
2675 +static void ext3_xattr_cache_remove(struct buffer_head *);
2676 +static void ext3_xattr_rehash(struct ext3_xattr_header *,
2677 + struct ext3_xattr_entry *);
2679 +static struct mb_cache *ext3_xattr_cache;
2682 +# define ext3_xattr_cache_insert(bh) 0
2683 +# define ext3_xattr_cache_find(inode, header) NULL
2684 +# define ext3_xattr_cache_remove(bh) while(0) {}
2685 +# define ext3_xattr_rehash(header, entry) while(0) {}
2689 + * If a file system does not share extended attributes among inodes,
2690 + * we should not need the ext3_xattr_sem semaphore. However, the
2691 + * filesystem may still contain shared blocks, so we always take
2695 +DECLARE_MUTEX(ext3_xattr_sem);
2698 +ext3_xattr_new_block(handle_t *handle, struct inode *inode,
2699 + int * errp, int force)
2701 + struct super_block *sb = inode->i_sb;
2702 + int goal = le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block) +
2703 + EXT3_I(inode)->i_block_group * EXT3_BLOCKS_PER_GROUP(sb);
2705 + /* How can we enforce the allocation? */
2706 + int block = ext3_new_block(handle, inode, goal, 0, 0, errp);
2709 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
2715 +ext3_xattr_quota_alloc(struct inode *inode, int force)
2717 + /* How can we enforce the allocation? */
2719 + int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
2721 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
2723 + int error = DQUOT_ALLOC_BLOCK(inode, 1);
2731 +ext3_xattr_quota_free(struct inode *inode)
2733 + DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
2734 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
2738 +ext3_xattr_free_block(handle_t *handle, struct inode * inode,
2739 + unsigned long block)
2741 + ext3_free_blocks(handle, inode, block, 1);
2742 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
2746 +# define ext3_xattr_quota_free(inode) \
2747 + DQUOT_FREE_BLOCK(inode, 1)
2748 +# define ext3_xattr_free_block(handle, inode, block) \
2749 + ext3_free_blocks(handle, inode, block, 1)
2752 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
2754 +static inline struct buffer_head *
2755 +sb_bread(struct super_block *sb, int block)
2757 + return bread(sb->s_dev, block, sb->s_blocksize);
2760 +static inline struct buffer_head *
2761 +sb_getblk(struct super_block *sb, int block)
2763 + return getblk(sb->s_dev, block, sb->s_blocksize);
2768 +struct ext3_xattr_handler *ext3_xattr_handlers[EXT3_XATTR_INDEX_MAX];
2769 +rwlock_t ext3_handler_lock = RW_LOCK_UNLOCKED;
2772 +ext3_xattr_register(int name_index, struct ext3_xattr_handler *handler)
2774 + int error = -EINVAL;
2776 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
2777 + write_lock(&ext3_handler_lock);
2778 + if (!ext3_xattr_handlers[name_index-1]) {
2779 + ext3_xattr_handlers[name_index-1] = handler;
2782 + write_unlock(&ext3_handler_lock);
2788 +ext3_xattr_unregister(int name_index, struct ext3_xattr_handler *handler)
2790 + if (name_index > 0 || name_index <= EXT3_XATTR_INDEX_MAX) {
2791 + write_lock(&ext3_handler_lock);
2792 + ext3_xattr_handlers[name_index-1] = NULL;
2793 + write_unlock(&ext3_handler_lock);
2797 +static inline const char *
2798 +strcmp_prefix(const char *a, const char *a_prefix)
2800 + while (*a_prefix && *a == *a_prefix) {
2804 + return *a_prefix ? NULL : a;
2808 + * Decode the extended attribute name, and translate it into
2809 + * the name_index and name suffix.
2811 +static inline struct ext3_xattr_handler *
2812 +ext3_xattr_resolve_name(const char **name)
2814 + struct ext3_xattr_handler *handler = NULL;
2819 + read_lock(&ext3_handler_lock);
2820 + for (i=0; i<EXT3_XATTR_INDEX_MAX; i++) {
2821 + if (ext3_xattr_handlers[i]) {
2822 + const char *n = strcmp_prefix(*name,
2823 + ext3_xattr_handlers[i]->prefix);
2825 + handler = ext3_xattr_handlers[i];
2831 + read_unlock(&ext3_handler_lock);
2835 +static inline struct ext3_xattr_handler *
2836 +ext3_xattr_handler(int name_index)
2838 + struct ext3_xattr_handler *handler = NULL;
2839 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
2840 + read_lock(&ext3_handler_lock);
2841 + handler = ext3_xattr_handlers[name_index-1];
2842 + read_unlock(&ext3_handler_lock);
2848 + * Inode operation getxattr()
2850 + * dentry->d_inode->i_sem down
2851 + * BKL held [before 2.5.x]
2854 +ext3_getxattr(struct dentry *dentry, const char *name,
2855 + void *buffer, size_t size)
2857 + struct ext3_xattr_handler *handler;
2858 + struct inode *inode = dentry->d_inode;
2860 + handler = ext3_xattr_resolve_name(&name);
2863 + return handler->get(inode, name, buffer, size);
2867 + * Inode operation listxattr()
2869 + * dentry->d_inode->i_sem down
2870 + * BKL held [before 2.5.x]
2873 +ext3_listxattr(struct dentry *dentry, char *buffer, size_t size)
2875 + return ext3_xattr_list(dentry->d_inode, buffer, size);
2879 + * Inode operation setxattr()
2881 + * dentry->d_inode->i_sem down
2882 + * BKL held [before 2.5.x]
2885 +ext3_setxattr(struct dentry *dentry, const char *name,
2886 + const void *value, size_t size, int flags)
2888 + struct ext3_xattr_handler *handler;
2889 + struct inode *inode = dentry->d_inode;
2892 + value = ""; /* empty EA, do not remove */
2893 + handler = ext3_xattr_resolve_name(&name);
2896 + return handler->set(inode, name, value, size, flags);
2900 + * Inode operation removexattr()
2902 + * dentry->d_inode->i_sem down
2903 + * BKL held [before 2.5.x]
2906 +ext3_removexattr(struct dentry *dentry, const char *name)
2908 + struct ext3_xattr_handler *handler;
2909 + struct inode *inode = dentry->d_inode;
2911 + handler = ext3_xattr_resolve_name(&name);
2914 + return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
2918 + * ext3_xattr_get()
2920 + * Copy an extended attribute into the buffer
2921 + * provided, or compute the buffer size required.
2922 + * Buffer is NULL to compute the size of the buffer required.
2924 + * Returns a negative error number on failure, or the number of bytes
2925 + * used / required on success.
2928 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
2929 + void *buffer, size_t buffer_size)
2931 + struct buffer_head *bh = NULL;
2932 + struct ext3_xattr_entry *entry;
2933 + unsigned int block, size;
2935 + int name_len, error;
2937 + ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
2938 + name_index, name, buffer, (long)buffer_size);
2942 + if (!EXT3_I(inode)->i_file_acl)
2944 + block = EXT3_I(inode)->i_file_acl;
2945 + ea_idebug(inode, "reading block %d", block);
2946 + bh = sb_bread(inode->i_sb, block);
2949 + ea_bdebug(bh, "b_count=%d, refcount=%d",
2950 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
2951 + end = bh->b_data + bh->b_size;
2952 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
2953 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
2954 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_get",
2955 + "inode %ld: bad block %d", inode->i_ino, block);
2959 + /* find named attribute */
2960 + name_len = strlen(name);
2963 + if (name_len > 255)
2965 + entry = FIRST_ENTRY(bh);
2966 + while (!IS_LAST_ENTRY(entry)) {
2967 + struct ext3_xattr_entry *next =
2968 + EXT3_XATTR_NEXT(entry);
2969 + if ((char *)next >= end)
2971 + if (name_index == entry->e_name_index &&
2972 + name_len == entry->e_name_len &&
2973 + memcmp(name, entry->e_name, name_len) == 0)
2977 + /* Check the remaining name entries */
2978 + while (!IS_LAST_ENTRY(entry)) {
2979 + struct ext3_xattr_entry *next =
2980 + EXT3_XATTR_NEXT(entry);
2981 + if ((char *)next >= end)
2985 + if (ext3_xattr_cache_insert(bh))
2986 + ea_idebug(inode, "cache insert failed");
2990 + /* check the buffer size */
2991 + if (entry->e_value_block != 0)
2993 + size = le32_to_cpu(entry->e_value_size);
2994 + if (size > inode->i_sb->s_blocksize ||
2995 + le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
2998 + if (ext3_xattr_cache_insert(bh))
2999 + ea_idebug(inode, "cache insert failed");
3002 + if (size > buffer_size)
3004 + /* return value of attribute */
3005 + memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
3017 + * ext3_xattr_list()
3019 + * Copy a list of attribute names into the buffer
3020 + * provided, or compute the buffer size required.
3021 + * Buffer is NULL to compute the size of the buffer required.
3023 + * Returns a negative error number on failure, or the number of bytes
3024 + * used / required on success.
3027 +ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
3029 + struct buffer_head *bh = NULL;
3030 + struct ext3_xattr_entry *entry;
3031 + unsigned int block, size = 0;
3035 + ea_idebug(inode, "buffer=%p, buffer_size=%ld",
3036 + buffer, (long)buffer_size);
3038 + if (!EXT3_I(inode)->i_file_acl)
3040 + block = EXT3_I(inode)->i_file_acl;
3041 + ea_idebug(inode, "reading block %d", block);
3042 + bh = sb_bread(inode->i_sb, block);
3045 + ea_bdebug(bh, "b_count=%d, refcount=%d",
3046 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
3047 + end = bh->b_data + bh->b_size;
3048 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
3049 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
3050 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_list",
3051 + "inode %ld: bad block %d", inode->i_ino, block);
3055 + /* compute the size required for the list of attribute names */
3056 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
3057 + entry = EXT3_XATTR_NEXT(entry)) {
3058 + struct ext3_xattr_handler *handler;
3059 + struct ext3_xattr_entry *next =
3060 + EXT3_XATTR_NEXT(entry);
3061 + if ((char *)next >= end)
3064 + handler = ext3_xattr_handler(entry->e_name_index);
3066 + size += handler->list(NULL, inode, entry->e_name,
3067 + entry->e_name_len);
3070 + if (ext3_xattr_cache_insert(bh))
3071 + ea_idebug(inode, "cache insert failed");
3077 + if (size > buffer_size)
3081 + /* list the attribute names */
3083 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
3084 + entry = EXT3_XATTR_NEXT(entry)) {
3085 + struct ext3_xattr_handler *handler;
3087 + handler = ext3_xattr_handler(entry->e_name_index);
3089 + buf += handler->list(buf, inode, entry->e_name,
3090 + entry->e_name_len);
3101 + * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is
3102 + * not set, set it.
3104 +static void ext3_xattr_update_super_block(handle_t *handle,
3105 + struct super_block *sb)
3107 + if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR))
3111 + ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh);
3112 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
3113 + EXT3_SB(sb)->s_feature_compat |= EXT3_FEATURE_COMPAT_EXT_ATTR;
3115 + EXT3_SB(sb)->s_es->s_feature_compat |=
3116 + cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR);
3118 + ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
3123 + * ext3_xattr_set()
3125 + * Create, replace or remove an extended attribute for this inode. Buffer
3126 + * is NULL to remove an existing extended attribute, and non-NULL to
3127 + * either replace an existing extended attribute, or create a new extended
3128 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
3129 + * specify that an extended attribute must exist and must not exist
3130 + * previous to the call, respectively.
3132 + * Returns 0, or a negative error number on failure.
3135 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
3136 + const char *name, const void *value, size_t value_len, int flags)
3138 + struct super_block *sb = inode->i_sb;
3139 + struct buffer_head *bh = NULL;
3140 + struct ext3_xattr_header *header = NULL;
3141 + struct ext3_xattr_entry *here, *last;
3142 + unsigned int name_len;
3143 + int block = EXT3_I(inode)->i_file_acl;
3144 + int min_offs = sb->s_blocksize, not_found = 1, free, error;
3148 + * header -- Points either into bh, or to a temporarily
3149 + * allocated buffer.
3150 + * here -- The named entry found, or the place for inserting, within
3151 + * the block pointed to by header.
3152 + * last -- Points right after the last named entry within the block
3153 + * pointed to by header.
3154 + * min_offs -- The offset of the first value (values are aligned
3155 + * towards the end of the block).
3156 + * end -- Points right after the block pointed to by header.
3159 + ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
3160 + name_index, name, value, (long)value_len);
3162 + if (IS_RDONLY(inode))
3164 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
3166 + if (value == NULL)
3170 + name_len = strlen(name);
3171 + if (name_len > 255 || value_len > sb->s_blocksize)
3173 + down(&ext3_xattr_sem);
3176 + /* The inode already has an extended attribute block. */
3177 + bh = sb_bread(sb, block);
3181 + ea_bdebug(bh, "b_count=%d, refcount=%d",
3182 + atomic_read(&(bh->b_count)),
3183 + le32_to_cpu(HDR(bh)->h_refcount));
3185 + end = bh->b_data + bh->b_size;
3186 + if (header->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
3187 + header->h_blocks != cpu_to_le32(1)) {
3188 +bad_block: ext3_error(sb, "ext3_xattr_set",
3189 + "inode %ld: bad block %d", inode->i_ino, block);
3193 + /* Find the named attribute. */
3194 + here = FIRST_ENTRY(bh);
3195 + while (!IS_LAST_ENTRY(here)) {
3196 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(here);
3197 + if ((char *)next >= end)
3199 + if (!here->e_value_block && here->e_value_size) {
3200 + int offs = le16_to_cpu(here->e_value_offs);
3201 + if (offs < min_offs)
3204 + not_found = name_index - here->e_name_index;
3206 + not_found = name_len - here->e_name_len;
3208 + not_found = memcmp(name, here->e_name,name_len);
3209 + if (not_found <= 0)
3214 + /* We still need to compute min_offs and last. */
3215 + while (!IS_LAST_ENTRY(last)) {
3216 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
3217 + if ((char *)next >= end)
3219 + if (!last->e_value_block && last->e_value_size) {
3220 + int offs = le16_to_cpu(last->e_value_offs);
3221 + if (offs < min_offs)
3227 + /* Check whether we have enough space left. */
3228 + free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
3230 + /* We will use a new extended attribute block. */
3231 + free = sb->s_blocksize -
3232 + sizeof(struct ext3_xattr_header) - sizeof(__u32);
3233 + here = last = NULL; /* avoid gcc uninitialized warning. */
3237 + /* Request to remove a nonexistent attribute? */
3239 + if (flags & XATTR_REPLACE)
3242 + if (value == NULL)
3245 + free -= EXT3_XATTR_LEN(name_len);
3247 + /* Request to create an existing attribute? */
3249 + if (flags & XATTR_CREATE)
3251 + if (!here->e_value_block && here->e_value_size) {
3252 + unsigned int size = le32_to_cpu(here->e_value_size);
3254 + if (le16_to_cpu(here->e_value_offs) + size >
3255 + sb->s_blocksize || size > sb->s_blocksize)
3257 + free += EXT3_XATTR_SIZE(size);
3260 + free -= EXT3_XATTR_SIZE(value_len);
3265 + /* Here we know that we can set the new attribute. */
3268 + if (header->h_refcount == cpu_to_le32(1)) {
3269 + ea_bdebug(bh, "modifying in-place");
3270 + ext3_xattr_cache_remove(bh);
3271 + error = ext3_journal_get_write_access(handle, bh);
3277 + ea_bdebug(bh, "cloning");
3278 + header = kmalloc(bh->b_size, GFP_KERNEL);
3280 + if (header == NULL)
3282 + memcpy(header, HDR(bh), bh->b_size);
3283 + header->h_refcount = cpu_to_le32(1);
3284 + offset = (char *)header - bh->b_data;
3285 + here = ENTRY((char *)here + offset);
3286 + last = ENTRY((char *)last + offset);
3289 + /* Allocate a buffer where we construct the new block. */
3290 + header = kmalloc(sb->s_blocksize, GFP_KERNEL);
3292 + if (header == NULL)
3294 + memset(header, 0, sb->s_blocksize);
3295 + end = (char *)header + sb->s_blocksize;
3296 + header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC);
3297 + header->h_blocks = header->h_refcount = cpu_to_le32(1);
3298 + last = here = ENTRY(header+1);
3302 + /* Insert the new name. */
3303 + int size = EXT3_XATTR_LEN(name_len);
3304 + int rest = (char *)last - (char *)here;
3305 + memmove((char *)here + size, here, rest);
3306 + memset(here, 0, size);
3307 + here->e_name_index = name_index;
3308 + here->e_name_len = name_len;
3309 + memcpy(here->e_name, name, name_len);
3311 + /* Remove the old value. */
3312 + if (!here->e_value_block && here->e_value_size) {
3313 + char *first_val = (char *)header + min_offs;
3314 + int offs = le16_to_cpu(here->e_value_offs);
3315 + char *val = (char *)header + offs;
3316 + size_t size = EXT3_XATTR_SIZE(
3317 + le32_to_cpu(here->e_value_size));
3318 + memmove(first_val + size, first_val, val - first_val);
3319 + memset(first_val, 0, size);
3320 + here->e_value_offs = 0;
3323 + /* Adjust all value offsets. */
3324 + last = ENTRY(header+1);
3325 + while (!IS_LAST_ENTRY(last)) {
3326 + int o = le16_to_cpu(last->e_value_offs);
3327 + if (!last->e_value_block && o < offs)
3328 + last->e_value_offs =
3329 + cpu_to_le16(o + size);
3330 + last = EXT3_XATTR_NEXT(last);
3333 + if (value == NULL) {
3334 + /* Remove this attribute. */
3335 + if (EXT3_XATTR_NEXT(ENTRY(header+1)) == last) {
3336 + /* This block is now empty. */
3337 + error = ext3_xattr_set2(handle, inode, bh,NULL);
3340 + /* Remove the old name. */
3341 + int size = EXT3_XATTR_LEN(name_len);
3342 + last = ENTRY((char *)last - size);
3343 + memmove(here, (char*)here + size,
3344 + (char*)last - (char*)here);
3345 + memset(last, 0, size);
3350 + if (value != NULL) {
3351 + /* Insert the new value. */
3352 + here->e_value_size = cpu_to_le32(value_len);
3354 + size_t size = EXT3_XATTR_SIZE(value_len);
3355 + char *val = (char *)header + min_offs - size;
3356 + here->e_value_offs =
3357 + cpu_to_le16((char *)val - (char *)header);
3358 + memset(val + size - EXT3_XATTR_PAD, 0,
3359 + EXT3_XATTR_PAD); /* Clear the pad bytes. */
3360 + memcpy(val, value, value_len);
3363 + ext3_xattr_rehash(header, here);
3365 + error = ext3_xattr_set2(handle, inode, bh, header);
3369 + if (!(bh && header == HDR(bh)))
3371 + up(&ext3_xattr_sem);
3377 + * Second half of ext3_xattr_set(): Update the file system.
3380 +ext3_xattr_set2(handle_t *handle, struct inode *inode,
3381 + struct buffer_head *old_bh, struct ext3_xattr_header *header)
3383 + struct super_block *sb = inode->i_sb;
3384 + struct buffer_head *new_bh = NULL;
3388 + new_bh = ext3_xattr_cache_find(inode, header);
3391 + * We found an identical block in the cache.
3392 + * The old block will be released after updating
3395 + ea_bdebug(old_bh, "reusing block %ld",
3396 + new_bh->b_blocknr);
3399 + if (ext3_xattr_quota_alloc(inode, 1))
3402 + error = ext3_journal_get_write_access(handle, new_bh);
3405 + HDR(new_bh)->h_refcount = cpu_to_le32(
3406 + le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
3407 + ea_bdebug(new_bh, "refcount now=%d",
3408 + le32_to_cpu(HDR(new_bh)->h_refcount));
3409 + } else if (old_bh && header == HDR(old_bh)) {
3410 + /* Keep this block. */
3412 + ext3_xattr_cache_insert(new_bh);
3414 + /* We need to allocate a new block */
3415 + int force = EXT3_I(inode)->i_file_acl != 0;
3416 + int block = ext3_xattr_new_block(handle, inode,
3420 + ea_idebug(inode, "creating block %d", block);
3422 + new_bh = sb_getblk(sb, block);
3424 +getblk_failed: ext3_xattr_free_block(handle, inode, block);
3428 + lock_buffer(new_bh);
3429 + error = ext3_journal_get_create_access(handle, new_bh);
3431 + unlock_buffer(new_bh);
3432 + goto getblk_failed;
3434 + memcpy(new_bh->b_data, header, new_bh->b_size);
3435 + mark_buffer_uptodate(new_bh, 1);
3436 + unlock_buffer(new_bh);
3437 + ext3_xattr_cache_insert(new_bh);
3439 + ext3_xattr_update_super_block(handle, sb);
3441 + error = ext3_journal_dirty_metadata(handle, new_bh);
3446 + /* Update the inode. */
3447 + EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
3448 + inode->i_ctime = CURRENT_TIME;
3449 + ext3_mark_inode_dirty(handle, inode);
3450 + if (IS_SYNC(inode))
3451 + handle->h_sync = 1;
3454 + if (old_bh && old_bh != new_bh) {
3456 + * If there was an old block, and we are not still using it,
3457 + * we now release the old block.
3459 + unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
3461 + error = ext3_journal_get_write_access(handle, old_bh);
3464 + if (refcount == 1) {
3465 + /* Free the old block. */
3466 + ea_bdebug(old_bh, "freeing");
3467 + ext3_xattr_free_block(handle, inode, old_bh->b_blocknr);
3469 + /* ext3_forget() calls bforget() for us, but we
3470 + let our caller release old_bh, so we need to
3471 + duplicate the handle before. */
3473 + ext3_forget(handle, 1, inode, old_bh,old_bh->b_blocknr);
3475 + /* Decrement the refcount only. */
3477 + HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
3478 + ext3_xattr_quota_free(inode);
3479 + ext3_journal_dirty_metadata(handle, old_bh);
3480 + ea_bdebug(old_bh, "refcount now=%d", refcount);
3485 + if (old_bh != new_bh)
3492 + * ext3_xattr_delete_inode()
3494 + * Free extended attribute resources associated with this inode. This
3495 + * is called immediately before an inode is freed.
3498 +ext3_xattr_delete_inode(handle_t *handle, struct inode *inode)
3500 + struct buffer_head *bh;
3501 + unsigned int block = EXT3_I(inode)->i_file_acl;
3505 + down(&ext3_xattr_sem);
3507 + bh = sb_bread(inode->i_sb, block);
3509 + ext3_error(inode->i_sb, "ext3_xattr_delete_inode",
3510 + "inode %ld: block %d read error", inode->i_ino, block);
3513 + ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
3514 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
3515 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
3516 + ext3_error(inode->i_sb, "ext3_xattr_delete_inode",
3517 + "inode %ld: bad block %d", inode->i_ino, block);
3520 + ext3_journal_get_write_access(handle, bh);
3521 + ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
3522 + if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
3523 + ext3_xattr_cache_remove(bh);
3524 + ext3_xattr_free_block(handle, inode, block);
3525 + ext3_forget(handle, 1, inode, bh, block);
3528 + HDR(bh)->h_refcount = cpu_to_le32(
3529 + le32_to_cpu(HDR(bh)->h_refcount) - 1);
3530 + ext3_journal_dirty_metadata(handle, bh);
3531 + if (IS_SYNC(inode))
3532 + handle->h_sync = 1;
3533 + ext3_xattr_quota_free(inode);
3535 + EXT3_I(inode)->i_file_acl = 0;
3539 + up(&ext3_xattr_sem);
3543 + * ext3_xattr_put_super()
3545 + * This is called when a file system is unmounted.
3548 +ext3_xattr_put_super(struct super_block *sb)
3550 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
3551 + mb_cache_shrink(ext3_xattr_cache, sb->s_dev);
3555 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
3558 + * ext3_xattr_cache_insert()
3560 + * Create a new entry in the extended attribute cache, and insert
3561 + * it unless such an entry is already in the cache.
3563 + * Returns 0, or a negative error number on failure.
3566 +ext3_xattr_cache_insert(struct buffer_head *bh)
3568 + __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
3569 + struct mb_cache_entry *ce;
3572 + ce = mb_cache_entry_alloc(ext3_xattr_cache);
3575 + error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
3577 + mb_cache_entry_free(ce);
3578 + if (error == -EBUSY) {
3579 + ea_bdebug(bh, "already in cache (%d cache entries)",
3580 + atomic_read(&ext3_xattr_cache->c_entry_count));
3584 + ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
3585 + atomic_read(&ext3_xattr_cache->c_entry_count));
3586 + mb_cache_entry_release(ce);
3592 + * ext3_xattr_cmp()
3594 + * Compare two extended attribute blocks for equality.
3596 + * Returns 0 if the blocks are equal, 1 if they differ, and
3597 + * a negative error number on errors.
3600 +ext3_xattr_cmp(struct ext3_xattr_header *header1,
3601 + struct ext3_xattr_header *header2)
3603 + struct ext3_xattr_entry *entry1, *entry2;
3605 + entry1 = ENTRY(header1+1);
3606 + entry2 = ENTRY(header2+1);
3607 + while (!IS_LAST_ENTRY(entry1)) {
3608 + if (IS_LAST_ENTRY(entry2))
3610 + if (entry1->e_hash != entry2->e_hash ||
3611 + entry1->e_name_len != entry2->e_name_len ||
3612 + entry1->e_value_size != entry2->e_value_size ||
3613 + memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
3615 + if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
3617 + if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
3618 + (char *)header2 + le16_to_cpu(entry2->e_value_offs),
3619 + le32_to_cpu(entry1->e_value_size)))
3622 + entry1 = EXT3_XATTR_NEXT(entry1);
3623 + entry2 = EXT3_XATTR_NEXT(entry2);
3625 + if (!IS_LAST_ENTRY(entry2))
3631 + * ext3_xattr_cache_find()
3633 + * Find an identical extended attribute block.
3635 + * Returns a pointer to the block found, or NULL if such a block was
3636 + * not found or an error occurred.
3638 +static struct buffer_head *
3639 +ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header)
3641 + __u32 hash = le32_to_cpu(header->h_hash);
3642 + struct mb_cache_entry *ce;
3644 + if (!header->h_hash)
3645 + return NULL; /* never share */
3646 + ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
3647 + ce = mb_cache_entry_find_first(ext3_xattr_cache, 0, inode->i_dev, hash);
3649 + struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
3652 + ext3_error(inode->i_sb, "ext3_xattr_cache_find",
3653 + "inode %ld: block %ld read error",
3654 + inode->i_ino, ce->e_block);
3655 + } else if (le32_to_cpu(HDR(bh)->h_refcount) >
3656 + EXT3_XATTR_REFCOUNT_MAX) {
3657 + ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
3658 + le32_to_cpu(HDR(bh)->h_refcount),
3659 + EXT3_XATTR_REFCOUNT_MAX);
3660 + } else if (!ext3_xattr_cmp(header, HDR(bh))) {
3661 + ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
3662 + mb_cache_entry_release(ce);
3666 + ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
3672 + * ext3_xattr_cache_remove()
3674 + * Remove the cache entry of a block from the cache. Called when a
3675 + * block becomes invalid.
3678 +ext3_xattr_cache_remove(struct buffer_head *bh)
3680 + struct mb_cache_entry *ce;
3682 + ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_dev, bh->b_blocknr);
3684 + ea_bdebug(bh, "removing (%d cache entries remaining)",
3685 + atomic_read(&ext3_xattr_cache->c_entry_count)-1);
3686 + mb_cache_entry_free(ce);
3688 + ea_bdebug(bh, "no cache entry");
3691 +#define NAME_HASH_SHIFT 5
3692 +#define VALUE_HASH_SHIFT 16
3695 + * ext3_xattr_hash_entry()
3697 + * Compute the hash of an extended attribute.
3699 +static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
3700 + struct ext3_xattr_entry *entry)
3703 + char *name = entry->e_name;
3706 + for (n=0; n < entry->e_name_len; n++) {
3707 + hash = (hash << NAME_HASH_SHIFT) ^
3708 + (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
3712 + if (entry->e_value_block == 0 && entry->e_value_size != 0) {
3713 + __u32 *value = (__u32 *)((char *)header +
3714 + le16_to_cpu(entry->e_value_offs));
3715 + for (n = (le32_to_cpu(entry->e_value_size) +
3716 + EXT3_XATTR_ROUND) >> EXT3_XATTR_PAD_BITS; n; n--) {
3717 + hash = (hash << VALUE_HASH_SHIFT) ^
3718 + (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
3719 + le32_to_cpu(*value++);
3722 + entry->e_hash = cpu_to_le32(hash);
3725 +#undef NAME_HASH_SHIFT
3726 +#undef VALUE_HASH_SHIFT
3728 +#define BLOCK_HASH_SHIFT 16
3731 + * ext3_xattr_rehash()
3733 + * Re-compute the extended attribute hash value after an entry has changed.
3735 +static void ext3_xattr_rehash(struct ext3_xattr_header *header,
3736 + struct ext3_xattr_entry *entry)
3738 + struct ext3_xattr_entry *here;
3741 + ext3_xattr_hash_entry(header, entry);
3742 + here = ENTRY(header+1);
3743 + while (!IS_LAST_ENTRY(here)) {
3744 + if (!here->e_hash) {
3745 + /* Block is not shared if an entry's hash value == 0 */
3749 + hash = (hash << BLOCK_HASH_SHIFT) ^
3750 + (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
3751 + le32_to_cpu(here->e_hash);
3752 + here = EXT3_XATTR_NEXT(here);
3754 + header->h_hash = cpu_to_le32(hash);
3757 +#undef BLOCK_HASH_SHIFT
3760 +init_ext3_xattr(void)
3762 + ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL,
3763 + sizeof(struct mb_cache_entry) +
3764 + sizeof(struct mb_cache_entry_index), 1, 61);
3765 + if (!ext3_xattr_cache)
3772 +exit_ext3_xattr(void)
3774 + if (ext3_xattr_cache)
3775 + mb_cache_destroy(ext3_xattr_cache);
3776 + ext3_xattr_cache = NULL;
3779 +#else /* CONFIG_EXT3_FS_XATTR_SHARING */
3782 +init_ext3_xattr(void)
3788 +exit_ext3_xattr(void)
3792 +#endif /* CONFIG_EXT3_FS_XATTR_SHARING */
3793 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
3794 +++ linux-2.4.22-ac1-alexey/fs/ext3/xattr_user.c 2003-09-25 23:57:02.000000000 +0400
3797 + * linux/fs/ext3/xattr_user.c
3798 + * Handler for extended user attributes.
3800 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
3803 +#include <linux/module.h>
3804 +#include <linux/string.h>
3805 +#include <linux/fs.h>
3806 +#include <linux/ext3_jbd.h>
3807 +#include <linux/ext3_fs.h>
3808 +#include <linux/ext3_xattr.h>
3810 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3811 +# include <linux/ext3_acl.h>
3814 +#define XATTR_USER_PREFIX "user."
3817 +ext3_xattr_user_list(char *list, struct inode *inode,
3818 + const char *name, int name_len)
3820 + const int prefix_len = sizeof(XATTR_USER_PREFIX)-1;
3822 + if (!test_opt(inode->i_sb, XATTR_USER))
3826 + memcpy(list, XATTR_USER_PREFIX, prefix_len);
3827 + memcpy(list+prefix_len, name, name_len);
3828 + list[prefix_len + name_len] = '\0';
3830 + return prefix_len + name_len + 1;
3834 +ext3_xattr_user_get(struct inode *inode, const char *name,
3835 + void *buffer, size_t size)
3839 + if (strcmp(name, "") == 0)
3841 + if (!test_opt(inode->i_sb, XATTR_USER))
3843 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3844 + error = ext3_permission_locked(inode, MAY_READ);
3846 + error = permission(inode, MAY_READ);
3851 + return ext3_xattr_get(inode, EXT3_XATTR_INDEX_USER, name,
3856 +ext3_xattr_user_set(struct inode *inode, const char *name,
3857 + const void *value, size_t size, int flags)
3862 + if (strcmp(name, "") == 0)
3864 + if (!test_opt(inode->i_sb, XATTR_USER))
3866 + if ( !S_ISREG(inode->i_mode) &&
3867 + (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
3869 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3870 + error = ext3_permission_locked(inode, MAY_WRITE);
3872 + error = permission(inode, MAY_WRITE);
3877 + handle = ext3_journal_start(inode, EXT3_XATTR_TRANS_BLOCKS);
3878 + if (IS_ERR(handle))
3879 + return PTR_ERR(handle);
3880 + error = ext3_xattr_set(handle, inode, EXT3_XATTR_INDEX_USER, name,
3881 + value, size, flags);
3882 + ext3_journal_stop(handle, inode);
3887 +struct ext3_xattr_handler ext3_xattr_user_handler = {
3888 + prefix: XATTR_USER_PREFIX,
3889 + list: ext3_xattr_user_list,
3890 + get: ext3_xattr_user_get,
3891 + set: ext3_xattr_user_set,
3895 +init_ext3_xattr_user(void)
3897 + return ext3_xattr_register(EXT3_XATTR_INDEX_USER,
3898 + &ext3_xattr_user_handler);
3902 +exit_ext3_xattr_user(void)
3904 + ext3_xattr_unregister(EXT3_XATTR_INDEX_USER,
3905 + &ext3_xattr_user_handler);
3907 --- linux-2.4.22-ac1/fs/jfs/jfs_xattr.h~xattr-0.8.54-2.4.22-rh 2002-11-29 02:53:15.000000000 +0300
3908 +++ linux-2.4.22-ac1-alexey/fs/jfs/jfs_xattr.h 2003-09-25 23:57:02.000000000 +0400
3909 @@ -52,8 +52,10 @@ struct jfs_ea_list {
3910 #define END_EALIST(ealist) \
3911 ((struct jfs_ea *) (((char *) (ealist)) + EALIST_SIZE(ealist)))
3913 -extern int __jfs_setxattr(struct inode *, const char *, void *, size_t, int);
3914 -extern int jfs_setxattr(struct dentry *, const char *, void *, size_t, int);
3915 +extern int __jfs_setxattr(struct inode *, const char *, const void *, size_t,
3917 +extern int jfs_setxattr(struct dentry *, const char *, const void *, size_t,
3919 extern ssize_t __jfs_getxattr(struct inode *, const char *, void *, size_t);
3920 extern ssize_t jfs_getxattr(struct dentry *, const char *, void *, size_t);
3921 extern ssize_t jfs_listxattr(struct dentry *, char *, size_t);
3922 --- linux-2.4.22-ac1/fs/jfs/xattr.c~xattr-0.8.54-2.4.22-rh 2002-11-29 02:53:15.000000000 +0300
3923 +++ linux-2.4.22-ac1-alexey/fs/jfs/xattr.c 2003-09-25 23:57:02.000000000 +0400
3924 @@ -641,7 +641,7 @@ static int ea_put(struct inode *inode, s
3927 static int can_set_xattr(struct inode *inode, const char *name,
3928 - void *value, size_t value_len)
3929 + const void *value, size_t value_len)
3931 if (IS_RDONLY(inode))
3933 @@ -660,7 +660,7 @@ static int can_set_xattr(struct inode *i
3934 return permission(inode, MAY_WRITE);
3937 -int __jfs_setxattr(struct inode *inode, const char *name, void *value,
3938 +int __jfs_setxattr(struct inode *inode, const char *name, const void *value,
3939 size_t value_len, int flags)
3941 struct jfs_ea_list *ealist;
3942 @@ -799,7 +799,7 @@ int __jfs_setxattr(struct inode *inode,
3946 -int jfs_setxattr(struct dentry *dentry, const char *name, void *value,
3947 +int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
3948 size_t value_len, int flags)
3950 if (value == NULL) { /* empty EA, do not remove */
3951 --- linux-2.4.22-ac1/fs/Makefile~xattr-0.8.54-2.4.22-rh 2003-09-25 14:50:00.000000000 +0400
3952 +++ linux-2.4.22-ac1-alexey/fs/Makefile 2003-09-25 23:57:02.000000000 +0400
3953 @@ -82,6 +82,9 @@ obj-y += binfmt_script.o
3955 obj-$(CONFIG_BINFMT_ELF) += binfmt_elf.o
3957 +export-objs += mbcache.o
3958 +obj-$(CONFIG_FS_MBCACHE) += mbcache.o
3960 # persistent filesystems
3961 obj-y += $(join $(subdir-y),$(subdir-y:%=/%.o))
3963 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
3964 +++ linux-2.4.22-ac1-alexey/fs/mbcache.c 2003-09-25 23:57:02.000000000 +0400
3967 + * linux/fs/mbcache.c
3968 + * (C) 2001-2002 Andreas Gruenbacher, <a.gruenbacher@computer.org>
3972 + * Filesystem Meta Information Block Cache (mbcache)
3974 + * The mbcache caches blocks of block devices that need to be located
3975 + * by their device/block number, as well as by other criteria (such
3976 + * as the block's contents).
3978 + * There can only be one cache entry in a cache per device and block number.
3979 + * Additional indexes need not be unique in this sense. The number of
3980 + * additional indexes (=other criteria) can be hardwired at compile time
3981 + * or specified at cache create time.
3983 + * Each cache entry is of fixed size. An entry may be `valid' or `invalid'
3984 + * in the cache. A valid entry is in the main hash tables of the cache,
3985 + * and may also be in the lru list. An invalid entry is not in any hashes
3988 + * A valid cache entry is only in the lru list if no handles refer to it.
3989 + * Invalid cache entries will be freed when the last handle to the cache
3990 + * entry is released. Entries that cannot be freed immediately are put
3991 + * back on the lru list.
3994 +#include <linux/kernel.h>
3995 +#include <linux/module.h>
3997 +#include <linux/fs.h>
3998 +#include <linux/slab.h>
3999 +#include <linux/sched.h>
4000 +#include <linux/cache_def.h>
4001 +#include <linux/version.h>
4002 +#include <linux/init.h>
4003 +#include <linux/mbcache.h>
4006 +#ifdef MB_CACHE_DEBUG
4007 +# define mb_debug(f...) do { \
4008 + printk(KERN_DEBUG f); \
4011 +#define mb_assert(c) do { if (!(c)) \
4012 + printk(KERN_ERR "assertion " #c " failed\n"); \
4015 +# define mb_debug(f...) do { } while(0)
4016 +# define mb_assert(c) do { } while(0)
4018 +#define mb_error(f...) do { \
4019 + printk(KERN_ERR f); \
4023 +MODULE_AUTHOR("Andreas Gruenbacher <a.gruenbacher@computer.org>");
4024 +MODULE_DESCRIPTION("Meta block cache (for extended attributes)");
4025 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
4026 +MODULE_LICENSE("GPL");
4029 +EXPORT_SYMBOL(mb_cache_create);
4030 +EXPORT_SYMBOL(mb_cache_shrink);
4031 +EXPORT_SYMBOL(mb_cache_destroy);
4032 +EXPORT_SYMBOL(mb_cache_entry_alloc);
4033 +EXPORT_SYMBOL(mb_cache_entry_insert);
4034 +EXPORT_SYMBOL(mb_cache_entry_release);
4035 +EXPORT_SYMBOL(mb_cache_entry_takeout);
4036 +EXPORT_SYMBOL(mb_cache_entry_free);
4037 +EXPORT_SYMBOL(mb_cache_entry_dup);
4038 +EXPORT_SYMBOL(mb_cache_entry_get);
4039 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
4040 +EXPORT_SYMBOL(mb_cache_entry_find_first);
4041 +EXPORT_SYMBOL(mb_cache_entry_find_next);
4046 + * Global data: list of all mbcache's, lru list, and a spinlock for
4047 + * accessing cache data structures on SMP machines. The lru list is
4048 + * global across all mbcaches.
4051 +static LIST_HEAD(mb_cache_list);
4052 +static LIST_HEAD(mb_cache_lru_list);
4053 +static spinlock_t mb_cache_spinlock = SPIN_LOCK_UNLOCKED;
4056 +mb_cache_indexes(struct mb_cache *cache)
4058 +#ifdef MB_CACHE_INDEXES_COUNT
4059 + return MB_CACHE_INDEXES_COUNT;
4061 + return cache->c_indexes_count;
4066 + * What the mbcache registers as to get shrunk dynamically.
4070 +mb_cache_memory_pressure(int priority, unsigned int gfp_mask);
4072 +static struct cache_definition mb_cache_definition = {
4074 + mb_cache_memory_pressure
4079 +__mb_cache_entry_is_hashed(struct mb_cache_entry *ce)
4081 + return !list_empty(&ce->e_block_list);
4086 +__mb_cache_entry_unhash(struct mb_cache_entry *ce)
4090 + if (__mb_cache_entry_is_hashed(ce)) {
4091 + list_del_init(&ce->e_block_list);
4092 + for (n=0; n<mb_cache_indexes(ce->e_cache); n++)
4093 + list_del(&ce->e_indexes[n].o_list);
4099 +__mb_cache_entry_forget(struct mb_cache_entry *ce, int gfp_mask)
4101 + struct mb_cache *cache = ce->e_cache;
4103 + mb_assert(atomic_read(&ce->e_used) == 0);
4104 + if (cache->c_op.free && cache->c_op.free(ce, gfp_mask)) {
4105 + /* free failed -- put back on the lru list
4106 + for freeing later. */
4107 + spin_lock(&mb_cache_spinlock);
4108 + list_add(&ce->e_lru_list, &mb_cache_lru_list);
4109 + spin_unlock(&mb_cache_spinlock);
4111 + kmem_cache_free(cache->c_entry_cache, ce);
4112 + atomic_dec(&cache->c_entry_count);
4118 +__mb_cache_entry_release_unlock(struct mb_cache_entry *ce)
4120 + if (atomic_dec_and_test(&ce->e_used)) {
4121 + if (__mb_cache_entry_is_hashed(ce))
4122 + list_add_tail(&ce->e_lru_list, &mb_cache_lru_list);
4124 + spin_unlock(&mb_cache_spinlock);
4125 + __mb_cache_entry_forget(ce, GFP_KERNEL);
4129 + spin_unlock(&mb_cache_spinlock);
4134 + * mb_cache_memory_pressure() memory pressure callback
4136 + * This function is called by the kernel memory management when memory
4139 + * @priority: Amount by which to shrink the cache (0 = highes priority)
4140 + * @gfp_mask: (ignored)
4143 +mb_cache_memory_pressure(int priority, unsigned int gfp_mask)
4145 + LIST_HEAD(free_list);
4146 + struct list_head *l, *ltmp;
4149 + spin_lock(&mb_cache_spinlock);
4150 + list_for_each(l, &mb_cache_list) {
4151 + struct mb_cache *cache =
4152 + list_entry(l, struct mb_cache, c_cache_list);
4153 + mb_debug("cache %s (%d)", cache->c_name,
4154 + atomic_read(&cache->c_entry_count));
4155 + count += atomic_read(&cache->c_entry_count);
4157 + mb_debug("trying to free %d of %d entries",
4158 + count / (priority ? priority : 1), count);
4160 + count /= priority;
4161 + while (count-- && !list_empty(&mb_cache_lru_list)) {
4162 + struct mb_cache_entry *ce =
4163 + list_entry(mb_cache_lru_list.next,
4164 + struct mb_cache_entry, e_lru_list);
4165 + list_del(&ce->e_lru_list);
4166 + __mb_cache_entry_unhash(ce);
4167 + list_add_tail(&ce->e_lru_list, &free_list);
4169 + spin_unlock(&mb_cache_spinlock);
4170 + list_for_each_safe(l, ltmp, &free_list) {
4171 + __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4172 + e_lru_list), gfp_mask);
4178 + * mb_cache_create() create a new cache
4180 + * All entries in one cache are equal size. Cache entries may be from
4181 + * multiple devices. If this is the first mbcache created, registers
4182 + * the cache with kernel memory management. Returns NULL if no more
4183 + * memory was available.
4185 + * @name: name of the cache (informal)
4186 + * @cache_op: contains the callback called when freeing a cache entry
4187 + * @entry_size: The size of a cache entry, including
4188 + * struct mb_cache_entry
4189 + * @indexes_count: number of additional indexes in the cache. Must equal
4190 + * MB_CACHE_INDEXES_COUNT if the number of indexes is
4192 + * @bucket_count: number of hash buckets
4195 +mb_cache_create(const char *name, struct mb_cache_op *cache_op,
4196 + size_t entry_size, int indexes_count, int bucket_count)
4199 + struct mb_cache *cache = NULL;
4201 + if(entry_size < sizeof(struct mb_cache_entry) +
4202 + indexes_count * sizeof(struct mb_cache_entry_index))
4205 + MOD_INC_USE_COUNT;
4206 + cache = kmalloc(sizeof(struct mb_cache) +
4207 + indexes_count * sizeof(struct list_head), GFP_KERNEL);
4210 + cache->c_name = name;
4211 + cache->c_op.free = NULL;
4213 + cache->c_op.free = cache_op->free;
4214 + atomic_set(&cache->c_entry_count, 0);
4215 + cache->c_bucket_count = bucket_count;
4216 +#ifdef MB_CACHE_INDEXES_COUNT
4217 + mb_assert(indexes_count == MB_CACHE_INDEXES_COUNT);
4219 + cache->c_indexes_count = indexes_count;
4221 + cache->c_block_hash = kmalloc(bucket_count * sizeof(struct list_head),
4223 + if (!cache->c_block_hash)
4225 + for (n=0; n<bucket_count; n++)
4226 + INIT_LIST_HEAD(&cache->c_block_hash[n]);
4227 + for (m=0; m<indexes_count; m++) {
4228 + cache->c_indexes_hash[m] = kmalloc(bucket_count *
4229 + sizeof(struct list_head),
4231 + if (!cache->c_indexes_hash[m])
4233 + for (n=0; n<bucket_count; n++)
4234 + INIT_LIST_HEAD(&cache->c_indexes_hash[m][n]);
4236 + cache->c_entry_cache = kmem_cache_create(name, entry_size, 0,
4237 + 0 /*SLAB_POISON | SLAB_RED_ZONE*/, NULL, NULL);
4238 + if (!cache->c_entry_cache)
4241 + spin_lock(&mb_cache_spinlock);
4242 + list_add(&cache->c_cache_list, &mb_cache_list);
4243 + spin_unlock(&mb_cache_spinlock);
4249 + kfree(cache->c_indexes_hash[m]);
4250 + if (cache->c_block_hash)
4251 + kfree(cache->c_block_hash);
4254 + MOD_DEC_USE_COUNT;
4260 + * mb_cache_shrink()
4262 + * Removes all cache entires of a device from the cache. All cache entries
4263 + * currently in use cannot be freed, and thus remain in the cache.
4265 + * @cache: which cache to shrink
4266 + * @dev: which device's cache entries to shrink
4269 +mb_cache_shrink(struct mb_cache *cache, kdev_t dev)
4271 + LIST_HEAD(free_list);
4272 + struct list_head *l, *ltmp;
4274 + spin_lock(&mb_cache_spinlock);
4275 + list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
4276 + struct mb_cache_entry *ce =
4277 + list_entry(l, struct mb_cache_entry, e_lru_list);
4278 + if (ce->e_dev == dev) {
4279 + list_del(&ce->e_lru_list);
4280 + list_add_tail(&ce->e_lru_list, &free_list);
4281 + __mb_cache_entry_unhash(ce);
4284 + spin_unlock(&mb_cache_spinlock);
4285 + list_for_each_safe(l, ltmp, &free_list) {
4286 + __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4287 + e_lru_list), GFP_KERNEL);
4293 + * mb_cache_destroy()
4295 + * Shrinks the cache to its minimum possible size (hopefully 0 entries),
4296 + * and then destroys it. If this was the last mbcache, un-registers the
4297 + * mbcache from kernel memory management.
4300 +mb_cache_destroy(struct mb_cache *cache)
4302 + LIST_HEAD(free_list);
4303 + struct list_head *l, *ltmp;
4306 + spin_lock(&mb_cache_spinlock);
4307 + list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
4308 + struct mb_cache_entry *ce =
4309 + list_entry(l, struct mb_cache_entry, e_lru_list);
4310 + if (ce->e_cache == cache) {
4311 + list_del(&ce->e_lru_list);
4312 + list_add_tail(&ce->e_lru_list, &free_list);
4313 + __mb_cache_entry_unhash(ce);
4316 + list_del(&cache->c_cache_list);
4317 + spin_unlock(&mb_cache_spinlock);
4318 + list_for_each_safe(l, ltmp, &free_list) {
4319 + __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
4320 + e_lru_list), GFP_KERNEL);
4323 + if (atomic_read(&cache->c_entry_count) > 0) {
4324 + mb_error("cache %s: %d orphaned entries",
4326 + atomic_read(&cache->c_entry_count));
4329 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
4330 + /* We don't have kmem_cache_destroy() in 2.2.x */
4331 + kmem_cache_shrink(cache->c_entry_cache);
4333 + kmem_cache_destroy(cache->c_entry_cache);
4335 + for (n=0; n < mb_cache_indexes(cache); n++)
4336 + kfree(cache->c_indexes_hash[n]);
4337 + kfree(cache->c_block_hash);
4340 + MOD_DEC_USE_COUNT;
4345 + * mb_cache_entry_alloc()
4347 + * Allocates a new cache entry. The new entry will not be valid initially,
4348 + * and thus cannot be looked up yet. It should be filled with data, and
4349 + * then inserted into the cache using mb_cache_entry_insert(). Returns NULL
4350 + * if no more memory was available.
4352 +struct mb_cache_entry *
4353 +mb_cache_entry_alloc(struct mb_cache *cache)
4355 + struct mb_cache_entry *ce;
4357 + atomic_inc(&cache->c_entry_count);
4358 + ce = kmem_cache_alloc(cache->c_entry_cache, GFP_KERNEL);
4360 + INIT_LIST_HEAD(&ce->e_lru_list);
4361 + INIT_LIST_HEAD(&ce->e_block_list);
4362 + ce->e_cache = cache;
4363 + atomic_set(&ce->e_used, 1);
4370 + * mb_cache_entry_insert()
4372 + * Inserts an entry that was allocated using mb_cache_entry_alloc() into
4373 + * the cache. After this, the cache entry can be looked up, but is not yet
4374 + * in the lru list as the caller still holds a handle to it. Returns 0 on
4375 + * success, or -EBUSY if a cache entry for that device + inode exists
4376 + * already (this may happen after a failed lookup, if another process has
4377 + * inserted the same cache entry in the meantime).
4379 + * @dev: device the cache entry belongs to
4380 + * @block: block number
4381 + * @keys: array of additional keys. There must be indexes_count entries
4382 + * in the array (as specified when creating the cache).
4385 +mb_cache_entry_insert(struct mb_cache_entry *ce, kdev_t dev,
4386 + unsigned long block, unsigned int keys[])
4388 + struct mb_cache *cache = ce->e_cache;
4389 + unsigned int bucket = (HASHDEV(dev) + block) % cache->c_bucket_count;
4390 + struct list_head *l;
4391 + int error = -EBUSY, n;
4393 + spin_lock(&mb_cache_spinlock);
4394 + list_for_each(l, &cache->c_block_hash[bucket]) {
4395 + struct mb_cache_entry *ce =
4396 + list_entry(l, struct mb_cache_entry, e_block_list);
4397 + if (ce->e_dev == dev && ce->e_block == block)
4400 + __mb_cache_entry_unhash(ce);
4402 + ce->e_block = block;
4403 + list_add(&ce->e_block_list, &cache->c_block_hash[bucket]);
4404 + for (n=0; n<mb_cache_indexes(cache); n++) {
4405 + ce->e_indexes[n].o_key = keys[n];
4406 + bucket = keys[n] % cache->c_bucket_count;
4407 + list_add(&ce->e_indexes[n].o_list,
4408 + &cache->c_indexes_hash[n][bucket]);
4411 + spin_unlock(&mb_cache_spinlock);
4417 + * mb_cache_entry_release()
4419 + * Release a handle to a cache entry. When the last handle to a cache entry
4420 + * is released it is either freed (if it is invalid) or otherwise inserted
4421 + * in to the lru list.
4424 +mb_cache_entry_release(struct mb_cache_entry *ce)
4426 + spin_lock(&mb_cache_spinlock);
4427 + __mb_cache_entry_release_unlock(ce);
4432 + * mb_cache_entry_takeout()
4434 + * Take a cache entry out of the cache, making it invalid. The entry can later
4435 + * be re-inserted using mb_cache_entry_insert(), or released using
4436 + * mb_cache_entry_release().
4439 +mb_cache_entry_takeout(struct mb_cache_entry *ce)
4441 + spin_lock(&mb_cache_spinlock);
4442 + mb_assert(list_empty(&ce->e_lru_list));
4443 + __mb_cache_entry_unhash(ce);
4444 + spin_unlock(&mb_cache_spinlock);
4449 + * mb_cache_entry_free()
4451 + * This is equivalent to the sequence mb_cache_entry_takeout() --
4452 + * mb_cache_entry_release().
4455 +mb_cache_entry_free(struct mb_cache_entry *ce)
4457 + spin_lock(&mb_cache_spinlock);
4458 + mb_assert(list_empty(&ce->e_lru_list));
4459 + __mb_cache_entry_unhash(ce);
4460 + __mb_cache_entry_release_unlock(ce);
4465 + * mb_cache_entry_dup()
4467 + * Duplicate a handle to a cache entry (does not duplicate the cache entry
4468 + * itself). After the call, both the old and the new handle must be released.
4470 +struct mb_cache_entry *
4471 +mb_cache_entry_dup(struct mb_cache_entry *ce)
4473 + atomic_inc(&ce->e_used);
4479 + * mb_cache_entry_get()
4481 + * Get a cache entry by device / block number. (There can only be one entry
4482 + * in the cache per device and block.) Returns NULL if no such cache entry
4485 +struct mb_cache_entry *
4486 +mb_cache_entry_get(struct mb_cache *cache, kdev_t dev, unsigned long block)
4488 + unsigned int bucket = (HASHDEV(dev) + block) % cache->c_bucket_count;
4489 + struct list_head *l;
4490 + struct mb_cache_entry *ce;
4492 + spin_lock(&mb_cache_spinlock);
4493 + list_for_each(l, &cache->c_block_hash[bucket]) {
4494 + ce = list_entry(l, struct mb_cache_entry, e_block_list);
4495 + if (ce->e_dev == dev && ce->e_block == block) {
4496 + if (!list_empty(&ce->e_lru_list))
4497 + list_del_init(&ce->e_lru_list);
4498 + atomic_inc(&ce->e_used);
4505 + spin_unlock(&mb_cache_spinlock);
4509 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
4511 +static struct mb_cache_entry *
4512 +__mb_cache_entry_find(struct list_head *l, struct list_head *head,
4513 + int index, kdev_t dev, unsigned int key)
4515 + while (l != head) {
4516 + struct mb_cache_entry *ce =
4517 + list_entry(l, struct mb_cache_entry,
4518 + e_indexes[index].o_list);
4519 + if (ce->e_dev == dev && ce->e_indexes[index].o_key == key) {
4520 + if (!list_empty(&ce->e_lru_list))
4521 + list_del_init(&ce->e_lru_list);
4522 + atomic_inc(&ce->e_used);
4532 + * mb_cache_entry_find_first()
4534 + * Find the first cache entry on a given device with a certain key in
4535 + * an additional index. Additonal matches can be found with
4536 + * mb_cache_entry_find_next(). Returns NULL if no match was found.
4538 + * @cache: the cache to search
4539 + * @index: the number of the additonal index to search (0<=index<indexes_count)
4540 + * @dev: the device the cache entry should belong to
4541 + * @key: the key in the index
4543 +struct mb_cache_entry *
4544 +mb_cache_entry_find_first(struct mb_cache *cache, int index, kdev_t dev,
4547 + unsigned int bucket = key % cache->c_bucket_count;
4548 + struct list_head *l;
4549 + struct mb_cache_entry *ce;
4551 + mb_assert(index < mb_cache_indexes(cache));
4552 + spin_lock(&mb_cache_spinlock);
4553 + l = cache->c_indexes_hash[index][bucket].next;
4554 + ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
4556 + spin_unlock(&mb_cache_spinlock);
4562 + * mb_cache_entry_find_next()
4564 + * Find the next cache entry on a given device with a certain key in an
4565 + * additional index. Returns NULL if no match could be found. The previous
4566 + * entry is atomatically released, so that mb_cache_entry_find_next() can
4567 + * be called like this:
4569 + * entry = mb_cache_entry_find_first();
4572 + * entry = mb_cache_entry_find_next(entry, ...);
4575 + * @prev: The previous match
4576 + * @index: the number of the additonal index to search (0<=index<indexes_count)
4577 + * @dev: the device the cache entry should belong to
4578 + * @key: the key in the index
4580 +struct mb_cache_entry *
4581 +mb_cache_entry_find_next(struct mb_cache_entry *prev, int index, kdev_t dev,
4584 + struct mb_cache *cache = prev->e_cache;
4585 + unsigned int bucket = key % cache->c_bucket_count;
4586 + struct list_head *l;
4587 + struct mb_cache_entry *ce;
4589 + mb_assert(index < mb_cache_indexes(cache));
4590 + spin_lock(&mb_cache_spinlock);
4591 + l = prev->e_indexes[index].o_list.next;
4592 + ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
4594 + __mb_cache_entry_release_unlock(prev);
4598 +#endif /* !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0) */
4600 +static int __init init_mbcache(void)
4602 + register_cache(&mb_cache_definition);
4606 +static void __exit exit_mbcache(void)
4608 + unregister_cache(&mb_cache_definition);
4611 +module_init(init_mbcache)
4612 +module_exit(exit_mbcache)
4614 --- linux-2.4.22-ac1/include/asm-arm/unistd.h~xattr-0.8.54-2.4.22-rh 2003-08-25 15:44:43.000000000 +0400
4615 +++ linux-2.4.22-ac1-alexey/include/asm-arm/unistd.h 2003-09-25 23:57:02.000000000 +0400
4617 #define __NR_security (__NR_SYSCALL_BASE+223)
4618 #define __NR_gettid (__NR_SYSCALL_BASE+224)
4619 #define __NR_readahead (__NR_SYSCALL_BASE+225)
4620 -#if 0 /* allocated in 2.5 */
4621 #define __NR_setxattr (__NR_SYSCALL_BASE+226)
4622 #define __NR_lsetxattr (__NR_SYSCALL_BASE+227)
4623 #define __NR_fsetxattr (__NR_SYSCALL_BASE+228)
4625 #define __NR_removexattr (__NR_SYSCALL_BASE+235)
4626 #define __NR_lremovexattr (__NR_SYSCALL_BASE+236)
4627 #define __NR_fremovexattr (__NR_SYSCALL_BASE+237)
4629 #define __NR_tkill (__NR_SYSCALL_BASE+238)
4630 #if 0 /* allocated in 2.5 */
4631 #define __NR_sendfile64 (__NR_SYSCALL_BASE+239)
4632 --- linux-2.4.22-ac1/include/asm-ppc64/unistd.h~xattr-0.8.54-2.4.22-rh 2003-06-13 18:51:38.000000000 +0400
4633 +++ linux-2.4.22-ac1-alexey/include/asm-ppc64/unistd.h 2003-09-25 23:57:02.000000000 +0400
4635 #define __NR_mincore 206
4636 #define __NR_gettid 207
4637 #define __NR_tkill 208
4639 #define __NR_setxattr 209
4640 #define __NR_lsetxattr 210
4641 #define __NR_fsetxattr 211
4643 #define __NR_removexattr 218
4644 #define __NR_lremovexattr 219
4645 #define __NR_fremovexattr 220
4646 +#if 0 /* Reserved syscalls */
4647 #define __NR_futex 221
4648 #define __NR_sched_setaffinity 222
4649 #define __NR_sched_getaffinity 223
4650 --- linux-2.4.22-ac1/include/asm-s390/unistd.h~xattr-0.8.54-2.4.22-rh 2003-06-13 18:51:38.000000000 +0400
4651 +++ linux-2.4.22-ac1-alexey/include/asm-s390/unistd.h 2003-09-26 00:14:23.000000000 +0400
4652 @@ -213,6 +213,19 @@
4653 #define __NR_getdents64 220
4654 #define __NR_fcntl64 221
4655 #define __NR_readahead 222
4656 +#define __NR_setxattr 224
4657 +#define __NR_lsetxattr 225
4658 +#define __NR_fsetxattr 226
4659 +#define __NR_getxattr 227
4660 +#define __NR_lgetxattr 228
4661 +#define __NR_fgetxattr 229
4662 +#define __NR_listxattr 230
4663 +#define __NR_llistxattr 231
4664 +#define __NR_flistxattr 232
4665 +#define __NR_removexattr 233
4666 +#define __NR_lremovexattr 234
4667 +#define __NR_fremovexattr 235
4670 * Numbers 224-235 are reserved for posix acl
4672 --- linux-2.4.22-ac1/include/asm-s390x/unistd.h~xattr-0.8.54-2.4.22-rh 2003-06-13 18:51:38.000000000 +0400
4673 +++ linux-2.4.22-ac1-alexey/include/asm-s390x/unistd.h 2003-09-26 00:15:11.000000000 +0400
4674 @@ -181,6 +181,19 @@
4675 #define __NR_mincore 218
4676 #define __NR_madvise 219
4677 #define __NR_readahead 222
4678 +#define __NR_setxattr 224
4679 +#define __NR_lsetxattr 225
4680 +#define __NR_fsetxattr 226
4681 +#define __NR_getxattr 227
4682 +#define __NR_lgetxattr 228
4683 +#define __NR_fgetxattr 229
4684 +#define __NR_listxattr 230
4685 +#define __NR_llistxattr 231
4686 +#define __NR_flistxattr 232
4687 +#define __NR_removexattr 233
4688 +#define __NR_lremovexattr 234
4689 +#define __NR_fremovexattr 235
4692 * Numbers 224-235 are reserved for posix acl
4694 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
4695 +++ linux-2.4.22-ac1-alexey/include/linux/cache_def.h 2003-09-25 23:57:02.000000000 +0400
4698 + * linux/cache_def.h
4699 + * Handling of caches defined in drivers, filesystems, ...
4701 + * Copyright (C) 2002 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
4704 +struct cache_definition {
4706 + void (*shrink)(int, unsigned int);
4707 + struct list_head link;
4710 +extern void register_cache(struct cache_definition *);
4711 +extern void unregister_cache(struct cache_definition *);
4712 --- linux-2.4.22-ac1/include/linux/errno.h~xattr-0.8.54-2.4.22-rh 2001-02-10 01:46:13.000000000 +0300
4713 +++ linux-2.4.22-ac1-alexey/include/linux/errno.h 2003-09-25 23:57:02.000000000 +0400
4718 +/* Defined for extended attributes */
4719 +#define ENOATTR ENODATA /* No such attribute */
4720 +#define ENOTSUP EOPNOTSUPP /* Operation not supported */
4723 --- linux-2.4.22-ac1/include/linux/ext2_fs.h~xattr-0.8.54-2.4.22-rh 2003-06-13 18:51:38.000000000 +0400
4724 +++ linux-2.4.22-ac1-alexey/include/linux/ext2_fs.h 2003-09-25 23:57:02.000000000 +0400
4727 #define EXT2_BAD_INO 1 /* Bad blocks inode */
4728 #define EXT2_ROOT_INO 2 /* Root inode */
4729 -#define EXT2_ACL_IDX_INO 3 /* ACL inode */
4730 -#define EXT2_ACL_DATA_INO 4 /* ACL inode */
4731 #define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
4732 #define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
4736 # define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
4738 -#define EXT2_ACLE_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
4739 #define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
4741 # define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
4742 @@ -121,28 +118,6 @@
4748 -struct ext2_acl_header /* Header of Access Control Lists */
4751 - __u32 aclh_file_count;
4752 - __u32 aclh_acle_count;
4753 - __u32 aclh_first_acle;
4756 -struct ext2_acl_entry /* Access Control List Entry */
4759 - __u16 acle_perms; /* Access permissions */
4760 - __u16 acle_type; /* Type of entry */
4761 - __u16 acle_tag; /* User or group identity */
4763 - __u32 acle_next; /* Pointer on next entry for the */
4764 - /* same inode or on next free entry */
4768 * Structure of a blocks group descriptor
4770 struct ext2_group_desc
4771 @@ -314,6 +289,7 @@ struct ext2_inode {
4772 #define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
4773 #define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
4774 #define EXT2_MOUNT_NO_UID32 0x0200 /* Disable 32-bit UIDs */
4775 +#define EXT2_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
4777 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
4778 #define set_opt(o, opt) o |= EXT2_MOUNT_##opt
4779 @@ -397,6 +373,7 @@ struct ext2_super_block {
4782 #define EXT2_SB(sb) (&((sb)->u.ext2_sb))
4783 +#define EXT2_I(inode) (&((inode)->u.ext2_i))
4785 /* Assume that user mode programs are passing in an ext2fs superblock, not
4786 * a kernel struct super_block. This will allow us to call the feature-test
4787 @@ -466,7 +443,7 @@ struct ext2_super_block {
4788 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
4789 #define EXT2_FEATURE_INCOMPAT_ANY 0xffffffff
4791 -#define EXT2_FEATURE_COMPAT_SUPP 0
4792 +#define EXT2_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
4793 #define EXT2_FEATURE_INCOMPAT_SUPP EXT2_FEATURE_INCOMPAT_FILETYPE
4794 #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
4795 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
4796 @@ -624,8 +601,10 @@ extern struct address_space_operations e
4799 extern struct inode_operations ext2_dir_inode_operations;
4800 +extern struct inode_operations ext2_special_inode_operations;
4803 +extern struct inode_operations ext2_symlink_inode_operations;
4804 extern struct inode_operations ext2_fast_symlink_inode_operations;
4806 #endif /* __KERNEL__ */
4807 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
4808 +++ linux-2.4.22-ac1-alexey/include/linux/ext2_xattr.h 2003-09-25 23:57:02.000000000 +0400
4811 + File: linux/ext2_xattr.h
4813 + On-disk format of extended attributes for the ext2 filesystem.
4815 + (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
4818 +#include <linux/config.h>
4819 +#include <linux/init.h>
4820 +#include <linux/xattr.h>
4822 +/* Magic value in attribute blocks */
4823 +#define EXT2_XATTR_MAGIC 0xEA020000
4825 +/* Maximum number of references to one attribute block */
4826 +#define EXT2_XATTR_REFCOUNT_MAX 1024
4829 +#define EXT2_XATTR_INDEX_MAX 10
4830 +#define EXT2_XATTR_INDEX_USER 1
4831 +#define EXT2_XATTR_INDEX_POSIX_ACL_ACCESS 2
4832 +#define EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT 3
4834 +struct ext2_xattr_header {
4835 + __u32 h_magic; /* magic number for identification */
4836 + __u32 h_refcount; /* reference count */
4837 + __u32 h_blocks; /* number of disk blocks used */
4838 + __u32 h_hash; /* hash value of all attributes */
4839 + __u32 h_reserved[4]; /* zero right now */
4842 +struct ext2_xattr_entry {
4843 + __u8 e_name_len; /* length of name */
4844 + __u8 e_name_index; /* attribute name index */
4845 + __u16 e_value_offs; /* offset in disk block of value */
4846 + __u32 e_value_block; /* disk block attribute is stored on (n/i) */
4847 + __u32 e_value_size; /* size of attribute value */
4848 + __u32 e_hash; /* hash value of name and value */
4849 + char e_name[0]; /* attribute name */
4852 +#define EXT2_XATTR_PAD_BITS 2
4853 +#define EXT2_XATTR_PAD (1<<EXT2_XATTR_PAD_BITS)
4854 +#define EXT2_XATTR_ROUND (EXT2_XATTR_PAD-1)
4855 +#define EXT2_XATTR_LEN(name_len) \
4856 + (((name_len) + EXT2_XATTR_ROUND + \
4857 + sizeof(struct ext2_xattr_entry)) & ~EXT2_XATTR_ROUND)
4858 +#define EXT2_XATTR_NEXT(entry) \
4859 + ( (struct ext2_xattr_entry *)( \
4860 + (char *)(entry) + EXT2_XATTR_LEN((entry)->e_name_len)) )
4861 +#define EXT2_XATTR_SIZE(size) \
4862 + (((size) + EXT2_XATTR_ROUND) & ~EXT2_XATTR_ROUND)
4866 +# ifdef CONFIG_EXT2_FS_XATTR
4868 +struct ext2_xattr_handler {
4870 + size_t (*list)(char *list, struct inode *inode, const char *name,
4872 + int (*get)(struct inode *inode, const char *name, void *buffer,
4874 + int (*set)(struct inode *inode, const char *name, const void *buffer,
4875 + size_t size, int flags);
4878 +extern int ext2_xattr_register(int, struct ext2_xattr_handler *);
4879 +extern void ext2_xattr_unregister(int, struct ext2_xattr_handler *);
4881 +extern int ext2_setxattr(struct dentry *, const char *, const void *, size_t, int);
4882 +extern ssize_t ext2_getxattr(struct dentry *, const char *, void *, size_t);
4883 +extern ssize_t ext2_listxattr(struct dentry *, char *, size_t);
4884 +extern int ext2_removexattr(struct dentry *, const char *);
4886 +extern int ext2_xattr_get(struct inode *, int, const char *, void *, size_t);
4887 +extern int ext2_xattr_list(struct inode *, char *, size_t);
4888 +extern int ext2_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
4890 +extern void ext2_xattr_delete_inode(struct inode *);
4891 +extern void ext2_xattr_put_super(struct super_block *);
4893 +extern int init_ext2_xattr(void) __init;
4894 +extern void exit_ext2_xattr(void);
4896 +# else /* CONFIG_EXT2_FS_XATTR */
4897 +# define ext2_setxattr NULL
4898 +# define ext2_getxattr NULL
4899 +# define ext2_listxattr NULL
4900 +# define ext2_removexattr NULL
4903 +ext2_xattr_get(struct inode *inode, int name_index,
4904 + const char *name, void *buffer, size_t size)
4910 +ext2_xattr_list(struct inode *inode, char *buffer, size_t size)
4916 +ext2_xattr_set(struct inode *inode, int name_index, const char *name,
4917 + const void *value, size_t size, int flags)
4923 +ext2_xattr_delete_inode(struct inode *inode)
4928 +ext2_xattr_put_super(struct super_block *sb)
4933 +init_ext2_xattr(void)
4939 +exit_ext2_xattr(void)
4943 +# endif /* CONFIG_EXT2_FS_XATTR */
4945 +# ifdef CONFIG_EXT2_FS_XATTR_USER
4947 +extern int init_ext2_xattr_user(void) __init;
4948 +extern void exit_ext2_xattr_user(void);
4950 +# else /* CONFIG_EXT2_FS_XATTR_USER */
4953 +init_ext2_xattr_user(void)
4959 +exit_ext2_xattr_user(void)
4963 +# endif /* CONFIG_EXT2_FS_XATTR_USER */
4965 +#endif /* __KERNEL__ */
4967 --- linux-2.4.22-ac1/include/linux/ext3_fs.h~xattr-0.8.54-2.4.22-rh 2003-09-25 14:58:30.000000000 +0400
4968 +++ linux-2.4.22-ac1-alexey/include/linux/ext3_fs.h 2003-09-25 23:57:02.000000000 +0400
4971 #define EXT3_BAD_INO 1 /* Bad blocks inode */
4972 #define EXT3_ROOT_INO 2 /* Root inode */
4973 -#define EXT3_ACL_IDX_INO 3 /* ACL inode */
4974 -#define EXT3_ACL_DATA_INO 4 /* ACL inode */
4975 #define EXT3_BOOT_LOADER_INO 5 /* Boot loader inode */
4976 #define EXT3_UNDEL_DIR_INO 6 /* Undelete directory inode */
4977 #define EXT3_RESIZE_INO 7 /* Reserved group descriptors inode */
4980 # define EXT3_BLOCK_SIZE(s) (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
4982 -#define EXT3_ACLE_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_acl_entry))
4983 #define EXT3_ADDR_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (__u32))
4985 # define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
4986 @@ -129,28 +126,6 @@
4992 -struct ext3_acl_header /* Header of Access Control Lists */
4995 - __u32 aclh_file_count;
4996 - __u32 aclh_acle_count;
4997 - __u32 aclh_first_acle;
5000 -struct ext3_acl_entry /* Access Control List Entry */
5003 - __u16 acle_perms; /* Access permissions */
5004 - __u16 acle_type; /* Type of entry */
5005 - __u16 acle_tag; /* User or group identity */
5007 - __u32 acle_next; /* Pointer on next entry for the */
5008 - /* same inode or on next free entry */
5012 * Structure of a blocks group descriptor
5014 struct ext3_group_desc
5015 @@ -346,6 +321,7 @@ struct ext3_inode {
5016 #define EXT3_MOUNT_WRITEBACK_DATA 0x0C00 /* No data ordering */
5017 #define EXT3_MOUNT_UPDATE_JOURNAL 0x1000 /* Update the journal format */
5018 #define EXT3_MOUNT_NO_UID32 0x2000 /* Disable 32-bit UIDs */
5019 +#define EXT3_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
5021 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
5022 #ifndef _LINUX_EXT2_FS_H
5023 @@ -523,7 +499,7 @@ struct ext3_super_block {
5024 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
5025 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
5027 -#define EXT3_FEATURE_COMPAT_SUPP 0
5028 +#define EXT3_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
5029 #define EXT3_FEATURE_INCOMPAT_SUPP (EXT3_FEATURE_INCOMPAT_FILETYPE| \
5030 EXT3_FEATURE_INCOMPAT_RECOVER)
5031 #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
5032 @@ -707,6 +683,7 @@ extern void ext3_check_inodes_bitmap (st
5033 extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
5036 +extern int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
5037 extern struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
5038 extern struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
5040 @@ -776,8 +753,10 @@ extern struct address_space_operations e
5043 extern struct inode_operations ext3_dir_inode_operations;
5044 +extern struct inode_operations ext3_special_inode_operations;
5047 +extern struct inode_operations ext3_symlink_inode_operations;
5048 extern struct inode_operations ext3_fast_symlink_inode_operations;
5051 --- linux-2.4.22-ac1/include/linux/ext3_jbd.h~xattr-0.8.54-2.4.22-rh 2003-09-25 14:55:12.000000000 +0400
5052 +++ linux-2.4.22-ac1-alexey/include/linux/ext3_jbd.h 2003-09-25 23:57:02.000000000 +0400
5055 #define EXT3_SINGLEDATA_TRANS_BLOCKS 8U
5057 +/* Extended attributes may touch two data buffers, two bitmap buffers,
5058 + * and two group and summaries. */
5060 +#define EXT3_XATTR_TRANS_BLOCKS 8
5062 /* Define the minimum size for a transaction which modifies data. This
5063 * needs to take into account the fact that we may end up modifying two
5064 * quota files too (one for the group, one for the user quota). The
5065 * superblock only gets updated once, of course, so don't bother
5066 * counting that again for the quota updates. */
5068 -#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS - 2)
5069 +#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS + \
5070 + EXT3_XATTR_TRANS_BLOCKS - 2)
5072 extern int ext3_writepage_trans_blocks(struct inode *inode);
5074 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
5075 +++ linux-2.4.22-ac1-alexey/include/linux/ext3_xattr.h 2003-09-25 23:57:02.000000000 +0400
5078 + File: linux/ext3_xattr.h
5080 + On-disk format of extended attributes for the ext3 filesystem.
5082 + (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
5085 +#include <linux/config.h>
5086 +#include <linux/init.h>
5087 +#include <linux/xattr.h>
5089 +/* Magic value in attribute blocks */
5090 +#define EXT3_XATTR_MAGIC 0xEA020000
5092 +/* Maximum number of references to one attribute block */
5093 +#define EXT3_XATTR_REFCOUNT_MAX 1024
5096 +#define EXT3_XATTR_INDEX_MAX 10
5097 +#define EXT3_XATTR_INDEX_USER 1
5098 +#define EXT3_XATTR_INDEX_POSIX_ACL_ACCESS 2
5099 +#define EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT 3
5101 +struct ext3_xattr_header {
5102 + __u32 h_magic; /* magic number for identification */
5103 + __u32 h_refcount; /* reference count */
5104 + __u32 h_blocks; /* number of disk blocks used */
5105 + __u32 h_hash; /* hash value of all attributes */
5106 + __u32 h_reserved[4]; /* zero right now */
5109 +struct ext3_xattr_entry {
5110 + __u8 e_name_len; /* length of name */
5111 + __u8 e_name_index; /* attribute name index */
5112 + __u16 e_value_offs; /* offset in disk block of value */
5113 + __u32 e_value_block; /* disk block attribute is stored on (n/i) */
5114 + __u32 e_value_size; /* size of attribute value */
5115 + __u32 e_hash; /* hash value of name and value */
5116 + char e_name[0]; /* attribute name */
5119 +#define EXT3_XATTR_PAD_BITS 2
5120 +#define EXT3_XATTR_PAD (1<<EXT3_XATTR_PAD_BITS)
5121 +#define EXT3_XATTR_ROUND (EXT3_XATTR_PAD-1)
5122 +#define EXT3_XATTR_LEN(name_len) \
5123 + (((name_len) + EXT3_XATTR_ROUND + \
5124 + sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND)
5125 +#define EXT3_XATTR_NEXT(entry) \
5126 + ( (struct ext3_xattr_entry *)( \
5127 + (char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) )
5128 +#define EXT3_XATTR_SIZE(size) \
5129 + (((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND)
5133 +# ifdef CONFIG_EXT3_FS_XATTR
5135 +struct ext3_xattr_handler {
5137 + size_t (*list)(char *list, struct inode *inode, const char *name,
5139 + int (*get)(struct inode *inode, const char *name, void *buffer,
5141 + int (*set)(struct inode *inode, const char *name, const void *buffer,
5142 + size_t size, int flags);
5145 +extern int ext3_xattr_register(int, struct ext3_xattr_handler *);
5146 +extern void ext3_xattr_unregister(int, struct ext3_xattr_handler *);
5148 +extern int ext3_setxattr(struct dentry *, const char *, const void *, size_t, int);
5149 +extern ssize_t ext3_getxattr(struct dentry *, const char *, void *, size_t);
5150 +extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
5151 +extern int ext3_removexattr(struct dentry *, const char *);
5153 +extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
5154 +extern int ext3_xattr_list(struct inode *, char *, size_t);
5155 +extern int ext3_xattr_set(handle_t *handle, struct inode *, int, const char *, const void *, size_t, int);
5157 +extern void ext3_xattr_delete_inode(handle_t *, struct inode *);
5158 +extern void ext3_xattr_put_super(struct super_block *);
5160 +extern int init_ext3_xattr(void) __init;
5161 +extern void exit_ext3_xattr(void);
5163 +# else /* CONFIG_EXT3_FS_XATTR */
5164 +# define ext3_setxattr NULL
5165 +# define ext3_getxattr NULL
5166 +# define ext3_listxattr NULL
5167 +# define ext3_removexattr NULL
5170 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
5171 + void *buffer, size_t size)
5177 +ext3_xattr_list(struct inode *inode, void *buffer, size_t size)
5183 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
5184 + const char *name, const void *value, size_t size, int flags)
5190 +ext3_xattr_delete_inode(handle_t *handle, struct inode *inode)
5195 +ext3_xattr_put_super(struct super_block *sb)
5200 +init_ext3_xattr(void)
5206 +exit_ext3_xattr(void)
5210 +# endif /* CONFIG_EXT3_FS_XATTR */
5212 +# ifdef CONFIG_EXT3_FS_XATTR_USER
5214 +extern int init_ext3_xattr_user(void) __init;
5215 +extern void exit_ext3_xattr_user(void);
5217 +# else /* CONFIG_EXT3_FS_XATTR_USER */
5220 +init_ext3_xattr_user(void)
5226 +exit_ext3_xattr_user(void)
5230 +#endif /* CONFIG_EXT3_FS_XATTR_USER */
5232 +#endif /* __KERNEL__ */
5234 --- linux-2.4.22-ac1/include/linux/fs.h~xattr-0.8.54-2.4.22-rh 2003-09-25 14:45:32.000000000 +0400
5235 +++ linux-2.4.22-ac1-alexey/include/linux/fs.h 2003-09-25 23:57:02.000000000 +0400
5236 @@ -918,7 +918,7 @@ struct inode_operations {
5237 int (*setattr) (struct dentry *, struct iattr *);
5238 int (*setattr_raw) (struct inode *, struct iattr *);
5239 int (*getattr) (struct dentry *, struct iattr *);
5240 - int (*setxattr) (struct dentry *, const char *, void *, size_t, int);
5241 + int (*setxattr) (struct dentry *, const char *, const void *, size_t, int);
5242 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
5243 ssize_t (*listxattr) (struct dentry *, char *, size_t);
5244 int (*removexattr) (struct dentry *, const char *);
5245 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
5246 +++ linux-2.4.22-ac1-alexey/include/linux/mbcache.h 2003-09-25 23:57:02.000000000 +0400
5249 + File: linux/mbcache.h
5251 + (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
5254 +/* Hardwire the number of additional indexes */
5255 +#define MB_CACHE_INDEXES_COUNT 1
5257 +struct mb_cache_entry;
5259 +struct mb_cache_op {
5260 + int (*free)(struct mb_cache_entry *, int);
5264 + struct list_head c_cache_list;
5265 + const char *c_name;
5266 + struct mb_cache_op c_op;
5267 + atomic_t c_entry_count;
5268 + int c_bucket_count;
5269 +#ifndef MB_CACHE_INDEXES_COUNT
5270 + int c_indexes_count;
5272 + kmem_cache_t *c_entry_cache;
5273 + struct list_head *c_block_hash;
5274 + struct list_head *c_indexes_hash[0];
5277 +struct mb_cache_entry_index {
5278 + struct list_head o_list;
5279 + unsigned int o_key;
5282 +struct mb_cache_entry {
5283 + struct list_head e_lru_list;
5284 + struct mb_cache *e_cache;
5287 + unsigned long e_block;
5288 + struct list_head e_block_list;
5289 + struct mb_cache_entry_index e_indexes[0];
5292 +/* Functions on caches */
5294 +struct mb_cache * mb_cache_create(const char *, struct mb_cache_op *, size_t,
5296 +void mb_cache_shrink(struct mb_cache *, kdev_t);
5297 +void mb_cache_destroy(struct mb_cache *);
5299 +/* Functions on cache entries */
5301 +struct mb_cache_entry *mb_cache_entry_alloc(struct mb_cache *);
5302 +int mb_cache_entry_insert(struct mb_cache_entry *, kdev_t, unsigned long,
5304 +void mb_cache_entry_rehash(struct mb_cache_entry *, unsigned int[]);
5305 +void mb_cache_entry_release(struct mb_cache_entry *);
5306 +void mb_cache_entry_takeout(struct mb_cache_entry *);
5307 +void mb_cache_entry_free(struct mb_cache_entry *);
5308 +struct mb_cache_entry *mb_cache_entry_dup(struct mb_cache_entry *);
5309 +struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *, kdev_t,
5311 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
5312 +struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache, int,
5313 + kdev_t, unsigned int);
5314 +struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache_entry *, int,
5315 + kdev_t, unsigned int);
5317 --- linux-2.4.22-ac1/kernel/ksyms.c~xattr-0.8.54-2.4.22-rh 2003-09-25 14:42:46.000000000 +0400
5318 +++ linux-2.4.22-ac1-alexey/kernel/ksyms.c 2003-09-26 00:19:05.000000000 +0400
5321 #include <linux/config.h>
5322 #include <linux/slab.h>
5323 +#include <linux/cache_def.h>
5324 #include <linux/smp.h>
5325 #include <linux/module.h>
5326 #include <linux/blkdev.h>
5327 @@ -106,6 +107,7 @@ EXPORT_SYMBOL(exit_files);
5328 EXPORT_SYMBOL(exit_fs);
5329 EXPORT_SYMBOL(exit_sighand);
5330 EXPORT_SYMBOL(unshare_files);
5331 +EXPORT_SYMBOL(copy_fs_struct);
5333 /* internal kernel memory management */
5334 EXPORT_SYMBOL(_alloc_pages);
5335 @@ -124,6 +126,8 @@ EXPORT_SYMBOL(kmem_cache_validate);
5336 EXPORT_SYMBOL(kmem_cache_alloc);
5337 EXPORT_SYMBOL(kmem_cache_free);
5338 EXPORT_SYMBOL(kmem_cache_size);
5339 +EXPORT_SYMBOL(register_cache);
5340 +EXPORT_SYMBOL(unregister_cache);
5341 EXPORT_SYMBOL(kmalloc);
5342 EXPORT_SYMBOL(kfree);
5343 EXPORT_SYMBOL(vfree);
5344 --- linux-2.4.22-ac1/mm/vmscan.c~xattr-0.8.54-2.4.22-rh 2003-09-25 14:16:28.000000000 +0400
5345 +++ linux-2.4.22-ac1-alexey/mm/vmscan.c 2003-09-25 23:57:02.000000000 +0400
5347 #include <linux/kernel_stat.h>
5348 #include <linux/swap.h>
5349 #include <linux/swapctl.h>
5350 +#include <linux/cache_def.h>
5351 #include <linux/smp_lock.h>
5352 #include <linux/pagemap.h>
5353 #include <linux/init.h>
5356 #define DEF_PRIORITY (6)
5358 +static DECLARE_MUTEX(other_caches_sem);
5359 +static LIST_HEAD(cache_definitions);
5361 +void register_cache(struct cache_definition *cache)
5363 + down(&other_caches_sem);
5364 + list_add(&cache->link, &cache_definitions);
5365 + up(&other_caches_sem);
5368 +void unregister_cache(struct cache_definition *cache)
5370 + down(&other_caches_sem);
5371 + list_del(&cache->link);
5372 + up(&other_caches_sem);
5375 +static void shrink_other_caches(unsigned int priority, int gfp_mask)
5377 + struct list_head *p;
5379 + if (down_trylock(&other_caches_sem))
5382 + list_for_each_prev(p, &cache_definitions) {
5383 + struct cache_definition *cache =
5384 + list_entry(p, struct cache_definition, link);
5386 + cache->shrink(priority, gfp_mask);
5388 + up(&other_caches_sem);
5392 * The swap-out function returns 1 if it successfully
5393 * scanned all the pages it was asked to (`count').
5394 @@ -577,6 +611,7 @@ static int shrink_caches(zone_t * classz
5396 shrink_dcache_memory(priority, gfp_mask);
5397 shrink_icache_memory(priority, gfp_mask);
5398 + shrink_other_caches(priority, gfp_mask);
5400 shrink_dqcache_memory(DEF_PRIORITY, gfp_mask);