Whamcloud - gitweb
Remove VFS extended attribute interface so that extN will build even if the
[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,13 +2138,15 @@
117                 inode->i_op = &ext3_dir_inode_operations;
118                 inode->i_fop = &ext3_dir_operations;
119         } else if (S_ISLNK(inode->i_mode)) {
120 -               if (!inode->i_blocks)
121 +               if (ext3_inode_is_fast_symlink(inode))
122                         inode->i_op = &ext3_fast_symlink_inode_operations;
123                 else {
124 -                       inode->i_op = &page_symlink_inode_operations;
125 +                       inode->i_op = &ext3_symlink_inode_operations;
126                         inode->i_mapping->a_ops = &ext3_aops;
127                 }
128 -       } else 
129 +       } else {
130 +               inode->i_op = &ext3_special_inode_operations;
131                 init_special_inode(inode, inode->i_mode,
132                                    le32_to_cpu(iloc.raw_inode->i_block[0]));
133 +       }
134         /* inode->i_attr_flags = 0;                             unused */
135 diff -Nur linux-2.4.18/fs/ext3/namei.c linux-2.4.18ea/fs/ext3/namei.c
136 --- linux-2.4.18/fs/ext3/namei.c        Fri Nov  9 23:25:04 2001
137 +++ linux-2.4.18ea/fs/ext3/namei.c      Mon Mar 11 03:27:00 2002
138 @@ -23,6 +23,7 @@
139  #include <linux/sched.h>
140  #include <linux/ext3_fs.h>
141  #include <linux/ext3_jbd.h>
142 +#include <linux/ext3_xattr.h>
143  #include <linux/fcntl.h>
144  #include <linux/stat.h>
145  #include <linux/string.h>
146 @@ -466,6 +467,8 @@
147                 inode->i_mapping->a_ops = &ext3_aops;
148                 ext3_mark_inode_dirty(handle, inode);
149                 err = ext3_add_nondir(handle, dentry, inode);
150 +               if (err)
151 +                       ext3_xattr_drop_inode(handle, inode);
152         }
153         ext3_journal_stop(handle, dir);
154         return err;
155 @@ -491,6 +494,8 @@
156                 init_special_inode(inode, mode, rdev);
157                 ext3_mark_inode_dirty(handle, inode);
158                 err = ext3_add_nondir(handle, dentry, inode);
159 +               if (err)
160 +                       ext3_xattr_drop_inode(handle, inode);
161         }
162         ext3_journal_stop(handle, dir);
163         return err;
164 @@ -514,7 +519,7 @@
165         if (IS_SYNC(dir))
166                 handle->h_sync = 1;
167  
168 -       inode = ext3_new_inode (handle, dir, S_IFDIR);
169 +       inode = ext3_new_inode (handle, dir, S_IFDIR | mode);
170         err = PTR_ERR(inode);
171         if (IS_ERR(inode))
172                 goto out_stop;
173 @@ -522,7 +527,6 @@
174         inode->i_op = &ext3_dir_inode_operations;
175         inode->i_fop = &ext3_dir_operations;
176 -       inode->i_size = inode->u.ext3_i.i_disksize = inode->i_sb->s_blocksize;
177 -       inode->i_blocks = 0;    
178 +       inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
179         dir_block = ext3_bread (handle, inode, 0, 1, &err);
180         if (!dir_block) {
181                 inode->i_nlink--; /* is this nlink == 0? */
182 @@ -549,9 +553,6 @@
183         BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata");
184         ext3_journal_dirty_metadata(handle, dir_block);
185         brelse (dir_block);
186 -       inode->i_mode = S_IFDIR | mode;
187 -       if (dir->i_mode & S_ISGID)
188 -               inode->i_mode |= S_ISGID;
189         ext3_mark_inode_dirty(handle, inode);
190         err = ext3_add_entry (handle, dentry, inode);
191         if (err)
192 @@ -565,6 +566,7 @@
193         return err;
194  
195  out_no_entry:
196 +       ext3_xattr_drop_inode(handle, inode);
197         inode->i_nlink = 0;
198         ext3_mark_inode_dirty(handle, inode);
199         iput (inode);
200 @@ -917,7 +919,7 @@
201                 goto out_stop;
202  
203 -       if (l > sizeof (inode->u.ext3_i.i_data)) {
204 -               inode->i_op = &page_symlink_inode_operations;
205 +       if (l > sizeof(EXT3_I(inode)->i_data)) {
206 +               inode->i_op = &ext3_symlink_inode_operations;
207                 inode->i_mapping->a_ops = &ext3_aops;
208                 /*
209                  * block_symlink() calls back into ext3_prepare/commit_write.
210 diff -Nur linux-2.4.18/fs/ext3/super.c linux-2.4.18ea/fs/ext3/super.c
211 --- linux-2.4.18/fs/ext3/super.c        Sun Feb 24 04:42:59 2002
212 +++ linux-2.4.18ea/fs/ext3/super.c      Thu Apr  4 21:41:05 2002
213 @@ -24,6 +24,7 @@
214  #include <linux/jbd.h>
215  #include <linux/ext3_fs.h>
216  #include <linux/ext3_jbd.h>
217 +#include <linux/ext3_xattr.h>
218  #include <linux/slab.h>
219  #include <linux/init.h>
220  #include <linux/locks.h>
221 @@ -404,6 +405,7 @@
222         kdev_t j_dev = sbi->s_journal->j_dev;
223         int i;
224  
225 +       ext3_xattr_put_super(sb);
226         journal_destroy(sbi->s_journal);
227         if (!(sb->s_flags & MS_RDONLY)) {
228                 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
229 @@ -1734,14 +1772,25 @@
230  
231  static DECLARE_FSTYPE_DEV(ext3_fs_type, "ext3", ext3_read_super);
232  
233 -static int __init init_ext3_fs(void)
234 +static void exit_ext3_fs(void)
235  {
236 -        return register_filesystem(&ext3_fs_type);
237 +       unregister_filesystem(&ext3_fs_type);
238 +       exit_ext3_xattr_user();
239 +       exit_ext3_xattr();
240  }
241  
242 -static void __exit exit_ext3_fs(void)
243 +static int __init init_ext3_fs(void)
244  {
245 -       unregister_filesystem(&ext3_fs_type);
246 +       int error = init_ext3_xattr();
247 +       if (!error)
248 +               error = init_ext3_xattr_user();
249 +       if (!error)
250 +               error = register_filesystem(&ext3_fs_type);
251 +       if (!error)
252 +               return 0;
253 +
254 +       exit_ext3_fs();
255 +       return error;
256  }
257  
258  EXPORT_NO_SYMBOLS;
259 diff -Nur linux-2.4.18/fs/ext3/xattr.c linux-2.4.18ea/fs/ext3/xattr.c
260 --- linux-2.4.18/fs/ext3/xattr.c        Thu Jan  1 01:00:00 1970
261 +++ linux-2.4.18ea/fs/ext3/xattr.c      Wed Apr  3 13:19:05 2002
262 @@ -0,0 +1,1247 @@
263 +/*
264 + * linux/fs/ext3/xattr.c
265 + *
266 + * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
267 + *
268 + * Fix by Harrison Xing <harrison@mountainviewdata.com>.
269 + * Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>.
270 + * Extended attributes for symlinks and special files added per
271 + *  suggestion of Luka Renko <luka.renko@hermes.si>.
272 + */
273 +
274 +/*
275 + * Extended attributes are stored on disk blocks allocated outside of
276 + * any inode. The i_file_acl field is then made to point to this allocated
277 + * block. If all extended attributes of an inode are identical, these
278 + * inodes may share the same extended attribute block. Such situations
279 + * are automatically detected by keeping a cache of recent attribute block
280 + * numbers and hashes over the block's contents in memory.
281 + *
282 + *
283 + * Extended attribute block layout:
284 + *
285 + *   +------------------+
286 + *   | header           |
287 + *   Â¦ entry 1          | |
288 + *   | entry 2          | | growing downwards
289 + *   | entry 3          | v
290 + *   | four null bytes  |
291 + *   | . . .            |
292 + *   | value 1          | ^
293 + *   | value 3          | | growing upwards
294 + *   | value 2          | |
295 + *   +------------------+
296 + *
297 + * The block header is followed by multiple entry descriptors. These entry
298 + * descriptors are variable in size, and alligned to EXT3_XATTR_PAD
299 + * byte boundaries. The entry descriptors are sorted by attribute name,
300 + * so that two extended attribute blocks can be compared efficiently.
301 + *
302 + * Attribute values are aligned to the end of the block, stored in
303 + * no specific order. They are also padded to EXT3_XATTR_PAD byte
304 + * boundaries. No additional gaps are left between them.
305 + *
306 + * Locking strategy
307 + * ----------------
308 + * The VFS already holds the BKL and the inode->i_sem semaphore when any of
309 + * the xattr inode operations are called, so we are guaranteed that only one
310 + * processes accesses extended attributes of an inode at any time.
311 + *
312 + * For writing we also grab the ext3_xattr_sem semaphore. This ensures that
313 + * only a single process is modifying an extended attribute block, even
314 + * if the block is shared among inodes.
315 + *
316 + * Note for porting to 2.5
317 + * -----------------------
318 + * The BKL will no longer be held in the xattr inode operations.
319 + */
320 +
321 +#include <linux/fs.h>
322 +#include <linux/locks.h>
323 +#include <linux/slab.h>
324 +#include <linux/ext3_jbd.h>
325 +#include <linux/ext3_fs.h>
326 +#include <linux/ext3_xattr.h>
327 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
328 +#include <linux/mbcache.h>
329 +#endif
330 +#include <linux/quotaops.h>
331 +#include <asm/semaphore.h>
332 +#include <linux/compatmac.h>
333 +#include <linux/module.h>
334 +
335 +/* These symbols may be needed by a module. */
336 +EXPORT_SYMBOL(extN_xattr_register);
337 +EXPORT_SYMBOL(extN_xattr_unregister);
338 +EXPORT_SYMBOL(extN_xattr_get);
339 +EXPORT_SYMBOL(extN_xattr_list);
340 +EXPORT_SYMBOL(extN_xattr_set);
341 +
342 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
343 +# define mark_buffer_dirty(bh) mark_buffer_dirty(bh, 1)
344 +#endif
345 +
346 +#define HDR(bh) ((struct ext3_xattr_header *)((bh)->b_data))
347 +#define ENTRY(ptr) ((struct ext3_xattr_entry *)(ptr))
348 +#define FIRST_ENTRY(bh) ENTRY(HDR(bh)+1)
349 +#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
350 +
351 +#ifdef EXT3_XATTR_DEBUG
352 +# define ea_idebug(inode, f...) do { \
353 +               printk(KERN_DEBUG "inode %s:%ld: ", \
354 +                       kdevname(inode->i_dev), inode->i_ino); \
355 +               printk(f); \
356 +               printk("\n"); \
357 +       } while (0)
358 +# define ea_bdebug(bh, f...) do { \
359 +               printk(KERN_DEBUG "block %s:%ld: ", \
360 +                       kdevname(bh->b_dev), bh->b_blocknr); \
361 +               printk(f); \
362 +               printk("\n"); \
363 +       } while (0)
364 +#else
365 +# define ea_idebug(f...)
366 +# define ea_bdebug(f...)
367 +#endif
368 +
369 +static int ext3_xattr_set2(handle_t *, struct inode *, struct buffer_head *,
370 +                          struct ext3_xattr_header *);
371 +
372 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
373 +
374 +static int ext3_xattr_cache_insert(struct buffer_head *);
375 +static struct buffer_head *ext3_xattr_cache_find(struct inode *,
376 +                                                struct ext3_xattr_header *);
377 +static void ext3_xattr_cache_remove(struct buffer_head *);
378 +static void ext3_xattr_rehash(struct ext3_xattr_header *,
379 +                             struct ext3_xattr_entry *);
380 +
381 +static struct mb_cache *ext3_xattr_cache;
382 +
383 +#else
384 +# define ext3_xattr_cache_insert(bh) 0
385 +# define ext3_xattr_cache_find(inode, header) NULL
386 +# define ext3_xattr_cache_remove(bh) do {} while(0)
387 +# define ext3_xattr_rehash(header, entry) do {} while(0)
388 +#endif
389 +
390 +/*
391 + * If a file system does not share extended attributes among inodes,
392 + * we should not need the ext3_xattr_sem semaphore. However, the
393 + * filesystem may still contain shared blocks, so we always take
394 + * the lock.
395 + */
396 +
397 +DECLARE_MUTEX(ext3_xattr_sem);
398 +
399 +static inline void
400 +ext3_xattr_lock(void)
401 +{
402 +       down(&ext3_xattr_sem);
403 +}
404 +
405 +static inline void
406 +ext3_xattr_unlock(void)
407 +{
408 +       up(&ext3_xattr_sem);
409 +}
410 +
411 +static inline int
412 +ext3_xattr_new_block(handle_t *handle, struct inode *inode,
413 +                    int * errp, int force)
414 +{
415 +       struct super_block *sb = inode->i_sb;
416 +       int goal = le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block) +
417 +               EXT3_I(inode)->i_block_group * EXT3_BLOCKS_PER_GROUP(sb);
418 +
419 +       /* How can we enforce the allocation? */
420 +       int block = ext3_new_block(handle, inode, goal, 0, 0, errp);
421 +#ifdef OLD_QUOTAS
422 +       if (!*errp)
423 +               inode->i_blocks += inode->i_sb->s_blocksize >> 9;
424 +#endif
425 +       return block;
426 +}
427 +
428 +static inline int
429 +ext3_xattr_quota_alloc(struct inode *inode, int force)
430 +{
431 +       /* How can we enforce the allocation? */
432 +#ifdef OLD_QUOTAS
433 +       int error = DQUOT_ALLOC_BLOCK(inode->i_sb, inode, 1);
434 +       if (!error)
435 +               inode->i_blocks += inode->i_sb->s_blocksize >> 9;
436 +#else
437 +       int error = DQUOT_ALLOC_BLOCK(inode, 1);
438 +#endif
439 +       return error;
440 +}
441 +
442 +#ifdef OLD_QUOTAS
443 +
444 +static inline void
445 +ext3_xattr_quota_free(struct inode *inode)
446 +{
447 +       DQUOT_FREE_BLOCK(inode->i_sb, inode, 1);
448 +       inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
449 +}
450 +
451 +static inline void
452 +ext3_xattr_free_block(handle_t *handle, struct inode * inode,
453 +                     unsigned long block)
454 +{
455 +       ext3_free_blocks(handle, inode, block, 1);
456 +       inode->i_blocks -= inode->i_sb->s_blocksize >> 9;
457 +}
458 +
459 +#else
460 +# define ext3_xattr_quota_free(inode) \
461 +       DQUOT_FREE_BLOCK(inode, 1)
462 +# define ext3_xattr_free_block(handle, inode, block) \
463 +       ext3_free_blocks(handle, inode, block, 1)
464 +#endif
465 +
466 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
467 +
468 +static inline struct buffer_head *
469 +sb_bread(struct super_block *sb, int block)
470 +{
471 +       return bread(sb->s_dev, block, sb->s_blocksize);
472 +}
473 +
474 +static inline struct buffer_head *
475 +sb_getblk(struct super_block *sb, int block)
476 +{
477 +       return getblk(sb->s_dev, block, sb->s_blocksize);
478 +}
479 +
480 +#endif
481 +
482 +struct ext3_xattr_handler *ext3_xattr_handlers[EXT3_XATTR_INDEX_MAX];
483 +rwlock_t ext3_handler_lock = RW_LOCK_UNLOCKED;
484 +
485 +int
486 +ext3_xattr_register(int name_index, struct ext3_xattr_handler *handler)
487 +{
488 +       int error = -EINVAL;
489 +
490 +       if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
491 +               write_lock(&ext3_handler_lock);
492 +               if (!ext3_xattr_handlers[name_index-1]) {
493 +                       ext3_xattr_handlers[name_index-1] = handler;
494 +                       error = 0;
495 +               }
496 +               write_unlock(&ext3_handler_lock);
497 +       }
498 +       return error;
499 +}
500 +
501 +void
502 +ext3_xattr_unregister(int name_index, struct ext3_xattr_handler *handler)
503 +{
504 +       if (name_index > 0 || name_index <= EXT3_XATTR_INDEX_MAX) {
505 +               write_lock(&ext3_handler_lock);
506 +               ext3_xattr_handlers[name_index-1] = NULL;
507 +               write_unlock(&ext3_handler_lock);
508 +       }
509 +}
510 +
511 +static inline const char *
512 +strcmp_prefix(const char *a, const char *a_prefix)
513 +{
514 +       while (*a_prefix && *a == *a_prefix) {
515 +               a++;
516 +               a_prefix++;
517 +       }
518 +       return *a_prefix ? NULL : a;
519 +}
520 +
521 +/*
522 + * Decode the extended attribute name, and translate it into
523 + * the name_index and name suffix.
524 + */
525 +static inline struct ext3_xattr_handler *
526 +ext3_xattr_resolve_name(const char **name)
527 +{
528 +       struct ext3_xattr_handler *handler = NULL;
529 +       int i;
530 +
531 +       if (!*name)
532 +               return NULL;
533 +       read_lock(&ext3_handler_lock);
534 +       for (i=0; i<EXT3_XATTR_INDEX_MAX; i++) {
535 +               if (ext3_xattr_handlers[i]) {
536 +                       const char *n = strcmp_prefix(*name,
537 +                               ext3_xattr_handlers[i]->prefix);
538 +                       if (n) {
539 +                               handler = ext3_xattr_handlers[i];
540 +                               *name = n;
541 +                               break;
542 +                       }
543 +               }
544 +       }
545 +       read_unlock(&ext3_handler_lock);
546 +       return handler;
547 +}
548 +
549 +static inline struct ext3_xattr_handler *
550 +ext3_xattr_handler(int name_index)
551 +{
552 +       struct ext3_xattr_handler *handler = NULL;
553 +       if (name_index > 0 && name_index <= EXT3_XATTR_INDEX_MAX) {
554 +               read_lock(&ext3_handler_lock);
555 +               handler = ext3_xattr_handlers[name_index-1];
556 +               read_unlock(&ext3_handler_lock);
557 +       }
558 +       return handler;
559 +}
560 +
561 +/*
562 + * Inode operation getxattr()
563 + *
564 + * dentry->d_inode->i_sem down
565 + * BKL held [before 2.5.x]
566 + */
567 +ssize_t
568 +ext3_getxattr(struct dentry *dentry, const char *name,
569 +             void *buffer, size_t size)
570 +{
571 +       struct ext3_xattr_handler *handler;
572 +       struct inode *inode = dentry->d_inode;
573 +
574 +       handler = ext3_xattr_resolve_name(&name);
575 +       if (!handler)
576 +               return -ENOTSUP;
577 +       return handler->get(inode, name, buffer, size);
578 +}
579 +
580 +/*
581 + * Inode operation listxattr()
582 + *
583 + * dentry->d_inode->i_sem down
584 + * BKL held [before 2.5.x]
585 + */
586 +ssize_t
587 +ext3_listxattr(struct dentry *dentry, char *buffer, size_t size)
588 +{
589 +       return ext3_xattr_list(dentry->d_inode, buffer, size);
590 +}
591 +
592 +/*
593 + * Inode operation setxattr()
594 + *
595 + * dentry->d_inode->i_sem down
596 + * BKL held [before 2.5.x]
597 + */
598 +int
599 +ext3_setxattr(struct dentry *dentry, const char *name,
600 +             void *value, size_t size, int flags)
601 +{
602 +       struct ext3_xattr_handler *handler;
603 +       struct inode *inode = dentry->d_inode;
604 +
605 +       if (size == 0)
606 +               value = "";  /* empty EA, do not remove */
607 +       handler = ext3_xattr_resolve_name(&name);
608 +       if (!handler)
609 +               return -ENOTSUP;
610 +       return handler->set(inode, name, value, size, flags);
611 +}
612 +
613 +/*
614 + * Inode operation removexattr()
615 + *
616 + * dentry->d_inode->i_sem down
617 + * BKL held [before 2.5.x]
618 + */
619 +int
620 +ext3_removexattr(struct dentry *dentry, const char *name)
621 +{
622 +       struct ext3_xattr_handler *handler;
623 +       struct inode *inode = dentry->d_inode;
624 +
625 +       handler = ext3_xattr_resolve_name(&name);
626 +       if (!handler)
627 +               return -ENOTSUP;
628 +       return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
629 +}
630 +
631 +/*
632 + * ext3_xattr_get()
633 + *
634 + * Copy an extended attribute into the buffer
635 + * provided, or compute the buffer size required.
636 + * Buffer is NULL to compute the size of the buffer required.
637 + *
638 + * Returns a negative error number on failure, or the number of bytes
639 + * used / required on success.
640 + */
641 +int
642 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
643 +              void *buffer, size_t buffer_size)
644 +{
645 +       struct buffer_head *bh = NULL;
646 +       struct ext3_xattr_entry *entry;
647 +       unsigned int block, size;
648 +       char *end;
649 +       int name_len, error;
650 +
651 +       ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
652 +                 name_index, name, buffer, (long)buffer_size);
653 +
654 +       if (name == NULL)
655 +               return -EINVAL;
656 +       if (!EXT3_I(inode)->i_file_acl)
657 +               return -ENOATTR;
658 +       block = EXT3_I(inode)->i_file_acl;
659 +       ea_idebug(inode, "reading block %d", block);
660 +       bh = sb_bread(inode->i_sb, block);
661 +       if (!bh)
662 +               return -EIO;
663 +       ea_bdebug(bh, "b_count=%d, refcount=%d",
664 +               atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
665 +       end = bh->b_data + bh->b_size;
666 +       if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
667 +           HDR(bh)->h_blocks != cpu_to_le32(1)) {
668 +bad_block:     ext3_error(inode->i_sb, "ext3_xattr_get",
669 +                       "inode %ld: bad block %d", inode->i_ino, block);
670 +               error = -EIO;
671 +               goto cleanup;
672 +       }
673 +       /* find named attribute */
674 +       name_len = strlen(name);
675 +
676 +       error = -ERANGE;
677 +       if (name_len > 255)
678 +               goto cleanup;
679 +       entry = FIRST_ENTRY(bh);
680 +       while (!IS_LAST_ENTRY(entry)) {
681 +               struct ext3_xattr_entry *next =
682 +                       EXT3_XATTR_NEXT(entry);
683 +               if ((char *)next >= end)
684 +                       goto bad_block;
685 +               if (name_index == entry->e_name_index &&
686 +                   name_len == entry->e_name_len &&
687 +                   memcmp(name, entry->e_name, name_len) == 0)
688 +                       goto found;
689 +               entry = next;
690 +       }
691 +       /* Check the remaining name entries */
692 +       while (!IS_LAST_ENTRY(entry)) {
693 +               struct ext3_xattr_entry *next =
694 +                       EXT3_XATTR_NEXT(entry);
695 +               if ((char *)next >= end)
696 +                       goto bad_block;
697 +               entry = next;
698 +       }
699 +       if (ext3_xattr_cache_insert(bh))
700 +               ea_idebug(inode, "cache insert failed");
701 +       error = -ENOATTR;
702 +       goto cleanup;
703 +found:
704 +       /* check the buffer size */
705 +       if (entry->e_value_block != 0)
706 +               goto bad_block;
707 +       size = le32_to_cpu(entry->e_value_size);
708 +       if (size > inode->i_sb->s_blocksize ||
709 +           le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
710 +               goto bad_block;
711 +
712 +       if (ext3_xattr_cache_insert(bh))
713 +               ea_idebug(inode, "cache insert failed");
714 +       if (buffer) {
715 +               error = -ERANGE;
716 +               if (size > buffer_size)
717 +                       goto cleanup;
718 +               /* return value of attribute */
719 +               memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
720 +                       size);
721 +       }
722 +       error = size;
723 +
724 +cleanup:
725 +       brelse(bh);
726 +
727 +       return error;
728 +}
729 +
730 +/*
731 + * ext3_xattr_list()
732 + *
733 + * Copy a list of attribute names into the buffer
734 + * provided, or compute the buffer size required.
735 + * Buffer is NULL to compute the size of the buffer required.
736 + *
737 + * Returns a negative error number on failure, or the number of bytes
738 + * used / required on success.
739 + */
740 +int
741 +ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
742 +{
743 +       struct buffer_head *bh = NULL;
744 +       struct ext3_xattr_entry *entry;
745 +       unsigned int block, size = 0;
746 +       char *buf, *end;
747 +       int error;
748 +
749 +       ea_idebug(inode, "buffer=%p, buffer_size=%ld",
750 +                 buffer, (long)buffer_size);
751 +
752 +       if (!EXT3_I(inode)->i_file_acl)
753 +               return 0;
754 +       block = EXT3_I(inode)->i_file_acl;
755 +       ea_idebug(inode, "reading block %d", block);
756 +       bh = sb_bread(inode->i_sb, block);
757 +       if (!bh)
758 +               return -EIO;
759 +       ea_bdebug(bh, "b_count=%d, refcount=%d",
760 +               atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
761 +       end = bh->b_data + bh->b_size;
762 +       if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
763 +           HDR(bh)->h_blocks != cpu_to_le32(1)) {
764 +bad_block:     ext3_error(inode->i_sb, "ext3_xattr_list",
765 +                       "inode %ld: bad block %d", inode->i_ino, block);
766 +               error = -EIO;
767 +               goto cleanup;
768 +       }
769 +       /* compute the size required for the list of attribute names */
770 +       for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
771 +            entry = EXT3_XATTR_NEXT(entry)) {
772 +               struct ext3_xattr_handler *handler;
773 +               struct ext3_xattr_entry *next =
774 +                       EXT3_XATTR_NEXT(entry);
775 +               if ((char *)next >= end)
776 +                       goto bad_block;
777 +
778 +               handler = ext3_xattr_handler(entry->e_name_index);
779 +               if (handler) {
780 +                       size += handler->list(NULL, inode, entry->e_name,
781 +                                             entry->e_name_len) + 1;
782 +               }
783 +       }
784 +
785 +       if (ext3_xattr_cache_insert(bh))
786 +               ea_idebug(inode, "cache insert failed");
787 +       if (!buffer) {
788 +               error = size;
789 +               goto cleanup;
790 +       } else {
791 +               error = -ERANGE;
792 +               if (size > buffer_size)
793 +                       goto cleanup;
794 +       }
795 +
796 +       /* list the attribute names */
797 +       buf = buffer;
798 +       for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
799 +            entry = EXT3_XATTR_NEXT(entry)) {
800 +               struct ext3_xattr_handler *handler;
801 +
802 +               handler = ext3_xattr_handler(entry->e_name_index);
803 +               if (handler) {
804 +                       buf += handler->list(buf, inode, entry->e_name,
805 +                                            entry->e_name_len);
806 +                       *buf++ = '\0';
807 +               }
808 +       }
809 +       error = size;
810 +
811 +cleanup:
812 +       brelse(bh);
813 +
814 +       return error;
815 +}
816 +
817 +/*
818 + * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is
819 + * not set, set it.
820 + */
821 +static void ext3_xattr_update_super_block(handle_t *handle,
822 +                                         struct super_block *sb)
823 +{
824 +       if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR))
825 +               return;
826 +
827 +       lock_super(sb);
828 +       ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh);
829 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
830 +       EXT3_SB(sb)->s_feature_compat |= EXT3_FEATURE_COMPAT_EXT_ATTR;
831 +#endif
832 +       EXT3_SB(sb)->s_es->s_feature_compat |=
833 +               cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR);
834 +       sb->s_dirt = 1;
835 +       ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
836 +       unlock_super(sb);
837 +}
838 +
839 +/*
840 + * ext3_xattr_set()
841 + *
842 + * Create, replace or remove an extended attribute for this inode. Buffer
843 + * is NULL to remove an existing extended attribute, and non-NULL to
844 + * either replace an existing extended attribute, or create a new extended
845 + * attribute. The flags XATTR_REPLACE and XATTR_CREATE
846 + * specify that an extended attribute must exist and must not exist
847 + * previous to the call, respectively.
848 + *
849 + * Returns 0, or a negative error number on failure.
850 + */
851 +int
852 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
853 +              const char *name, void *value, size_t value_len, int flags)
854 +{
855 +       struct super_block *sb = inode->i_sb;
856 +       struct buffer_head *bh = NULL;
857 +       struct ext3_xattr_header *header = NULL;
858 +       struct ext3_xattr_entry *here, *last;
859 +       unsigned int name_len;
860 +       int min_offs = sb->s_blocksize, not_found = 1, free, error;
861 +       char *end;
862 +       
863 +       /*
864 +        * header -- Points either into bh, or to a temporarily
865 +        *           allocated buffer.
866 +        * here -- The named entry found, or the place for inserting, within
867 +        *         the block pointed to by header.
868 +        * last -- Points right after the last named entry within the block
869 +        *         pointed to by header.
870 +        * min_offs -- The offset of the first value (values are aligned
871 +        *             towards the end of the block).
872 +        * end -- Points right after the block pointed to by header.
873 +        */
874 +       
875 +       ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
876 +                 name_index, name, value, (long)value_len);
877 +
878 +       if (IS_RDONLY(inode))
879 +               return -EROFS;
880 +       if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
881 +               return -EPERM;
882 +       if (value == NULL)
883 +               value_len = 0;
884 +       if (name == NULL)
885 +               return -EINVAL;
886 +       name_len = strlen(name);
887 +       if (name_len > 255 || value_len > sb->s_blocksize)
888 +               return -ERANGE;
889 +       ext3_xattr_lock();
890 +
891 +       if (EXT3_I(inode)->i_file_acl) {
892 +               /* The inode already has an extended attribute block. */
893 +               int block = EXT3_I(inode)->i_file_acl;
894 +
895 +               bh = sb_bread(sb, block);
896 +               error = -EIO;
897 +               if (!bh)
898 +                       goto cleanup;
899 +               ea_bdebug(bh, "b_count=%d, refcount=%d",
900 +                       atomic_read(&(bh->b_count)),
901 +                       le32_to_cpu(HDR(bh)->h_refcount));
902 +               header = HDR(bh);
903 +               end = bh->b_data + bh->b_size;
904 +               if (header->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
905 +                   header->h_blocks != cpu_to_le32(1)) {
906 +bad_block:             ext3_error(sb, "ext3_xattr_set",
907 +                               "inode %ld: bad block %d", inode->i_ino, block);
908 +                       error = -EIO;
909 +                       goto cleanup;
910 +               }
911 +               /* Find the named attribute. */
912 +               here = FIRST_ENTRY(bh);
913 +               while (!IS_LAST_ENTRY(here)) {
914 +                       struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(here);
915 +                       if ((char *)next >= end)
916 +                               goto bad_block;
917 +                       if (!here->e_value_block && here->e_value_size) {
918 +                               int offs = le16_to_cpu(here->e_value_offs);
919 +                               if (offs < min_offs)
920 +                                       min_offs = offs;
921 +                       }
922 +                       not_found = name_index - here->e_name_index;
923 +                       if (!not_found)
924 +                               not_found = name_len - here->e_name_len;
925 +                       if (!not_found)
926 +                               not_found = memcmp(name, here->e_name,name_len);
927 +                       if (not_found <= 0)
928 +                               break;
929 +                       here = next;
930 +               }
931 +               last = here;
932 +               /* We still need to compute min_offs and last. */
933 +               while (!IS_LAST_ENTRY(last)) {
934 +                       struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
935 +                       if ((char *)next >= end)
936 +                               goto bad_block;
937 +                       if (!last->e_value_block && last->e_value_size) {
938 +                               int offs = le16_to_cpu(last->e_value_offs);
939 +                               if (offs < min_offs)
940 +                                       min_offs = offs;
941 +                       }
942 +                       last = next;
943 +               }
944 +
945 +               /* Check whether we have enough space left. */
946 +               free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
947 +       } else {
948 +               /* We will use a new extended attribute block. */
949 +               free = sb->s_blocksize -
950 +                       sizeof(struct ext3_xattr_header) - sizeof(__u32);
951 +               here = last = NULL;  /* avoid gcc uninitialized warning. */
952 +       }
953 +
954 +       if (not_found) {
955 +               /* Request to remove a nonexistent attribute? */
956 +               error = -ENOATTR;
957 +               if (flags & XATTR_REPLACE)
958 +                       goto cleanup;
959 +               error = 0;
960 +               if (value == NULL)
961 +                       goto cleanup;
962 +               else
963 +                       free -= EXT3_XATTR_LEN(name_len);
964 +       } else {
965 +               /* Request to create an existing attribute? */
966 +               error = -EEXIST;
967 +               if (flags & XATTR_CREATE)
968 +                       goto cleanup;
969 +               if (!here->e_value_block && here->e_value_size) {
970 +                       unsigned int size = le32_to_cpu(here->e_value_size);
971 +
972 +                       if (le16_to_cpu(here->e_value_offs) + size > 
973 +                           sb->s_blocksize || size > sb->s_blocksize)
974 +                               goto bad_block;
975 +                       free += EXT3_XATTR_SIZE(size);
976 +               }
977 +       }
978 +       free -= EXT3_XATTR_SIZE(value_len);
979 +       error = -ENOSPC;
980 +       if (free < 0)
981 +               goto cleanup;
982 +
983 +       /* Here we know that we can set the new attribute. */
984 +
985 +       if (header) {
986 +               if (header->h_refcount == cpu_to_le32(1)) {
987 +                       ea_bdebug(bh, "modifying in-place");
988 +                       ext3_xattr_cache_remove(bh);
989 +                       error = ext3_journal_get_write_access(handle, bh);
990 +                       if (error)
991 +                               goto cleanup;
992 +               } else {
993 +                       int offset;
994 +
995 +                       ea_bdebug(bh, "cloning");
996 +                       header = kmalloc(bh->b_size, GFP_KERNEL);
997 +                       error = -ENOMEM;
998 +                       if (header == NULL)
999 +                               goto cleanup;
1000 +                       memcpy(header, HDR(bh), bh->b_size);
1001 +                       header->h_refcount = cpu_to_le32(1);
1002 +                       offset = (char *)header - bh->b_data;
1003 +                       here = ENTRY((char *)here + offset);
1004 +                       last = ENTRY((char *)last + offset);
1005 +               }
1006 +       } else {
1007 +               /* Allocate a buffer where we construct the new block. */
1008 +               header = kmalloc(sb->s_blocksize, GFP_KERNEL);
1009 +               error = -ENOMEM;
1010 +               if (header == NULL)
1011 +                       goto cleanup;
1012 +               memset(header, 0, sb->s_blocksize);
1013 +               end = (char *)header + sb->s_blocksize;
1014 +               header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC);
1015 +               header->h_blocks = header->h_refcount = cpu_to_le32(1);
1016 +               last = here = ENTRY(header+1);
1017 +       }
1018 +
1019 +       if (not_found) {
1020 +               /* Insert the new name. */
1021 +               int size = EXT3_XATTR_LEN(name_len);
1022 +               int rest = (char *)last - (char *)here;
1023 +               memmove((char *)here + size, here, rest);
1024 +               memset(here, 0, size);
1025 +               here->e_name_index = name_index;
1026 +               here->e_name_len = name_len;
1027 +               memcpy(here->e_name, name, name_len);
1028 +       } else {
1029 +               /* Remove the old value. */
1030 +               if (!here->e_value_block && here->e_value_size) {
1031 +                       char *first_val = (char *)header + min_offs;
1032 +                       int offs = le16_to_cpu(here->e_value_offs);
1033 +                       char *val = (char *)header + offs;
1034 +                       size_t size = EXT3_XATTR_SIZE(
1035 +                               le32_to_cpu(here->e_value_size));
1036 +                       memmove(first_val + size, first_val, val - first_val);
1037 +                       memset(first_val, 0, size);
1038 +                       here->e_value_offs = 0;
1039 +                       min_offs += size;
1040 +
1041 +                       /* Adjust all value offsets. */
1042 +                       last = ENTRY(header+1);
1043 +                       while (!IS_LAST_ENTRY(last)) {
1044 +                               int o = le16_to_cpu(last->e_value_offs);
1045 +                               if (!last->e_value_block && o < offs)
1046 +                                       last->e_value_offs =
1047 +                                               cpu_to_le16(o + size);
1048 +                               last = EXT3_XATTR_NEXT(last);
1049 +                       }
1050 +               }
1051 +               if (value == NULL) {
1052 +                       /* Remove this attribute. */
1053 +                       if (EXT3_XATTR_NEXT(ENTRY(header+1)) == last) {
1054 +                               /* This block is now empty. */
1055 +                               error = ext3_xattr_set2(handle, inode, bh,NULL);
1056 +                               goto cleanup;
1057 +                       } else {
1058 +                               /* Remove the old name. */
1059 +                               int size = EXT3_XATTR_LEN(name_len);
1060 +                               last = ENTRY((char *)last - size);
1061 +                               memmove(here, (char*)here + size,
1062 +                                       (char*)last - (char*)here);
1063 +                               memset(last, 0, size);
1064 +                       }
1065 +               }
1066 +       }
1067 +
1068 +       if (value != NULL) {
1069 +               /* Insert the new value. */
1070 +               here->e_value_size = cpu_to_le32(value_len);
1071 +               if (value_len) {
1072 +                       size_t size = EXT3_XATTR_SIZE(value_len);
1073 +                       char *val = (char *)header + min_offs - size;
1074 +                       here->e_value_offs =
1075 +                               cpu_to_le16((char *)val - (char *)header);
1076 +                       memset(val + size - EXT3_XATTR_PAD, 0,
1077 +                              EXT3_XATTR_PAD); /* Clear the pad bytes. */
1078 +                       memcpy(val, value, value_len);
1079 +               }
1080 +       }
1081 +       ext3_xattr_rehash(header, here);
1082 +
1083 +       error = ext3_xattr_set2(handle, inode, bh, header);
1084 +
1085 +cleanup:
1086 +       brelse(bh);
1087 +       if (!(bh && header == HDR(bh)))
1088 +               kfree(header);
1089 +       ext3_xattr_unlock();
1090 +
1091 +       return error;
1092 +}
1093 +
1094 +/*
1095 + * Second half of ext3_xattr_set(): Update the file system.
1096 + */
1097 +static int
1098 +ext3_xattr_set2(handle_t *handle, struct inode *inode,
1099 +               struct buffer_head *old_bh, struct ext3_xattr_header *header)
1100 +{
1101 +       struct super_block *sb = inode->i_sb;
1102 +       struct buffer_head *new_bh = NULL;
1103 +       int error;
1104 +
1105 +       if (header) {
1106 +               new_bh = ext3_xattr_cache_find(inode, header);
1107 +               if (new_bh) {
1108 +                       /*
1109 +                        * We found an identical block in the cache.
1110 +                        * The old block will be released after updating
1111 +                        * the inode.
1112 +                        */
1113 +                       ea_bdebug(old_bh, "reusing block %ld",
1114 +                               new_bh->b_blocknr);
1115 +                       
1116 +                       error = -EDQUOT;
1117 +                       if (ext3_xattr_quota_alloc(inode, 1))
1118 +                               goto cleanup;
1119 +                       
1120 +                       error = ext3_journal_get_write_access(handle, new_bh);
1121 +                       if (error)
1122 +                               goto cleanup;
1123 +                       HDR(new_bh)->h_refcount = cpu_to_le32(
1124 +                               le32_to_cpu(HDR(new_bh)->h_refcount) + 1);
1125 +                       ea_bdebug(new_bh, "refcount now=%d",
1126 +                               le32_to_cpu(HDR(new_bh)->h_refcount));
1127 +               } else if (old_bh && header == HDR(old_bh)) {
1128 +                       /* Keep this block. */
1129 +                       new_bh = old_bh;
1130 +                       (void)ext3_xattr_cache_insert(new_bh);
1131 +               } else {
1132 +                       /* We need to allocate a new block */
1133 +                       int force = EXT3_I(inode)->i_file_acl != 0;
1134 +                       int block = ext3_xattr_new_block(handle, inode,
1135 +                                                        &error, force);
1136 +                       if (error)
1137 +                               goto cleanup;
1138 +                       ea_idebug(inode, "creating block %d", block);
1139 +
1140 +                       new_bh = sb_getblk(sb, block);
1141 +                       if (!new_bh) {
1142 +getblk_failed:                 ext3_xattr_free_block(handle, inode, block);
1143 +                               error = -EIO;
1144 +                               goto cleanup;
1145 +                       }
1146 +                       lock_buffer(new_bh);
1147 +                       error = ext3_journal_get_create_access(handle, new_bh);
1148 +                       if (error) {
1149 +                               unlock_buffer(new_bh);
1150 +                               goto getblk_failed;
1151 +                       }
1152 +                       memcpy(new_bh->b_data, header, new_bh->b_size);
1153 +                       mark_buffer_uptodate(new_bh, 1);
1154 +                       unlock_buffer(new_bh);
1155 +                       (void)ext3_xattr_cache_insert(new_bh);
1156 +                       ext3_xattr_update_super_block(handle, sb);
1157 +               }
1158 +               error = ext3_journal_dirty_metadata(handle, new_bh);
1159 +               if (error)
1160 +                       goto cleanup;
1161 +       }
1162 +
1163 +       /* Update the inode. */
1164 +       EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
1165 +       inode->i_ctime = CURRENT_TIME;
1166 +       ext3_mark_inode_dirty(handle, inode);
1167 +       if (IS_SYNC(inode))
1168 +               handle->h_sync = 1;
1169 +
1170 +       error = 0;
1171 +       if (old_bh && old_bh != new_bh) {
1172 +               /*
1173 +                * If there was an old block, and we are not still using it,
1174 +                * we now release the old block.
1175 +               */
1176 +               unsigned int refcount = le32_to_cpu(HDR(old_bh)->h_refcount);
1177 +
1178 +               error = ext3_journal_get_write_access(handle, old_bh);
1179 +               if (error)
1180 +                       goto cleanup;
1181 +               if (refcount == 1) {
1182 +                       /* Free the old block. */
1183 +                       ea_bdebug(old_bh, "freeing");
1184 +                       ext3_xattr_free_block(handle, inode, old_bh->b_blocknr);
1185 +
1186 +                       /* ext3_forget() calls bforget() for us, but we
1187 +                          let our caller release old_bh, so we need to
1188 +                          duplicate the handle before. */
1189 +                       get_bh(old_bh);
1190 +                       ext3_forget(handle, 1, inode, old_bh,old_bh->b_blocknr);
1191 +               } else {
1192 +                       /* Decrement the refcount only. */
1193 +                       refcount--;
1194 +                       HDR(old_bh)->h_refcount = cpu_to_le32(refcount);
1195 +                       ext3_xattr_quota_free(inode);
1196 +                       ext3_journal_dirty_metadata(handle, old_bh);
1197 +                       ea_bdebug(old_bh, "refcount now=%d", refcount);
1198 +               }
1199 +       }
1200 +
1201 +cleanup:
1202 +       if (old_bh != new_bh)
1203 +               brelse(new_bh);
1204 +
1205 +       return error;
1206 +}
1207 +
1208 +/*
1209 + * ext3_xattr_drop_inode()
1210 + *
1211 + * Free extended attribute resources associated with this inode. This
1212 + * is called immediately before an inode is freed.
1213 + */
1214 +void
1215 +ext3_xattr_drop_inode(handle_t *handle, struct inode *inode)
1216 +{
1217 +       struct buffer_head *bh;
1218 +       unsigned int block = EXT3_I(inode)->i_file_acl;
1219 +
1220 +       if (!block)
1221 +               return;
1222 +       ext3_xattr_lock();
1223 +
1224 +       bh = sb_bread(inode->i_sb, block);
1225 +       if (!bh) {
1226 +               ext3_error(inode->i_sb, "ext3_xattr_drop_inode",
1227 +                       "inode %ld: block %d read error", inode->i_ino, block);
1228 +               goto cleanup;
1229 +       }
1230 +       ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
1231 +       if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
1232 +           HDR(bh)->h_blocks != cpu_to_le32(1)) {
1233 +               ext3_error(inode->i_sb, "ext3_xattr_drop_inode",
1234 +                       "inode %ld: bad block %d", inode->i_ino, block);
1235 +               goto cleanup;
1236 +       }
1237 +       ext3_journal_get_write_access(handle, bh);
1238 +       ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
1239 +       if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
1240 +               ext3_xattr_cache_remove(bh);
1241 +               ext3_xattr_free_block(handle, inode, block);
1242 +               ext3_forget(handle, 1, inode, bh, block);
1243 +               bh = NULL;
1244 +       } else {
1245 +               HDR(bh)->h_refcount = cpu_to_le32(
1246 +                       le32_to_cpu(HDR(bh)->h_refcount) - 1);
1247 +               ext3_journal_dirty_metadata(handle, bh);
1248 +               if (IS_SYNC(inode))
1249 +                       handle->h_sync = 1;
1250 +               ext3_xattr_quota_free(inode);
1251 +       }
1252 +       EXT3_I(inode)->i_file_acl = 0;
1253 +
1254 +cleanup:
1255 +       brelse(bh);
1256 +       ext3_xattr_unlock();
1257 +}
1258 +
1259 +/*
1260 + * ext3_xattr_put_super()
1261 + *
1262 + * This is called when a file system is unmounted.
1263 + */
1264 +void
1265 +ext3_xattr_put_super(struct super_block *sb)
1266 +{
1267 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
1268 +       mb_cache_shrink(ext3_xattr_cache, sb->s_dev);
1269 +#endif
1270 +}
1271 +
1272 +#ifdef CONFIG_EXT3_FS_XATTR_SHARING
1273 +
1274 +/*
1275 + * ext3_xattr_cache_insert()
1276 + *
1277 + * Create a new entry in the extended attribute cache, and insert
1278 + * it unless such an entry is already in the cache.
1279 + *
1280 + * Returns 0, or a negative error number on failure.
1281 + */
1282 +static int
1283 +ext3_xattr_cache_insert(struct buffer_head *bh)
1284 +{
1285 +       __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
1286 +       struct mb_cache_entry *ce;
1287 +       int error;
1288 +
1289 +       ce = mb_cache_entry_alloc(ext3_xattr_cache);
1290 +       if (!ce)
1291 +               return -ENOMEM;
1292 +       error = mb_cache_entry_insert(ce, bh->b_dev, bh->b_blocknr, &hash);
1293 +       if (error) {
1294 +               mb_cache_entry_free(ce);
1295 +               if (error == -EBUSY) {
1296 +                       ea_bdebug(bh, "already in cache (%d cache entries)",
1297 +                               atomic_read(&ext3_xattr_cache->c_entry_count));
1298 +                       error = 0;
1299 +               }
1300 +       } else {
1301 +               ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash,
1302 +                         atomic_read(&ext3_xattr_cache->c_entry_count));
1303 +               mb_cache_entry_release(ce);
1304 +       }
1305 +       return error;
1306 +}
1307 +
1308 +/*
1309 + * ext3_xattr_cmp()
1310 + *
1311 + * Compare two extended attribute blocks for equality.
1312 + *
1313 + * Returns 0 if the blocks are equal, 1 if they differ, and
1314 + * a negative error number on errors.
1315 + */
1316 +static int
1317 +ext3_xattr_cmp(struct ext3_xattr_header *header1,
1318 +              struct ext3_xattr_header *header2)
1319 +{
1320 +       struct ext3_xattr_entry *entry1, *entry2;
1321 +
1322 +       entry1 = ENTRY(header1+1);
1323 +       entry2 = ENTRY(header2+1);
1324 +       while (!IS_LAST_ENTRY(entry1)) {
1325 +               if (IS_LAST_ENTRY(entry2))
1326 +                       return 1;
1327 +               if (entry1->e_hash != entry2->e_hash ||
1328 +                   entry1->e_name_len != entry2->e_name_len ||
1329 +                   entry1->e_value_size != entry2->e_value_size ||
1330 +                   memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
1331 +                       return 1;
1332 +               if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
1333 +                       return -EIO;
1334 +               if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
1335 +                          (char *)header2 + le16_to_cpu(entry2->e_value_offs),
1336 +                          le32_to_cpu(entry1->e_value_size)))
1337 +                       return 1;
1338 +
1339 +               entry1 = EXT3_XATTR_NEXT(entry1);
1340 +               entry2 = EXT3_XATTR_NEXT(entry2);
1341 +       }
1342 +       if (!IS_LAST_ENTRY(entry2))
1343 +               return 1;
1344 +       return 0;
1345 +}
1346 +
1347 +/*
1348 + * ext3_xattr_cache_find()
1349 + *
1350 + * Find an identical extended attribute block.
1351 + *
1352 + * Returns a pointer to the block found, or NULL if such a block was
1353 + * not found or an error occurred.
1354 + */
1355 +static struct buffer_head *
1356 +ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header)
1357 +{
1358 +       __u32 hash = le32_to_cpu(header->h_hash);
1359 +       struct mb_cache_entry *ce;
1360 +
1361 +       if (!header->h_hash)
1362 +               return NULL;  /* never share */
1363 +       ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
1364 +       ce = mb_cache_entry_find_first(ext3_xattr_cache, 0, inode->i_dev, hash);
1365 +       while (ce) {
1366 +               struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
1367 +
1368 +               if (!bh) {
1369 +                       ext3_error(inode->i_sb, "ext3_xattr_cache_find",
1370 +                               "inode %ld: block %ld read error",
1371 +                               inode->i_ino, ce->e_block);
1372 +               } else if (le32_to_cpu(HDR(bh)->h_refcount) >
1373 +                          EXT3_XATTR_REFCOUNT_MAX) {
1374 +                       ea_idebug(inode, "block %ld refcount %d>%d",ce->e_block,
1375 +                               le32_to_cpu(HDR(bh)->h_refcount),
1376 +                               EXT3_XATTR_REFCOUNT_MAX);
1377 +               } else if (!ext3_xattr_cmp(header, HDR(bh))) {
1378 +                       ea_bdebug(bh, "b_count=%d",atomic_read(&(bh->b_count)));
1379 +                       mb_cache_entry_release(ce);
1380 +                       return bh;
1381 +               }
1382 +               brelse(bh);
1383 +               ce = mb_cache_entry_find_next(ce, 0, inode->i_dev, hash);
1384 +       }
1385 +       return NULL;
1386 +}
1387 +
1388 +/*
1389 + * ext3_xattr_cache_remove()
1390 + *
1391 + * Remove the cache entry of a block from the cache. Called when a
1392 + * block becomes invalid.
1393 + */
1394 +static void
1395 +ext3_xattr_cache_remove(struct buffer_head *bh)
1396 +{
1397 +       struct mb_cache_entry *ce;
1398 +
1399 +       ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_dev, bh->b_blocknr);
1400 +       if (ce) {
1401 +               ea_bdebug(bh, "removing (%d cache entries remaining)",
1402 +                         atomic_read(&ext3_xattr_cache->c_entry_count)-1);
1403 +               mb_cache_entry_free(ce);
1404 +       } else 
1405 +               ea_bdebug(bh, "no cache entry");
1406 +}
1407 +
1408 +#define NAME_HASH_SHIFT 5
1409 +#define VALUE_HASH_SHIFT 16
1410 +
1411 +/*
1412 + * ext3_xattr_hash_entry()
1413 + *
1414 + * Compute the hash of an extended attribute.
1415 + */
1416 +static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
1417 +                                        struct ext3_xattr_entry *entry)
1418 +{
1419 +       __u32 hash = 0;
1420 +       char *name = entry->e_name;
1421 +       int n;
1422 +
1423 +       for (n=0; n < entry->e_name_len; n++) {
1424 +               hash = (hash << NAME_HASH_SHIFT) ^
1425 +                      (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
1426 +                      *name++;
1427 +       }
1428 +
1429 +       if (entry->e_value_block == 0 && entry->e_value_size != 0) {
1430 +               __u32 *value = (__u32 *)((char *)header +
1431 +                       le16_to_cpu(entry->e_value_offs));
1432 +               for (n = (le32_to_cpu(entry->e_value_size) +
1433 +                    EXT3_XATTR_ROUND) >> EXT3_XATTR_PAD_BITS; n; n--) {
1434 +                       hash = (hash << VALUE_HASH_SHIFT) ^
1435 +                              (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
1436 +                              le32_to_cpu(*value++);
1437 +               }
1438 +       }
1439 +       entry->e_hash = cpu_to_le32(hash);
1440 +}
1441 +
1442 +#undef NAME_HASH_SHIFT
1443 +#undef VALUE_HASH_SHIFT
1444 +
1445 +#define BLOCK_HASH_SHIFT 16
1446 +
1447 +/*
1448 + * ext3_xattr_rehash()
1449 + *
1450 + * Re-compute the extended attribute hash value after an entry has changed.
1451 + */
1452 +static void ext3_xattr_rehash(struct ext3_xattr_header *header,
1453 +                             struct ext3_xattr_entry *entry)
1454 +{
1455 +       struct ext3_xattr_entry *here;
1456 +       __u32 hash = 0;
1457 +       
1458 +       ext3_xattr_hash_entry(header, entry);
1459 +       here = ENTRY(header+1);
1460 +       while (!IS_LAST_ENTRY(here)) {
1461 +               if (!here->e_hash) {
1462 +                       /* Block is not shared if an entry's hash value == 0 */
1463 +                       hash = 0;
1464 +                       break;
1465 +               }
1466 +               hash = (hash << BLOCK_HASH_SHIFT) ^
1467 +                      (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
1468 +                      le32_to_cpu(here->e_hash);
1469 +               here = EXT3_XATTR_NEXT(here);
1470 +       }
1471 +       header->h_hash = cpu_to_le32(hash);
1472 +}
1473 +
1474 +#undef BLOCK_HASH_SHIFT
1475 +
1476 +int __init
1477 +init_ext3_xattr(void)
1478 +{
1479 +       ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL,
1480 +               sizeof(struct mb_cache_entry) +
1481 +               sizeof(struct mb_cache_entry_index), 1, 61);
1482 +       if (!ext3_xattr_cache)
1483 +               return -ENOMEM;
1484 +
1485 +       return 0;
1486 +}
1487 +
1488 +void
1489 +exit_ext3_xattr(void)
1490 +{
1491 +       if (ext3_xattr_cache)
1492 +               mb_cache_destroy(ext3_xattr_cache);
1493 +       ext3_xattr_cache = NULL;
1494 +}
1495 +
1496 +#else  /* CONFIG_EXT3_FS_XATTR_SHARING */
1497 +
1498 +int __init
1499 +init_ext3_xattr(void)
1500 +{
1501 +       return 0;
1502 +}
1503 +
1504 +void
1505 +exit_ext3_xattr(void)
1506 +{
1507 +}
1508 +
1509 +#endif  /* CONFIG_EXT3_FS_XATTR_SHARING */
1510 diff -Nur linux-2.4.18/include/linux/ext3_fs.h linux-2.4.18ea/include/linux/ext3_fs.h
1511 --- linux-2.4.18/include/linux/ext3_fs.h        Sun Feb 24 04:42:59 2002
1512 +++ linux-2.4.18ea/include/linux/ext3_fs.h      Mon Mar 11 03:27:00 2002
1513 @@ -58,8 +58,6 @@
1514   */
1515  #define        EXT3_BAD_INO             1      /* Bad blocks inode */
1516  #define EXT3_ROOT_INO           2      /* Root inode */
1517 -#define EXT3_ACL_IDX_INO        3      /* ACL inode */
1518 -#define EXT3_ACL_DATA_INO       4      /* ACL inode */
1519  #define EXT3_BOOT_LOADER_INO    5      /* Boot loader inode */
1520  #define EXT3_UNDEL_DIR_INO      6      /* Undelete directory inode */
1521  #define EXT3_RESIZE_INO                 7      /* Reserved group descriptors inode */
1522 @@ -89,7 +87,6 @@
1523  #else
1524  # define EXT3_BLOCK_SIZE(s)            (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
1525  #endif
1526 -#define EXT3_ACLE_PER_BLOCK(s)         (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_acl_entry))
1527  #define        EXT3_ADDR_PER_BLOCK(s)          (EXT3_BLOCK_SIZE(s) / sizeof (__u32))
1528  #ifdef __KERNEL__
1529  # define EXT3_BLOCK_SIZE_BITS(s)       ((s)->s_blocksize_bits)
1530 @@ -124,28 +121,6 @@
1531  #endif
1532  
1533  /*
1534 - * ACL structures
1535 - */
1536 -struct ext3_acl_header /* Header of Access Control Lists */
1537 -{
1538 -       __u32   aclh_size;
1539 -       __u32   aclh_file_count;
1540 -       __u32   aclh_acle_count;
1541 -       __u32   aclh_first_acle;
1542 -};
1543 -
1544 -struct ext3_acl_entry  /* Access Control List Entry */
1545 -{
1546 -       __u32   acle_size;
1547 -       __u16   acle_perms;     /* Access permissions */
1548 -       __u16   acle_type;      /* Type of entry */
1549 -       __u16   acle_tag;       /* User or group identity */
1550 -       __u16   acle_pad1;
1551 -       __u32   acle_next;      /* Pointer on next entry for the */
1552 -                                       /* same inode or on next free entry */
1553 -};
1554 -
1555 -/*
1556   * Structure of a blocks group descriptor
1557   */
1558  struct ext3_group_desc
1559 @@ -512,7 +487,7 @@
1560  #define EXT3_FEATURE_INCOMPAT_RECOVER          0x0004 /* Needs recovery */
1561  #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV      0x0008 /* Journal device */
1562  
1563 -#define EXT3_FEATURE_COMPAT_SUPP       0
1564 +#define EXT3_FEATURE_COMPAT_SUPP       EXT3_FEATURE_COMPAT_EXT_ATTR
1565  #define EXT3_FEATURE_INCOMPAT_SUPP     (EXT3_FEATURE_INCOMPAT_FILETYPE| \
1566                                          EXT3_FEATURE_INCOMPAT_RECOVER)
1567  #define EXT3_FEATURE_RO_COMPAT_SUPP    (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
1568 @@ -603,4 +578,22 @@
1569  */
1570  
1571 +/* Defined for extended attributes */
1572 +#define CONFIG_EXT3_FS_XATTR y
1573 +#ifndef ENOATTR
1574 +#define ENOATTR ENODATA                /* No such attribute */
1575 +#endif
1576 +#ifndef ENOTSUP
1577 +#define ENOTSUP EOPNOTSUPP     /* Operation not supported */
1578 +#endif
1579 +#ifndef XATTR_NAME_MAX
1580 +#define XATTR_NAME_MAX   255   /* # chars in an extended attribute name */
1581 +#define XATTR_SIZE_MAX 65536   /* size of an extended attribute value (64k) */
1582 +#define XATTR_LIST_MAX 65536   /* size of extended attribute namelist (64k) */
1583 +#endif
1584 +#ifndef XATTR_CREATE
1585 +#define XATTR_CREATE   1       /* set value, fail if attr already exists */
1586 +#define XATTR_REPLACE  2       /* set value, fail if attr does not exist */
1587 +#endif
1588 +
1589  /*
1590   * Ok, these declarations are also in <linux/kernel.h> but none of the
1591 @@ -628,6 +603,7 @@
1592  extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
1593  
1594  /* inode.c */
1595 +extern int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
1596  extern struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
1597  extern struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
1598  
1599 @@ -694,8 +670,10 @@
1600  
1601  /* namei.c */
1602  extern struct inode_operations ext3_dir_inode_operations;
1603 +extern struct inode_operations ext3_special_inode_operations;
1604  
1605  /* symlink.c */
1606 +extern struct inode_operations ext3_symlink_inode_operations;
1607  extern struct inode_operations ext3_fast_symlink_inode_operations;
1608  
1609  
1610 diff -Nur linux-2.4.18/include/linux/ext3_jbd.h linux-2.4.18ea/include/linux/ext3_jbd.h
1611 --- linux-2.4.18/include/linux/ext3_jbd.h       Fri Dec 21 18:42:03 2001
1612 +++ linux-2.4.18ea/include/linux/ext3_jbd.h     Mon Mar 25 00:11:36 2002
1613 @@ -30,13 +30,19 @@
1614  
1615  #define EXT3_SINGLEDATA_TRANS_BLOCKS   8
1616  
1617 +/* Extended attributes may touch two data buffers, two bitmap buffers,
1618 + * and two group and summaries. */
1619 +
1620 +#define EXT3_XATTR_TRANS_BLOCKS                8
1621 +
1622  /* Define the minimum size for a transaction which modifies data.  This
1623   * needs to take into account the fact that we may end up modifying two
1624   * quota files too (one for the group, one for the user quota).  The
1625   * superblock only gets updated once, of course, so don't bother
1626   * counting that again for the quota updates. */
1627  
1628 -#define EXT3_DATA_TRANS_BLOCKS         (3 * EXT3_SINGLEDATA_TRANS_BLOCKS - 2)
1629 +#define EXT3_DATA_TRANS_BLOCKS         (3 * EXT3_SINGLEDATA_TRANS_BLOCKS + \
1630 +                                        EXT3_XATTR_TRANS_BLOCKS - 2)
1631  
1632  extern int ext3_writepage_trans_blocks(struct inode *inode);
1633  
1634 diff -Nur linux-2.4.18/include/linux/ext3_xattr.h linux-2.4.18ea/include/linux/ext3_xattr.h
1635 --- linux-2.4.18/include/linux/ext3_xattr.h     Thu Jan  1 01:00:00 1970
1636 +++ linux-2.4.18ea/include/linux/ext3_xattr.h   Fri Apr  5 10:08:01 2002
1637 @@ -0,0 +1,155 @@
1638 +/*
1639 +  File: linux/ext3_xattr.h
1640 +
1641 +  On-disk format of extended attributes for the ext3 filesystem.
1642 +
1643 +  (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
1644 +*/
1645 +
1646 +#include <linux/config.h>
1647 +#include <linux/init.h>
1648 +#include <linux/xattr.h>
1649 +
1650 +/* Magic value in attribute blocks */
1651 +#define EXT3_XATTR_MAGIC               0xEA020000
1652 +
1653 +/* Maximum number of references to one attribute block */
1654 +#define EXT3_XATTR_REFCOUNT_MAX                1024
1655 +
1656 +/* Name indexes */
1657 +#define EXT3_XATTR_INDEX_MAX                   10
1658 +#define EXT3_XATTR_INDEX_USER                  1
1659 +
1660 +struct ext3_xattr_header {
1661 +       __u32   h_magic;        /* magic number for identification */
1662 +       __u32   h_refcount;     /* reference count */
1663 +       __u32   h_blocks;       /* number of disk blocks used */
1664 +       __u32   h_hash;         /* hash value of all attributes */
1665 +       __u32   h_reserved[4];  /* zero right now */
1666 +};
1667 +
1668 +struct ext3_xattr_entry {
1669 +       __u8    e_name_len;     /* length of name */
1670 +       __u8    e_name_index;   /* attribute name index */
1671 +       __u16   e_value_offs;   /* offset in disk block of value */
1672 +       __u32   e_value_block;  /* disk block attribute is stored on (n/i) */
1673 +       __u32   e_value_size;   /* size of attribute value */
1674 +       __u32   e_hash;         /* hash value of name and value */
1675 +       char    e_name[0];      /* attribute name */
1676 +};
1677 +
1678 +#define EXT3_XATTR_PAD_BITS            2
1679 +#define EXT3_XATTR_PAD         (1<<EXT3_XATTR_PAD_BITS)
1680 +#define EXT3_XATTR_ROUND               (EXT3_XATTR_PAD-1)
1681 +#define EXT3_XATTR_LEN(name_len) \
1682 +       (((name_len) + EXT3_XATTR_ROUND + \
1683 +       sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND)
1684 +#define EXT3_XATTR_NEXT(entry) \
1685 +       ( (struct ext3_xattr_entry *)( \
1686 +         (char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) )
1687 +#define EXT3_XATTR_SIZE(size) \
1688 +       (((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND)
1689 +
1690 +#ifdef __KERNEL__
1691 +
1692 +# ifdef CONFIG_EXT3_FS_XATTR
1693 +
1694 +struct ext3_xattr_handler {
1695 +       char *prefix;
1696 +       size_t (*list)(char *list, struct inode *inode, const char *name,
1697 +                      int name_len);
1698 +       int (*get)(struct inode *inode, const char *name, void *buffer,
1699 +                  size_t size);
1700 +       int (*set)(struct inode *inode, const char *name, void *buffer,
1701 +                  size_t size, int flags);
1702 +};
1703 +
1704 +extern int ext3_xattr_register(int, struct ext3_xattr_handler *);
1705 +extern void ext3_xattr_unregister(int, struct ext3_xattr_handler *);
1706 +
1707 +extern int ext3_setxattr(struct dentry *, const char *, void *, size_t, int);
1708 +extern ssize_t ext3_getxattr(struct dentry *, const char *, void *, size_t);
1709 +extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
1710 +extern int ext3_removexattr(struct dentry *, const char *);
1711 +
1712 +extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
1713 +extern int ext3_xattr_list(struct inode *, char *, size_t);
1714 +extern int ext3_xattr_set(handle_t *handle, struct inode *, int, const char *, void *, size_t, int);
1715 +
1716 +extern void ext3_xattr_drop_inode(handle_t *, struct inode *);
1717 +extern void ext3_xattr_put_super(struct super_block *);
1718 +
1719 +extern int init_ext3_xattr(void) __init;
1720 +extern void exit_ext3_xattr(void);
1721 +
1722 +# else  /* CONFIG_EXT3_FS_XATTR */
1723 +#  define ext3_setxattr                NULL
1724 +#  define ext3_getxattr                NULL
1725 +#  define ext3_listxattr       NULL
1726 +#  define ext3_removexattr     NULL
1727 +
1728 +static inline int
1729 +ext3_xattr_get(struct inode *inode, int name_index, const char *name,
1730 +              void *buffer, size_t size, int flags)
1731 +{
1732 +       return -ENOTSUP;
1733 +}
1734 +
1735 +static inline int
1736 +ext3_xattr_list(struct inode *inode, void *buffer, size_t size, int flags)
1737 +{
1738 +       return -ENOTSUP;
1739 +}
1740 +
1741 +static inline int
1742 +ext3_xattr_set(handle_t *handle, struct inode *inode, int name_index,
1743 +              const char *name, void *value, size_t size, int flags)
1744 +{
1745 +       return -ENOTSUP;
1746 +}
1747 +
1748 +static inline void
1749 +ext3_xattr_drop_inode(handle_t *handle, struct inode *inode)
1750 +{
1751 +}
1752 +
1753 +static inline void
1754 +ext3_xattr_put_super(struct super_block *sb)
1755 +{
1756 +}
1757 +
1758 +static inline int
1759 +init_ext3_xattr(void)
1760 +{
1761 +       return 0;
1762 +}
1763 +
1764 +static inline void
1765 +exit_ext3_xattr(void)
1766 +{
1767 +}
1768 +
1769 +# endif  /* CONFIG_EXT3_FS_XATTR */
1770 +
1771 +# ifdef CONFIG_EXT3_FS_XATTR_USER
1772 +
1773 +extern int init_ext3_xattr_user(void) __init;
1774 +extern void exit_ext3_xattr_user(void);
1775 +
1776 +# else  /* CONFIG_EXT3_FS_XATTR_USER */
1777 +
1778 +static inline int
1779 +init_ext3_xattr_user(void)
1780 +{
1781 +       return 0;
1782 +}
1783 +
1784 +static inline void
1785 +exit_ext3_xattr_user(void)
1786 +{
1787 +}
1788 +
1789 +#endif  /* CONFIG_EXT3_FS_XATTR_USER */
1790 +
1791 +#endif  /* __KERNEL__ */
1792 +
1793 diff -Nur linux-2.4.18/include/linux/xattr.h linux-2.4.18ea/include/linux/xattr.h
1794 --- linux-2.4.18/include/linux/xattr.h  Thu Jan  1 01:00:00 1970
1795 +++ linux-2.4.18ea/include/linux/xattr.h        Sun Mar 24 23:42:21 2002
1796 @@ -0,0 +1,15 @@
1797 +/*
1798 +  File: linux/xattr.h
1799 +
1800 +  Extended attributes handling.
1801 +
1802 +  Copyright (C) 2001 by Andreas Gruenbacher <a.gruenbacher@computer.org>
1803 +  Copyright (C) 2001 SGI - Silicon Graphics, Inc <linux-xfs@oss.sgi.com>
1804 +*/
1805 +#ifndef _LINUX_XATTR_H
1806 +#define _LINUX_XATTR_H
1807 +
1808 +#define XATTR_CREATE   1       /* set value, fail if attr already exists */
1809 +#define XATTR_REPLACE  2       /* set value, fail if attr does not exist */
1810 +
1811 +#endif /* _LINUX_XATTR_H */