2 fs/ext3/ext3-exports.c | 13
7 fs/ext3/xattr.c | 1242 +++++++++++++++++++++++++++++++++++++++++++++
8 include/linux/ext3_fs.h | 46 -
9 include/linux/ext3_jbd.h | 8
10 include/linux/ext3_xattr.h | 155 +++++
11 include/linux/xattr.h | 15
12 11 files changed, 1494 insertions(+), 51 deletions(-)
14 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
15 +++ linux-2.4.18-alexey/fs/ext3/ext3-exports.c 2003-09-01 14:55:39.000000000 +0400
17 +#include <linux/config.h>
18 +#include <linux/module.h>
19 +#include <linux/ext3_fs.h>
20 +#include <linux/ext3_jbd.h>
21 +#include <linux/ext3_xattr.h>
23 +EXPORT_SYMBOL(ext3_force_commit);
24 +EXPORT_SYMBOL(ext3_bread);
25 +EXPORT_SYMBOL(ext3_xattr_register);
26 +EXPORT_SYMBOL(ext3_xattr_unregister);
27 +EXPORT_SYMBOL(ext3_xattr_get);
28 +EXPORT_SYMBOL(ext3_xattr_list);
29 +EXPORT_SYMBOL(ext3_xattr_set);
30 --- linux-2.4.18/fs/ext3/ialloc.c~linux-2.4.18ea-0.8.26-2 2003-07-28 17:52:04.000000000 +0400
31 +++ linux-2.4.18-alexey/fs/ext3/ialloc.c 2003-09-01 14:55:39.000000000 +0400
33 #include <linux/jbd.h>
34 #include <linux/ext3_fs.h>
35 #include <linux/ext3_jbd.h>
36 +#include <linux/ext3_xattr.h>
37 #include <linux/stat.h>
38 #include <linux/string.h>
39 #include <linux/locks.h>
40 @@ -216,6 +217,7 @@ void ext3_free_inode (handle_t *handle,
41 * as writing the quota to disk may need the lock as well.
44 + ext3_xattr_drop_inode(handle, inode);
45 DQUOT_FREE_INODE(inode);
48 --- linux-2.4.18/fs/ext3/inode.c~linux-2.4.18ea-0.8.26-2 2003-07-28 17:52:04.000000000 +0400
49 +++ linux-2.4.18-alexey/fs/ext3/inode.c 2003-09-01 14:55:39.000000000 +0400
52 #undef SEARCH_FROM_ZERO
55 + * Test whether an inode is a fast symlink.
57 +static inline int ext3_inode_is_fast_symlink(struct inode *inode)
59 + int ea_blocks = EXT3_I(inode)->i_file_acl ?
60 + (inode->i_sb->s_blocksize >> 9) : 0;
62 + return (S_ISLNK(inode->i_mode) &&
63 + inode->i_blocks - ea_blocks == 0);
66 /* The ext3 forget function must perform a revoke if we are freeing data
67 * which has been journaled. Metadata (eg. indirect blocks) must be
68 * revoked in all cases.
70 * still needs to be revoked.
73 -static int ext3_forget(handle_t *handle, int is_metadata,
74 +int ext3_forget(handle_t *handle, int is_metadata,
75 struct inode *inode, struct buffer_head *bh,
78 @@ -164,9 +176,7 @@ void ext3_delete_inode (struct inode * i
82 - if (is_bad_inode(inode) ||
83 - inode->i_ino == EXT3_ACL_IDX_INO ||
84 - inode->i_ino == EXT3_ACL_DATA_INO)
85 + if (is_bad_inode(inode))
89 @@ -1877,6 +1887,8 @@ void ext3_truncate(struct inode * inode)
90 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
91 S_ISLNK(inode->i_mode)))
93 + if (ext3_inode_is_fast_symlink(inode))
95 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
98 @@ -2038,8 +2050,6 @@ int ext3_get_inode_loc (struct inode *in
99 struct ext3_group_desc * gdp;
101 if ((inode->i_ino != EXT3_ROOT_INO &&
102 - inode->i_ino != EXT3_ACL_IDX_INO &&
103 - inode->i_ino != EXT3_ACL_DATA_INO &&
104 inode->i_ino != EXT3_JOURNAL_INO &&
105 inode->i_ino < EXT3_FIRST_INO(inode->i_sb)) ||
106 inode->i_ino > le32_to_cpu(
107 @@ -2166,10 +2176,7 @@ void ext3_read_inode(struct inode * inod
111 - if (inode->i_ino == EXT3_ACL_IDX_INO ||
112 - inode->i_ino == EXT3_ACL_DATA_INO)
113 - /* Nothing to do */ ;
114 - else if (S_ISREG(inode->i_mode)) {
115 + if (S_ISREG(inode->i_mode)) {
116 inode->i_op = &ext3_file_inode_operations;
117 inode->i_fop = &ext3_file_operations;
118 inode->i_mapping->a_ops = &ext3_aops;
119 @@ -2177,7 +2184,7 @@ void ext3_read_inode(struct inode * inod
120 inode->i_op = &ext3_dir_inode_operations;
121 inode->i_fop = &ext3_dir_operations;
122 } else if (S_ISLNK(inode->i_mode)) {
123 - if (!inode->i_blocks)
124 + if (ext3_inode_is_fast_symlink(inode))
125 inode->i_op = &ext3_fast_symlink_inode_operations;
127 inode->i_op = &page_symlink_inode_operations;
128 --- linux-2.4.18/fs/ext3/Makefile~linux-2.4.18ea-0.8.26-2 2003-08-29 16:53:17.000000000 +0400
129 +++ linux-2.4.18-alexey/fs/ext3/Makefile 2003-09-01 14:55:50.000000000 +0400
134 -export-objs := super.o inode.o
135 +export-objs := ext3-exports.o
137 obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
138 - ioctl.o namei.o super.o symlink.o hash.o
139 + ioctl.o namei.o super.o symlink.o xattr.o hash.o ext3-exports.o
142 include $(TOPDIR)/Rules.make
143 --- linux-2.4.18/fs/ext3/namei.c~linux-2.4.18ea-0.8.26-2 2003-09-01 11:50:59.000000000 +0400
144 +++ linux-2.4.18-alexey/fs/ext3/namei.c 2003-09-01 14:55:39.000000000 +0400
146 #include <linux/sched.h>
147 #include <linux/ext3_fs.h>
148 #include <linux/ext3_jbd.h>
149 +#include <linux/ext3_xattr.h>
150 #include <linux/fcntl.h>
151 #include <linux/stat.h>
152 #include <linux/string.h>
153 @@ -1524,6 +1525,7 @@ static int ext3_add_nondir(handle_t *han
154 d_instantiate(dentry, inode);
157 + ext3_xattr_drop_inode(handle, inode);
158 ext3_dec_count(handle, inode);
161 @@ -1612,7 +1614,7 @@ static int ext3_mkdir(struct inode * dir
165 - inode = ext3_new_inode (handle, dir, S_IFDIR);
166 + inode = ext3_new_inode (handle, dir, S_IFDIR | mode);
167 err = PTR_ERR(inode);
170 @@ -1620,7 +1622,6 @@ static int ext3_mkdir(struct inode * dir
171 inode->i_op = &ext3_dir_inode_operations;
172 inode->i_fop = &ext3_dir_operations;
173 inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
174 - inode->i_blocks = 0;
175 dir_block = ext3_bread (handle, inode, 0, 1, &err);
177 inode->i_nlink--; /* is this nlink == 0? */
178 @@ -1647,9 +1648,6 @@ static int ext3_mkdir(struct inode * dir
179 BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata");
180 ext3_journal_dirty_metadata(handle, dir_block);
182 - inode->i_mode = S_IFDIR | mode;
183 - if (dir->i_mode & S_ISGID)
184 - inode->i_mode |= S_ISGID;
185 ext3_mark_inode_dirty(handle, inode);
186 err = ext3_add_entry (handle, dentry, inode);
188 --- linux-2.4.18/fs/ext3/super.c~linux-2.4.18ea-0.8.26-2 2003-08-29 16:53:17.000000000 +0400
189 +++ linux-2.4.18-alexey/fs/ext3/super.c 2003-09-01 14:55:39.000000000 +0400
191 #include <linux/jbd.h>
192 #include <linux/ext3_fs.h>
193 #include <linux/ext3_jbd.h>
194 +#include <linux/ext3_xattr.h>
195 #include <linux/slab.h>
196 #include <linux/init.h>
197 #include <linux/locks.h>
198 @@ -406,6 +407,7 @@ void ext3_put_super (struct super_block
199 kdev_t j_dev = sbi->s_journal->j_dev;
202 + ext3_xattr_put_super(sb);
203 journal_destroy(sbi->s_journal);
204 if (!(sb->s_flags & MS_RDONLY)) {
205 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
206 @@ -1743,18 +1745,27 @@ int ext3_statfs (struct super_block * sb
208 static DECLARE_FSTYPE_DEV(ext3_fs_type, "ext3", ext3_read_super);
210 -static int __init init_ext3_fs(void)
211 +static void exit_ext3_fs(void)
213 - return register_filesystem(&ext3_fs_type);
214 + unregister_filesystem(&ext3_fs_type);
215 + exit_ext3_xattr_user();
219 -static void __exit exit_ext3_fs(void)
220 +static int __init init_ext3_fs(void)
222 - unregister_filesystem(&ext3_fs_type);
223 + int error = init_ext3_xattr();
225 + error = init_ext3_xattr_user();
227 + error = register_filesystem(&ext3_fs_type);
235 -EXPORT_SYMBOL(ext3_force_commit);
236 -EXPORT_SYMBOL(ext3_bread);
238 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
239 MODULE_DESCRIPTION("Second Extended Filesystem with journaling extensions");
240 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
241 +++ linux-2.4.18-alexey/fs/ext3/xattr.c 2003-09-01 14:55:39.000000000 +0400
244 + * linux/fs/ext3/xattr.c
246 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
248 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
249 + * Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>.
250 + * Extended attributes for symlinks and special files added per
251 + * suggestion of Luka Renko <luka.renko@hermes.si>.
255 + * Extended attributes are stored on disk blocks allocated outside of
256 + * any inode. The i_file_acl field is then made to point to this allocated
257 + * block. If all extended attributes of an inode are identical, these
258 + * inodes may share the same extended attribute block. Such situations
259 + * are automatically detected by keeping a cache of recent attribute block
260 + * numbers and hashes over the block's contents in memory.
263 + * Extended attribute block layout:
265 + * +------------------+
268 + * | entry 2 | | growing downwards
270 + * | four null bytes |
273 + * | value 3 | | growing upwards
275 + * +------------------+
277 + * The block header is followed by multiple entry descriptors. These entry
278 + * descriptors are variable in size, and alligned to EXT3_XATTR_PAD
279 + * byte boundaries. The entry descriptors are sorted by attribute name,
280 + * so that two extended attribute blocks can be compared efficiently.
282 + * Attribute values are aligned to the end of the block, stored in
283 + * no specific order. They are also padded to EXT3_XATTR_PAD byte
284 + * boundaries. No additional gaps are left between them.
288 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
289 + * the xattr inode operations are called, so we are guaranteed that only one
290 + * processes accesses extended attributes of an inode at any time.
292 + * For writing we also grab the ext3_xattr_sem semaphore. This ensures that
293 + * only a single process is modifying an extended attribute block, even
294 + * if the block is shared among inodes.
296 + * Note for porting to 2.5
297 + * -----------------------
298 + * The BKL will no longer be held in the xattr inode operations.
301 +#include <linux/fs.h>
302 +#include <linux/locks.h>
303 +#include <linux/slab.h>
304 +#include <linux/ext3_jbd.h>
305 +#include <linux/ext3_fs.h>
306 +#include <linux/ext3_xattr.h>
307 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
308 +#include <linux/mbcache.h>
310 +#include <linux/quotaops.h>
311 +#include <asm/semaphore.h>
312 +#include <linux/compatmac.h>
313 +#include <linux/module.h>
315 +/* These symbols may be needed by a module. */
317 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
318 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
321 +#define HDR(bh) ((struct ext3_xattr_header *)((bh)->b_data))
322 +#define ENTRY(ptr) ((struct ext3_xattr_entry *)(ptr))
323 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
324 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
326 +#ifdef EXT3_XATTR_DEBUG
327 +# define ea_idebug(inode, f...) do { \
328 + printk(KERN_DEBUG "inode %s:%ld: ", \
329 + kdevname(inode->i_dev), inode->i_ino); \
333 +# define ea_bdebug(bh, f...) do { \
334 + printk(KERN_DEBUG "block %s:%ld: ", \
335 + kdevname(bh->b_dev), bh->b_blocknr); \
340 +# define ea_idebug(f...)
341 +# define ea_bdebug(f...)
344 +static int ext3_xattr_set2(handle_t *, struct inode *, struct buffer_head *,
345 + struct ext3_xattr_header *);
347 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
349 +static int ext3_xattr_cache_insert(struct buffer_head *);
350 +static struct buffer_head *ext3_xattr_cache_find(struct inode *,
351 + struct ext3_xattr_header *);
352 +static void ext3_xattr_cache_remove(struct buffer_head *);
353 +static void ext3_xattr_rehash(struct ext3_xattr_header *,
354 + struct ext3_xattr_entry *);
356 +static struct mb_cache *ext3_xattr_cache;
359 +# define ext3_xattr_cache_insert(bh) 0
360 +# define ext3_xattr_cache_find(inode, header) NULL
361 +# define ext3_xattr_cache_remove(bh) do {} while(0)
362 +# define ext3_xattr_rehash(header, entry) do {} while(0)
366 + * If a file system does not share extended attributes among inodes,
367 + * we should not need the ext3_xattr_sem semaphore. However, the
368 + * filesystem may still contain shared blocks, so we always take
372 +DECLARE_MUTEX(ext3_xattr_sem);
375 +ext3_xattr_lock(void)
377 + down(&ext3_xattr_sem);
381 +ext3_xattr_unlock(void)
383 + up(&ext3_xattr_sem);
387 +ext3_xattr_new_block(handle_t *handle, struct inode *inode,
388 + int * errp, int force)
390 + struct super_block *sb = inode->i_sb;
391 + int goal = le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block) +
392 + EXT3_I(inode)->i_block_group * EXT3_BLOCKS_PER_GROUP(sb);
394 + /* How can we enforce the allocation? */
395 + int block = ext3_new_block(handle, inode, goal, 0, 0, errp);
398 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
404 +ext3_xattr_quota_alloc(struct inode *inode, int force)
406 + /* How can we enforce the allocation? */
408 + int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
410 + inode->i_blocks += inode->i_sb->s_blocksize >> 9;
412 + int error = DQUOT_ALLOC_BLOCK(inode, 1);
420 +ext3_xattr_quota_free(struct inode *inode)
422 + DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
423 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
427 +ext3_xattr_free_block(handle_t *handle, struct inode * inode,
428 + unsigned long block)
430 + ext3_free_blocks(handle, inode, block, 1);
431 + inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
435 +# define ext3_xattr_quota_free(inode) \
436 + DQUOT_FREE_BLOCK(inode, 1)
437 +# define ext3_xattr_free_block(handle, inode, block) \
438 + ext3_free_blocks(handle, inode, block, 1)
441 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
443 +static inline struct buffer_head *
444 +sb_bread(struct super_block *sb, int block)
446 + return bread(sb->s_dev, block, sb->s_blocksize);
449 +static inline struct buffer_head *
450 +sb_getblk(struct super_block *sb, int block)
452 + return getblk(sb->s_dev, block, sb->s_blocksize);
457 +struct ext3_xattr_handler *ext3_xattr_handlers[EXT3_XATTR_INDEX_MAX];
458 +rwlock_t ext3_handler_lock = RW_LOCK_UNLOCKED;
461 +ext3_xattr_register(int name_index, struct ext3_xattr_handler *handler)
463 + int error = -EINVAL;
465 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
466 + write_lock(&ext3_handler_lock);
467 + if (!ext3_xattr_handlers[name_index-1]) {
468 + ext3_xattr_handlers[name_index-1] = handler;
471 + write_unlock(&ext3_handler_lock);
477 +ext3_xattr_unregister(int name_index, struct ext3_xattr_handler *handler)
479 + if (name_index > 0 || name_index <= EXT3_XATTR_INDEX_MAX) {
480 + write_lock(&ext3_handler_lock);
481 + ext3_xattr_handlers[name_index-1] = NULL;
482 + write_unlock(&ext3_handler_lock);
486 +static inline const char *
487 +strcmp_prefix(const char *a, const char *a_prefix)
489 + while (*a_prefix && *a == *a_prefix) {
493 + return *a_prefix ? NULL : a;
497 + * Decode the extended attribute name, and translate it into
498 + * the name_index and name suffix.
500 +static inline struct ext3_xattr_handler *
501 +ext3_xattr_resolve_name(const char **name)
503 + struct ext3_xattr_handler *handler = NULL;
508 + read_lock(&ext3_handler_lock);
509 + for (i=0; i<EXT3_XATTR_INDEX_MAX; i++) {
510 + if (ext3_xattr_handlers[i]) {
511 + const char *n = strcmp_prefix(*name,
512 + ext3_xattr_handlers[i]->prefix);
514 + handler = ext3_xattr_handlers[i];
520 + read_unlock(&ext3_handler_lock);
524 +static inline struct ext3_xattr_handler *
525 +ext3_xattr_handler(int name_index)
527 + struct ext3_xattr_handler *handler = NULL;
528 + if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
529 + read_lock(&ext3_handler_lock);
530 + handler = ext3_xattr_handlers[name_index-1];
531 + read_unlock(&ext3_handler_lock);
537 + * Inode operation getxattr()
539 + * dentry->d_inode->i_sem down
540 + * BKL held [before 2.5.x]
543 +ext3_getxattr(struct dentry *dentry, const char *name,
544 + void *buffer, size_t size)
546 + struct ext3_xattr_handler *handler;
547 + struct inode *inode = dentry->d_inode;
549 + handler = ext3_xattr_resolve_name(&name);
552 + return handler->get(inode, name, buffer, size);
556 + * Inode operation listxattr()
558 + * dentry->d_inode->i_sem down
559 + * BKL held [before 2.5.x]
562 +ext3_listxattr(struct dentry *dentry, char *buffer, size_t size)
564 + return ext3_xattr_list(dentry->d_inode, buffer, size);
568 + * Inode operation setxattr()
570 + * dentry->d_inode->i_sem down
571 + * BKL held [before 2.5.x]
574 +ext3_setxattr(struct dentry *dentry, const char *name,
575 + void *value, size_t size, int flags)
577 + struct ext3_xattr_handler *handler;
578 + struct inode *inode = dentry->d_inode;
581 + value = ""; /* empty EA, do not remove */
582 + handler = ext3_xattr_resolve_name(&name);
585 + return handler->set(inode, name, value, size, flags);
589 + * Inode operation removexattr()
591 + * dentry->d_inode->i_sem down
592 + * BKL held [before 2.5.x]
595 +ext3_removexattr(struct dentry *dentry, const char *name)
597 + struct ext3_xattr_handler *handler;
598 + struct inode *inode = dentry->d_inode;
600 + handler = ext3_xattr_resolve_name(&name);
603 + return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
609 + * Copy an extended attribute into the buffer
610 + * provided, or compute the buffer size required.
611 + * Buffer is NULL to compute the size of the buffer required.
613 + * Returns a negative error number on failure, or the number of bytes
614 + * used / required on success.
617 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
618 + void *buffer, size_t buffer_size)
620 + struct buffer_head *bh = NULL;
621 + struct ext3_xattr_entry *entry;
622 + unsigned int block, size;
624 + int name_len, error;
626 + ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
627 + name_index, name, buffer, (long)buffer_size);
631 + if (!EXT3_I(inode)->i_file_acl)
633 + block = EXT3_I(inode)->i_file_acl;
634 + ea_idebug(inode, "reading block %d", block);
635 + bh = sb_bread(inode->i_sb, block);
638 + ea_bdebug(bh, "b_count=%d, refcount=%d",
639 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
640 + end = bh->b_data + bh->b_size;
641 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
642 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
643 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_get",
644 + "inode %ld: bad block %d", inode->i_ino, block);
648 + /* find named attribute */
649 + name_len = strlen(name);
652 + if (name_len > 255)
654 + entry = FIRST_ENTRY(bh);
655 + while (!IS_LAST_ENTRY(entry)) {
656 + struct ext3_xattr_entry *next =
657 + EXT3_XATTR_NEXT(entry);
658 + if ((char *)next >= end)
660 + if (name_index == entry->e_name_index &&
661 + name_len == entry->e_name_len &&
662 + memcmp(name, entry->e_name, name_len) == 0)
666 + /* Check the remaining name entries */
667 + while (!IS_LAST_ENTRY(entry)) {
668 + struct ext3_xattr_entry *next =
669 + EXT3_XATTR_NEXT(entry);
670 + if ((char *)next >= end)
674 + if (ext3_xattr_cache_insert(bh))
675 + ea_idebug(inode, "cache insert failed");
679 + /* check the buffer size */
680 + if (entry->e_value_block != 0)
682 + size = le32_to_cpu(entry->e_value_size);
683 + if (size > inode->i_sb->s_blocksize ||
684 + le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
687 + if (ext3_xattr_cache_insert(bh))
688 + ea_idebug(inode, "cache insert failed");
691 + if (size > buffer_size)
693 + /* return value of attribute */
694 + memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
706 + * ext3_xattr_list()
708 + * Copy a list of attribute names into the buffer
709 + * provided, or compute the buffer size required.
710 + * Buffer is NULL to compute the size of the buffer required.
712 + * Returns a negative error number on failure, or the number of bytes
713 + * used / required on success.
716 +ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
718 + struct buffer_head *bh = NULL;
719 + struct ext3_xattr_entry *entry;
720 + unsigned int block, size = 0;
724 + ea_idebug(inode, "buffer=%p, buffer_size=%ld",
725 + buffer, (long)buffer_size);
727 + if (!EXT3_I(inode)->i_file_acl)
729 + block = EXT3_I(inode)->i_file_acl;
730 + ea_idebug(inode, "reading block %d", block);
731 + bh = sb_bread(inode->i_sb, block);
734 + ea_bdebug(bh, "b_count=%d, refcount=%d",
735 + atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
736 + end = bh->b_data + bh->b_size;
737 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
738 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
739 +bad_block: ext3_error(inode->i_sb, "ext3_xattr_list",
740 + "inode %ld: bad block %d", inode->i_ino, block);
744 + /* compute the size required for the list of attribute names */
745 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
746 + entry = EXT3_XATTR_NEXT(entry)) {
747 + struct ext3_xattr_handler *handler;
748 + struct ext3_xattr_entry *next =
749 + EXT3_XATTR_NEXT(entry);
750 + if ((char *)next >= end)
753 + handler = ext3_xattr_handler(entry->e_name_index);
755 + size += handler->list(NULL, inode, entry->e_name,
756 + entry->e_name_len) + 1;
760 + if (ext3_xattr_cache_insert(bh))
761 + ea_idebug(inode, "cache insert failed");
767 + if (size > buffer_size)
771 + /* list the attribute names */
773 + for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
774 + entry = EXT3_XATTR_NEXT(entry)) {
775 + struct ext3_xattr_handler *handler;
777 + handler = ext3_xattr_handler(entry->e_name_index);
779 + buf += handler->list(buf, inode, entry->e_name,
780 + entry->e_name_len);
793 + * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is
796 +static void ext3_xattr_update_super_block(handle_t *handle,
797 + struct super_block *sb)
799 + if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR))
803 + ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh);
804 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
805 + EXT3_SB(sb)->s_feature_compat |= EXT3_FEATURE_COMPAT_EXT_ATTR;
807 + EXT3_SB(sb)->s_es->s_feature_compat |=
808 + cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR);
810 + ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
817 + * Create, replace or remove an extended attribute for this inode. Buffer
818 + * is NULL to remove an existing extended attribute, and non-NULL to
819 + * either replace an existing extended attribute, or create a new extended
820 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
821 + * specify that an extended attribute must exist and must not exist
822 + * previous to the call, respectively.
824 + * Returns 0, or a negative error number on failure.
827 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
828 + const char *name, void *value, size_t value_len, int flags)
830 + struct super_block *sb = inode->i_sb;
831 + struct buffer_head *bh = NULL;
832 + struct ext3_xattr_header *header = NULL;
833 + struct ext3_xattr_entry *here, *last;
834 + unsigned int name_len;
835 + int min_offs = sb->s_blocksize, not_found = 1, free, error;
839 + * header -- Points either into bh, or to a temporarily
840 + * allocated buffer.
841 + * here -- The named entry found, or the place for inserting, within
842 + * the block pointed to by header.
843 + * last -- Points right after the last named entry within the block
844 + * pointed to by header.
845 + * min_offs -- The offset of the first value (values are aligned
846 + * towards the end of the block).
847 + * end -- Points right after the block pointed to by header.
850 + ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
851 + name_index, name, value, (long)value_len);
853 + if (IS_RDONLY(inode))
855 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
861 + name_len = strlen(name);
862 + if (name_len > 255 || value_len > sb->s_blocksize)
866 + if (EXT3_I(inode)->i_file_acl) {
867 + /* The inode already has an extended attribute block. */
868 + int block = EXT3_I(inode)->i_file_acl;
870 + bh = sb_bread(sb, block);
874 + ea_bdebug(bh, "b_count=%d, refcount=%d",
875 + atomic_read(&(bh->b_count)),
876 + le32_to_cpu(HDR(bh)->h_refcount));
878 + end = bh->b_data + bh->b_size;
879 + if (header->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
880 + header->h_blocks != cpu_to_le32(1)) {
881 +bad_block: ext3_error(sb, "ext3_xattr_set",
882 + "inode %ld: bad block %d", inode->i_ino, block);
886 + /* Find the named attribute. */
887 + here = FIRST_ENTRY(bh);
888 + while (!IS_LAST_ENTRY(here)) {
889 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(here);
890 + if ((char *)next >= end)
892 + if (!here->e_value_block && here->e_value_size) {
893 + int offs = le16_to_cpu(here->e_value_offs);
894 + if (offs < min_offs)
897 + not_found = name_index - here->e_name_index;
899 + not_found = name_len - here->e_name_len;
901 + not_found = memcmp(name, here->e_name,name_len);
902 + if (not_found <= 0)
907 + /* We still need to compute min_offs and last. */
908 + while (!IS_LAST_ENTRY(last)) {
909 + struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
910 + if ((char *)next >= end)
912 + if (!last->e_value_block && last->e_value_size) {
913 + int offs = le16_to_cpu(last->e_value_offs);
914 + if (offs < min_offs)
920 + /* Check whether we have enough space left. */
921 + free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
923 + /* We will use a new extended attribute block. */
924 + free = sb->s_blocksize -
925 + sizeof(struct ext3_xattr_header) - sizeof(__u32);
926 + here = last = NULL; /* avoid gcc uninitialized warning. */
930 + /* Request to remove a nonexistent attribute? */
932 + if (flags & XATTR_REPLACE)
938 + free -= EXT3_XATTR_LEN(name_len);
940 + /* Request to create an existing attribute? */
942 + if (flags & XATTR_CREATE)
944 + if (!here->e_value_block && here->e_value_size) {
945 + unsigned int size = le32_to_cpu(here->e_value_size);
947 + if (le16_to_cpu(here->e_value_offs) + size >
948 + sb->s_blocksize || size > sb->s_blocksize)
950 + free += EXT3_XATTR_SIZE(size);
953 + free -= EXT3_XATTR_SIZE(value_len);
958 + /* Here we know that we can set the new attribute. */
961 + if (header->h_refcount == cpu_to_le32(1)) {
962 + ea_bdebug(bh, "modifying in-place");
963 + ext3_xattr_cache_remove(bh);
964 + error = ext3_journal_get_write_access(handle, bh);
970 + ea_bdebug(bh, "cloning");
971 + header = kmalloc(bh->b_size, GFP_KERNEL);
973 + if (header == NULL)
975 + memcpy(header, HDR(bh), bh->b_size);
976 + header->h_refcount = cpu_to_le32(1);
977 + offset = (char *)header - bh->b_data;
978 + here = ENTRY((char *)here + offset);
979 + last = ENTRY((char *)last + offset);
982 + /* Allocate a buffer where we construct the new block. */
983 + header = kmalloc(sb->s_blocksize, GFP_KERNEL);
985 + if (header == NULL)
987 + memset(header, 0, sb->s_blocksize);
988 + end = (char *)header + sb->s_blocksize;
989 + header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC);
990 + header->h_blocks = header->h_refcount = cpu_to_le32(1);
991 + last = here = ENTRY(header+1);
995 + /* Insert the new name. */
996 + int size = EXT3_XATTR_LEN(name_len);
997 + int rest = (char *)last - (char *)here;
998 + memmove((char *)here + size, here, rest);
999 + memset(here, 0, size);
1000 + here->e_name_index = name_index;
1001 + here->e_name_len = name_len;
1002 + memcpy(here->e_name, name, name_len);
1004 + /* Remove the old value. */
1005 + if (!here->e_value_block && here->e_value_size) {
1006 + char *first_val = (char *)header + min_offs;
1007 + int offs = le16_to_cpu(here->e_value_offs);
1008 + char *val = (char *)header + offs;
1009 + size_t size = EXT3_XATTR_SIZE(
1010 + le32_to_cpu(here->e_value_size));
1011 + memmove(first_val + size, first_val, val - first_val);
1012 + memset(first_val, 0, size);
1013 + here->e_value_offs = 0;
1016 + /* Adjust all value offsets. */
1017 + last = ENTRY(header+1);
1018 + while (!IS_LAST_ENTRY(last)) {
1019 + int o = le16_to_cpu(last->e_value_offs);
1020 + if (!last->e_value_block && o < offs)
1021 + last->e_value_offs =
1022 + cpu_to_le16(o + size);
1023 + last = EXT3_XATTR_NEXT(last);
1026 + if (value == NULL) {
1027 + /* Remove this attribute. */
1028 + if (EXT3_XATTR_NEXT(ENTRY(header+1)) == last) {
1029 + /* This block is now empty. */
1030 + error = ext3_xattr_set2(handle, inode, bh,NULL);
1033 + /* Remove the old name. */
1034 + int size = EXT3_XATTR_LEN(name_len);
1035 + last = ENTRY((char *)last - size);
1036 + memmove(here, (char*)here + size,
1037 + (char*)last - (char*)here);
1038 + memset(last, 0, size);
1043 + if (value != NULL) {
1044 + /* Insert the new value. */
1045 + here->e_value_size = cpu_to_le32(value_len);
1047 + size_t size = EXT3_XATTR_SIZE(value_len);
1048 + char *val = (char *)header + min_offs - size;
1049 + here->e_value_offs =
1050 + cpu_to_le16((char *)val - (char *)header);
1051 + memset(val + size - EXT3_XATTR_PAD, 0,
1052 + EXT3_XATTR_PAD); /* Clear the pad bytes. */
1053 + memcpy(val, value, value_len);
1056 + ext3_xattr_rehash(header, here);
1058 + error = ext3_xattr_set2(handle, inode, bh, header);
1062 + if (!(bh && header == HDR(bh)))
1064 + ext3_xattr_unlock();
1070 + * Second half of ext3_xattr_set(): Update the file system.
1073 +ext3_xattr_set2(handle_t *handle, struct inode *inode,
1074 + struct buffer_head *old_bh, struct ext3_xattr_header *header)
1076 + struct super_block *sb = inode->i_sb;
1077 + struct buffer_head *new_bh = NULL;
1081 + new_bh = ext3_xattr_cache_find(inode, header);
1084 + * We found an identical block in the cache.
1085 + * The old block will be released after updating
1088 + ea_bdebug(old_bh, "reusing block %ld",
1089 + new_bh->b_blocknr);
1092 + if (ext3_xattr_quota_alloc(inode, 1))
1095 + error = ext3_journal_get_write_access(handle, new_bh);
1098 + HDR(new_bh)->h_refcount = cpu_to_le32(
1099 + le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
1100 + ea_bdebug(new_bh, "refcount now=%d",
1101 + le32_to_cpu(HDR(new_bh)->h_refcount));
1102 + } else if (old_bh && header == HDR(old_bh)) {
1103 + /* Keep this block. */
1105 + (void)ext3_xattr_cache_insert(new_bh);
1107 + /* We need to allocate a new block */
1108 + int force = EXT3_I(inode)->i_file_acl != 0;
1109 + int block = ext3_xattr_new_block(handle, inode,
1113 + ea_idebug(inode, "creating block %d", block);
1115 + new_bh = sb_getblk(sb, block);
1117 +getblk_failed: ext3_xattr_free_block(handle, inode, block);
1121 + lock_buffer(new_bh);
1122 + error = ext3_journal_get_create_access(handle, new_bh);
1124 + unlock_buffer(new_bh);
1125 + goto getblk_failed;
1127 + memcpy(new_bh->b_data, header, new_bh->b_size);
1128 + mark_buffer_uptodate(new_bh, 1);
1129 + unlock_buffer(new_bh);
1130 + (void)ext3_xattr_cache_insert(new_bh);
1131 + ext3_xattr_update_super_block(handle, sb);
1133 + error = ext3_journal_dirty_metadata(handle, new_bh);
1138 + /* Update the inode. */
1139 + EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
1140 + inode->i_ctime = CURRENT_TIME;
1141 + ext3_mark_inode_dirty(handle, inode);
1142 + if (IS_SYNC(inode))
1143 + handle->h_sync = 1;
1146 + if (old_bh && old_bh != new_bh) {
1148 + * If there was an old block, and we are not still using it,
1149 + * we now release the old block.
1151 + unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
1153 + error = ext3_journal_get_write_access(handle, old_bh);
1156 + if (refcount == 1) {
1157 + /* Free the old block. */
1158 + ea_bdebug(old_bh, "freeing");
1159 + ext3_xattr_free_block(handle, inode, old_bh->b_blocknr);
1161 + /* ext3_forget() calls bforget() for us, but we
1162 + let our caller release old_bh, so we need to
1163 + duplicate the handle before. */
1165 + ext3_forget(handle, 1, inode, old_bh,old_bh->b_blocknr);
1167 + /* Decrement the refcount only. */
1169 + HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
1170 + ext3_xattr_quota_free(inode);
1171 + ext3_journal_dirty_metadata(handle, old_bh);
1172 + ea_bdebug(old_bh, "refcount now=%d", refcount);
1177 + if (old_bh != new_bh)
1184 + * ext3_xattr_drop_inode()
1186 + * Free extended attribute resources associated with this inode. This
1187 + * is called immediately before an inode is freed.
1190 +ext3_xattr_drop_inode(handle_t *handle, struct inode *inode)
1192 + struct buffer_head *bh;
1193 + unsigned int block = EXT3_I(inode)->i_file_acl;
1197 + ext3_xattr_lock();
1199 + bh = sb_bread(inode->i_sb, block);
1201 + ext3_error(inode->i_sb, "ext3_xattr_drop_inode",
1202 + "inode %ld: block %d read error", inode->i_ino, block);
1205 + ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
1206 + if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
1207 + HDR(bh)->h_blocks != cpu_to_le32(1)) {
1208 + ext3_error(inode->i_sb, "ext3_xattr_drop_inode",
1209 + "inode %ld: bad block %d", inode->i_ino, block);
1212 + ext3_journal_get_write_access(handle, bh);
1213 + ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
1214 + if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
1215 + ext3_xattr_cache_remove(bh);
1216 + ext3_xattr_free_block(handle, inode, block);
1217 + ext3_forget(handle, 1, inode, bh, block);
1220 + HDR(bh)->h_refcount = cpu_to_le32(
1221 + le32_to_cpu(HDR(bh)->h_refcount) - 1);
1222 + ext3_journal_dirty_metadata(handle, bh);
1223 + if (IS_SYNC(inode))
1224 + handle->h_sync = 1;
1225 + ext3_xattr_quota_free(inode);
1227 + EXT3_I(inode)->i_file_acl = 0;
1231 + ext3_xattr_unlock();
1235 + * ext3_xattr_put_super()
1237 + * This is called when a file system is unmounted.
1240 +ext3_xattr_put_super(struct super_block *sb)
1242 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
1243 + mb_cache_shrink(ext3_xattr_cache, sb->s_dev);
1247 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
1250 + * ext3_xattr_cache_insert()
1252 + * Create a new entry in the extended attribute cache, and insert
1253 + * it unless such an entry is already in the cache.
1255 + * Returns 0, or a negative error number on failure.
1258 +ext3_xattr_cache_insert(struct buffer_head *bh)
1260 + __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
1261 + struct mb_cache_entry *ce;
1264 + ce = mb_cache_entry_alloc(ext3_xattr_cache);
1267 + error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
1269 + mb_cache_entry_free(ce);
1270 + if (error == -EBUSY) {
1271 + ea_bdebug(bh, "already in cache (%d cache entries)",
1272 + atomic_read(&ext3_xattr_cache->c_entry_count));
1276 + ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
1277 + atomic_read(&ext3_xattr_cache->c_entry_count));
1278 + mb_cache_entry_release(ce);
1284 + * ext3_xattr_cmp()
1286 + * Compare two extended attribute blocks for equality.
1288 + * Returns 0 if the blocks are equal, 1 if they differ, and
1289 + * a negative error number on errors.
1292 +ext3_xattr_cmp(struct ext3_xattr_header *header1,
1293 + struct ext3_xattr_header *header2)
1295 + struct ext3_xattr_entry *entry1, *entry2;
1297 + entry1 = ENTRY(header1+1);
1298 + entry2 = ENTRY(header2+1);
1299 + while (!IS_LAST_ENTRY(entry1)) {
1300 + if (IS_LAST_ENTRY(entry2))
1302 + if (entry1->e_hash != entry2->e_hash ||
1303 + entry1->e_name_len != entry2->e_name_len ||
1304 + entry1->e_value_size != entry2->e_value_size ||
1305 + memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
1307 + if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
1309 + if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
1310 + (char *)header2 + le16_to_cpu(entry2->e_value_offs),
1311 + le32_to_cpu(entry1->e_value_size)))
1314 + entry1 = EXT3_XATTR_NEXT(entry1);
1315 + entry2 = EXT3_XATTR_NEXT(entry2);
1317 + if (!IS_LAST_ENTRY(entry2))
1323 + * ext3_xattr_cache_find()
1325 + * Find an identical extended attribute block.
1327 + * Returns a pointer to the block found, or NULL if such a block was
1328 + * not found or an error occurred.
1330 +static struct buffer_head *
1331 +ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header)
1333 + __u32 hash = le32_to_cpu(header->h_hash);
1334 + struct mb_cache_entry *ce;
1336 + if (!header->h_hash)
1337 + return NULL; /* never share */
1338 + ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
1339 + ce = mb_cache_entry_find_first(ext3_xattr_cache, 0, inode->i_dev, hash);
1341 + struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
1344 + ext3_error(inode->i_sb, "ext3_xattr_cache_find",
1345 + "inode %ld: block %ld read error",
1346 + inode->i_ino, ce->e_block);
1347 + } else if (le32_to_cpu(HDR(bh)->h_refcount) >
1348 + EXT3_XATTR_REFCOUNT_MAX) {
1349 + ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
1350 + le32_to_cpu(HDR(bh)->h_refcount),
1351 + EXT3_XATTR_REFCOUNT_MAX);
1352 + } else if (!ext3_xattr_cmp(header, HDR(bh))) {
1353 + ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
1354 + mb_cache_entry_release(ce);
1358 + ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
1364 + * ext3_xattr_cache_remove()
1366 + * Remove the cache entry of a block from the cache. Called when a
1367 + * block becomes invalid.
1370 +ext3_xattr_cache_remove(struct buffer_head *bh)
1372 + struct mb_cache_entry *ce;
1374 + ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_dev, bh->b_blocknr);
1376 + ea_bdebug(bh, "removing (%d cache entries remaining)",
1377 + atomic_read(&ext3_xattr_cache->c_entry_count)-1);
1378 + mb_cache_entry_free(ce);
1380 + ea_bdebug(bh, "no cache entry");
1383 +#define NAME_HASH_SHIFT 5
1384 +#define VALUE_HASH_SHIFT 16
1387 + * ext3_xattr_hash_entry()
1389 + * Compute the hash of an extended attribute.
1391 +static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
1392 + struct ext3_xattr_entry *entry)
1395 + char *name = entry->e_name;
1398 + for (n=0; n < entry->e_name_len; n++) {
1399 + hash = (hash << NAME_HASH_SHIFT) ^
1400 + (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
1404 + if (entry->e_value_block == 0 && entry->e_value_size != 0) {
1405 + __u32 *value = (__u32 *)((char *)header +
1406 + le16_to_cpu(entry->e_value_offs));
1407 + for (n = (le32_to_cpu(entry->e_value_size) +
1408 + EXT3_XATTR_ROUND) >> EXT3_XATTR_PAD_BITS; n; n--) {
1409 + hash = (hash << VALUE_HASH_SHIFT) ^
1410 + (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
1411 + le32_to_cpu(*value++);
1414 + entry->e_hash = cpu_to_le32(hash);
1417 +#undef NAME_HASH_SHIFT
1418 +#undef VALUE_HASH_SHIFT
1420 +#define BLOCK_HASH_SHIFT 16
1423 + * ext3_xattr_rehash()
1425 + * Re-compute the extended attribute hash value after an entry has changed.
1427 +static void ext3_xattr_rehash(struct ext3_xattr_header *header,
1428 + struct ext3_xattr_entry *entry)
1430 + struct ext3_xattr_entry *here;
1433 + ext3_xattr_hash_entry(header, entry);
1434 + here = ENTRY(header+1);
1435 + while (!IS_LAST_ENTRY(here)) {
1436 + if (!here->e_hash) {
1437 + /* Block is not shared if an entry's hash value == 0 */
1441 + hash = (hash << BLOCK_HASH_SHIFT) ^
1442 + (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
1443 + le32_to_cpu(here->e_hash);
1444 + here = EXT3_XATTR_NEXT(here);
1446 + header->h_hash = cpu_to_le32(hash);
1449 +#undef BLOCK_HASH_SHIFT
1452 +init_ext3_xattr(void)
1454 + ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL,
1455 + sizeof(struct mb_cache_entry) +
1456 + sizeof(struct mb_cache_entry_index), 1, 61);
1457 + if (!ext3_xattr_cache)
1464 +exit_ext3_xattr(void)
1466 + if (ext3_xattr_cache)
1467 + mb_cache_destroy(ext3_xattr_cache);
1468 + ext3_xattr_cache = NULL;
1471 +#else /* CONFIG_EXT3_FS_XATTR_SHARING */
1474 +init_ext3_xattr(void)
1480 +exit_ext3_xattr(void)
1484 +#endif /* CONFIG_EXT3_FS_XATTR_SHARING */
1485 --- linux-2.4.18/include/linux/ext3_fs.h~linux-2.4.18ea-0.8.26-2 2003-09-01 11:51:00.000000000 +0400
1486 +++ linux-2.4.18-alexey/include/linux/ext3_fs.h 2003-09-01 14:55:39.000000000 +0400
1489 #define EXT3_BAD_INO 1 /* Bad blocks inode */
1490 #define EXT3_ROOT_INO 2 /* Root inode */
1491 -#define EXT3_ACL_IDX_INO 3 /* ACL inode */
1492 -#define EXT3_ACL_DATA_INO 4 /* ACL inode */
1493 #define EXT3_BOOT_LOADER_INO 5 /* Boot loader inode */
1494 #define EXT3_UNDEL_DIR_INO 6 /* Undelete directory inode */
1495 #define EXT3_RESIZE_INO 7 /* Reserved group descriptors inode */
1498 # define EXT3_BLOCK_SIZE(s) (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
1500 -#define EXT3_ACLE_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_acl_entry))
1501 #define EXT3_ADDR_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (__u32))
1503 # define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
1504 @@ -129,28 +126,6 @@
1510 -struct ext3_acl_header /* Header of Access Control Lists */
1513 - __u32 aclh_file_count;
1514 - __u32 aclh_acle_count;
1515 - __u32 aclh_first_acle;
1518 -struct ext3_acl_entry /* Access Control List Entry */
1521 - __u16 acle_perms; /* Access permissions */
1522 - __u16 acle_type; /* Type of entry */
1523 - __u16 acle_tag; /* User or group identity */
1525 - __u32 acle_next; /* Pointer on next entry for the */
1526 - /* same inode or on next free entry */
1530 * Structure of a blocks group descriptor
1532 struct ext3_group_desc
1533 @@ -521,7 +496,7 @@ struct ext3_super_block {
1534 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
1535 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
1537 -#define EXT3_FEATURE_COMPAT_SUPP 0
1538 +#define EXT3_FEATURE_COMPAT_SUPP EXT3_FEATURE_COMPAT_EXT_ATTR
1539 #define EXT3_FEATURE_INCOMPAT_SUPP (EXT3_FEATURE_INCOMPAT_FILETYPE| \
1540 EXT3_FEATURE_INCOMPAT_RECOVER)
1541 #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
1542 @@ -623,6 +598,24 @@ struct dx_hash_info
1543 #define HASH_NB_ALWAYS 1
1546 +/* Defined for extended attributes */
1547 +#define CONFIG_EXT3_FS_XATTR y
1549 +#define ENOATTR ENODATA /* No such attribute */
1552 +#define ENOTSUP EOPNOTSUPP /* Operation not supported */
1554 +#ifndef XATTR_NAME_MAX
1555 +#define XATTR_NAME_MAX 255 /* # chars in an extended attribute name */
1556 +#define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */
1557 +#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */
1559 +#ifndef XATTR_CREATE
1560 +#define XATTR_CREATE 1 /* set value, fail if attr already exists */
1561 +#define XATTR_REPLACE 2 /* set value, fail if attr does not exist */
1565 * Describe an inode's exact location on disk and in memory
1567 @@ -704,6 +697,7 @@ extern void ext3_check_inodes_bitmap (st
1568 extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
1571 +extern int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
1572 extern struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
1573 extern struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
1575 --- linux-2.4.18/include/linux/ext3_jbd.h~linux-2.4.18ea-0.8.26-2 2003-08-29 16:53:17.000000000 +0400
1576 +++ linux-2.4.18-alexey/include/linux/ext3_jbd.h 2003-09-01 14:55:39.000000000 +0400
1579 #define EXT3_SINGLEDATA_TRANS_BLOCKS 8
1581 +/* Extended attributes may touch two data buffers, two bitmap buffers,
1582 + * and two group and summaries. */
1584 +#define EXT3_XATTR_TRANS_BLOCKS 8
1586 /* Define the minimum size for a transaction which modifies data. This
1587 * needs to take into account the fact that we may end up modifying two
1588 * quota files too (one for the group, one for the user quota). The
1589 * superblock only gets updated once, of course, so don't bother
1590 * counting that again for the quota updates. */
1592 -#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS - 2)
1593 +#define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS + \
1594 + EXT3_XATTR_TRANS_BLOCKS - 2)
1596 extern int ext3_writepage_trans_blocks(struct inode *inode);
1598 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
1599 +++ linux-2.4.18-alexey/include/linux/ext3_xattr.h 2003-09-01 14:55:39.000000000 +0400
1602 + File: linux/ext3_xattr.h
1604 + On-disk format of extended attributes for the ext3 filesystem.
1606 + (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
1609 +#include <linux/config.h>
1610 +#include <linux/init.h>
1611 +#include <linux/xattr.h>
1613 +/* Magic value in attribute blocks */
1614 +#define EXT3_XATTR_MAGIC 0xEA020000
1616 +/* Maximum number of references to one attribute block */
1617 +#define EXT3_XATTR_REFCOUNT_MAX 1024
1620 +#define EXT3_XATTR_INDEX_MAX 10
1621 +#define EXT3_XATTR_INDEX_USER 1
1623 +struct ext3_xattr_header {
1624 + __u32 h_magic; /* magic number for identification */
1625 + __u32 h_refcount; /* reference count */
1626 + __u32 h_blocks; /* number of disk blocks used */
1627 + __u32 h_hash; /* hash value of all attributes */
1628 + __u32 h_reserved[4]; /* zero right now */
1631 +struct ext3_xattr_entry {
1632 + __u8 e_name_len; /* length of name */
1633 + __u8 e_name_index; /* attribute name index */
1634 + __u16 e_value_offs; /* offset in disk block of value */
1635 + __u32 e_value_block; /* disk block attribute is stored on (n/i) */
1636 + __u32 e_value_size; /* size of attribute value */
1637 + __u32 e_hash; /* hash value of name and value */
1638 + char e_name[0]; /* attribute name */
1641 +#define EXT3_XATTR_PAD_BITS 2
1642 +#define EXT3_XATTR_PAD (1<<EXT3_XATTR_PAD_BITS)
1643 +#define EXT3_XATTR_ROUND (EXT3_XATTR_PAD-1)
1644 +#define EXT3_XATTR_LEN(name_len) \
1645 + (((name_len) + EXT3_XATTR_ROUND + \
1646 + sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND)
1647 +#define EXT3_XATTR_NEXT(entry) \
1648 + ( (struct ext3_xattr_entry *)( \
1649 + (char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) )
1650 +#define EXT3_XATTR_SIZE(size) \
1651 + (((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND)
1655 +# ifdef CONFIG_EXT3_FS_XATTR
1657 +struct ext3_xattr_handler {
1659 + size_t (*list)(char *list, struct inode *inode, const char *name,
1661 + int (*get)(struct inode *inode, const char *name, void *buffer,
1663 + int (*set)(struct inode *inode, const char *name, void *buffer,
1664 + size_t size, int flags);
1667 +extern int ext3_xattr_register(int, struct ext3_xattr_handler *);
1668 +extern void ext3_xattr_unregister(int, struct ext3_xattr_handler *);
1670 +extern int ext3_setxattr(struct dentry *, const char *, void *, size_t, int);
1671 +extern ssize_t ext3_getxattr(struct dentry *, const char *, void *, size_t);
1672 +extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
1673 +extern int ext3_removexattr(struct dentry *, const char *);
1675 +extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
1676 +extern int ext3_xattr_list(struct inode *, char *, size_t);
1677 +extern int ext3_xattr_set(handle_t *handle, struct inode *, int, const char *, void *, size_t, int);
1679 +extern void ext3_xattr_drop_inode(handle_t *, struct inode *);
1680 +extern void ext3_xattr_put_super(struct super_block *);
1682 +extern int init_ext3_xattr(void) __init;
1683 +extern void exit_ext3_xattr(void);
1685 +# else /* CONFIG_EXT3_FS_XATTR */
1686 +# define ext3_setxattr NULL
1687 +# define ext3_getxattr NULL
1688 +# define ext3_listxattr NULL
1689 +# define ext3_removexattr NULL
1692 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
1693 + void *buffer, size_t size, int flags)
1699 +ext3_xattr_list(struct inode *inode, void *buffer, size_t size, int flags)
1705 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
1706 + const char *name, void *value, size_t size, int flags)
1712 +ext3_xattr_drop_inode(handle_t *handle, struct inode *inode)
1717 +ext3_xattr_put_super(struct super_block *sb)
1722 +init_ext3_xattr(void)
1728 +exit_ext3_xattr(void)
1732 +# endif /* CONFIG_EXT3_FS_XATTR */
1734 +# ifdef CONFIG_EXT3_FS_XATTR_USER
1736 +extern int init_ext3_xattr_user(void) __init;
1737 +extern void exit_ext3_xattr_user(void);
1739 +# else /* CONFIG_EXT3_FS_XATTR_USER */
1742 +init_ext3_xattr_user(void)
1748 +exit_ext3_xattr_user(void)
1752 +#endif /* CONFIG_EXT3_FS_XATTR_USER */
1754 +#endif /* __KERNEL__ */
1756 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
1757 +++ linux-2.4.18-alexey/include/linux/xattr.h 2003-09-01 14:55:39.000000000 +0400
1760 + File: linux/xattr.h
1762 + Extended attributes handling.
1764 + Copyright (C) 2001 by Andreas Gruenbacher <a.gruenbacher@computer.org>
1765 + Copyright (C) 2001 SGI - Silicon Graphics, Inc <linux-xfs@oss.sgi.com>
1767 +#ifndef _LINUX_XATTR_H
1768 +#define _LINUX_XATTR_H
1770 +#define XATTR_CREATE 1 /* set value, fail if attr already exists */
1771 +#define XATTR_REPLACE 2 /* set value, fail if attr does not exist */
1773 +#endif /* _LINUX_XATTR_H */