Whamcloud - gitweb
15df90c5200181c4f8c47af41281e263d18181f3
[fs/lustre-release.git] / lustre / extN / linux-2.4.18ea-0.8.26.diff
1 Linux Extended Attributes -- Kernel Patch
2 24 April 2002, 11:31:18
3
4
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.
9
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.
14
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
18
19
20 After extracting the linux-2.4.18.tar.gz package, apply this patch as follows:
21
22         cd linux
23         patch -p1 < ../linux-2.4.18ea-0.8.26.patch
24
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
28 @@ -17,6 +17,7 @@
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>
36 @@ -216,6 +217,7 @@
37          * as writing the quota to disk may need the lock as well.
38          */
39         DQUOT_INIT(inode);
40 +       ext3_xattr_drop_inode(handle, inode);
41         DQUOT_FREE_INODE(inode);
42         DQUOT_DROP(inode);
43  
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
47 @@ -39,6 +39,18 @@
48   */
49  #undef SEARCH_FROM_ZERO
50  
51 +/*
52 + * Test whether an inode is a fast symlink.
53 + */
54 +static inline int ext3_inode_is_fast_symlink(struct inode *inode)
55 +{
56 +       int ea_blocks = EXT3_I(inode)->i_file_acl ?
57 +               (inode->i_sb->s_blocksize >> 9) : 0;
58 +
59 +       return (S_ISLNK(inode->i_mode) &&
60 +               inode->i_blocks - ea_blocks == 0);
61 +}
62 +
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. 
66 @@ -48,7 +60,7 @@
67   * still needs to be revoked.
68   */
69  
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,
73                        int blocknr)
74  {
75 @@ -164,9 +176,7 @@
76  {
77         handle_t *handle;
78         
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))
83                 goto no_delete;
84  
85         lock_kernel();
86 @@ -1845,6 +1855,8 @@
87         if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
88             S_ISLNK(inode->i_mode)))
89                 return;
90 +       if (ext3_inode_is_fast_symlink(inode))
91 +               return;
92         if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
93                 return;
94  
95 @@ -1992,8 +2004,6 @@
96         struct ext3_group_desc * gdp;
97                 
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 @@
105  
106         brelse (iloc.bh);
107  
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;
123                 else {
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
128 @@ -23,6 +23,7 @@
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>
136 @@ -465,6 +466,8 @@
137                 inode->i_fop = &extN_file_operations;
138                 inode->i_mapping->a_ops = &ext3_aops;
139                 err = ext3_add_nondir(handle, dentry, inode);
140 +               if (err)
141 +                       ext3_xattr_drop_inode(handle, inode);
142                 ext3_mark_inode_dirty(handle, inode);
143         }
144         ext3_journal_stop(handle, dir);
145 @@ -490,6 +493,8 @@
146         if (!IS_ERR(inode)) {
147                 init_special_inode(inode, mode, rdev);
148                 err = ext3_add_nondir(handle, dentry, inode);
149 +               if (err)
150 +                       ext3_xattr_drop_inode(handle, inode);
151                 ext3_mark_inode_dirty(handle, inode);
152         }
153         ext3_journal_stop(handle, dir);
154 @@ -514,7 +519,7 @@
155         if (IS_SYNC(dir))
156                 handle->h_sync = 1;
157  
158 -       inode = ext3_new_inode (handle, dir, S_IFDIR);
159 +       inode = ext3_new_inode (handle, dir, S_IFDIR | mode);
160         err = PTR_ERR(inode);
161         if (IS_ERR(inode))
162                 goto out_stop;
163 @@ -522,7 +527,6 @@
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);
170         if (!dir_block) {
171                 inode->i_nlink--; /* is this nlink == 0? */
172 @@ -549,9 +553,6 @@
173         BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata");
174         ext3_journal_dirty_metadata(handle, dir_block);
175         brelse (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);
181         if (err)
182 @@ -565,6 +566,7 @@
183         return err;
184  
185  out_no_entry:
186 +       ext3_xattr_drop_inode(handle, inode);
187         inode->i_nlink = 0;
188         ext3_mark_inode_dirty(handle, inode);
189         iput (inode);
190 @@ -917,5 +919,5 @@
191                 goto out_stop;
192  
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
200 @@ -24,6 +24,7 @@
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>
208 @@ -404,6 +405,7 @@
209         kdev_t j_dev = sbi->s_journal->j_dev;
210         int i;
211  
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 @@
217  
218  static DECLARE_FSTYPE_DEV(ext3_fs_type, "ext3", ext3_read_super);
219  
220 -static int __init init_ext3_fs(void)
221 +static void exit_ext3_fs(void)
222  {
223 -        return register_filesystem(&ext3_fs_type);
224 +       unregister_filesystem(&ext3_fs_type);
225 +       exit_ext3_xattr_user();
226 +       exit_ext3_xattr();
227  }
228  
229 -static void __exit exit_ext3_fs(void)
230 +static int __init init_ext3_fs(void)
231  {
232 -       unregister_filesystem(&ext3_fs_type);
233 +       int error = init_ext3_xattr();
234 +       if (!error)
235 +               error = init_ext3_xattr_user();
236 +       if (!error)
237 +               error = register_filesystem(&ext3_fs_type);
238 +       if (!error)
239 +               return 0;
240 +
241 +       exit_ext3_fs();
242 +       return error;
243  }
244  
245  EXPORT_NO_SYMBOLS;
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
249 @@ -0,0 +1,1247 @@
250 +/*
251 + * linux/fs/ext3/xattr.c
252 + *
253 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
254 + *
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>.
259 + */
260 +
261 +/*
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.
268 + *
269 + *
270 + * Extended attribute block layout:
271 + *
272 + *   +------------------+
273 + *   | header           |
274 + *   Â¦ entry 1          | |
275 + *   | entry 2          | | growing downwards
276 + *   | entry 3          | v
277 + *   | four null bytes  |
278 + *   | . . .            |
279 + *   | value 1          | ^
280 + *   | value 3          | | growing upwards
281 + *   | value 2          | |
282 + *   +------------------+
283 + *
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.
288 + *
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.
292 + *
293 + * Locking strategy
294 + * ----------------
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.
298 + *
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.
302 + *
303 + * Note for porting to 2.5
304 + * -----------------------
305 + * The BKL will no longer be held in the xattr inode operations.
306 + */
307 +
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>
316 +#endif
317 +#include <linux/quotaops.h>
318 +#include <asm/semaphore.h>
319 +#include <linux/compatmac.h>
320 +#include <linux/module.h>
321 +
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);
328 +
329 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
330 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
331 +#endif
332 +
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)
337 +
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); \
342 +               printk(f); \
343 +               printk("\n"); \
344 +       } while (0)
345 +# define ea_bdebug(bh, f...) do { \
346 +               printk(KERN_DEBUG "block %s:%ld: ", \
347 +                       kdevname(bh->b_dev), bh->b_blocknr); \
348 +               printk(f); \
349 +               printk("\n"); \
350 +       } while (0)
351 +#else
352 +# define ea_idebug(f...)
353 +# define ea_bdebug(f...)
354 +#endif
355 +
356 +static int ext3_xattr_set2(handle_t *, struct inode *, struct buffer_head *,
357 +                          struct ext3_xattr_header *);
358 +
359 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
360 +
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 *);
367 +
368 +static struct mb_cache *ext3_xattr_cache;
369 +
370 +#else
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)
375 +#endif
376 +
377 +/*
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
381 + * the lock.
382 + */
383 +
384 +DECLARE_MUTEX(ext3_xattr_sem);
385 +
386 +static inline void
387 +ext3_xattr_lock(void)
388 +{
389 +       down(&ext3_xattr_sem);
390 +}
391 +
392 +static inline void
393 +ext3_xattr_unlock(void)
394 +{
395 +       up(&ext3_xattr_sem);
396 +}
397 +
398 +static inline int
399 +ext3_xattr_new_block(handle_t *handle, struct inode *inode,
400 +                    int * errp, int force)
401 +{
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);
405 +
406 +       /* How can we enforce the allocation? */
407 +       int block = ext3_new_block(handle, inode, goal, 0, 0, errp);
408 +#ifdef OLD_QUOTAS
409 +       if (!*errp)
410 +               inode->i_blocks += inode->i_sb->s_blocksize >> 9;
411 +#endif
412 +       return block;
413 +}
414 +
415 +static inline int
416 +ext3_xattr_quota_alloc(struct inode *inode, int force)
417 +{
418 +       /* How can we enforce the allocation? */
419 +#ifdef OLD_QUOTAS
420 +       int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
421 +       if (!error)
422 +               inode->i_blocks += inode->i_sb->s_blocksize >> 9;
423 +#else
424 +       int error = DQUOT_ALLOC_BLOCK(inode, 1);
425 +#endif
426 +       return error;
427 +}
428 +
429 +#ifdef OLD_QUOTAS
430 +
431 +static inline void
432 +ext3_xattr_quota_free(struct inode *inode)
433 +{
434 +       DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
435 +       inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
436 +}
437 +
438 +static inline void
439 +ext3_xattr_free_block(handle_t *handle, struct inode * inode,
440 +                     unsigned long block)
441 +{
442 +       ext3_free_blocks(handle, inode, block, 1);
443 +       inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
444 +}
445 +
446 +#else
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)
451 +#endif
452 +
453 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
454 +
455 +static inline struct buffer_head *
456 +sb_bread(struct super_block *sb, int block)
457 +{
458 +       return bread(sb->s_dev, block, sb->s_blocksize);
459 +}
460 +
461 +static inline struct buffer_head *
462 +sb_getblk(struct super_block *sb, int block)
463 +{
464 +       return getblk(sb->s_dev, block, sb->s_blocksize);
465 +}
466 +
467 +#endif
468 +
469 +struct ext3_xattr_handler *ext3_xattr_handlers[EXT3_XATTR_INDEX_MAX];
470 +rwlock_t ext3_handler_lock = RW_LOCK_UNLOCKED;
471 +
472 +int
473 +ext3_xattr_register(int name_index, struct ext3_xattr_handler *handler)
474 +{
475 +       int error = -EINVAL;
476 +
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;
481 +                       error = 0;
482 +               }
483 +               write_unlock(&ext3_handler_lock);
484 +       }
485 +       return error;
486 +}
487 +
488 +void
489 +ext3_xattr_unregister(int name_index, struct ext3_xattr_handler *handler)
490 +{
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);
495 +       }
496 +}
497 +
498 +static inline const char *
499 +strcmp_prefix(const char *a, const char *a_prefix)
500 +{
501 +       while (*a_prefix && *a == *a_prefix) {
502 +               a++;
503 +               a_prefix++;
504 +       }
505 +       return *a_prefix ? NULL : a;
506 +}
507 +
508 +/*
509 + * Decode the extended attribute name, and translate it into
510 + * the name_index and name suffix.
511 + */
512 +static inline struct ext3_xattr_handler *
513 +ext3_xattr_resolve_name(const char **name)
514 +{
515 +       struct ext3_xattr_handler *handler = NULL;
516 +       int i;
517 +
518 +       if (!*name)
519 +               return 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);
525 +                       if (n) {
526 +                               handler = ext3_xattr_handlers[i];
527 +                               *name = n;
528 +                               break;
529 +                       }
530 +               }
531 +       }
532 +       read_unlock(&ext3_handler_lock);
533 +       return handler;
534 +}
535 +
536 +static inline struct ext3_xattr_handler *
537 +ext3_xattr_handler(int name_index)
538 +{
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);
544 +       }
545 +       return handler;
546 +}
547 +
548 +/*
549 + * Inode operation getxattr()
550 + *
551 + * dentry->d_inode->i_sem down
552 + * BKL held [before 2.5.x]
553 + */
554 +ssize_t
555 +ext3_getxattr(struct dentry *dentry, const char *name,
556 +             void *buffer, size_t size)
557 +{
558 +       struct ext3_xattr_handler *handler;
559 +       struct inode *inode = dentry->d_inode;
560 +
561 +       handler = ext3_xattr_resolve_name(&name);
562 +       if (!handler)
563 +               return -ENOTSUP;
564 +       return handler->get(inode, name, buffer, size);
565 +}
566 +
567 +/*
568 + * Inode operation listxattr()
569 + *
570 + * dentry->d_inode->i_sem down
571 + * BKL held [before 2.5.x]
572 + */
573 +ssize_t
574 +ext3_listxattr(struct dentry *dentry, char *buffer, size_t size)
575 +{
576 +       return ext3_xattr_list(dentry->d_inode, buffer, size);
577 +}
578 +
579 +/*
580 + * Inode operation setxattr()
581 + *
582 + * dentry->d_inode->i_sem down
583 + * BKL held [before 2.5.x]
584 + */
585 +int
586 +ext3_setxattr(struct dentry *dentry, const char *name,
587 +             void *value, size_t size, int flags)
588 +{
589 +       struct ext3_xattr_handler *handler;
590 +       struct inode *inode = dentry->d_inode;
591 +
592 +       if (size == 0)
593 +               value = "";  /* empty EA, do not remove */
594 +       handler = ext3_xattr_resolve_name(&name);
595 +       if (!handler)
596 +               return -ENOTSUP;
597 +       return handler->set(inode, name, value, size, flags);
598 +}
599 +
600 +/*
601 + * Inode operation removexattr()
602 + *
603 + * dentry->d_inode->i_sem down
604 + * BKL held [before 2.5.x]
605 + */
606 +int
607 +ext3_removexattr(struct dentry *dentry, const char *name)
608 +{
609 +       struct ext3_xattr_handler *handler;
610 +       struct inode *inode = dentry->d_inode;
611 +
612 +       handler = ext3_xattr_resolve_name(&name);
613 +       if (!handler)
614 +               return -ENOTSUP;
615 +       return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
616 +}
617 +
618 +/*
619 + * ext3_xattr_get()
620 + *
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.
624 + *
625 + * Returns a negative error number on failure, or the number of bytes
626 + * used / required on success.
627 + */
628 +int
629 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
630 +              void *buffer, size_t buffer_size)
631 +{
632 +       struct buffer_head *bh = NULL;
633 +       struct ext3_xattr_entry *entry;
634 +       unsigned int block, size;
635 +       char *end;
636 +       int name_len, error;
637 +
638 +       ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
639 +                 name_index, name, buffer, (long)buffer_size);
640 +
641 +       if (name == NULL)
642 +               return -EINVAL;
643 +       if (!EXT3_I(inode)->i_file_acl)
644 +               return -ENOATTR;
645 +       block = EXT3_I(inode)->i_file_acl;
646 +       ea_idebug(inode, "reading block %d", block);
647 +       bh = sb_bread(inode->i_sb, block);
648 +       if (!bh)
649 +               return -EIO;
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);
657 +               error = -EIO;
658 +               goto cleanup;
659 +       }
660 +       /* find named attribute */
661 +       name_len = strlen(name);
662 +
663 +       error = -ERANGE;
664 +       if (name_len > 255)
665 +               goto cleanup;
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)
671 +                       goto bad_block;
672 +               if (name_index == entry->e_name_index &&
673 +                   name_len == entry->e_name_len &&
674 +                   memcmp(name, entry->e_name, name_len) == 0)
675 +                       goto found;
676 +               entry = next;
677 +       }
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)
683 +                       goto bad_block;
684 +               entry = next;
685 +       }
686 +       if (ext3_xattr_cache_insert(bh))
687 +               ea_idebug(inode, "cache insert failed");
688 +       error = -ENOATTR;
689 +       goto cleanup;
690 +found:
691 +       /* check the buffer size */
692 +       if (entry->e_value_block != 0)
693 +               goto bad_block;
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)
697 +               goto bad_block;
698 +
699 +       if (ext3_xattr_cache_insert(bh))
700 +               ea_idebug(inode, "cache insert failed");
701 +       if (buffer) {
702 +               error = -ERANGE;
703 +               if (size > buffer_size)
704 +                       goto cleanup;
705 +               /* return value of attribute */
706 +               memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
707 +                       size);
708 +       }
709 +       error = size;
710 +
711 +cleanup:
712 +       brelse(bh);
713 +
714 +       return error;
715 +}
716 +
717 +/*
718 + * ext3_xattr_list()
719 + *
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.
723 + *
724 + * Returns a negative error number on failure, or the number of bytes
725 + * used / required on success.
726 + */
727 +int
728 +ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
729 +{
730 +       struct buffer_head *bh = NULL;
731 +       struct ext3_xattr_entry *entry;
732 +       unsigned int block, size = 0;
733 +       char *buf, *end;
734 +       int error;
735 +
736 +       ea_idebug(inode, "buffer=%p, buffer_size=%ld",
737 +                 buffer, (long)buffer_size);
738 +
739 +       if (!EXT3_I(inode)->i_file_acl)
740 +               return 0;
741 +       block = EXT3_I(inode)->i_file_acl;
742 +       ea_idebug(inode, "reading block %d", block);
743 +       bh = sb_bread(inode->i_sb, block);
744 +       if (!bh)
745 +               return -EIO;
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);
753 +               error = -EIO;
754 +               goto cleanup;
755 +       }
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)
763 +                       goto bad_block;
764 +
765 +               handler = ext3_xattr_handler(entry->e_name_index);
766 +               if (handler) {
767 +                       size += handler->list(NULL, inode, entry->e_name,
768 +                                             entry->e_name_len) + 1;
769 +               }
770 +       }
771 +
772 +       if (ext3_xattr_cache_insert(bh))
773 +               ea_idebug(inode, "cache insert failed");
774 +       if (!buffer) {
775 +               error = size;
776 +               goto cleanup;
777 +       } else {
778 +               error = -ERANGE;
779 +               if (size > buffer_size)
780 +                       goto cleanup;
781 +       }
782 +
783 +       /* list the attribute names */
784 +       buf = buffer;
785 +       for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
786 +            entry = EXT3_XATTR_NEXT(entry)) {
787 +               struct ext3_xattr_handler *handler;
788 +
789 +               handler = ext3_xattr_handler(entry->e_name_index);
790 +               if (handler) {
791 +                       buf += handler->list(buf, inode, entry->e_name,
792 +                                            entry->e_name_len);
793 +                       *buf++ = '\0';
794 +               }
795 +       }
796 +       error = size;
797 +
798 +cleanup:
799 +       brelse(bh);
800 +
801 +       return error;
802 +}
803 +
804 +/*
805 + * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is
806 + * not set, set it.
807 + */
808 +static void ext3_xattr_update_super_block(handle_t *handle,
809 +                                         struct super_block *sb)
810 +{
811 +       if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR))
812 +               return;
813 +
814 +       lock_super(sb);
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;
818 +#endif
819 +       EXT3_SB(sb)->s_es->s_feature_compat |=
820 +               cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR);
821 +       sb->s_dirt = 1;
822 +       ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
823 +       unlock_super(sb);
824 +}
825 +
826 +/*
827 + * ext3_xattr_set()
828 + *
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.
835 + *
836 + * Returns 0, or a negative error number on failure.
837 + */
838 +int
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)
841 +{
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;
848 +       char *end;
849 +       
850 +       /*
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.
860 +        */
861 +       
862 +       ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
863 +                 name_index, name, value, (long)value_len);
864 +
865 +       if (IS_RDONLY(inode))
866 +               return -EROFS;
867 +       if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
868 +               return -EPERM;
869 +       if (value == NULL)
870 +               value_len = 0;
871 +       if (name == NULL)
872 +               return -EINVAL;
873 +       name_len = strlen(name);
874 +       if (name_len > 255 || value_len > sb->s_blocksize)
875 +               return -ERANGE;
876 +       ext3_xattr_lock();
877 +
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;
881 +
882 +               bh = sb_bread(sb, block);
883 +               error = -EIO;
884 +               if (!bh)
885 +                       goto cleanup;
886 +               ea_bdebug(bh, "b_count=%d, refcount=%d",
887 +                       atomic_read(&(bh->b_count)),
888 +                       le32_to_cpu(HDR(bh)->h_refcount));
889 +               header = HDR(bh);
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);
895 +                       error = -EIO;
896 +                       goto cleanup;
897 +               }
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)
903 +                               goto bad_block;
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)
907 +                                       min_offs = offs;
908 +                       }
909 +                       not_found = name_index - here->e_name_index;
910 +                       if (!not_found)
911 +                               not_found = name_len - here->e_name_len;
912 +                       if (!not_found)
913 +                               not_found = memcmp(name, here->e_name,name_len);
914 +                       if (not_found <= 0)
915 +                               break;
916 +                       here = next;
917 +               }
918 +               last = here;
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)
923 +                               goto bad_block;
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)
927 +                                       min_offs = offs;
928 +                       }
929 +                       last = next;
930 +               }
931 +
932 +               /* Check whether we have enough space left. */
933 +               free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
934 +       } else {
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. */
939 +       }
940 +
941 +       if (not_found) {
942 +               /* Request to remove a nonexistent attribute? */
943 +               error = -ENOATTR;
944 +               if (flags & XATTR_REPLACE)
945 +                       goto cleanup;
946 +               error = 0;
947 +               if (value == NULL)
948 +                       goto cleanup;
949 +               else
950 +                       free -= EXT3_XATTR_LEN(name_len);
951 +       } else {
952 +               /* Request to create an existing attribute? */
953 +               error = -EEXIST;
954 +               if (flags & XATTR_CREATE)
955 +                       goto cleanup;
956 +               if (!here->e_value_block && here->e_value_size) {
957 +                       unsigned int size = le32_to_cpu(here->e_value_size);
958 +
959 +                       if (le16_to_cpu(here->e_value_offs) + size > 
960 +                           sb->s_blocksize || size > sb->s_blocksize)
961 +                               goto bad_block;
962 +                       free += EXT3_XATTR_SIZE(size);
963 +               }
964 +       }
965 +       free -= EXT3_XATTR_SIZE(value_len);
966 +       error = -ENOSPC;
967 +       if (free < 0)
968 +               goto cleanup;
969 +
970 +       /* Here we know that we can set the new attribute. */
971 +
972 +       if (header) {
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);
977 +                       if (error)
978 +                               goto cleanup;
979 +               } else {
980 +                       int offset;
981 +
982 +                       ea_bdebug(bh, "cloning");
983 +                       header = kmalloc(bh->b_size, GFP_KERNEL);
984 +                       error = -ENOMEM;
985 +                       if (header == NULL)
986 +                               goto cleanup;
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);
992 +               }
993 +       } else {
994 +               /* Allocate a buffer where we construct the new block. */
995 +               header = kmalloc(sb->s_blocksize, GFP_KERNEL);
996 +               error = -ENOMEM;
997 +               if (header == NULL)
998 +                       goto cleanup;
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);
1004 +       }
1005 +
1006 +       if (not_found) {
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);
1015 +       } else {
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;
1026 +                       min_offs += size;
1027 +
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);
1036 +                       }
1037 +               }
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);
1043 +                               goto cleanup;
1044 +                       } else {
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);
1051 +                       }
1052 +               }
1053 +       }
1054 +
1055 +       if (value != NULL) {
1056 +               /* Insert the new value. */
1057 +               here->e_value_size = cpu_to_le32(value_len);
1058 +               if (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);
1066 +               }
1067 +       }
1068 +       ext3_xattr_rehash(header, here);
1069 +
1070 +       error = ext3_xattr_set2(handle, inode, bh, header);
1071 +
1072 +cleanup:
1073 +       brelse(bh);
1074 +       if (!(bh && header == HDR(bh)))
1075 +               kfree(header);
1076 +       ext3_xattr_unlock();
1077 +
1078 +       return error;
1079 +}
1080 +
1081 +/*
1082 + * Second half of ext3_xattr_set(): Update the file system.
1083 + */
1084 +static int
1085 +ext3_xattr_set2(handle_t *handle, struct inode *inode,
1086 +               struct buffer_head *old_bh, struct ext3_xattr_header *header)
1087 +{
1088 +       struct super_block *sb = inode->i_sb;
1089 +       struct buffer_head *new_bh = NULL;
1090 +       int error;
1091 +
1092 +       if (header) {
1093 +               new_bh = ext3_xattr_cache_find(inode, header);
1094 +               if (new_bh) {
1095 +                       /*
1096 +                        * We found an identical block in the cache.
1097 +                        * The old block will be released after updating
1098 +                        * the inode.
1099 +                        */
1100 +                       ea_bdebug(old_bh, "reusing block %ld",
1101 +                               new_bh->b_blocknr);
1102 +                       
1103 +                       error = -EDQUOT;
1104 +                       if (ext3_xattr_quota_alloc(inode, 1))
1105 +                               goto cleanup;
1106 +                       
1107 +                       error = ext3_journal_get_write_access(handle, new_bh);
1108 +                       if (error)
1109 +                               goto cleanup;
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. */
1116 +                       new_bh = old_bh;
1117 +                       (void)ext3_xattr_cache_insert(new_bh);
1118 +               } else {
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,
1122 +                                                        &error, force);
1123 +                       if (error)
1124 +                               goto cleanup;
1125 +                       ea_idebug(inode, "creating block %d", block);
1126 +
1127 +                       new_bh = sb_getblk(sb, block);
1128 +                       if (!new_bh) {
1129 +getblk_failed:                 ext3_xattr_free_block(handle, inode, block);
1130 +                               error = -EIO;
1131 +                               goto cleanup;
1132 +                       }
1133 +                       lock_buffer(new_bh);
1134 +                       error = ext3_journal_get_create_access(handle, new_bh);
1135 +                       if (error) {
1136 +                               unlock_buffer(new_bh);
1137 +                               goto getblk_failed;
1138 +                       }
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);
1144 +               }
1145 +               error = ext3_journal_dirty_metadata(handle, new_bh);
1146 +               if (error)
1147 +                       goto cleanup;
1148 +       }
1149 +
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;
1156 +
1157 +       error = 0;
1158 +       if (old_bh && old_bh != new_bh) {
1159 +               /*
1160 +                * If there was an old block, and we are not still using it,
1161 +                * we now release the old block.
1162 +               */
1163 +               unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
1164 +
1165 +               error = ext3_journal_get_write_access(handle, old_bh);
1166 +               if (error)
1167 +                       goto cleanup;
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);
1172 +
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. */
1176 +                       get_bh(old_bh);
1177 +                       ext3_forget(handle, 1, inode, old_bh,old_bh->b_blocknr);
1178 +               } else {
1179 +                       /* Decrement the refcount only. */
1180 +                       refcount--;
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);
1185 +               }
1186 +       }
1187 +
1188 +cleanup:
1189 +       if (old_bh != new_bh)
1190 +               brelse(new_bh);
1191 +
1192 +       return error;
1193 +}
1194 +
1195 +/*
1196 + * ext3_xattr_drop_inode()
1197 + *
1198 + * Free extended attribute resources associated with this inode. This
1199 + * is called immediately before an inode is freed.
1200 + */
1201 +void
1202 +ext3_xattr_drop_inode(handle_t *handle, struct inode *inode)
1203 +{
1204 +       struct buffer_head *bh;
1205 +       unsigned int block = EXT3_I(inode)->i_file_acl;
1206 +
1207 +       if (!block)
1208 +               return;
1209 +       ext3_xattr_lock();
1210 +
1211 +       bh = sb_bread(inode->i_sb, block);
1212 +       if (!bh) {
1213 +               ext3_error(inode->i_sb, "ext3_xattr_drop_inode",
1214 +                       "inode %ld: block %d read error", inode->i_ino, block);
1215 +               goto cleanup;
1216 +       }
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);
1222 +               goto cleanup;
1223 +       }
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);
1230 +               bh = NULL;
1231 +       } else {
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);
1238 +       }
1239 +       EXT3_I(inode)->i_file_acl = 0;
1240 +
1241 +cleanup:
1242 +       brelse(bh);
1243 +       ext3_xattr_unlock();
1244 +}
1245 +
1246 +/*
1247 + * ext3_xattr_put_super()
1248 + *
1249 + * This is called when a file system is unmounted.
1250 + */
1251 +void
1252 +ext3_xattr_put_super(struct super_block *sb)
1253 +{
1254 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
1255 +       mb_cache_shrink(ext3_xattr_cache, sb->s_dev);
1256 +#endif
1257 +}
1258 +
1259 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
1260 +
1261 +/*
1262 + * ext3_xattr_cache_insert()
1263 + *
1264 + * Create a new entry in the extended attribute cache, and insert
1265 + * it unless such an entry is already in the cache.
1266 + *
1267 + * Returns 0, or a negative error number on failure.
1268 + */
1269 +static int
1270 +ext3_xattr_cache_insert(struct buffer_head *bh)
1271 +{
1272 +       __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
1273 +       struct mb_cache_entry *ce;
1274 +       int error;
1275 +
1276 +       ce = mb_cache_entry_alloc(ext3_xattr_cache);
1277 +       if (!ce)
1278 +               return -ENOMEM;
1279 +       error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
1280 +       if (error) {
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));
1285 +                       error = 0;
1286 +               }
1287 +       } else {
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);
1291 +       }
1292 +       return error;
1293 +}
1294 +
1295 +/*
1296 + * ext3_xattr_cmp()
1297 + *
1298 + * Compare two extended attribute blocks for equality.
1299 + *
1300 + * Returns 0 if the blocks are equal, 1 if they differ, and
1301 + * a negative error number on errors.
1302 + */
1303 +static int
1304 +ext3_xattr_cmp(struct ext3_xattr_header *header1,
1305 +              struct ext3_xattr_header *header2)
1306 +{
1307 +       struct ext3_xattr_entry *entry1, *entry2;
1308 +
1309 +       entry1 = ENTRY(header1+1);
1310 +       entry2 = ENTRY(header2+1);
1311 +       while (!IS_LAST_ENTRY(entry1)) {
1312 +               if (IS_LAST_ENTRY(entry2))
1313 +                       return 1;
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))
1318 +                       return 1;
1319 +               if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
1320 +                       return -EIO;
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)))
1324 +                       return 1;
1325 +
1326 +               entry1 = EXT3_XATTR_NEXT(entry1);
1327 +               entry2 = EXT3_XATTR_NEXT(entry2);
1328 +       }
1329 +       if (!IS_LAST_ENTRY(entry2))
1330 +               return 1;
1331 +       return 0;
1332 +}
1333 +
1334 +/*
1335 + * ext3_xattr_cache_find()
1336 + *
1337 + * Find an identical extended attribute block.
1338 + *
1339 + * Returns a pointer to the block found, or NULL if such a block was
1340 + * not found or an error occurred.
1341 + */
1342 +static struct buffer_head *
1343 +ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header)
1344 +{
1345 +       __u32 hash = le32_to_cpu(header->h_hash);
1346 +       struct mb_cache_entry *ce;
1347 +
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);
1352 +       while (ce) {
1353 +               struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
1354 +
1355 +               if (!bh) {
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);
1367 +                       return bh;
1368 +               }
1369 +               brelse(bh);
1370 +               ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
1371 +       }
1372 +       return NULL;
1373 +}
1374 +
1375 +/*
1376 + * ext3_xattr_cache_remove()
1377 + *
1378 + * Remove the cache entry of a block from the cache. Called when a
1379 + * block becomes invalid.
1380 + */
1381 +static void
1382 +ext3_xattr_cache_remove(struct buffer_head *bh)
1383 +{
1384 +       struct mb_cache_entry *ce;
1385 +
1386 +       ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_dev, bh->b_blocknr);
1387 +       if (ce) {
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);
1391 +       } else 
1392 +               ea_bdebug(bh, "no cache entry");
1393 +}
1394 +
1395 +#define NAME_HASH_SHIFT 5
1396 +#define VALUE_HASH_SHIFT 16
1397 +
1398 +/*
1399 + * ext3_xattr_hash_entry()
1400 + *
1401 + * Compute the hash of an extended attribute.
1402 + */
1403 +static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
1404 +                                        struct ext3_xattr_entry *entry)
1405 +{
1406 +       __u32 hash = 0;
1407 +       char *name = entry->e_name;
1408 +       int n;
1409 +
1410 +       for (n=0; n < entry->e_name_len; n++) {
1411 +               hash = (hash << NAME_HASH_SHIFT) ^
1412 +                      (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
1413 +                      *name++;
1414 +       }
1415 +
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++);
1424 +               }
1425 +       }
1426 +       entry->e_hash = cpu_to_le32(hash);
1427 +}
1428 +
1429 +#undef NAME_HASH_SHIFT
1430 +#undef VALUE_HASH_SHIFT
1431 +
1432 +#define BLOCK_HASH_SHIFT 16
1433 +
1434 +/*
1435 + * ext3_xattr_rehash()
1436 + *
1437 + * Re-compute the extended attribute hash value after an entry has changed.
1438 + */
1439 +static void ext3_xattr_rehash(struct ext3_xattr_header *header,
1440 +                             struct ext3_xattr_entry *entry)
1441 +{
1442 +       struct ext3_xattr_entry *here;
1443 +       __u32 hash = 0;
1444 +       
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 */
1450 +                       hash = 0;
1451 +                       break;
1452 +               }
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);
1457 +       }
1458 +       header->h_hash = cpu_to_le32(hash);
1459 +}
1460 +
1461 +#undef BLOCK_HASH_SHIFT
1462 +
1463 +int __init
1464 +init_ext3_xattr(void)
1465 +{
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)
1470 +               return -ENOMEM;
1471 +
1472 +       return 0;
1473 +}
1474 +
1475 +void
1476 +exit_ext3_xattr(void)
1477 +{
1478 +       if (ext3_xattr_cache)
1479 +               mb_cache_destroy(ext3_xattr_cache);
1480 +       ext3_xattr_cache = NULL;
1481 +}
1482 +
1483 +#else  /* CONFIG_EXT3_FS_XATTR_SHARING */
1484 +
1485 +int __init
1486 +init_ext3_xattr(void)
1487 +{
1488 +       return 0;
1489 +}
1490 +
1491 +void
1492 +exit_ext3_xattr(void)
1493 +{
1494 +}
1495 +
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
1500 @@ -58,8 +58,6 @@
1501   */
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 */
1509 @@ -89,7 +87,6 @@
1510  #else
1511  # define EXT3_BLOCK_SIZE(s)            (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
1512  #endif
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))
1515  #ifdef __KERNEL__
1516  # define EXT3_BLOCK_SIZE_BITS(s)       ((s)->s_blocksize_bits)
1517 @@ -124,28 +121,6 @@
1518  #endif
1519  
1520  /*
1521 - * ACL structures
1522 - */
1523 -struct ext3_acl_header /* Header of Access Control Lists */
1524 -{
1525 -       __u32   aclh_size;
1526 -       __u32   aclh_file_count;
1527 -       __u32   aclh_acle_count;
1528 -       __u32   aclh_first_acle;
1529 -};
1530 -
1531 -struct ext3_acl_entry  /* Access Control List Entry */
1532 -{
1533 -       __u32   acle_size;
1534 -       __u16   acle_perms;     /* Access permissions */
1535 -       __u16   acle_type;      /* Type of entry */
1536 -       __u16   acle_tag;       /* User or group identity */
1537 -       __u16   acle_pad1;
1538 -       __u32   acle_next;      /* Pointer on next entry for the */
1539 -                                       /* same inode or on next free entry */
1540 -};
1541 -
1542 -/*
1543   * Structure of a blocks group descriptor
1544   */
1545  struct ext3_group_desc
1546 @@ -512,7 +487,7 @@
1547  #define EXT3_FEATURE_INCOMPAT_RECOVER          0x0004 /* Needs recovery */
1548  #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV      0x0008 /* Journal device */
1549  
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 @@
1556  */
1557  
1558 +/* Defined for extended attributes */
1559 +#define CONFIG_EXT3_FS_XATTR y
1560 +#ifndef ENOATTR
1561 +#define ENOATTR ENODATA                /* No such attribute */
1562 +#endif
1563 +#ifndef ENOTSUP
1564 +#define ENOTSUP EOPNOTSUPP     /* Operation not supported */
1565 +#endif
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) */
1570 +#endif
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 */
1574 +#endif
1575 +
1576  /*
1577   * Ok, these declarations are also in <linux/kernel.h> but none of the
1578 @@ -628,6 +603,7 @@
1579  extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
1580  
1581  /* inode.c */
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 *);
1585  
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
1589 @@ -30,13 +30,19 @@
1590  
1591  #define EXT3_SINGLEDATA_TRANS_BLOCKS   8
1592  
1593 +/* Extended attributes may touch two data buffers, two bitmap buffers,
1594 + * and two group and summaries. */
1595 +
1596 +#define EXT3_XATTR_TRANS_BLOCKS                8
1597 +
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. */
1603  
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)
1607  
1608  extern int ext3_writepage_trans_blocks(struct inode *inode);
1609  
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
1613 @@ -0,0 +1,155 @@
1614 +/*
1615 +  File: linux/ext3_xattr.h
1616 +
1617 +  On-disk format of extended attributes for the ext3 filesystem.
1618 +
1619 +  (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
1620 +*/
1621 +
1622 +#include <linux/config.h>
1623 +#include <linux/init.h>
1624 +#include <linux/xattr.h>
1625 +
1626 +/* Magic value in attribute blocks */
1627 +#define EXT3_XATTR_MAGIC               0xEA020000
1628 +
1629 +/* Maximum number of references to one attribute block */
1630 +#define EXT3_XATTR_REFCOUNT_MAX                1024
1631 +
1632 +/* Name indexes */
1633 +#define EXT3_XATTR_INDEX_MAX                   10
1634 +#define EXT3_XATTR_INDEX_USER                  1
1635 +
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 */
1642 +};
1643 +
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 */
1652 +};
1653 +
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)
1665 +
1666 +#ifdef __KERNEL__
1667 +
1668 +# ifdef CONFIG_EXT3_FS_XATTR
1669 +
1670 +struct ext3_xattr_handler {
1671 +       char *prefix;
1672 +       size_t (*list)(char *list, struct inode *inode, const char *name,
1673 +                      int name_len);
1674 +       int (*get)(struct inode *inode, const char *name, void *buffer,
1675 +                  size_t size);
1676 +       int (*set)(struct inode *inode, const char *name, void *buffer,
1677 +                  size_t size, int flags);
1678 +};
1679 +
1680 +extern int ext3_xattr_register(int, struct ext3_xattr_handler *);
1681 +extern void ext3_xattr_unregister(int, struct ext3_xattr_handler *);
1682 +
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 *);
1687 +
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);
1691 +
1692 +extern void ext3_xattr_drop_inode(handle_t *, struct inode *);
1693 +extern void ext3_xattr_put_super(struct super_block *);
1694 +
1695 +extern int init_ext3_xattr(void) __init;
1696 +extern void exit_ext3_xattr(void);
1697 +
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
1703 +
1704 +static inline int
1705 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
1706 +              void *buffer, size_t size, int flags)
1707 +{
1708 +       return -ENOTSUP;
1709 +}
1710 +
1711 +static inline int
1712 +ext3_xattr_list(struct inode *inode, void *buffer, size_t size, int flags)
1713 +{
1714 +       return -ENOTSUP;
1715 +}
1716 +
1717 +static inline int
1718 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
1719 +              const char *name, void *value, size_t size, int flags)
1720 +{
1721 +       return -ENOTSUP;
1722 +}
1723 +
1724 +static inline void
1725 +ext3_xattr_drop_inode(handle_t *handle, struct inode *inode)
1726 +{
1727 +}
1728 +
1729 +static inline void
1730 +ext3_xattr_put_super(struct super_block *sb)
1731 +{
1732 +}
1733 +
1734 +static inline int
1735 +init_ext3_xattr(void)
1736 +{
1737 +       return 0;
1738 +}
1739 +
1740 +static inline void
1741 +exit_ext3_xattr(void)
1742 +{
1743 +}
1744 +
1745 +# endif  /* CONFIG_EXT3_FS_XATTR */
1746 +
1747 +# ifdef CONFIG_EXT3_FS_XATTR_USER
1748 +
1749 +extern int init_ext3_xattr_user(void) __init;
1750 +extern void exit_ext3_xattr_user(void);
1751 +
1752 +# else  /* CONFIG_EXT3_FS_XATTR_USER */
1753 +
1754 +static inline int
1755 +init_ext3_xattr_user(void)
1756 +{
1757 +       return 0;
1758 +}
1759 +
1760 +static inline void
1761 +exit_ext3_xattr_user(void)
1762 +{
1763 +}
1764 +
1765 +#endif  /* CONFIG_EXT3_FS_XATTR_USER */
1766 +
1767 +#endif  /* __KERNEL__ */
1768 +
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
1772 @@ -0,0 +1,15 @@
1773 +/*
1774 +  File: linux/xattr.h
1775 +
1776 +  Extended attributes handling.
1777 +
1778 +  Copyright (C) 2001 by Andreas Gruenbacher <a.gruenbacher@computer.org>
1779 +  Copyright (C) 2001 SGI - Silicon Graphics, Inc <linux-xfs@oss.sgi.com>
1780 +*/
1781 +#ifndef _LINUX_XATTR_H
1782 +#define _LINUX_XATTR_H
1783 +
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 */
1786 +
1787 +#endif /* _LINUX_XATTR_H */