3 --- linux-2.4.18-18/fs/ext3/ialloc.c~linux-2.4.18ea-0.8.26 2003-04-20 16:14:31.000000000 +0800
4 +++ linux-2.4.18-18-root/fs/ext3/ialloc.c 2003-04-20 16:14:31.000000000 +0800
7 #include <linux/ext3_fs.h>
8 #include <linux/ext3_jbd.h>
9 +#include <linux/ext3_xattr.h>
10 #include <linux/stat.h>
11 #include <linux/string.h>
12 #include <linux/locks.h>
13 @@ -216,6 +217,7 @@ void ext3_free_inode (handle_t *handle,
14 * as writing the quota to disk may need the lock as well.
17 + ext3_xattr_drop_inode(handle, inode);
18 DQUOT_FREE_INODE(inode);
21 --- linux-2.4.18-18/fs/ext3/inode.c~linux-2.4.18ea-0.8.26 2003-04-20 16:14:31.000000000 +0800
22 +++ linux-2.4.18-18-root/fs/ext3/inode.c 2003-04-20 16:14:31.000000000 +0800
25 #undef SEARCH_FROM_ZERO
28 + * Test whether an inode is a fast symlink.
30 +static inline int ext3_inode_is_fast_symlink(struct inode *inode)
32 + int ea_blocks = EXT3_I(inode)->i_file_acl ?
33 + (inode->i_sb->s_blocksize >> 9) : 0;
35 + return (S_ISLNK(inode->i_mode) &&
36 + inode->i_blocks - ea_blocks == 0);
39 /* The ext3 forget function must perform a revoke if we are freeing data
40 * which has been journaled. Metadata (eg. indirect blocks) must be
41 * revoked in all cases.
43 * still needs to be revoked.
46 -static int ext3_forget(handle_t *handle, int is_metadata,
47 +int ext3_forget(handle_t *handle, int is_metadata,
48 struct inode *inode, struct buffer_head *bh,
51 @@ -164,9 +176,7 @@ void ext3_delete_inode (struct inode * i
55 - if (is_bad_inode(inode) ||
56 - inode->i_ino == EXT3_ACL_IDX_INO ||
57 - inode->i_ino == EXT3_ACL_DATA_INO)
58 + if (is_bad_inode(inode))
62 @@ -1861,6 +1871,8 @@ void ext3_truncate(struct inode * inode)
63 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
64 S_ISLNK(inode->i_mode)))
66 + if (ext3_inode_is_fast_symlink(inode))
68 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
71 @@ -2008,8 +2020,6 @@ int ext3_get_inode_loc (struct inode *in
72 struct ext3_group_desc * gdp;
74 if ((inode->i_ino != EXT3_ROOT_INO &&
75 - inode->i_ino != EXT3_ACL_IDX_INO &&
76 - inode->i_ino != EXT3_ACL_DATA_INO &&
77 inode->i_ino != EXT3_JOURNAL_INO &&
78 inode->i_ino < EXT3_FIRST_INO(inode->i_sb)) ||
79 inode->i_ino > le32_to_cpu(
80 @@ -2136,10 +2146,7 @@ void ext3_read_inode(struct inode * inod
84 - if (inode->i_ino == EXT3_ACL_IDX_INO ||
85 - inode->i_ino == EXT3_ACL_DATA_INO)
86 - /* Nothing to do */ ;
87 - else if (S_ISREG(inode->i_mode)) {
88 + if (S_ISREG(inode->i_mode)) {
89 inode->i_op = &ext3_file_inode_operations;
90 inode->i_fop = &ext3_file_operations;
91 inode->i_mapping->a_ops = &ext3_aops;
92 @@ -2147,7 +2154,7 @@ void ext3_read_inode(struct inode * inod
93 inode->i_op = &ext3_dir_inode_operations;
94 inode->i_fop = &ext3_dir_operations;
95 } else if (S_ISLNK(inode->i_mode)) {
96 - if (!inode->i_blocks)
97 + if (ext3_inode_is_fast_symlink(inode))
98 inode->i_op = &ext3_fast_symlink_inode_operations;
100 inode->i_op = &page_symlink_inode_operations;
101 --- linux-2.4.18-18/fs/ext3/namei.c~linux-2.4.18ea-0.8.26 2003-04-20 16:14:31.000000000 +0800
102 +++ linux-2.4.18-18-root/fs/ext3/namei.c 2003-04-20 16:14:31.000000000 +0800
104 #include <linux/sched.h>
105 #include <linux/ext3_fs.h>
106 #include <linux/ext3_jbd.h>
107 +#include <linux/ext3_xattr.h>
108 #include <linux/fcntl.h>
109 #include <linux/stat.h>
110 #include <linux/string.h>
111 @@ -1183,6 +1184,7 @@ static int ext3_add_nondir(handle_t *han
112 d_instantiate(dentry, inode);
115 + ext3_xattr_drop_inode(handle, inode);
116 ext3_dec_count(handle, inode);
119 @@ -1268,15 +1270,14 @@ static int ext3_mkdir(struct inode * dir
123 - inode = ext3_new_inode (handle, dir, S_IFDIR);
124 + inode = ext3_new_inode (handle, dir, S_IFDIR | mode);
125 err = PTR_ERR(inode);
129 inode->i_op = &ext3_dir_inode_operations;
130 inode->i_fop = &ext3_dir_operations;
131 - inode->i_size = inode->u.ext3_i.i_disksize = inode->i_sb->s_blocksize;
132 - inode->i_blocks = 0;
133 + inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
134 dir_block = ext3_bread (handle, inode, 0, 1, &err);
136 inode->i_nlink--; /* is this nlink == 0? */
137 @@ -1303,9 +1304,6 @@ static int ext3_mkdir(struct inode * dir
138 BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata");
139 ext3_journal_dirty_metadata(handle, dir_block);
141 - inode->i_mode = S_IFDIR | mode;
142 - if (dir->i_mode & S_ISGID)
143 - inode->i_mode |= S_ISGID;
144 ext3_mark_inode_dirty(handle, inode);
145 err = ext3_add_entry (handle, dentry, inode);
147 @@ -1671,7 +1669,7 @@ static int ext3_symlink (struct inode *
151 - if (l > sizeof (inode->u.ext3_i.i_data)) {
152 + if (l > sizeof(EXT3_I(inode)->i_data)) {
153 inode->i_op = &page_symlink_inode_operations;
154 inode->i_mapping->a_ops = &ext3_aops;
156 --- linux-2.4.18-18/fs/ext3/super.c~linux-2.4.18ea-0.8.26 2003-04-20 16:14:31.000000000 +0800
157 +++ linux-2.4.18-18-root/fs/ext3/super.c 2003-04-20 16:14:31.000000000 +0800
159 #include <linux/jbd.h>
160 #include <linux/ext3_fs.h>
161 #include <linux/ext3_jbd.h>
162 +#include <linux/ext3_xattr.h>
163 #include <linux/slab.h>
164 #include <linux/init.h>
165 #include <linux/locks.h>
166 @@ -404,6 +405,7 @@ void ext3_put_super (struct super_block
167 kdev_t j_dev = sbi->s_journal->j_dev;
170 + ext3_xattr_put_super(sb);
171 journal_destroy(sbi->s_journal);
172 if (!(sb->s_flags & MS_RDONLY)) {
173 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
174 @@ -1748,14 +1750,25 @@ int ext3_statfs (struct super_block * sb
176 static DECLARE_FSTYPE_DEV(ext3_fs_type, "ext3", ext3_read_super);
178 -static int __init init_ext3_fs(void)
179 +static void exit_ext3_fs(void)
181 - return register_filesystem(&ext3_fs_type);
182 + unregister_filesystem(&ext3_fs_type);
183 + exit_ext3_xattr_user();
187 -static void __exit exit_ext3_fs(void)
188 +static int __init init_ext3_fs(void)
190 - unregister_filesystem(&ext3_fs_type);
191 + int error = init_ext3_xattr();
193 + error = init_ext3_xattr_user();
195 + error = register_filesystem(&ext3_fs_type);
203 EXPORT_SYMBOL(ext3_bread);
204 --- /dev/null 2002-08-31 07:31:37.000000000 +0800
205 +++ linux-2.4.18-18-root/fs/ext3/xattr.c 2003-04-20 16:14:31.000000000 +0800
208 + * linux/fs/ext3/xattr.c
210 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
212 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
213 + * Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>.
214 + * Extended attributes for symlinks and special files added per
215 + * suggestion of Luka Renko <luka.renko@hermes.si>.
219 + * Extended attributes are stored on disk blocks allocated outside of
220 + * any inode. The i_file_acl field is then made to point to this allocated
221 + * block. If all extended attributes of an inode are identical, these
222 + * inodes may share the same extended attribute block. Such situations
223 + * are automatically detected by keeping a cache of recent attribute block
224 + * numbers and hashes over the block's contents in memory.
227 + * Extended attribute block layout:
229 + * +------------------+
232 + * | entry 2 | | growing downwards
234 + * | four null bytes |
237 + * | value 3 | | growing upwards
239 + * +------------------+
241 + * The block header is followed by multiple entry descriptors. These entry
242 + * descriptors are variable in size, and alligned to EXT3_XATTR_PAD
243 + * byte boundaries. The entry descriptors are sorted by attribute name,
244 + * so that two extended attribute blocks can be compared efficiently.
246 + * Attribute values are aligned to the end of the block, stored in
247 + * no specific order. They are also padded to EXT3_XATTR_PAD byte
248 + * boundaries. No additional gaps are left between them.
252 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
253 + * the xattr inode operations are called, so we are guaranteed that only one
254 + * processes accesses extended attributes of an inode at any time.
256 + * For writing we also grab the ext3_xattr_sem semaphore. This ensures that
257 + * only a single process is modifying an extended attribute block, even
258 + * if the block is shared among inodes.
260 + * Note for porting to 2.5
261 + * -----------------------
262 + * The BKL will no longer be held in the xattr inode operations.
265 +#include <linux/fs.h>
266 +#include <linux/locks.h>
267 +#include <linux/slab.h>
268 +#include <linux/ext3_jbd.h>
269 +#include <linux/ext3_fs.h>
270 +#include <linux/ext3_xattr.h>
271 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
272 +#include <linux/mbcache.h>
274 +#include <linux/quotaops.h>
275 +#include <asm/semaphore.h>
276 +#include <linux/compatmac.h>
277 +#include <linux/module.h>
279 +/* These symbols may be needed by a module. */
280 +EXPORT_SYMBOL(ext3_xattr_register);
281 +EXPORT_SYMBOL(ext3_xattr_unregister);
282 +EXPORT_SYMBOL(ext3_xattr_get);
283 +EXPORT_SYMBOL(ext3_xattr_list);
284 +EXPORT_SYMBOL(ext3_xattr_set);
286 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
287 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
290 +#define HDR(bh) ((struct ext3_xattr_header *)((bh)->b_data))
291 +#define ENTRY(ptr) ((struct ext3_xattr_entry *)(ptr))
292 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
293 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
295 +#ifdef EXT3_XATTR_DEBUG
296 +# define ea_idebug(inode, f...) do { \
297 + printk(KERN_DEBUG "inode %s:%ld: ", \
298 + kdevname(inode->i_dev), inode->i_ino); \
302 +# define ea_bdebug(bh, f...) do { \
303 + printk(KERN_DEBUG "block %s:%ld: ", \
304 + kdevname(bh->b_dev), bh->b_blocknr); \
309 +# define ea_idebug(f...)
310 +# define ea_bdebug(f...)
313 +static int ext3_xattr_set2(handle_t *, struct inode *, struct buffer_head *,
314 + struct ext3_xattr_header *);
316 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
318 +static int ext3_xattr_cache_insert(struct buffer_head *);
319 +static struct buffer_head *ext3_xattr_cache_find(struct inode *,
320 + struct ext3_xattr_header *);
321 +static void ext3_xattr_cache_remove(struct buffer_head *);
322 +static void ext3_xattr_rehash(struct ext3_xattr_header *,
323 + struct ext3_xattr_entry *);
325 +static struct mb_cache *ext3_xattr_cache;
328 +# define ext3_xattr_cache_insert(bh) 0
329 +# define ext3_xattr_cache_find(inode, header) NULL
330 +# define ext3_xattr_cache_remove(bh) do {} while(0)
331 +# define ext3_xattr_rehash(header, entry) do {} while(0)
335 + * If a file system does not share extended attributes among inodes,
336 + * we should not need the ext3_xattr_sem semaphore. However, the
337 + * filesystem may still contain shared blocks, so we always take
341 +DECLARE_MUTEX(ext3_xattr_sem);
344 +ext3_xattr_lock(void)
346 + down(&ext3_xattr_sem);
350 +ext3_xattr_unlock(void)
352 + up(&ext3_xattr_sem);
356 +ext3_xattr_new_block(handle_t *handle, struct inode *inode,
357 + int * errp, int force)
359 + struct super_block *sb = inode->i_sb;
360 + int goal = le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block) +
361 + EXT3_I(inode)->i_block_group * EXT3_BLOCKS_PER_GROUP(sb);
363 + /* How can we enforce the allocation? */
364 + int block = ext3_new_block(handle, inode, goal, 0, 0, errp);
367 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
373 +ext3_xattr_quota_alloc(struct inode *inode, int force)
375 + /* How can we enforce the allocation? */
377 + int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
379 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
381 + int error = DQUOT_ALLOC_BLOCK(inode, 1);
389 +ext3_xattr_quota_free(struct inode *inode)
391 + DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
392 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
396 +ext3_xattr_free_block(handle_t *handle, struct inode * inode,
397 + unsigned long block)
399 + ext3_free_blocks(handle, inode, block, 1);
400 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
404 +# define ext3_xattr_quota_free(inode) \
405 + DQUOT_FREE_BLOCK(inode, 1)
406 +# define ext3_xattr_free_block(handle, inode, block) \
407 + ext3_free_blocks(handle, inode, block, 1)
410 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
412 +static inline struct buffer_head *
413 +sb_bread(struct super_block *sb, int block)
415 + return bread(sb->s_dev, block, sb->s_blocksize);
418 +static inline struct buffer_head *
419 +sb_getblk(struct super_block *sb, int block)
421 + return getblk(sb->s_dev, block, sb->s_blocksize);
426 +struct ext3_xattr_handler *ext3_xattr_handlers[EXT3_XATTR_INDEX_MAX];
427 +rwlock_t ext3_handler_lock = RW_LOCK_UNLOCKED;
430 +ext3_xattr_register(int name_index, struct ext3_xattr_handler *handler)
432 + int error = -EINVAL;
434 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
435 + write_lock(&ext3_handler_lock);
436 + if (!ext3_xattr_handlers[name_index-1]) {
437 + ext3_xattr_handlers[name_index-1] = handler;
440 + write_unlock(&ext3_handler_lock);
446 +ext3_xattr_unregister(int name_index, struct ext3_xattr_handler *handler)
448 + if (name_index > 0 || name_index <= EXT3_XATTR_INDEX_MAX) {
449 + write_lock(&ext3_handler_lock);
450 + ext3_xattr_handlers[name_index-1] = NULL;
451 + write_unlock(&ext3_handler_lock);
455 +static inline const char *
456 +strcmp_prefix(const char *a, const char *a_prefix)
458 + while (*a_prefix && *a == *a_prefix) {
462 + return *a_prefix ? NULL : a;
466 + * Decode the extended attribute name, and translate it into
467 + * the name_index and name suffix.
469 +static inline struct ext3_xattr_handler *
470 +ext3_xattr_resolve_name(const char **name)
472 + struct ext3_xattr_handler *handler = NULL;
477 + read_lock(&ext3_handler_lock);
478 + for (i=0; i<EXT3_XATTR_INDEX_MAX; i++) {
479 + if (ext3_xattr_handlers[i]) {
480 + const char *n = strcmp_prefix(*name,
481 + ext3_xattr_handlers[i]->prefix);
483 + handler = ext3_xattr_handlers[i];
489 + read_unlock(&ext3_handler_lock);
493 +static inline struct ext3_xattr_handler *
494 +ext3_xattr_handler(int name_index)
496 + struct ext3_xattr_handler *handler = NULL;
497 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
498 + read_lock(&ext3_handler_lock);
499 + handler = ext3_xattr_handlers[name_index-1];
500 + read_unlock(&ext3_handler_lock);
506 + * Inode operation getxattr()
508 + * dentry->d_inode->i_sem down
509 + * BKL held [before 2.5.x]
512 +ext3_getxattr(struct dentry *dentry, const char *name,
513 + void *buffer, size_t size)
515 + struct ext3_xattr_handler *handler;
516 + struct inode *inode = dentry->d_inode;
518 + handler = ext3_xattr_resolve_name(&name);
521 + return handler->get(inode, name, buffer, size);
525 + * Inode operation listxattr()
527 + * dentry->d_inode->i_sem down
528 + * BKL held [before 2.5.x]
531 +ext3_listxattr(struct dentry *dentry, char *buffer, size_t size)
533 + return ext3_xattr_list(dentry->d_inode, buffer, size);
537 + * Inode operation setxattr()
539 + * dentry->d_inode->i_sem down
540 + * BKL held [before 2.5.x]
543 +ext3_setxattr(struct dentry *dentry, const char *name,
544 + void *value, size_t size, int flags)
546 + struct ext3_xattr_handler *handler;
547 + struct inode *inode = dentry->d_inode;
550 + value = ""; /* empty EA, do not remove */
551 + handler = ext3_xattr_resolve_name(&name);
554 + return handler->set(inode, name, value, size, flags);
558 + * Inode operation removexattr()
560 + * dentry->d_inode->i_sem down
561 + * BKL held [before 2.5.x]
564 +ext3_removexattr(struct dentry *dentry, const char *name)
566 + struct ext3_xattr_handler *handler;
567 + struct inode *inode = dentry->d_inode;
569 + handler = ext3_xattr_resolve_name(&name);
572 + return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
578 + * Copy an extended attribute into the buffer
579 + * provided, or compute the buffer size required.
580 + * Buffer is NULL to compute the size of the buffer required.
582 + * Returns a negative error number on failure, or the number of bytes
583 + * used / required on success.
586 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
587 + void *buffer, size_t buffer_size)
589 + struct buffer_head *bh = NULL;
590 + struct ext3_xattr_entry *entry;
591 + unsigned int block, size;
593 + int name_len, error;
595 + ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
596 + name_index, name, buffer, (long)buffer_size);
600 + if (!EXT3_I(inode)->i_file_acl)
602 + block = EXT3_I(inode)->i_file_acl;
603 + ea_idebug(inode, "reading block %d", block);
604 + bh = sb_bread(inode->i_sb, block);
607 + ea_bdebug(bh, "b_count=%d, refcount=%d",
608 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
609 + end = bh->b_data + bh->b_size;
610 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
611 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
612 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_get",
613 + "inode %ld: bad block %d", inode->i_ino, block);
617 + /* find named attribute */
618 + name_len = strlen(name);
621 + if (name_len > 255)
623 + entry = FIRST_ENTRY(bh);
624 + while (!IS_LAST_ENTRY(entry)) {
625 + struct ext3_xattr_entry *next =
626 + EXT3_XATTR_NEXT(entry);
627 + if ((char *)next >= end)
629 + if (name_index == entry->e_name_index &&
630 + name_len == entry->e_name_len &&
631 + memcmp(name, entry->e_name, name_len) == 0)
635 + /* Check the remaining name entries */
636 + while (!IS_LAST_ENTRY(entry)) {
637 + struct ext3_xattr_entry *next =
638 + EXT3_XATTR_NEXT(entry);
639 + if ((char *)next >= end)
643 + if (ext3_xattr_cache_insert(bh))
644 + ea_idebug(inode, "cache insert failed");
648 + /* check the buffer size */
649 + if (entry->e_value_block != 0)
651 + size = le32_to_cpu(entry->e_value_size);
652 + if (size > inode->i_sb->s_blocksize ||
653 + le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
656 + if (ext3_xattr_cache_insert(bh))
657 + ea_idebug(inode, "cache insert failed");
660 + if (size > buffer_size)
662 + /* return value of attribute */
663 + memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
675 + * ext3_xattr_list()
677 + * Copy a list of attribute names into the buffer
678 + * provided, or compute the buffer size required.
679 + * Buffer is NULL to compute the size of the buffer required.
681 + * Returns a negative error number on failure, or the number of bytes
682 + * used / required on success.
685 +ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
687 + struct buffer_head *bh = NULL;
688 + struct ext3_xattr_entry *entry;
689 + unsigned int block, size = 0;
693 + ea_idebug(inode, "buffer=%p, buffer_size=%ld",
694 + buffer, (long)buffer_size);
696 + if (!EXT3_I(inode)->i_file_acl)
698 + block = EXT3_I(inode)->i_file_acl;
699 + ea_idebug(inode, "reading block %d", block);
700 + bh = sb_bread(inode->i_sb, block);
703 + ea_bdebug(bh, "b_count=%d, refcount=%d",
704 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
705 + end = bh->b_data + bh->b_size;
706 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
707 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
708 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_list",
709 + "inode %ld: bad block %d", inode->i_ino, block);
713 + /* compute the size required for the list of attribute names */
714 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
715 + entry = EXT3_XATTR_NEXT(entry)) {
716 + struct ext3_xattr_handler *handler;
717 + struct ext3_xattr_entry *next =
718 + EXT3_XATTR_NEXT(entry);
719 + if ((char *)next >= end)
722 + handler = ext3_xattr_handler(entry->e_name_index);
724 + size += handler->list(NULL, inode, entry->e_name,
725 + entry->e_name_len) + 1;
729 + if (ext3_xattr_cache_insert(bh))
730 + ea_idebug(inode, "cache insert failed");
736 + if (size > buffer_size)
740 + /* list the attribute names */
742 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
743 + entry = EXT3_XATTR_NEXT(entry)) {
744 + struct ext3_xattr_handler *handler;
746 + handler = ext3_xattr_handler(entry->e_name_index);
748 + buf += handler->list(buf, inode, entry->e_name,
749 + entry->e_name_len);
762 + * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is
765 +static void ext3_xattr_update_super_block(handle_t *handle,
766 + struct super_block *sb)
768 + if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR))
772 + ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh);
773 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
774 + EXT3_SB(sb)->s_feature_compat |= EXT3_FEATURE_COMPAT_EXT_ATTR;
776 + EXT3_SB(sb)->s_es->s_feature_compat |=
777 + cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR);
779 + ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
786 + * Create, replace or remove an extended attribute for this inode. Buffer
787 + * is NULL to remove an existing extended attribute, and non-NULL to
788 + * either replace an existing extended attribute, or create a new extended
789 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
790 + * specify that an extended attribute must exist and must not exist
791 + * previous to the call, respectively.
793 + * Returns 0, or a negative error number on failure.
796 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
797 + const char *name, void *value, size_t value_len, int flags)
799 + struct super_block *sb = inode->i_sb;
800 + struct buffer_head *bh = NULL;
801 + struct ext3_xattr_header *header = NULL;
802 + struct ext3_xattr_entry *here, *last;
803 + unsigned int name_len;
804 + int min_offs = sb->s_blocksize, not_found = 1, free, error;
808 + * header -- Points either into bh, or to a temporarily
809 + * allocated buffer.
810 + * here -- The named entry found, or the place for inserting, within
811 + * the block pointed to by header.
812 + * last -- Points right after the last named entry within the block
813 + * pointed to by header.
814 + * min_offs -- The offset of the first value (values are aligned
815 + * towards the end of the block).
816 + * end -- Points right after the block pointed to by header.
819 + ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
820 + name_index, name, value, (long)value_len);
822 + if (IS_RDONLY(inode))
824 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
830 + name_len = strlen(name);
831 + if (name_len > 255 || value_len > sb->s_blocksize)
835 + if (EXT3_I(inode)->i_file_acl) {
836 + /* The inode already has an extended attribute block. */
837 + int block = EXT3_I(inode)->i_file_acl;
839 + bh = sb_bread(sb, block);
843 + ea_bdebug(bh, "b_count=%d, refcount=%d",
844 + atomic_read(&(bh->b_count)),
845 + le32_to_cpu(HDR(bh)->h_refcount));
847 + end = bh->b_data + bh->b_size;
848 + if (header->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
849 + header->h_blocks != cpu_to_le32(1)) {
850 +bad_block: ext3_error(sb, "ext3_xattr_set",
851 + "inode %ld: bad block %d", inode->i_ino, block);
855 + /* Find the named attribute. */
856 + here = FIRST_ENTRY(bh);
857 + while (!IS_LAST_ENTRY(here)) {
858 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(here);
859 + if ((char *)next >= end)
861 + if (!here->e_value_block && here->e_value_size) {
862 + int offs = le16_to_cpu(here->e_value_offs);
863 + if (offs < min_offs)
866 + not_found = name_index - here->e_name_index;
868 + not_found = name_len - here->e_name_len;
870 + not_found = memcmp(name, here->e_name,name_len);
871 + if (not_found <= 0)
876 + /* We still need to compute min_offs and last. */
877 + while (!IS_LAST_ENTRY(last)) {
878 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
879 + if ((char *)next >= end)
881 + if (!last->e_value_block && last->e_value_size) {
882 + int offs = le16_to_cpu(last->e_value_offs);
883 + if (offs < min_offs)
889 + /* Check whether we have enough space left. */
890 + free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
892 + /* We will use a new extended attribute block. */
893 + free = sb->s_blocksize -
894 + sizeof(struct ext3_xattr_header) - sizeof(__u32);
895 + here = last = NULL; /* avoid gcc uninitialized warning. */
899 + /* Request to remove a nonexistent attribute? */
901 + if (flags & XATTR_REPLACE)
907 + free -= EXT3_XATTR_LEN(name_len);
909 + /* Request to create an existing attribute? */
911 + if (flags & XATTR_CREATE)
913 + if (!here->e_value_block && here->e_value_size) {
914 + unsigned int size = le32_to_cpu(here->e_value_size);
916 + if (le16_to_cpu(here->e_value_offs) + size >
917 + sb->s_blocksize || size > sb->s_blocksize)
919 + free += EXT3_XATTR_SIZE(size);
922 + free -= EXT3_XATTR_SIZE(value_len);
927 + /* Here we know that we can set the new attribute. */
930 + if (header->h_refcount == cpu_to_le32(1)) {
931 + ea_bdebug(bh, "modifying in-place");
932 + ext3_xattr_cache_remove(bh);
933 + error = ext3_journal_get_write_access(handle, bh);
939 + ea_bdebug(bh, "cloning");
940 + header = kmalloc(bh->b_size, GFP_KERNEL);
942 + if (header == NULL)
944 + memcpy(header, HDR(bh), bh->b_size);
945 + header->h_refcount = cpu_to_le32(1);
946 + offset = (char *)header - bh->b_data;
947 + here = ENTRY((char *)here + offset);
948 + last = ENTRY((char *)last + offset);
951 + /* Allocate a buffer where we construct the new block. */
952 + header = kmalloc(sb->s_blocksize, GFP_KERNEL);
954 + if (header == NULL)
956 + memset(header, 0, sb->s_blocksize);
957 + end = (char *)header + sb->s_blocksize;
958 + header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC);
959 + header->h_blocks = header->h_refcount = cpu_to_le32(1);
960 + last = here = ENTRY(header+1);
964 + /* Insert the new name. */
965 + int size = EXT3_XATTR_LEN(name_len);
966 + int rest = (char *)last - (char *)here;
967 + memmove((char *)here + size, here, rest);
968 + memset(here, 0, size);
969 + here->e_name_index = name_index;
970 + here->e_name_len = name_len;
971 + memcpy(here->e_name, name, name_len);
973 + /* Remove the old value. */
974 + if (!here->e_value_block && here->e_value_size) {
975 + char *first_val = (char *)header + min_offs;
976 + int offs = le16_to_cpu(here->e_value_offs);
977 + char *val = (char *)header + offs;
978 + size_t size = EXT3_XATTR_SIZE(
979 + le32_to_cpu(here->e_value_size));
980 + memmove(first_val + size, first_val, val - first_val);
981 + memset(first_val, 0, size);
982 + here->e_value_offs = 0;
985 + /* Adjust all value offsets. */
986 + last = ENTRY(header+1);
987 + while (!IS_LAST_ENTRY(last)) {
988 + int o = le16_to_cpu(last->e_value_offs);
989 + if (!last->e_value_block && o < offs)
990 + last->e_value_offs =
991 + cpu_to_le16(o + size);
992 + last = EXT3_XATTR_NEXT(last);
995 + if (value == NULL) {
996 + /* Remove this attribute. */
997 + if (EXT3_XATTR_NEXT(ENTRY(header+1)) == last) {
998 + /* This block is now empty. */
999 + error = ext3_xattr_set2(handle, inode, bh,NULL);
1002 + /* Remove the old name. */
1003 + int size = EXT3_XATTR_LEN(name_len);
1004 + last = ENTRY((char *)last - size);
1005 + memmove(here, (char*)here + size,
1006 + (char*)last - (char*)here);
1007 + memset(last, 0, size);
1012 + if (value != NULL) {
1013 + /* Insert the new value. */
1014 + here->e_value_size = cpu_to_le32(value_len);
1016 + size_t size = EXT3_XATTR_SIZE(value_len);
1017 + char *val = (char *)header + min_offs - size;
1018 + here->e_value_offs =
1019 + cpu_to_le16((char *)val - (char *)header);
1020 + memset(val + size - EXT3_XATTR_PAD, 0,
1021 + EXT3_XATTR_PAD); /* Clear the pad bytes. */
1022 + memcpy(val, value, value_len);
1025 + ext3_xattr_rehash(header, here);
1027 + error = ext3_xattr_set2(handle, inode, bh, header);
1031 + if (!(bh && header == HDR(bh)))
1033 + ext3_xattr_unlock();
1039 + * Second half of ext3_xattr_set(): Update the file system.
1042 +ext3_xattr_set2(handle_t *handle, struct inode *inode,
1043 + struct buffer_head *old_bh, struct ext3_xattr_header *header)
1045 + struct super_block *sb = inode->i_sb;
1046 + struct buffer_head *new_bh = NULL;
1050 + new_bh = ext3_xattr_cache_find(inode, header);
1053 + * We found an identical block in the cache.
1054 + * The old block will be released after updating
1057 + ea_bdebug(old_bh, "reusing block %ld",
1058 + new_bh->b_blocknr);
1061 + if (ext3_xattr_quota_alloc(inode, 1))
1064 + error = ext3_journal_get_write_access(handle, new_bh);
1067 + HDR(new_bh)->h_refcount = cpu_to_le32(
1068 + le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
1069 + ea_bdebug(new_bh, "refcount now=%d",
1070 + le32_to_cpu(HDR(new_bh)->h_refcount));
1071 + } else if (old_bh && header == HDR(old_bh)) {
1072 + /* Keep this block. */
1074 + (void)ext3_xattr_cache_insert(new_bh);
1076 + /* We need to allocate a new block */
1077 + int force = EXT3_I(inode)->i_file_acl != 0;
1078 + int block = ext3_xattr_new_block(handle, inode,
1082 + ea_idebug(inode, "creating block %d", block);
1084 + new_bh = sb_getblk(sb, block);
1086 +getblk_failed: ext3_xattr_free_block(handle, inode, block);
1090 + lock_buffer(new_bh);
1091 + error = ext3_journal_get_create_access(handle, new_bh);
1093 + unlock_buffer(new_bh);
1094 + goto getblk_failed;
1096 + memcpy(new_bh->b_data, header, new_bh->b_size);
1097 + mark_buffer_uptodate(new_bh, 1);
1098 + unlock_buffer(new_bh);
1099 + (void)ext3_xattr_cache_insert(new_bh);
1100 + ext3_xattr_update_super_block(handle, sb);
1102 + error = ext3_journal_dirty_metadata(handle, new_bh);
1107 + /* Update the inode. */
1108 + EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
1109 + inode->i_ctime = CURRENT_TIME;
1110 + ext3_mark_inode_dirty(handle, inode);
1111 + if (IS_SYNC(inode))
1112 + handle->h_sync = 1;
1115 + if (old_bh && old_bh != new_bh) {
1117 + * If there was an old block, and we are not still using it,
1118 + * we now release the old block.
1120 + unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
1122 + error = ext3_journal_get_write_access(handle, old_bh);
1125 + if (refcount == 1) {
1126 + /* Free the old block. */
1127 + ea_bdebug(old_bh, "freeing");
1128 + ext3_xattr_free_block(handle, inode, old_bh->b_blocknr);
1130 + /* ext3_forget() calls bforget() for us, but we
1131 + let our caller release old_bh, so we need to
1132 + duplicate the handle before. */
1134 + ext3_forget(handle, 1, inode, old_bh,old_bh->b_blocknr);
1136 + /* Decrement the refcount only. */
1138 + HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
1139 + ext3_xattr_quota_free(inode);
1140 + ext3_journal_dirty_metadata(handle, old_bh);
1141 + ea_bdebug(old_bh, "refcount now=%d", refcount);
1146 + if (old_bh != new_bh)
1153 + * ext3_xattr_drop_inode()
1155 + * Free extended attribute resources associated with this inode. This
1156 + * is called immediately before an inode is freed.
1159 +ext3_xattr_drop_inode(handle_t *handle, struct inode *inode)
1161 + struct buffer_head *bh;
1162 + unsigned int block = EXT3_I(inode)->i_file_acl;
1166 + ext3_xattr_lock();
1168 + bh = sb_bread(inode->i_sb, block);
1170 + ext3_error(inode->i_sb, "ext3_xattr_drop_inode",
1171 + "inode %ld: block %d read error", inode->i_ino, block);
1174 + ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
1175 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
1176 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1177 + ext3_error(inode->i_sb, "ext3_xattr_drop_inode",
1178 + "inode %ld: bad block %d", inode->i_ino, block);
1181 + ext3_journal_get_write_access(handle, bh);
1182 + ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
1183 + if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
1184 + ext3_xattr_cache_remove(bh);
1185 + ext3_xattr_free_block(handle, inode, block);
1186 + ext3_forget(handle, 1, inode, bh, block);
1189 + HDR(bh)->h_refcount = cpu_to_le32(
1190 + le32_to_cpu(HDR(bh)->h_refcount) - 1);
1191 + ext3_journal_dirty_metadata(handle, bh);
1192 + if (IS_SYNC(inode))
1193 + handle->h_sync = 1;
1194 + ext3_xattr_quota_free(inode);
1196 + EXT3_I(inode)->i_file_acl = 0;
1200 + ext3_xattr_unlock();
1204 + * ext3_xattr_put_super()
1206 + * This is called when a file system is unmounted.
1209 +ext3_xattr_put_super(struct super_block *sb)
1211 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
1212 + mb_cache_shrink(ext3_xattr_cache, sb->s_dev);
1216 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
1219 + * ext3_xattr_cache_insert()
1221 + * Create a new entry in the extended attribute cache, and insert
1222 + * it unless such an entry is already in the cache.
1224 + * Returns 0, or a negative error number on failure.
1227 +ext3_xattr_cache_insert(struct buffer_head *bh)
1229 + __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
1230 + struct mb_cache_entry *ce;
1233 + ce = mb_cache_entry_alloc(ext3_xattr_cache);
1236 + error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
1238 + mb_cache_entry_free(ce);
1239 + if (error == -EBUSY) {
1240 + ea_bdebug(bh, "already in cache (%d cache entries)",
1241 + atomic_read(&ext3_xattr_cache->c_entry_count));
1245 + ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
1246 + atomic_read(&ext3_xattr_cache->c_entry_count));
1247 + mb_cache_entry_release(ce);
1253 + * ext3_xattr_cmp()
1255 + * Compare two extended attribute blocks for equality.
1257 + * Returns 0 if the blocks are equal, 1 if they differ, and
1258 + * a negative error number on errors.
1261 +ext3_xattr_cmp(struct ext3_xattr_header *header1,
1262 + struct ext3_xattr_header *header2)
1264 + struct ext3_xattr_entry *entry1, *entry2;
1266 + entry1 = ENTRY(header1+1);
1267 + entry2 = ENTRY(header2+1);
1268 + while (!IS_LAST_ENTRY(entry1)) {
1269 + if (IS_LAST_ENTRY(entry2))
1271 + if (entry1->e_hash != entry2->e_hash ||
1272 + entry1->e_name_len != entry2->e_name_len ||
1273 + entry1->e_value_size != entry2->e_value_size ||
1274 + memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
1276 + if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
1278 + if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
1279 + (char *)header2 + le16_to_cpu(entry2->e_value_offs),
1280 + le32_to_cpu(entry1->e_value_size)))
1283 + entry1 = EXT3_XATTR_NEXT(entry1);
1284 + entry2 = EXT3_XATTR_NEXT(entry2);
1286 + if (!IS_LAST_ENTRY(entry2))
1292 + * ext3_xattr_cache_find()
1294 + * Find an identical extended attribute block.
1296 + * Returns a pointer to the block found, or NULL if such a block was
1297 + * not found or an error occurred.
1299 +static struct buffer_head *
1300 +ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header)
1302 + __u32 hash = le32_to_cpu(header->h_hash);
1303 + struct mb_cache_entry *ce;
1305 + if (!header->h_hash)
1306 + return NULL; /* never share */
1307 + ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
1308 + ce = mb_cache_entry_find_first(ext3_xattr_cache, 0, inode->i_dev, hash);
1310 + struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
1313 + ext3_error(inode->i_sb, "ext3_xattr_cache_find",
1314 + "inode %ld: block %ld read error",
1315 + inode->i_ino, ce->e_block);
1316 + } else if (le32_to_cpu(HDR(bh)->h_refcount) >
1317 + EXT3_XATTR_REFCOUNT_MAX) {
1318 + ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
1319 + le32_to_cpu(HDR(bh)->h_refcount),
1320 + EXT3_XATTR_REFCOUNT_MAX);
1321 + } else if (!ext3_xattr_cmp(header, HDR(bh))) {
1322 + ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
1323 + mb_cache_entry_release(ce);
1327 + ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
1333 + * ext3_xattr_cache_remove()
1335 + * Remove the cache entry of a block from the cache. Called when a
1336 + * block becomes invalid.
1339 +ext3_xattr_cache_remove(struct buffer_head *bh)
1341 + struct mb_cache_entry *ce;
1343 + ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_dev, bh->b_blocknr);
1345 + ea_bdebug(bh, "removing (%d cache entries remaining)",
1346 + atomic_read(&ext3_xattr_cache->c_entry_count)-1);
1347 + mb_cache_entry_free(ce);
1349 + ea_bdebug(bh, "no cache entry");
1352 +#define NAME_HASH_SHIFT 5
1353 +#define VALUE_HASH_SHIFT 16
1356 + * ext3_xattr_hash_entry()
1358 + * Compute the hash of an extended attribute.
1360 +static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
1361 + struct ext3_xattr_entry *entry)
1364 + char *name = entry->e_name;
1367 + for (n=0; n < entry->e_name_len; n++) {
1368 + hash = (hash << NAME_HASH_SHIFT) ^
1369 + (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
1373 + if (entry->e_value_block == 0 && entry->e_value_size != 0) {
1374 + __u32 *value = (__u32 *)((char *)header +
1375 + le16_to_cpu(entry->e_value_offs));
1376 + for (n = (le32_to_cpu(entry->e_value_size) +
1377 + EXT3_XATTR_ROUND) >> EXT3_XATTR_PAD_BITS; n; n--) {
1378 + hash = (hash << VALUE_HASH_SHIFT) ^
1379 + (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
1380 + le32_to_cpu(*value++);
1383 + entry->e_hash = cpu_to_le32(hash);
1386 +#undef NAME_HASH_SHIFT
1387 +#undef VALUE_HASH_SHIFT
1389 +#define BLOCK_HASH_SHIFT 16
1392 + * ext3_xattr_rehash()
1394 + * Re-compute the extended attribute hash value after an entry has changed.
1396 +static void ext3_xattr_rehash(struct ext3_xattr_header *header,
1397 + struct ext3_xattr_entry *entry)
1399 + struct ext3_xattr_entry *here;
1402 + ext3_xattr_hash_entry(header, entry);
1403 + here = ENTRY(header+1);
1404 + while (!IS_LAST_ENTRY(here)) {
1405 + if (!here->e_hash) {
1406 + /* Block is not shared if an entry's hash value == 0 */
1410 + hash = (hash << BLOCK_HASH_SHIFT) ^
1411 + (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
1412 + le32_to_cpu(here->e_hash);
1413 + here = EXT3_XATTR_NEXT(here);
1415 + header->h_hash = cpu_to_le32(hash);
1418 +#undef BLOCK_HASH_SHIFT
1421 +init_ext3_xattr(void)
1423 + ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL,
1424 + sizeof(struct mb_cache_entry) +
1425 + sizeof(struct mb_cache_entry_index), 1, 61);
1426 + if (!ext3_xattr_cache)
1433 +exit_ext3_xattr(void)
1435 + if (ext3_xattr_cache)
1436 + mb_cache_destroy(ext3_xattr_cache);
1437 + ext3_xattr_cache = NULL;
1440 +#else /* CONFIG_EXT3_FS_XATTR_SHARING */
1443 +init_ext3_xattr(void)
1449 +exit_ext3_xattr(void)
1453 +#endif /* CONFIG_EXT3_FS_XATTR_SHARING */
1454 --- linux-2.4.18-18/include/linux/ext3_fs.h~linux-2.4.18ea-0.8.26 2003-04-20 16:14:31.000000000 +0800
1455 +++ linux-2.4.18-18-root/include/linux/ext3_fs.h 2003-04-20 16:14:31.000000000 +0800
1458 #define EXT3_BAD_INO 1 /* Bad blocks inode */
1459 #define EXT3_ROOT_INO 2 /* Root inode */
1460 -#define EXT3_ACL_IDX_INO 3 /* ACL inode */
1461 -#define EXT3_ACL_DATA_INO 4 /* ACL inode */
1462 #define EXT3_BOOT_LOADER_INO 5 /* Boot loader inode */
1463 #define EXT3_UNDEL_DIR_INO 6 /* Undelete directory inode */
1464 #define EXT3_RESIZE_INO 7 /* Reserved group descriptors inode */
1467 # define EXT3_BLOCK_SIZE(s) (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
1469 -#define EXT3_ACLE_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_acl_entry))
1470 #define EXT3_ADDR_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (__u32))
1472 # define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
1473 @@ -124,28 +121,6 @@
1479 -struct ext3_acl_header /* Header of Access Control Lists */
1482 - __u32 aclh_file_count;
1483 - __u32 aclh_acle_count;
1484 - __u32 aclh_first_acle;
1487 -struct ext3_acl_entry /* Access Control List Entry */
1490 - __u16 acle_perms; /* Access permissions */
1491 - __u16 acle_type; /* Type of entry */
1492 - __u16 acle_tag; /* User or group identity */
1494 - __u32 acle_next; /* Pointer on next entry for the */
1495 - /* same inode or on next free entry */
1499 * Structure of a blocks group descriptor
1501 struct ext3_group_desc
1502 @@ -513,7 +488,7 @@ struct ext3_super_block {
1503 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
1504 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
1506 -#define EXT3_FEATURE_COMPAT_SUPP 0
1507 +#define EXT3_FEATURE_COMPAT_SUPP EXT3_FEATURE_COMPAT_EXT_ATTR
1508 #define EXT3_FEATURE_INCOMPAT_SUPP (EXT3_FEATURE_INCOMPAT_FILETYPE| \
1509 EXT3_FEATURE_INCOMPAT_RECOVER)
1510 #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
1511 @@ -606,6 +581,24 @@ struct ext3_iloc
1512 unsigned long block_group;
1515 +/* Defined for extended attributes */
1516 +#define CONFIG_EXT3_FS_XATTR y
1518 +#define ENOATTR ENODATA /* No such attribute */
1521 +#define ENOTSUP EOPNOTSUPP /* Operation not supported */
1523 +#ifndef XATTR_NAME_MAX
1524 +#define XATTR_NAME_MAX 255 /* # chars in an extended attribute name */
1525 +#define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */
1526 +#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */
1528 +#ifndef XATTR_CREATE
1529 +#define XATTR_CREATE 1 /* set value, fail if attr already exists */
1530 +#define XATTR_REPLACE 2 /* set value, fail if attr does not exist */
1534 * Function prototypes
1536 @@ -647,6 +640,7 @@ extern void ext3_check_inodes_bitmap (st
1537 extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
1540 +extern int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
1541 extern struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
1542 extern struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
1544 --- linux-2.4.18-18/include/linux/ext3_jbd.h~linux-2.4.18ea-0.8.26 2003-04-20 16:14:31.000000000 +0800
1545 +++ linux-2.4.18-18-root/include/linux/ext3_jbd.h 2003-04-20 16:14:31.000000000 +0800
1548 #define EXT3_SINGLEDATA_TRANS_BLOCKS 8
1550 +/* Extended attributes may touch two data buffers, two bitmap buffers,
1551 + * and two group and summaries. */
1553 +#define EXT3_XATTR_TRANS_BLOCKS 8
1555 /* Define the minimum size for a transaction which modifies data. This
1556 * needs to take into account the fact that we may end up modifying two
1557 * quota files too (one for the group, one for the user quota). The
1558 * superblock only gets updated once, of course, so don't bother
1559 * counting that again for the quota updates. */
1561 -#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS - 2)
1562 +#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS + \
1563 + EXT3_XATTR_TRANS_BLOCKS - 2)
1565 extern int ext3_writepage_trans_blocks(struct inode *inode);
1567 --- /dev/null 2002-08-31 07:31:37.000000000 +0800
1568 +++ linux-2.4.18-18-root/include/linux/ext3_xattr.h 2003-04-20 16:14:31.000000000 +0800
1571 + File: linux/ext3_xattr.h
1573 + On-disk format of extended attributes for the ext3 filesystem.
1575 + (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
1578 +#include <linux/config.h>
1579 +#include <linux/init.h>
1580 +#include <linux/xattr.h>
1582 +/* Magic value in attribute blocks */
1583 +#define EXT3_XATTR_MAGIC 0xEA020000
1585 +/* Maximum number of references to one attribute block */
1586 +#define EXT3_XATTR_REFCOUNT_MAX 1024
1589 +#define EXT3_XATTR_INDEX_MAX 10
1590 +#define EXT3_XATTR_INDEX_USER 1
1592 +struct ext3_xattr_header {
1593 + __u32 h_magic; /* magic number for identification */
1594 + __u32 h_refcount; /* reference count */
1595 + __u32 h_blocks; /* number of disk blocks used */
1596 + __u32 h_hash; /* hash value of all attributes */
1597 + __u32 h_reserved[4]; /* zero right now */
1600 +struct ext3_xattr_entry {
1601 + __u8 e_name_len; /* length of name */
1602 + __u8 e_name_index; /* attribute name index */
1603 + __u16 e_value_offs; /* offset in disk block of value */
1604 + __u32 e_value_block; /* disk block attribute is stored on (n/i) */
1605 + __u32 e_value_size; /* size of attribute value */
1606 + __u32 e_hash; /* hash value of name and value */
1607 + char e_name[0]; /* attribute name */
1610 +#define EXT3_XATTR_PAD_BITS 2
1611 +#define EXT3_XATTR_PAD (1<<EXT3_XATTR_PAD_BITS)
1612 +#define EXT3_XATTR_ROUND (EXT3_XATTR_PAD-1)
1613 +#define EXT3_XATTR_LEN(name_len) \
1614 + (((name_len) + EXT3_XATTR_ROUND + \
1615 + sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND)
1616 +#define EXT3_XATTR_NEXT(entry) \
1617 + ( (struct ext3_xattr_entry *)( \
1618 + (char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) )
1619 +#define EXT3_XATTR_SIZE(size) \
1620 + (((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND)
1624 +# ifdef CONFIG_EXT3_FS_XATTR
1626 +struct ext3_xattr_handler {
1628 + size_t (*list)(char *list, struct inode *inode, const char *name,
1630 + int (*get)(struct inode *inode, const char *name, void *buffer,
1632 + int (*set)(struct inode *inode, const char *name, void *buffer,
1633 + size_t size, int flags);
1636 +extern int ext3_xattr_register(int, struct ext3_xattr_handler *);
1637 +extern void ext3_xattr_unregister(int, struct ext3_xattr_handler *);
1639 +extern int ext3_setxattr(struct dentry *, const char *, void *, size_t, int);
1640 +extern ssize_t ext3_getxattr(struct dentry *, const char *, void *, size_t);
1641 +extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
1642 +extern int ext3_removexattr(struct dentry *, const char *);
1644 +extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
1645 +extern int ext3_xattr_list(struct inode *, char *, size_t);
1646 +extern int ext3_xattr_set(handle_t *handle, struct inode *, int, const char *, void *, size_t, int);
1648 +extern void ext3_xattr_drop_inode(handle_t *, struct inode *);
1649 +extern void ext3_xattr_put_super(struct super_block *);
1651 +extern int init_ext3_xattr(void) __init;
1652 +extern void exit_ext3_xattr(void);
1654 +# else /* CONFIG_EXT3_FS_XATTR */
1655 +# define ext3_setxattr NULL
1656 +# define ext3_getxattr NULL
1657 +# define ext3_listxattr NULL
1658 +# define ext3_removexattr NULL
1661 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
1662 + void *buffer, size_t size, int flags)
1668 +ext3_xattr_list(struct inode *inode, void *buffer, size_t size, int flags)
1674 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
1675 + const char *name, void *value, size_t size, int flags)
1681 +ext3_xattr_drop_inode(handle_t *handle, struct inode *inode)
1686 +ext3_xattr_put_super(struct super_block *sb)
1691 +init_ext3_xattr(void)
1697 +exit_ext3_xattr(void)
1701 +# endif /* CONFIG_EXT3_FS_XATTR */
1703 +# ifdef CONFIG_EXT3_FS_XATTR_USER
1705 +extern int init_ext3_xattr_user(void) __init;
1706 +extern void exit_ext3_xattr_user(void);
1708 +# else /* CONFIG_EXT3_FS_XATTR_USER */
1711 +init_ext3_xattr_user(void)
1717 +exit_ext3_xattr_user(void)
1721 +#endif /* CONFIG_EXT3_FS_XATTR_USER */
1723 +#endif /* __KERNEL__ */
1725 --- /dev/null 2002-08-31 07:31:37.000000000 +0800
1726 +++ linux-2.4.18-18-root/include/linux/xattr.h 2003-04-20 16:14:31.000000000 +0800
1729 + File: linux/xattr.h
1731 + Extended attributes handling.
1733 + Copyright (C) 2001 by Andreas Gruenbacher <a.gruenbacher@computer.org>
1734 + Copyright (C) 2001 SGI - Silicon Graphics, Inc <linux-xfs@oss.sgi.com>
1736 +#ifndef _LINUX_XATTR_H
1737 +#define _LINUX_XATTR_H
1739 +#define XATTR_CREATE 1 /* set value, fail if attr already exists */
1740 +#define XATTR_REPLACE 2 /* set value, fail if attr does not exist */
1742 +#endif /* _LINUX_XATTR_H */
1743 --- linux-2.4.18-18/fs/ext3/Makefile~linux-2.4.18ea-0.8.26 2003-04-20 16:14:54.000000000 +0800
1744 +++ linux-2.4.18-18-root/fs/ext3/Makefile 2003-04-20 16:15:15.000000000 +0800
1749 -export-objs := super.o inode.o
1750 +export-objs := super.o inode.o xattr.o
1752 obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
1753 - ioctl.o namei.o super.o symlink.o
1754 + ioctl.o namei.o super.o symlink.o xattr.o
1755 obj-m := $(O_TARGET)
1757 include $(TOPDIR)/Rules.make