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/ialloc.c linux-2.4.18ea/fs/ext3/ialloc.c
26 --- linux-2.4.18/fs/ext3/ialloc.c Sun Feb 24 04:42:59 2002
27 +++ linux-2.4.18ea/fs/ext3/ialloc.c Sun Feb 24 04:34:43 2002
29 #include <linux/jbd.h>
30 #include <linux/ext3_fs.h>
31 #include <linux/ext3_jbd.h>
32 +#include <linux/ext3_xattr.h>
33 #include <linux/stat.h>
34 #include <linux/string.h>
35 #include <linux/locks.h>
37 * as writing the quota to disk may need the lock as well.
40 + ext3_xattr_drop_inode(handle, inode);
41 DQUOT_FREE_INODE(inode);
44 diff -Nur linux-2.4.18/fs/ext3/inode.c linux-2.4.18ea/fs/ext3/inode.c
45 --- linux-2.4.18/fs/ext3/inode.c Sun Feb 24 04:42:59 2002
46 +++ linux-2.4.18ea/fs/ext3/inode.c Thu Mar 14 21:51:59 2002
49 #undef SEARCH_FROM_ZERO
52 + * Test whether an inode is a fast symlink.
54 +static inline int ext3_inode_is_fast_symlink(struct inode *inode)
56 + int ea_blocks = EXT3_I(inode)->i_file_acl ?
57 + (inode->i_sb->s_blocksize >> 9) : 0;
59 + return (S_ISLNK(inode->i_mode) &&
60 + inode->i_blocks - ea_blocks == 0);
63 /* The ext3 forget function must perform a revoke if we are freeing data
64 * which has been journaled. Metadata (eg. indirect blocks) must be
65 * revoked in all cases.
67 * still needs to be revoked.
70 -static int ext3_forget(handle_t *handle, int is_metadata,
71 +int ext3_forget(handle_t *handle, int is_metadata,
72 struct inode *inode, struct buffer_head *bh,
79 - if (is_bad_inode(inode) ||
80 - inode->i_ino == EXT3_ACL_IDX_INO ||
81 - inode->i_ino == EXT3_ACL_DATA_INO)
82 + if (is_bad_inode(inode))
87 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
88 S_ISLNK(inode->i_mode)))
90 + if (ext3_inode_is_fast_symlink(inode))
92 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
96 struct ext3_group_desc * gdp;
98 if ((inode->i_ino != EXT3_ROOT_INO &&
99 - inode->i_ino != EXT3_ACL_IDX_INO &&
100 - inode->i_ino != EXT3_ACL_DATA_INO &&
101 inode->i_ino != EXT3_JOURNAL_INO &&
102 inode->i_ino < EXT3_FIRST_INO(inode->i_sb)) ||
103 inode->i_ino > le32_to_cpu(
104 @@ -2120,10 +2130,7 @@
108 - if (inode->i_ino == EXT3_ACL_IDX_INO ||
109 - inode->i_ino == EXT3_ACL_DATA_INO)
110 - /* Nothing to do */ ;
111 - else if (S_ISREG(inode->i_mode)) {
112 + if (S_ISREG(inode->i_mode)) {
113 inode->i_op = &ext3_file_inode_operations;
114 inode->i_fop = &ext3_file_operations;
115 inode->i_mapping->a_ops = &ext3_aops;
116 @@ -2131,13 +2138,15 @@
117 inode->i_op = &ext3_dir_inode_operations;
118 inode->i_fop = &ext3_dir_operations;
119 } else if (S_ISLNK(inode->i_mode)) {
120 - if (!inode->i_blocks)
121 + if (ext3_inode_is_fast_symlink(inode))
122 inode->i_op = &ext3_fast_symlink_inode_operations;
124 - inode->i_op = &page_symlink_inode_operations;
125 + inode->i_op = &ext3_symlink_inode_operations;
126 inode->i_mapping->a_ops = &ext3_aops;
130 + inode->i_op = &ext3_special_inode_operations;
131 init_special_inode(inode, inode->i_mode,
132 le32_to_cpu(iloc.raw_inode->i_block[0]));
134 /* inode->i_attr_flags = 0; unused */
135 diff -Nur linux-2.4.18/fs/ext3/namei.c linux-2.4.18ea/fs/ext3/namei.c
136 --- linux-2.4.18/fs/ext3/namei.c Fri Nov 9 23:25:04 2001
137 +++ linux-2.4.18ea/fs/ext3/namei.c Mon Mar 11 03:27:00 2002
139 #include <linux/sched.h>
140 #include <linux/ext3_fs.h>
141 #include <linux/ext3_jbd.h>
142 +#include <linux/ext3_xattr.h>
143 #include <linux/fcntl.h>
144 #include <linux/stat.h>
145 #include <linux/string.h>
147 inode->i_mapping->a_ops = &ext3_aops;
148 ext3_mark_inode_dirty(handle, inode);
149 err = ext3_add_nondir(handle, dentry, inode);
151 + ext3_xattr_drop_inode(handle, inode);
153 ext3_journal_stop(handle, dir);
156 init_special_inode(inode, mode, rdev);
157 ext3_mark_inode_dirty(handle, inode);
158 err = ext3_add_nondir(handle, dentry, inode);
160 + ext3_xattr_drop_inode(handle, inode);
162 ext3_journal_stop(handle, dir);
168 - inode = ext3_new_inode (handle, dir, S_IFDIR);
169 + inode = ext3_new_inode (handle, dir, S_IFDIR | mode);
170 err = PTR_ERR(inode);
174 inode->i_op = &ext3_dir_inode_operations;
175 inode->i_fop = &ext3_dir_operations;
176 - inode->i_size = inode->u.ext3_i.i_disksize = inode->i_sb->s_blocksize;
177 - inode->i_blocks = 0;
178 + inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
179 dir_block = ext3_bread (handle, inode, 0, 1, &err);
181 inode->i_nlink--; /* is this nlink == 0? */
183 BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata");
184 ext3_journal_dirty_metadata(handle, dir_block);
186 - inode->i_mode = S_IFDIR | mode;
187 - if (dir->i_mode & S_ISGID)
188 - inode->i_mode |= S_ISGID;
189 ext3_mark_inode_dirty(handle, inode);
190 err = ext3_add_entry (handle, dentry, inode);
196 + ext3_xattr_drop_inode(handle, inode);
198 ext3_mark_inode_dirty(handle, inode);
203 - if (l > sizeof (inode->u.ext3_i.i_data)) {
204 - inode->i_op = &page_symlink_inode_operations;
205 + if (l > sizeof(EXT3_I(inode)->i_data)) {
206 + inode->i_op = &ext3_symlink_inode_operations;
207 inode->i_mapping->a_ops = &ext3_aops;
209 * block_symlink() calls back into ext3_prepare/commit_write.
210 diff -Nur linux-2.4.18/fs/ext3/super.c linux-2.4.18ea/fs/ext3/super.c
211 --- linux-2.4.18/fs/ext3/super.c Sun Feb 24 04:42:59 2002
212 +++ linux-2.4.18ea/fs/ext3/super.c Thu Apr 4 21:41:05 2002
214 #include <linux/jbd.h>
215 #include <linux/ext3_fs.h>
216 #include <linux/ext3_jbd.h>
217 +#include <linux/ext3_xattr.h>
218 #include <linux/slab.h>
219 #include <linux/init.h>
220 #include <linux/locks.h>
222 kdev_t j_dev = sbi->s_journal->j_dev;
225 + ext3_xattr_put_super(sb);
226 journal_destroy(sbi->s_journal);
227 if (!(sb->s_flags & MS_RDONLY)) {
228 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
229 @@ -1734,14 +1772,25 @@
231 static DECLARE_FSTYPE_DEV(ext3_fs_type, "ext3", ext3_read_super);
233 -static int __init init_ext3_fs(void)
234 +static void exit_ext3_fs(void)
236 - return register_filesystem(&ext3_fs_type);
237 + unregister_filesystem(&ext3_fs_type);
238 + exit_ext3_xattr_user();
242 -static void __exit exit_ext3_fs(void)
243 +static int __init init_ext3_fs(void)
245 - unregister_filesystem(&ext3_fs_type);
246 + int error = init_ext3_xattr();
248 + error = init_ext3_xattr_user();
250 + error = register_filesystem(&ext3_fs_type);
259 diff -Nur linux-2.4.18/fs/ext3/xattr.c linux-2.4.18ea/fs/ext3/xattr.c
260 --- linux-2.4.18/fs/ext3/xattr.c Thu Jan 1 01:00:00 1970
261 +++ linux-2.4.18ea/fs/ext3/xattr.c Wed Apr 3 13:19:05 2002
264 + * linux/fs/ext3/xattr.c
266 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
268 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
269 + * Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>.
270 + * Extended attributes for symlinks and special files added per
271 + * suggestion of Luka Renko <luka.renko@hermes.si>.
275 + * Extended attributes are stored on disk blocks allocated outside of
276 + * any inode. The i_file_acl field is then made to point to this allocated
277 + * block. If all extended attributes of an inode are identical, these
278 + * inodes may share the same extended attribute block. Such situations
279 + * are automatically detected by keeping a cache of recent attribute block
280 + * numbers and hashes over the block's contents in memory.
283 + * Extended attribute block layout:
285 + * +------------------+
288 + * | entry 2 | | growing downwards
290 + * | four null bytes |
293 + * | value 3 | | growing upwards
295 + * +------------------+
297 + * The block header is followed by multiple entry descriptors. These entry
298 + * descriptors are variable in size, and alligned to EXT3_XATTR_PAD
299 + * byte boundaries. The entry descriptors are sorted by attribute name,
300 + * so that two extended attribute blocks can be compared efficiently.
302 + * Attribute values are aligned to the end of the block, stored in
303 + * no specific order. They are also padded to EXT3_XATTR_PAD byte
304 + * boundaries. No additional gaps are left between them.
308 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
309 + * the xattr inode operations are called, so we are guaranteed that only one
310 + * processes accesses extended attributes of an inode at any time.
312 + * For writing we also grab the ext3_xattr_sem semaphore. This ensures that
313 + * only a single process is modifying an extended attribute block, even
314 + * if the block is shared among inodes.
316 + * Note for porting to 2.5
317 + * -----------------------
318 + * The BKL will no longer be held in the xattr inode operations.
321 +#include <linux/fs.h>
322 +#include <linux/locks.h>
323 +#include <linux/slab.h>
324 +#include <linux/ext3_jbd.h>
325 +#include <linux/ext3_fs.h>
326 +#include <linux/ext3_xattr.h>
327 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
328 +#include <linux/mbcache.h>
330 +#include <linux/quotaops.h>
331 +#include <asm/semaphore.h>
332 +#include <linux/compatmac.h>
333 +#include <linux/module.h>
335 +/* These symbols may be needed by a module. */
336 +EXPORT_SYMBOL(extN_xattr_register);
337 +EXPORT_SYMBOL(extN_xattr_unregister);
338 +EXPORT_SYMBOL(extN_xattr_get);
339 +EXPORT_SYMBOL(extN_xattr_list);
340 +EXPORT_SYMBOL(extN_xattr_set);
342 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
343 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
346 +#define HDR(bh) ((struct ext3_xattr_header *)((bh)->b_data))
347 +#define ENTRY(ptr) ((struct ext3_xattr_entry *)(ptr))
348 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
349 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
351 +#ifdef EXT3_XATTR_DEBUG
352 +# define ea_idebug(inode, f...) do { \
353 + printk(KERN_DEBUG "inode %s:%ld: ", \
354 + kdevname(inode->i_dev), inode->i_ino); \
358 +# define ea_bdebug(bh, f...) do { \
359 + printk(KERN_DEBUG "block %s:%ld: ", \
360 + kdevname(bh->b_dev), bh->b_blocknr); \
365 +# define ea_idebug(f...)
366 +# define ea_bdebug(f...)
369 +static int ext3_xattr_set2(handle_t *, struct inode *, struct buffer_head *,
370 + struct ext3_xattr_header *);
372 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
374 +static int ext3_xattr_cache_insert(struct buffer_head *);
375 +static struct buffer_head *ext3_xattr_cache_find(struct inode *,
376 + struct ext3_xattr_header *);
377 +static void ext3_xattr_cache_remove(struct buffer_head *);
378 +static void ext3_xattr_rehash(struct ext3_xattr_header *,
379 + struct ext3_xattr_entry *);
381 +static struct mb_cache *ext3_xattr_cache;
384 +# define ext3_xattr_cache_insert(bh) 0
385 +# define ext3_xattr_cache_find(inode, header) NULL
386 +# define ext3_xattr_cache_remove(bh) do {} while(0)
387 +# define ext3_xattr_rehash(header, entry) do {} while(0)
391 + * If a file system does not share extended attributes among inodes,
392 + * we should not need the ext3_xattr_sem semaphore. However, the
393 + * filesystem may still contain shared blocks, so we always take
397 +DECLARE_MUTEX(ext3_xattr_sem);
400 +ext3_xattr_lock(void)
402 + down(&ext3_xattr_sem);
406 +ext3_xattr_unlock(void)
408 + up(&ext3_xattr_sem);
412 +ext3_xattr_new_block(handle_t *handle, struct inode *inode,
413 + int * errp, int force)
415 + struct super_block *sb = inode->i_sb;
416 + int goal = le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block) +
417 + EXT3_I(inode)->i_block_group * EXT3_BLOCKS_PER_GROUP(sb);
419 + /* How can we enforce the allocation? */
420 + int block = ext3_new_block(handle, inode, goal, 0, 0, errp);
423 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
429 +ext3_xattr_quota_alloc(struct inode *inode, int force)
431 + /* How can we enforce the allocation? */
433 + int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
435 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
437 + int error = DQUOT_ALLOC_BLOCK(inode, 1);
445 +ext3_xattr_quota_free(struct inode *inode)
447 + DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
448 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
452 +ext3_xattr_free_block(handle_t *handle, struct inode * inode,
453 + unsigned long block)
455 + ext3_free_blocks(handle, inode, block, 1);
456 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
460 +# define ext3_xattr_quota_free(inode) \
461 + DQUOT_FREE_BLOCK(inode, 1)
462 +# define ext3_xattr_free_block(handle, inode, block) \
463 + ext3_free_blocks(handle, inode, block, 1)
466 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
468 +static inline struct buffer_head *
469 +sb_bread(struct super_block *sb, int block)
471 + return bread(sb->s_dev, block, sb->s_blocksize);
474 +static inline struct buffer_head *
475 +sb_getblk(struct super_block *sb, int block)
477 + return getblk(sb->s_dev, block, sb->s_blocksize);
482 +struct ext3_xattr_handler *ext3_xattr_handlers[EXT3_XATTR_INDEX_MAX];
483 +rwlock_t ext3_handler_lock = RW_LOCK_UNLOCKED;
486 +ext3_xattr_register(int name_index, struct ext3_xattr_handler *handler)
488 + int error = -EINVAL;
490 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
491 + write_lock(&ext3_handler_lock);
492 + if (!ext3_xattr_handlers[name_index-1]) {
493 + ext3_xattr_handlers[name_index-1] = handler;
496 + write_unlock(&ext3_handler_lock);
502 +ext3_xattr_unregister(int name_index, struct ext3_xattr_handler *handler)
504 + if (name_index > 0 || name_index <= EXT3_XATTR_INDEX_MAX) {
505 + write_lock(&ext3_handler_lock);
506 + ext3_xattr_handlers[name_index-1] = NULL;
507 + write_unlock(&ext3_handler_lock);
511 +static inline const char *
512 +strcmp_prefix(const char *a, const char *a_prefix)
514 + while (*a_prefix && *a == *a_prefix) {
518 + return *a_prefix ? NULL : a;
522 + * Decode the extended attribute name, and translate it into
523 + * the name_index and name suffix.
525 +static inline struct ext3_xattr_handler *
526 +ext3_xattr_resolve_name(const char **name)
528 + struct ext3_xattr_handler *handler = NULL;
533 + read_lock(&ext3_handler_lock);
534 + for (i=0; i<EXT3_XATTR_INDEX_MAX; i++) {
535 + if (ext3_xattr_handlers[i]) {
536 + const char *n = strcmp_prefix(*name,
537 + ext3_xattr_handlers[i]->prefix);
539 + handler = ext3_xattr_handlers[i];
545 + read_unlock(&ext3_handler_lock);
549 +static inline struct ext3_xattr_handler *
550 +ext3_xattr_handler(int name_index)
552 + struct ext3_xattr_handler *handler = NULL;
553 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
554 + read_lock(&ext3_handler_lock);
555 + handler = ext3_xattr_handlers[name_index-1];
556 + read_unlock(&ext3_handler_lock);
562 + * Inode operation getxattr()
564 + * dentry->d_inode->i_sem down
565 + * BKL held [before 2.5.x]
568 +ext3_getxattr(struct dentry *dentry, const char *name,
569 + void *buffer, size_t size)
571 + struct ext3_xattr_handler *handler;
572 + struct inode *inode = dentry->d_inode;
574 + handler = ext3_xattr_resolve_name(&name);
577 + return handler->get(inode, name, buffer, size);
581 + * Inode operation listxattr()
583 + * dentry->d_inode->i_sem down
584 + * BKL held [before 2.5.x]
587 +ext3_listxattr(struct dentry *dentry, char *buffer, size_t size)
589 + return ext3_xattr_list(dentry->d_inode, buffer, size);
593 + * Inode operation setxattr()
595 + * dentry->d_inode->i_sem down
596 + * BKL held [before 2.5.x]
599 +ext3_setxattr(struct dentry *dentry, const char *name,
600 + void *value, size_t size, int flags)
602 + struct ext3_xattr_handler *handler;
603 + struct inode *inode = dentry->d_inode;
606 + value = ""; /* empty EA, do not remove */
607 + handler = ext3_xattr_resolve_name(&name);
610 + return handler->set(inode, name, value, size, flags);
614 + * Inode operation removexattr()
616 + * dentry->d_inode->i_sem down
617 + * BKL held [before 2.5.x]
620 +ext3_removexattr(struct dentry *dentry, const char *name)
622 + struct ext3_xattr_handler *handler;
623 + struct inode *inode = dentry->d_inode;
625 + handler = ext3_xattr_resolve_name(&name);
628 + return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
634 + * Copy an extended attribute into the buffer
635 + * provided, or compute the buffer size required.
636 + * Buffer is NULL to compute the size of the buffer required.
638 + * Returns a negative error number on failure, or the number of bytes
639 + * used / required on success.
642 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
643 + void *buffer, size_t buffer_size)
645 + struct buffer_head *bh = NULL;
646 + struct ext3_xattr_entry *entry;
647 + unsigned int block, size;
649 + int name_len, error;
651 + ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
652 + name_index, name, buffer, (long)buffer_size);
656 + if (!EXT3_I(inode)->i_file_acl)
658 + block = EXT3_I(inode)->i_file_acl;
659 + ea_idebug(inode, "reading block %d", block);
660 + bh = sb_bread(inode->i_sb, block);
663 + ea_bdebug(bh, "b_count=%d, refcount=%d",
664 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
665 + end = bh->b_data + bh->b_size;
666 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
667 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
668 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_get",
669 + "inode %ld: bad block %d", inode->i_ino, block);
673 + /* find named attribute */
674 + name_len = strlen(name);
677 + if (name_len > 255)
679 + entry = FIRST_ENTRY(bh);
680 + while (!IS_LAST_ENTRY(entry)) {
681 + struct ext3_xattr_entry *next =
682 + EXT3_XATTR_NEXT(entry);
683 + if ((char *)next >= end)
685 + if (name_index == entry->e_name_index &&
686 + name_len == entry->e_name_len &&
687 + memcmp(name, entry->e_name, name_len) == 0)
691 + /* Check the remaining name entries */
692 + while (!IS_LAST_ENTRY(entry)) {
693 + struct ext3_xattr_entry *next =
694 + EXT3_XATTR_NEXT(entry);
695 + if ((char *)next >= end)
699 + if (ext3_xattr_cache_insert(bh))
700 + ea_idebug(inode, "cache insert failed");
704 + /* check the buffer size */
705 + if (entry->e_value_block != 0)
707 + size = le32_to_cpu(entry->e_value_size);
708 + if (size > inode->i_sb->s_blocksize ||
709 + le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
712 + if (ext3_xattr_cache_insert(bh))
713 + ea_idebug(inode, "cache insert failed");
716 + if (size > buffer_size)
718 + /* return value of attribute */
719 + memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
731 + * ext3_xattr_list()
733 + * Copy a list of attribute names into the buffer
734 + * provided, or compute the buffer size required.
735 + * Buffer is NULL to compute the size of the buffer required.
737 + * Returns a negative error number on failure, or the number of bytes
738 + * used / required on success.
741 +ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
743 + struct buffer_head *bh = NULL;
744 + struct ext3_xattr_entry *entry;
745 + unsigned int block, size = 0;
749 + ea_idebug(inode, "buffer=%p, buffer_size=%ld",
750 + buffer, (long)buffer_size);
752 + if (!EXT3_I(inode)->i_file_acl)
754 + block = EXT3_I(inode)->i_file_acl;
755 + ea_idebug(inode, "reading block %d", block);
756 + bh = sb_bread(inode->i_sb, block);
759 + ea_bdebug(bh, "b_count=%d, refcount=%d",
760 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
761 + end = bh->b_data + bh->b_size;
762 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
763 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
764 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_list",
765 + "inode %ld: bad block %d", inode->i_ino, block);
769 + /* compute the size required for the list of attribute names */
770 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
771 + entry = EXT3_XATTR_NEXT(entry)) {
772 + struct ext3_xattr_handler *handler;
773 + struct ext3_xattr_entry *next =
774 + EXT3_XATTR_NEXT(entry);
775 + if ((char *)next >= end)
778 + handler = ext3_xattr_handler(entry->e_name_index);
780 + size += handler->list(NULL, inode, entry->e_name,
781 + entry->e_name_len) + 1;
785 + if (ext3_xattr_cache_insert(bh))
786 + ea_idebug(inode, "cache insert failed");
792 + if (size > buffer_size)
796 + /* list the attribute names */
798 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
799 + entry = EXT3_XATTR_NEXT(entry)) {
800 + struct ext3_xattr_handler *handler;
802 + handler = ext3_xattr_handler(entry->e_name_index);
804 + buf += handler->list(buf, inode, entry->e_name,
805 + entry->e_name_len);
818 + * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is
821 +static void ext3_xattr_update_super_block(handle_t *handle,
822 + struct super_block *sb)
824 + if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR))
828 + ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh);
829 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
830 + EXT3_SB(sb)->s_feature_compat |= EXT3_FEATURE_COMPAT_EXT_ATTR;
832 + EXT3_SB(sb)->s_es->s_feature_compat |=
833 + cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR);
835 + ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
842 + * Create, replace or remove an extended attribute for this inode. Buffer
843 + * is NULL to remove an existing extended attribute, and non-NULL to
844 + * either replace an existing extended attribute, or create a new extended
845 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
846 + * specify that an extended attribute must exist and must not exist
847 + * previous to the call, respectively.
849 + * Returns 0, or a negative error number on failure.
852 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
853 + const char *name, void *value, size_t value_len, int flags)
855 + struct super_block *sb = inode->i_sb;
856 + struct buffer_head *bh = NULL;
857 + struct ext3_xattr_header *header = NULL;
858 + struct ext3_xattr_entry *here, *last;
859 + unsigned int name_len;
860 + int min_offs = sb->s_blocksize, not_found = 1, free, error;
864 + * header -- Points either into bh, or to a temporarily
865 + * allocated buffer.
866 + * here -- The named entry found, or the place for inserting, within
867 + * the block pointed to by header.
868 + * last -- Points right after the last named entry within the block
869 + * pointed to by header.
870 + * min_offs -- The offset of the first value (values are aligned
871 + * towards the end of the block).
872 + * end -- Points right after the block pointed to by header.
875 + ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
876 + name_index, name, value, (long)value_len);
878 + if (IS_RDONLY(inode))
880 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
886 + name_len = strlen(name);
887 + if (name_len > 255 || value_len > sb->s_blocksize)
891 + if (EXT3_I(inode)->i_file_acl) {
892 + /* The inode already has an extended attribute block. */
893 + int block = EXT3_I(inode)->i_file_acl;
895 + bh = sb_bread(sb, block);
899 + ea_bdebug(bh, "b_count=%d, refcount=%d",
900 + atomic_read(&(bh->b_count)),
901 + le32_to_cpu(HDR(bh)->h_refcount));
903 + end = bh->b_data + bh->b_size;
904 + if (header->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
905 + header->h_blocks != cpu_to_le32(1)) {
906 +bad_block: ext3_error(sb, "ext3_xattr_set",
907 + "inode %ld: bad block %d", inode->i_ino, block);
911 + /* Find the named attribute. */
912 + here = FIRST_ENTRY(bh);
913 + while (!IS_LAST_ENTRY(here)) {
914 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(here);
915 + if ((char *)next >= end)
917 + if (!here->e_value_block && here->e_value_size) {
918 + int offs = le16_to_cpu(here->e_value_offs);
919 + if (offs < min_offs)
922 + not_found = name_index - here->e_name_index;
924 + not_found = name_len - here->e_name_len;
926 + not_found = memcmp(name, here->e_name,name_len);
927 + if (not_found <= 0)
932 + /* We still need to compute min_offs and last. */
933 + while (!IS_LAST_ENTRY(last)) {
934 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
935 + if ((char *)next >= end)
937 + if (!last->e_value_block && last->e_value_size) {
938 + int offs = le16_to_cpu(last->e_value_offs);
939 + if (offs < min_offs)
945 + /* Check whether we have enough space left. */
946 + free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
948 + /* We will use a new extended attribute block. */
949 + free = sb->s_blocksize -
950 + sizeof(struct ext3_xattr_header) - sizeof(__u32);
951 + here = last = NULL; /* avoid gcc uninitialized warning. */
955 + /* Request to remove a nonexistent attribute? */
957 + if (flags & XATTR_REPLACE)
963 + free -= EXT3_XATTR_LEN(name_len);
965 + /* Request to create an existing attribute? */
967 + if (flags & XATTR_CREATE)
969 + if (!here->e_value_block && here->e_value_size) {
970 + unsigned int size = le32_to_cpu(here->e_value_size);
972 + if (le16_to_cpu(here->e_value_offs) + size >
973 + sb->s_blocksize || size > sb->s_blocksize)
975 + free += EXT3_XATTR_SIZE(size);
978 + free -= EXT3_XATTR_SIZE(value_len);
983 + /* Here we know that we can set the new attribute. */
986 + if (header->h_refcount == cpu_to_le32(1)) {
987 + ea_bdebug(bh, "modifying in-place");
988 + ext3_xattr_cache_remove(bh);
989 + error = ext3_journal_get_write_access(handle, bh);
995 + ea_bdebug(bh, "cloning");
996 + header = kmalloc(bh->b_size, GFP_KERNEL);
998 + if (header == NULL)
1000 + memcpy(header, HDR(bh), bh->b_size);
1001 + header->h_refcount = cpu_to_le32(1);
1002 + offset = (char *)header - bh->b_data;
1003 + here = ENTRY((char *)here + offset);
1004 + last = ENTRY((char *)last + offset);
1007 + /* Allocate a buffer where we construct the new block. */
1008 + header = kmalloc(sb->s_blocksize, GFP_KERNEL);
1010 + if (header == NULL)
1012 + memset(header, 0, sb->s_blocksize);
1013 + end = (char *)header + sb->s_blocksize;
1014 + header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC);
1015 + header->h_blocks = header->h_refcount = cpu_to_le32(1);
1016 + last = here = ENTRY(header+1);
1020 + /* Insert the new name. */
1021 + int size = EXT3_XATTR_LEN(name_len);
1022 + int rest = (char *)last - (char *)here;
1023 + memmove((char *)here + size, here, rest);
1024 + memset(here, 0, size);
1025 + here->e_name_index = name_index;
1026 + here->e_name_len = name_len;
1027 + memcpy(here->e_name, name, name_len);
1029 + /* Remove the old value. */
1030 + if (!here->e_value_block && here->e_value_size) {
1031 + char *first_val = (char *)header + min_offs;
1032 + int offs = le16_to_cpu(here->e_value_offs);
1033 + char *val = (char *)header + offs;
1034 + size_t size = EXT3_XATTR_SIZE(
1035 + le32_to_cpu(here->e_value_size));
1036 + memmove(first_val + size, first_val, val - first_val);
1037 + memset(first_val, 0, size);
1038 + here->e_value_offs = 0;
1041 + /* Adjust all value offsets. */
1042 + last = ENTRY(header+1);
1043 + while (!IS_LAST_ENTRY(last)) {
1044 + int o = le16_to_cpu(last->e_value_offs);
1045 + if (!last->e_value_block && o < offs)
1046 + last->e_value_offs =
1047 + cpu_to_le16(o + size);
1048 + last = EXT3_XATTR_NEXT(last);
1051 + if (value == NULL) {
1052 + /* Remove this attribute. */
1053 + if (EXT3_XATTR_NEXT(ENTRY(header+1)) == last) {
1054 + /* This block is now empty. */
1055 + error = ext3_xattr_set2(handle, inode, bh,NULL);
1058 + /* Remove the old name. */
1059 + int size = EXT3_XATTR_LEN(name_len);
1060 + last = ENTRY((char *)last - size);
1061 + memmove(here, (char*)here + size,
1062 + (char*)last - (char*)here);
1063 + memset(last, 0, size);
1068 + if (value != NULL) {
1069 + /* Insert the new value. */
1070 + here->e_value_size = cpu_to_le32(value_len);
1072 + size_t size = EXT3_XATTR_SIZE(value_len);
1073 + char *val = (char *)header + min_offs - size;
1074 + here->e_value_offs =
1075 + cpu_to_le16((char *)val - (char *)header);
1076 + memset(val + size - EXT3_XATTR_PAD, 0,
1077 + EXT3_XATTR_PAD); /* Clear the pad bytes. */
1078 + memcpy(val, value, value_len);
1081 + ext3_xattr_rehash(header, here);
1083 + error = ext3_xattr_set2(handle, inode, bh, header);
1087 + if (!(bh && header == HDR(bh)))
1089 + ext3_xattr_unlock();
1095 + * Second half of ext3_xattr_set(): Update the file system.
1098 +ext3_xattr_set2(handle_t *handle, struct inode *inode,
1099 + struct buffer_head *old_bh, struct ext3_xattr_header *header)
1101 + struct super_block *sb = inode->i_sb;
1102 + struct buffer_head *new_bh = NULL;
1106 + new_bh = ext3_xattr_cache_find(inode, header);
1109 + * We found an identical block in the cache.
1110 + * The old block will be released after updating
1113 + ea_bdebug(old_bh, "reusing block %ld",
1114 + new_bh->b_blocknr);
1117 + if (ext3_xattr_quota_alloc(inode, 1))
1120 + error = ext3_journal_get_write_access(handle, new_bh);
1123 + HDR(new_bh)->h_refcount = cpu_to_le32(
1124 + le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
1125 + ea_bdebug(new_bh, "refcount now=%d",
1126 + le32_to_cpu(HDR(new_bh)->h_refcount));
1127 + } else if (old_bh && header == HDR(old_bh)) {
1128 + /* Keep this block. */
1130 + (void)ext3_xattr_cache_insert(new_bh);
1132 + /* We need to allocate a new block */
1133 + int force = EXT3_I(inode)->i_file_acl != 0;
1134 + int block = ext3_xattr_new_block(handle, inode,
1138 + ea_idebug(inode, "creating block %d", block);
1140 + new_bh = sb_getblk(sb, block);
1142 +getblk_failed: ext3_xattr_free_block(handle, inode, block);
1146 + lock_buffer(new_bh);
1147 + error = ext3_journal_get_create_access(handle, new_bh);
1149 + unlock_buffer(new_bh);
1150 + goto getblk_failed;
1152 + memcpy(new_bh->b_data, header, new_bh->b_size);
1153 + mark_buffer_uptodate(new_bh, 1);
1154 + unlock_buffer(new_bh);
1155 + (void)ext3_xattr_cache_insert(new_bh);
1156 + ext3_xattr_update_super_block(handle, sb);
1158 + error = ext3_journal_dirty_metadata(handle, new_bh);
1163 + /* Update the inode. */
1164 + EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
1165 + inode->i_ctime = CURRENT_TIME;
1166 + ext3_mark_inode_dirty(handle, inode);
1167 + if (IS_SYNC(inode))
1168 + handle->h_sync = 1;
1171 + if (old_bh && old_bh != new_bh) {
1173 + * If there was an old block, and we are not still using it,
1174 + * we now release the old block.
1176 + unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
1178 + error = ext3_journal_get_write_access(handle, old_bh);
1181 + if (refcount == 1) {
1182 + /* Free the old block. */
1183 + ea_bdebug(old_bh, "freeing");
1184 + ext3_xattr_free_block(handle, inode, old_bh->b_blocknr);
1186 + /* ext3_forget() calls bforget() for us, but we
1187 + let our caller release old_bh, so we need to
1188 + duplicate the handle before. */
1190 + ext3_forget(handle, 1, inode, old_bh,old_bh->b_blocknr);
1192 + /* Decrement the refcount only. */
1194 + HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
1195 + ext3_xattr_quota_free(inode);
1196 + ext3_journal_dirty_metadata(handle, old_bh);
1197 + ea_bdebug(old_bh, "refcount now=%d", refcount);
1202 + if (old_bh != new_bh)
1209 + * ext3_xattr_drop_inode()
1211 + * Free extended attribute resources associated with this inode. This
1212 + * is called immediately before an inode is freed.
1215 +ext3_xattr_drop_inode(handle_t *handle, struct inode *inode)
1217 + struct buffer_head *bh;
1218 + unsigned int block = EXT3_I(inode)->i_file_acl;
1222 + ext3_xattr_lock();
1224 + bh = sb_bread(inode->i_sb, block);
1226 + ext3_error(inode->i_sb, "ext3_xattr_drop_inode",
1227 + "inode %ld: block %d read error", inode->i_ino, block);
1230 + ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
1231 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
1232 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1233 + ext3_error(inode->i_sb, "ext3_xattr_drop_inode",
1234 + "inode %ld: bad block %d", inode->i_ino, block);
1237 + ext3_journal_get_write_access(handle, bh);
1238 + ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
1239 + if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
1240 + ext3_xattr_cache_remove(bh);
1241 + ext3_xattr_free_block(handle, inode, block);
1242 + ext3_forget(handle, 1, inode, bh, block);
1245 + HDR(bh)->h_refcount = cpu_to_le32(
1246 + le32_to_cpu(HDR(bh)->h_refcount) - 1);
1247 + ext3_journal_dirty_metadata(handle, bh);
1248 + if (IS_SYNC(inode))
1249 + handle->h_sync = 1;
1250 + ext3_xattr_quota_free(inode);
1252 + EXT3_I(inode)->i_file_acl = 0;
1256 + ext3_xattr_unlock();
1260 + * ext3_xattr_put_super()
1262 + * This is called when a file system is unmounted.
1265 +ext3_xattr_put_super(struct super_block *sb)
1267 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
1268 + mb_cache_shrink(ext3_xattr_cache, sb->s_dev);
1272 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
1275 + * ext3_xattr_cache_insert()
1277 + * Create a new entry in the extended attribute cache, and insert
1278 + * it unless such an entry is already in the cache.
1280 + * Returns 0, or a negative error number on failure.
1283 +ext3_xattr_cache_insert(struct buffer_head *bh)
1285 + __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
1286 + struct mb_cache_entry *ce;
1289 + ce = mb_cache_entry_alloc(ext3_xattr_cache);
1292 + error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
1294 + mb_cache_entry_free(ce);
1295 + if (error == -EBUSY) {
1296 + ea_bdebug(bh, "already in cache (%d cache entries)",
1297 + atomic_read(&ext3_xattr_cache->c_entry_count));
1301 + ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
1302 + atomic_read(&ext3_xattr_cache->c_entry_count));
1303 + mb_cache_entry_release(ce);
1309 + * ext3_xattr_cmp()
1311 + * Compare two extended attribute blocks for equality.
1313 + * Returns 0 if the blocks are equal, 1 if they differ, and
1314 + * a negative error number on errors.
1317 +ext3_xattr_cmp(struct ext3_xattr_header *header1,
1318 + struct ext3_xattr_header *header2)
1320 + struct ext3_xattr_entry *entry1, *entry2;
1322 + entry1 = ENTRY(header1+1);
1323 + entry2 = ENTRY(header2+1);
1324 + while (!IS_LAST_ENTRY(entry1)) {
1325 + if (IS_LAST_ENTRY(entry2))
1327 + if (entry1->e_hash != entry2->e_hash ||
1328 + entry1->e_name_len != entry2->e_name_len ||
1329 + entry1->e_value_size != entry2->e_value_size ||
1330 + memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
1332 + if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
1334 + if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
1335 + (char *)header2 + le16_to_cpu(entry2->e_value_offs),
1336 + le32_to_cpu(entry1->e_value_size)))
1339 + entry1 = EXT3_XATTR_NEXT(entry1);
1340 + entry2 = EXT3_XATTR_NEXT(entry2);
1342 + if (!IS_LAST_ENTRY(entry2))
1348 + * ext3_xattr_cache_find()
1350 + * Find an identical extended attribute block.
1352 + * Returns a pointer to the block found, or NULL if such a block was
1353 + * not found or an error occurred.
1355 +static struct buffer_head *
1356 +ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header)
1358 + __u32 hash = le32_to_cpu(header->h_hash);
1359 + struct mb_cache_entry *ce;
1361 + if (!header->h_hash)
1362 + return NULL; /* never share */
1363 + ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
1364 + ce = mb_cache_entry_find_first(ext3_xattr_cache, 0, inode->i_dev, hash);
1366 + struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
1369 + ext3_error(inode->i_sb, "ext3_xattr_cache_find",
1370 + "inode %ld: block %ld read error",
1371 + inode->i_ino, ce->e_block);
1372 + } else if (le32_to_cpu(HDR(bh)->h_refcount) >
1373 + EXT3_XATTR_REFCOUNT_MAX) {
1374 + ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
1375 + le32_to_cpu(HDR(bh)->h_refcount),
1376 + EXT3_XATTR_REFCOUNT_MAX);
1377 + } else if (!ext3_xattr_cmp(header, HDR(bh))) {
1378 + ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
1379 + mb_cache_entry_release(ce);
1383 + ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
1389 + * ext3_xattr_cache_remove()
1391 + * Remove the cache entry of a block from the cache. Called when a
1392 + * block becomes invalid.
1395 +ext3_xattr_cache_remove(struct buffer_head *bh)
1397 + struct mb_cache_entry *ce;
1399 + ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_dev, bh->b_blocknr);
1401 + ea_bdebug(bh, "removing (%d cache entries remaining)",
1402 + atomic_read(&ext3_xattr_cache->c_entry_count)-1);
1403 + mb_cache_entry_free(ce);
1405 + ea_bdebug(bh, "no cache entry");
1408 +#define NAME_HASH_SHIFT 5
1409 +#define VALUE_HASH_SHIFT 16
1412 + * ext3_xattr_hash_entry()
1414 + * Compute the hash of an extended attribute.
1416 +static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
1417 + struct ext3_xattr_entry *entry)
1420 + char *name = entry->e_name;
1423 + for (n=0; n < entry->e_name_len; n++) {
1424 + hash = (hash << NAME_HASH_SHIFT) ^
1425 + (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
1429 + if (entry->e_value_block == 0 && entry->e_value_size != 0) {
1430 + __u32 *value = (__u32 *)((char *)header +
1431 + le16_to_cpu(entry->e_value_offs));
1432 + for (n = (le32_to_cpu(entry->e_value_size) +
1433 + EXT3_XATTR_ROUND) >> EXT3_XATTR_PAD_BITS; n; n--) {
1434 + hash = (hash << VALUE_HASH_SHIFT) ^
1435 + (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
1436 + le32_to_cpu(*value++);
1439 + entry->e_hash = cpu_to_le32(hash);
1442 +#undef NAME_HASH_SHIFT
1443 +#undef VALUE_HASH_SHIFT
1445 +#define BLOCK_HASH_SHIFT 16
1448 + * ext3_xattr_rehash()
1450 + * Re-compute the extended attribute hash value after an entry has changed.
1452 +static void ext3_xattr_rehash(struct ext3_xattr_header *header,
1453 + struct ext3_xattr_entry *entry)
1455 + struct ext3_xattr_entry *here;
1458 + ext3_xattr_hash_entry(header, entry);
1459 + here = ENTRY(header+1);
1460 + while (!IS_LAST_ENTRY(here)) {
1461 + if (!here->e_hash) {
1462 + /* Block is not shared if an entry's hash value == 0 */
1466 + hash = (hash << BLOCK_HASH_SHIFT) ^
1467 + (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
1468 + le32_to_cpu(here->e_hash);
1469 + here = EXT3_XATTR_NEXT(here);
1471 + header->h_hash = cpu_to_le32(hash);
1474 +#undef BLOCK_HASH_SHIFT
1477 +init_ext3_xattr(void)
1479 + ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL,
1480 + sizeof(struct mb_cache_entry) +
1481 + sizeof(struct mb_cache_entry_index), 1, 61);
1482 + if (!ext3_xattr_cache)
1489 +exit_ext3_xattr(void)
1491 + if (ext3_xattr_cache)
1492 + mb_cache_destroy(ext3_xattr_cache);
1493 + ext3_xattr_cache = NULL;
1496 +#else /* CONFIG_EXT3_FS_XATTR_SHARING */
1499 +init_ext3_xattr(void)
1505 +exit_ext3_xattr(void)
1509 +#endif /* CONFIG_EXT3_FS_XATTR_SHARING */
1510 diff -Nur linux-2.4.18/include/linux/ext3_fs.h linux-2.4.18ea/include/linux/ext3_fs.h
1511 --- linux-2.4.18/include/linux/ext3_fs.h Sun Feb 24 04:42:59 2002
1512 +++ linux-2.4.18ea/include/linux/ext3_fs.h Mon Mar 11 03:27:00 2002
1515 #define EXT3_BAD_INO 1 /* Bad blocks inode */
1516 #define EXT3_ROOT_INO 2 /* Root inode */
1517 -#define EXT3_ACL_IDX_INO 3 /* ACL inode */
1518 -#define EXT3_ACL_DATA_INO 4 /* ACL inode */
1519 #define EXT3_BOOT_LOADER_INO 5 /* Boot loader inode */
1520 #define EXT3_UNDEL_DIR_INO 6 /* Undelete directory inode */
1521 #define EXT3_RESIZE_INO 7 /* Reserved group descriptors inode */
1524 # define EXT3_BLOCK_SIZE(s) (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
1526 -#define EXT3_ACLE_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_acl_entry))
1527 #define EXT3_ADDR_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (__u32))
1529 # define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
1530 @@ -124,28 +121,6 @@
1536 -struct ext3_acl_header /* Header of Access Control Lists */
1539 - __u32 aclh_file_count;
1540 - __u32 aclh_acle_count;
1541 - __u32 aclh_first_acle;
1544 -struct ext3_acl_entry /* Access Control List Entry */
1547 - __u16 acle_perms; /* Access permissions */
1548 - __u16 acle_type; /* Type of entry */
1549 - __u16 acle_tag; /* User or group identity */
1551 - __u32 acle_next; /* Pointer on next entry for the */
1552 - /* same inode or on next free entry */
1556 * Structure of a blocks group descriptor
1558 struct ext3_group_desc
1560 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
1561 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
1563 -#define EXT3_FEATURE_COMPAT_SUPP 0
1564 +#define EXT3_FEATURE_COMPAT_SUPP EXT3_FEATURE_COMPAT_EXT_ATTR
1565 #define EXT3_FEATURE_INCOMPAT_SUPP (EXT3_FEATURE_INCOMPAT_FILETYPE| \
1566 EXT3_FEATURE_INCOMPAT_RECOVER)
1567 #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
1568 @@ -603,4 +578,22 @@
1571 +/* Defined for extended attributes */
1572 +#define CONFIG_EXT3_FS_XATTR y
1574 +#define ENOATTR ENODATA /* No such attribute */
1577 +#define ENOTSUP EOPNOTSUPP /* Operation not supported */
1579 +#ifndef XATTR_NAME_MAX
1580 +#define XATTR_NAME_MAX 255 /* # chars in an extended attribute name */
1581 +#define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */
1582 +#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */
1584 +#ifndef XATTR_CREATE
1585 +#define XATTR_CREATE 1 /* set value, fail if attr already exists */
1586 +#define XATTR_REPLACE 2 /* set value, fail if attr does not exist */
1590 * Ok, these declarations are also in <linux/kernel.h> but none of the
1592 extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
1595 +extern int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
1596 extern struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
1597 extern struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
1599 @@ -694,8 +670,10 @@
1602 extern struct inode_operations ext3_dir_inode_operations;
1603 +extern struct inode_operations ext3_special_inode_operations;
1606 +extern struct inode_operations ext3_symlink_inode_operations;
1607 extern struct inode_operations ext3_fast_symlink_inode_operations;
1610 diff -Nur linux-2.4.18/include/linux/ext3_jbd.h linux-2.4.18ea/include/linux/ext3_jbd.h
1611 --- linux-2.4.18/include/linux/ext3_jbd.h Fri Dec 21 18:42:03 2001
1612 +++ linux-2.4.18ea/include/linux/ext3_jbd.h Mon Mar 25 00:11:36 2002
1615 #define EXT3_SINGLEDATA_TRANS_BLOCKS 8
1617 +/* Extended attributes may touch two data buffers, two bitmap buffers,
1618 + * and two group and summaries. */
1620 +#define EXT3_XATTR_TRANS_BLOCKS 8
1622 /* Define the minimum size for a transaction which modifies data. This
1623 * needs to take into account the fact that we may end up modifying two
1624 * quota files too (one for the group, one for the user quota). The
1625 * superblock only gets updated once, of course, so don't bother
1626 * counting that again for the quota updates. */
1628 -#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS - 2)
1629 +#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS + \
1630 + EXT3_XATTR_TRANS_BLOCKS - 2)
1632 extern int ext3_writepage_trans_blocks(struct inode *inode);
1634 diff -Nur linux-2.4.18/include/linux/ext3_xattr.h linux-2.4.18ea/include/linux/ext3_xattr.h
1635 --- linux-2.4.18/include/linux/ext3_xattr.h Thu Jan 1 01:00:00 1970
1636 +++ linux-2.4.18ea/include/linux/ext3_xattr.h Fri Apr 5 10:08:01 2002
1639 + File: linux/ext3_xattr.h
1641 + On-disk format of extended attributes for the ext3 filesystem.
1643 + (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
1646 +#include <linux/config.h>
1647 +#include <linux/init.h>
1648 +#include <linux/xattr.h>
1650 +/* Magic value in attribute blocks */
1651 +#define EXT3_XATTR_MAGIC 0xEA020000
1653 +/* Maximum number of references to one attribute block */
1654 +#define EXT3_XATTR_REFCOUNT_MAX 1024
1657 +#define EXT3_XATTR_INDEX_MAX 10
1658 +#define EXT3_XATTR_INDEX_USER 1
1660 +struct ext3_xattr_header {
1661 + __u32 h_magic; /* magic number for identification */
1662 + __u32 h_refcount; /* reference count */
1663 + __u32 h_blocks; /* number of disk blocks used */
1664 + __u32 h_hash; /* hash value of all attributes */
1665 + __u32 h_reserved[4]; /* zero right now */
1668 +struct ext3_xattr_entry {
1669 + __u8 e_name_len; /* length of name */
1670 + __u8 e_name_index; /* attribute name index */
1671 + __u16 e_value_offs; /* offset in disk block of value */
1672 + __u32 e_value_block; /* disk block attribute is stored on (n/i) */
1673 + __u32 e_value_size; /* size of attribute value */
1674 + __u32 e_hash; /* hash value of name and value */
1675 + char e_name[0]; /* attribute name */
1678 +#define EXT3_XATTR_PAD_BITS 2
1679 +#define EXT3_XATTR_PAD (1<<EXT3_XATTR_PAD_BITS)
1680 +#define EXT3_XATTR_ROUND (EXT3_XATTR_PAD-1)
1681 +#define EXT3_XATTR_LEN(name_len) \
1682 + (((name_len) + EXT3_XATTR_ROUND + \
1683 + sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND)
1684 +#define EXT3_XATTR_NEXT(entry) \
1685 + ( (struct ext3_xattr_entry *)( \
1686 + (char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) )
1687 +#define EXT3_XATTR_SIZE(size) \
1688 + (((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND)
1692 +# ifdef CONFIG_EXT3_FS_XATTR
1694 +struct ext3_xattr_handler {
1696 + size_t (*list)(char *list, struct inode *inode, const char *name,
1698 + int (*get)(struct inode *inode, const char *name, void *buffer,
1700 + int (*set)(struct inode *inode, const char *name, void *buffer,
1701 + size_t size, int flags);
1704 +extern int ext3_xattr_register(int, struct ext3_xattr_handler *);
1705 +extern void ext3_xattr_unregister(int, struct ext3_xattr_handler *);
1707 +extern int ext3_setxattr(struct dentry *, const char *, void *, size_t, int);
1708 +extern ssize_t ext3_getxattr(struct dentry *, const char *, void *, size_t);
1709 +extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
1710 +extern int ext3_removexattr(struct dentry *, const char *);
1712 +extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
1713 +extern int ext3_xattr_list(struct inode *, char *, size_t);
1714 +extern int ext3_xattr_set(handle_t *handle, struct inode *, int, const char *, void *, size_t, int);
1716 +extern void ext3_xattr_drop_inode(handle_t *, struct inode *);
1717 +extern void ext3_xattr_put_super(struct super_block *);
1719 +extern int init_ext3_xattr(void) __init;
1720 +extern void exit_ext3_xattr(void);
1722 +# else /* CONFIG_EXT3_FS_XATTR */
1723 +# define ext3_setxattr NULL
1724 +# define ext3_getxattr NULL
1725 +# define ext3_listxattr NULL
1726 +# define ext3_removexattr NULL
1729 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
1730 + void *buffer, size_t size, int flags)
1736 +ext3_xattr_list(struct inode *inode, void *buffer, size_t size, int flags)
1742 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
1743 + const char *name, void *value, size_t size, int flags)
1749 +ext3_xattr_drop_inode(handle_t *handle, struct inode *inode)
1754 +ext3_xattr_put_super(struct super_block *sb)
1759 +init_ext3_xattr(void)
1765 +exit_ext3_xattr(void)
1769 +# endif /* CONFIG_EXT3_FS_XATTR */
1771 +# ifdef CONFIG_EXT3_FS_XATTR_USER
1773 +extern int init_ext3_xattr_user(void) __init;
1774 +extern void exit_ext3_xattr_user(void);
1776 +# else /* CONFIG_EXT3_FS_XATTR_USER */
1779 +init_ext3_xattr_user(void)
1785 +exit_ext3_xattr_user(void)
1789 +#endif /* CONFIG_EXT3_FS_XATTR_USER */
1791 +#endif /* __KERNEL__ */
1793 diff -Nur linux-2.4.18/include/linux/xattr.h linux-2.4.18ea/include/linux/xattr.h
1794 --- linux-2.4.18/include/linux/xattr.h Thu Jan 1 01:00:00 1970
1795 +++ linux-2.4.18ea/include/linux/xattr.h Sun Mar 24 23:42:21 2002
1798 + File: linux/xattr.h
1800 + Extended attributes handling.
1802 + Copyright (C) 2001 by Andreas Gruenbacher <a.gruenbacher@computer.org>
1803 + Copyright (C) 2001 SGI - Silicon Graphics, Inc <linux-xfs@oss.sgi.com>
1805 +#ifndef _LINUX_XATTR_H
1806 +#define _LINUX_XATTR_H
1808 +#define XATTR_CREATE 1 /* set value, fail if attr already exists */
1809 +#define XATTR_REPLACE 2 /* set value, fail if attr does not exist */
1811 +#endif /* _LINUX_XATTR_H */