1 Linux Extended Attributes -- Kernel Patch
2 24 April 2002, 11:31:18
5 This patch is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This patch is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this patch; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 After extracting the linux-2.4.18.tar.gz package, apply this patch as follows:
23 patch -p1 < ../linux-2.4.18ea-0.8.26.patch
25 diff -Nur linux-2.4.18/fs/ext3/file.c linux-2.4.18ea/fs/ext3/file.c
26 --- linux-2.4.18/fs/ext3/file.c Thu Nov 15 22:37:55 2001
27 +++ linux-2.4.18ea/fs/ext3/file.c Sun Feb 24 04:34:43 2002
29 #include <linux/locks.h>
30 #include <linux/jbd.h>
31 #include <linux/ext3_fs.h>
32 +#include <linux/ext3_xattr.h>
33 #include <linux/ext3_jbd.h>
34 #include <linux/smp_lock.h>
37 struct inode_operations ext3_file_inode_operations = {
38 truncate: ext3_truncate, /* BKL held */
39 setattr: ext3_setattr, /* BKL held */
40 + setxattr: ext3_setxattr, /* BKL held */
41 + getxattr: ext3_getxattr, /* BKL held */
42 + listxattr: ext3_listxattr, /* BKL held */
43 + removexattr: ext3_removexattr, /* BKL held */
46 diff -Nur linux-2.4.18/fs/ext3/ialloc.c linux-2.4.18ea/fs/ext3/ialloc.c
47 --- linux-2.4.18/fs/ext3/ialloc.c Sun Feb 24 04:42:59 2002
48 +++ linux-2.4.18ea/fs/ext3/ialloc.c Sun Feb 24 04:34:43 2002
50 #include <linux/jbd.h>
51 #include <linux/ext3_fs.h>
52 #include <linux/ext3_jbd.h>
53 +#include <linux/ext3_xattr.h>
54 #include <linux/stat.h>
55 #include <linux/string.h>
56 #include <linux/locks.h>
58 * as writing the quota to disk may need the lock as well.
61 + ext3_xattr_drop_inode(handle, inode);
62 DQUOT_FREE_INODE(inode);
65 diff -Nur linux-2.4.18/fs/ext3/inode.c linux-2.4.18ea/fs/ext3/inode.c
66 --- linux-2.4.18/fs/ext3/inode.c Sun Feb 24 04:42:59 2002
67 +++ linux-2.4.18ea/fs/ext3/inode.c Thu Mar 14 21:51:59 2002
70 #undef SEARCH_FROM_ZERO
73 + * Test whether an inode is a fast symlink.
75 +static inline int ext3_inode_is_fast_symlink(struct inode *inode)
77 + int ea_blocks = EXT3_I(inode)->i_file_acl ?
78 + (inode->i_sb->s_blocksize >> 9) : 0;
80 + return (S_ISLNK(inode->i_mode) &&
81 + inode->i_blocks - ea_blocks == 0);
84 /* The ext3 forget function must perform a revoke if we are freeing data
85 * which has been journaled. Metadata (eg. indirect blocks) must be
86 * revoked in all cases.
88 * still needs to be revoked.
91 -static int ext3_forget(handle_t *handle, int is_metadata,
92 +int ext3_forget(handle_t *handle, int is_metadata,
93 struct inode *inode, struct buffer_head *bh,
100 - if (is_bad_inode(inode) ||
101 - inode->i_ino == EXT3_ACL_IDX_INO ||
102 - inode->i_ino == EXT3_ACL_DATA_INO)
103 + if (is_bad_inode(inode))
107 @@ -1845,6 +1855,8 @@
108 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
109 S_ISLNK(inode->i_mode)))
111 + if (ext3_inode_is_fast_symlink(inode))
113 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
116 @@ -1992,8 +2004,6 @@
117 struct ext3_group_desc * gdp;
119 if ((inode->i_ino != EXT3_ROOT_INO &&
120 - inode->i_ino != EXT3_ACL_IDX_INO &&
121 - inode->i_ino != EXT3_ACL_DATA_INO &&
122 inode->i_ino != EXT3_JOURNAL_INO &&
123 inode->i_ino < EXT3_FIRST_INO(inode->i_sb)) ||
124 inode->i_ino > le32_to_cpu(
125 @@ -2120,10 +2130,7 @@
129 - if (inode->i_ino == EXT3_ACL_IDX_INO ||
130 - inode->i_ino == EXT3_ACL_DATA_INO)
131 - /* Nothing to do */ ;
132 - else if (S_ISREG(inode->i_mode)) {
133 + if (S_ISREG(inode->i_mode)) {
134 inode->i_op = &ext3_file_inode_operations;
135 inode->i_fop = &ext3_file_operations;
136 inode->i_mapping->a_ops = &ext3_aops;
137 @@ -2131,13 +2138,15 @@
138 inode->i_op = &ext3_dir_inode_operations;
139 inode->i_fop = &ext3_dir_operations;
140 } else if (S_ISLNK(inode->i_mode)) {
141 - if (!inode->i_blocks)
142 + if (ext3_inode_is_fast_symlink(inode))
143 inode->i_op = &ext3_fast_symlink_inode_operations;
145 - inode->i_op = &page_symlink_inode_operations;
146 + inode->i_op = &ext3_symlink_inode_operations;
147 inode->i_mapping->a_ops = &ext3_aops;
151 + inode->i_op = &ext3_special_inode_operations;
152 init_special_inode(inode, inode->i_mode,
153 le32_to_cpu(iloc.raw_inode->i_block[0]));
155 /* inode->i_attr_flags = 0; unused */
156 diff -Nur linux-2.4.18/fs/ext3/namei.c linux-2.4.18ea/fs/ext3/namei.c
157 --- linux-2.4.18/fs/ext3/namei.c Fri Nov 9 23:25:04 2001
158 +++ linux-2.4.18ea/fs/ext3/namei.c Mon Mar 11 03:27:00 2002
160 #include <linux/sched.h>
161 #include <linux/ext3_fs.h>
162 #include <linux/ext3_jbd.h>
163 +#include <linux/ext3_xattr.h>
164 #include <linux/fcntl.h>
165 #include <linux/stat.h>
166 #include <linux/string.h>
168 inode->i_mapping->a_ops = &ext3_aops;
169 ext3_mark_inode_dirty(handle, inode);
170 err = ext3_add_nondir(handle, dentry, inode);
172 + ext3_xattr_drop_inode(handle, inode);
174 ext3_journal_stop(handle, dir);
177 init_special_inode(inode, mode, rdev);
178 ext3_mark_inode_dirty(handle, inode);
179 err = ext3_add_nondir(handle, dentry, inode);
181 + ext3_xattr_drop_inode(handle, inode);
183 ext3_journal_stop(handle, dir);
189 - inode = ext3_new_inode (handle, dir, S_IFDIR);
190 + inode = ext3_new_inode (handle, dir, S_IFDIR | mode);
191 err = PTR_ERR(inode);
195 inode->i_op = &ext3_dir_inode_operations;
196 inode->i_fop = &ext3_dir_operations;
197 - inode->i_size = inode->u.ext3_i.i_disksize = inode->i_sb->s_blocksize;
198 - inode->i_blocks = 0;
199 + inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
200 dir_block = ext3_bread (handle, inode, 0, 1, &err);
202 inode->i_nlink--; /* is this nlink == 0? */
204 BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata");
205 ext3_journal_dirty_metadata(handle, dir_block);
207 - inode->i_mode = S_IFDIR | mode;
208 - if (dir->i_mode & S_ISGID)
209 - inode->i_mode |= S_ISGID;
210 ext3_mark_inode_dirty(handle, inode);
211 err = ext3_add_entry (handle, dentry, inode);
217 + ext3_xattr_drop_inode(handle, inode);
219 ext3_mark_inode_dirty(handle, inode);
224 - if (l > sizeof (inode->u.ext3_i.i_data)) {
225 - inode->i_op = &page_symlink_inode_operations;
226 + if (l > sizeof(EXT3_I(inode)->i_data)) {
227 + inode->i_op = &ext3_symlink_inode_operations;
228 inode->i_mapping->a_ops = &ext3_aops;
230 * block_symlink() calls back into ext3_prepare/commit_write.
231 @@ -1122,4 +1124,16 @@
232 rmdir: ext3_rmdir, /* BKL held */
233 mknod: ext3_mknod, /* BKL held */
234 rename: ext3_rename, /* BKL held */
235 + setxattr: ext3_setxattr, /* BKL held */
236 + getxattr: ext3_getxattr, /* BKL held */
237 + listxattr: ext3_listxattr, /* BKL held */
238 + removexattr: ext3_removexattr, /* BKL held */
241 +struct inode_operations ext3_special_inode_operations = {
242 + setxattr: ext3_setxattr, /* BKL held */
243 + getxattr: ext3_getxattr, /* BKL held */
244 + listxattr: ext3_listxattr, /* BKL held */
245 + removexattr: ext3_removexattr, /* BKL held */
248 diff -Nur linux-2.4.18/fs/ext3/super.c linux-2.4.18ea/fs/ext3/super.c
249 --- linux-2.4.18/fs/ext3/super.c Sun Feb 24 04:42:59 2002
250 +++ linux-2.4.18ea/fs/ext3/super.c Thu Apr 4 21:41:05 2002
252 #include <linux/jbd.h>
253 #include <linux/ext3_fs.h>
254 #include <linux/ext3_jbd.h>
255 +#include <linux/ext3_xattr.h>
256 #include <linux/slab.h>
257 #include <linux/init.h>
258 #include <linux/locks.h>
260 kdev_t j_dev = sbi->s_journal->j_dev;
263 + ext3_xattr_put_super(sb);
264 journal_destroy(sbi->s_journal);
265 if (!(sb->s_flags & MS_RDONLY)) {
266 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
267 @@ -1734,14 +1772,25 @@
269 static DECLARE_FSTYPE_DEV(ext3_fs_type, "ext3", ext3_read_super);
271 -static int __init init_ext3_fs(void)
272 +static void exit_ext3_fs(void)
274 - return register_filesystem(&ext3_fs_type);
275 + unregister_filesystem(&ext3_fs_type);
276 + exit_ext3_xattr_user();
280 -static void __exit exit_ext3_fs(void)
281 +static int __init init_ext3_fs(void)
283 - unregister_filesystem(&ext3_fs_type);
284 + int error = init_ext3_xattr();
286 + error = init_ext3_xattr_user();
288 + error = register_filesystem(&ext3_fs_type);
297 diff -Nur linux-2.4.18/fs/ext3/symlink.c linux-2.4.18ea/fs/ext3/symlink.c
298 --- linux-2.4.18/fs/ext3/symlink.c Fri Nov 9 23:25:04 2001
299 +++ linux-2.4.18ea/fs/ext3/symlink.c Mon Mar 11 03:27:00 2002
301 #include <linux/fs.h>
302 #include <linux/jbd.h>
303 #include <linux/ext3_fs.h>
304 +#include <linux/ext3_xattr.h>
306 static int ext3_readlink(struct dentry *dentry, char *buffer, int buflen)
309 return vfs_follow_link(nd, s);
312 +struct inode_operations ext3_symlink_inode_operations = {
313 + readlink: page_readlink, /* BKL not held. Don't need */
314 + follow_link: page_follow_link, /* BKL not held. Don't need */
315 + setxattr: ext3_setxattr, /* BKL held */
316 + getxattr: ext3_getxattr, /* BKL held */
317 + listxattr: ext3_listxattr, /* BKL held */
318 + removexattr: ext3_removexattr, /* BKL held */
321 struct inode_operations ext3_fast_symlink_inode_operations = {
322 readlink: ext3_readlink, /* BKL not held. Don't need */
323 follow_link: ext3_follow_link, /* BKL not held. Don't need */
324 + setxattr: ext3_setxattr, /* BKL held */
325 + getxattr: ext3_getxattr, /* BKL held */
326 + listxattr: ext3_listxattr, /* BKL held */
327 + removexattr: ext3_removexattr, /* BKL held */
329 diff -Nur linux-2.4.18/fs/ext3/xattr.c linux-2.4.18ea/fs/ext3/xattr.c
330 --- linux-2.4.18/fs/ext3/xattr.c Thu Jan 1 01:00:00 1970
331 +++ linux-2.4.18ea/fs/ext3/xattr.c Wed Apr 3 13:19:05 2002
334 + * linux/fs/ext3/xattr.c
336 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
338 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
339 + * Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>.
340 + * Extended attributes for symlinks and special files added per
341 + * suggestion of Luka Renko <luka.renko@hermes.si>.
345 + * Extended attributes are stored on disk blocks allocated outside of
346 + * any inode. The i_file_acl field is then made to point to this allocated
347 + * block. If all extended attributes of an inode are identical, these
348 + * inodes may share the same extended attribute block. Such situations
349 + * are automatically detected by keeping a cache of recent attribute block
350 + * numbers and hashes over the block's contents in memory.
353 + * Extended attribute block layout:
355 + * +------------------+
358 + * | entry 2 | | growing downwards
360 + * | four null bytes |
363 + * | value 3 | | growing upwards
365 + * +------------------+
367 + * The block header is followed by multiple entry descriptors. These entry
368 + * descriptors are variable in size, and alligned to EXT3_XATTR_PAD
369 + * byte boundaries. The entry descriptors are sorted by attribute name,
370 + * so that two extended attribute blocks can be compared efficiently.
372 + * Attribute values are aligned to the end of the block, stored in
373 + * no specific order. They are also padded to EXT3_XATTR_PAD byte
374 + * boundaries. No additional gaps are left between them.
378 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
379 + * the xattr inode operations are called, so we are guaranteed that only one
380 + * processes accesses extended attributes of an inode at any time.
382 + * For writing we also grab the ext3_xattr_sem semaphore. This ensures that
383 + * only a single process is modifying an extended attribute block, even
384 + * if the block is shared among inodes.
386 + * Note for porting to 2.5
387 + * -----------------------
388 + * The BKL will no longer be held in the xattr inode operations.
391 +#include <linux/fs.h>
392 +#include <linux/locks.h>
393 +#include <linux/slab.h>
394 +#include <linux/ext3_jbd.h>
395 +#include <linux/ext3_fs.h>
396 +#include <linux/ext3_xattr.h>
397 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
398 +#include <linux/mbcache.h>
400 +#include <linux/quotaops.h>
401 +#include <asm/semaphore.h>
402 +#include <linux/compatmac.h>
404 +#define EXT3_EA_USER "user."
406 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
407 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
410 +#define HDR(bh) ((struct ext3_xattr_header *)((bh)->b_data))
411 +#define ENTRY(ptr) ((struct ext3_xattr_entry *)(ptr))
412 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
413 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
415 +#ifdef EXT3_XATTR_DEBUG
416 +# define ea_idebug(inode, f...) do { \
417 + printk(KERN_DEBUG "inode %s:%ld: ", \
418 + kdevname(inode->i_dev), inode->i_ino); \
422 +# define ea_bdebug(bh, f...) do { \
423 + printk(KERN_DEBUG "block %s:%ld: ", \
424 + kdevname(bh->b_dev), bh->b_blocknr); \
429 +# define ea_idebug(f...)
430 +# define ea_bdebug(f...)
433 +static int ext3_xattr_set2(handle_t *, struct inode *, struct buffer_head *,
434 + struct ext3_xattr_header *);
436 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
438 +static int ext3_xattr_cache_insert(struct buffer_head *);
439 +static struct buffer_head *ext3_xattr_cache_find(struct inode *,
440 + struct ext3_xattr_header *);
441 +static void ext3_xattr_cache_remove(struct buffer_head *);
442 +static void ext3_xattr_rehash(struct ext3_xattr_header *,
443 + struct ext3_xattr_entry *);
445 +static struct mb_cache *ext3_xattr_cache;
448 +# define ext3_xattr_cache_insert(bh) 0
449 +# define ext3_xattr_cache_find(inode, header) NULL
450 +# define ext3_xattr_cache_remove(bh) do {} while(0)
451 +# define ext3_xattr_rehash(header, entry) do {} while(0)
455 + * If a file system does not share extended attributes among inodes,
456 + * we should not need the ext3_xattr_sem semaphore. However, the
457 + * filesystem may still contain shared blocks, so we always take
461 +DECLARE_MUTEX(ext3_xattr_sem);
464 +ext3_xattr_lock(void)
466 + down(&ext3_xattr_sem);
470 +ext3_xattr_unlock(void)
472 + up(&ext3_xattr_sem);
476 +ext3_xattr_new_block(handle_t *handle, struct inode *inode,
477 + int * errp, int force)
479 + struct super_block *sb = inode->i_sb;
480 + int goal = le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block) +
481 + EXT3_I(inode)->i_block_group * EXT3_BLOCKS_PER_GROUP(sb);
483 + /* How can we enforce the allocation? */
484 + int block = ext3_new_block(handle, inode, goal, 0, 0, errp);
487 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
493 +ext3_xattr_quota_alloc(struct inode *inode, int force)
495 + /* How can we enforce the allocation? */
497 + int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
499 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
501 + int error = DQUOT_ALLOC_BLOCK(inode, 1);
509 +ext3_xattr_quota_free(struct inode *inode)
511 + DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
512 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
516 +ext3_xattr_free_block(handle_t *handle, struct inode * inode,
517 + unsigned long block)
519 + ext3_free_blocks(handle, inode, block, 1);
520 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
524 +# define ext3_xattr_quota_free(inode) \
525 + DQUOT_FREE_BLOCK(inode, 1)
526 +# define ext3_xattr_free_block(handle, inode, block) \
527 + ext3_free_blocks(handle, inode, block, 1)
530 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
532 +static inline struct buffer_head *
533 +sb_bread(struct super_block *sb, int block)
535 + return bread(sb->s_dev, block, sb->s_blocksize);
538 +static inline struct buffer_head *
539 +sb_getblk(struct super_block *sb, int block)
541 + return getblk(sb->s_dev, block, sb->s_blocksize);
546 +struct ext3_xattr_handler *ext3_xattr_handlers[EXT3_XATTR_INDEX_MAX];
547 +rwlock_t ext3_handler_lock = RW_LOCK_UNLOCKED;
550 +ext3_xattr_register(int name_index, struct ext3_xattr_handler *handler)
552 + int error = -EINVAL;
554 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
555 + write_lock(&ext3_handler_lock);
556 + if (!ext3_xattr_handlers[name_index-1]) {
557 + ext3_xattr_handlers[name_index-1] = handler;
560 + write_unlock(&ext3_handler_lock);
566 +ext3_xattr_unregister(int name_index, struct ext3_xattr_handler *handler)
568 + if (name_index > 0 || name_index <= EXT3_XATTR_INDEX_MAX) {
569 + write_lock(&ext3_handler_lock);
570 + ext3_xattr_handlers[name_index-1] = NULL;
571 + write_unlock(&ext3_handler_lock);
575 +static inline const char *
576 +strcmp_prefix(const char *a, const char *a_prefix)
578 + while (*a_prefix && *a == *a_prefix) {
582 + return *a_prefix ? NULL : a;
586 + * Decode the extended attribute name, and translate it into
587 + * the name_index and name suffix.
589 +static inline struct ext3_xattr_handler *
590 +ext3_xattr_resolve_name(const char **name)
592 + struct ext3_xattr_handler *handler = NULL;
597 + read_lock(&ext3_handler_lock);
598 + for (i=0; i<EXT3_XATTR_INDEX_MAX; i++) {
599 + if (ext3_xattr_handlers[i]) {
600 + const char *n = strcmp_prefix(*name,
601 + ext3_xattr_handlers[i]->prefix);
603 + handler = ext3_xattr_handlers[i];
609 + read_unlock(&ext3_handler_lock);
613 +static inline struct ext3_xattr_handler *
614 +ext3_xattr_handler(int name_index)
616 + struct ext3_xattr_handler *handler = NULL;
617 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
618 + read_lock(&ext3_handler_lock);
619 + handler = ext3_xattr_handlers[name_index-1];
620 + read_unlock(&ext3_handler_lock);
626 + * Inode operation getxattr()
628 + * dentry->d_inode->i_sem down
629 + * BKL held [before 2.5.x]
632 +ext3_getxattr(struct dentry *dentry, const char *name,
633 + void *buffer, size_t size)
635 + struct ext3_xattr_handler *handler;
636 + struct inode *inode = dentry->d_inode;
638 + handler = ext3_xattr_resolve_name(&name);
641 + return handler->get(inode, name, buffer, size);
645 + * Inode operation listxattr()
647 + * dentry->d_inode->i_sem down
648 + * BKL held [before 2.5.x]
651 +ext3_listxattr(struct dentry *dentry, char *buffer, size_t size)
653 + return ext3_xattr_list(dentry->d_inode, buffer, size);
657 + * Inode operation setxattr()
659 + * dentry->d_inode->i_sem down
660 + * BKL held [before 2.5.x]
663 +ext3_setxattr(struct dentry *dentry, const char *name,
664 + void *value, size_t size, int flags)
666 + struct ext3_xattr_handler *handler;
667 + struct inode *inode = dentry->d_inode;
670 + value = ""; /* empty EA, do not remove */
671 + handler = ext3_xattr_resolve_name(&name);
674 + return handler->set(inode, name, value, size, flags);
678 + * Inode operation removexattr()
680 + * dentry->d_inode->i_sem down
681 + * BKL held [before 2.5.x]
684 +ext3_removexattr(struct dentry *dentry, const char *name)
686 + struct ext3_xattr_handler *handler;
687 + struct inode *inode = dentry->d_inode;
689 + handler = ext3_xattr_resolve_name(&name);
692 + return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
698 + * Copy an extended attribute into the buffer
699 + * provided, or compute the buffer size required.
700 + * Buffer is NULL to compute the size of the buffer required.
702 + * Returns a negative error number on failure, or the number of bytes
703 + * used / required on success.
706 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
707 + void *buffer, size_t buffer_size)
709 + struct buffer_head *bh = NULL;
710 + struct ext3_xattr_entry *entry;
711 + unsigned int block, size;
713 + int name_len, error;
715 + ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
716 + name_index, name, buffer, (long)buffer_size);
720 + if (!EXT3_I(inode)->i_file_acl)
722 + block = EXT3_I(inode)->i_file_acl;
723 + ea_idebug(inode, "reading block %d", block);
724 + bh = sb_bread(inode->i_sb, block);
727 + ea_bdebug(bh, "b_count=%d, refcount=%d",
728 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
729 + end = bh->b_data + bh->b_size;
730 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
731 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
732 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_get",
733 + "inode %ld: bad block %d", inode->i_ino, block);
737 + /* find named attribute */
738 + name_len = strlen(name);
741 + if (name_len > 255)
743 + entry = FIRST_ENTRY(bh);
744 + while (!IS_LAST_ENTRY(entry)) {
745 + struct ext3_xattr_entry *next =
746 + EXT3_XATTR_NEXT(entry);
747 + if ((char *)next >= end)
749 + if (name_index == entry->e_name_index &&
750 + name_len == entry->e_name_len &&
751 + memcmp(name, entry->e_name, name_len) == 0)
755 + /* Check the remaining name entries */
756 + while (!IS_LAST_ENTRY(entry)) {
757 + struct ext3_xattr_entry *next =
758 + EXT3_XATTR_NEXT(entry);
759 + if ((char *)next >= end)
763 + if (ext3_xattr_cache_insert(bh))
764 + ea_idebug(inode, "cache insert failed");
768 + /* check the buffer size */
769 + if (entry->e_value_block != 0)
771 + size = le32_to_cpu(entry->e_value_size);
772 + if (size > inode->i_sb->s_blocksize ||
773 + le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
776 + if (ext3_xattr_cache_insert(bh))
777 + ea_idebug(inode, "cache insert failed");
780 + if (size > buffer_size)
782 + /* return value of attribute */
783 + memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
795 + * ext3_xattr_list()
797 + * Copy a list of attribute names into the buffer
798 + * provided, or compute the buffer size required.
799 + * Buffer is NULL to compute the size of the buffer required.
801 + * Returns a negative error number on failure, or the number of bytes
802 + * used / required on success.
805 +ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
807 + struct buffer_head *bh = NULL;
808 + struct ext3_xattr_entry *entry;
809 + unsigned int block, size = 0;
813 + ea_idebug(inode, "buffer=%p, buffer_size=%ld",
814 + buffer, (long)buffer_size);
816 + if (!EXT3_I(inode)->i_file_acl)
818 + block = EXT3_I(inode)->i_file_acl;
819 + ea_idebug(inode, "reading block %d", block);
820 + bh = sb_bread(inode->i_sb, block);
823 + ea_bdebug(bh, "b_count=%d, refcount=%d",
824 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
825 + end = bh->b_data + bh->b_size;
826 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
827 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
828 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_list",
829 + "inode %ld: bad block %d", inode->i_ino, block);
833 + /* compute the size required for the list of attribute names */
834 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
835 + entry = EXT3_XATTR_NEXT(entry)) {
836 + struct ext3_xattr_handler *handler;
837 + struct ext3_xattr_entry *next =
838 + EXT3_XATTR_NEXT(entry);
839 + if ((char *)next >= end)
842 + handler = ext3_xattr_handler(entry->e_name_index);
844 + size += handler->list(NULL, inode, entry->e_name,
845 + entry->e_name_len) + 1;
849 + if (ext3_xattr_cache_insert(bh))
850 + ea_idebug(inode, "cache insert failed");
856 + if (size > buffer_size)
860 + /* list the attribute names */
862 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
863 + entry = EXT3_XATTR_NEXT(entry)) {
864 + struct ext3_xattr_handler *handler;
866 + handler = ext3_xattr_handler(entry->e_name_index);
868 + buf += handler->list(buf, inode, entry->e_name,
869 + entry->e_name_len);
882 + * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is
885 +static void ext3_xattr_update_super_block(handle_t *handle,
886 + struct super_block *sb)
888 + if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR))
892 + ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh);
893 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
894 + EXT3_SB(sb)->s_feature_compat |= EXT3_FEATURE_COMPAT_EXT_ATTR;
896 + EXT3_SB(sb)->s_es->s_feature_compat |=
897 + cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR);
899 + ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
906 + * Create, replace or remove an extended attribute for this inode. Buffer
907 + * is NULL to remove an existing extended attribute, and non-NULL to
908 + * either replace an existing extended attribute, or create a new extended
909 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
910 + * specify that an extended attribute must exist and must not exist
911 + * previous to the call, respectively.
913 + * Returns 0, or a negative error number on failure.
916 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
917 + const char *name, void *value, size_t value_len, int flags)
919 + struct super_block *sb = inode->i_sb;
920 + struct buffer_head *bh = NULL;
921 + struct ext3_xattr_header *header = NULL;
922 + struct ext3_xattr_entry *here, *last;
923 + unsigned int name_len;
924 + int min_offs = sb->s_blocksize, not_found = 1, free, error;
928 + * header -- Points either into bh, or to a temporarily
929 + * allocated buffer.
930 + * here -- The named entry found, or the place for inserting, within
931 + * the block pointed to by header.
932 + * last -- Points right after the last named entry within the block
933 + * pointed to by header.
934 + * min_offs -- The offset of the first value (values are aligned
935 + * towards the end of the block).
936 + * end -- Points right after the block pointed to by header.
939 + ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
940 + name_index, name, value, (long)value_len);
942 + if (IS_RDONLY(inode))
944 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
950 + name_len = strlen(name);
951 + if (name_len > 255 || value_len > sb->s_blocksize)
955 + if (EXT3_I(inode)->i_file_acl) {
956 + /* The inode already has an extended attribute block. */
957 + int block = EXT3_I(inode)->i_file_acl;
959 + bh = sb_bread(sb, block);
963 + ea_bdebug(bh, "b_count=%d, refcount=%d",
964 + atomic_read(&(bh->b_count)),
965 + le32_to_cpu(HDR(bh)->h_refcount));
967 + end = bh->b_data + bh->b_size;
968 + if (header->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
969 + header->h_blocks != cpu_to_le32(1)) {
970 +bad_block: ext3_error(sb, "ext3_xattr_set",
971 + "inode %ld: bad block %d", inode->i_ino, block);
975 + /* Find the named attribute. */
976 + here = FIRST_ENTRY(bh);
977 + while (!IS_LAST_ENTRY(here)) {
978 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(here);
979 + if ((char *)next >= end)
981 + if (!here->e_value_block && here->e_value_size) {
982 + int offs = le16_to_cpu(here->e_value_offs);
983 + if (offs < min_offs)
986 + not_found = name_index - here->e_name_index;
988 + not_found = name_len - here->e_name_len;
990 + not_found = memcmp(name, here->e_name,name_len);
991 + if (not_found <= 0)
996 + /* We still need to compute min_offs and last. */
997 + while (!IS_LAST_ENTRY(last)) {
998 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
999 + if ((char *)next >= end)
1001 + if (!last->e_value_block && last->e_value_size) {
1002 + int offs = le16_to_cpu(last->e_value_offs);
1003 + if (offs < min_offs)
1009 + /* Check whether we have enough space left. */
1010 + free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
1012 + /* We will use a new extended attribute block. */
1013 + free = sb->s_blocksize -
1014 + sizeof(struct ext3_xattr_header) - sizeof(__u32);
1015 + here = last = NULL; /* avoid gcc uninitialized warning. */
1019 + /* Request to remove a nonexistent attribute? */
1021 + if (flags & XATTR_REPLACE)
1024 + if (value == NULL)
1027 + free -= EXT3_XATTR_LEN(name_len);
1029 + /* Request to create an existing attribute? */
1031 + if (flags & XATTR_CREATE)
1033 + if (!here->e_value_block && here->e_value_size) {
1034 + unsigned int size = le32_to_cpu(here->e_value_size);
1036 + if (le16_to_cpu(here->e_value_offs) + size >
1037 + sb->s_blocksize || size > sb->s_blocksize)
1039 + free += EXT3_XATTR_SIZE(size);
1042 + free -= EXT3_XATTR_SIZE(value_len);
1047 + /* Here we know that we can set the new attribute. */
1050 + if (header->h_refcount == cpu_to_le32(1)) {
1051 + ea_bdebug(bh, "modifying in-place");
1052 + ext3_xattr_cache_remove(bh);
1053 + error = ext3_journal_get_write_access(handle, bh);
1059 + ea_bdebug(bh, "cloning");
1060 + header = kmalloc(bh->b_size, GFP_KERNEL);
1062 + if (header == NULL)
1064 + memcpy(header, HDR(bh), bh->b_size);
1065 + header->h_refcount = cpu_to_le32(1);
1066 + offset = (char *)header - bh->b_data;
1067 + here = ENTRY((char *)here + offset);
1068 + last = ENTRY((char *)last + offset);
1071 + /* Allocate a buffer where we construct the new block. */
1072 + header = kmalloc(sb->s_blocksize, GFP_KERNEL);
1074 + if (header == NULL)
1076 + memset(header, 0, sb->s_blocksize);
1077 + end = (char *)header + sb->s_blocksize;
1078 + header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC);
1079 + header->h_blocks = header->h_refcount = cpu_to_le32(1);
1080 + last = here = ENTRY(header+1);
1084 + /* Insert the new name. */
1085 + int size = EXT3_XATTR_LEN(name_len);
1086 + int rest = (char *)last - (char *)here;
1087 + memmove((char *)here + size, here, rest);
1088 + memset(here, 0, size);
1089 + here->e_name_index = name_index;
1090 + here->e_name_len = name_len;
1091 + memcpy(here->e_name, name, name_len);
1093 + /* Remove the old value. */
1094 + if (!here->e_value_block && here->e_value_size) {
1095 + char *first_val = (char *)header + min_offs;
1096 + int offs = le16_to_cpu(here->e_value_offs);
1097 + char *val = (char *)header + offs;
1098 + size_t size = EXT3_XATTR_SIZE(
1099 + le32_to_cpu(here->e_value_size));
1100 + memmove(first_val + size, first_val, val - first_val);
1101 + memset(first_val, 0, size);
1102 + here->e_value_offs = 0;
1105 + /* Adjust all value offsets. */
1106 + last = ENTRY(header+1);
1107 + while (!IS_LAST_ENTRY(last)) {
1108 + int o = le16_to_cpu(last->e_value_offs);
1109 + if (!last->e_value_block && o < offs)
1110 + last->e_value_offs =
1111 + cpu_to_le16(o + size);
1112 + last = EXT3_XATTR_NEXT(last);
1115 + if (value == NULL) {
1116 + /* Remove this attribute. */
1117 + if (EXT3_XATTR_NEXT(ENTRY(header+1)) == last) {
1118 + /* This block is now empty. */
1119 + error = ext3_xattr_set2(handle, inode, bh,NULL);
1122 + /* Remove the old name. */
1123 + int size = EXT3_XATTR_LEN(name_len);
1124 + last = ENTRY((char *)last - size);
1125 + memmove(here, (char*)here + size,
1126 + (char*)last - (char*)here);
1127 + memset(last, 0, size);
1132 + if (value != NULL) {
1133 + /* Insert the new value. */
1134 + here->e_value_size = cpu_to_le32(value_len);
1136 + size_t size = EXT3_XATTR_SIZE(value_len);
1137 + char *val = (char *)header + min_offs - size;
1138 + here->e_value_offs =
1139 + cpu_to_le16((char *)val - (char *)header);
1140 + memset(val + size - EXT3_XATTR_PAD, 0,
1141 + EXT3_XATTR_PAD); /* Clear the pad bytes. */
1142 + memcpy(val, value, value_len);
1145 + ext3_xattr_rehash(header, here);
1147 + error = ext3_xattr_set2(handle, inode, bh, header);
1151 + if (!(bh && header == HDR(bh)))
1153 + ext3_xattr_unlock();
1159 + * Second half of ext3_xattr_set(): Update the file system.
1162 +ext3_xattr_set2(handle_t *handle, struct inode *inode,
1163 + struct buffer_head *old_bh, struct ext3_xattr_header *header)
1165 + struct super_block *sb = inode->i_sb;
1166 + struct buffer_head *new_bh = NULL;
1170 + new_bh = ext3_xattr_cache_find(inode, header);
1173 + * We found an identical block in the cache.
1174 + * The old block will be released after updating
1177 + ea_bdebug(old_bh, "reusing block %ld",
1178 + new_bh->b_blocknr);
1181 + if (ext3_xattr_quota_alloc(inode, 1))
1184 + error = ext3_journal_get_write_access(handle, new_bh);
1187 + HDR(new_bh)->h_refcount = cpu_to_le32(
1188 + le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
1189 + ea_bdebug(new_bh, "refcount now=%d",
1190 + le32_to_cpu(HDR(new_bh)->h_refcount));
1191 + } else if (old_bh && header == HDR(old_bh)) {
1192 + /* Keep this block. */
1194 + ext3_xattr_cache_insert(new_bh);
1196 + /* We need to allocate a new block */
1197 + int force = EXT3_I(inode)->i_file_acl != 0;
1198 + int block = ext3_xattr_new_block(handle, inode,
1202 + ea_idebug(inode, "creating block %d", block);
1204 + new_bh = sb_getblk(sb, block);
1206 +getblk_failed: ext3_xattr_free_block(handle, inode, block);
1210 + lock_buffer(new_bh);
1211 + error = ext3_journal_get_create_access(handle, new_bh);
1213 + unlock_buffer(new_bh);
1214 + goto getblk_failed;
1216 + memcpy(new_bh->b_data, header, new_bh->b_size);
1217 + mark_buffer_uptodate(new_bh, 1);
1218 + unlock_buffer(new_bh);
1219 + ext3_xattr_cache_insert(new_bh);
1220 + ext3_xattr_update_super_block(handle, sb);
1222 + error = ext3_journal_dirty_metadata(handle, new_bh);
1227 + /* Update the inode. */
1228 + EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
1229 + inode->i_ctime = CURRENT_TIME;
1230 + ext3_mark_inode_dirty(handle, inode);
1231 + if (IS_SYNC(inode))
1232 + handle->h_sync = 1;
1235 + if (old_bh && old_bh != new_bh) {
1237 + * If there was an old block, and we are not still using it,
1238 + * we now release the old block.
1240 + unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
1242 + error = ext3_journal_get_write_access(handle, old_bh);
1245 + if (refcount == 1) {
1246 + /* Free the old block. */
1247 + ea_bdebug(old_bh, "freeing");
1248 + ext3_xattr_free_block(handle, inode, old_bh->b_blocknr);
1250 + /* ext3_forget() calls bforget() for us, but we
1251 + let our caller release old_bh, so we need to
1252 + duplicate the handle before. */
1254 + ext3_forget(handle, 1, inode, old_bh,old_bh->b_blocknr);
1256 + /* Decrement the refcount only. */
1258 + HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
1259 + ext3_xattr_quota_free(inode);
1260 + ext3_journal_dirty_metadata(handle, old_bh);
1261 + ea_bdebug(old_bh, "refcount now=%d", refcount);
1266 + if (old_bh != new_bh)
1273 + * ext3_xattr_drop_inode()
1275 + * Free extended attribute resources associated with this inode. This
1276 + * is called immediately before an inode is freed.
1279 +ext3_xattr_drop_inode(handle_t *handle, struct inode *inode)
1281 + struct buffer_head *bh;
1282 + unsigned int block = EXT3_I(inode)->i_file_acl;
1286 + ext3_xattr_lock();
1288 + bh = sb_bread(inode->i_sb, block);
1290 + ext3_error(inode->i_sb, "ext3_xattr_drop_inode",
1291 + "inode %ld: block %d read error", inode->i_ino, block);
1294 + ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
1295 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
1296 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1297 + ext3_error(inode->i_sb, "ext3_xattr_drop_inode",
1298 + "inode %ld: bad block %d", inode->i_ino, block);
1301 + ext3_journal_get_write_access(handle, bh);
1302 + ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
1303 + if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
1304 + ext3_xattr_cache_remove(bh);
1305 + ext3_xattr_free_block(handle, inode, block);
1306 + ext3_forget(handle, 1, inode, bh, block);
1309 + HDR(bh)->h_refcount = cpu_to_le32(
1310 + le32_to_cpu(HDR(bh)->h_refcount) - 1);
1311 + ext3_journal_dirty_metadata(handle, bh);
1312 + if (IS_SYNC(inode))
1313 + handle->h_sync = 1;
1314 + ext3_xattr_quota_free(inode);
1316 + EXT3_I(inode)->i_file_acl = 0;
1320 + ext3_xattr_unlock();
1324 + * ext3_xattr_put_super()
1326 + * This is called when a file system is unmounted.
1329 +ext3_xattr_put_super(struct super_block *sb)
1331 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
1332 + mb_cache_shrink(ext3_xattr_cache, sb->s_dev);
1336 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
1339 + * ext3_xattr_cache_insert()
1341 + * Create a new entry in the extended attribute cache, and insert
1342 + * it unless such an entry is already in the cache.
1344 + * Returns 0, or a negative error number on failure.
1347 +ext3_xattr_cache_insert(struct buffer_head *bh)
1349 + __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
1350 + struct mb_cache_entry *ce;
1353 + ce = mb_cache_entry_alloc(ext3_xattr_cache);
1356 + error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
1358 + mb_cache_entry_free(ce);
1359 + if (error == -EBUSY) {
1360 + ea_bdebug(bh, "already in cache (%d cache entries)",
1361 + atomic_read(&ext3_xattr_cache->c_entry_count));
1365 + ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
1366 + atomic_read(&ext3_xattr_cache->c_entry_count));
1367 + mb_cache_entry_release(ce);
1373 + * ext3_xattr_cmp()
1375 + * Compare two extended attribute blocks for equality.
1377 + * Returns 0 if the blocks are equal, 1 if they differ, and
1378 + * a negative error number on errors.
1381 +ext3_xattr_cmp(struct ext3_xattr_header *header1,
1382 + struct ext3_xattr_header *header2)
1384 + struct ext3_xattr_entry *entry1, *entry2;
1386 + entry1 = ENTRY(header1+1);
1387 + entry2 = ENTRY(header2+1);
1388 + while (!IS_LAST_ENTRY(entry1)) {
1389 + if (IS_LAST_ENTRY(entry2))
1391 + if (entry1->e_hash != entry2->e_hash ||
1392 + entry1->e_name_len != entry2->e_name_len ||
1393 + entry1->e_value_size != entry2->e_value_size ||
1394 + memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
1396 + if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
1398 + if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
1399 + (char *)header2 + le16_to_cpu(entry2->e_value_offs),
1400 + le32_to_cpu(entry1->e_value_size)))
1403 + entry1 = EXT3_XATTR_NEXT(entry1);
1404 + entry2 = EXT3_XATTR_NEXT(entry2);
1406 + if (!IS_LAST_ENTRY(entry2))
1412 + * ext3_xattr_cache_find()
1414 + * Find an identical extended attribute block.
1416 + * Returns a pointer to the block found, or NULL if such a block was
1417 + * not found or an error occurred.
1419 +static struct buffer_head *
1420 +ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header)
1422 + __u32 hash = le32_to_cpu(header->h_hash);
1423 + struct mb_cache_entry *ce;
1425 + if (!header->h_hash)
1426 + return NULL; /* never share */
1427 + ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
1428 + ce = mb_cache_entry_find_first(ext3_xattr_cache, 0, inode->i_dev, hash);
1430 + struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
1433 + ext3_error(inode->i_sb, "ext3_xattr_cache_find",
1434 + "inode %ld: block %ld read error",
1435 + inode->i_ino, ce->e_block);
1436 + } else if (le32_to_cpu(HDR(bh)->h_refcount) >
1437 + EXT3_XATTR_REFCOUNT_MAX) {
1438 + ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
1439 + le32_to_cpu(HDR(bh)->h_refcount),
1440 + EXT3_XATTR_REFCOUNT_MAX);
1441 + } else if (!ext3_xattr_cmp(header, HDR(bh))) {
1442 + ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
1443 + mb_cache_entry_release(ce);
1447 + ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
1453 + * ext3_xattr_cache_remove()
1455 + * Remove the cache entry of a block from the cache. Called when a
1456 + * block becomes invalid.
1459 +ext3_xattr_cache_remove(struct buffer_head *bh)
1461 + struct mb_cache_entry *ce;
1463 + ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_dev, bh->b_blocknr);
1465 + ea_bdebug(bh, "removing (%d cache entries remaining)",
1466 + atomic_read(&ext3_xattr_cache->c_entry_count)-1);
1467 + mb_cache_entry_free(ce);
1469 + ea_bdebug(bh, "no cache entry");
1472 +#define NAME_HASH_SHIFT 5
1473 +#define VALUE_HASH_SHIFT 16
1476 + * ext3_xattr_hash_entry()
1478 + * Compute the hash of an extended attribute.
1480 +static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
1481 + struct ext3_xattr_entry *entry)
1484 + char *name = entry->e_name;
1487 + for (n=0; n < entry->e_name_len; n++) {
1488 + hash = (hash << NAME_HASH_SHIFT) ^
1489 + (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
1493 + if (entry->e_value_block == 0 && entry->e_value_size != 0) {
1494 + __u32 *value = (__u32 *)((char *)header +
1495 + le16_to_cpu(entry->e_value_offs));
1496 + for (n = (le32_to_cpu(entry->e_value_size) +
1497 + EXT3_XATTR_ROUND) >> EXT3_XATTR_PAD_BITS; n; n--) {
1498 + hash = (hash << VALUE_HASH_SHIFT) ^
1499 + (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
1500 + le32_to_cpu(*value++);
1503 + entry->e_hash = cpu_to_le32(hash);
1506 +#undef NAME_HASH_SHIFT
1507 +#undef VALUE_HASH_SHIFT
1509 +#define BLOCK_HASH_SHIFT 16
1512 + * ext3_xattr_rehash()
1514 + * Re-compute the extended attribute hash value after an entry has changed.
1516 +static void ext3_xattr_rehash(struct ext3_xattr_header *header,
1517 + struct ext3_xattr_entry *entry)
1519 + struct ext3_xattr_entry *here;
1522 + ext3_xattr_hash_entry(header, entry);
1523 + here = ENTRY(header+1);
1524 + while (!IS_LAST_ENTRY(here)) {
1525 + if (!here->e_hash) {
1526 + /* Block is not shared if an entry's hash value == 0 */
1530 + hash = (hash << BLOCK_HASH_SHIFT) ^
1531 + (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
1532 + le32_to_cpu(here->e_hash);
1533 + here = EXT3_XATTR_NEXT(here);
1535 + header->h_hash = cpu_to_le32(hash);
1538 +#undef BLOCK_HASH_SHIFT
1541 +init_ext3_xattr(void)
1543 + ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL,
1544 + sizeof(struct mb_cache_entry) +
1545 + sizeof(struct mb_cache_entry_index), 1, 61);
1546 + if (!ext3_xattr_cache)
1553 +exit_ext3_xattr(void)
1555 + if (ext3_xattr_cache)
1556 + mb_cache_destroy(ext3_xattr_cache);
1557 + ext3_xattr_cache = NULL;
1560 +#else /* CONFIG_EXT3_FS_XATTR_SHARING */
1563 +init_ext3_xattr(void)
1569 +exit_ext3_xattr(void)
1573 +#endif /* CONFIG_EXT3_FS_XATTR_SHARING */
1574 diff -Nur linux-2.4.18/include/linux/ext3_fs.h linux-2.4.18ea/include/linux/ext3_fs.h
1575 --- linux-2.4.18/include/linux/ext3_fs.h Sun Feb 24 04:42:59 2002
1576 +++ linux-2.4.18ea/include/linux/ext3_fs.h Mon Mar 11 03:27:00 2002
1579 #define EXT3_BAD_INO 1 /* Bad blocks inode */
1580 #define EXT3_ROOT_INO 2 /* Root inode */
1581 -#define EXT3_ACL_IDX_INO 3 /* ACL inode */
1582 -#define EXT3_ACL_DATA_INO 4 /* ACL inode */
1583 #define EXT3_BOOT_LOADER_INO 5 /* Boot loader inode */
1584 #define EXT3_UNDEL_DIR_INO 6 /* Undelete directory inode */
1585 #define EXT3_RESIZE_INO 7 /* Reserved group descriptors inode */
1588 # define EXT3_BLOCK_SIZE(s) (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
1590 -#define EXT3_ACLE_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_acl_entry))
1591 #define EXT3_ADDR_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (__u32))
1593 # define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
1594 @@ -124,28 +121,6 @@
1600 -struct ext3_acl_header /* Header of Access Control Lists */
1603 - __u32 aclh_file_count;
1604 - __u32 aclh_acle_count;
1605 - __u32 aclh_first_acle;
1608 -struct ext3_acl_entry /* Access Control List Entry */
1611 - __u16 acle_perms; /* Access permissions */
1612 - __u16 acle_type; /* Type of entry */
1613 - __u16 acle_tag; /* User or group identity */
1615 - __u32 acle_next; /* Pointer on next entry for the */
1616 - /* same inode or on next free entry */
1620 * Structure of a blocks group descriptor
1622 struct ext3_group_desc
1624 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
1625 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
1627 -#define EXT3_FEATURE_COMPAT_SUPP 0
1628 +#define EXT3_FEATURE_COMPAT_SUPP EXT3_FEATURE_COMPAT_EXT_ATTR
1629 #define EXT3_FEATURE_INCOMPAT_SUPP (EXT3_FEATURE_INCOMPAT_FILETYPE| \
1630 EXT3_FEATURE_INCOMPAT_RECOVER)
1631 #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
1632 @@ -603,4 +578,22 @@
1635 +/* Defined for extended attributes */
1636 +#define CONFIG_EXT3_FS_XATTR y
1638 +#define ENOATTR ENODATA /* No such attribute */
1641 +#define ENOTSUP EOPNOTSUPP /* Operation not supported */
1643 +#ifndef XATTR_NAME_MAX
1644 +#define XATTR_NAME_MAX 255 /* # chars in an extended attribute name */
1645 +#define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */
1646 +#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */
1648 +#ifndef XATTR_CREATE
1649 +#define XATTR_CREATE 1 /* set value, fail if attr already exists */
1650 +#define XATTR_REPLACE 2 /* set value, fail if attr does not exist */
1654 * Ok, these declarations are also in <linux/kernel.h> but none of the
1656 extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
1659 +extern int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
1660 extern struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
1661 extern struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
1663 @@ -694,8 +670,10 @@
1666 extern struct inode_operations ext3_dir_inode_operations;
1667 +extern struct inode_operations ext3_special_inode_operations;
1670 +extern struct inode_operations ext3_symlink_inode_operations;
1671 extern struct inode_operations ext3_fast_symlink_inode_operations;
1674 diff -Nur linux-2.4.18/include/linux/ext3_jbd.h linux-2.4.18ea/include/linux/ext3_jbd.h
1675 --- linux-2.4.18/include/linux/ext3_jbd.h Fri Dec 21 18:42:03 2001
1676 +++ linux-2.4.18ea/include/linux/ext3_jbd.h Mon Mar 25 00:11:36 2002
1679 #define EXT3_SINGLEDATA_TRANS_BLOCKS 8
1681 +/* Extended attributes may touch two data buffers, two bitmap buffers,
1682 + * and two group and summaries. */
1684 +#define EXT3_XATTR_TRANS_BLOCKS 8
1686 /* Define the minimum size for a transaction which modifies data. This
1687 * needs to take into account the fact that we may end up modifying two
1688 * quota files too (one for the group, one for the user quota). The
1689 * superblock only gets updated once, of course, so don't bother
1690 * counting that again for the quota updates. */
1692 -#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS - 2)
1693 +#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS + \
1694 + EXT3_XATTR_TRANS_BLOCKS - 2)
1696 extern int ext3_writepage_trans_blocks(struct inode *inode);
1698 diff -Nur linux-2.4.18/include/linux/ext3_xattr.h linux-2.4.18ea/include/linux/ext3_xattr.h
1699 --- linux-2.4.18/include/linux/ext3_xattr.h Thu Jan 1 01:00:00 1970
1700 +++ linux-2.4.18ea/include/linux/ext3_xattr.h Fri Apr 5 10:08:01 2002
1703 + File: linux/ext3_xattr.h
1705 + On-disk format of extended attributes for the ext3 filesystem.
1707 + (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
1710 +#include <linux/config.h>
1711 +#include <linux/init.h>
1712 +#include <linux/xattr.h>
1714 +/* Magic value in attribute blocks */
1715 +#define EXT3_XATTR_MAGIC 0xEA020000
1717 +/* Maximum number of references to one attribute block */
1718 +#define EXT3_XATTR_REFCOUNT_MAX 1024
1721 +#define EXT3_XATTR_INDEX_MAX 10
1722 +#define EXT3_XATTR_INDEX_USER 1
1724 +struct ext3_xattr_header {
1725 + __u32 h_magic; /* magic number for identification */
1726 + __u32 h_refcount; /* reference count */
1727 + __u32 h_blocks; /* number of disk blocks used */
1728 + __u32 h_hash; /* hash value of all attributes */
1729 + __u32 h_reserved[4]; /* zero right now */
1732 +struct ext3_xattr_entry {
1733 + __u8 e_name_len; /* length of name */
1734 + __u8 e_name_index; /* attribute name index */
1735 + __u16 e_value_offs; /* offset in disk block of value */
1736 + __u32 e_value_block; /* disk block attribute is stored on (n/i) */
1737 + __u32 e_value_size; /* size of attribute value */
1738 + __u32 e_hash; /* hash value of name and value */
1739 + char e_name[0]; /* attribute name */
1742 +#define EXT3_XATTR_PAD_BITS 2
1743 +#define EXT3_XATTR_PAD (1<<EXT3_XATTR_PAD_BITS)
1744 +#define EXT3_XATTR_ROUND (EXT3_XATTR_PAD-1)
1745 +#define EXT3_XATTR_LEN(name_len) \
1746 + (((name_len) + EXT3_XATTR_ROUND + \
1747 + sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND)
1748 +#define EXT3_XATTR_NEXT(entry) \
1749 + ( (struct ext3_xattr_entry *)( \
1750 + (char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) )
1751 +#define EXT3_XATTR_SIZE(size) \
1752 + (((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND)
1756 +# ifdef CONFIG_EXT3_FS_XATTR
1758 +struct ext3_xattr_handler {
1760 + size_t (*list)(char *list, struct inode *inode, const char *name,
1762 + int (*get)(struct inode *inode, const char *name, void *buffer,
1764 + int (*set)(struct inode *inode, const char *name, void *buffer,
1765 + size_t size, int flags);
1768 +extern int ext3_xattr_register(int, struct ext3_xattr_handler *);
1769 +extern void ext3_xattr_unregister(int, struct ext3_xattr_handler *);
1771 +extern int ext3_setxattr(struct dentry *, const char *, void *, size_t, int);
1772 +extern ssize_t ext3_getxattr(struct dentry *, const char *, void *, size_t);
1773 +extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
1774 +extern int ext3_removexattr(struct dentry *, const char *);
1776 +extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
1777 +extern int ext3_xattr_list(struct inode *, char *, size_t);
1778 +extern int ext3_xattr_set(handle_t *handle, struct inode *, int, const char *, void *, size_t, int);
1780 +extern void ext3_xattr_drop_inode(handle_t *, struct inode *);
1781 +extern void ext3_xattr_put_super(struct super_block *);
1783 +extern int init_ext3_xattr(void) __init;
1784 +extern void exit_ext3_xattr(void);
1786 +# else /* CONFIG_EXT3_FS_XATTR */
1787 +# define ext3_setxattr NULL
1788 +# define ext3_getxattr NULL
1789 +# define ext3_listxattr NULL
1790 +# define ext3_removexattr NULL
1793 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
1794 + void *buffer, size_t size, int flags)
1800 +ext3_xattr_list(struct inode *inode, void *buffer, size_t size, int flags)
1806 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
1807 + const char *name, void *value, size_t size, int flags)
1813 +ext3_xattr_drop_inode(handle_t *handle, struct inode *inode)
1818 +ext3_xattr_put_super(struct super_block *sb)
1823 +init_ext3_xattr(void)
1829 +exit_ext3_xattr(void)
1833 +# endif /* CONFIG_EXT3_FS_XATTR */
1835 +# ifdef CONFIG_EXT3_FS_XATTR_USER
1837 +extern int init_ext3_xattr_user(void) __init;
1838 +extern void exit_ext3_xattr_user(void);
1840 +# else /* CONFIG_EXT3_FS_XATTR_USER */
1843 +init_ext3_xattr_user(void)
1849 +exit_ext3_xattr_user(void)
1853 +#endif /* CONFIG_EXT3_FS_XATTR_USER */
1855 +#endif /* __KERNEL__ */
1857 diff -Nur linux-2.4.18/include/linux/xattr.h linux-2.4.18ea/include/linux/xattr.h
1858 --- linux-2.4.18/include/linux/xattr.h Thu Jan 1 01:00:00 1970
1859 +++ linux-2.4.18ea/include/linux/xattr.h Sun Mar 24 23:42:21 2002
1862 + File: linux/xattr.h
1864 + Extended attributes handling.
1866 + Copyright (C) 2001 by Andreas Gruenbacher <a.gruenbacher@computer.org>
1867 + Copyright (C) 2001 SGI - Silicon Graphics, Inc <linux-xfs@oss.sgi.com>
1869 +#ifndef _LINUX_XATTR_H
1870 +#define _LINUX_XATTR_H
1872 +#define XATTR_CREATE 1 /* set value, fail if attr already exists */
1873 +#define XATTR_REPLACE 2 /* set value, fail if attr does not exist */
1875 +#endif /* _LINUX_XATTR_H */