Changeset 6f10638 in mainline
- Timestamp:
- 2012-07-10T11:02:51Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a8435881
- Parents:
- 292c843
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_extent.c
r292c843 r6f10638 741 741 ext4_extent_path_t *path, uint32_t iblock) 742 742 { 743 744 743 int rc; 745 744 746 745 ext4_extent_path_t *path_ptr = path + path->depth; 747 748 uint16_t entries = ext4_extent_header_get_entries_count(path_ptr->header);749 uint16_t limit = ext4_extent_header_get_max_entries_count(path_ptr->header);750 746 751 747 uint32_t block_size = … … 755 751 while (path_ptr > path) { 756 752 757 entries = ext4_extent_header_get_entries_count(path_ptr->header);758 limit = ext4_extent_header_get_max_entries_count(path_ptr->header);753 uint16_t entries = ext4_extent_header_get_entries_count(path_ptr->header); 754 uint16_t limit = ext4_extent_header_get_max_entries_count(path_ptr->header); 759 755 760 756 if (entries == limit) { 761 762 EXT4FS_DBG("Full non-root node (\%s)", path_ptr->depth ? "index" : "extent");763 757 764 758 /* Full node - allocate block for new one */ … … 798 792 } 799 793 794 /* Initialize on-disk structure (header) */ 800 795 ext4_extent_header_set_entries_count(path_ptr->header, 1); 801 796 ext4_extent_header_set_max_entries_count(path_ptr->header, limit); 797 ext4_extent_header_set_magic(path_ptr->header, EXT4_EXTENT_MAGIC); 798 ext4_extent_header_set_depth(path_ptr->header, path_ptr->depth); 799 ext4_extent_header_set_generation(path_ptr->header, 0); 802 800 803 801 path_ptr->block->dirty = true; … … 807 805 808 806 } else { 809 810 // EXT4FS_DBG("Adding entry non-root node (\%s)", path_ptr->depth ? "index" : "extent");811 807 812 808 /* Node with free space */ … … 835 831 if (path_ptr == path) { 836 832 837 entries = ext4_extent_header_get_entries_count(path->header);838 limit = ext4_extent_header_get_max_entries_count(path->header);833 uint16_t entries = ext4_extent_header_get_entries_count(path->header); 834 uint16_t limit = ext4_extent_header_get_max_entries_count(path->header); 839 835 840 836 if (entries == limit) { 841 842 EXT4FS_DBG("Splitting root");843 837 844 838 uint32_t new_fblock; … … 864 858 EXT4_INODE_BLOCKS * sizeof(uint32_t)); 865 859 866 ext4_extent_header_t *dbg_header = block->data; 867 EXT4FS_DBG("old root: items = \%u, depth = \%u", ext4_extent_header_get_entries_count(dbg_header), ext4_extent_header_get_depth(dbg_header)); 868 869 if (ext4_extent_header_get_depth(dbg_header)) { 870 for (uint16_t x = 0; x < ext4_extent_header_get_entries_count(dbg_header); ++x) { 871 ext4_extent_index_t *iii = EXT4_EXTENT_FIRST_INDEX(dbg_header) + x; 872 EXT4FS_DBG("root item \%u, iblock = \%u, leaf = \%u", x, ext4_extent_index_get_first_block(iii), (uint32_t)ext4_extent_index_get_leaf(iii)); 873 } 874 } else { 875 for (uint16_t x = 0; x < ext4_extent_header_get_entries_count(dbg_header); ++x) { 876 ext4_extent_t *iii = EXT4_EXTENT_FIRST(dbg_header) + x; 877 EXT4FS_DBG("root item \%u, iblock = \%u, leaf = \%u, count = \%u", x, ext4_extent_get_first_block(iii), (uint32_t)ext4_extent_get_start(iii), ext4_extent_get_block_count(iii)); 878 } 879 } 860 // Data block initialized !!! 861 862 block_t *root_block = path->block; 863 uint16_t root_depth = path->depth; 864 ext4_extent_header_t *root_header = path->header; 880 865 881 866 /* Make space for tree growing */ 882 path_ptr = path + 1;883 size_t bytes = (path->depth + 1) * sizeof(ext4_extent_path_t);884 memmove(path_ptr, path, bytes); 885 886 /* Initialize new root metadata */ 887 path->block = path_ptr->block;888 path->header = path_ptr->header; 889 path->depth = path_ptr->depth + 1;890 path->extent = NULL; 891 path->index = EXT4_EXTENT_FIRST_INDEX(path->header);892 893 ext4_extent_header_set_entries_count(path->header, 1);894 ext4_extent_header_set_depth(path->header, path->depth);895 ext4_extent_index_set_first_block(path->index, 0); 896 ext4_extent_index_set_leaf(path->index, new_fblock);897 898 path->block->dirty = true;899 900 901 /* Switch storage for "old root"*/902 path_ptr->block = block;903 path_ptr->header = (ext4_extent_header_t *)block->data;904 905 /* Add new entry to the "old root"*/906 if ( path_ptr->depth) {867 ext4_extent_path_t *new_root = path; 868 ext4_extent_path_t *old_root = path + 1; 869 870 // size_t move_bytes = (path->depth + 1) * sizeof(ext4_extent_path_t); 871 // memmove(old_root, new_root, move_bytes); 872 // memcpy(old_root, new_root, move_bytes); 873 874 size_t nbytes = sizeof(ext4_extent_path_t) * (path->depth + 1); 875 876 ext4_extent_path_t *tmp_path = malloc(sizeof(ext4_extent_path_t) * (path->depth + 2)); 877 if (tmp_path == NULL) { 878 return ENOMEM; 879 } 880 881 memcpy(tmp_path, path, nbytes); 882 memset(path, 0, sizeof(ext4_extent_path_t)); 883 memcpy(path + 1, tmp_path, nbytes); 884 free(tmp_path); 885 886 /* Update old root structure */ 887 old_root->block = block; 888 old_root->header = (ext4_extent_header_t *)block->data; 889 890 /* Add new entry and update limit for entries */ 891 if (old_root->depth) { 907 892 limit = (block_size - sizeof(ext4_extent_header_t)) / 908 893 sizeof(ext4_extent_index_t); 909 path_ptr->index = EXT4_EXTENT_FIRST_INDEX(path_ptr->header) + entries;910 ext4_extent_index_set_first_block( path_ptr->index, iblock);911 ext4_extent_index_set_leaf( path_ptr->index, (path_ptr+ 1)->block->lba);912 path_ptr->extent = NULL;894 old_root->index = EXT4_EXTENT_FIRST_INDEX(old_root->header) + entries; 895 ext4_extent_index_set_first_block(old_root->index, iblock); 896 ext4_extent_index_set_leaf(old_root->index, (old_root + 1)->block->lba); 897 old_root->extent = NULL; 913 898 } else { 914 899 limit = (block_size - sizeof(ext4_extent_header_t)) / 915 900 sizeof(ext4_extent_t); 916 path_ptr->extent = EXT4_EXTENT_FIRST(path_ptr->header) + entries; 917 ext4_extent_set_first_block(path_ptr->extent, iblock); 918 path_ptr->index = NULL; 919 } 920 ext4_extent_header_set_entries_count(path_ptr->header, entries + 1); 921 ext4_extent_header_set_max_entries_count(path_ptr->header, limit); 922 923 path_ptr->block->dirty = true; 924 925 926 EXT4FS_DBG("new root: items = \%u, depth = \%u, tmp depth = \%u", ext4_extent_header_get_entries_count(path->header), ext4_extent_header_get_depth(path->header), path->depth); 927 928 for (uint16_t x = 0; x < ext4_extent_header_get_entries_count(path->header); ++x) { 929 ext4_extent_index_t *iii = EXT4_EXTENT_FIRST_INDEX(path->header) + x; 930 EXT4FS_DBG("root item \%u, iblock = \%u, leaf = \%u", x, ext4_extent_index_get_first_block(iii), (uint32_t)ext4_extent_index_get_leaf(iii)); 931 } 901 old_root->extent = EXT4_EXTENT_FIRST(old_root->header) + entries; 902 ext4_extent_set_first_block(old_root->extent, iblock); 903 old_root->index = NULL; 904 } 905 ext4_extent_header_set_entries_count(old_root->header, entries + 1); 906 ext4_extent_header_set_max_entries_count(old_root->header, limit); 907 908 old_root->block->dirty = true; 909 910 /* Re-initialize new root metadata */ 911 new_root->depth = root_depth + 1; 912 new_root->block = root_block; 913 new_root->header = root_header; 914 new_root->extent = NULL; 915 new_root->index = EXT4_EXTENT_FIRST_INDEX(new_root->header); 916 917 ext4_extent_header_set_depth(new_root->header, new_root->depth); 918 919 /* Create new entry in root */ 920 ext4_extent_header_set_entries_count(new_root->header, 1); 921 ext4_extent_index_set_first_block(new_root->index, 0); 922 ext4_extent_index_set_leaf(new_root->index, new_fblock); 923 924 new_root->block->dirty = true; 932 925 933 926 } else { 934 935 EXT4FS_DBG("Adding entry to root node");936 927 937 928 if (path->depth) { … … 948 939 } 949 940 } 950 951 941 952 942 return EOK; … … 1088 1078 path_ptr = path + tree_depth; 1089 1079 1090 assert(tree_depth == path->depth);1091 1092 1080 /* Initialize newly created extent */ 1093 1081 ext4_extent_set_block_count(path_ptr->extent, 1);
Note:
See TracChangeset
for help on using the changeset viewer.