126
static void dump_path(const char *tag, struct ext2_extent_handle *handle,
127
struct extent_path *path)
129
struct extent_path *ppp = path;
130
printf("%s: level=%d\n", tag, handle->level);
133
printf("%s: path=%ld buf=%p entries=%d max_entries=%d left=%d "
134
"visit_num=%d flags=0x%x end_blk=%llu curr=%p(%ld)\n",
135
tag, (ppp - handle->path), ppp->buf, ppp->entries,
136
ppp->max_entries, ppp->left, ppp->visit_num, ppp->flags,
137
ppp->end_blk, ppp->curr, ppp->curr - (void *)ppp->buf);
139
dbg_show_header((struct ext3_extent_header *)ppp->buf);
142
dbg_show_index(ppp->curr);
144
dbg_show_extent(ppp->curr);
147
} while (ppp >= handle->path);
125
154
#define dbg_show_header(eh) do { } while (0)
126
155
#define dbg_show_index(ix) do { } while (0)
127
156
#define dbg_show_extent(ex) do { } while (0)
128
157
#define dbg_print_extent(desc, ex) do { } while (0)
158
#define dump_path(tag, handle, path) do { } while (0)
847
static int splitting_at_eof(struct ext2_extent_handle *handle,
848
struct extent_path *path)
850
struct extent_path *ppp = path;
851
dump_path(__func__, handle, path);
853
if (handle->level == 0)
860
} while (ppp >= handle->path);
818
866
* allocate a new block, move half the current node to it, and update parent
820
868
* handle will be left pointing at original record.
822
errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle)
870
static errcode_t extent_node_split(ext2_extent_handle_t handle,
824
873
errcode_t retval = 0;
825
874
blk64_t new_node_pblk;
890
940
return EXT2_ET_NO_CURRENT_NODE;
943
* Normally, we try to split a full node in half. This doesn't turn
944
* out so well if we're tacking extents on the end of the file because
945
* then we're stuck with a tree of half-full extent blocks. This of
946
* course doesn't apply to the root level.
948
no_balance = expand_allowed ? splitting_at_eof(handle, path) : 0;
892
950
/* extent header of the current node we'll split */
893
951
eh = (struct ext3_extent_header *)path->buf;
1034
1095
/* new node hooked in, so update inode block count (do this here?) */
1035
handle->inode->i_blocks += (handle->fs->blocksize *
1036
EXT2FS_CLUSTER_RATIO(handle->fs)) / 512;
1096
ext2fs_iblk_add_blocks(handle->fs, handle->inode, 1);
1037
1097
retval = ext2fs_write_inode(handle->fs, handle->ino,
1038
1098
handle->inode);
1110
errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle)
1112
return extent_node_split(handle, 0);
1050
1115
errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags,
1051
1116
struct ext2fs_extent *extent)
1078
1143
printf("node full (level %d) - splitting\n",
1079
1144
handle->level);
1081
retval = ext2fs_extent_node_split(handle);
1146
retval = extent_node_split(handle, 1);
1084
1149
path = handle->path + handle->level;