1 Documentation/Configure.help | 66 ++
2 arch/ia64/defconfig | 7
11 fs/ext2/symlink.c | 14
12 fs/ext2/xattr.c | 1212 +++++++++++++++++++++++++++++++++++++++++
13 fs/ext2/xattr_user.c | 103 +++
15 fs/ext3/ext3-exports.c | 13
18 fs/ext3/inode.c | 35 -
20 fs/ext3/super.c | 36 +
21 fs/ext3/symlink.c | 14
22 fs/ext3/xattr.c | 1225 ++++++++++++++++++++++++++++++++++++++++++
23 fs/ext3/xattr_user.c | 111 +++
24 fs/jfs/jfs_xattr.h | 6
26 fs/mbcache.c | 648 ++++++++++++++++++++++
27 include/linux/cache_def.h | 15
28 include/linux/errno.h | 4
29 include/linux/ext2_fs.h | 31 -
30 include/linux/ext2_xattr.h | 157 +++++
31 include/linux/ext3_fs.h | 31 -
32 include/linux/ext3_jbd.h | 8
33 include/linux/ext3_xattr.h | 157 +++++
34 include/linux/fs.h | 2
35 include/linux/mbcache.h | 69 ++
38 62 files changed, 4343 insertions(+), 182 deletions(-)
40 --- linux/Documentation/Configure.help~linux-2.4.20-xattr-0.8.54-hp Fri May 16 08:39:23 2003
41 +++ linux-mmonroe/Documentation/Configure.help Fri May 16 08:43:00 2003
42 @@ -15309,6 +15309,39 @@ CONFIG_EXT2_FS
43 be compiled as a module, and so this could be dangerous. Most
44 everyone wants to say Y here.
46 +Ext2 extended attributes
48 + Extended attributes are name:value pairs associated with inodes by
49 + the kernel or by users (see the attr(5) manual page, or visit
50 + <http://acl.bestbits.at/> for details).
54 +Ext2 extended attribute block sharing
55 +CONFIG_EXT2_FS_XATTR_SHARING
56 + This options enables code for sharing identical extended attribute
57 + blocks among multiple inodes.
61 +Ext2 extended user attributes
62 +CONFIG_EXT2_FS_XATTR_USER
63 + This option enables extended user attributes on ext2. Processes can
64 + associate extended user attributes with inodes to store additional
65 + information such as the character encoding of files, etc. (see the
66 + attr(5) manual page, or visit <http://acl.bestbits.at/> for details).
70 +Ext2 trusted extended attributes
71 +CONFIG_EXT2_FS_XATTR_TRUSTED
72 + This option enables extended attributes on ext2 that are accessible
73 + (and visible) only to users capable of CAP_SYS_ADMIN. Usually this
74 + is only the super user. Trusted extended attributes are meant for
75 + implementing system/security services.
79 Ext3 journalling file system support (EXPERIMENTAL)
81 This is the journalling version of the Second extended file system
82 @@ -15341,6 +15374,39 @@ CONFIG_EXT3_FS
83 of your root partition (the one containing the directory /) cannot
84 be compiled as a module, and so this may be dangerous.
86 +Ext3 extended attributes
88 + Extended attributes are name:value pairs associated with inodes by
89 + the kernel or by users (see the attr(5) manual page, or visit
90 + <http://acl.bestbits.at/> for details).
94 +Ext3 extended attribute block sharing
95 +CONFIG_EXT3_FS_XATTR_SHARING
96 + This options enables code for sharing identical extended attribute
97 + blocks among multiple inodes.
101 +Ext3 extended user attributes
102 +CONFIG_EXT3_FS_XATTR_USER
103 + This option enables extended user attributes on ext3. Processes can
104 + associate extended user attributes with inodes to store additional
105 + information such as the character encoding of files, etc. (see the
106 + attr(5) manual page, or visit <http://acl.bestbits.at/> for details).
110 +Ext3 trusted extended attributes
111 +CONFIG_EXT3_FS_XATTR_TRUSTED
112 + This option enables extended attributes on ext3 that are accessible
113 + (and visible) only to users capable of CAP_SYS_ADMIN. Usually this
114 + is only the super user. Trusted extended attributes are meant for
115 + implementing system/security services.
119 Journal Block Device support (JBD for ext3) (EXPERIMENTAL)
121 This is a generic journalling layer for block devices. It is
122 --- linux/arch/ia64/defconfig~linux-2.4.20-xattr-0.8.54-hp Fri May 16 08:39:14 2003
123 +++ linux-mmonroe/arch/ia64/defconfig Fri May 16 08:43:00 2003
126 # Automatically generated make config: don't edit
128 +CONFIG_EXT3_FS_XATTR=y
129 +# CONFIG_EXT3_FS_XATTR_SHARING is not set
130 +# CONFIG_EXT3_FS_XATTR_USER is not set
131 +# CONFIG_EXT2_FS_XATTR is not set
132 +# CONFIG_EXT2_FS_XATTR_SHARING is not set
133 +# CONFIG_EXT2_FS_XATTR_USER is not set
134 +# CONFIG_FS_MBCACHE is not set
137 # Code maturity level options
138 --- linux/fs/Config.in~linux-2.4.20-xattr-0.8.54-hp Fri May 16 08:39:14 2003
139 +++ linux-mmonroe/fs/Config.in Fri May 16 08:43:01 2003
140 @@ -35,6 +35,11 @@ dep_mbool ' Debug Befs' CONFIG_BEFS_DEB
141 dep_tristate 'BFS file system support (EXPERIMENTAL)' CONFIG_BFS_FS $CONFIG_EXPERIMENTAL
143 tristate 'Ext3 journalling file system support' CONFIG_EXT3_FS
144 +dep_mbool ' Ext3 extended attributes' CONFIG_EXT3_FS_XATTR $CONFIG_EXT3_FS
145 +dep_bool ' Ext3 extended attribute block sharing' \
146 + CONFIG_EXT3_FS_XATTR_SHARING $CONFIG_EXT3_FS_XATTR
147 +dep_bool ' Ext3 extended user attributes' \
148 + CONFIG_EXT3_FS_XATTR_USER $CONFIG_EXT3_FS_XATTR
149 # CONFIG_JBD could be its own option (even modular), but until there are
150 # other users than ext3, we will simply make it be the same as CONFIG_EXT3_FS
151 # dep_tristate ' Journal Block Device support (JBD for ext3)' CONFIG_JBD $CONFIG_EXT3_FS
152 @@ -98,6 +103,11 @@ dep_mbool ' QNX4FS write support (DANGE
153 tristate 'ROM file system support' CONFIG_ROMFS_FS
155 tristate 'Second extended fs support' CONFIG_EXT2_FS
156 +dep_mbool ' Ext2 extended attributes' CONFIG_EXT2_FS_XATTR $CONFIG_EXT2_FS
157 +dep_bool ' Ext2 extended attribute block sharing' \
158 + CONFIG_EXT2_FS_XATTR_SHARING $CONFIG_EXT2_FS_XATTR
159 +dep_bool ' Ext2 extended user attributes' \
160 + CONFIG_EXT2_FS_XATTR_USER $CONFIG_EXT2_FS_XATTR
162 tristate 'System V/Xenix/V7/Coherent file system support' CONFIG_SYSV_FS
164 @@ -176,6 +186,10 @@ else
165 define_tristate CONFIG_ZISOFS_FS n
168 +# Meta block cache for Extended Attributes (ext2/ext3)
169 +#tristate 'Meta block cache' CONFIG_FS_MBCACHE
170 +define_tristate CONFIG_FS_MBCACHE y
172 mainmenu_option next_comment
173 comment 'Partition Types'
174 source fs/partitions/Config.in
175 --- linux/fs/Makefile~linux-2.4.20-xattr-0.8.54-hp Fri May 16 08:42:46 2003
176 +++ linux-mmonroe/fs/Makefile Fri May 16 08:43:01 2003
177 @@ -80,6 +80,9 @@ obj-y += binfmt_script.o
179 obj-$(CONFIG_BINFMT_ELF) += binfmt_elf.o
181 +export-objs += mbcache.o
182 +obj-$(CONFIG_FS_MBCACHE) += mbcache.o
184 # persistent filesystems
185 obj-y += $(join $(subdir-y),$(subdir-y:%=/%.o))
187 --- linux/fs/ext2/Makefile~linux-2.4.20-xattr-0.8.54-hp Thu Oct 11 08:05:18 2001
188 +++ linux-mmonroe/fs/ext2/Makefile Fri May 16 08:43:01 2003
189 @@ -13,4 +13,8 @@ obj-y := balloc.o bitmap.o dir.o file
190 ioctl.o namei.o super.o symlink.o
193 +export-objs += xattr.o
194 +obj-$(CONFIG_EXT2_FS_XATTR) += xattr.o
195 +obj-$(CONFIG_EXT2_FS_XATTR_USER) += xattr_user.o
197 include $(TOPDIR)/Rules.make
198 --- linux/fs/ext2/file.c~linux-2.4.20-xattr-0.8.54-hp Thu Oct 11 08:05:18 2001
199 +++ linux-mmonroe/fs/ext2/file.c Fri May 16 08:43:01 2003
202 #include <linux/fs.h>
203 #include <linux/ext2_fs.h>
204 +#include <linux/ext2_xattr.h>
205 #include <linux/sched.h>
208 @@ -51,4 +52,8 @@ struct file_operations ext2_file_operati
210 struct inode_operations ext2_file_inode_operations = {
211 truncate: ext2_truncate,
212 + setxattr: ext2_setxattr,
213 + getxattr: ext2_getxattr,
214 + listxattr: ext2_listxattr,
215 + removexattr: ext2_removexattr,
217 --- linux/fs/ext2/ialloc.c~linux-2.4.20-xattr-0.8.54-hp Thu Nov 28 15:53:15 2002
218 +++ linux-mmonroe/fs/ext2/ialloc.c Fri May 16 08:43:01 2003
220 #include <linux/config.h>
221 #include <linux/fs.h>
222 #include <linux/ext2_fs.h>
223 +#include <linux/ext2_xattr.h>
224 #include <linux/locks.h>
225 #include <linux/quotaops.h>
227 @@ -167,6 +168,7 @@ void ext2_free_inode (struct inode * ino
229 if (!is_bad_inode(inode)) {
230 /* Quota is already initialized in iput() */
231 + ext2_xattr_delete_inode(inode);
232 DQUOT_FREE_INODE(inode);
235 --- linux/fs/ext2/inode.c~linux-2.4.20-xattr-0.8.54-hp Thu Nov 28 15:53:15 2002
236 +++ linux-mmonroe/fs/ext2/inode.c Fri May 16 08:43:01 2003
237 @@ -39,6 +39,18 @@ MODULE_LICENSE("GPL");
238 static int ext2_update_inode(struct inode * inode, int do_sync);
241 + * Test whether an inode is a fast symlink.
243 +static inline int ext2_inode_is_fast_symlink(struct inode *inode)
245 + int ea_blocks = inode->u.ext2_i.i_file_acl ?
246 + (inode->i_sb->s_blocksize >> 9) : 0;
248 + return (S_ISLNK(inode->i_mode) &&
249 + inode->i_blocks - ea_blocks == 0);
253 * Called at each iput()
255 void ext2_put_inode (struct inode * inode)
256 @@ -53,9 +65,7 @@ void ext2_delete_inode (struct inode * i
260 - if (is_bad_inode(inode) ||
261 - inode->i_ino == EXT2_ACL_IDX_INO ||
262 - inode->i_ino == EXT2_ACL_DATA_INO)
263 + if (is_bad_inode(inode))
265 inode->u.ext2_i.i_dtime = CURRENT_TIME;
266 mark_inode_dirty(inode);
267 @@ -801,6 +811,8 @@ void ext2_truncate (struct inode * inode
268 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
269 S_ISLNK(inode->i_mode)))
271 + if (ext2_inode_is_fast_symlink(inode))
273 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
276 @@ -888,8 +900,7 @@ void ext2_read_inode (struct inode * ino
277 unsigned long offset;
278 struct ext2_group_desc * gdp;
280 - if ((inode->i_ino != EXT2_ROOT_INO && inode->i_ino != EXT2_ACL_IDX_INO &&
281 - inode->i_ino != EXT2_ACL_DATA_INO &&
282 + if ((inode->i_ino != EXT2_ROOT_INO &&
283 inode->i_ino < EXT2_FIRST_INO(inode->i_sb)) ||
284 inode->i_ino > le32_to_cpu(inode->i_sb->u.ext2_sb.s_es->s_inodes_count)) {
285 ext2_error (inode->i_sb, "ext2_read_inode",
286 @@ -974,10 +985,7 @@ void ext2_read_inode (struct inode * ino
287 for (block = 0; block < EXT2_N_BLOCKS; block++)
288 inode->u.ext2_i.i_data[block] = raw_inode->i_block[block];
290 - if (inode->i_ino == EXT2_ACL_IDX_INO ||
291 - inode->i_ino == EXT2_ACL_DATA_INO)
292 - /* Nothing to do */ ;
293 - else if (S_ISREG(inode->i_mode)) {
294 + if (S_ISREG(inode->i_mode)) {
295 inode->i_op = &ext2_file_inode_operations;
296 inode->i_fop = &ext2_file_operations;
297 inode->i_mapping->a_ops = &ext2_aops;
298 @@ -986,15 +994,17 @@ void ext2_read_inode (struct inode * ino
299 inode->i_fop = &ext2_dir_operations;
300 inode->i_mapping->a_ops = &ext2_aops;
301 } else if (S_ISLNK(inode->i_mode)) {
302 - if (!inode->i_blocks)
303 + if (ext2_inode_is_fast_symlink(inode))
304 inode->i_op = &ext2_fast_symlink_inode_operations;
306 - inode->i_op = &page_symlink_inode_operations;
307 + inode->i_op = &ext2_symlink_inode_operations;
308 inode->i_mapping->a_ops = &ext2_aops;
312 + inode->i_op = &ext2_special_inode_operations;
313 init_special_inode(inode, inode->i_mode,
314 le32_to_cpu(raw_inode->i_block[0]));
317 inode->i_attr_flags = 0;
318 if (inode->u.ext2_i.i_flags & EXT2_SYNC_FL) {
319 --- linux/fs/ext2/namei.c~linux-2.4.20-xattr-0.8.54-hp Wed Oct 3 22:57:36 2001
320 +++ linux-mmonroe/fs/ext2/namei.c Fri May 16 08:43:01 2003
323 #include <linux/fs.h>
324 #include <linux/ext2_fs.h>
325 +#include <linux/ext2_xattr.h>
326 #include <linux/pagemap.h>
329 @@ -136,7 +137,7 @@ static int ext2_symlink (struct inode *
331 if (l > sizeof (inode->u.ext2_i.i_data)) {
333 - inode->i_op = &page_symlink_inode_operations;
334 + inode->i_op = &ext2_symlink_inode_operations;
335 inode->i_mapping->a_ops = &ext2_aops;
336 err = block_symlink(inode, symname, l);
338 @@ -345,4 +346,15 @@ struct inode_operations ext2_dir_inode_o
342 + setxattr: ext2_setxattr,
343 + getxattr: ext2_getxattr,
344 + listxattr: ext2_listxattr,
345 + removexattr: ext2_removexattr,
348 +struct inode_operations ext2_special_inode_operations = {
349 + setxattr: ext2_setxattr,
350 + getxattr: ext2_getxattr,
351 + listxattr: ext2_listxattr,
352 + removexattr: ext2_removexattr,
354 --- linux/fs/ext2/super.c~linux-2.4.20-xattr-0.8.54-hp Thu Nov 28 15:53:15 2002
355 +++ linux-mmonroe/fs/ext2/super.c Fri May 16 08:43:01 2003
357 #include <linux/string.h>
358 #include <linux/fs.h>
359 #include <linux/ext2_fs.h>
360 +#include <linux/ext2_xattr.h>
361 #include <linux/slab.h>
362 #include <linux/init.h>
363 #include <linux/locks.h>
364 @@ -125,6 +126,7 @@ void ext2_put_super (struct super_block
368 + ext2_xattr_put_super(sb);
369 if (!(sb->s_flags & MS_RDONLY)) {
370 struct ext2_super_block *es = EXT2_SB(sb)->s_es;
372 @@ -175,6 +177,13 @@ static int parse_options (char * options
373 this_char = strtok (NULL, ",")) {
374 if ((value = strchr (this_char, '=')) != NULL)
376 +#ifdef CONFIG_EXT2_FS_XATTR_USER
377 + if (!strcmp (this_char, "user_xattr"))
378 + set_opt (*mount_options, XATTR_USER);
379 + else if (!strcmp (this_char, "nouser_xattr"))
380 + clear_opt (*mount_options, XATTR_USER);
383 if (!strcmp (this_char, "bsddf"))
384 clear_opt (*mount_options, MINIX_DF);
385 else if (!strcmp (this_char, "nouid32")) {
386 @@ -424,6 +433,9 @@ struct super_block * ext2_read_super (st
387 blocksize = BLOCK_SIZE;
389 sb->u.ext2_sb.s_mount_opt = 0;
390 +#ifdef CONFIG_EXT2_FS_XATTR_USER
391 + /* set_opt (sb->u.ext2_sb.s_mount_opt, XATTR_USER); */
393 if (!parse_options ((char *) data, &sb_block, &resuid, &resgid,
394 &sb->u.ext2_sb.s_mount_opt)) {
396 @@ -813,12 +825,27 @@ static DECLARE_FSTYPE_DEV(ext2_fs_type,
398 static int __init init_ext2_fs(void)
400 - return register_filesystem(&ext2_fs_type);
401 + int error = init_ext2_xattr();
404 + error = init_ext2_xattr_user();
407 + error = register_filesystem(&ext2_fs_type);
411 + exit_ext2_xattr_user();
417 static void __exit exit_ext2_fs(void)
419 unregister_filesystem(&ext2_fs_type);
420 + exit_ext2_xattr_user();
425 --- linux/fs/ext2/symlink.c~linux-2.4.20-xattr-0.8.54-hp Wed Sep 27 13:41:33 2000
426 +++ linux-mmonroe/fs/ext2/symlink.c Fri May 16 08:43:01 2003
429 #include <linux/fs.h>
430 #include <linux/ext2_fs.h>
431 +#include <linux/ext2_xattr.h>
433 static int ext2_readlink(struct dentry *dentry, char *buffer, int buflen)
435 @@ -32,7 +33,20 @@ static int ext2_follow_link(struct dentr
436 return vfs_follow_link(nd, s);
439 +struct inode_operations ext2_symlink_inode_operations = {
440 + readlink: page_readlink,
441 + follow_link: page_follow_link,
442 + setxattr: ext2_setxattr,
443 + getxattr: ext2_getxattr,
444 + listxattr: ext2_listxattr,
445 + removexattr: ext2_removexattr,
448 struct inode_operations ext2_fast_symlink_inode_operations = {
449 readlink: ext2_readlink,
450 follow_link: ext2_follow_link,
451 + setxattr: ext2_setxattr,
452 + getxattr: ext2_getxattr,
453 + listxattr: ext2_listxattr,
454 + removexattr: ext2_removexattr,
456 --- /dev/null Mon May 20 21:11:23 2002
457 +++ linux-mmonroe/fs/ext2/xattr.c Fri May 16 08:43:01 2003
460 + * linux/fs/ext2/xattr.c
462 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
464 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
465 + * Extended attributes for symlinks and special files added per
466 + * suggestion of Luka Renko <luka.renko@hermes.si>.
470 + * Extended attributes are stored on disk blocks allocated outside of
471 + * any inode. The i_file_acl field is then made to point to this allocated
472 + * block. If all extended attributes of an inode are identical, these
473 + * inodes may share the same extended attribute block. Such situations
474 + * are automatically detected by keeping a cache of recent attribute block
475 + * numbers and hashes over the block's contents in memory.
478 + * Extended attribute block layout:
480 + * +------------------+
483 + * | entry 2 | | growing downwards
485 + * | four null bytes |
488 + * | value 3 | | growing upwards
490 + * +------------------+
492 + * The block header is followed by multiple entry descriptors. These entry
493 + * descriptors are variable in size, and alligned to EXT2_XATTR_PAD
494 + * byte boundaries. The entry descriptors are sorted by attribute name,
495 + * so that two extended attribute blocks can be compared efficiently.
497 + * Attribute values are aligned to the end of the block, stored in
498 + * no specific order. They are also padded to EXT2_XATTR_PAD byte
499 + * boundaries. No additional gaps are left between them.
503 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
504 + * the xattr inode operations are called, so we are guaranteed that only one
505 + * processes accesses extended attributes of an inode at any time.
507 + * For writing we also grab the ext2_xattr_sem semaphore. This ensures that
508 + * only a single process is modifying an extended attribute block, even
509 + * if the block is shared among inodes.
511 + * Note for porting to 2.5
512 + * -----------------------
513 + * The BKL will no longer be held in the xattr inode operations.
516 +#include <linux/module.h>
517 +#include <linux/locks.h>
518 +#include <linux/slab.h>
519 +#include <linux/fs.h>
520 +#include <linux/ext2_fs.h>
521 +#include <linux/ext2_xattr.h>
522 +#include <linux/mbcache.h>
523 +#include <linux/quotaops.h>
524 +#include <asm/semaphore.h>
525 +#include <linux/compatmac.h>
527 +/* These symbols may be needed by a module. */
528 +EXPORT_SYMBOL(ext2_xattr_register);
529 +EXPORT_SYMBOL(ext2_xattr_unregister);
530 +EXPORT_SYMBOL(ext2_xattr_get);
531 +EXPORT_SYMBOL(ext2_xattr_list);
532 +EXPORT_SYMBOL(ext2_xattr_set);
534 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
535 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
538 +#define HDR(bh) ((struct ext2_xattr_header *)((bh)->b_data))
539 +#define ENTRY(ptr) ((struct ext2_xattr_entry *)(ptr))
540 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
541 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
543 +#ifdef EXT2_XATTR_DEBUG
544 +# define ea_idebug(inode, f...) do { \
545 + printk(KERN_DEBUG "inode %s:%ld: ", \
546 + kdevname(inode->i_dev), inode->i_ino); \
550 +# define ea_bdebug(bh, f...) do { \
551 + printk(KERN_DEBUG "block %s:%ld: ", \
552 + kdevname(bh->b_dev), bh->b_blocknr); \
557 +# define ea_idebug(f...)
558 +# define ea_bdebug(f...)
561 +static int ext2_xattr_set2(struct inode *, struct buffer_head *,
562 + struct ext2_xattr_header *);
564 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
566 +static int ext2_xattr_cache_insert(struct buffer_head *);
567 +static struct buffer_head *ext2_xattr_cache_find(struct inode *,
568 + struct ext2_xattr_header *);
569 +static void ext2_xattr_cache_remove(struct buffer_head *);
570 +static void ext2_xattr_rehash(struct ext2_xattr_header *,
571 + struct ext2_xattr_entry *);
573 +static struct mb_cache *ext2_xattr_cache;
576 +# define ext2_xattr_cache_insert(bh) 0
577 +# define ext2_xattr_cache_find(inode, header) NULL
578 +# define ext2_xattr_cache_remove(bh) while(0) {}
579 +# define ext2_xattr_rehash(header, entry) while(0) {}
583 + * If a file system does not share extended attributes among inodes,
584 + * we should not need the ext2_xattr_sem semaphore. However, the
585 + * filesystem may still contain shared blocks, so we always take
589 +DECLARE_MUTEX(ext2_xattr_sem);
592 +ext2_xattr_new_block(struct inode *inode, int * errp, int force)
594 + struct super_block *sb = inode->i_sb;
595 + int goal = le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block) +
596 + EXT2_I(inode)->i_block_group * EXT2_BLOCKS_PER_GROUP(sb);
598 + /* How can we enforce the allocation? */
599 + int block = ext2_new_block(inode, goal, 0, 0, errp);
602 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
608 +ext2_xattr_quota_alloc(struct inode *inode, int force)
610 + /* How can we enforce the allocation? */
612 + int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
614 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
616 + int error = DQUOT_ALLOC_BLOCK(inode, 1);
624 +ext2_xattr_quota_free(struct inode *inode)
626 + DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
627 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
631 +ext2_xattr_free_block(struct inode * inode, unsigned long block)
633 + ext2_free_blocks(inode, block, 1);
634 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
638 +# define ext2_xattr_quota_free(inode) \
639 + DQUOT_FREE_BLOCK(inode, 1)
640 +# define ext2_xattr_free_block(inode, block) \
641 + ext2_free_blocks(inode, block, 1)
644 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
646 +static inline struct buffer_head *
647 +sb_bread(struct super_block *sb, int block)
649 + return bread(sb->s_dev, block, sb->s_blocksize);
652 +static inline struct buffer_head *
653 +sb_getblk(struct super_block *sb, int block)
655 + return getblk(sb->s_dev, block, sb->s_blocksize);
660 +struct ext2_xattr_handler *ext2_xattr_handlers[EXT2_XATTR_INDEX_MAX];
661 +rwlock_t ext2_handler_lock = RW_LOCK_UNLOCKED;
664 +ext2_xattr_register(int name_index, struct ext2_xattr_handler *handler)
666 + int error = -EINVAL;
668 + if (name_index > 0 && name_index <= EXT2_XATTR_INDEX_MAX) {
669 + write_lock(&ext2_handler_lock);
670 + if (!ext2_xattr_handlers[name_index-1]) {
671 + ext2_xattr_handlers[name_index-1] = handler;
674 + write_unlock(&ext2_handler_lock);
680 +ext2_xattr_unregister(int name_index, struct ext2_xattr_handler *handler)
682 + if (name_index > 0 || name_index <= EXT2_XATTR_INDEX_MAX) {
683 + write_lock(&ext2_handler_lock);
684 + ext2_xattr_handlers[name_index-1] = NULL;
685 + write_unlock(&ext2_handler_lock);
689 +static inline const char *
690 +strcmp_prefix(const char *a, const char *a_prefix)
692 + while (*a_prefix && *a == *a_prefix) {
696 + return *a_prefix ? NULL : a;
700 + * Decode the extended attribute name, and translate it into
701 + * the name_index and name suffix.
703 +static struct ext2_xattr_handler *
704 +ext2_xattr_resolve_name(const char **name)
706 + struct ext2_xattr_handler *handler = NULL;
711 + read_lock(&ext2_handler_lock);
712 + for (i=0; i<EXT2_XATTR_INDEX_MAX; i++) {
713 + if (ext2_xattr_handlers[i]) {
714 + const char *n = strcmp_prefix(*name,
715 + ext2_xattr_handlers[i]->prefix);
717 + handler = ext2_xattr_handlers[i];
723 + read_unlock(&ext2_handler_lock);
727 +static inline struct ext2_xattr_handler *
728 +ext2_xattr_handler(int name_index)
730 + struct ext2_xattr_handler *handler = NULL;
731 + if (name_index > 0 && name_index <= EXT2_XATTR_INDEX_MAX) {
732 + read_lock(&ext2_handler_lock);
733 + handler = ext2_xattr_handlers[name_index-1];
734 + read_unlock(&ext2_handler_lock);
740 + * Inode operation getxattr()
742 + * dentry->d_inode->i_sem down
743 + * BKL held [before 2.5.x]
746 +ext2_getxattr(struct dentry *dentry, const char *name,
747 + void *buffer, size_t size)
749 + struct ext2_xattr_handler *handler;
750 + struct inode *inode = dentry->d_inode;
752 + handler = ext2_xattr_resolve_name(&name);
755 + return handler->get(inode, name, buffer, size);
759 + * Inode operation listxattr()
761 + * dentry->d_inode->i_sem down
762 + * BKL held [before 2.5.x]
765 +ext2_listxattr(struct dentry *dentry, char *buffer, size_t size)
767 + return ext2_xattr_list(dentry->d_inode, buffer, size);
771 + * Inode operation setxattr()
773 + * dentry->d_inode->i_sem down
774 + * BKL held [before 2.5.x]
777 +ext2_setxattr(struct dentry *dentry, const char *name,
778 + const void *value, size_t size, int flags)
780 + struct ext2_xattr_handler *handler;
781 + struct inode *inode = dentry->d_inode;
784 + value = ""; /* empty EA, do not remove */
785 + handler = ext2_xattr_resolve_name(&name);
788 + return handler->set(inode, name, value, size, flags);
792 + * Inode operation removexattr()
794 + * dentry->d_inode->i_sem down
795 + * BKL held [before 2.5.x]
798 +ext2_removexattr(struct dentry *dentry, const char *name)
800 + struct ext2_xattr_handler *handler;
801 + struct inode *inode = dentry->d_inode;
803 + handler = ext2_xattr_resolve_name(&name);
806 + return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
812 + * Copy an extended attribute into the buffer
813 + * provided, or compute the buffer size required.
814 + * Buffer is NULL to compute the size of the buffer required.
816 + * Returns a negative error number on failure, or the number of bytes
817 + * used / required on success.
820 +ext2_xattr_get(struct inode *inode, int name_index, const char *name,
821 + void *buffer, size_t buffer_size)
823 + struct buffer_head *bh = NULL;
824 + struct ext2_xattr_entry *entry;
825 + unsigned int block, size;
827 + int name_len, error;
829 + ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
830 + name_index, name, buffer, (long)buffer_size);
834 + if (!EXT2_I(inode)->i_file_acl)
836 + block = EXT2_I(inode)->i_file_acl;
837 + ea_idebug(inode, "reading block %d", block);
838 + bh = sb_bread(inode->i_sb, block);
841 + ea_bdebug(bh, "b_count=%d, refcount=%d",
842 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
843 + end = bh->b_data + bh->b_size;
844 + if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
845 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
846 +bad_block: ext2_error(inode->i_sb, "ext2_xattr_get",
847 + "inode %ld: bad block %d", inode->i_ino, block);
851 + /* find named attribute */
852 + name_len = strlen(name);
855 + if (name_len > 255)
857 + entry = FIRST_ENTRY(bh);
858 + while (!IS_LAST_ENTRY(entry)) {
859 + struct ext2_xattr_entry *next =
860 + EXT2_XATTR_NEXT(entry);
861 + if ((char *)next >= end)
863 + if (name_index == entry->e_name_index &&
864 + name_len == entry->e_name_len &&
865 + memcmp(name, entry->e_name, name_len) == 0)
869 + /* Check the remaining name entries */
870 + while (!IS_LAST_ENTRY(entry)) {
871 + struct ext2_xattr_entry *next =
872 + EXT2_XATTR_NEXT(entry);
873 + if ((char *)next >= end)
877 + if (ext2_xattr_cache_insert(bh))
878 + ea_idebug(inode, "cache insert failed");
882 + /* check the buffer size */
883 + if (entry->e_value_block != 0)
885 + size = le32_to_cpu(entry->e_value_size);
886 + if (size > inode->i_sb->s_blocksize ||
887 + le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
890 + if (ext2_xattr_cache_insert(bh))
891 + ea_idebug(inode, "cache insert failed");
894 + if (size > buffer_size)
896 + /* return value of attribute */
897 + memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
909 + * ext2_xattr_list()
911 + * Copy a list of attribute names into the buffer
912 + * provided, or compute the buffer size required.
913 + * Buffer is NULL to compute the size of the buffer required.
915 + * Returns a negative error number on failure, or the number of bytes
916 + * used / required on success.
919 +ext2_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
921 + struct buffer_head *bh = NULL;
922 + struct ext2_xattr_entry *entry;
923 + unsigned int block, size = 0;
927 + ea_idebug(inode, "buffer=%p, buffer_size=%ld",
928 + buffer, (long)buffer_size);
930 + if (!EXT2_I(inode)->i_file_acl)
932 + block = EXT2_I(inode)->i_file_acl;
933 + ea_idebug(inode, "reading block %d", block);
934 + bh = sb_bread(inode->i_sb, block);
937 + ea_bdebug(bh, "b_count=%d, refcount=%d",
938 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
939 + end = bh->b_data + bh->b_size;
940 + if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
941 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
942 +bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
943 + "inode %ld: bad block %d", inode->i_ino, block);
947 + /* compute the size required for the list of attribute names */
948 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
949 + entry = EXT2_XATTR_NEXT(entry)) {
950 + struct ext2_xattr_handler *handler;
951 + struct ext2_xattr_entry *next =
952 + EXT2_XATTR_NEXT(entry);
953 + if ((char *)next >= end)
956 + handler = ext2_xattr_handler(entry->e_name_index);
958 + size += handler->list(NULL, inode, entry->e_name,
959 + entry->e_name_len);
962 + if (ext2_xattr_cache_insert(bh))
963 + ea_idebug(inode, "cache insert failed");
969 + if (size > buffer_size)
973 + /* list the attribute names */
975 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
976 + entry = EXT2_XATTR_NEXT(entry)) {
977 + struct ext2_xattr_handler *handler;
979 + handler = ext2_xattr_handler(entry->e_name_index);
981 + buf += handler->list(buf, inode, entry->e_name,
982 + entry->e_name_len);
993 + * If the EXT2_FEATURE_COMPAT_EXT_ATTR feature of this file system is
996 +static void ext2_xattr_update_super_block(struct super_block *sb)
998 + if (EXT2_HAS_COMPAT_FEATURE(sb, EXT2_FEATURE_COMPAT_EXT_ATTR))
1002 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
1003 + EXT2_SB(sb)->s_feature_compat |= EXT2_FEATURE_COMPAT_EXT_ATTR;
1005 + EXT2_SB(sb)->s_es->s_feature_compat |=
1006 + cpu_to_le32(EXT2_FEATURE_COMPAT_EXT_ATTR);
1008 + mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
1013 + * ext2_xattr_set()
1015 + * Create, replace or remove an extended attribute for this inode. Buffer
1016 + * is NULL to remove an existing extended attribute, and non-NULL to
1017 + * either replace an existing extended attribute, or create a new extended
1018 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
1019 + * specify that an extended attribute must exist and must not exist
1020 + * previous to the call, respectively.
1022 + * Returns 0, or a negative error number on failure.
1025 +ext2_xattr_set(struct inode *inode, int name_index, const char *name,
1026 + const void *value, size_t value_len, int flags)
1028 + struct super_block *sb = inode->i_sb;
1029 + struct buffer_head *bh = NULL;
1030 + struct ext2_xattr_header *header = NULL;
1031 + struct ext2_xattr_entry *here, *last;
1032 + unsigned int name_len;
1033 + int block = EXT2_I(inode)->i_file_acl;
1034 + int min_offs = sb->s_blocksize, not_found = 1, free, error;
1038 + * header -- Points either into bh, or to a temporarily
1039 + * allocated buffer.
1040 + * here -- The named entry found, or the place for inserting, within
1041 + * the block pointed to by header.
1042 + * last -- Points right after the last named entry within the block
1043 + * pointed to by header.
1044 + * min_offs -- The offset of the first value (values are aligned
1045 + * towards the end of the block).
1046 + * end -- Points right after the block pointed to by header.
1049 + ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
1050 + name_index, name, value, (long)value_len);
1052 + if (IS_RDONLY(inode))
1054 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1056 + if (value == NULL)
1060 + name_len = strlen(name);
1061 + if (name_len > 255 || value_len > sb->s_blocksize)
1063 + down(&ext2_xattr_sem);
1066 + /* The inode already has an extended attribute block. */
1068 + bh = sb_bread(sb, block);
1072 + ea_bdebug(bh, "b_count=%d, refcount=%d",
1073 + atomic_read(&(bh->b_count)),
1074 + le32_to_cpu(HDR(bh)->h_refcount));
1076 + end = bh->b_data + bh->b_size;
1077 + if (header->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1078 + header->h_blocks != cpu_to_le32(1)) {
1079 +bad_block: ext2_error(sb, "ext2_xattr_set",
1080 + "inode %ld: bad block %d", inode->i_ino, block);
1084 + /* Find the named attribute. */
1085 + here = FIRST_ENTRY(bh);
1086 + while (!IS_LAST_ENTRY(here)) {
1087 + struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(here);
1088 + if ((char *)next >= end)
1090 + if (!here->e_value_block && here->e_value_size) {
1091 + int offs = le16_to_cpu(here->e_value_offs);
1092 + if (offs < min_offs)
1095 + not_found = name_index - here->e_name_index;
1097 + not_found = name_len - here->e_name_len;
1099 + not_found = memcmp(name, here->e_name,name_len);
1100 + if (not_found <= 0)
1105 + /* We still need to compute min_offs and last. */
1106 + while (!IS_LAST_ENTRY(last)) {
1107 + struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(last);
1108 + if ((char *)next >= end)
1110 + if (!last->e_value_block && last->e_value_size) {
1111 + int offs = le16_to_cpu(last->e_value_offs);
1112 + if (offs < min_offs)
1118 + /* Check whether we have enough space left. */
1119 + free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
1121 + /* We will use a new extended attribute block. */
1122 + free = sb->s_blocksize -
1123 + sizeof(struct ext2_xattr_header) - sizeof(__u32);
1124 + here = last = NULL; /* avoid gcc uninitialized warning. */
1128 + /* Request to remove a nonexistent attribute? */
1130 + if (flags & XATTR_REPLACE)
1133 + if (value == NULL)
1136 + free -= EXT2_XATTR_LEN(name_len);
1138 + /* Request to create an existing attribute? */
1140 + if (flags & XATTR_CREATE)
1142 + if (!here->e_value_block && here->e_value_size) {
1143 + unsigned int size = le32_to_cpu(here->e_value_size);
1145 + if (le16_to_cpu(here->e_value_offs) + size >
1146 + sb->s_blocksize || size > sb->s_blocksize)
1148 + free += EXT2_XATTR_SIZE(size);
1151 + free -= EXT2_XATTR_SIZE(value_len);
1156 + /* Here we know that we can set the new attribute. */
1159 + if (header->h_refcount == cpu_to_le32(1)) {
1160 + ea_bdebug(bh, "modifying in-place");
1161 + ext2_xattr_cache_remove(bh);
1165 + ea_bdebug(bh, "cloning");
1166 + header = kmalloc(bh->b_size, GFP_KERNEL);
1168 + if (header == NULL)
1170 + memcpy(header, HDR(bh), bh->b_size);
1171 + header->h_refcount = cpu_to_le32(1);
1172 + offset = (char *)header - bh->b_data;
1173 + here = ENTRY((char *)here + offset);
1174 + last = ENTRY((char *)last + offset);
1177 + /* Allocate a buffer where we construct the new block. */
1178 + header = kmalloc(sb->s_blocksize, GFP_KERNEL);
1180 + if (header == NULL)
1182 + memset(header, 0, sb->s_blocksize);
1183 + end = (char *)header + sb->s_blocksize;
1184 + header->h_magic = cpu_to_le32(EXT2_XATTR_MAGIC);
1185 + header->h_blocks = header->h_refcount = cpu_to_le32(1);
1186 + last = here = ENTRY(header+1);
1190 + /* Insert the new name. */
1191 + int size = EXT2_XATTR_LEN(name_len);
1192 + int rest = (char *)last - (char *)here;
1193 + memmove((char *)here + size, here, rest);
1194 + memset(here, 0, size);
1195 + here->e_name_index = name_index;
1196 + here->e_name_len = name_len;
1197 + memcpy(here->e_name, name, name_len);
1199 + /* Remove the old value. */
1200 + if (!here->e_value_block && here->e_value_size) {
1201 + char *first_val = (char *)header + min_offs;
1202 + int offs = le16_to_cpu(here->e_value_offs);
1203 + char *val = (char *)header + offs;
1204 + size_t size = EXT2_XATTR_SIZE(
1205 + le32_to_cpu(here->e_value_size));
1206 + memmove(first_val + size, first_val, val - first_val);
1207 + memset(first_val, 0, size);
1208 + here->e_value_offs = 0;
1211 + /* Adjust all value offsets. */
1212 + last = ENTRY(header+1);
1213 + while (!IS_LAST_ENTRY(last)) {
1214 + int o = le16_to_cpu(last->e_value_offs);
1215 + if (!last->e_value_block && o < offs)
1216 + last->e_value_offs =
1217 + cpu_to_le16(o + size);
1218 + last = EXT2_XATTR_NEXT(last);
1221 + if (value == NULL) {
1222 + /* Remove this attribute. */
1223 + if (EXT2_XATTR_NEXT(ENTRY(header+1)) == last) {
1224 + /* This block is now empty. */
1225 + error = ext2_xattr_set2(inode, bh, NULL);
1228 + /* Remove the old name. */
1229 + int size = EXT2_XATTR_LEN(name_len);
1230 + last = ENTRY((char *)last - size);
1231 + memmove(here, (char*)here + size,
1232 + (char*)last - (char*)here);
1233 + memset(last, 0, size);
1238 + if (value != NULL) {
1239 + /* Insert the new value. */
1240 + here->e_value_size = cpu_to_le32(value_len);
1242 + size_t size = EXT2_XATTR_SIZE(value_len);
1243 + char *val = (char *)header + min_offs - size;
1244 + here->e_value_offs =
1245 + cpu_to_le16((char *)val - (char *)header);
1246 + memset(val + size - EXT2_XATTR_PAD, 0,
1247 + EXT2_XATTR_PAD); /* Clear the pad bytes. */
1248 + memcpy(val, value, value_len);
1251 + ext2_xattr_rehash(header, here);
1253 + error = ext2_xattr_set2(inode, bh, header);
1257 + if (!(bh && header == HDR(bh)))
1259 + up(&ext2_xattr_sem);
1265 + * Second half of ext2_xattr_set(): Update the file system.
1268 +ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
1269 + struct ext2_xattr_header *header)
1271 + struct super_block *sb = inode->i_sb;
1272 + struct buffer_head *new_bh = NULL;
1276 + new_bh = ext2_xattr_cache_find(inode, header);
1279 + * We found an identical block in the cache.
1280 + * The old block will be released after updating
1283 + ea_bdebug(old_bh, "reusing block %ld",
1284 + new_bh->b_blocknr);
1287 + if (ext2_xattr_quota_alloc(inode, 1))
1290 + HDR(new_bh)->h_refcount = cpu_to_le32(
1291 + le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
1292 + ea_bdebug(new_bh, "refcount now=%d",
1293 + le32_to_cpu(HDR(new_bh)->h_refcount));
1294 + } else if (old_bh && header == HDR(old_bh)) {
1295 + /* Keep this block. */
1297 + (void)ext2_xattr_cache_insert(new_bh);
1299 + /* We need to allocate a new block */
1300 + int force = EXT2_I(inode)->i_file_acl != 0;
1301 + int block = ext2_xattr_new_block(inode, &error, force);
1304 + ea_idebug(inode, "creating block %d", block);
1306 + new_bh = sb_getblk(sb, block);
1308 + ext2_xattr_free_block(inode, block);
1312 + lock_buffer(new_bh);
1313 + memcpy(new_bh->b_data, header, new_bh->b_size);
1314 + mark_buffer_uptodate(new_bh, 1);
1315 + unlock_buffer(new_bh);
1316 + (void)ext2_xattr_cache_insert(new_bh);
1318 + ext2_xattr_update_super_block(sb);
1320 + mark_buffer_dirty(new_bh);
1321 + if (IS_SYNC(inode)) {
1322 + ll_rw_block(WRITE, 1, &new_bh);
1323 + wait_on_buffer(new_bh);
1325 + if (buffer_req(new_bh) && !buffer_uptodate(new_bh))
1330 + /* Update the inode. */
1331 + EXT2_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
1332 + inode->i_ctime = CURRENT_TIME;
1333 + if (IS_SYNC(inode)) {
1334 + error = ext2_sync_inode (inode);
1338 + mark_inode_dirty(inode);
1341 + if (old_bh && old_bh != new_bh) {
1343 + * If there was an old block, and we are not still using it,
1344 + * we now release the old block.
1346 + unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
1348 + if (refcount == 1) {
1349 + /* Free the old block. */
1350 + ea_bdebug(old_bh, "freeing");
1351 + ext2_xattr_free_block(inode, old_bh->b_blocknr);
1352 + mark_buffer_clean(old_bh);
1354 + /* Decrement the refcount only. */
1356 + HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
1357 + ext2_xattr_quota_free(inode);
1358 + mark_buffer_dirty(old_bh);
1359 + ea_bdebug(old_bh, "refcount now=%d", refcount);
1364 + if (old_bh != new_bh)
1371 + * ext2_xattr_delete_inode()
1373 + * Free extended attribute resources associated with this inode. This
1374 + * is called immediately before an inode is freed.
1377 +ext2_xattr_delete_inode(struct inode *inode)
1379 + struct buffer_head *bh;
1380 + unsigned int block = EXT2_I(inode)->i_file_acl;
1384 + down(&ext2_xattr_sem);
1386 + bh = sb_bread(inode->i_sb, block);
1388 + ext2_error(inode->i_sb, "ext2_xattr_delete_inode",
1389 + "inode %ld: block %d read error", inode->i_ino, block);
1392 + ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
1393 + if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
1394 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1395 + ext2_error(inode->i_sb, "ext2_xattr_delete_inode",
1396 + "inode %ld: bad block %d", inode->i_ino, block);
1399 + ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
1400 + if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
1401 + ext2_xattr_cache_remove(bh);
1402 + ext2_xattr_free_block(inode, block);
1406 + HDR(bh)->h_refcount = cpu_to_le32(
1407 + le32_to_cpu(HDR(bh)->h_refcount) - 1);
1408 + mark_buffer_dirty(bh);
1409 + if (IS_SYNC(inode)) {
1410 + ll_rw_block(WRITE, 1, &bh);
1411 + wait_on_buffer(bh);
1413 + ext2_xattr_quota_free(inode);
1415 + EXT2_I(inode)->i_file_acl = 0;
1419 + up(&ext2_xattr_sem);
1423 + * ext2_xattr_put_super()
1425 + * This is called when a file system is unmounted.
1428 +ext2_xattr_put_super(struct super_block *sb)
1430 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
1431 + mb_cache_shrink(ext2_xattr_cache, sb->s_dev);
1435 +#ifdef CONFIG_EXT2_FS_XATTR_SHARING
1438 + * ext2_xattr_cache_insert()
1440 + * Create a new entry in the extended attribute cache, and insert
1441 + * it unless such an entry is already in the cache.
1443 + * Returns 0, or a negative error number on failure.
1446 +ext2_xattr_cache_insert(struct buffer_head *bh)
1448 + __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
1449 + struct mb_cache_entry *ce;
1452 + ce = mb_cache_entry_alloc(ext2_xattr_cache);
1455 + error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
1457 + mb_cache_entry_free(ce);
1458 + if (error == -EBUSY) {
1459 + ea_bdebug(bh, "already in cache (%d cache entries)",
1460 + atomic_read(&ext2_xattr_cache->c_entry_count));
1464 + ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
1465 + atomic_read(&ext2_xattr_cache->c_entry_count));
1466 + mb_cache_entry_release(ce);
1472 + * ext2_xattr_cmp()
1474 + * Compare two extended attribute blocks for equality.
1476 + * Returns 0 if the blocks are equal, 1 if they differ, and
1477 + * a negative error number on errors.
1480 +ext2_xattr_cmp(struct ext2_xattr_header *header1,
1481 + struct ext2_xattr_header *header2)
1483 + struct ext2_xattr_entry *entry1, *entry2;
1485 + entry1 = ENTRY(header1+1);
1486 + entry2 = ENTRY(header2+1);
1487 + while (!IS_LAST_ENTRY(entry1)) {
1488 + if (IS_LAST_ENTRY(entry2))
1490 + if (entry1->e_hash != entry2->e_hash ||
1491 + entry1->e_name_len != entry2->e_name_len ||
1492 + entry1->e_value_size != entry2->e_value_size ||
1493 + memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
1495 + if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
1497 + if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
1498 + (char *)header2 + le16_to_cpu(entry2->e_value_offs),
1499 + le32_to_cpu(entry1->e_value_size)))
1502 + entry1 = EXT2_XATTR_NEXT(entry1);
1503 + entry2 = EXT2_XATTR_NEXT(entry2);
1505 + if (!IS_LAST_ENTRY(entry2))
1511 + * ext2_xattr_cache_find()
1513 + * Find an identical extended attribute block.
1515 + * Returns a pointer to the block found, or NULL if such a block was
1516 + * not found or an error occurred.
1518 +static struct buffer_head *
1519 +ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header)
1521 + __u32 hash = le32_to_cpu(header->h_hash);
1522 + struct mb_cache_entry *ce;
1524 + if (!header->h_hash)
1525 + return NULL; /* never share */
1526 + ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
1527 + ce = mb_cache_entry_find_first(ext2_xattr_cache, 0, inode->i_dev, hash);
1529 + struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
1532 + ext2_error(inode->i_sb, "ext2_xattr_cache_find",
1533 + "inode %ld: block %ld read error",
1534 + inode->i_ino, ce->e_block);
1535 + } else if (le32_to_cpu(HDR(bh)->h_refcount) >
1536 + EXT2_XATTR_REFCOUNT_MAX) {
1537 + ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
1538 + le32_to_cpu(HDR(bh)->h_refcount),
1539 + EXT2_XATTR_REFCOUNT_MAX);
1540 + } else if (!ext2_xattr_cmp(header, HDR(bh))) {
1541 + ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
1542 + mb_cache_entry_release(ce);
1546 + ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
1552 + * ext2_xattr_cache_remove()
1554 + * Remove the cache entry of a block from the cache. Called when a
1555 + * block becomes invalid.
1558 +ext2_xattr_cache_remove(struct buffer_head *bh)
1560 + struct mb_cache_entry *ce;
1562 + ce = mb_cache_entry_get(ext2_xattr_cache, bh->b_dev, bh->b_blocknr);
1564 + ea_bdebug(bh, "removing (%d cache entries remaining)",
1565 + atomic_read(&ext2_xattr_cache->c_entry_count)-1);
1566 + mb_cache_entry_free(ce);
1568 + ea_bdebug(bh, "no cache entry");
1571 +#define NAME_HASH_SHIFT 5
1572 +#define VALUE_HASH_SHIFT 16
1575 + * ext2_xattr_hash_entry()
1577 + * Compute the hash of an extended attribute.
1579 +static inline void ext2_xattr_hash_entry(struct ext2_xattr_header *header,
1580 + struct ext2_xattr_entry *entry)
1583 + char *name = entry->e_name;
1586 + for (n=0; n < entry->e_name_len; n++) {
1587 + hash = (hash << NAME_HASH_SHIFT) ^
1588 + (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
1592 + if (entry->e_value_block == 0 && entry->e_value_size != 0) {
1593 + __u32 *value = (__u32 *)((char *)header +
1594 + le16_to_cpu(entry->e_value_offs));
1595 + for (n = (le32_to_cpu(entry->e_value_size) +
1596 + EXT2_XATTR_ROUND) >> EXT2_XATTR_PAD_BITS; n; n--) {
1597 + hash = (hash << VALUE_HASH_SHIFT) ^
1598 + (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
1599 + le32_to_cpu(*value++);
1602 + entry->e_hash = cpu_to_le32(hash);
1605 +#undef NAME_HASH_SHIFT
1606 +#undef VALUE_HASH_SHIFT
1608 +#define BLOCK_HASH_SHIFT 16
1611 + * ext2_xattr_rehash()
1613 + * Re-compute the extended attribute hash value after an entry has changed.
1615 +static void ext2_xattr_rehash(struct ext2_xattr_header *header,
1616 + struct ext2_xattr_entry *entry)
1618 + struct ext2_xattr_entry *here;
1621 + ext2_xattr_hash_entry(header, entry);
1622 + here = ENTRY(header+1);
1623 + while (!IS_LAST_ENTRY(here)) {
1624 + if (!here->e_hash) {
1625 + /* Block is not shared if an entry's hash value == 0 */
1629 + hash = (hash << BLOCK_HASH_SHIFT) ^
1630 + (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
1631 + le32_to_cpu(here->e_hash);
1632 + here = EXT2_XATTR_NEXT(here);
1634 + header->h_hash = cpu_to_le32(hash);
1637 +#undef BLOCK_HASH_SHIFT
1640 +init_ext2_xattr(void)
1642 + ext2_xattr_cache = mb_cache_create("ext2_xattr", NULL,
1643 + sizeof(struct mb_cache_entry) +
1644 + sizeof(struct mb_cache_entry_index), 1, 61);
1645 + if (!ext2_xattr_cache)
1652 +exit_ext2_xattr(void)
1654 + mb_cache_destroy(ext2_xattr_cache);
1657 +#else /* CONFIG_EXT2_FS_XATTR_SHARING */
1660 +init_ext2_xattr(void)
1666 +exit_ext2_xattr(void)
1670 +#endif /* CONFIG_EXT2_FS_XATTR_SHARING */
1671 --- /dev/null Mon May 20 21:11:23 2002
1672 +++ linux-mmonroe/fs/ext2/xattr_user.c Fri May 16 08:43:01 2003
1675 + * linux/fs/ext2/xattr_user.c
1676 + * Handler for extended user attributes.
1678 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
1681 +#include <linux/module.h>
1682 +#include <linux/string.h>
1683 +#include <linux/fs.h>
1684 +#include <linux/ext2_fs.h>
1685 +#include <linux/ext2_xattr.h>
1687 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
1688 +# include <linux/ext2_acl.h>
1691 +#define XATTR_USER_PREFIX "user."
1694 +ext2_xattr_user_list(char *list, struct inode *inode,
1695 + const char *name, int name_len)
1697 + const int prefix_len = sizeof(XATTR_USER_PREFIX)-1;
1699 + if (!test_opt(inode->i_sb, XATTR_USER))
1703 + memcpy(list, XATTR_USER_PREFIX, prefix_len);
1704 + memcpy(list+prefix_len, name, name_len);
1705 + list[prefix_len + name_len] = '\0';
1707 + return prefix_len + name_len + 1;
1711 +ext2_xattr_user_get(struct inode *inode, const char *name,
1712 + void *buffer, size_t size)
1716 + if (strcmp(name, "") == 0)
1718 + if (!test_opt(inode->i_sb, XATTR_USER))
1720 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
1721 + error = ext2_permission_locked(inode, MAY_READ);
1723 + error = permission(inode, MAY_READ);
1728 + return ext2_xattr_get(inode, EXT2_XATTR_INDEX_USER, name,
1733 +ext2_xattr_user_set(struct inode *inode, const char *name,
1734 + const void *value, size_t size, int flags)
1738 + if (strcmp(name, "") == 0)
1740 + if (!test_opt(inode->i_sb, XATTR_USER))
1742 + if ( !S_ISREG(inode->i_mode) &&
1743 + (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
1745 +#ifdef CONFIG_EXT2_FS_POSIX_ACL
1746 + error = ext2_permission_locked(inode, MAY_WRITE);
1748 + error = permission(inode, MAY_WRITE);
1753 + return ext2_xattr_set(inode, EXT2_XATTR_INDEX_USER, name,
1754 + value, size, flags);
1757 +struct ext2_xattr_handler ext2_xattr_user_handler = {
1758 + prefix: XATTR_USER_PREFIX,
1759 + list: ext2_xattr_user_list,
1760 + get: ext2_xattr_user_get,
1761 + set: ext2_xattr_user_set,
1765 +init_ext2_xattr_user(void)
1767 + return ext2_xattr_register(EXT2_XATTR_INDEX_USER,
1768 + &ext2_xattr_user_handler);
1772 +exit_ext2_xattr_user(void)
1774 + ext2_xattr_unregister(EXT2_XATTR_INDEX_USER,
1775 + &ext2_xattr_user_handler);
1777 --- linux/fs/ext3/Makefile~linux-2.4.20-xattr-0.8.54-hp Fri May 16 08:42:46 2003
1778 +++ linux-mmonroe/fs/ext3/Makefile Fri May 16 08:43:01 2003
1781 -# Makefile for the linux ext2-filesystem routines.
1782 +# Makefile for the linux ext3-filesystem routines.
1784 # Note! Dependencies are done automagically by 'make dep', which also
1785 # removes any old dependencies. DON'T put your own dependencies here
1790 -export-objs := super.o inode.o
1791 +export-objs := ext3-exports.o
1793 obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
1794 - ioctl.o namei.o super.o symlink.o hash.o
1795 + ioctl.o namei.o super.o symlink.o hash.o ext3-exports.o
1796 obj-m := $(O_TARGET)
1798 +obj-$(CONFIG_EXT3_FS_XATTR) += xattr.o
1799 +obj-$(CONFIG_EXT3_FS_XATTR_USER) += xattr_user.o
1801 include $(TOPDIR)/Rules.make
1802 --- linux/fs/ext3/file.c~linux-2.4.20-xattr-0.8.54-hp Fri May 16 08:42:46 2003
1803 +++ linux-mmonroe/fs/ext3/file.c Fri May 16 08:43:01 2003
1805 #include <linux/locks.h>
1806 #include <linux/jbd.h>
1807 #include <linux/ext3_fs.h>
1808 +#include <linux/ext3_xattr.h>
1809 #include <linux/ext3_jbd.h>
1810 #include <linux/smp_lock.h>
1812 @@ -126,5 +127,9 @@ struct file_operations ext3_file_operati
1813 struct inode_operations ext3_file_inode_operations = {
1814 truncate: ext3_truncate, /* BKL held */
1815 setattr: ext3_setattr, /* BKL held */
1816 + setxattr: ext3_setxattr, /* BKL held */
1817 + getxattr: ext3_getxattr, /* BKL held */
1818 + listxattr: ext3_listxattr, /* BKL held */
1819 + removexattr: ext3_removexattr, /* BKL held */
1822 --- linux/fs/ext3/ialloc.c~linux-2.4.20-xattr-0.8.54-hp Thu Nov 28 15:53:15 2002
1823 +++ linux-mmonroe/fs/ext3/ialloc.c Fri May 16 08:43:01 2003
1825 #include <linux/jbd.h>
1826 #include <linux/ext3_fs.h>
1827 #include <linux/ext3_jbd.h>
1828 +#include <linux/ext3_xattr.h>
1829 #include <linux/stat.h>
1830 #include <linux/string.h>
1831 #include <linux/locks.h>
1832 @@ -216,6 +217,7 @@ void ext3_free_inode (handle_t *handle,
1833 * as writing the quota to disk may need the lock as well.
1836 + ext3_xattr_delete_inode(handle, inode);
1837 DQUOT_FREE_INODE(inode);
1840 --- linux/fs/ext3/inode.c~linux-2.4.20-xattr-0.8.54-hp Thu Nov 28 15:53:15 2002
1841 +++ linux-mmonroe/fs/ext3/inode.c Fri May 16 08:43:01 2003
1844 #undef SEARCH_FROM_ZERO
1847 + * Test whether an inode is a fast symlink.
1849 +static inline int ext3_inode_is_fast_symlink(struct inode *inode)
1851 + int ea_blocks = inode->u.ext3_i.i_file_acl ?
1852 + (inode->i_sb->s_blocksize >> 9) : 0;
1854 + return (S_ISLNK(inode->i_mode) &&
1855 + inode->i_blocks - ea_blocks == 0);
1858 /* The ext3 forget function must perform a revoke if we are freeing data
1859 * which has been journaled. Metadata (eg. indirect blocks) must be
1860 * revoked in all cases.
1862 * still needs to be revoked.
1865 -static int ext3_forget(handle_t *handle, int is_metadata,
1866 +int ext3_forget(handle_t *handle, int is_metadata,
1867 struct inode *inode, struct buffer_head *bh,
1870 @@ -164,9 +176,7 @@ void ext3_delete_inode (struct inode * i
1874 - if (is_bad_inode(inode) ||
1875 - inode->i_ino == EXT3_ACL_IDX_INO ||
1876 - inode->i_ino == EXT3_ACL_DATA_INO)
1877 + if (is_bad_inode(inode))
1881 @@ -1855,6 +1865,8 @@ void ext3_truncate(struct inode * inode)
1882 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1883 S_ISLNK(inode->i_mode)))
1885 + if (ext3_inode_is_fast_symlink(inode))
1887 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
1890 @@ -2002,8 +2014,6 @@ int ext3_get_inode_loc (struct inode *in
1891 struct ext3_group_desc * gdp;
1893 if ((inode->i_ino != EXT3_ROOT_INO &&
1894 - inode->i_ino != EXT3_ACL_IDX_INO &&
1895 - inode->i_ino != EXT3_ACL_DATA_INO &&
1896 inode->i_ino != EXT3_JOURNAL_INO &&
1897 inode->i_ino < EXT3_FIRST_INO(inode->i_sb)) ||
1898 inode->i_ino > le32_to_cpu(
1899 @@ -2130,10 +2140,7 @@ void ext3_read_inode(struct inode * inod
1903 - if (inode->i_ino == EXT3_ACL_IDX_INO ||
1904 - inode->i_ino == EXT3_ACL_DATA_INO)
1905 - /* Nothing to do */ ;
1906 - else if (S_ISREG(inode->i_mode)) {
1907 + if (S_ISREG(inode->i_mode)) {
1908 inode->i_op = &ext3_file_inode_operations;
1909 inode->i_fop = &ext3_file_operations;
1910 inode->i_mapping->a_ops = &ext3_aops;
1911 @@ -2141,15 +2148,17 @@ void ext3_read_inode(struct inode * inod
1912 inode->i_op = &ext3_dir_inode_operations;
1913 inode->i_fop = &ext3_dir_operations;
1914 } else if (S_ISLNK(inode->i_mode)) {
1915 - if (!inode->i_blocks)
1916 + if (ext3_inode_is_fast_symlink(inode))
1917 inode->i_op = &ext3_fast_symlink_inode_operations;
1919 - inode->i_op = &page_symlink_inode_operations;
1920 + inode->i_op = &ext3_symlink_inode_operations;
1921 inode->i_mapping->a_ops = &ext3_aops;
1925 + inode->i_op = &ext3_special_inode_operations;
1926 init_special_inode(inode, inode->i_mode,
1927 le32_to_cpu(iloc.raw_inode->i_block[0]));
1929 /* inode->i_attr_flags = 0; unused */
1930 if (inode->u.ext3_i.i_flags & EXT3_SYNC_FL) {
1931 /* inode->i_attr_flags |= ATTR_FLAG_SYNCRONOUS; unused */
1932 --- linux/fs/ext3/namei.c~linux-2.4.20-xattr-0.8.54-hp Fri May 16 08:42:47 2003
1933 +++ linux-mmonroe/fs/ext3/namei.c Fri May 16 08:43:01 2003
1935 #include <linux/sched.h>
1936 #include <linux/ext3_fs.h>
1937 #include <linux/ext3_jbd.h>
1938 +#include <linux/ext3_xattr.h>
1939 #include <linux/fcntl.h>
1940 #include <linux/stat.h>
1941 #include <linux/string.h>
1942 @@ -1611,7 +1612,7 @@ static int ext3_mkdir(struct inode * dir
1946 - inode = ext3_new_inode (handle, dir, S_IFDIR);
1947 + inode = ext3_new_inode (handle, dir, S_IFDIR | mode);
1948 err = PTR_ERR(inode);
1951 @@ -1619,7 +1620,6 @@ static int ext3_mkdir(struct inode * dir
1952 inode->i_op = &ext3_dir_inode_operations;
1953 inode->i_fop = &ext3_dir_operations;
1954 inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
1955 - inode->i_blocks = 0;
1956 dir_block = ext3_bread (handle, inode, 0, 1, &err);
1958 inode->i_nlink--; /* is this nlink == 0? */
1959 @@ -1646,9 +1646,6 @@ static int ext3_mkdir(struct inode * dir
1960 BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata");
1961 ext3_journal_dirty_metadata(handle, dir_block);
1963 - inode->i_mode = S_IFDIR | mode;
1964 - if (dir->i_mode & S_ISGID)
1965 - inode->i_mode |= S_ISGID;
1966 ext3_mark_inode_dirty(handle, inode);
1967 err = ext3_add_entry (handle, dentry, inode);
1969 @@ -2017,7 +2014,7 @@ static int ext3_symlink (struct inode *
1972 if (l > sizeof (EXT3_I(inode)->i_data)) {
1973 - inode->i_op = &page_symlink_inode_operations;
1974 + inode->i_op = &ext3_symlink_inode_operations;
1975 inode->i_mapping->a_ops = &ext3_aops;
1977 * block_symlink() calls back into ext3_prepare/commit_write.
1978 @@ -2244,4 +2241,16 @@ struct inode_operations ext3_dir_inode_o
1979 rmdir: ext3_rmdir, /* BKL held */
1980 mknod: ext3_mknod, /* BKL held */
1981 rename: ext3_rename, /* BKL held */
1982 + setxattr: ext3_setxattr, /* BKL held */
1983 + getxattr: ext3_getxattr, /* BKL held */
1984 + listxattr: ext3_listxattr, /* BKL held */
1985 + removexattr: ext3_removexattr, /* BKL held */
1988 +struct inode_operations ext3_special_inode_operations = {
1989 + setxattr: ext3_setxattr, /* BKL held */
1990 + getxattr: ext3_getxattr, /* BKL held */
1991 + listxattr: ext3_listxattr, /* BKL held */
1992 + removexattr: ext3_removexattr, /* BKL held */
1995 --- linux/fs/ext3/super.c~linux-2.4.20-xattr-0.8.54-hp Fri May 16 08:42:46 2003
1996 +++ linux-mmonroe/fs/ext3/super.c Fri May 16 08:43:01 2003
1998 #include <linux/jbd.h>
1999 #include <linux/ext3_fs.h>
2000 #include <linux/ext3_jbd.h>
2001 +#include <linux/ext3_xattr.h>
2002 #include <linux/slab.h>
2003 #include <linux/init.h>
2004 #include <linux/locks.h>
2005 @@ -406,6 +407,7 @@ void ext3_put_super (struct super_block
2006 kdev_t j_dev = sbi->s_journal->j_dev;
2009 + ext3_xattr_put_super(sb);
2010 journal_destroy(sbi->s_journal);
2011 if (!(sb->s_flags & MS_RDONLY)) {
2012 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
2013 @@ -502,6 +504,7 @@ static int parse_options (char * options
2016 unsigned long *mount_options = &sbi->s_mount_opt;
2018 uid_t *resuid = &sbi->s_resuid;
2019 gid_t *resgid = &sbi->s_resgid;
2021 @@ -514,6 +517,13 @@ static int parse_options (char * options
2022 this_char = strtok (NULL, ",")) {
2023 if ((value = strchr (this_char, '=')) != NULL)
2025 +#ifdef CONFIG_EXT3_FS_XATTR_USER
2026 + if (!strcmp (this_char, "user_xattr"))
2027 + set_opt (*mount_options, XATTR_USER);
2028 + else if (!strcmp (this_char, "nouser_xattr"))
2029 + clear_opt (*mount_options, XATTR_USER);
2032 if (!strcmp (this_char, "bsddf"))
2033 clear_opt (*mount_options, MINIX_DF);
2034 else if (!strcmp (this_char, "nouid32")) {
2035 @@ -931,6 +941,12 @@ struct super_block * ext3_read_super (st
2036 sbi->s_mount_opt = 0;
2037 sbi->s_resuid = EXT3_DEF_RESUID;
2038 sbi->s_resgid = EXT3_DEF_RESGID;
2040 + /* Default extended attribute flags */
2041 +#ifdef CONFIG_EXT3_FS_XATTR_USER
2042 + /* set_opt(sbi->s_mount_opt, XATTR_USER); */
2045 if (!parse_options ((char *) data, &sb_block, sbi, &journal_inum, 0)) {
2048 @@ -1768,17 +1784,29 @@ static DECLARE_FSTYPE_DEV(ext3_fs_type,
2050 static int __init init_ext3_fs(void)
2052 - return register_filesystem(&ext3_fs_type);
2053 + int error = init_ext3_xattr();
2056 + error = init_ext3_xattr_user();
2059 + error = register_filesystem(&ext3_fs_type);
2063 + exit_ext3_xattr_user();
2065 + exit_ext3_xattr();
2069 static void __exit exit_ext3_fs(void)
2071 unregister_filesystem(&ext3_fs_type);
2072 + exit_ext3_xattr_user();
2073 + exit_ext3_xattr();
2076 -EXPORT_SYMBOL(ext3_force_commit);
2077 -EXPORT_SYMBOL(ext3_bread);
2079 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
2080 MODULE_DESCRIPTION("Second Extended Filesystem with journaling extensions");
2081 MODULE_LICENSE("GPL");
2082 --- linux/fs/ext3/symlink.c~linux-2.4.20-xattr-0.8.54-hp Fri Nov 9 14:25:04 2001
2083 +++ linux-mmonroe/fs/ext3/symlink.c Fri May 16 08:43:01 2003
2085 #include <linux/fs.h>
2086 #include <linux/jbd.h>
2087 #include <linux/ext3_fs.h>
2088 +#include <linux/ext3_xattr.h>
2090 static int ext3_readlink(struct dentry *dentry, char *buffer, int buflen)
2092 @@ -33,7 +34,20 @@ static int ext3_follow_link(struct dentr
2093 return vfs_follow_link(nd, s);
2096 +struct inode_operations ext3_symlink_inode_operations = {
2097 + readlink: page_readlink, /* BKL not held. Don't need */
2098 + follow_link: page_follow_link, /* BKL not held. Don't need */
2099 + setxattr: ext3_setxattr, /* BKL held */
2100 + getxattr: ext3_getxattr, /* BKL held */
2101 + listxattr: ext3_listxattr, /* BKL held */
2102 + removexattr: ext3_removexattr, /* BKL held */
2105 struct inode_operations ext3_fast_symlink_inode_operations = {
2106 readlink: ext3_readlink, /* BKL not held. Don't need */
2107 follow_link: ext3_follow_link, /* BKL not held. Don't need */
2108 + setxattr: ext3_setxattr, /* BKL held */
2109 + getxattr: ext3_getxattr, /* BKL held */
2110 + listxattr: ext3_listxattr, /* BKL held */
2111 + removexattr: ext3_removexattr, /* BKL held */
2113 --- /dev/null Mon May 20 21:11:23 2002
2114 +++ linux-mmonroe/fs/ext3/xattr.c Fri May 16 08:43:01 2003
2117 + * linux/fs/ext3/xattr.c
2119 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
2121 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
2122 + * Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>.
2123 + * Extended attributes for symlinks and special files added per
2124 + * suggestion of Luka Renko <luka.renko@hermes.si>.
2128 + * Extended attributes are stored on disk blocks allocated outside of
2129 + * any inode. The i_file_acl field is then made to point to this allocated
2130 + * block. If all extended attributes of an inode are identical, these
2131 + * inodes may share the same extended attribute block. Such situations
2132 + * are automatically detected by keeping a cache of recent attribute block
2133 + * numbers and hashes over the block's contents in memory.
2136 + * Extended attribute block layout:
2138 + * +------------------+
2141 + * | entry 2 | | growing downwards
2143 + * | four null bytes |
2146 + * | value 3 | | growing upwards
2148 + * +------------------+
2150 + * The block header is followed by multiple entry descriptors. These entry
2151 + * descriptors are variable in size, and alligned to EXT3_XATTR_PAD
2152 + * byte boundaries. The entry descriptors are sorted by attribute name,
2153 + * so that two extended attribute blocks can be compared efficiently.
2155 + * Attribute values are aligned to the end of the block, stored in
2156 + * no specific order. They are also padded to EXT3_XATTR_PAD byte
2157 + * boundaries. No additional gaps are left between them.
2159 + * Locking strategy
2160 + * ----------------
2161 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
2162 + * the xattr inode operations are called, so we are guaranteed that only one
2163 + * processes accesses extended attributes of an inode at any time.
2165 + * For writing we also grab the ext3_xattr_sem semaphore. This ensures that
2166 + * only a single process is modifying an extended attribute block, even
2167 + * if the block is shared among inodes.
2169 + * Note for porting to 2.5
2170 + * -----------------------
2171 + * The BKL will no longer be held in the xattr inode operations.
2174 +#include <linux/module.h>
2175 +#include <linux/fs.h>
2176 +#include <linux/locks.h>
2177 +#include <linux/slab.h>
2178 +#include <linux/ext3_jbd.h>
2179 +#include <linux/ext3_fs.h>
2180 +#include <linux/ext3_xattr.h>
2181 +#include <linux/mbcache.h>
2182 +#include <linux/quotaops.h>
2183 +#include <asm/semaphore.h>
2184 +#include <linux/compatmac.h>
2186 +#define EXT3_EA_USER "user."
2188 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
2189 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
2192 +#define HDR(bh) ((struct ext3_xattr_header *)((bh)->b_data))
2193 +#define ENTRY(ptr) ((struct ext3_xattr_entry *)(ptr))
2194 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
2195 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
2197 +#ifdef EXT3_XATTR_DEBUG
2198 +# define ea_idebug(inode, f...) do { \
2199 + printk(KERN_DEBUG "inode %s:%ld: ", \
2200 + kdevname(inode->i_dev), inode->i_ino); \
2204 +# define ea_bdebug(bh, f...) do { \
2205 + printk(KERN_DEBUG "block %s:%ld: ", \
2206 + kdevname(bh->b_dev), bh->b_blocknr); \
2211 +# define ea_idebug(f...)
2212 +# define ea_bdebug(f...)
2215 +static int ext3_xattr_set2(handle_t *, struct inode *, struct buffer_head *,
2216 + struct ext3_xattr_header *);
2218 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
2220 +static int ext3_xattr_cache_insert(struct buffer_head *);
2221 +static struct buffer_head *ext3_xattr_cache_find(struct inode *,
2222 + struct ext3_xattr_header *);
2223 +static void ext3_xattr_cache_remove(struct buffer_head *);
2224 +static void ext3_xattr_rehash(struct ext3_xattr_header *,
2225 + struct ext3_xattr_entry *);
2227 +static struct mb_cache *ext3_xattr_cache;
2230 +# define ext3_xattr_cache_insert(bh) 0
2231 +# define ext3_xattr_cache_find(inode, header) NULL
2232 +# define ext3_xattr_cache_remove(bh) while(0) {}
2233 +# define ext3_xattr_rehash(header, entry) while(0) {}
2237 + * If a file system does not share extended attributes among inodes,
2238 + * we should not need the ext3_xattr_sem semaphore. However, the
2239 + * filesystem may still contain shared blocks, so we always take
2243 +DECLARE_MUTEX(ext3_xattr_sem);
2246 +ext3_xattr_new_block(handle_t *handle, struct inode *inode,
2247 + int * errp, int force)
2249 + struct super_block *sb = inode->i_sb;
2250 + int goal = le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block) +
2251 + EXT3_I(inode)->i_block_group * EXT3_BLOCKS_PER_GROUP(sb);
2253 + /* How can we enforce the allocation? */
2254 + int block = ext3_new_block(handle, inode, goal, 0, 0, errp);
2257 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
2263 +ext3_xattr_quota_alloc(struct inode *inode, int force)
2265 + /* How can we enforce the allocation? */
2267 + int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
2269 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
2271 + int error = DQUOT_ALLOC_BLOCK(inode, 1);
2279 +ext3_xattr_quota_free(struct inode *inode)
2281 + DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
2282 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
2286 +ext3_xattr_free_block(handle_t *handle, struct inode * inode,
2287 + unsigned long block)
2289 + ext3_free_blocks(handle, inode, block, 1);
2290 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
2294 +# define ext3_xattr_quota_free(inode) \
2295 + DQUOT_FREE_BLOCK(inode, 1)
2296 +# define ext3_xattr_free_block(handle, inode, block) \
2297 + ext3_free_blocks(handle, inode, block, 1)
2300 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
2302 +static inline struct buffer_head *
2303 +sb_bread(struct super_block *sb, int block)
2305 + return bread(sb->s_dev, block, sb->s_blocksize);
2308 +static inline struct buffer_head *
2309 +sb_getblk(struct super_block *sb, int block)
2311 + return getblk(sb->s_dev, block, sb->s_blocksize);
2316 +struct ext3_xattr_handler *ext3_xattr_handlers[EXT3_XATTR_INDEX_MAX];
2317 +rwlock_t ext3_handler_lock = RW_LOCK_UNLOCKED;
2320 +ext3_xattr_register(int name_index, struct ext3_xattr_handler *handler)
2322 + int error = -EINVAL;
2324 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
2325 + write_lock(&ext3_handler_lock);
2326 + if (!ext3_xattr_handlers[name_index-1]) {
2327 + ext3_xattr_handlers[name_index-1] = handler;
2330 + write_unlock(&ext3_handler_lock);
2336 +ext3_xattr_unregister(int name_index, struct ext3_xattr_handler *handler)
2338 + if (name_index > 0 || name_index <= EXT3_XATTR_INDEX_MAX) {
2339 + write_lock(&ext3_handler_lock);
2340 + ext3_xattr_handlers[name_index-1] = NULL;
2341 + write_unlock(&ext3_handler_lock);
2345 +static inline const char *
2346 +strcmp_prefix(const char *a, const char *a_prefix)
2348 + while (*a_prefix && *a == *a_prefix) {
2352 + return *a_prefix ? NULL : a;
2356 + * Decode the extended attribute name, and translate it into
2357 + * the name_index and name suffix.
2359 +static inline struct ext3_xattr_handler *
2360 +ext3_xattr_resolve_name(const char **name)
2362 + struct ext3_xattr_handler *handler = NULL;
2367 + read_lock(&ext3_handler_lock);
2368 + for (i=0; i<EXT3_XATTR_INDEX_MAX; i++) {
2369 + if (ext3_xattr_handlers[i]) {
2370 + const char *n = strcmp_prefix(*name,
2371 + ext3_xattr_handlers[i]->prefix);
2373 + handler = ext3_xattr_handlers[i];
2379 + read_unlock(&ext3_handler_lock);
2383 +static inline struct ext3_xattr_handler *
2384 +ext3_xattr_handler(int name_index)
2386 + struct ext3_xattr_handler *handler = NULL;
2387 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
2388 + read_lock(&ext3_handler_lock);
2389 + handler = ext3_xattr_handlers[name_index-1];
2390 + read_unlock(&ext3_handler_lock);
2396 + * Inode operation getxattr()
2398 + * dentry->d_inode->i_sem down
2399 + * BKL held [before 2.5.x]
2402 +ext3_getxattr(struct dentry *dentry, const char *name,
2403 + void *buffer, size_t size)
2405 + struct ext3_xattr_handler *handler;
2406 + struct inode *inode = dentry->d_inode;
2408 + handler = ext3_xattr_resolve_name(&name);
2411 + return handler->get(inode, name, buffer, size);
2415 + * Inode operation listxattr()
2417 + * dentry->d_inode->i_sem down
2418 + * BKL held [before 2.5.x]
2421 +ext3_listxattr(struct dentry *dentry, char *buffer, size_t size)
2423 + return ext3_xattr_list(dentry->d_inode, buffer, size);
2427 + * Inode operation setxattr()
2429 + * dentry->d_inode->i_sem down
2430 + * BKL held [before 2.5.x]
2433 +ext3_setxattr(struct dentry *dentry, const char *name,
2434 + const void *value, size_t size, int flags)
2436 + struct ext3_xattr_handler *handler;
2437 + struct inode *inode = dentry->d_inode;
2440 + value = ""; /* empty EA, do not remove */
2441 + handler = ext3_xattr_resolve_name(&name);
2444 + return handler->set(inode, name, value, size, flags);
2448 + * Inode operation removexattr()
2450 + * dentry->d_inode->i_sem down
2451 + * BKL held [before 2.5.x]
2454 +ext3_removexattr(struct dentry *dentry, const char *name)
2456 + struct ext3_xattr_handler *handler;
2457 + struct inode *inode = dentry->d_inode;
2459 + handler = ext3_xattr_resolve_name(&name);
2462 + return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
2466 + * ext3_xattr_get()
2468 + * Copy an extended attribute into the buffer
2469 + * provided, or compute the buffer size required.
2470 + * Buffer is NULL to compute the size of the buffer required.
2472 + * Returns a negative error number on failure, or the number of bytes
2473 + * used / required on success.
2476 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
2477 + void *buffer, size_t buffer_size)
2479 + struct buffer_head *bh = NULL;
2480 + struct ext3_xattr_entry *entry;
2481 + unsigned int block, size;
2483 + int name_len, error;
2485 + ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
2486 + name_index, name, buffer, (long)buffer_size);
2490 + if (!EXT3_I(inode)->i_file_acl)
2492 + block = EXT3_I(inode)->i_file_acl;
2493 + ea_idebug(inode, "reading block %d", block);
2494 + bh = sb_bread(inode->i_sb, block);
2497 + ea_bdebug(bh, "b_count=%d, refcount=%d",
2498 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
2499 + end = bh->b_data + bh->b_size;
2500 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
2501 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
2502 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_get",
2503 + "inode %ld: bad block %d", inode->i_ino, block);
2507 + /* find named attribute */
2508 + name_len = strlen(name);
2511 + if (name_len > 255)
2513 + entry = FIRST_ENTRY(bh);
2514 + while (!IS_LAST_ENTRY(entry)) {
2515 + struct ext3_xattr_entry *next =
2516 + EXT3_XATTR_NEXT(entry);
2517 + if ((char *)next >= end)
2519 + if (name_index == entry->e_name_index &&
2520 + name_len == entry->e_name_len &&
2521 + memcmp(name, entry->e_name, name_len) == 0)
2525 + /* Check the remaining name entries */
2526 + while (!IS_LAST_ENTRY(entry)) {
2527 + struct ext3_xattr_entry *next =
2528 + EXT3_XATTR_NEXT(entry);
2529 + if ((char *)next >= end)
2533 + if (ext3_xattr_cache_insert(bh))
2534 + ea_idebug(inode, "cache insert failed");
2538 + /* check the buffer size */
2539 + if (entry->e_value_block != 0)
2541 + size = le32_to_cpu(entry->e_value_size);
2542 + if (size > inode->i_sb->s_blocksize ||
2543 + le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
2546 + if (ext3_xattr_cache_insert(bh))
2547 + ea_idebug(inode, "cache insert failed");
2550 + if (size > buffer_size)
2552 + /* return value of attribute */
2553 + memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
2565 + * ext3_xattr_list()
2567 + * Copy a list of attribute names into the buffer
2568 + * provided, or compute the buffer size required.
2569 + * Buffer is NULL to compute the size of the buffer required.
2571 + * Returns a negative error number on failure, or the number of bytes
2572 + * used / required on success.
2575 +ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
2577 + struct buffer_head *bh = NULL;
2578 + struct ext3_xattr_entry *entry;
2579 + unsigned int block, size = 0;
2583 + ea_idebug(inode, "buffer=%p, buffer_size=%ld",
2584 + buffer, (long)buffer_size);
2586 + if (!EXT3_I(inode)->i_file_acl)
2588 + block = EXT3_I(inode)->i_file_acl;
2589 + ea_idebug(inode, "reading block %d", block);
2590 + bh = sb_bread(inode->i_sb, block);
2593 + ea_bdebug(bh, "b_count=%d, refcount=%d",
2594 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
2595 + end = bh->b_data + bh->b_size;
2596 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
2597 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
2598 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_list",
2599 + "inode %ld: bad block %d", inode->i_ino, block);
2603 + /* compute the size required for the list of attribute names */
2604 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
2605 + entry = EXT3_XATTR_NEXT(entry)) {
2606 + struct ext3_xattr_handler *handler;
2607 + struct ext3_xattr_entry *next =
2608 + EXT3_XATTR_NEXT(entry);
2609 + if ((char *)next >= end)
2612 + handler = ext3_xattr_handler(entry->e_name_index);
2614 + size += handler->list(NULL, inode, entry->e_name,
2615 + entry->e_name_len);
2618 + if (ext3_xattr_cache_insert(bh))
2619 + ea_idebug(inode, "cache insert failed");
2625 + if (size > buffer_size)
2629 + /* list the attribute names */
2631 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
2632 + entry = EXT3_XATTR_NEXT(entry)) {
2633 + struct ext3_xattr_handler *handler;
2635 + handler = ext3_xattr_handler(entry->e_name_index);
2637 + buf += handler->list(buf, inode, entry->e_name,
2638 + entry->e_name_len);
2649 + * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is
2650 + * not set, set it.
2652 +static void ext3_xattr_update_super_block(handle_t *handle,
2653 + struct super_block *sb)
2655 + if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR))
2659 + ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh);
2660 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
2661 + EXT3_SB(sb)->s_feature_compat |= EXT3_FEATURE_COMPAT_EXT_ATTR;
2663 + EXT3_SB(sb)->s_es->s_feature_compat |=
2664 + cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR);
2666 + ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
2671 + * ext3_xattr_set()
2673 + * Create, replace or remove an extended attribute for this inode. Buffer
2674 + * is NULL to remove an existing extended attribute, and non-NULL to
2675 + * either replace an existing extended attribute, or create a new extended
2676 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
2677 + * specify that an extended attribute must exist and must not exist
2678 + * previous to the call, respectively.
2680 + * Returns 0, or a negative error number on failure.
2683 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
2684 + const char *name, const void *value, size_t value_len, int flags)
2686 + struct super_block *sb = inode->i_sb;
2687 + struct buffer_head *bh = NULL;
2688 + struct ext3_xattr_header *header = NULL;
2689 + struct ext3_xattr_entry *here, *last;
2690 + unsigned int name_len;
2691 + int block = EXT3_I(inode)->i_file_acl;
2692 + int min_offs = sb->s_blocksize, not_found = 1, free, error;
2696 + * header -- Points either into bh, or to a temporarily
2697 + * allocated buffer.
2698 + * here -- The named entry found, or the place for inserting, within
2699 + * the block pointed to by header.
2700 + * last -- Points right after the last named entry within the block
2701 + * pointed to by header.
2702 + * min_offs -- The offset of the first value (values are aligned
2703 + * towards the end of the block).
2704 + * end -- Points right after the block pointed to by header.
2707 + ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
2708 + name_index, name, value, (long)value_len);
2710 + if (IS_RDONLY(inode))
2712 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2714 + if (value == NULL)
2718 + name_len = strlen(name);
2719 + if (name_len > 255 || value_len > sb->s_blocksize)
2721 + down(&ext3_xattr_sem);
2724 + /* The inode already has an extended attribute block. */
2725 + bh = sb_bread(sb, block);
2729 + ea_bdebug(bh, "b_count=%d, refcount=%d",
2730 + atomic_read(&(bh->b_count)),
2731 + le32_to_cpu(HDR(bh)->h_refcount));
2733 + end = bh->b_data + bh->b_size;
2734 + if (header->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
2735 + header->h_blocks != cpu_to_le32(1)) {
2736 +bad_block: ext3_error(sb, "ext3_xattr_set",
2737 + "inode %ld: bad block %d", inode->i_ino, block);
2741 + /* Find the named attribute. */
2742 + here = FIRST_ENTRY(bh);
2743 + while (!IS_LAST_ENTRY(here)) {
2744 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(here);
2745 + if ((char *)next >= end)
2747 + if (!here->e_value_block && here->e_value_size) {
2748 + int offs = le16_to_cpu(here->e_value_offs);
2749 + if (offs < min_offs)
2752 + not_found = name_index - here->e_name_index;
2754 + not_found = name_len - here->e_name_len;
2756 + not_found = memcmp(name, here->e_name,name_len);
2757 + if (not_found <= 0)
2762 + /* We still need to compute min_offs and last. */
2763 + while (!IS_LAST_ENTRY(last)) {
2764 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
2765 + if ((char *)next >= end)
2767 + if (!last->e_value_block && last->e_value_size) {
2768 + int offs = le16_to_cpu(last->e_value_offs);
2769 + if (offs < min_offs)
2775 + /* Check whether we have enough space left. */
2776 + free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
2778 + /* We will use a new extended attribute block. */
2779 + free = sb->s_blocksize -
2780 + sizeof(struct ext3_xattr_header) - sizeof(__u32);
2781 + here = last = NULL; /* avoid gcc uninitialized warning. */
2785 + /* Request to remove a nonexistent attribute? */
2787 + if (flags & XATTR_REPLACE)
2790 + if (value == NULL)
2793 + free -= EXT3_XATTR_LEN(name_len);
2795 + /* Request to create an existing attribute? */
2797 + if (flags & XATTR_CREATE)
2799 + if (!here->e_value_block && here->e_value_size) {
2800 + unsigned int size = le32_to_cpu(here->e_value_size);
2802 + if (le16_to_cpu(here->e_value_offs) + size >
2803 + sb->s_blocksize || size > sb->s_blocksize)
2805 + free += EXT3_XATTR_SIZE(size);
2808 + free -= EXT3_XATTR_SIZE(value_len);
2813 + /* Here we know that we can set the new attribute. */
2816 + if (header->h_refcount == cpu_to_le32(1)) {
2817 + ea_bdebug(bh, "modifying in-place");
2818 + ext3_xattr_cache_remove(bh);
2819 + error = ext3_journal_get_write_access(handle, bh);
2825 + ea_bdebug(bh, "cloning");
2826 + header = kmalloc(bh->b_size, GFP_KERNEL);
2828 + if (header == NULL)
2830 + memcpy(header, HDR(bh), bh->b_size);
2831 + header->h_refcount = cpu_to_le32(1);
2832 + offset = (char *)header - bh->b_data;
2833 + here = ENTRY((char *)here + offset);
2834 + last = ENTRY((char *)last + offset);
2837 + /* Allocate a buffer where we construct the new block. */
2838 + header = kmalloc(sb->s_blocksize, GFP_KERNEL);
2840 + if (header == NULL)
2842 + memset(header, 0, sb->s_blocksize);
2843 + end = (char *)header + sb->s_blocksize;
2844 + header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC);
2845 + header->h_blocks = header->h_refcount = cpu_to_le32(1);
2846 + last = here = ENTRY(header+1);
2850 + /* Insert the new name. */
2851 + int size = EXT3_XATTR_LEN(name_len);
2852 + int rest = (char *)last - (char *)here;
2853 + memmove((char *)here + size, here, rest);
2854 + memset(here, 0, size);
2855 + here->e_name_index = name_index;
2856 + here->e_name_len = name_len;
2857 + memcpy(here->e_name, name, name_len);
2859 + /* Remove the old value. */
2860 + if (!here->e_value_block && here->e_value_size) {
2861 + char *first_val = (char *)header + min_offs;
2862 + int offs = le16_to_cpu(here->e_value_offs);
2863 + char *val = (char *)header + offs;
2864 + size_t size = EXT3_XATTR_SIZE(
2865 + le32_to_cpu(here->e_value_size));
2866 + memmove(first_val + size, first_val, val - first_val);
2867 + memset(first_val, 0, size);
2868 + here->e_value_offs = 0;
2871 + /* Adjust all value offsets. */
2872 + last = ENTRY(header+1);
2873 + while (!IS_LAST_ENTRY(last)) {
2874 + int o = le16_to_cpu(last->e_value_offs);
2875 + if (!last->e_value_block && o < offs)
2876 + last->e_value_offs =
2877 + cpu_to_le16(o + size);
2878 + last = EXT3_XATTR_NEXT(last);
2881 + if (value == NULL) {
2882 + /* Remove this attribute. */
2883 + if (EXT3_XATTR_NEXT(ENTRY(header+1)) == last) {
2884 + /* This block is now empty. */
2885 + error = ext3_xattr_set2(handle, inode, bh,NULL);
2888 + /* Remove the old name. */
2889 + int size = EXT3_XATTR_LEN(name_len);
2890 + last = ENTRY((char *)last - size);
2891 + memmove(here, (char*)here + size,
2892 + (char*)last - (char*)here);
2893 + memset(last, 0, size);
2898 + if (value != NULL) {
2899 + /* Insert the new value. */
2900 + here->e_value_size = cpu_to_le32(value_len);
2902 + size_t size = EXT3_XATTR_SIZE(value_len);
2903 + char *val = (char *)header + min_offs - size;
2904 + here->e_value_offs =
2905 + cpu_to_le16((char *)val - (char *)header);
2906 + memset(val + size - EXT3_XATTR_PAD, 0,
2907 + EXT3_XATTR_PAD); /* Clear the pad bytes. */
2908 + memcpy(val, value, value_len);
2911 + ext3_xattr_rehash(header, here);
2913 + error = ext3_xattr_set2(handle, inode, bh, header);
2917 + if (!(bh && header == HDR(bh)))
2919 + up(&ext3_xattr_sem);
2925 + * Second half of ext3_xattr_set(): Update the file system.
2928 +ext3_xattr_set2(handle_t *handle, struct inode *inode,
2929 + struct buffer_head *old_bh, struct ext3_xattr_header *header)
2931 + struct super_block *sb = inode->i_sb;
2932 + struct buffer_head *new_bh = NULL;
2936 + new_bh = ext3_xattr_cache_find(inode, header);
2939 + * We found an identical block in the cache.
2940 + * The old block will be released after updating
2943 + ea_bdebug(old_bh, "reusing block %ld",
2944 + new_bh->b_blocknr);
2947 + if (ext3_xattr_quota_alloc(inode, 1))
2950 + error = ext3_journal_get_write_access(handle, new_bh);
2953 + HDR(new_bh)->h_refcount = cpu_to_le32(
2954 + le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
2955 + ea_bdebug(new_bh, "refcount now=%d",
2956 + le32_to_cpu(HDR(new_bh)->h_refcount));
2957 + } else if (old_bh && header == HDR(old_bh)) {
2958 + /* Keep this block. */
2960 + (void)ext3_xattr_cache_insert(new_bh);
2962 + /* We need to allocate a new block */
2963 + int force = EXT3_I(inode)->i_file_acl != 0;
2964 + int block = ext3_xattr_new_block(handle, inode,
2968 + ea_idebug(inode, "creating block %d", block);
2970 + new_bh = sb_getblk(sb, block);
2972 +getblk_failed: ext3_xattr_free_block(handle, inode, block);
2976 + lock_buffer(new_bh);
2977 + error = ext3_journal_get_create_access(handle, new_bh);
2979 + unlock_buffer(new_bh);
2980 + goto getblk_failed;
2982 + memcpy(new_bh->b_data, header, new_bh->b_size);
2983 + mark_buffer_uptodate(new_bh, 1);
2984 + unlock_buffer(new_bh);
2985 + (void)ext3_xattr_cache_insert(new_bh);
2987 + ext3_xattr_update_super_block(handle, sb);
2989 + error = ext3_journal_dirty_metadata(handle, new_bh);
2994 + /* Update the inode. */
2995 + EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
2996 + inode->i_ctime = CURRENT_TIME;
2997 + ext3_mark_inode_dirty(handle, inode);
2998 + if (IS_SYNC(inode))
2999 + handle->h_sync = 1;
3002 + if (old_bh && old_bh != new_bh) {
3004 + * If there was an old block, and we are not still using it,
3005 + * we now release the old block.
3007 + unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
3009 + error = ext3_journal_get_write_access(handle, old_bh);
3012 + if (refcount == 1) {
3013 + /* Free the old block. */
3014 + ea_bdebug(old_bh, "freeing");
3015 + ext3_xattr_free_block(handle, inode, old_bh->b_blocknr);
3017 + /* ext3_forget() calls bforget() for us, but we
3018 + let our caller release old_bh, so we need to
3019 + duplicate the handle before. */
3021 + ext3_forget(handle, 1, inode, old_bh,old_bh->b_blocknr);
3023 + /* Decrement the refcount only. */
3025 + HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
3026 + ext3_xattr_quota_free(inode);
3027 + ext3_journal_dirty_metadata(handle, old_bh);
3028 + ea_bdebug(old_bh, "refcount now=%d", refcount);
3033 + if (old_bh != new_bh)
3040 + * ext3_xattr_delete_inode()
3042 + * Free extended attribute resources associated with this inode. This
3043 + * is called immediately before an inode is freed.
3046 +ext3_xattr_delete_inode(handle_t *handle, struct inode *inode)
3048 + struct buffer_head *bh;
3049 + unsigned int block = EXT3_I(inode)->i_file_acl;
3053 + down(&ext3_xattr_sem);
3055 + bh = sb_bread(inode->i_sb, block);
3057 + ext3_error(inode->i_sb, "ext3_xattr_delete_inode",
3058 + "inode %ld: block %d read error", inode->i_ino, block);
3061 + ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
3062 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
3063 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
3064 + ext3_error(inode->i_sb, "ext3_xattr_delete_inode",
3065 + "inode %ld: bad block %d", inode->i_ino, block);
3068 + ext3_journal_get_write_access(handle, bh);
3069 + ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
3070 + if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
3071 + ext3_xattr_cache_remove(bh);
3072 + ext3_xattr_free_block(handle, inode, block);
3073 + ext3_forget(handle, 1, inode, bh, block);
3076 + HDR(bh)->h_refcount = cpu_to_le32(
3077 + le32_to_cpu(HDR(bh)->h_refcount) - 1);
3078 + ext3_journal_dirty_metadata(handle, bh);
3079 + if (IS_SYNC(inode))
3080 + handle->h_sync = 1;
3081 + ext3_xattr_quota_free(inode);
3083 + EXT3_I(inode)->i_file_acl = 0;
3087 + up(&ext3_xattr_sem);
3091 + * ext3_xattr_put_super()
3093 + * This is called when a file system is unmounted.
3096 +ext3_xattr_put_super(struct super_block *sb)
3098 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
3099 + mb_cache_shrink(ext3_xattr_cache, sb->s_dev);
3103 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
3106 + * ext3_xattr_cache_insert()
3108 + * Create a new entry in the extended attribute cache, and insert
3109 + * it unless such an entry is already in the cache.
3111 + * Returns 0, or a negative error number on failure.
3114 +ext3_xattr_cache_insert(struct buffer_head *bh)
3116 + __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
3117 + struct mb_cache_entry *ce;
3120 + ce = mb_cache_entry_alloc(ext3_xattr_cache);
3123 + error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
3125 + mb_cache_entry_free(ce);
3126 + if (error == -EBUSY) {
3127 + ea_bdebug(bh, "already in cache (%d cache entries)",
3128 + atomic_read(&ext3_xattr_cache->c_entry_count));
3132 + ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
3133 + atomic_read(&ext3_xattr_cache->c_entry_count));
3134 + mb_cache_entry_release(ce);
3140 + * ext3_xattr_cmp()
3142 + * Compare two extended attribute blocks for equality.
3144 + * Returns 0 if the blocks are equal, 1 if they differ, and
3145 + * a negative error number on errors.
3148 +ext3_xattr_cmp(struct ext3_xattr_header *header1,
3149 + struct ext3_xattr_header *header2)
3151 + struct ext3_xattr_entry *entry1, *entry2;
3153 + entry1 = ENTRY(header1+1);
3154 + entry2 = ENTRY(header2+1);
3155 + while (!IS_LAST_ENTRY(entry1)) {
3156 + if (IS_LAST_ENTRY(entry2))
3158 + if (entry1->e_hash != entry2->e_hash ||
3159 + entry1->e_name_len != entry2->e_name_len ||
3160 + entry1->e_value_size != entry2->e_value_size ||
3161 + memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
3163 + if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
3165 + if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
3166 + (char *)header2 + le16_to_cpu(entry2->e_value_offs),
3167 + le32_to_cpu(entry1->e_value_size)))
3170 + entry1 = EXT3_XATTR_NEXT(entry1);
3171 + entry2 = EXT3_XATTR_NEXT(entry2);
3173 + if (!IS_LAST_ENTRY(entry2))
3179 + * ext3_xattr_cache_find()
3181 + * Find an identical extended attribute block.
3183 + * Returns a pointer to the block found, or NULL if such a block was
3184 + * not found or an error occurred.
3186 +static struct buffer_head *
3187 +ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header)
3189 + __u32 hash = le32_to_cpu(header->h_hash);
3190 + struct mb_cache_entry *ce;
3192 + if (!header->h_hash)
3193 + return NULL; /* never share */
3194 + ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
3195 + ce = mb_cache_entry_find_first(ext3_xattr_cache, 0, inode->i_dev, hash);
3197 + struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
3200 + ext3_error(inode->i_sb, "ext3_xattr_cache_find",
3201 + "inode %ld: block %ld read error",
3202 + inode->i_ino, ce->e_block);
3203 + } else if (le32_to_cpu(HDR(bh)->h_refcount) >
3204 + EXT3_XATTR_REFCOUNT_MAX) {
3205 + ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
3206 + le32_to_cpu(HDR(bh)->h_refcount),
3207 + EXT3_XATTR_REFCOUNT_MAX);
3208 + } else if (!ext3_xattr_cmp(header, HDR(bh))) {
3209 + ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
3210 + mb_cache_entry_release(ce);
3214 + ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
3220 + * ext3_xattr_cache_remove()
3222 + * Remove the cache entry of a block from the cache. Called when a
3223 + * block becomes invalid.
3226 +ext3_xattr_cache_remove(struct buffer_head *bh)
3228 + struct mb_cache_entry *ce;
3230 + ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_dev, bh->b_blocknr);
3232 + ea_bdebug(bh, "removing (%d cache entries remaining)",
3233 + atomic_read(&ext3_xattr_cache->c_entry_count)-1);
3234 + mb_cache_entry_free(ce);
3236 + ea_bdebug(bh, "no cache entry");
3239 +#define NAME_HASH_SHIFT 5
3240 +#define VALUE_HASH_SHIFT 16
3243 + * ext3_xattr_hash_entry()
3245 + * Compute the hash of an extended attribute.
3247 +static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
3248 + struct ext3_xattr_entry *entry)
3251 + char *name = entry->e_name;
3254 + for (n=0; n < entry->e_name_len; n++) {
3255 + hash = (hash << NAME_HASH_SHIFT) ^
3256 + (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
3260 + if (entry->e_value_block == 0 && entry->e_value_size != 0) {
3261 + __u32 *value = (__u32 *)((char *)header +
3262 + le16_to_cpu(entry->e_value_offs));
3263 + for (n = (le32_to_cpu(entry->e_value_size) +
3264 + EXT3_XATTR_ROUND) >> EXT3_XATTR_PAD_BITS; n; n--) {
3265 + hash = (hash << VALUE_HASH_SHIFT) ^
3266 + (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
3267 + le32_to_cpu(*value++);
3270 + entry->e_hash = cpu_to_le32(hash);
3273 +#undef NAME_HASH_SHIFT
3274 +#undef VALUE_HASH_SHIFT
3276 +#define BLOCK_HASH_SHIFT 16
3279 + * ext3_xattr_rehash()
3281 + * Re-compute the extended attribute hash value after an entry has changed.
3283 +static void ext3_xattr_rehash(struct ext3_xattr_header *header,
3284 + struct ext3_xattr_entry *entry)
3286 + struct ext3_xattr_entry *here;
3289 + ext3_xattr_hash_entry(header, entry);
3290 + here = ENTRY(header+1);
3291 + while (!IS_LAST_ENTRY(here)) {
3292 + if (!here->e_hash) {
3293 + /* Block is not shared if an entry's hash value == 0 */
3297 + hash = (hash << BLOCK_HASH_SHIFT) ^
3298 + (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
3299 + le32_to_cpu(here->e_hash);
3300 + here = EXT3_XATTR_NEXT(here);
3302 + header->h_hash = cpu_to_le32(hash);
3305 +#undef BLOCK_HASH_SHIFT
3308 +init_ext3_xattr(void)
3310 + ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL,
3311 + sizeof(struct mb_cache_entry) +
3312 + sizeof(struct mb_cache_entry_index), 1, 61);
3313 + if (!ext3_xattr_cache)
3320 +exit_ext3_xattr(void)
3322 + if (ext3_xattr_cache)
3323 + mb_cache_destroy(ext3_xattr_cache);
3324 + ext3_xattr_cache = NULL;
3327 +#else /* CONFIG_EXT3_FS_XATTR_SHARING */
3330 +init_ext3_xattr(void)
3336 +exit_ext3_xattr(void)
3340 +#endif /* CONFIG_EXT3_FS_XATTR_SHARING */
3341 --- /dev/null Mon May 20 21:11:23 2002
3342 +++ linux-mmonroe/fs/ext3/xattr_user.c Fri May 16 08:43:01 2003
3345 + * linux/fs/ext3/xattr_user.c
3346 + * Handler for extended user attributes.
3348 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
3351 +#include <linux/module.h>
3352 +#include <linux/string.h>
3353 +#include <linux/fs.h>
3354 +#include <linux/ext3_jbd.h>
3355 +#include <linux/ext3_fs.h>
3356 +#include <linux/ext3_xattr.h>
3358 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3359 +# include <linux/ext3_acl.h>
3362 +#define XATTR_USER_PREFIX "user."
3365 +ext3_xattr_user_list(char *list, struct inode *inode,
3366 + const char *name, int name_len)
3368 + const int prefix_len = sizeof(XATTR_USER_PREFIX)-1;
3370 + if (!test_opt(inode->i_sb, XATTR_USER))
3374 + memcpy(list, XATTR_USER_PREFIX, prefix_len);
3375 + memcpy(list+prefix_len, name, name_len);
3376 + list[prefix_len + name_len] = '\0';
3378 + return prefix_len + name_len + 1;
3382 +ext3_xattr_user_get(struct inode *inode, const char *name,
3383 + void *buffer, size_t size)
3387 + if (strcmp(name, "") == 0)
3389 + if (!test_opt(inode->i_sb, XATTR_USER))
3391 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3392 + error = ext3_permission_locked(inode, MAY_READ);
3394 + error = permission(inode, MAY_READ);
3399 + return ext3_xattr_get(inode, EXT3_XATTR_INDEX_USER, name,
3404 +ext3_xattr_user_set(struct inode *inode, const char *name,
3405 + const void *value, size_t size, int flags)
3410 + if (strcmp(name, "") == 0)
3412 + if (!test_opt(inode->i_sb, XATTR_USER))
3414 + if ( !S_ISREG(inode->i_mode) &&
3415 + (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
3417 +#ifdef CONFIG_EXT3_FS_POSIX_ACL
3418 + error = ext3_permission_locked(inode, MAY_WRITE);
3420 + error = permission(inode, MAY_WRITE);
3425 + handle = ext3_journal_start(inode, EXT3_XATTR_TRANS_BLOCKS);
3426 + if (IS_ERR(handle))
3427 + return PTR_ERR(handle);
3428 + error = ext3_xattr_set(handle, inode, EXT3_XATTR_INDEX_USER, name,
3429 + value, size, flags);
3430 + ext3_journal_stop(handle, inode);
3435 +struct ext3_xattr_handler ext3_xattr_user_handler = {
3436 + prefix: XATTR_USER_PREFIX,
3437 + list: ext3_xattr_user_list,
3438 + get: ext3_xattr_user_get,
3439 + set: ext3_xattr_user_set,
3443 +init_ext3_xattr_user(void)
3445 + return ext3_xattr_register(EXT3_XATTR_INDEX_USER,
3446 + &ext3_xattr_user_handler);
3450 +exit_ext3_xattr_user(void)
3452 + ext3_xattr_unregister(EXT3_XATTR_INDEX_USER,
3453 + &ext3_xattr_user_handler);
3455 --- /dev/null Mon May 20 21:11:23 2002
3456 +++ linux-mmonroe/fs/ext3/ext3-exports.c Fri May 16 08:43:01 2003
3458 +#include <linux/config.h>
3459 +#include <linux/module.h>
3460 +#include <linux/ext3_fs.h>
3461 +#include <linux/ext3_jbd.h>
3462 +#include <linux/ext3_xattr.h>
3464 +EXPORT_SYMBOL(ext3_force_commit);
3465 +EXPORT_SYMBOL(ext3_bread);
3466 +EXPORT_SYMBOL(ext3_xattr_register);
3467 +EXPORT_SYMBOL(ext3_xattr_unregister);
3468 +EXPORT_SYMBOL(ext3_xattr_get);
3469 +EXPORT_SYMBOL(ext3_xattr_list);
3470 +EXPORT_SYMBOL(ext3_xattr_set);
3471 --- linux/fs/jfs/jfs_xattr.h~linux-2.4.20-xattr-0.8.54-hp Thu Nov 28 15:53:15 2002
3472 +++ linux-mmonroe/fs/jfs/jfs_xattr.h Fri May 16 08:43:01 2003
3473 @@ -52,8 +52,10 @@ struct jfs_ea_list {
3474 #define END_EALIST(ealist) \
3475 ((struct jfs_ea *) (((char *) (ealist)) + EALIST_SIZE(ealist)))
3477 -extern int __jfs_setxattr(struct inode *, const char *, void *, size_t, int);
3478 -extern int jfs_setxattr(struct dentry *, const char *, void *, size_t, int);
3479 +extern int __jfs_setxattr(struct inode *, const char *, const void *, size_t,
3481 +extern int jfs_setxattr(struct dentry *, const char *, const void *, size_t,
3483 extern ssize_t __jfs_getxattr(struct inode *, const char *, void *, size_t);
3484 extern ssize_t jfs_getxattr(struct dentry *, const char *, void *, size_t);
3485 extern ssize_t jfs_listxattr(struct dentry *, char *, size_t);
3486 --- linux/fs/jfs/xattr.c~linux-2.4.20-xattr-0.8.54-hp Thu Nov 28 15:53:15 2002
3487 +++ linux-mmonroe/fs/jfs/xattr.c Fri May 16 08:43:01 2003
3488 @@ -641,7 +641,7 @@ static int ea_put(struct inode *inode, s
3491 static int can_set_xattr(struct inode *inode, const char *name,
3492 - void *value, size_t value_len)
3493 + const void *value, size_t value_len)
3495 if (IS_RDONLY(inode))
3497 @@ -660,7 +660,7 @@ static int can_set_xattr(struct inode *i
3498 return permission(inode, MAY_WRITE);
3501 -int __jfs_setxattr(struct inode *inode, const char *name, void *value,
3502 +int __jfs_setxattr(struct inode *inode, const char *name, const void *value,
3503 size_t value_len, int flags)
3505 struct jfs_ea_list *ealist;
3506 @@ -799,7 +799,7 @@ int __jfs_setxattr(struct inode *inode,
3510 -int jfs_setxattr(struct dentry *dentry, const char *name, void *value,
3511 +int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
3512 size_t value_len, int flags)
3514 if (value == NULL) { /* empty EA, do not remove */
3515 --- /dev/null Mon May 20 21:11:23 2002
3516 +++ linux-mmonroe/fs/mbcache.c Fri May 16 08:43:01 2003
3519 + * linux/fs/mbcache.c
3520 + * (C) 2001-2002 Andreas Gruenbacher, <a.gruenbacher@computer.org>
3524 + * Filesystem Meta Information Block Cache (mbcache)
3526 + * The mbcache caches blocks of block devices that need to be located
3527 + * by their device/block number, as well as by other criteria (such
3528 + * as the block's contents).
3530 + * There can only be one cache entry in a cache per device and block number.
3531 + * Additional indexes need not be unique in this sense. The number of
3532 + * additional indexes (=other criteria) can be hardwired at compile time
3533 + * or specified at cache create time.
3535 + * Each cache entry is of fixed size. An entry may be `valid' or `invalid'
3536 + * in the cache. A valid entry is in the main hash tables of the cache,
3537 + * and may also be in the lru list. An invalid entry is not in any hashes
3540 + * A valid cache entry is only in the lru list if no handles refer to it.
3541 + * Invalid cache entries will be freed when the last handle to the cache
3542 + * entry is released. Entries that cannot be freed immediately are put
3543 + * back on the lru list.
3546 +#include <linux/kernel.h>
3547 +#include <linux/module.h>
3549 +#include <linux/fs.h>
3550 +#include <linux/slab.h>
3551 +#include <linux/sched.h>
3552 +#include <linux/cache_def.h>
3553 +#include <linux/version.h>
3554 +#include <linux/init.h>
3555 +#include <linux/mbcache.h>
3558 +#ifdef MB_CACHE_DEBUG
3559 +# define mb_debug(f...) do { \
3560 + printk(KERN_DEBUG f); \
3563 +#define mb_assert(c) do { if (!(c)) \
3564 + printk(KERN_ERR "assertion " #c " failed\n"); \
3567 +# define mb_debug(f...) do { } while(0)
3568 +# define mb_assert(c) do { } while(0)
3570 +#define mb_error(f...) do { \
3571 + printk(KERN_ERR f); \
3575 +MODULE_AUTHOR("Andreas Gruenbacher <a.gruenbacher@computer.org>");
3576 +MODULE_DESCRIPTION("Meta block cache (for extended attributes)");
3577 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
3578 +MODULE_LICENSE("GPL");
3581 +EXPORT_SYMBOL(mb_cache_create);
3582 +EXPORT_SYMBOL(mb_cache_shrink);
3583 +EXPORT_SYMBOL(mb_cache_destroy);
3584 +EXPORT_SYMBOL(mb_cache_entry_alloc);
3585 +EXPORT_SYMBOL(mb_cache_entry_insert);
3586 +EXPORT_SYMBOL(mb_cache_entry_release);
3587 +EXPORT_SYMBOL(mb_cache_entry_takeout);
3588 +EXPORT_SYMBOL(mb_cache_entry_free);
3589 +EXPORT_SYMBOL(mb_cache_entry_dup);
3590 +EXPORT_SYMBOL(mb_cache_entry_get);
3591 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
3592 +EXPORT_SYMBOL(mb_cache_entry_find_first);
3593 +EXPORT_SYMBOL(mb_cache_entry_find_next);
3598 + * Global data: list of all mbcache's, lru list, and a spinlock for
3599 + * accessing cache data structures on SMP machines. The lru list is
3600 + * global across all mbcaches.
3603 +static LIST_HEAD(mb_cache_list);
3604 +static LIST_HEAD(mb_cache_lru_list);
3605 +static spinlock_t mb_cache_spinlock = SPIN_LOCK_UNLOCKED;
3608 +mb_cache_indexes(struct mb_cache *cache)
3610 +#ifdef MB_CACHE_INDEXES_COUNT
3611 + return MB_CACHE_INDEXES_COUNT;
3613 + return cache->c_indexes_count;
3618 + * What the mbcache registers as to get shrunk dynamically.
3622 +mb_cache_memory_pressure(int priority, unsigned int gfp_mask);
3624 +static struct cache_definition mb_cache_definition = {
3626 + mb_cache_memory_pressure
3631 +__mb_cache_entry_is_hashed(struct mb_cache_entry *ce)
3633 + return !list_empty(&ce->e_block_list);
3638 +__mb_cache_entry_unhash(struct mb_cache_entry *ce)
3642 + if (__mb_cache_entry_is_hashed(ce)) {
3643 + list_del_init(&ce->e_block_list);
3644 + for (n=0; n<mb_cache_indexes(ce->e_cache); n++)
3645 + list_del(&ce->e_indexes[n].o_list);
3651 +__mb_cache_entry_forget(struct mb_cache_entry *ce, int gfp_mask)
3653 + struct mb_cache *cache = ce->e_cache;
3655 + mb_assert(atomic_read(&ce->e_used) == 0);
3656 + if (cache->c_op.free && cache->c_op.free(ce, gfp_mask)) {
3657 + /* free failed -- put back on the lru list
3658 + for freeing later. */
3659 + spin_lock(&mb_cache_spinlock);
3660 + list_add(&ce->e_lru_list, &mb_cache_lru_list);
3661 + spin_unlock(&mb_cache_spinlock);
3663 + kmem_cache_free(cache->c_entry_cache, ce);
3664 + atomic_dec(&cache->c_entry_count);
3670 +__mb_cache_entry_release_unlock(struct mb_cache_entry *ce)
3672 + if (atomic_dec_and_test(&ce->e_used)) {
3673 + if (__mb_cache_entry_is_hashed(ce))
3674 + list_add_tail(&ce->e_lru_list, &mb_cache_lru_list);
3676 + spin_unlock(&mb_cache_spinlock);
3677 + __mb_cache_entry_forget(ce, GFP_KERNEL);
3681 + spin_unlock(&mb_cache_spinlock);
3686 + * mb_cache_memory_pressure() memory pressure callback
3688 + * This function is called by the kernel memory management when memory
3691 + * @priority: Amount by which to shrink the cache (0 = highes priority)
3692 + * @gfp_mask: (ignored)
3695 +mb_cache_memory_pressure(int priority, unsigned int gfp_mask)
3697 + LIST_HEAD(free_list);
3698 + struct list_head *l, *ltmp;
3701 + spin_lock(&mb_cache_spinlock);
3702 + list_for_each(l, &mb_cache_list) {
3703 + struct mb_cache *cache =
3704 + list_entry(l, struct mb_cache, c_cache_list);
3705 + mb_debug("cache %s (%d)", cache->c_name,
3706 + atomic_read(&cache->c_entry_count));
3707 + count += atomic_read(&cache->c_entry_count);
3709 + mb_debug("trying to free %d of %d entries",
3710 + count / (priority ? priority : 1), count);
3712 + count /= priority;
3713 + while (count-- && !list_empty(&mb_cache_lru_list)) {
3714 + struct mb_cache_entry *ce =
3715 + list_entry(mb_cache_lru_list.next,
3716 + struct mb_cache_entry, e_lru_list);
3717 + list_del(&ce->e_lru_list);
3718 + __mb_cache_entry_unhash(ce);
3719 + list_add_tail(&ce->e_lru_list, &free_list);
3721 + spin_unlock(&mb_cache_spinlock);
3722 + list_for_each_safe(l, ltmp, &free_list) {
3723 + __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
3724 + e_lru_list), gfp_mask);
3730 + * mb_cache_create() create a new cache
3732 + * All entries in one cache are equal size. Cache entries may be from
3733 + * multiple devices. If this is the first mbcache created, registers
3734 + * the cache with kernel memory management. Returns NULL if no more
3735 + * memory was available.
3737 + * @name: name of the cache (informal)
3738 + * @cache_op: contains the callback called when freeing a cache entry
3739 + * @entry_size: The size of a cache entry, including
3740 + * struct mb_cache_entry
3741 + * @indexes_count: number of additional indexes in the cache. Must equal
3742 + * MB_CACHE_INDEXES_COUNT if the number of indexes is
3744 + * @bucket_count: number of hash buckets
3747 +mb_cache_create(const char *name, struct mb_cache_op *cache_op,
3748 + size_t entry_size, int indexes_count, int bucket_count)
3751 + struct mb_cache *cache = NULL;
3753 + if(entry_size < sizeof(struct mb_cache_entry) +
3754 + indexes_count * sizeof(struct mb_cache_entry_index))
3757 + MOD_INC_USE_COUNT;
3758 + cache = kmalloc(sizeof(struct mb_cache) +
3759 + indexes_count * sizeof(struct list_head), GFP_KERNEL);
3762 + cache->c_name = name;
3763 + cache->c_op.free = NULL;
3765 + cache->c_op.free = cache_op->free;
3766 + atomic_set(&cache->c_entry_count, 0);
3767 + cache->c_bucket_count = bucket_count;
3768 +#ifdef MB_CACHE_INDEXES_COUNT
3769 + mb_assert(indexes_count == MB_CACHE_INDEXES_COUNT);
3771 + cache->c_indexes_count = indexes_count;
3773 + cache->c_block_hash = kmalloc(bucket_count * sizeof(struct list_head),
3775 + if (!cache->c_block_hash)
3777 + for (n=0; n<bucket_count; n++)
3778 + INIT_LIST_HEAD(&cache->c_block_hash[n]);
3779 + for (m=0; m<indexes_count; m++) {
3780 + cache->c_indexes_hash[m] = kmalloc(bucket_count *
3781 + sizeof(struct list_head),
3783 + if (!cache->c_indexes_hash[m])
3785 + for (n=0; n<bucket_count; n++)
3786 + INIT_LIST_HEAD(&cache->c_indexes_hash[m][n]);
3788 + cache->c_entry_cache = kmem_cache_create(name, entry_size, 0,
3789 + 0 /*SLAB_POISON | SLAB_RED_ZONE*/, NULL, NULL);
3790 + if (!cache->c_entry_cache)
3793 + spin_lock(&mb_cache_spinlock);
3794 + list_add(&cache->c_cache_list, &mb_cache_list);
3795 + spin_unlock(&mb_cache_spinlock);
3801 + kfree(cache->c_indexes_hash[m]);
3802 + if (cache->c_block_hash)
3803 + kfree(cache->c_block_hash);
3806 + MOD_DEC_USE_COUNT;
3812 + * mb_cache_shrink()
3814 + * Removes all cache entires of a device from the cache. All cache entries
3815 + * currently in use cannot be freed, and thus remain in the cache.
3817 + * @cache: which cache to shrink
3818 + * @dev: which device's cache entries to shrink
3821 +mb_cache_shrink(struct mb_cache *cache, kdev_t dev)
3823 + LIST_HEAD(free_list);
3824 + struct list_head *l, *ltmp;
3826 + spin_lock(&mb_cache_spinlock);
3827 + list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
3828 + struct mb_cache_entry *ce =
3829 + list_entry(l, struct mb_cache_entry, e_lru_list);
3830 + if (ce->e_dev == dev) {
3831 + list_del(&ce->e_lru_list);
3832 + list_add_tail(&ce->e_lru_list, &free_list);
3833 + __mb_cache_entry_unhash(ce);
3836 + spin_unlock(&mb_cache_spinlock);
3837 + list_for_each_safe(l, ltmp, &free_list) {
3838 + __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
3839 + e_lru_list), GFP_KERNEL);
3845 + * mb_cache_destroy()
3847 + * Shrinks the cache to its minimum possible size (hopefully 0 entries),
3848 + * and then destroys it. If this was the last mbcache, un-registers the
3849 + * mbcache from kernel memory management.
3852 +mb_cache_destroy(struct mb_cache *cache)
3854 + LIST_HEAD(free_list);
3855 + struct list_head *l, *ltmp;
3858 + spin_lock(&mb_cache_spinlock);
3859 + list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
3860 + struct mb_cache_entry *ce =
3861 + list_entry(l, struct mb_cache_entry, e_lru_list);
3862 + if (ce->e_cache == cache) {
3863 + list_del(&ce->e_lru_list);
3864 + list_add_tail(&ce->e_lru_list, &free_list);
3865 + __mb_cache_entry_unhash(ce);
3868 + list_del(&cache->c_cache_list);
3869 + spin_unlock(&mb_cache_spinlock);
3870 + list_for_each_safe(l, ltmp, &free_list) {
3871 + __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
3872 + e_lru_list), GFP_KERNEL);
3875 + if (atomic_read(&cache->c_entry_count) > 0) {
3876 + mb_error("cache %s: %d orphaned entries",
3878 + atomic_read(&cache->c_entry_count));
3881 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
3882 + /* We don't have kmem_cache_destroy() in 2.2.x */
3883 + kmem_cache_shrink(cache->c_entry_cache);
3885 + kmem_cache_destroy(cache->c_entry_cache);
3887 + for (n=0; n < mb_cache_indexes(cache); n++)
3888 + kfree(cache->c_indexes_hash[n]);
3889 + kfree(cache->c_block_hash);
3892 + MOD_DEC_USE_COUNT;
3897 + * mb_cache_entry_alloc()
3899 + * Allocates a new cache entry. The new entry will not be valid initially,
3900 + * and thus cannot be looked up yet. It should be filled with data, and
3901 + * then inserted into the cache using mb_cache_entry_insert(). Returns NULL
3902 + * if no more memory was available.
3904 +struct mb_cache_entry *
3905 +mb_cache_entry_alloc(struct mb_cache *cache)
3907 + struct mb_cache_entry *ce;
3909 + atomic_inc(&cache->c_entry_count);
3910 + ce = kmem_cache_alloc(cache->c_entry_cache, GFP_KERNEL);
3912 + INIT_LIST_HEAD(&ce->e_lru_list);
3913 + INIT_LIST_HEAD(&ce->e_block_list);
3914 + ce->e_cache = cache;
3915 + atomic_set(&ce->e_used, 1);
3922 + * mb_cache_entry_insert()
3924 + * Inserts an entry that was allocated using mb_cache_entry_alloc() into
3925 + * the cache. After this, the cache entry can be looked up, but is not yet
3926 + * in the lru list as the caller still holds a handle to it. Returns 0 on
3927 + * success, or -EBUSY if a cache entry for that device + inode exists
3928 + * already (this may happen after a failed lookup, if another process has
3929 + * inserted the same cache entry in the meantime).
3931 + * @dev: device the cache entry belongs to
3932 + * @block: block number
3933 + * @keys: array of additional keys. There must be indexes_count entries
3934 + * in the array (as specified when creating the cache).
3937 +mb_cache_entry_insert(struct mb_cache_entry *ce, kdev_t dev,
3938 + unsigned long block, unsigned int keys[])
3940 + struct mb_cache *cache = ce->e_cache;
3941 + unsigned int bucket = (HASHDEV(dev) + block) % cache->c_bucket_count;
3942 + struct list_head *l;
3943 + int error = -EBUSY, n;
3945 + spin_lock(&mb_cache_spinlock);
3946 + list_for_each(l, &cache->c_block_hash[bucket]) {
3947 + struct mb_cache_entry *ce =
3948 + list_entry(l, struct mb_cache_entry, e_block_list);
3949 + if (ce->e_dev == dev && ce->e_block == block)
3952 + __mb_cache_entry_unhash(ce);
3954 + ce->e_block = block;
3955 + list_add(&ce->e_block_list, &cache->c_block_hash[bucket]);
3956 + for (n=0; n<mb_cache_indexes(cache); n++) {
3957 + ce->e_indexes[n].o_key = keys[n];
3958 + bucket = keys[n] % cache->c_bucket_count;
3959 + list_add(&ce->e_indexes[n].o_list,
3960 + &cache->c_indexes_hash[n][bucket]);
3963 + spin_unlock(&mb_cache_spinlock);
3969 + * mb_cache_entry_release()
3971 + * Release a handle to a cache entry. When the last handle to a cache entry
3972 + * is released it is either freed (if it is invalid) or otherwise inserted
3973 + * in to the lru list.
3976 +mb_cache_entry_release(struct mb_cache_entry *ce)
3978 + spin_lock(&mb_cache_spinlock);
3979 + __mb_cache_entry_release_unlock(ce);
3984 + * mb_cache_entry_takeout()
3986 + * Take a cache entry out of the cache, making it invalid. The entry can later
3987 + * be re-inserted using mb_cache_entry_insert(), or released using
3988 + * mb_cache_entry_release().
3991 +mb_cache_entry_takeout(struct mb_cache_entry *ce)
3993 + spin_lock(&mb_cache_spinlock);
3994 + mb_assert(list_empty(&ce->e_lru_list));
3995 + __mb_cache_entry_unhash(ce);
3996 + spin_unlock(&mb_cache_spinlock);
4001 + * mb_cache_entry_free()
4003 + * This is equivalent to the sequence mb_cache_entry_takeout() --
4004 + * mb_cache_entry_release().
4007 +mb_cache_entry_free(struct mb_cache_entry *ce)
4009 + spin_lock(&mb_cache_spinlock);
4010 + mb_assert(list_empty(&ce->e_lru_list));
4011 + __mb_cache_entry_unhash(ce);
4012 + __mb_cache_entry_release_unlock(ce);
4017 + * mb_cache_entry_dup()
4019 + * Duplicate a handle to a cache entry (does not duplicate the cache entry
4020 + * itself). After the call, both the old and the new handle must be released.
4022 +struct mb_cache_entry *
4023 +mb_cache_entry_dup(struct mb_cache_entry *ce)
4025 + atomic_inc(&ce->e_used);
4031 + * mb_cache_entry_get()
4033 + * Get a cache entry by device / block number. (There can only be one entry
4034 + * in the cache per device and block.) Returns NULL if no such cache entry
4037 +struct mb_cache_entry *
4038 +mb_cache_entry_get(struct mb_cache *cache, kdev_t dev, unsigned long block)
4040 + unsigned int bucket = (HASHDEV(dev) + block) % cache->c_bucket_count;
4041 + struct list_head *l;
4042 + struct mb_cache_entry *ce;
4044 + spin_lock(&mb_cache_spinlock);
4045 + list_for_each(l, &cache->c_block_hash[bucket]) {
4046 + ce = list_entry(l, struct mb_cache_entry, e_block_list);
4047 + if (ce->e_dev == dev && ce->e_block == block) {
4048 + if (!list_empty(&ce->e_lru_list))
4049 + list_del_init(&ce->e_lru_list);
4050 + atomic_inc(&ce->e_used);
4057 + spin_unlock(&mb_cache_spinlock);
4061 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
4063 +static struct mb_cache_entry *
4064 +__mb_cache_entry_find(struct list_head *l, struct list_head *head,
4065 + int index, kdev_t dev, unsigned int key)
4067 + while (l != head) {
4068 + struct mb_cache_entry *ce =
4069 + list_entry(l, struct mb_cache_entry,
4070 + e_indexes[index].o_list);
4071 + if (ce->e_dev == dev && ce->e_indexes[index].o_key == key) {
4072 + if (!list_empty(&ce->e_lru_list))
4073 + list_del_init(&ce->e_lru_list);
4074 + atomic_inc(&ce->e_used);
4084 + * mb_cache_entry_find_first()
4086 + * Find the first cache entry on a given device with a certain key in
4087 + * an additional index. Additonal matches can be found with
4088 + * mb_cache_entry_find_next(). Returns NULL if no match was found.
4090 + * @cache: the cache to search
4091 + * @index: the number of the additonal index to search (0<=index<indexes_count)
4092 + * @dev: the device the cache entry should belong to
4093 + * @key: the key in the index
4095 +struct mb_cache_entry *
4096 +mb_cache_entry_find_first(struct mb_cache *cache, int index, kdev_t dev,
4099 + unsigned int bucket = key % cache->c_bucket_count;
4100 + struct list_head *l;
4101 + struct mb_cache_entry *ce;
4103 + mb_assert(index < mb_cache_indexes(cache));
4104 + spin_lock(&mb_cache_spinlock);
4105 + l = cache->c_indexes_hash[index][bucket].next;
4106 + ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
4108 + spin_unlock(&mb_cache_spinlock);
4114 + * mb_cache_entry_find_next()
4116 + * Find the next cache entry on a given device with a certain key in an
4117 + * additional index. Returns NULL if no match could be found. The previous
4118 + * entry is atomatically released, so that mb_cache_entry_find_next() can
4119 + * be called like this:
4121 + * entry = mb_cache_entry_find_first();
4124 + * entry = mb_cache_entry_find_next(entry, ...);
4127 + * @prev: The previous match
4128 + * @index: the number of the additonal index to search (0<=index<indexes_count)
4129 + * @dev: the device the cache entry should belong to
4130 + * @key: the key in the index
4132 +struct mb_cache_entry *
4133 +mb_cache_entry_find_next(struct mb_cache_entry *prev, int index, kdev_t dev,
4136 + struct mb_cache *cache = prev->e_cache;
4137 + unsigned int bucket = key % cache->c_bucket_count;
4138 + struct list_head *l;
4139 + struct mb_cache_entry *ce;
4141 + mb_assert(index < mb_cache_indexes(cache));
4142 + spin_lock(&mb_cache_spinlock);
4143 + l = prev->e_indexes[index].o_list.next;
4144 + ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
4146 + __mb_cache_entry_release_unlock(prev);
4150 +#endif /* !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0) */
4152 +static int __init init_mbcache(void)
4154 + register_cache(&mb_cache_definition);
4158 +static void __exit exit_mbcache(void)
4160 + unregister_cache(&mb_cache_definition);
4163 +module_init(init_mbcache)
4164 +module_exit(exit_mbcache)
4166 --- /dev/null Mon May 20 21:11:23 2002
4167 +++ linux-mmonroe/include/linux/cache_def.h Fri May 16 08:43:01 2003
4170 + * linux/cache_def.h
4171 + * Handling of caches defined in drivers, filesystems, ...
4173 + * Copyright (C) 2002 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
4176 +struct cache_definition {
4178 + void (*shrink)(int, unsigned int);
4179 + struct list_head link;
4182 +extern void register_cache(struct cache_definition *);
4183 +extern void unregister_cache(struct cache_definition *);
4184 --- linux/include/linux/errno.h~linux-2.4.20-xattr-0.8.54-hp Fri Feb 9 14:46:13 2001
4185 +++ linux-mmonroe/include/linux/errno.h Fri May 16 08:43:01 2003
4190 +/* Defined for extended attributes */
4191 +#define ENOATTR ENODATA /* No such attribute */
4192 +#define ENOTSUP EOPNOTSUPP /* Operation not supported */
4195 --- linux/include/linux/ext2_fs.h~linux-2.4.20-xattr-0.8.54-hp Thu Nov 22 11:46:52 2001
4196 +++ linux-mmonroe/include/linux/ext2_fs.h Fri May 16 08:43:01 2003
4199 #define EXT2_BAD_INO 1 /* Bad blocks inode */
4200 #define EXT2_ROOT_INO 2 /* Root inode */
4201 -#define EXT2_ACL_IDX_INO 3 /* ACL inode */
4202 -#define EXT2_ACL_DATA_INO 4 /* ACL inode */
4203 #define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
4204 #define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
4208 # define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
4210 -#define EXT2_ACLE_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
4211 #define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
4213 # define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
4214 @@ -121,28 +118,6 @@
4220 -struct ext2_acl_header /* Header of Access Control Lists */
4223 - __u32 aclh_file_count;
4224 - __u32 aclh_acle_count;
4225 - __u32 aclh_first_acle;
4228 -struct ext2_acl_entry /* Access Control List Entry */
4231 - __u16 acle_perms; /* Access permissions */
4232 - __u16 acle_type; /* Type of entry */
4233 - __u16 acle_tag; /* User or group identity */
4235 - __u32 acle_next; /* Pointer on next entry for the */
4236 - /* same inode or on next free entry */
4240 * Structure of a blocks group descriptor
4242 struct ext2_group_desc
4243 @@ -314,6 +289,7 @@ struct ext2_inode {
4244 #define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
4245 #define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
4246 #define EXT2_MOUNT_NO_UID32 0x0200 /* Disable 32-bit UIDs */
4247 +#define EXT2_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
4249 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
4250 #define set_opt(o, opt) o |= EXT2_MOUNT_##opt
4251 @@ -397,6 +373,7 @@ struct ext2_super_block {
4254 #define EXT2_SB(sb) (&((sb)->u.ext2_sb))
4255 +#define EXT2_I(inode) (&((inode)->u.ext2_i))
4257 /* Assume that user mode programs are passing in an ext2fs superblock, not
4258 * a kernel struct super_block. This will allow us to call the feature-test
4259 @@ -466,7 +443,7 @@ struct ext2_super_block {
4260 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
4261 #define EXT2_FEATURE_INCOMPAT_ANY 0xffffffff
4263 -#define EXT2_FEATURE_COMPAT_SUPP 0
4264 +#define EXT2_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
4265 #define EXT2_FEATURE_INCOMPAT_SUPP EXT2_FEATURE_INCOMPAT_FILETYPE
4266 #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
4267 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
4268 @@ -623,8 +600,10 @@ extern struct address_space_operations e
4271 extern struct inode_operations ext2_dir_inode_operations;
4272 +extern struct inode_operations ext2_special_inode_operations;
4275 +extern struct inode_operations ext2_symlink_inode_operations;
4276 extern struct inode_operations ext2_fast_symlink_inode_operations;
4278 #endif /* __KERNEL__ */
4279 --- /dev/null Mon May 20 21:11:23 2002
4280 +++ linux-mmonroe/include/linux/ext2_xattr.h Fri May 16 08:43:01 2003
4283 + File: linux/ext2_xattr.h
4285 + On-disk format of extended attributes for the ext2 filesystem.
4287 + (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
4290 +#include <linux/config.h>
4291 +#include <linux/init.h>
4292 +#include <linux/xattr.h>
4294 +/* Magic value in attribute blocks */
4295 +#define EXT2_XATTR_MAGIC 0xEA020000
4297 +/* Maximum number of references to one attribute block */
4298 +#define EXT2_XATTR_REFCOUNT_MAX 1024
4301 +#define EXT2_XATTR_INDEX_MAX 10
4302 +#define EXT2_XATTR_INDEX_USER 1
4303 +#define EXT2_XATTR_INDEX_POSIX_ACL_ACCESS 2
4304 +#define EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT 3
4306 +struct ext2_xattr_header {
4307 + __u32 h_magic; /* magic number for identification */
4308 + __u32 h_refcount; /* reference count */
4309 + __u32 h_blocks; /* number of disk blocks used */
4310 + __u32 h_hash; /* hash value of all attributes */
4311 + __u32 h_reserved[4]; /* zero right now */
4314 +struct ext2_xattr_entry {
4315 + __u8 e_name_len; /* length of name */
4316 + __u8 e_name_index; /* attribute name index */
4317 + __u16 e_value_offs; /* offset in disk block of value */
4318 + __u32 e_value_block; /* disk block attribute is stored on (n/i) */
4319 + __u32 e_value_size; /* size of attribute value */
4320 + __u32 e_hash; /* hash value of name and value */
4321 + char e_name[0]; /* attribute name */
4324 +#define EXT2_XATTR_PAD_BITS 2
4325 +#define EXT2_XATTR_PAD (1<<EXT2_XATTR_PAD_BITS)
4326 +#define EXT2_XATTR_ROUND (EXT2_XATTR_PAD-1)
4327 +#define EXT2_XATTR_LEN(name_len) \
4328 + (((name_len) + EXT2_XATTR_ROUND + \
4329 + sizeof(struct ext2_xattr_entry)) & ~EXT2_XATTR_ROUND)
4330 +#define EXT2_XATTR_NEXT(entry) \
4331 + ( (struct ext2_xattr_entry *)( \
4332 + (char *)(entry) + EXT2_XATTR_LEN((entry)->e_name_len)) )
4333 +#define EXT2_XATTR_SIZE(size) \
4334 + (((size) + EXT2_XATTR_ROUND) & ~EXT2_XATTR_ROUND)
4338 +# ifdef CONFIG_EXT2_FS_XATTR
4340 +struct ext2_xattr_handler {
4342 + size_t (*list)(char *list, struct inode *inode, const char *name,
4344 + int (*get)(struct inode *inode, const char *name, void *buffer,
4346 + int (*set)(struct inode *inode, const char *name, const void *buffer,
4347 + size_t size, int flags);
4350 +extern int ext2_xattr_register(int, struct ext2_xattr_handler *);
4351 +extern void ext2_xattr_unregister(int, struct ext2_xattr_handler *);
4353 +extern int ext2_setxattr(struct dentry *, const char *, const void *, size_t, int);
4354 +extern ssize_t ext2_getxattr(struct dentry *, const char *, void *, size_t);
4355 +extern ssize_t ext2_listxattr(struct dentry *, char *, size_t);
4356 +extern int ext2_removexattr(struct dentry *, const char *);
4358 +extern int ext2_xattr_get(struct inode *, int, const char *, void *, size_t);
4359 +extern int ext2_xattr_list(struct inode *, char *, size_t);
4360 +extern int ext2_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
4362 +extern void ext2_xattr_delete_inode(struct inode *);
4363 +extern void ext2_xattr_put_super(struct super_block *);
4365 +extern int init_ext2_xattr(void) __init;
4366 +extern void exit_ext2_xattr(void);
4368 +# else /* CONFIG_EXT2_FS_XATTR */
4369 +# define ext2_setxattr NULL
4370 +# define ext2_getxattr NULL
4371 +# define ext2_listxattr NULL
4372 +# define ext2_removexattr NULL
4375 +ext2_xattr_get(struct inode *inode, int name_index,
4376 + const char *name, void *buffer, size_t size)
4382 +ext2_xattr_list(struct inode *inode, char *buffer, size_t size)
4388 +ext2_xattr_set(struct inode *inode, int name_index, const char *name,
4389 + const void *value, size_t size, int flags)
4395 +ext2_xattr_delete_inode(struct inode *inode)
4400 +ext2_xattr_put_super(struct super_block *sb)
4405 +init_ext2_xattr(void)
4411 +exit_ext2_xattr(void)
4415 +# endif /* CONFIG_EXT2_FS_XATTR */
4417 +# ifdef CONFIG_EXT2_FS_XATTR_USER
4419 +extern int init_ext2_xattr_user(void) __init;
4420 +extern void exit_ext2_xattr_user(void);
4422 +# else /* CONFIG_EXT2_FS_XATTR_USER */
4425 +init_ext2_xattr_user(void)
4431 +exit_ext2_xattr_user(void)
4435 +# endif /* CONFIG_EXT2_FS_XATTR_USER */
4437 +#endif /* __KERNEL__ */
4439 --- linux/include/linux/ext3_fs.h~linux-2.4.20-xattr-0.8.54-hp Fri May 16 08:42:47 2003
4440 +++ linux-mmonroe/include/linux/ext3_fs.h Fri May 16 08:43:01 2003
4443 #define EXT3_BAD_INO 1 /* Bad blocks inode */
4444 #define EXT3_ROOT_INO 2 /* Root inode */
4445 -#define EXT3_ACL_IDX_INO 3 /* ACL inode */
4446 -#define EXT3_ACL_DATA_INO 4 /* ACL inode */
4447 #define EXT3_BOOT_LOADER_INO 5 /* Boot loader inode */
4448 #define EXT3_UNDEL_DIR_INO 6 /* Undelete directory inode */
4449 #define EXT3_RESIZE_INO 7 /* Reserved group descriptors inode */
4452 # define EXT3_BLOCK_SIZE(s) (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
4454 -#define EXT3_ACLE_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_acl_entry))
4455 #define EXT3_ADDR_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (__u32))
4457 # define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
4458 @@ -129,28 +126,6 @@
4464 -struct ext3_acl_header /* Header of Access Control Lists */
4467 - __u32 aclh_file_count;
4468 - __u32 aclh_acle_count;
4469 - __u32 aclh_first_acle;
4472 -struct ext3_acl_entry /* Access Control List Entry */
4475 - __u16 acle_perms; /* Access permissions */
4476 - __u16 acle_type; /* Type of entry */
4477 - __u16 acle_tag; /* User or group identity */
4479 - __u32 acle_next; /* Pointer on next entry for the */
4480 - /* same inode or on next free entry */
4484 * Structure of a blocks group descriptor
4486 struct ext3_group_desc
4487 @@ -344,6 +319,7 @@ struct ext3_inode {
4488 #define EXT3_MOUNT_WRITEBACK_DATA 0x0C00 /* No data ordering */
4489 #define EXT3_MOUNT_UPDATE_JOURNAL 0x1000 /* Update the journal format */
4490 #define EXT3_MOUNT_NO_UID32 0x2000 /* Disable 32-bit UIDs */
4491 +#define EXT3_MOUNT_XATTR_USER 0x4000 /* Extended user attributes */
4493 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
4494 #ifndef _LINUX_EXT2_FS_H
4495 @@ -520,7 +496,7 @@ struct ext3_super_block {
4496 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
4497 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
4499 -#define EXT3_FEATURE_COMPAT_SUPP 0
4500 +#define EXT3_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
4501 #define EXT3_FEATURE_INCOMPAT_SUPP (EXT3_FEATURE_INCOMPAT_FILETYPE| \
4502 EXT3_FEATURE_INCOMPAT_RECOVER)
4503 #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
4504 @@ -703,6 +679,7 @@ extern void ext3_check_inodes_bitmap (st
4505 extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
4508 +extern int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
4509 extern struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
4510 extern struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
4512 @@ -771,8 +748,10 @@ extern struct address_space_operations e
4515 extern struct inode_operations ext3_dir_inode_operations;
4516 +extern struct inode_operations ext3_special_inode_operations;
4519 +extern struct inode_operations ext3_symlink_inode_operations;
4520 extern struct inode_operations ext3_fast_symlink_inode_operations;
4523 --- linux/include/linux/ext3_jbd.h~linux-2.4.20-xattr-0.8.54-hp Fri May 16 08:42:46 2003
4524 +++ linux-mmonroe/include/linux/ext3_jbd.h Fri May 16 08:43:01 2003
4527 #define EXT3_SINGLEDATA_TRANS_BLOCKS 8
4529 +/* Extended attributes may touch two data buffers, two bitmap buffers,
4530 + * and two group and summaries. */
4532 +#define EXT3_XATTR_TRANS_BLOCKS 8
4534 /* Define the minimum size for a transaction which modifies data. This
4535 * needs to take into account the fact that we may end up modifying two
4536 * quota files too (one for the group, one for the user quota). The
4537 * superblock only gets updated once, of course, so don't bother
4538 * counting that again for the quota updates. */
4540 -#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS - 2)
4541 +#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS + \
4542 + EXT3_XATTR_TRANS_BLOCKS - 2)
4544 extern int ext3_writepage_trans_blocks(struct inode *inode);
4546 --- /dev/null Mon May 20 21:11:23 2002
4547 +++ linux-mmonroe/include/linux/ext3_xattr.h Fri May 16 08:43:01 2003
4550 + File: linux/ext3_xattr.h
4552 + On-disk format of extended attributes for the ext3 filesystem.
4554 + (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
4557 +#include <linux/config.h>
4558 +#include <linux/init.h>
4559 +#include <linux/xattr.h>
4561 +/* Magic value in attribute blocks */
4562 +#define EXT3_XATTR_MAGIC 0xEA020000
4564 +/* Maximum number of references to one attribute block */
4565 +#define EXT3_XATTR_REFCOUNT_MAX 1024
4568 +#define EXT3_XATTR_INDEX_MAX 10
4569 +#define EXT3_XATTR_INDEX_USER 1
4570 +#define EXT3_XATTR_INDEX_POSIX_ACL_ACCESS 2
4571 +#define EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT 3
4573 +struct ext3_xattr_header {
4574 + __u32 h_magic; /* magic number for identification */
4575 + __u32 h_refcount; /* reference count */
4576 + __u32 h_blocks; /* number of disk blocks used */
4577 + __u32 h_hash; /* hash value of all attributes */
4578 + __u32 h_reserved[4]; /* zero right now */
4581 +struct ext3_xattr_entry {
4582 + __u8 e_name_len; /* length of name */
4583 + __u8 e_name_index; /* attribute name index */
4584 + __u16 e_value_offs; /* offset in disk block of value */
4585 + __u32 e_value_block; /* disk block attribute is stored on (n/i) */
4586 + __u32 e_value_size; /* size of attribute value */
4587 + __u32 e_hash; /* hash value of name and value */
4588 + char e_name[0]; /* attribute name */
4591 +#define EXT3_XATTR_PAD_BITS 2
4592 +#define EXT3_XATTR_PAD (1<<EXT3_XATTR_PAD_BITS)
4593 +#define EXT3_XATTR_ROUND (EXT3_XATTR_PAD-1)
4594 +#define EXT3_XATTR_LEN(name_len) \
4595 + (((name_len) + EXT3_XATTR_ROUND + \
4596 + sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND)
4597 +#define EXT3_XATTR_NEXT(entry) \
4598 + ( (struct ext3_xattr_entry *)( \
4599 + (char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) )
4600 +#define EXT3_XATTR_SIZE(size) \
4601 + (((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND)
4605 +# ifdef CONFIG_EXT3_FS_XATTR
4607 +struct ext3_xattr_handler {
4609 + size_t (*list)(char *list, struct inode *inode, const char *name,
4611 + int (*get)(struct inode *inode, const char *name, void *buffer,
4613 + int (*set)(struct inode *inode, const char *name, const void *buffer,
4614 + size_t size, int flags);
4617 +extern int ext3_xattr_register(int, struct ext3_xattr_handler *);
4618 +extern void ext3_xattr_unregister(int, struct ext3_xattr_handler *);
4620 +extern int ext3_setxattr(struct dentry *, const char *, const void *, size_t, int);
4621 +extern ssize_t ext3_getxattr(struct dentry *, const char *, void *, size_t);
4622 +extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
4623 +extern int ext3_removexattr(struct dentry *, const char *);
4625 +extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
4626 +extern int ext3_xattr_list(struct inode *, char *, size_t);
4627 +extern int ext3_xattr_set(handle_t *handle, struct inode *, int, const char *, const void *, size_t, int);
4629 +extern void ext3_xattr_delete_inode(handle_t *, struct inode *);
4630 +extern void ext3_xattr_put_super(struct super_block *);
4632 +extern int init_ext3_xattr(void) __init;
4633 +extern void exit_ext3_xattr(void);
4635 +# else /* CONFIG_EXT3_FS_XATTR */
4636 +# define ext3_setxattr NULL
4637 +# define ext3_getxattr NULL
4638 +# define ext3_listxattr NULL
4639 +# define ext3_removexattr NULL
4642 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
4643 + void *buffer, size_t size)
4649 +ext3_xattr_list(struct inode *inode, void *buffer, size_t size)
4655 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
4656 + const char *name, const void *value, size_t size, int flags)
4662 +ext3_xattr_delete_inode(handle_t *handle, struct inode *inode)
4667 +ext3_xattr_put_super(struct super_block *sb)
4672 +init_ext3_xattr(void)
4678 +exit_ext3_xattr(void)
4682 +# endif /* CONFIG_EXT3_FS_XATTR */
4684 +# ifdef CONFIG_EXT3_FS_XATTR_USER
4686 +extern int init_ext3_xattr_user(void) __init;
4687 +extern void exit_ext3_xattr_user(void);
4689 +# else /* CONFIG_EXT3_FS_XATTR_USER */
4692 +init_ext3_xattr_user(void)
4698 +exit_ext3_xattr_user(void)
4702 +#endif /* CONFIG_EXT3_FS_XATTR_USER */
4704 +#endif /* __KERNEL__ */
4706 --- linux/include/linux/fs.h~linux-2.4.20-xattr-0.8.54-hp Fri May 16 08:42:46 2003
4707 +++ linux-mmonroe/include/linux/fs.h Fri May 16 08:43:01 2003
4708 @@ -909,7 +909,7 @@ struct inode_operations {
4709 int (*setattr) (struct dentry *, struct iattr *);
4710 int (*setattr_raw) (struct inode *, struct iattr *);
4711 int (*getattr) (struct dentry *, struct iattr *);
4712 - int (*setxattr) (struct dentry *, const char *, void *, size_t, int);
4713 + int (*setxattr) (struct dentry *, const char *, const void *, size_t, int);
4714 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
4715 ssize_t (*listxattr) (struct dentry *, char *, size_t);
4716 int (*removexattr) (struct dentry *, const char *);
4717 --- /dev/null Mon May 20 21:11:23 2002
4718 +++ linux-mmonroe/include/linux/mbcache.h Fri May 16 08:43:01 2003
4721 + File: linux/mbcache.h
4723 + (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
4726 +/* Hardwire the number of additional indexes */
4727 +#define MB_CACHE_INDEXES_COUNT 1
4729 +struct mb_cache_entry;
4731 +struct mb_cache_op {
4732 + int (*free)(struct mb_cache_entry *, int);
4736 + struct list_head c_cache_list;
4737 + const char *c_name;
4738 + struct mb_cache_op c_op;
4739 + atomic_t c_entry_count;
4740 + int c_bucket_count;
4741 +#ifndef MB_CACHE_INDEXES_COUNT
4742 + int c_indexes_count;
4744 + kmem_cache_t *c_entry_cache;
4745 + struct list_head *c_block_hash;
4746 + struct list_head *c_indexes_hash[0];
4749 +struct mb_cache_entry_index {
4750 + struct list_head o_list;
4751 + unsigned int o_key;
4754 +struct mb_cache_entry {
4755 + struct list_head e_lru_list;
4756 + struct mb_cache *e_cache;
4759 + unsigned long e_block;
4760 + struct list_head e_block_list;
4761 + struct mb_cache_entry_index e_indexes[0];
4764 +/* Functions on caches */
4766 +struct mb_cache * mb_cache_create(const char *, struct mb_cache_op *, size_t,
4768 +void mb_cache_shrink(struct mb_cache *, kdev_t);
4769 +void mb_cache_destroy(struct mb_cache *);
4771 +/* Functions on cache entries */
4773 +struct mb_cache_entry *mb_cache_entry_alloc(struct mb_cache *);
4774 +int mb_cache_entry_insert(struct mb_cache_entry *, kdev_t, unsigned long,
4776 +void mb_cache_entry_rehash(struct mb_cache_entry *, unsigned int[]);
4777 +void mb_cache_entry_release(struct mb_cache_entry *);
4778 +void mb_cache_entry_takeout(struct mb_cache_entry *);
4779 +void mb_cache_entry_free(struct mb_cache_entry *);
4780 +struct mb_cache_entry *mb_cache_entry_dup(struct mb_cache_entry *);
4781 +struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *, kdev_t,
4783 +#if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
4784 +struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache, int,
4785 + kdev_t, unsigned int);
4786 +struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache_entry *, int,
4787 + kdev_t, unsigned int);
4789 --- linux/kernel/ksyms.c~linux-2.4.20-xattr-0.8.54-hp Fri May 16 08:42:45 2003
4790 +++ linux-mmonroe/kernel/ksyms.c Fri May 16 08:43:52 2003
4793 #include <linux/config.h>
4794 #include <linux/slab.h>
4795 +#include <linux/cache_def.h>
4796 #include <linux/module.h>
4797 #include <linux/blkdev.h>
4798 #include <linux/cdrom.h>
4799 @@ -106,6 +107,7 @@ EXPORT_SYMBOL(exit_mm);
4800 EXPORT_SYMBOL(exit_files);
4801 EXPORT_SYMBOL(exit_fs);
4802 EXPORT_SYMBOL(exit_sighand);
4803 +EXPORT_SYMBOL(copy_fs_struct);
4804 EXPORT_SYMBOL_GPL(make_pages_present);
4806 /* internal kernel memory management */
4807 @@ -126,6 +128,8 @@ EXPORT_SYMBOL(kmem_cache_validate);
4808 EXPORT_SYMBOL(kmem_cache_alloc);
4809 EXPORT_SYMBOL(kmem_cache_free);
4810 EXPORT_SYMBOL(kmem_cache_size);
4811 +EXPORT_SYMBOL(register_cache);
4812 +EXPORT_SYMBOL(unregister_cache);
4813 EXPORT_SYMBOL(kmalloc);
4814 EXPORT_SYMBOL(kfree);
4815 EXPORT_SYMBOL(vfree);
4816 --- linux/mm/vmscan.c~linux-2.4.20-xattr-0.8.54-hp Fri May 16 08:39:23 2003
4817 +++ linux-mmonroe/mm/vmscan.c Fri May 16 08:43:01 2003
4819 #include <linux/kernel_stat.h>
4820 #include <linux/swap.h>
4821 #include <linux/swapctl.h>
4822 +#include <linux/cache_def.h>
4823 #include <linux/smp_lock.h>
4824 #include <linux/pagemap.h>
4825 #include <linux/init.h>
4828 #define DEF_PRIORITY (6)
4830 +static DECLARE_MUTEX(other_caches_sem);
4831 +static LIST_HEAD(cache_definitions);
4833 +void register_cache(struct cache_definition *cache)
4835 + down(&other_caches_sem);
4836 + list_add(&cache->link, &cache_definitions);
4837 + up(&other_caches_sem);
4840 +void unregister_cache(struct cache_definition *cache)
4842 + down(&other_caches_sem);
4843 + list_del(&cache->link);
4844 + up(&other_caches_sem);
4847 +static void shrink_other_caches(unsigned int priority, int gfp_mask)
4849 + struct list_head *p;
4851 + if (down_trylock(&other_caches_sem))
4854 + list_for_each_prev(p, &cache_definitions) {
4855 + struct cache_definition *cache =
4856 + list_entry(p, struct cache_definition, link);
4858 + cache->shrink(priority, gfp_mask);
4860 + up(&other_caches_sem);
4864 * The swap-out function returns 1 if it successfully
4865 * scanned all the pages it was asked to (`count').
4866 @@ -579,6 +613,7 @@ static int shrink_caches(zone_t * classz
4868 shrink_dcache_memory(priority, gfp_mask);
4869 shrink_icache_memory(priority, gfp_mask);
4870 + shrink_other_caches(priority, gfp_mask);
4872 shrink_dqcache_memory(DEF_PRIORITY, gfp_mask);