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,7 +2138,7 @@
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 diff -Nur linux-2.4.18/fs/ext3/namei.c linux-2.4.18ea/fs/ext3/namei.c
126 --- linux-2.4.18/fs/ext3/namei.c Fri Nov 9 23:25:04 2001
127 +++ linux-2.4.18ea/fs/ext3/namei.c Mon Mar 11 03:27:00 2002
129 #include <linux/sched.h>
130 #include <linux/ext3_fs.h>
131 #include <linux/ext3_jbd.h>
132 +#include <linux/ext3_xattr.h>
133 #include <linux/fcntl.h>
134 #include <linux/stat.h>
135 #include <linux/string.h>
137 inode->i_fop = &extN_file_operations;
138 inode->i_mapping->a_ops = &ext3_aops;
139 err = ext3_add_nondir(handle, dentry, inode);
141 + ext3_xattr_drop_inode(handle, inode);
142 ext3_mark_inode_dirty(handle, inode);
144 ext3_journal_stop(handle, dir);
146 if (!IS_ERR(inode)) {
147 init_special_inode(inode, mode, rdev);
148 err = ext3_add_nondir(handle, dentry, inode);
150 + ext3_xattr_drop_inode(handle, inode);
151 ext3_mark_inode_dirty(handle, inode);
153 ext3_journal_stop(handle, dir);
158 - inode = ext3_new_inode (handle, dir, S_IFDIR);
159 + inode = ext3_new_inode (handle, dir, S_IFDIR | mode);
160 err = PTR_ERR(inode);
164 inode->i_op = &ext3_dir_inode_operations;
165 inode->i_fop = &ext3_dir_operations;
166 - inode->i_size = inode->u.ext3_i.i_disksize = inode->i_sb->s_blocksize;
167 - inode->i_blocks = 0;
168 + inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
169 dir_block = ext3_bread (handle, inode, 0, 1, &err);
171 inode->i_nlink--; /* is this nlink == 0? */
173 BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata");
174 ext3_journal_dirty_metadata(handle, dir_block);
176 - inode->i_mode = S_IFDIR | mode;
177 - if (dir->i_mode & S_ISGID)
178 - inode->i_mode |= S_ISGID;
179 ext3_mark_inode_dirty(handle, inode);
180 err = ext3_add_entry (handle, dentry, inode);
186 + ext3_xattr_drop_inode(handle, inode);
188 ext3_mark_inode_dirty(handle, inode);
193 - if (l > sizeof (inode->u.ext3_i.i_data)) {
194 + if (l > sizeof(EXT3_I(inode)->i_data)) {
195 inode->i_op = &page_symlink_inode_operations;
196 inode->i_mapping->a_ops = &ext3_aops;
197 diff -Nur linux-2.4.18/fs/ext3/super.c linux-2.4.18ea/fs/ext3/super.c
198 --- linux-2.4.18/fs/ext3/super.c Sun Feb 24 04:42:59 2002
199 +++ linux-2.4.18ea/fs/ext3/super.c Thu Apr 4 21:41:05 2002
201 #include <linux/jbd.h>
202 #include <linux/ext3_fs.h>
203 #include <linux/ext3_jbd.h>
204 +#include <linux/ext3_xattr.h>
205 #include <linux/slab.h>
206 #include <linux/init.h>
207 #include <linux/locks.h>
209 kdev_t j_dev = sbi->s_journal->j_dev;
212 + ext3_xattr_put_super(sb);
213 journal_destroy(sbi->s_journal);
214 if (!(sb->s_flags & MS_RDONLY)) {
215 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
216 @@ -1734,14 +1772,25 @@
218 static DECLARE_FSTYPE_DEV(ext3_fs_type, "ext3", ext3_read_super);
220 -static int __init init_ext3_fs(void)
221 +static void exit_ext3_fs(void)
223 - return register_filesystem(&ext3_fs_type);
224 + unregister_filesystem(&ext3_fs_type);
225 + exit_ext3_xattr_user();
229 -static void __exit exit_ext3_fs(void)
230 +static int __init init_ext3_fs(void)
232 - unregister_filesystem(&ext3_fs_type);
233 + int error = init_ext3_xattr();
235 + error = init_ext3_xattr_user();
237 + error = register_filesystem(&ext3_fs_type);
246 diff -Nur linux-2.4.18/fs/ext3/xattr.c linux-2.4.18ea/fs/ext3/xattr.c
247 --- linux-2.4.18/fs/ext3/xattr.c Thu Jan 1 01:00:00 1970
248 +++ linux-2.4.18ea/fs/ext3/xattr.c Wed Apr 3 13:19:05 2002
251 + * linux/fs/ext3/xattr.c
253 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
255 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
256 + * Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>.
257 + * Extended attributes for symlinks and special files added per
258 + * suggestion of Luka Renko <luka.renko@hermes.si>.
262 + * Extended attributes are stored on disk blocks allocated outside of
263 + * any inode. The i_file_acl field is then made to point to this allocated
264 + * block. If all extended attributes of an inode are identical, these
265 + * inodes may share the same extended attribute block. Such situations
266 + * are automatically detected by keeping a cache of recent attribute block
267 + * numbers and hashes over the block's contents in memory.
270 + * Extended attribute block layout:
272 + * +------------------+
275 + * | entry 2 | | growing downwards
277 + * | four null bytes |
280 + * | value 3 | | growing upwards
282 + * +------------------+
284 + * The block header is followed by multiple entry descriptors. These entry
285 + * descriptors are variable in size, and alligned to EXT3_XATTR_PAD
286 + * byte boundaries. The entry descriptors are sorted by attribute name,
287 + * so that two extended attribute blocks can be compared efficiently.
289 + * Attribute values are aligned to the end of the block, stored in
290 + * no specific order. They are also padded to EXT3_XATTR_PAD byte
291 + * boundaries. No additional gaps are left between them.
295 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
296 + * the xattr inode operations are called, so we are guaranteed that only one
297 + * processes accesses extended attributes of an inode at any time.
299 + * For writing we also grab the ext3_xattr_sem semaphore. This ensures that
300 + * only a single process is modifying an extended attribute block, even
301 + * if the block is shared among inodes.
303 + * Note for porting to 2.5
304 + * -----------------------
305 + * The BKL will no longer be held in the xattr inode operations.
308 +#include <linux/fs.h>
309 +#include <linux/locks.h>
310 +#include <linux/slab.h>
311 +#include <linux/ext3_jbd.h>
312 +#include <linux/ext3_fs.h>
313 +#include <linux/ext3_xattr.h>
314 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
315 +#include <linux/mbcache.h>
317 +#include <linux/quotaops.h>
318 +#include <asm/semaphore.h>
319 +#include <linux/compatmac.h>
320 +#include <linux/module.h>
322 +/* These symbols may be needed by a module. */
323 +EXPORT_SYMBOL(extN_xattr_register);
324 +EXPORT_SYMBOL(extN_xattr_unregister);
325 +EXPORT_SYMBOL(extN_xattr_get);
326 +EXPORT_SYMBOL(extN_xattr_list);
327 +EXPORT_SYMBOL(extN_xattr_set);
329 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
330 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
333 +#define HDR(bh) ((struct ext3_xattr_header *)((bh)->b_data))
334 +#define ENTRY(ptr) ((struct ext3_xattr_entry *)(ptr))
335 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
336 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
338 +#ifdef EXT3_XATTR_DEBUG
339 +# define ea_idebug(inode, f...) do { \
340 + printk(KERN_DEBUG "inode %s:%ld: ", \
341 + kdevname(inode->i_dev), inode->i_ino); \
345 +# define ea_bdebug(bh, f...) do { \
346 + printk(KERN_DEBUG "block %s:%ld: ", \
347 + kdevname(bh->b_dev), bh->b_blocknr); \
352 +# define ea_idebug(f...)
353 +# define ea_bdebug(f...)
356 +static int ext3_xattr_set2(handle_t *, struct inode *, struct buffer_head *,
357 + struct ext3_xattr_header *);
359 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
361 +static int ext3_xattr_cache_insert(struct buffer_head *);
362 +static struct buffer_head *ext3_xattr_cache_find(struct inode *,
363 + struct ext3_xattr_header *);
364 +static void ext3_xattr_cache_remove(struct buffer_head *);
365 +static void ext3_xattr_rehash(struct ext3_xattr_header *,
366 + struct ext3_xattr_entry *);
368 +static struct mb_cache *ext3_xattr_cache;
371 +# define ext3_xattr_cache_insert(bh) 0
372 +# define ext3_xattr_cache_find(inode, header) NULL
373 +# define ext3_xattr_cache_remove(bh) do {} while(0)
374 +# define ext3_xattr_rehash(header, entry) do {} while(0)
378 + * If a file system does not share extended attributes among inodes,
379 + * we should not need the ext3_xattr_sem semaphore. However, the
380 + * filesystem may still contain shared blocks, so we always take
384 +DECLARE_MUTEX(ext3_xattr_sem);
387 +ext3_xattr_lock(void)
389 + down(&ext3_xattr_sem);
393 +ext3_xattr_unlock(void)
395 + up(&ext3_xattr_sem);
399 +ext3_xattr_new_block(handle_t *handle, struct inode *inode,
400 + int * errp, int force)
402 + struct super_block *sb = inode->i_sb;
403 + int goal = le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block) +
404 + EXT3_I(inode)->i_block_group * EXT3_BLOCKS_PER_GROUP(sb);
406 + /* How can we enforce the allocation? */
407 + int block = ext3_new_block(handle, inode, goal, 0, 0, errp);
410 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
416 +ext3_xattr_quota_alloc(struct inode *inode, int force)
418 + /* How can we enforce the allocation? */
420 + int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
422 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
424 + int error = DQUOT_ALLOC_BLOCK(inode, 1);
432 +ext3_xattr_quota_free(struct inode *inode)
434 + DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
435 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
439 +ext3_xattr_free_block(handle_t *handle, struct inode * inode,
440 + unsigned long block)
442 + ext3_free_blocks(handle, inode, block, 1);
443 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
447 +# define ext3_xattr_quota_free(inode) \
448 + DQUOT_FREE_BLOCK(inode, 1)
449 +# define ext3_xattr_free_block(handle, inode, block) \
450 + ext3_free_blocks(handle, inode, block, 1)
453 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
455 +static inline struct buffer_head *
456 +sb_bread(struct super_block *sb, int block)
458 + return bread(sb->s_dev, block, sb->s_blocksize);
461 +static inline struct buffer_head *
462 +sb_getblk(struct super_block *sb, int block)
464 + return getblk(sb->s_dev, block, sb->s_blocksize);
469 +struct ext3_xattr_handler *ext3_xattr_handlers[EXT3_XATTR_INDEX_MAX];
470 +rwlock_t ext3_handler_lock = RW_LOCK_UNLOCKED;
473 +ext3_xattr_register(int name_index, struct ext3_xattr_handler *handler)
475 + int error = -EINVAL;
477 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
478 + write_lock(&ext3_handler_lock);
479 + if (!ext3_xattr_handlers[name_index-1]) {
480 + ext3_xattr_handlers[name_index-1] = handler;
483 + write_unlock(&ext3_handler_lock);
489 +ext3_xattr_unregister(int name_index, struct ext3_xattr_handler *handler)
491 + if (name_index > 0 || name_index <= EXT3_XATTR_INDEX_MAX) {
492 + write_lock(&ext3_handler_lock);
493 + ext3_xattr_handlers[name_index-1] = NULL;
494 + write_unlock(&ext3_handler_lock);
498 +static inline const char *
499 +strcmp_prefix(const char *a, const char *a_prefix)
501 + while (*a_prefix && *a == *a_prefix) {
505 + return *a_prefix ? NULL : a;
509 + * Decode the extended attribute name, and translate it into
510 + * the name_index and name suffix.
512 +static inline struct ext3_xattr_handler *
513 +ext3_xattr_resolve_name(const char **name)
515 + struct ext3_xattr_handler *handler = NULL;
520 + read_lock(&ext3_handler_lock);
521 + for (i=0; i<EXT3_XATTR_INDEX_MAX; i++) {
522 + if (ext3_xattr_handlers[i]) {
523 + const char *n = strcmp_prefix(*name,
524 + ext3_xattr_handlers[i]->prefix);
526 + handler = ext3_xattr_handlers[i];
532 + read_unlock(&ext3_handler_lock);
536 +static inline struct ext3_xattr_handler *
537 +ext3_xattr_handler(int name_index)
539 + struct ext3_xattr_handler *handler = NULL;
540 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
541 + read_lock(&ext3_handler_lock);
542 + handler = ext3_xattr_handlers[name_index-1];
543 + read_unlock(&ext3_handler_lock);
549 + * Inode operation getxattr()
551 + * dentry->d_inode->i_sem down
552 + * BKL held [before 2.5.x]
555 +ext3_getxattr(struct dentry *dentry, const char *name,
556 + void *buffer, size_t size)
558 + struct ext3_xattr_handler *handler;
559 + struct inode *inode = dentry->d_inode;
561 + handler = ext3_xattr_resolve_name(&name);
564 + return handler->get(inode, name, buffer, size);
568 + * Inode operation listxattr()
570 + * dentry->d_inode->i_sem down
571 + * BKL held [before 2.5.x]
574 +ext3_listxattr(struct dentry *dentry, char *buffer, size_t size)
576 + return ext3_xattr_list(dentry->d_inode, buffer, size);
580 + * Inode operation setxattr()
582 + * dentry->d_inode->i_sem down
583 + * BKL held [before 2.5.x]
586 +ext3_setxattr(struct dentry *dentry, const char *name,
587 + void *value, size_t size, int flags)
589 + struct ext3_xattr_handler *handler;
590 + struct inode *inode = dentry->d_inode;
593 + value = ""; /* empty EA, do not remove */
594 + handler = ext3_xattr_resolve_name(&name);
597 + return handler->set(inode, name, value, size, flags);
601 + * Inode operation removexattr()
603 + * dentry->d_inode->i_sem down
604 + * BKL held [before 2.5.x]
607 +ext3_removexattr(struct dentry *dentry, const char *name)
609 + struct ext3_xattr_handler *handler;
610 + struct inode *inode = dentry->d_inode;
612 + handler = ext3_xattr_resolve_name(&name);
615 + return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
621 + * Copy an extended attribute into the buffer
622 + * provided, or compute the buffer size required.
623 + * Buffer is NULL to compute the size of the buffer required.
625 + * Returns a negative error number on failure, or the number of bytes
626 + * used / required on success.
629 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
630 + void *buffer, size_t buffer_size)
632 + struct buffer_head *bh = NULL;
633 + struct ext3_xattr_entry *entry;
634 + unsigned int block, size;
636 + int name_len, error;
638 + ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
639 + name_index, name, buffer, (long)buffer_size);
643 + if (!EXT3_I(inode)->i_file_acl)
645 + block = EXT3_I(inode)->i_file_acl;
646 + ea_idebug(inode, "reading block %d", block);
647 + bh = sb_bread(inode->i_sb, block);
650 + ea_bdebug(bh, "b_count=%d, refcount=%d",
651 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
652 + end = bh->b_data + bh->b_size;
653 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
654 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
655 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_get",
656 + "inode %ld: bad block %d", inode->i_ino, block);
660 + /* find named attribute */
661 + name_len = strlen(name);
664 + if (name_len > 255)
666 + entry = FIRST_ENTRY(bh);
667 + while (!IS_LAST_ENTRY(entry)) {
668 + struct ext3_xattr_entry *next =
669 + EXT3_XATTR_NEXT(entry);
670 + if ((char *)next >= end)
672 + if (name_index == entry->e_name_index &&
673 + name_len == entry->e_name_len &&
674 + memcmp(name, entry->e_name, name_len) == 0)
678 + /* Check the remaining name entries */
679 + while (!IS_LAST_ENTRY(entry)) {
680 + struct ext3_xattr_entry *next =
681 + EXT3_XATTR_NEXT(entry);
682 + if ((char *)next >= end)
686 + if (ext3_xattr_cache_insert(bh))
687 + ea_idebug(inode, "cache insert failed");
691 + /* check the buffer size */
692 + if (entry->e_value_block != 0)
694 + size = le32_to_cpu(entry->e_value_size);
695 + if (size > inode->i_sb->s_blocksize ||
696 + le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
699 + if (ext3_xattr_cache_insert(bh))
700 + ea_idebug(inode, "cache insert failed");
703 + if (size > buffer_size)
705 + /* return value of attribute */
706 + memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
718 + * ext3_xattr_list()
720 + * Copy a list of attribute names into the buffer
721 + * provided, or compute the buffer size required.
722 + * Buffer is NULL to compute the size of the buffer required.
724 + * Returns a negative error number on failure, or the number of bytes
725 + * used / required on success.
728 +ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
730 + struct buffer_head *bh = NULL;
731 + struct ext3_xattr_entry *entry;
732 + unsigned int block, size = 0;
736 + ea_idebug(inode, "buffer=%p, buffer_size=%ld",
737 + buffer, (long)buffer_size);
739 + if (!EXT3_I(inode)->i_file_acl)
741 + block = EXT3_I(inode)->i_file_acl;
742 + ea_idebug(inode, "reading block %d", block);
743 + bh = sb_bread(inode->i_sb, block);
746 + ea_bdebug(bh, "b_count=%d, refcount=%d",
747 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
748 + end = bh->b_data + bh->b_size;
749 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
750 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
751 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_list",
752 + "inode %ld: bad block %d", inode->i_ino, block);
756 + /* compute the size required for the list of attribute names */
757 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
758 + entry = EXT3_XATTR_NEXT(entry)) {
759 + struct ext3_xattr_handler *handler;
760 + struct ext3_xattr_entry *next =
761 + EXT3_XATTR_NEXT(entry);
762 + if ((char *)next >= end)
765 + handler = ext3_xattr_handler(entry->e_name_index);
767 + size += handler->list(NULL, inode, entry->e_name,
768 + entry->e_name_len) + 1;
772 + if (ext3_xattr_cache_insert(bh))
773 + ea_idebug(inode, "cache insert failed");
779 + if (size > buffer_size)
783 + /* list the attribute names */
785 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
786 + entry = EXT3_XATTR_NEXT(entry)) {
787 + struct ext3_xattr_handler *handler;
789 + handler = ext3_xattr_handler(entry->e_name_index);
791 + buf += handler->list(buf, inode, entry->e_name,
792 + entry->e_name_len);
805 + * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is
808 +static void ext3_xattr_update_super_block(handle_t *handle,
809 + struct super_block *sb)
811 + if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR))
815 + ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh);
816 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
817 + EXT3_SB(sb)->s_feature_compat |= EXT3_FEATURE_COMPAT_EXT_ATTR;
819 + EXT3_SB(sb)->s_es->s_feature_compat |=
820 + cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR);
822 + ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
829 + * Create, replace or remove an extended attribute for this inode. Buffer
830 + * is NULL to remove an existing extended attribute, and non-NULL to
831 + * either replace an existing extended attribute, or create a new extended
832 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
833 + * specify that an extended attribute must exist and must not exist
834 + * previous to the call, respectively.
836 + * Returns 0, or a negative error number on failure.
839 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
840 + const char *name, void *value, size_t value_len, int flags)
842 + struct super_block *sb = inode->i_sb;
843 + struct buffer_head *bh = NULL;
844 + struct ext3_xattr_header *header = NULL;
845 + struct ext3_xattr_entry *here, *last;
846 + unsigned int name_len;
847 + int min_offs = sb->s_blocksize, not_found = 1, free, error;
851 + * header -- Points either into bh, or to a temporarily
852 + * allocated buffer.
853 + * here -- The named entry found, or the place for inserting, within
854 + * the block pointed to by header.
855 + * last -- Points right after the last named entry within the block
856 + * pointed to by header.
857 + * min_offs -- The offset of the first value (values are aligned
858 + * towards the end of the block).
859 + * end -- Points right after the block pointed to by header.
862 + ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
863 + name_index, name, value, (long)value_len);
865 + if (IS_RDONLY(inode))
867 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
873 + name_len = strlen(name);
874 + if (name_len > 255 || value_len > sb->s_blocksize)
878 + if (EXT3_I(inode)->i_file_acl) {
879 + /* The inode already has an extended attribute block. */
880 + int block = EXT3_I(inode)->i_file_acl;
882 + bh = sb_bread(sb, block);
886 + ea_bdebug(bh, "b_count=%d, refcount=%d",
887 + atomic_read(&(bh->b_count)),
888 + le32_to_cpu(HDR(bh)->h_refcount));
890 + end = bh->b_data + bh->b_size;
891 + if (header->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
892 + header->h_blocks != cpu_to_le32(1)) {
893 +bad_block: ext3_error(sb, "ext3_xattr_set",
894 + "inode %ld: bad block %d", inode->i_ino, block);
898 + /* Find the named attribute. */
899 + here = FIRST_ENTRY(bh);
900 + while (!IS_LAST_ENTRY(here)) {
901 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(here);
902 + if ((char *)next >= end)
904 + if (!here->e_value_block && here->e_value_size) {
905 + int offs = le16_to_cpu(here->e_value_offs);
906 + if (offs < min_offs)
909 + not_found = name_index - here->e_name_index;
911 + not_found = name_len - here->e_name_len;
913 + not_found = memcmp(name, here->e_name,name_len);
914 + if (not_found <= 0)
919 + /* We still need to compute min_offs and last. */
920 + while (!IS_LAST_ENTRY(last)) {
921 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
922 + if ((char *)next >= end)
924 + if (!last->e_value_block && last->e_value_size) {
925 + int offs = le16_to_cpu(last->e_value_offs);
926 + if (offs < min_offs)
932 + /* Check whether we have enough space left. */
933 + free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
935 + /* We will use a new extended attribute block. */
936 + free = sb->s_blocksize -
937 + sizeof(struct ext3_xattr_header) - sizeof(__u32);
938 + here = last = NULL; /* avoid gcc uninitialized warning. */
942 + /* Request to remove a nonexistent attribute? */
944 + if (flags & XATTR_REPLACE)
950 + free -= EXT3_XATTR_LEN(name_len);
952 + /* Request to create an existing attribute? */
954 + if (flags & XATTR_CREATE)
956 + if (!here->e_value_block && here->e_value_size) {
957 + unsigned int size = le32_to_cpu(here->e_value_size);
959 + if (le16_to_cpu(here->e_value_offs) + size >
960 + sb->s_blocksize || size > sb->s_blocksize)
962 + free += EXT3_XATTR_SIZE(size);
965 + free -= EXT3_XATTR_SIZE(value_len);
970 + /* Here we know that we can set the new attribute. */
973 + if (header->h_refcount == cpu_to_le32(1)) {
974 + ea_bdebug(bh, "modifying in-place");
975 + ext3_xattr_cache_remove(bh);
976 + error = ext3_journal_get_write_access(handle, bh);
982 + ea_bdebug(bh, "cloning");
983 + header = kmalloc(bh->b_size, GFP_KERNEL);
985 + if (header == NULL)
987 + memcpy(header, HDR(bh), bh->b_size);
988 + header->h_refcount = cpu_to_le32(1);
989 + offset = (char *)header - bh->b_data;
990 + here = ENTRY((char *)here + offset);
991 + last = ENTRY((char *)last + offset);
994 + /* Allocate a buffer where we construct the new block. */
995 + header = kmalloc(sb->s_blocksize, GFP_KERNEL);
997 + if (header == NULL)
999 + memset(header, 0, sb->s_blocksize);
1000 + end = (char *)header + sb->s_blocksize;
1001 + header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC);
1002 + header->h_blocks = header->h_refcount = cpu_to_le32(1);
1003 + last = here = ENTRY(header+1);
1007 + /* Insert the new name. */
1008 + int size = EXT3_XATTR_LEN(name_len);
1009 + int rest = (char *)last - (char *)here;
1010 + memmove((char *)here + size, here, rest);
1011 + memset(here, 0, size);
1012 + here->e_name_index = name_index;
1013 + here->e_name_len = name_len;
1014 + memcpy(here->e_name, name, name_len);
1016 + /* Remove the old value. */
1017 + if (!here->e_value_block && here->e_value_size) {
1018 + char *first_val = (char *)header + min_offs;
1019 + int offs = le16_to_cpu(here->e_value_offs);
1020 + char *val = (char *)header + offs;
1021 + size_t size = EXT3_XATTR_SIZE(
1022 + le32_to_cpu(here->e_value_size));
1023 + memmove(first_val + size, first_val, val - first_val);
1024 + memset(first_val, 0, size);
1025 + here->e_value_offs = 0;
1028 + /* Adjust all value offsets. */
1029 + last = ENTRY(header+1);
1030 + while (!IS_LAST_ENTRY(last)) {
1031 + int o = le16_to_cpu(last->e_value_offs);
1032 + if (!last->e_value_block && o < offs)
1033 + last->e_value_offs =
1034 + cpu_to_le16(o + size);
1035 + last = EXT3_XATTR_NEXT(last);
1038 + if (value == NULL) {
1039 + /* Remove this attribute. */
1040 + if (EXT3_XATTR_NEXT(ENTRY(header+1)) == last) {
1041 + /* This block is now empty. */
1042 + error = ext3_xattr_set2(handle, inode, bh,NULL);
1045 + /* Remove the old name. */
1046 + int size = EXT3_XATTR_LEN(name_len);
1047 + last = ENTRY((char *)last - size);
1048 + memmove(here, (char*)here + size,
1049 + (char*)last - (char*)here);
1050 + memset(last, 0, size);
1055 + if (value != NULL) {
1056 + /* Insert the new value. */
1057 + here->e_value_size = cpu_to_le32(value_len);
1059 + size_t size = EXT3_XATTR_SIZE(value_len);
1060 + char *val = (char *)header + min_offs - size;
1061 + here->e_value_offs =
1062 + cpu_to_le16((char *)val - (char *)header);
1063 + memset(val + size - EXT3_XATTR_PAD, 0,
1064 + EXT3_XATTR_PAD); /* Clear the pad bytes. */
1065 + memcpy(val, value, value_len);
1068 + ext3_xattr_rehash(header, here);
1070 + error = ext3_xattr_set2(handle, inode, bh, header);
1074 + if (!(bh && header == HDR(bh)))
1076 + ext3_xattr_unlock();
1082 + * Second half of ext3_xattr_set(): Update the file system.
1085 +ext3_xattr_set2(handle_t *handle, struct inode *inode,
1086 + struct buffer_head *old_bh, struct ext3_xattr_header *header)
1088 + struct super_block *sb = inode->i_sb;
1089 + struct buffer_head *new_bh = NULL;
1093 + new_bh = ext3_xattr_cache_find(inode, header);
1096 + * We found an identical block in the cache.
1097 + * The old block will be released after updating
1100 + ea_bdebug(old_bh, "reusing block %ld",
1101 + new_bh->b_blocknr);
1104 + if (ext3_xattr_quota_alloc(inode, 1))
1107 + error = ext3_journal_get_write_access(handle, new_bh);
1110 + HDR(new_bh)->h_refcount = cpu_to_le32(
1111 + le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
1112 + ea_bdebug(new_bh, "refcount now=%d",
1113 + le32_to_cpu(HDR(new_bh)->h_refcount));
1114 + } else if (old_bh && header == HDR(old_bh)) {
1115 + /* Keep this block. */
1117 + (void)ext3_xattr_cache_insert(new_bh);
1119 + /* We need to allocate a new block */
1120 + int force = EXT3_I(inode)->i_file_acl != 0;
1121 + int block = ext3_xattr_new_block(handle, inode,
1125 + ea_idebug(inode, "creating block %d", block);
1127 + new_bh = sb_getblk(sb, block);
1129 +getblk_failed: ext3_xattr_free_block(handle, inode, block);
1133 + lock_buffer(new_bh);
1134 + error = ext3_journal_get_create_access(handle, new_bh);
1136 + unlock_buffer(new_bh);
1137 + goto getblk_failed;
1139 + memcpy(new_bh->b_data, header, new_bh->b_size);
1140 + mark_buffer_uptodate(new_bh, 1);
1141 + unlock_buffer(new_bh);
1142 + (void)ext3_xattr_cache_insert(new_bh);
1143 + ext3_xattr_update_super_block(handle, sb);
1145 + error = ext3_journal_dirty_metadata(handle, new_bh);
1150 + /* Update the inode. */
1151 + EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
1152 + inode->i_ctime = CURRENT_TIME;
1153 + ext3_mark_inode_dirty(handle, inode);
1154 + if (IS_SYNC(inode))
1155 + handle->h_sync = 1;
1158 + if (old_bh && old_bh != new_bh) {
1160 + * If there was an old block, and we are not still using it,
1161 + * we now release the old block.
1163 + unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
1165 + error = ext3_journal_get_write_access(handle, old_bh);
1168 + if (refcount == 1) {
1169 + /* Free the old block. */
1170 + ea_bdebug(old_bh, "freeing");
1171 + ext3_xattr_free_block(handle, inode, old_bh->b_blocknr);
1173 + /* ext3_forget() calls bforget() for us, but we
1174 + let our caller release old_bh, so we need to
1175 + duplicate the handle before. */
1177 + ext3_forget(handle, 1, inode, old_bh,old_bh->b_blocknr);
1179 + /* Decrement the refcount only. */
1181 + HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
1182 + ext3_xattr_quota_free(inode);
1183 + ext3_journal_dirty_metadata(handle, old_bh);
1184 + ea_bdebug(old_bh, "refcount now=%d", refcount);
1189 + if (old_bh != new_bh)
1196 + * ext3_xattr_drop_inode()
1198 + * Free extended attribute resources associated with this inode. This
1199 + * is called immediately before an inode is freed.
1202 +ext3_xattr_drop_inode(handle_t *handle, struct inode *inode)
1204 + struct buffer_head *bh;
1205 + unsigned int block = EXT3_I(inode)->i_file_acl;
1209 + ext3_xattr_lock();
1211 + bh = sb_bread(inode->i_sb, block);
1213 + ext3_error(inode->i_sb, "ext3_xattr_drop_inode",
1214 + "inode %ld: block %d read error", inode->i_ino, block);
1217 + ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
1218 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
1219 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1220 + ext3_error(inode->i_sb, "ext3_xattr_drop_inode",
1221 + "inode %ld: bad block %d", inode->i_ino, block);
1224 + ext3_journal_get_write_access(handle, bh);
1225 + ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
1226 + if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
1227 + ext3_xattr_cache_remove(bh);
1228 + ext3_xattr_free_block(handle, inode, block);
1229 + ext3_forget(handle, 1, inode, bh, block);
1232 + HDR(bh)->h_refcount = cpu_to_le32(
1233 + le32_to_cpu(HDR(bh)->h_refcount) - 1);
1234 + ext3_journal_dirty_metadata(handle, bh);
1235 + if (IS_SYNC(inode))
1236 + handle->h_sync = 1;
1237 + ext3_xattr_quota_free(inode);
1239 + EXT3_I(inode)->i_file_acl = 0;
1243 + ext3_xattr_unlock();
1247 + * ext3_xattr_put_super()
1249 + * This is called when a file system is unmounted.
1252 +ext3_xattr_put_super(struct super_block *sb)
1254 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
1255 + mb_cache_shrink(ext3_xattr_cache, sb->s_dev);
1259 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
1262 + * ext3_xattr_cache_insert()
1264 + * Create a new entry in the extended attribute cache, and insert
1265 + * it unless such an entry is already in the cache.
1267 + * Returns 0, or a negative error number on failure.
1270 +ext3_xattr_cache_insert(struct buffer_head *bh)
1272 + __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
1273 + struct mb_cache_entry *ce;
1276 + ce = mb_cache_entry_alloc(ext3_xattr_cache);
1279 + error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
1281 + mb_cache_entry_free(ce);
1282 + if (error == -EBUSY) {
1283 + ea_bdebug(bh, "already in cache (%d cache entries)",
1284 + atomic_read(&ext3_xattr_cache->c_entry_count));
1288 + ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
1289 + atomic_read(&ext3_xattr_cache->c_entry_count));
1290 + mb_cache_entry_release(ce);
1296 + * ext3_xattr_cmp()
1298 + * Compare two extended attribute blocks for equality.
1300 + * Returns 0 if the blocks are equal, 1 if they differ, and
1301 + * a negative error number on errors.
1304 +ext3_xattr_cmp(struct ext3_xattr_header *header1,
1305 + struct ext3_xattr_header *header2)
1307 + struct ext3_xattr_entry *entry1, *entry2;
1309 + entry1 = ENTRY(header1+1);
1310 + entry2 = ENTRY(header2+1);
1311 + while (!IS_LAST_ENTRY(entry1)) {
1312 + if (IS_LAST_ENTRY(entry2))
1314 + if (entry1->e_hash != entry2->e_hash ||
1315 + entry1->e_name_len != entry2->e_name_len ||
1316 + entry1->e_value_size != entry2->e_value_size ||
1317 + memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
1319 + if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
1321 + if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
1322 + (char *)header2 + le16_to_cpu(entry2->e_value_offs),
1323 + le32_to_cpu(entry1->e_value_size)))
1326 + entry1 = EXT3_XATTR_NEXT(entry1);
1327 + entry2 = EXT3_XATTR_NEXT(entry2);
1329 + if (!IS_LAST_ENTRY(entry2))
1335 + * ext3_xattr_cache_find()
1337 + * Find an identical extended attribute block.
1339 + * Returns a pointer to the block found, or NULL if such a block was
1340 + * not found or an error occurred.
1342 +static struct buffer_head *
1343 +ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header)
1345 + __u32 hash = le32_to_cpu(header->h_hash);
1346 + struct mb_cache_entry *ce;
1348 + if (!header->h_hash)
1349 + return NULL; /* never share */
1350 + ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
1351 + ce = mb_cache_entry_find_first(ext3_xattr_cache, 0, inode->i_dev, hash);
1353 + struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
1356 + ext3_error(inode->i_sb, "ext3_xattr_cache_find",
1357 + "inode %ld: block %ld read error",
1358 + inode->i_ino, ce->e_block);
1359 + } else if (le32_to_cpu(HDR(bh)->h_refcount) >
1360 + EXT3_XATTR_REFCOUNT_MAX) {
1361 + ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
1362 + le32_to_cpu(HDR(bh)->h_refcount),
1363 + EXT3_XATTR_REFCOUNT_MAX);
1364 + } else if (!ext3_xattr_cmp(header, HDR(bh))) {
1365 + ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
1366 + mb_cache_entry_release(ce);
1370 + ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
1376 + * ext3_xattr_cache_remove()
1378 + * Remove the cache entry of a block from the cache. Called when a
1379 + * block becomes invalid.
1382 +ext3_xattr_cache_remove(struct buffer_head *bh)
1384 + struct mb_cache_entry *ce;
1386 + ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_dev, bh->b_blocknr);
1388 + ea_bdebug(bh, "removing (%d cache entries remaining)",
1389 + atomic_read(&ext3_xattr_cache->c_entry_count)-1);
1390 + mb_cache_entry_free(ce);
1392 + ea_bdebug(bh, "no cache entry");
1395 +#define NAME_HASH_SHIFT 5
1396 +#define VALUE_HASH_SHIFT 16
1399 + * ext3_xattr_hash_entry()
1401 + * Compute the hash of an extended attribute.
1403 +static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
1404 + struct ext3_xattr_entry *entry)
1407 + char *name = entry->e_name;
1410 + for (n=0; n < entry->e_name_len; n++) {
1411 + hash = (hash << NAME_HASH_SHIFT) ^
1412 + (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
1416 + if (entry->e_value_block == 0 && entry->e_value_size != 0) {
1417 + __u32 *value = (__u32 *)((char *)header +
1418 + le16_to_cpu(entry->e_value_offs));
1419 + for (n = (le32_to_cpu(entry->e_value_size) +
1420 + EXT3_XATTR_ROUND) >> EXT3_XATTR_PAD_BITS; n; n--) {
1421 + hash = (hash << VALUE_HASH_SHIFT) ^
1422 + (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
1423 + le32_to_cpu(*value++);
1426 + entry->e_hash = cpu_to_le32(hash);
1429 +#undef NAME_HASH_SHIFT
1430 +#undef VALUE_HASH_SHIFT
1432 +#define BLOCK_HASH_SHIFT 16
1435 + * ext3_xattr_rehash()
1437 + * Re-compute the extended attribute hash value after an entry has changed.
1439 +static void ext3_xattr_rehash(struct ext3_xattr_header *header,
1440 + struct ext3_xattr_entry *entry)
1442 + struct ext3_xattr_entry *here;
1445 + ext3_xattr_hash_entry(header, entry);
1446 + here = ENTRY(header+1);
1447 + while (!IS_LAST_ENTRY(here)) {
1448 + if (!here->e_hash) {
1449 + /* Block is not shared if an entry's hash value == 0 */
1453 + hash = (hash << BLOCK_HASH_SHIFT) ^
1454 + (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
1455 + le32_to_cpu(here->e_hash);
1456 + here = EXT3_XATTR_NEXT(here);
1458 + header->h_hash = cpu_to_le32(hash);
1461 +#undef BLOCK_HASH_SHIFT
1464 +init_ext3_xattr(void)
1466 + ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL,
1467 + sizeof(struct mb_cache_entry) +
1468 + sizeof(struct mb_cache_entry_index), 1, 61);
1469 + if (!ext3_xattr_cache)
1476 +exit_ext3_xattr(void)
1478 + if (ext3_xattr_cache)
1479 + mb_cache_destroy(ext3_xattr_cache);
1480 + ext3_xattr_cache = NULL;
1483 +#else /* CONFIG_EXT3_FS_XATTR_SHARING */
1486 +init_ext3_xattr(void)
1492 +exit_ext3_xattr(void)
1496 +#endif /* CONFIG_EXT3_FS_XATTR_SHARING */
1497 diff -Nur linux-2.4.18/include/linux/ext3_fs.h linux-2.4.18ea/include/linux/ext3_fs.h
1498 --- linux-2.4.18/include/linux/ext3_fs.h Sun Feb 24 04:42:59 2002
1499 +++ linux-2.4.18ea/include/linux/ext3_fs.h Mon Mar 11 03:27:00 2002
1502 #define EXT3_BAD_INO 1 /* Bad blocks inode */
1503 #define EXT3_ROOT_INO 2 /* Root inode */
1504 -#define EXT3_ACL_IDX_INO 3 /* ACL inode */
1505 -#define EXT3_ACL_DATA_INO 4 /* ACL inode */
1506 #define EXT3_BOOT_LOADER_INO 5 /* Boot loader inode */
1507 #define EXT3_UNDEL_DIR_INO 6 /* Undelete directory inode */
1508 #define EXT3_RESIZE_INO 7 /* Reserved group descriptors inode */
1511 # define EXT3_BLOCK_SIZE(s) (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
1513 -#define EXT3_ACLE_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_acl_entry))
1514 #define EXT3_ADDR_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (__u32))
1516 # define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
1517 @@ -124,28 +121,6 @@
1523 -struct ext3_acl_header /* Header of Access Control Lists */
1526 - __u32 aclh_file_count;
1527 - __u32 aclh_acle_count;
1528 - __u32 aclh_first_acle;
1531 -struct ext3_acl_entry /* Access Control List Entry */
1534 - __u16 acle_perms; /* Access permissions */
1535 - __u16 acle_type; /* Type of entry */
1536 - __u16 acle_tag; /* User or group identity */
1538 - __u32 acle_next; /* Pointer on next entry for the */
1539 - /* same inode or on next free entry */
1543 * Structure of a blocks group descriptor
1545 struct ext3_group_desc
1547 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
1548 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
1550 -#define EXT3_FEATURE_COMPAT_SUPP 0
1551 +#define EXT3_FEATURE_COMPAT_SUPP EXT3_FEATURE_COMPAT_EXT_ATTR
1552 #define EXT3_FEATURE_INCOMPAT_SUPP (EXT3_FEATURE_INCOMPAT_FILETYPE| \
1553 EXT3_FEATURE_INCOMPAT_RECOVER)
1554 #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
1555 @@ -603,4 +578,22 @@
1558 +/* Defined for extended attributes */
1559 +#define CONFIG_EXT3_FS_XATTR y
1561 +#define ENOATTR ENODATA /* No such attribute */
1564 +#define ENOTSUP EOPNOTSUPP /* Operation not supported */
1566 +#ifndef XATTR_NAME_MAX
1567 +#define XATTR_NAME_MAX 255 /* # chars in an extended attribute name */
1568 +#define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */
1569 +#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */
1571 +#ifndef XATTR_CREATE
1572 +#define XATTR_CREATE 1 /* set value, fail if attr already exists */
1573 +#define XATTR_REPLACE 2 /* set value, fail if attr does not exist */
1577 * Ok, these declarations are also in <linux/kernel.h> but none of the
1579 extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
1582 +extern int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
1583 extern struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
1584 extern struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
1586 diff -Nur linux-2.4.18/include/linux/ext3_jbd.h linux-2.4.18ea/include/linux/ext3_jbd.h
1587 --- linux-2.4.18/include/linux/ext3_jbd.h Fri Dec 21 18:42:03 2001
1588 +++ linux-2.4.18ea/include/linux/ext3_jbd.h Mon Mar 25 00:11:36 2002
1591 #define EXT3_SINGLEDATA_TRANS_BLOCKS 8
1593 +/* Extended attributes may touch two data buffers, two bitmap buffers,
1594 + * and two group and summaries. */
1596 +#define EXT3_XATTR_TRANS_BLOCKS 8
1598 /* Define the minimum size for a transaction which modifies data. This
1599 * needs to take into account the fact that we may end up modifying two
1600 * quota files too (one for the group, one for the user quota). The
1601 * superblock only gets updated once, of course, so don't bother
1602 * counting that again for the quota updates. */
1604 -#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS - 2)
1605 +#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS + \
1606 + EXT3_XATTR_TRANS_BLOCKS - 2)
1608 extern int ext3_writepage_trans_blocks(struct inode *inode);
1610 diff -Nur linux-2.4.18/include/linux/ext3_xattr.h linux-2.4.18ea/include/linux/ext3_xattr.h
1611 --- linux-2.4.18/include/linux/ext3_xattr.h Thu Jan 1 01:00:00 1970
1612 +++ linux-2.4.18ea/include/linux/ext3_xattr.h Fri Apr 5 10:08:01 2002
1615 + File: linux/ext3_xattr.h
1617 + On-disk format of extended attributes for the ext3 filesystem.
1619 + (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
1622 +#include <linux/config.h>
1623 +#include <linux/init.h>
1624 +#include <linux/xattr.h>
1626 +/* Magic value in attribute blocks */
1627 +#define EXT3_XATTR_MAGIC 0xEA020000
1629 +/* Maximum number of references to one attribute block */
1630 +#define EXT3_XATTR_REFCOUNT_MAX 1024
1633 +#define EXT3_XATTR_INDEX_MAX 10
1634 +#define EXT3_XATTR_INDEX_USER 1
1636 +struct ext3_xattr_header {
1637 + __u32 h_magic; /* magic number for identification */
1638 + __u32 h_refcount; /* reference count */
1639 + __u32 h_blocks; /* number of disk blocks used */
1640 + __u32 h_hash; /* hash value of all attributes */
1641 + __u32 h_reserved[4]; /* zero right now */
1644 +struct ext3_xattr_entry {
1645 + __u8 e_name_len; /* length of name */
1646 + __u8 e_name_index; /* attribute name index */
1647 + __u16 e_value_offs; /* offset in disk block of value */
1648 + __u32 e_value_block; /* disk block attribute is stored on (n/i) */
1649 + __u32 e_value_size; /* size of attribute value */
1650 + __u32 e_hash; /* hash value of name and value */
1651 + char e_name[0]; /* attribute name */
1654 +#define EXT3_XATTR_PAD_BITS 2
1655 +#define EXT3_XATTR_PAD (1<<EXT3_XATTR_PAD_BITS)
1656 +#define EXT3_XATTR_ROUND (EXT3_XATTR_PAD-1)
1657 +#define EXT3_XATTR_LEN(name_len) \
1658 + (((name_len) + EXT3_XATTR_ROUND + \
1659 + sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND)
1660 +#define EXT3_XATTR_NEXT(entry) \
1661 + ( (struct ext3_xattr_entry *)( \
1662 + (char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) )
1663 +#define EXT3_XATTR_SIZE(size) \
1664 + (((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND)
1668 +# ifdef CONFIG_EXT3_FS_XATTR
1670 +struct ext3_xattr_handler {
1672 + size_t (*list)(char *list, struct inode *inode, const char *name,
1674 + int (*get)(struct inode *inode, const char *name, void *buffer,
1676 + int (*set)(struct inode *inode, const char *name, void *buffer,
1677 + size_t size, int flags);
1680 +extern int ext3_xattr_register(int, struct ext3_xattr_handler *);
1681 +extern void ext3_xattr_unregister(int, struct ext3_xattr_handler *);
1683 +extern int ext3_setxattr(struct dentry *, const char *, void *, size_t, int);
1684 +extern ssize_t ext3_getxattr(struct dentry *, const char *, void *, size_t);
1685 +extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
1686 +extern int ext3_removexattr(struct dentry *, const char *);
1688 +extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
1689 +extern int ext3_xattr_list(struct inode *, char *, size_t);
1690 +extern int ext3_xattr_set(handle_t *handle, struct inode *, int, const char *, void *, size_t, int);
1692 +extern void ext3_xattr_drop_inode(handle_t *, struct inode *);
1693 +extern void ext3_xattr_put_super(struct super_block *);
1695 +extern int init_ext3_xattr(void) __init;
1696 +extern void exit_ext3_xattr(void);
1698 +# else /* CONFIG_EXT3_FS_XATTR */
1699 +# define ext3_setxattr NULL
1700 +# define ext3_getxattr NULL
1701 +# define ext3_listxattr NULL
1702 +# define ext3_removexattr NULL
1705 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
1706 + void *buffer, size_t size, int flags)
1712 +ext3_xattr_list(struct inode *inode, void *buffer, size_t size, int flags)
1718 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
1719 + const char *name, void *value, size_t size, int flags)
1725 +ext3_xattr_drop_inode(handle_t *handle, struct inode *inode)
1730 +ext3_xattr_put_super(struct super_block *sb)
1735 +init_ext3_xattr(void)
1741 +exit_ext3_xattr(void)
1745 +# endif /* CONFIG_EXT3_FS_XATTR */
1747 +# ifdef CONFIG_EXT3_FS_XATTR_USER
1749 +extern int init_ext3_xattr_user(void) __init;
1750 +extern void exit_ext3_xattr_user(void);
1752 +# else /* CONFIG_EXT3_FS_XATTR_USER */
1755 +init_ext3_xattr_user(void)
1761 +exit_ext3_xattr_user(void)
1765 +#endif /* CONFIG_EXT3_FS_XATTR_USER */
1767 +#endif /* __KERNEL__ */
1769 diff -Nur linux-2.4.18/include/linux/xattr.h linux-2.4.18ea/include/linux/xattr.h
1770 --- linux-2.4.18/include/linux/xattr.h Thu Jan 1 01:00:00 1970
1771 +++ linux-2.4.18ea/include/linux/xattr.h Sun Mar 24 23:42:21 2002
1774 + File: linux/xattr.h
1776 + Extended attributes handling.
1778 + Copyright (C) 2001 by Andreas Gruenbacher <a.gruenbacher@computer.org>
1779 + Copyright (C) 2001 SGI - Silicon Graphics, Inc <linux-xfs@oss.sgi.com>
1781 +#ifndef _LINUX_XATTR_H
1782 +#define _LINUX_XATTR_H
1784 +#define XATTR_CREATE 1 /* set value, fail if attr already exists */
1785 +#define XATTR_REPLACE 2 /* set value, fail if attr does not exist */
1787 +#endif /* _LINUX_XATTR_H */