Whamcloud - gitweb
- missed patches from suse-2.4.21-2 series added
[fs/lustre-release.git] / lustre / kernel_patches / patches / ext3-ea-in-inode-2.4.21-chaos.patch
1  fs/ext3/ialloc.c          |    6 
2  fs/ext3/inode.c           |   12 
3  fs/ext3/super.c           |    6 
4  fs/ext3/xattr.c           |  597 +++++++++++++++++++++++++++++++++++++++++++++-
5  include/linux/ext3_fs.h   |    2 
6  include/linux/ext3_fs_i.h |    3 
7  6 files changed, 615 insertions(+), 11 deletions(-)
8
9 Index: linux-2.4.21-chaos/fs/ext3/ialloc.c
10 ===================================================================
11 --- linux-2.4.21-chaos.orig/fs/ext3/ialloc.c    2003-12-12 17:39:10.000000000 +0300
12 +++ linux-2.4.21-chaos/fs/ext3/ialloc.c 2003-12-12 17:39:55.000000000 +0300
13 @@ -580,6 +580,12 @@
14         insert_inode_hash(inode);
15         inode->i_generation = sbi->s_next_generation++;
16  
17 +       if (EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE) {
18 +               EXT3_I(inode)->i_extra_isize = sizeof(__u16)    /* i_extra_isize */
19 +                               + sizeof(__u16);        /* i_pad1 */
20 +       } else
21 +               EXT3_I(inode)->i_extra_isize = 0;
22 +
23         ei->i_state = EXT3_STATE_NEW;
24         err = ext3_get_inode_loc_new(inode, &iloc, 1);
25         if (err) goto fail;
26 Index: linux-2.4.21-chaos/fs/ext3/inode.c
27 ===================================================================
28 --- linux-2.4.21-chaos.orig/fs/ext3/inode.c     2003-12-12 17:39:11.000000000 +0300
29 +++ linux-2.4.21-chaos/fs/ext3/inode.c  2003-12-12 17:39:55.000000000 +0300
30 @@ -2502,6 +2502,12 @@
31                 ei->i_data[block] = iloc.raw_inode->i_block[block];
32         INIT_LIST_HEAD(&ei->i_orphan);
33  
34 +       if (EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE)
35 +               EXT3_I(inode)->i_extra_isize =
36 +                       le16_to_cpu(raw_inode->i_extra_isize);
37 +       else
38 +               EXT3_I(inode)->i_extra_isize = 0;
39 +
40         if (S_ISREG(inode->i_mode)) {
41                 inode->i_op = &ext3_file_inode_operations;
42                 inode->i_fop = &ext3_file_operations;
43 @@ -2564,6 +2570,8 @@
44                 if (err)
45                         goto out_brelse;
46         }
47 +       if (EXT3_I(inode)->i_state & EXT3_STATE_NEW)
48 +               memset(raw_inode, 0, EXT3_INODE_SIZE(inode->i_sb));
49         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
50         if(!(test_opt(inode->i_sb, NO_UID32))) {
51                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
52 @@ -2646,6 +2654,10 @@
53         else for (block = 0; block < EXT3_N_BLOCKS; block++)
54                 raw_inode->i_block[block] = ei->i_data[block];
55  
56 +       if (EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE)
57 +               raw_inode->i_extra_isize =
58 +                       cpu_to_le16(EXT3_I(inode)->i_extra_isize);
59 +
60         BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata");
61         rc = ext3_journal_dirty_metadata(handle, bh);
62         if (!err)
63 Index: linux-2.4.21-chaos/fs/ext3/xattr.c
64 ===================================================================
65 --- linux-2.4.21-chaos.orig/fs/ext3/xattr.c     2003-12-12 17:38:44.000000000 +0300
66 +++ linux-2.4.21-chaos/fs/ext3/xattr.c  2003-12-12 17:42:58.000000000 +0300
67 @@ -88,6 +88,9 @@
68                                   struct buffer_head *,
69                                   struct ext3_xattr_header *);
70  
71 +int ext3_xattr_block_set(handle_t *, struct inode *, int, const char *,
72 +                       const void *, size_t, int);
73 +
74  #ifdef CONFIG_EXT3_FS_XATTR_SHARING
75  
76  static int ext3_xattr_cache_insert(struct buffer_head *);
77 @@ -256,17 +259,12 @@
78  }
79  
80  /*
81 - * ext3_xattr_get()
82 - *
83 - * Copy an extended attribute into the buffer
84 - * provided, or compute the buffer size required.
85 - * Buffer is NULL to compute the size of the buffer required.
86 + * ext3_xattr_block_get()
87   *
88 - * Returns a negative error number on failure, or the number of bytes
89 - * used / required on success.
90 + * routine looks for attribute in EA block and returns it's value and size
91   */
92  int
93 -ext3_xattr_get(struct inode *inode, int name_index, const char *name,
94 +ext3_xattr_block_get(struct inode *inode, int name_index, const char *name,
95                void *buffer, size_t buffer_size)
96  {
97         struct buffer_head *bh = NULL;
98 @@ -359,6 +357,94 @@
99  }
100  
101  /*
102 + * ext3_xattr_ibode_get()
103 + *
104 + * routine looks for attribute in inode body and returns it's value and size
105 + */
106 +int
107 +ext3_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
108 +              void *buffer, size_t buffer_size)
109 +{
110 +       int size, name_len = strlen(name), storage_size;
111 +       struct ext3_xattr_entry *last;
112 +       struct ext3_inode *raw_inode;
113 +       struct ext3_iloc iloc;
114 +       char *start, *end;
115 +       int ret = -ENOENT;
116 +       
117 +       if (EXT3_SB(inode->i_sb)->s_inode_size <= EXT3_GOOD_OLD_INODE_SIZE)
118 +               return -ENOENT;
119 +
120 +       ret = ext3_get_inode_loc(inode, &iloc);
121 +       if (ret)
122 +               return ret;
123 +       raw_inode = iloc.raw_inode;
124 +
125 +       storage_size = EXT3_SB(inode->i_sb)->s_inode_size -
126 +                               EXT3_GOOD_OLD_INODE_SIZE -
127 +                               EXT3_I(inode)->i_extra_isize -
128 +                               sizeof(__u32);
129 +       start = (char *) raw_inode + EXT3_GOOD_OLD_INODE_SIZE +
130 +                       EXT3_I(inode)->i_extra_isize;
131 +       if (le32_to_cpu((*(__u32*) start)) != EXT3_XATTR_MAGIC) {
132 +               brelse(iloc.bh);
133 +               return -ENOENT;
134 +       }
135 +       start += sizeof(__u32);
136 +       end = (char *) raw_inode + EXT3_SB(inode->i_sb)->s_inode_size;
137 +
138 +       last = (struct ext3_xattr_entry *) start;
139 +       while (!IS_LAST_ENTRY(last)) {
140 +               struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
141 +               if (le32_to_cpu(last->e_value_size) > storage_size ||
142 +                               (char *) next >= end) {
143 +                       ext3_error(inode->i_sb, "ext3_xattr_ibody_get",
144 +                               "inode %ld", inode->i_ino);
145 +                       brelse(iloc.bh);
146 +                       return -EIO;
147 +               }
148 +               if (name_index == last->e_name_index &&
149 +                   name_len == last->e_name_len &&
150 +                   !memcmp(name, last->e_name, name_len))
151 +                       goto found;
152 +               last = next;
153 +       }
154 +
155 +       /* can't find EA */
156 +       brelse(iloc.bh);
157 +       return -ENOENT;
158 +       
159 +found:
160 +       size = le32_to_cpu(last->e_value_size);
161 +       if (buffer) {
162 +               ret = -ERANGE;
163 +               if (buffer_size >= size) {
164 +                       memcpy(buffer, start + le16_to_cpu(last->e_value_offs),
165 +                       size);
166 +                       ret = size;
167 +               }
168 +       } else
169 +               ret = size;
170 +       brelse(iloc.bh);
171 +       return ret;
172 +}
173 +
174 +int ext3_xattr_get(struct inode *inode, int name_index, const char *name,
175 +                       void *buffer, size_t buffer_size)
176 +{
177 +       int err;
178 +
179 +       /* try to find attribute in inode body */
180 +       err = ext3_xattr_ibody_get(inode, name_index, name,
181 +                                       buffer, buffer_size);
182 +       if (err < 0)
183 +               /* search was unsuccessful, try to find EA in dedicated block */
184 +               err = ext3_xattr_block_get(inode, name_index, name,
185 +                               buffer, buffer_size);
186 +       return err;
187 +}
188 +
189 +/*
190   * ext3_xattr_list()
191   *
192   * Copy a list of attribute names into the buffer
193 @@ -369,7 +455,7 @@
194   * used / required on success.
195   */
196  int
197 -ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
198 +ext3_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size)
199  {
200         struct buffer_head *bh = NULL;
201         struct ext3_xattr_entry *entry;
202 @@ -446,6 +532,131 @@
203         return error;
204  }
205  
206 +/* ext3_xattr_ibody_list()
207 + *
208 + * generate list of attributes stored in inode body
209 + */
210 +int
211 +ext3_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size)
212 +{
213 +       struct ext3_xattr_entry *last;
214 +       struct ext3_inode *raw_inode;
215 +       char *start, *end, *buf;
216 +       struct ext3_iloc iloc;
217 +       int storage_size;
218 +       int ret;
219 +       int size = 0;
220 +       
221 +       if (EXT3_SB(inode->i_sb)->s_inode_size <= EXT3_GOOD_OLD_INODE_SIZE)
222 +               return 0;
223 +
224 +       ret = ext3_get_inode_loc(inode, &iloc);
225 +       if (ret)
226 +               return ret;
227 +       raw_inode = iloc.raw_inode;
228 +
229 +       storage_size = EXT3_SB(inode->i_sb)->s_inode_size -
230 +                               EXT3_GOOD_OLD_INODE_SIZE -
231 +                               EXT3_I(inode)->i_extra_isize -
232 +                               sizeof(__u32);
233 +       start = (char *) raw_inode + EXT3_GOOD_OLD_INODE_SIZE +
234 +                       EXT3_I(inode)->i_extra_isize;
235 +       if (le32_to_cpu((*(__u32*) start)) != EXT3_XATTR_MAGIC) {
236 +               brelse(iloc.bh);
237 +               return 0;
238 +       }
239 +       start += sizeof(__u32);
240 +       end = (char *) raw_inode + EXT3_SB(inode->i_sb)->s_inode_size;
241 +
242 +       last = (struct ext3_xattr_entry *) start;
243 +       while (!IS_LAST_ENTRY(last)) {
244 +               struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
245 +               struct ext3_xattr_handler *handler;
246 +               if (le32_to_cpu(last->e_value_size) > storage_size ||
247 +                               (char *) next >= end) {
248 +                       ext3_error(inode->i_sb, "ext3_xattr_ibody_list",
249 +                               "inode %ld", inode->i_ino);
250 +                       brelse(iloc.bh);
251 +                       return -EIO;
252 +               }
253 +               handler = ext3_xattr_handler(last->e_name_index);
254 +               if (handler)
255 +                       size += handler->list(NULL, inode, last->e_name,
256 +                                             last->e_name_len);
257 +               last = next;
258 +       }
259 +
260 +       if (!buffer) {
261 +               ret = size;
262 +               goto cleanup;
263 +       } else {
264 +               ret = -ERANGE;
265 +               if (size > buffer_size)
266 +                       goto cleanup;
267 +       }
268 +
269 +       last = (struct ext3_xattr_entry *) start;
270 +       buf = buffer;
271 +       while (!IS_LAST_ENTRY(last)) {
272 +               struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
273 +               struct ext3_xattr_handler *handler;
274 +               handler = ext3_xattr_handler(last->e_name_index);
275 +               if (handler)
276 +                       buf += handler->list(buf, inode, last->e_name,
277 +                                             last->e_name_len);
278 +               last = next;
279 +       }
280 +       ret = size;
281 +cleanup:
282 +       brelse(iloc.bh);
283 +       return ret;
284 +}
285 +
286 +/*
287 + * ext3_xattr_list()
288 + *
289 + * Copy a list of attribute names into the buffer
290 + * provided, or compute the buffer size required.
291 + * Buffer is NULL to compute the size of the buffer required.
292 + *
293 + * Returns a negative error number on failure, or the number of bytes
294 + * used / required on success.
295 + */
296 +int
297 +ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
298 +{
299 +       int error;
300 +       int size = buffer_size;
301 +
302 +       /* get list of attributes stored in inode body */
303 +       error = ext3_xattr_ibody_list(inode, buffer, buffer_size);
304 +       if (error < 0) {
305 +               /* some error occured while collecting
306 +                * attributes in inode body */
307 +               size = 0;
308 +               goto cleanup;
309 +       }
310 +       size = error;
311 +
312 +       /* get list of attributes stored in dedicated block */
313 +       if (buffer) {
314 +               buffer_size -= error;
315 +               if (buffer_size <= 0) {
316 +                       buffer = NULL;
317 +                       buffer_size = 0;
318 +               } else
319 +                       buffer += error;
320 +       }
321 +
322 +       error = ext3_xattr_block_list(inode, buffer, buffer_size);
323 +       if (error < 0)
324 +               /* listing was successful, so we return len */
325 +               size = 0;
326 +
327 +cleanup:
328 +       return error + size;
329 +}
330 +
331  /*
332   * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is
333   * not set, set it.
334 @@ -480,6 +691,102 @@
335   */
336  int
337  ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
338 +                       const char *name, const void *value, size_t value_len,
339 +                       int flags)
340 +{
341 +       struct ext3_xattr_entry entry;
342 +       int err, where = 0, found = 0, total;
343 +       int free1 = -1, free2 = -1;
344 +       int name_len;
345 +       
346 +       ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
347 +                 name_index, name, value, (long)value_len);
348 +
349 +       if (IS_RDONLY(inode))
350 +               return -EROFS;
351 +       if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
352 +               return -EPERM;
353 +       if (value == NULL)
354 +               value_len = 0;
355 +       if (name == NULL)
356 +               return -EINVAL;
357 +       name_len = strlen(name);
358 +       if (name_len > 255 || value_len > inode->i_sb->s_blocksize)
359 +               return -ERANGE;
360 +
361 +       /* try to find attribute in inode body */
362 +       err = ext3_xattr_ibody_find(inode, name_index, name, &entry, &free1);
363 +       if (err == 0) {
364 +               /* found EA in inode */
365 +               found = 1;
366 +               where = 0;
367 +       } else if (err == -ENOENT) {
368 +               /* there is no such attribute in inode body */
369 +               /* try to find attribute in dedicated block */
370 +               err = ext3_xattr_block_find(inode, name_index, name,
371 +                                               &entry, &free2);
372 +               if (err != 0 && err != -ENOENT) {
373 +                       /* not found EA in block */
374 +                       goto finish;    
375 +               } else if (err == 0) {
376 +                       /* found EA in block */
377 +                       where = 1;
378 +                       found = 1;
379 +               }
380 +       } else
381 +               goto finish;
382 +
383 +       /* check flags: may replace? may create ? */
384 +       if (found && (flags & XATTR_CREATE)) {
385 +               err = -EEXIST;
386 +               goto finish;
387 +       } else if (!found && (flags & XATTR_REPLACE)) {
388 +               err = -ENODATA;
389 +               goto finish;
390 +       }
391 +
392 +       /* check if we have enough space to store attribute */
393 +       total = EXT3_XATTR_LEN(strlen(name)) + value_len;
394 +       if (free1 >= 0 && total > free1 && free2 >= 0 && total > free2) {
395 +               /* have no enough space */
396 +               err = -ENOSPC;
397 +               goto finish;
398 +       }
399 +       
400 +       /* time to remove attribute */
401 +       if (found) {
402 +               if (where == 0) {
403 +                       /* EA is stored in inode body */
404 +                       ext3_xattr_ibody_set(handle, inode, name_index, name,
405 +                                       NULL, 0, flags);
406 +               } else {
407 +                       /* EA is stored in separated block */
408 +                       ext3_xattr_block_set(handle, inode, name_index, name,
409 +                                       NULL, 0, flags);
410 +               }
411 +       }
412 +
413 +       /* try to store EA in inode body */
414 +       err = ext3_xattr_ibody_set(handle, inode, name_index, name,
415 +                               value, value_len, flags);
416 +       if (err) {
417 +               /* can't store EA in inode body */
418 +               /* try to store in block */
419 +               err = ext3_xattr_block_set(handle, inode, name_index,
420 +                                       name, value, value_len, flags); 
421 +       }
422 +
423 +finish:        
424 +       return err;
425 +}
426 +
427 +/*
428 + * ext3_xattr_block_set()
429 + *
430 + * this routine add/remove/replace attribute in EA block
431 + */
432 +int
433 +ext3_xattr_block_set(handle_t *handle, struct inode *inode, int name_index,
434                       const char *name, const void *value, size_t value_len,
435                       int flags)
436  {
437 @@ -868,6 +1174,279 @@
438  }
439  
440  /*
441 + * ext3_xattr_ibody_find()
442 + *
443 + * search attribute and calculate free space in inode body
444 + * NOTE: free space includes space our attribute hold
445 + */
446 +int
447 +ext3_xattr_ibody_find(struct inode *inode, int name_index,
448 +               const char *name, struct ext3_xattr_entry *rentry, int *free)
449 +{
450 +       struct ext3_xattr_entry *last;
451 +       struct ext3_inode *raw_inode;
452 +       int name_len = strlen(name);
453 +       int err, storage_size;
454 +       struct ext3_iloc iloc;
455 +       char *start, *end;
456 +       int ret = -ENOENT;
457 +       
458 +       if (EXT3_SB(inode->i_sb)->s_inode_size <= EXT3_GOOD_OLD_INODE_SIZE)
459 +               return ret;
460 +
461 +       err = ext3_get_inode_loc(inode, &iloc);
462 +       if (err)
463 +               return -EIO;
464 +       raw_inode = iloc.raw_inode;
465 +
466 +       storage_size = EXT3_SB(inode->i_sb)->s_inode_size -
467 +                               EXT3_GOOD_OLD_INODE_SIZE -
468 +                               EXT3_I(inode)->i_extra_isize -
469 +                               sizeof(__u32);
470 +       *free = storage_size - sizeof(__u32);
471 +       start = (char *) raw_inode + EXT3_GOOD_OLD_INODE_SIZE +
472 +                       EXT3_I(inode)->i_extra_isize;
473 +       if (le32_to_cpu((*(__u32*) start)) != EXT3_XATTR_MAGIC) {
474 +               brelse(iloc.bh);
475 +               return -ENOENT;
476 +       }
477 +       start += sizeof(__u32);
478 +       end = (char *) raw_inode + EXT3_SB(inode->i_sb)->s_inode_size;
479 +
480 +       last = (struct ext3_xattr_entry *) start;
481 +       while (!IS_LAST_ENTRY(last)) {
482 +               struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);
483 +               if (le32_to_cpu(last->e_value_size) > storage_size ||
484 +                               (char *) next >= end) {
485 +                       ext3_error(inode->i_sb, "ext3_xattr_ibody_find",
486 +                               "inode %ld", inode->i_ino);
487 +                       brelse(iloc.bh);
488 +                       return -EIO;
489 +               }
490 +
491 +               if (name_index == last->e_name_index &&
492 +                   name_len == last->e_name_len &&
493 +                   !memcmp(name, last->e_name, name_len)) {
494 +                       memcpy(rentry, last, sizeof(struct ext3_xattr_entry));
495 +                       ret = 0;
496 +               } else {
497 +                       *free -= EXT3_XATTR_LEN(last->e_name_len);
498 +                       *free -= le32_to_cpu(last->e_value_size);
499 +               }
500 +               last = next;
501 +       }
502 +       
503 +       brelse(iloc.bh);
504 +       return ret;
505 +}
506 +
507 +/*
508 + * ext3_xattr_block_find()
509 + *
510 + * search attribute and calculate free space in EA block (if it allocated)
511 + * NOTE: free space includes space our attribute hold
512 + */
513 +int
514 +ext3_xattr_block_find(struct inode *inode, int name_index, const char *name,
515 +              struct ext3_xattr_entry *rentry, int *free)
516 +{
517 +       struct buffer_head *bh = NULL;
518 +       struct ext3_xattr_entry *entry;
519 +       char *end;
520 +       int name_len, error = -ENOENT;
521 +
522 +       if (!EXT3_I(inode)->i_file_acl) {
523 +               *free = inode->i_sb->s_blocksize -
524 +                       sizeof(struct ext3_xattr_header) -
525 +                       sizeof(__u32);
526 +               return -ENOENT;
527 +       }
528 +       ea_idebug(inode, "reading block %d", EXT3_I(inode)->i_file_acl);
529 +       bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl);
530 +       if (!bh)
531 +               return -EIO;
532 +       ea_bdebug(bh, "b_count=%d, refcount=%d",
533 +               atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
534 +       end = bh->b_data + bh->b_size;
535 +       if (HDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
536 +           HDR(bh)->h_blocks != cpu_to_le32(1)) {
537 +bad_block:     ext3_error(inode->i_sb, "ext3_xattr_get",
538 +                       "inode %ld: bad block %d", inode->i_ino,
539 +                       EXT3_I(inode)->i_file_acl);
540 +               brelse(bh);
541 +               return -EIO;
542 +       }
543 +       /* find named attribute */
544 +       name_len = strlen(name);
545 +       *free = bh->b_size - sizeof(__u32);
546 +
547 +       entry = FIRST_ENTRY(bh);
548 +       while (!IS_LAST_ENTRY(entry)) {
549 +               struct ext3_xattr_entry *next =
550 +                       EXT3_XATTR_NEXT(entry);
551 +               if ((char *)next >= end)
552 +                       goto bad_block;
553 +               if (name_index == entry->e_name_index &&
554 +                   name_len == entry->e_name_len &&
555 +                   memcmp(name, entry->e_name, name_len) == 0) {
556 +                       memcpy(rentry, entry, sizeof(struct ext3_xattr_entry));
557 +                       error = 0;
558 +               } else {
559 +                       *free -= EXT3_XATTR_LEN(entry->e_name_len);
560 +                       *free -= le32_to_cpu(entry->e_value_size);
561 +               }
562 +               entry = next;
563 +       }
564 +       brelse(bh);
565 +
566 +       return error;
567 +}
568 +
569 +/*
570 + * ext3_xattr_inode_set()
571 + *
572 + * this routine add/remove/replace attribute in inode body
573 + */
574 +int
575 +ext3_xattr_ibody_set(handle_t *handle, struct inode *inode, int name_index,
576 +                     const char *name, const void *value, size_t value_len,
577 +                     int flags)
578 +{
579 +       struct ext3_xattr_entry *last, *next, *here = NULL;
580 +       struct ext3_inode *raw_inode;
581 +       int name_len = strlen(name);
582 +       int esize = EXT3_XATTR_LEN(name_len);
583 +       struct buffer_head *bh;
584 +       int err, storage_size;
585 +       struct ext3_iloc iloc;
586 +       int free, min_offs;
587 +       char *start, *end;
588 +       
589 +       if (EXT3_SB(inode->i_sb)->s_inode_size <= EXT3_GOOD_OLD_INODE_SIZE)
590 +               return -ENOSPC;
591 +
592 +       err = ext3_get_inode_loc(inode, &iloc);
593 +       if (err)
594 +               return err;
595 +       raw_inode = iloc.raw_inode;
596 +       bh = iloc.bh;
597 +
598 +       storage_size = EXT3_SB(inode->i_sb)->s_inode_size -
599 +                               EXT3_GOOD_OLD_INODE_SIZE -
600 +                               EXT3_I(inode)->i_extra_isize -
601 +                               sizeof(__u32);
602 +       start = (char *) raw_inode + EXT3_GOOD_OLD_INODE_SIZE +
603 +                       EXT3_I(inode)->i_extra_isize;
604 +       if ((*(__u32*) start) != EXT3_XATTR_MAGIC) {
605 +               /* inode had no attributes before */
606 +               *((__u32*) start) = cpu_to_le32(EXT3_XATTR_MAGIC);
607 +       }
608 +       start += sizeof(__u32);
609 +       end = (char *) raw_inode + EXT3_SB(inode->i_sb)->s_inode_size;
610 +       min_offs = storage_size;
611 +       free = storage_size - sizeof(__u32);
612 +
613 +       last = (struct ext3_xattr_entry *) start;       
614 +       while (!IS_LAST_ENTRY(last)) {
615 +               next = EXT3_XATTR_NEXT(last);
616 +               if (le32_to_cpu(last->e_value_size) > storage_size ||
617 +                               (char *) next >= end) {
618 +                       ext3_error(inode->i_sb, "ext3_xattr_ibody_set",
619 +                               "inode %ld", inode->i_ino);
620 +                       brelse(bh);
621 +                       return -EIO;
622 +               }
623 +               
624 +               if (last->e_value_size) {
625 +                       int offs = le16_to_cpu(last->e_value_offs);
626 +                       if (offs < min_offs)
627 +                               min_offs = offs;
628 +               }
629 +               if (name_index == last->e_name_index &&
630 +                       name_len == last->e_name_len &&
631 +                       !memcmp(name, last->e_name, name_len))
632 +                       here = last;
633 +               else {
634 +                       /* we calculate all but our attribute
635 +                        * because it will be removed before changing */
636 +                       free -= EXT3_XATTR_LEN(last->e_name_len);
637 +                       free -= le32_to_cpu(last->e_value_size);
638 +               }
639 +               last = next;
640 +       }
641 +
642 +       if (value && (esize + value_len > free)) {
643 +               brelse(bh);
644 +               return -ENOSPC;
645 +       }
646 +       
647 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
648 +       if (err) {
649 +               brelse(bh);     
650 +               return err;
651 +       }
652 +
653 +       if (here) {
654 +               /* time to remove old value */
655 +               struct ext3_xattr_entry *e;
656 +               int size = le32_to_cpu(here->e_value_size);
657 +               int border = le16_to_cpu(here->e_value_offs);
658 +               char *src;
659 +
660 +               /* move tail */
661 +               memmove(start + min_offs + size, start + min_offs,
662 +                               border - min_offs);
663 +
664 +               /* recalculate offsets */
665 +               e = (struct ext3_xattr_entry *) start;
666 +               while (!IS_LAST_ENTRY(e)) {
667 +                       struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(e);
668 +                       int offs = le16_to_cpu(e->e_value_offs);
669 +                       if (offs < border)
670 +                               e->e_value_offs =
671 +                                       cpu_to_le16(offs + size);
672 +                       e = next;
673 +               }
674 +               min_offs += size;
675 +
676 +               /* remove entry */
677 +               border = EXT3_XATTR_LEN(here->e_name_len);
678 +               src = (char *) here + EXT3_XATTR_LEN(here->e_name_len);
679 +               size = (char *) last - src;
680 +               if ((char *) here + size > end)
681 +                       printk("ALERT at %s:%d: 0x%p + %d > 0x%p\n",
682 +                                       __FILE__, __LINE__, here, size, end);
683 +               memmove(here, src, size);
684 +               last = (struct ext3_xattr_entry *) ((char *) last - border);
685 +               *((__u32 *) last) = 0;
686 +       }
687 +       
688 +       if (value) {
689 +               int offs = min_offs - value_len;
690 +               /* use last to create new entry */
691 +               last->e_name_len = strlen(name);
692 +               last->e_name_index = name_index;
693 +               last->e_value_offs = cpu_to_le16(offs);
694 +               last->e_value_size = cpu_to_le32(value_len);
695 +               last->e_hash = last->e_value_block = 0;
696 +               memset(last->e_name, 0, esize);
697 +               memcpy(last->e_name, name, last->e_name_len);
698 +               if (start + offs + value_len > end)
699 +                       printk("ALERT at %s:%d: 0x%p + %d + %d > 0x%p\n",
700 +                                       __FILE__, __LINE__, start, offs,
701 +                                       value_len, end);
702 +               memcpy(start + offs, value, value_len);
703 +               last = EXT3_XATTR_NEXT(last);
704 +               *((__u32 *) last) = 0;
705 +       }
706 +       
707 +       ext3_mark_iloc_dirty(handle, inode, &iloc);
708 +       brelse(bh);
709 +
710 +       return 0;
711 +}
712 +
713 +/*
714   * ext3_xattr_set_trans()
715   *
716   * Like ext3_xattr_set_handle, but start from an inode. This extended
717 Index: linux-2.4.21-chaos/fs/ext3/super.c
718 ===================================================================
719 --- linux-2.4.21-chaos.orig/fs/ext3/super.c     2003-12-12 17:39:11.000000000 +0300
720 +++ linux-2.4.21-chaos/fs/ext3/super.c  2003-12-12 17:39:55.000000000 +0300
721 @@ -1354,8 +1354,10 @@
722         } else {
723                 sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
724                 sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
725 -               if (sbi->s_inode_size != EXT3_GOOD_OLD_INODE_SIZE) {
726 -                       printk (KERN_ERR
727 +               if ((sbi->s_inode_size < EXT3_GOOD_OLD_INODE_SIZE) ||
728 +                               (sbi->s_inode_size & (sbi->s_inode_size - 1)) ||
729 +                               (sbi->s_inode_size > blocksize)) {
730 +                       printk (KERN_ERR
731                                 "EXT3-fs: unsupported inode size: %d\n",
732                                 sbi->s_inode_size);
733                         goto failed_mount;
734 Index: linux-2.4.21-chaos/include/linux/ext3_fs.h
735 ===================================================================
736 --- linux-2.4.21-chaos.orig/include/linux/ext3_fs.h     2003-12-12 17:39:10.000000000 +0300
737 +++ linux-2.4.21-chaos/include/linux/ext3_fs.h  2003-12-12 17:39:55.000000000 +0300
738 @@ -268,6 +268,8 @@
739                         __u32   m_i_reserved2[2];
740                 } masix2;
741         } osd2;                         /* OS dependent 2 */
742 +       __u16   i_extra_isize;
743 +       __u16   i_pad1;
744  };
745  
746  #define i_size_high    i_dir_acl
747 Index: linux-2.4.21-chaos/include/linux/ext3_fs_i.h
748 ===================================================================
749 --- linux-2.4.21-chaos.orig/include/linux/ext3_fs_i.h   2003-12-05 16:54:33.000000000 +0300
750 +++ linux-2.4.21-chaos/include/linux/ext3_fs_i.h        2003-12-12 17:39:55.000000000 +0300
751 @@ -76,6 +76,9 @@
752          */
753         loff_t  i_disksize;
754  
755 +       /* on-disk additional length */
756 +       __u16 i_extra_isize;
757 +
758         /*
759          * truncate_sem is for serialising ext3_truncate() against
760          * ext3_getblock().  In the 2.4 ext2 design, great chunks of inode's