• Home
  • Raw
  • Download

Lines Matching refs:handle

162 void ext2fs_extent_free(ext2_extent_handle_t handle)  in ext2fs_extent_free()  argument
166 if (!handle) in ext2fs_extent_free()
169 if (handle->path) { in ext2fs_extent_free()
170 for (i=1; i <= handle->max_depth; i++) { in ext2fs_extent_free()
171 if (handle->path[i].buf) in ext2fs_extent_free()
172 ext2fs_free_mem(&handle->path[i].buf); in ext2fs_extent_free()
174 ext2fs_free_mem(&handle->path); in ext2fs_extent_free()
176 ext2fs_free_mem(&handle); in ext2fs_extent_free()
189 struct ext2_extent_handle *handle; in ext2fs_extent_open2() local
200 retval = ext2fs_get_mem(sizeof(struct ext2_extent_handle), &handle); in ext2fs_extent_open2()
203 memset(handle, 0, sizeof(struct ext2_extent_handle)); in ext2fs_extent_open2()
205 handle->ino = ino; in ext2fs_extent_open2()
206 handle->fs = fs; in ext2fs_extent_open2()
209 handle->inode = inode; in ext2fs_extent_open2()
211 handle->inode = &handle->inodebuf; in ext2fs_extent_open2()
212 retval = ext2fs_read_inode(fs, ino, handle->inode); in ext2fs_extent_open2()
217 eh = (struct ext3_extent_header *) &handle->inode->i_block[0]; in ext2fs_extent_open2()
220 if (handle->inode->i_block[i]) in ext2fs_extent_open2()
226 i = (sizeof(handle->inode->i_block) - sizeof(*eh)) / in ext2fs_extent_open2()
229 handle->inode->i_flags |= EXT4_EXTENTS_FL; in ext2fs_extent_open2()
232 if (!(handle->inode->i_flags & EXT4_EXTENTS_FL)) { in ext2fs_extent_open2()
237 retval = ext2fs_extent_header_verify(eh, sizeof(handle->inode->i_block)); in ext2fs_extent_open2()
241 handle->max_depth = ext2fs_le16_to_cpu(eh->eh_depth); in ext2fs_extent_open2()
242 handle->type = ext2fs_le16_to_cpu(eh->eh_magic); in ext2fs_extent_open2()
244 retval = ext2fs_get_mem(((handle->max_depth+1) * in ext2fs_extent_open2()
246 &handle->path); in ext2fs_extent_open2()
247 memset(handle->path, 0, in ext2fs_extent_open2()
248 (handle->max_depth+1) * sizeof(struct extent_path)); in ext2fs_extent_open2()
249 handle->path[0].buf = (char *) handle->inode->i_block; in ext2fs_extent_open2()
251 handle->path[0].left = handle->path[0].entries = in ext2fs_extent_open2()
253 handle->path[0].max_entries = ext2fs_le16_to_cpu(eh->eh_max); in ext2fs_extent_open2()
254 handle->path[0].curr = 0; in ext2fs_extent_open2()
255 handle->path[0].end_blk = in ext2fs_extent_open2()
256 (EXT2_I_SIZE(handle->inode) + fs->blocksize - 1) >> in ext2fs_extent_open2()
258 handle->path[0].visit_num = 1; in ext2fs_extent_open2()
259 handle->level = 0; in ext2fs_extent_open2()
260 handle->magic = EXT2_ET_MAGIC_EXTENT_HANDLE; in ext2fs_extent_open2()
262 *ret_handle = handle; in ext2fs_extent_open2()
266 ext2fs_extent_free(handle); in ext2fs_extent_open2()
274 errcode_t ext2fs_extent_get(ext2_extent_handle_t handle, in ext2fs_extent_get() argument
286 EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); in ext2fs_extent_get()
288 if (!handle->path) in ext2fs_extent_get()
294 path = handle->path + handle->level; in ext2fs_extent_get()
297 if (handle->level < handle->max_depth) { in ext2fs_extent_get()
304 else if (handle->level > 0) in ext2fs_extent_get()
312 else if (handle->level > 0) in ext2fs_extent_get()
328 if (handle->level < handle->max_depth) { in ext2fs_extent_get()
335 else if (handle->level > 0) in ext2fs_extent_get()
343 else if (handle->level > 0) in ext2fs_extent_get()
358 if ((handle->level < handle->max_depth) && in ext2fs_extent_get()
374 handle->level = 0; in ext2fs_extent_get()
375 path = handle->path + handle->level; in ext2fs_extent_get()
403 if (handle->level < handle->max_depth) in ext2fs_extent_get()
414 if (handle->level <= 0) in ext2fs_extent_get()
416 handle->level--; in ext2fs_extent_get()
425 if (!path->curr ||(handle->level >= handle->max_depth)) in ext2fs_extent_get()
431 retval = ext2fs_get_mem(handle->fs->blocksize, in ext2fs_extent_get()
438 if ((handle->fs->flags & EXT2_FLAG_IMAGE_FILE) && in ext2fs_extent_get()
439 (handle->fs->io != handle->fs->image_io)) in ext2fs_extent_get()
440 memset(newpath->buf, 0, handle->fs->blocksize); in ext2fs_extent_get()
442 retval = io_channel_read_blk64(handle->fs->io, in ext2fs_extent_get()
447 handle->level++; in ext2fs_extent_get()
451 retval = ext2fs_extent_header_verify(eh, handle->fs->blocksize); in ext2fs_extent_get()
453 handle->level--; in ext2fs_extent_get()
477 if (handle->level < handle->max_depth) in ext2fs_extent_get()
482 handle->level, handle->max_depth, in ext2fs_extent_get()
498 if (handle->level == handle->max_depth) { in ext2fs_extent_get()
527 (handle->level != handle->max_depth)) in ext2fs_extent_get()
531 ((handle->level != handle->max_depth) || in ext2fs_extent_get()
538 static errcode_t update_path(ext2_extent_handle_t handle) in update_path() argument
544 if (handle->level == 0) { in update_path()
545 retval = ext2fs_write_inode(handle->fs, handle->ino, in update_path()
546 handle->inode); in update_path()
548 ix = handle->path[handle->level - 1].curr; in update_path()
552 retval = io_channel_write_blk64(handle->fs->io, in update_path()
553 blk, 1, handle->path[handle->level].buf); in update_path()
559 errcode_t ext2fs_extent_save_path(ext2_extent_handle_t handle,
567 retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent);
571 retval = ext2fs_extent_get_info(handle, &info);
606 errcode_t ext2fs_extent_goto2(ext2_extent_handle_t handle, in ext2fs_extent_goto2() argument
612 retval = ext2fs_extent_get(handle, EXT2_EXTENT_ROOT, &extent); in ext2fs_extent_goto2()
619 if (leaf_level > handle->max_depth) { in ext2fs_extent_goto2()
622 leaf_level, handle->max_depth); in ext2fs_extent_goto2()
628 printf("goto extent ino %u, level %d, %llu\n", handle->ino, in ext2fs_extent_goto2()
636 if (handle->max_depth - handle->level == leaf_level) { in ext2fs_extent_goto2()
642 retval = ext2fs_extent_get(handle, in ext2fs_extent_goto2()
647 retval = ext2fs_extent_get(handle, in ext2fs_extent_goto2()
657 retval = ext2fs_extent_get(handle, EXT2_EXTENT_NEXT_SIB, in ext2fs_extent_goto2()
672 retval = ext2fs_extent_get(handle, EXT2_EXTENT_PREV_SIB, in ext2fs_extent_goto2()
682 retval = ext2fs_extent_get(handle, EXT2_EXTENT_DOWN, in ext2fs_extent_goto2()
693 errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle, in ext2fs_extent_goto() argument
696 return ext2fs_extent_goto2(handle, 0, blk); in ext2fs_extent_goto()
708 errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle) in ext2fs_extent_fix_parents() argument
717 EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); in ext2fs_extent_fix_parents()
719 if (!(handle->fs->flags & EXT2_FLAG_RW)) in ext2fs_extent_fix_parents()
722 if (!handle->path) in ext2fs_extent_fix_parents()
725 path = handle->path + handle->level; in ext2fs_extent_fix_parents()
729 retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); in ext2fs_extent_fix_parents()
736 if ((retval = ext2fs_extent_get_info(handle, &info))) in ext2fs_extent_fix_parents()
741 while (handle->level > 0 && in ext2fs_extent_fix_parents()
743 retval = ext2fs_extent_get(handle, EXT2_EXTENT_UP, &extent); in ext2fs_extent_fix_parents()
748 path = handle->path + handle->level; in ext2fs_extent_fix_parents()
751 retval = ext2fs_extent_replace(handle, 0, &extent); in ext2fs_extent_fix_parents()
754 update_path(handle); in ext2fs_extent_fix_parents()
758 retval = ext2fs_extent_goto2(handle, orig_height, start); in ext2fs_extent_fix_parents()
763 errcode_t ext2fs_extent_replace(ext2_extent_handle_t handle, in ext2fs_extent_replace() argument
771 EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); in ext2fs_extent_replace()
773 if (!(handle->fs->flags & EXT2_FLAG_RW)) in ext2fs_extent_replace()
776 if (!handle->path) in ext2fs_extent_replace()
779 path = handle->path + handle->level; in ext2fs_extent_replace()
784 printf("extent replace: %u ", handle->ino); in ext2fs_extent_replace()
788 if (handle->level == handle->max_depth) { in ext2fs_extent_replace()
812 update_path(handle); in ext2fs_extent_replace()
821 errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle) in ext2fs_extent_node_split() argument
838 EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); in ext2fs_extent_node_split()
840 if (!(handle->fs->flags & EXT2_FLAG_RW)) in ext2fs_extent_node_split()
843 if (!handle->path) in ext2fs_extent_node_split()
847 printf("splitting node at level %d\n", handle->level); in ext2fs_extent_node_split()
849 retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); in ext2fs_extent_node_split()
853 retval = ext2fs_extent_get_info(handle, &info); in ext2fs_extent_node_split()
862 if (handle->level && in ext2fs_extent_node_split()
863 (handle->path[handle->level - 1].entries >= in ext2fs_extent_node_split()
864 handle->path[handle->level - 1].max_entries)) { in ext2fs_extent_node_split()
868 handle->level - 1); in ext2fs_extent_node_split()
871 retval = ext2fs_extent_get(handle, EXT2_EXTENT_UP, &extent); in ext2fs_extent_node_split()
876 retval = ext2fs_extent_node_split(handle); in ext2fs_extent_node_split()
881 retval = ext2fs_extent_goto2(handle, orig_height, orig_lblk); in ext2fs_extent_node_split()
887 path = handle->path + handle->level; in ext2fs_extent_node_split()
895 if (handle->level == 0) { in ext2fs_extent_node_split()
898 retval = ext2fs_get_mem(((handle->max_depth+2) * in ext2fs_extent_node_split()
904 ((handle->max_depth+2) * sizeof(struct extent_path))); in ext2fs_extent_node_split()
912 handle->level); in ext2fs_extent_node_split()
924 block_buf = malloc(handle->fs->blocksize); in ext2fs_extent_node_split()
931 dgrp_t group = ext2fs_group_of_ino(handle->fs, handle->ino); in ext2fs_extent_node_split()
932 __u8 log_flex = handle->fs->super->s_log_groups_per_flex; in ext2fs_extent_node_split()
936 goal_blk = ext2fs_group_first_block2(handle->fs, group); in ext2fs_extent_node_split()
938 retval = ext2fs_alloc_block2(handle->fs, goal_blk, block_buf, in ext2fs_extent_node_split()
953 neweh->eh_max = ext2fs_cpu_to_le16((handle->fs->blocksize - in ext2fs_extent_node_split()
966 retval = io_channel_write_blk64(handle->fs->io, new_node_pblk, 1, in ext2fs_extent_node_split()
975 if (handle->level == 0) { in ext2fs_extent_node_split()
977 sizeof(struct extent_path) * (handle->max_depth+1)); in ext2fs_extent_node_split()
978 handle->path = newpath; in ext2fs_extent_node_split()
980 path = handle->path; in ext2fs_extent_node_split()
983 handle->max_depth++; in ext2fs_extent_node_split()
984 eh->eh_depth = ext2fs_cpu_to_le16(handle->max_depth); in ext2fs_extent_node_split()
992 retval = update_path(handle); in ext2fs_extent_node_split()
998 retval = ext2fs_extent_get(handle, EXT2_EXTENT_FIRST_SIB, &extent); in ext2fs_extent_node_split()
1004 extent.e_len = handle->path[0].end_blk - extent.e_lblk; in ext2fs_extent_node_split()
1005 retval = ext2fs_extent_replace(handle, 0, &extent); in ext2fs_extent_node_split()
1011 retval = ext2fs_extent_get(handle, EXT2_EXTENT_UP, &extent); in ext2fs_extent_node_split()
1015 retval = ext2fs_extent_replace(handle, 0, &extent); in ext2fs_extent_node_split()
1023 retval = ext2fs_extent_insert(handle, EXT2_EXTENT_INSERT_AFTER, &extent); in ext2fs_extent_node_split()
1029 retval = ext2fs_extent_goto2(handle, orig_height, orig_lblk); in ext2fs_extent_node_split()
1034 handle->inode->i_blocks += (handle->fs->blocksize * in ext2fs_extent_node_split()
1035 EXT2FS_CLUSTER_RATIO(handle->fs)) / 512; in ext2fs_extent_node_split()
1036 retval = ext2fs_write_inode(handle->fs, handle->ino, in ext2fs_extent_node_split()
1037 handle->inode); in ext2fs_extent_node_split()
1049 errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags, in ext2fs_extent_insert() argument
1057 EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); in ext2fs_extent_insert()
1059 if (!(handle->fs->flags & EXT2_FLAG_RW)) in ext2fs_extent_insert()
1062 if (!handle->path) in ext2fs_extent_insert()
1066 printf("extent insert: %u ", handle->ino); in ext2fs_extent_insert()
1070 path = handle->path + handle->level; in ext2fs_extent_insert()
1078 handle->level); in ext2fs_extent_insert()
1080 retval = ext2fs_extent_node_split(handle); in ext2fs_extent_insert()
1083 path = handle->path + handle->level; in ext2fs_extent_insert()
1108 retval = ext2fs_extent_replace(handle, 0, extent); in ext2fs_extent_insert()
1112 retval = update_path(handle); in ext2fs_extent_insert()
1119 ext2fs_extent_delete(handle, 0); in ext2fs_extent_insert()
1145 errcode_t ext2fs_extent_set_bmap(ext2_extent_handle_t handle, in ext2fs_extent_set_bmap() argument
1163 EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); in ext2fs_extent_set_bmap()
1167 handle->ino, logical, physical, flags); in ext2fs_extent_set_bmap()
1170 if (!(handle->fs->flags & EXT2_FLAG_RW)) in ext2fs_extent_set_bmap()
1173 if (!handle->path) in ext2fs_extent_set_bmap()
1176 path = handle->path + handle->level; in ext2fs_extent_set_bmap()
1194 if ((handle->max_depth == 0) && (path->entries == 0)) { in ext2fs_extent_set_bmap()
1195 retval = ext2fs_extent_insert(handle, 0, &newextent); in ext2fs_extent_set_bmap()
1200 if ((retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, in ext2fs_extent_set_bmap()
1206 if ((retval = ext2fs_extent_get_info(handle, &info))) in ext2fs_extent_set_bmap()
1212 retval = ext2fs_extent_goto(handle, logical); in ext2fs_extent_set_bmap()
1234 retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); in ext2fs_extent_set_bmap()
1239 retval = ext2fs_extent_get(handle, EXT2_EXTENT_NEXT_LEAF, &next_extent); in ext2fs_extent_set_bmap()
1251 retval = ext2fs_extent_goto(handle, logical); in ext2fs_extent_set_bmap()
1254 retval = ext2fs_extent_get(handle, EXT2_EXTENT_PREV_LEAF, &prev_extent); in ext2fs_extent_set_bmap()
1266 retval = ext2fs_extent_goto(handle, logical); in ext2fs_extent_set_bmap()
1288 retval = ext2fs_extent_replace(handle, 0, &extent); in ext2fs_extent_set_bmap()
1296 retval = ext2fs_extent_replace(handle, 0, &extent); in ext2fs_extent_set_bmap()
1302 retval = ext2fs_extent_get(handle, in ext2fs_extent_set_bmap()
1310 retval = ext2fs_extent_replace(handle, 0, &next_extent); in ext2fs_extent_set_bmap()
1312 retval = ext2fs_extent_insert(handle, 0, &newextent); in ext2fs_extent_set_bmap()
1314 retval = ext2fs_extent_insert(handle, in ext2fs_extent_set_bmap()
1318 retval = ext2fs_extent_fix_parents(handle); in ext2fs_extent_set_bmap()
1326 retval = ext2fs_extent_replace(handle, 0, &newextent); in ext2fs_extent_set_bmap()
1328 retval = ext2fs_extent_delete(handle, 0); in ext2fs_extent_set_bmap()
1331 ec = ext2fs_extent_fix_parents(handle); in ext2fs_extent_set_bmap()
1348 retval = ext2fs_extent_get(handle, in ext2fs_extent_set_bmap()
1355 retval = ext2fs_extent_replace(handle, 0, in ext2fs_extent_set_bmap()
1359 retval = ext2fs_extent_fix_parents(handle); in ext2fs_extent_set_bmap()
1363 retval = ext2fs_extent_insert(handle, in ext2fs_extent_set_bmap()
1368 retval = ext2fs_extent_get(handle, in ext2fs_extent_set_bmap()
1375 retval = ext2fs_extent_replace(handle, 0, &extent); in ext2fs_extent_set_bmap()
1390 retval = ext2fs_extent_get(handle, in ext2fs_extent_set_bmap()
1395 retval = ext2fs_extent_replace(handle, 0, in ext2fs_extent_set_bmap()
1398 retval = ext2fs_extent_insert(handle, in ext2fs_extent_set_bmap()
1402 retval = ext2fs_extent_get(handle, in ext2fs_extent_set_bmap()
1411 retval = ext2fs_extent_replace(handle, 0, &extent); in ext2fs_extent_set_bmap()
1414 retval = ext2fs_extent_fix_parents(handle); in ext2fs_extent_set_bmap()
1429 retval = ext2fs_extent_replace(handle, 0, &extent); in ext2fs_extent_set_bmap()
1435 retval = ext2fs_extent_insert(handle, in ext2fs_extent_set_bmap()
1444 retval = ext2fs_extent_insert(handle, in ext2fs_extent_set_bmap()
1452 if (orig_height > handle->max_depth) in ext2fs_extent_set_bmap()
1453 orig_height = handle->max_depth; /* In case we shortened the tree */ in ext2fs_extent_set_bmap()
1454 ext2fs_extent_goto2(handle, orig_height, orig_lblk); in ext2fs_extent_set_bmap()
1458 errcode_t ext2fs_extent_delete(ext2_extent_handle_t handle, int flags) in ext2fs_extent_delete() argument
1465 EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); in ext2fs_extent_delete()
1467 if (!(handle->fs->flags & EXT2_FLAG_RW)) in ext2fs_extent_delete()
1470 if (!handle->path) in ext2fs_extent_delete()
1477 retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, in ext2fs_extent_delete()
1480 printf("extent delete %u ", handle->ino); in ext2fs_extent_delete()
1486 path = handle->path + handle->level; in ext2fs_extent_delete()
1505 if (path->entries == 0 && handle->level) { in ext2fs_extent_delete()
1509 retval = ext2fs_extent_get(handle, EXT2_EXTENT_UP, in ext2fs_extent_delete()
1514 retval = ext2fs_extent_delete(handle, flags); in ext2fs_extent_delete()
1515 handle->inode->i_blocks -= in ext2fs_extent_delete()
1516 (handle->fs->blocksize * in ext2fs_extent_delete()
1517 EXT2FS_CLUSTER_RATIO(handle->fs)) / 512; in ext2fs_extent_delete()
1518 retval = ext2fs_write_inode(handle->fs, handle->ino, in ext2fs_extent_delete()
1519 handle->inode); in ext2fs_extent_delete()
1520 ext2fs_block_alloc_stats2(handle->fs, in ext2fs_extent_delete()
1526 if ((path->entries == 0) && (handle->level == 0)) in ext2fs_extent_delete()
1527 eh->eh_depth = handle->max_depth = 0; in ext2fs_extent_delete()
1528 retval = update_path(handle); in ext2fs_extent_delete()
1533 errcode_t ext2fs_extent_get_info(ext2_extent_handle_t handle, in ext2fs_extent_get_info() argument
1538 EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); in ext2fs_extent_get_info()
1542 path = handle->path + handle->level; in ext2fs_extent_get_info()
1555 info->curr_level = handle->level; in ext2fs_extent_get_info()
1556 info->max_depth = handle->max_depth; in ext2fs_extent_get_info()