1 Index: linux-2.4.24/fs/ext3/extents-in-ea.c
2 ===================================================================
3 --- linux-2.4.24.orig/fs/ext3/extents-in-ea.c 2003-01-30 13:24:37.000000000 +0300
4 +++ linux-2.4.24/fs/ext3/extents-in-ea.c 2004-08-06 03:54:47.000000000 +0400
7 + * Copyright (C) 2003 Alex Tomas <alex@clusterfs.com>
9 + * This program is free software; you can redistribute it and/or modify
10 + * it under the terms of the GNU General Public License version 2 as
11 + * published by the Free Software Foundation.
13 + * This program is distributed in the hope that it will be useful,
14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 + * GNU General Public License for more details.
18 + * You should have received a copy of the GNU General Public Licens
19 + * along with this program; if not, write to the Free Software
20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-
23 +#include <linux/module.h>
24 +#include <linux/fs.h>
25 +#include <linux/time.h>
26 +#include <linux/ext3_jbd.h>
27 +#include <linux/jbd.h>
28 +#include <linux/smp_lock.h>
29 +#include <linux/highuid.h>
30 +#include <linux/pagemap.h>
31 +#include <linux/quotaops.h>
32 +#include <linux/string.h>
33 +#include <linux/ext3_extents.h>
34 +#include <linux/ext3_xattr.h>
35 +#include <linux/slab.h>
36 +#include <asm/uaccess.h>
38 +static int ext3_get_ea_write_access(handle_t *handle, void *buffer)
40 + struct buffer_head *bh = (struct buffer_head *) buffer;
41 + return ext3_journal_get_write_access(handle, bh);
44 +static int ext3_mark_ea_buffer_dirty(handle_t *handle, void *buffer)
46 + struct buffer_head *bh = (struct buffer_head *) buffer;
47 + ext3_journal_dirty_metadata(handle, bh);
51 +static struct ext3_extents_helpers ext3_ea_helpers = {
52 + .get_write_access = ext3_get_ea_write_access,
53 + .mark_buffer_dirty = ext3_mark_ea_buffer_dirty,
56 + .remove_extent = NULL,
57 + .remove_extent_credits = NULL,
60 +int ext3_init_tree_in_ea_desc(struct ext3_extents_tree *tree,
61 + struct inode *inode, int name_index,
64 + struct buffer_head *bh;
65 + int offset, err, size;
67 + err = ext3_xattr_get_ea_loc(inode, name_index, eaname,
68 + &bh, &offset, &size);
73 + EXT_ASSERT(size >= sizeof(struct ext3_extent_header)
74 + + sizeof(struct ext3_extent));
75 + tree->inode = inode;
76 + tree->root = (void *) bh->b_data + offset;
77 + tree->buffer_len = size;
78 + tree->buffer = (void *) bh;
79 + tree->ops = &ext3_ea_helpers;
80 + tree->cex = NULL; /* FIXME: add cache store later */
84 +void ext3_release_tree_in_ea_desc(struct ext3_extents_tree *tree)
86 + struct buffer_head *bh;
88 + bh = (struct buffer_head *) tree->buffer;
93 +int ext3_init_tree_in_ea(struct inode *inode, int name_index,
94 + const char *eaname, int size)
96 + struct ext3_extents_tree tree;
101 + root = kmalloc(size, GFP_USER);
104 + memset(root, 0, size);
106 + /* first, create ea to store root of the tree */
107 + handle = ext3_journal_start(inode, EXT3_ALLOC_NEEDED + 3);
108 + if (IS_ERR(handle))
109 + return PTR_ERR(handle);
110 + if ((err = ext3_xattr_set(handle, inode, name_index,
111 + eaname, root, size, 0)))
113 + if ((err = ext3_init_tree_in_ea_desc(&tree, inode, name_index, eaname)))
115 + err = ext3_extent_tree_init(handle, &tree);
116 + ext3_release_tree_in_ea_desc(&tree);
118 + ext3_journal_stop(handle, inode);
124 +ext3_ext_in_ea_new_extent(struct ext3_extents_tree *tree,
125 + struct ext3_ext_path *path,
126 + struct ext3_extent *newex, int exist)
128 + struct inode *inode = tree->inode;
131 + unsigned long tgen;
134 + return EXT_CONTINUE;
136 + tgen = EXT_GENERATION(tree);
137 + needed = ext3_ext_calc_credits_for_insert(tree, path);
138 + up_write(&EXT3_I(inode)->truncate_sem);
139 + handle = ext3_journal_start(tree->inode, needed + 10);
140 + if (IS_ERR(handle)) {
141 + down_write(&EXT3_I(inode)->truncate_sem);
142 + return PTR_ERR(handle);
145 + if (tgen != EXT_GENERATION(tree)) {
146 + /* the tree has changed. so path can be invalid at moment */
147 + ext3_journal_stop(handle, inode);
148 + down_write(&EXT3_I(inode)->truncate_sem);
152 + down_write(&EXT3_I(inode)->truncate_sem);
154 + /* insert new extent */
155 + newex->e_start = 0;
156 + err = ext3_ext_insert_extent(handle, tree, path, newex);
158 + ext3_journal_stop(handle, tree->inode);
163 +int ext3_ext_in_ea_alloc_space(struct inode *inode, int name_index,
164 + const char *eaname, unsigned long from,
167 + struct ext3_extents_tree tree;
170 + err = ext3_init_tree_in_ea_desc(&tree, inode, name_index, eaname);
172 + down_write(&EXT3_I(inode)->truncate_sem);
173 + err = ext3_ext_walk_space(&tree, from, num,
174 + ext3_ext_in_ea_new_extent);
175 + ext3_release_tree_in_ea_desc(&tree);
176 + up_write(&EXT3_I(inode)->truncate_sem);
181 +int ext3_ext_in_ea_remove_space(struct inode *inode, int name_index,
182 + const char *eaname, unsigned long from,
185 + struct ext3_extents_tree tree;
188 + err = ext3_init_tree_in_ea_desc(&tree, inode, name_index, eaname);
190 + err = ext3_ext_remove_space(&tree, from, num);
191 + ext3_release_tree_in_ea_desc(&tree);
196 +int ext3_ext_in_ea_presence(struct inode *inode, int name_index,
197 + const char *eaname, unsigned long block)
199 + struct ext3_extents_tree tree;
200 + struct ext3_ext_path *path;
201 + struct ext3_extent *ex;
204 + err = ext3_init_tree_in_ea_desc(&tree, inode, name_index, eaname);
208 + /* find extent for this block */
209 + path = ext3_ext_find_extent(&tree, block, NULL);
210 + if (IS_ERR(path)) {
211 + err = PTR_ERR(path);
215 + depth = EXT_DEPTH(&tree);
216 + ex = path[depth].p_ext;
218 + /* there is no extent yet */
222 + if (block >= ex->e_block && block < ex->e_block + ex->e_num)
225 + ext3_release_tree_in_ea_desc(&tree);
229 Index: linux-2.4.24/fs/ext3/Makefile
230 ===================================================================
231 --- linux-2.4.24.orig/fs/ext3/Makefile 2004-08-06 02:43:24.000000000 +0400
232 +++ linux-2.4.24/fs/ext3/Makefile 2004-08-06 03:52:43.000000000 +0400
236 export-objs += xattr.o
237 -obj-$(CONFIG_EXT3_FS_XATTR) += xattr.o
238 +obj-$(CONFIG_EXT3_FS_XATTR) += xattr.o extents-in-ea.o
239 obj-$(CONFIG_EXT3_FS_XATTR_USER) += xattr_user.o
241 include $(TOPDIR)/Rules.make
242 Index: linux-2.4.24/fs/ext3/xattr.c
243 ===================================================================
244 --- linux-2.4.24.orig/fs/ext3/xattr.c 2004-08-06 00:47:18.000000000 +0400
245 +++ linux-2.4.24/fs/ext3/xattr.c 2004-08-06 03:52:43.000000000 +0400
249 ext3_xattr_ibody_find(struct inode *inode, int name_index,
250 - const char *name, struct ext3_xattr_entry *rentry, int *free)
251 + const char *name, struct ext3_xattr_entry *rentry, int *free,
252 + struct buffer_head **bh, int *offset)
254 struct ext3_xattr_entry *last;
255 struct ext3_inode *raw_inode;
257 name_len == last->e_name_len &&
258 !memcmp(name, last->e_name, name_len)) {
259 memcpy(rentry, last, sizeof(struct ext3_xattr_entry));
262 + voff = start + le16_to_cpu(last->e_value_offs);
263 + *offset = voff - (void *) iloc.bh->b_data;
271 *free -= EXT3_XATTR_LEN(last->e_name_len);
275 ext3_xattr_block_find(struct inode *inode, int name_index, const char *name,
276 - struct ext3_xattr_entry *rentry, int *free)
277 + struct ext3_xattr_entry *rentry, int *free,
278 + struct buffer_head **tbh, int *offset)
280 struct buffer_head *bh = NULL;
281 struct ext3_xattr_entry *entry;
283 memcmp(name, entry->e_name, name_len) == 0) {
284 memcpy(rentry, entry, sizeof(struct ext3_xattr_entry));
287 + *offset = le16_to_cpu(entry->e_value_offs);
293 *free -= EXT3_XATTR_LEN(entry->e_name_len);
294 *free -= le32_to_cpu(entry->e_value_size);
295 @@ -1073,7 +1090,8 @@
298 /* try to find attribute in inode body */
299 - err = ext3_xattr_ibody_find(inode, name_index, name, &entry, &free1);
300 + err = ext3_xattr_ibody_find(inode, name_index, name,
301 + &entry, &free1, NULL, NULL);
303 /* found EA in inode */
305 @@ -1082,7 +1100,7 @@
306 /* there is no such attribute in inode body */
307 /* try to find attribute in dedicated block */
308 err = ext3_xattr_block_find(inode, name_index, name,
310 + &entry, &free2, NULL, NULL);
311 if (err != 0 && err != -ENOENT) {
312 /* not found EA in block */
314 @@ -1138,6 +1156,38 @@
318 +int ext3_xattr_get_ea_loc(struct inode *inode, int name_index,
319 + const char *name, struct buffer_head **bh,
320 + int *offset, int *size)
322 + int free1 = -1, free2 = -1, err, name_len;
323 + struct ext3_xattr_entry entry;
325 + ea_idebug(inode, "name=%d.%s", name_index, name);
329 + name_len = strlen(name);
330 + if (name_len > 255)
333 + down(&ext3_xattr_sem);
335 + /* try to find attribute in inode body */
336 + err = ext3_xattr_ibody_find(inode, name_index, name,
337 + &entry, &free1, bh, offset);
338 + if (err == -ENOENT) {
339 + /* there is no such attribute in inode body */
340 + /* try to find attribute in dedicated block */
341 + err = ext3_xattr_block_find(inode, name_index, name,
342 + &entry, &free2, bh, offset);
344 + if (err == 0 && size)
345 + *size = le32_to_cpu(entry.e_value_size);
346 + up(&ext3_xattr_sem);
351 * ext3_xattr_block_set()
353 Index: linux-2.4.24/include/linux/ext3_xattr.h
354 ===================================================================
355 --- linux-2.4.24.orig/include/linux/ext3_xattr.h 2004-08-06 00:47:18.000000000 +0400
356 +++ linux-2.4.24/include/linux/ext3_xattr.h 2004-08-06 03:52:43.000000000 +0400
358 extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
359 extern int ext3_xattr_list(struct inode *, char *, size_t);
360 extern int ext3_xattr_set(handle_t *handle, struct inode *, int, const char *, const void *, size_t, int);
361 +extern int ext3_xattr_get_ea_loc(struct inode *, int, const char *, struct buffer_head **, int *, int *);
363 extern void ext3_xattr_delete_inode(handle_t *, struct inode *);
364 extern void ext3_xattr_put_super(struct super_block *);