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