1 Index: linux-2.6.9-full/include/linux/ext3_extents.h
2 ===================================================================
3 --- linux-2.6.9-full.orig/include/linux/ext3_extents.h 2007-03-23 15:57:00.000000000 +0300
4 +++ linux-2.6.9-full/include/linux/ext3_extents.h 2007-03-26 22:08:16.000000000 +0400
5 @@ -242,6 +242,8 @@ struct ext3_extent_tree_stats {
9 +extern int ext3_ext_search_left(struct ext3_extents_tree *, struct ext3_ext_path *, unsigned long *, unsigned long *);
10 +extern int ext3_ext_search_right(struct ext3_extents_tree *, struct ext3_ext_path *, unsigned long *, unsigned long *);
11 extern void ext3_init_tree_desc(struct ext3_extents_tree *, struct inode *);
12 extern int ext3_extent_tree_init(handle_t *, struct ext3_extents_tree *);
13 extern int ext3_ext_calc_credits_for_insert(struct ext3_extents_tree *, struct ext3_ext_path *);
14 Index: linux-2.6.9-full/fs/ext3/extents.c
15 ===================================================================
16 --- linux-2.6.9-full.orig/fs/ext3/extents.c 2007-03-23 15:57:00.000000000 +0300
17 +++ linux-2.6.9-full/fs/ext3/extents.c 2007-03-26 22:07:37.000000000 +0400
18 @@ -929,6 +929,150 @@ repeat:
22 + * search the closest allocated block to the left for *logical
23 + * and returns it at @logical + it's physical address at @phys
24 + * if *logical is the smallest allocated block, the function
25 + * returns 0 at @phys
26 + * return value contains 0 (success) or error code
29 +ext3_ext_search_left(struct ext3_extents_tree *tree, struct ext3_ext_path *path,
30 + unsigned long *logical, unsigned long *phys)
32 + struct ext3_extent_idx *ix;
33 + struct ext3_extent *ex;
36 + BUG_ON(path == NULL);
37 + depth = path->p_depth;
40 + if (depth == 0 && path->p_ext == NULL)
43 + /* usually extent in the path covers blocks smaller
44 + * then *logical, but it can be that extent is the
45 + * first one in the file */
47 + ex = path[depth].p_ext;
48 + if (*logical < ex->ee_block) {
49 + BUG_ON(EXT_FIRST_EXTENT(path[depth].p_hdr) != ex);
50 + while (--depth >= 0) {
51 + ix = path[depth].p_idx;
52 + BUG_ON(ix != EXT_FIRST_INDEX(path[depth].p_hdr));
57 + BUG_ON(*logical < ex->ee_block + ex->ee_len);
59 + *logical = ex->ee_block + ex->ee_len - 1;
60 + *phys = ex->ee_start + ex->ee_len - 1;
63 +EXPORT_SYMBOL(ext3_ext_search_left);
66 + * search the closest allocated block to the right for *logical
67 + * and returns it at @logical + it's physical address at @phys
68 + * if *logical is the smallest allocated block, the function
69 + * returns 0 at @phys
70 + * return value contains 0 (success) or error code
73 +ext3_ext_search_right(struct ext3_extents_tree *tree, struct ext3_ext_path *path,
74 + unsigned long *logical, unsigned long *phys)
76 + struct buffer_head *bh = NULL;
77 + struct ext3_extent_header *eh;
78 + struct ext3_extent_idx *ix;
79 + struct ext3_extent *ex;
80 + unsigned long block;
83 + BUG_ON(path == NULL);
84 + depth = path->p_depth;
87 + if (depth == 0 && path->p_ext == NULL)
90 + /* usually extent in the path covers blocks smaller
91 + * then *logical, but it can be that extent is the
92 + * first one in the file */
94 + ex = path[depth].p_ext;
95 + if (*logical < ex->ee_block) {
96 + BUG_ON(EXT_FIRST_EXTENT(path[depth].p_hdr) != ex);
97 + while (--depth >= 0) {
98 + ix = path[depth].p_idx;
99 + BUG_ON(ix != EXT_FIRST_INDEX(path[depth].p_hdr));
101 + *logical = ex->ee_block;
102 + *phys = ex->ee_start;
106 + BUG_ON(*logical < ex->ee_block + ex->ee_len);
108 + if (ex != EXT_LAST_EXTENT(path[depth].p_hdr)) {
109 + /* next allocated block in this leaf */
111 + *logical = ex->ee_block;
112 + *phys = ex->ee_start;
116 + /* go up and search for index to the right */
117 + while (--depth >= 0) {
118 + ix = path[depth].p_idx;
119 + if (ix != EXT_LAST_INDEX(path[depth].p_hdr))
124 + /* we've gone up to the root and
125 + * found no index to the right */
129 + /* we've found index to the right, let's
130 + * follow it and find the closest allocated
131 + * block to the right */
133 + block = ix->ei_leaf;
134 + while (++depth < path->p_depth) {
135 + bh = sb_bread(tree->inode->i_sb, block);
138 + eh = EXT_BLOCK_HDR(bh);
139 + if (ext3_ext_check_header(eh)) {
143 + ix = EXT_FIRST_INDEX(eh);
144 + block = ix->ei_leaf;
148 + bh = sb_bread(tree->inode->i_sb, block);
151 + eh = EXT_BLOCK_HDR(bh);
152 + if (ext3_ext_check_header(eh)) {
156 + ex = EXT_FIRST_EXTENT(eh);
157 + *logical = ex->ee_block;
158 + *phys = ex->ee_start;
163 +EXPORT_SYMBOL(ext3_ext_search_right);
166 * returns allocated block in subsequent extent or EXT_MAX_BLOCK
167 * NOTE: it consider block number from index entry as
168 * allocated block. thus, index entries have to be consistent