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