Changeset 8eff2b0 in mainline
- Timestamp:
- 2012-07-15T10:22:13Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 249154b
- Parents:
- 80bd676
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_extent.c
r80bd676 r8eff2b0 826 826 827 827 assert(path_ptr == path); 828 // TODO condition is redundant here829 828 830 829 /* Should be the root split too? */ 831 if (path_ptr == path) { 832 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); 835 836 if (entries == limit) { 837 838 uint32_t new_fblock; 839 rc = ext4_balloc_alloc_block(inode_ref, &new_fblock); 840 if (rc != EOK) { 841 EXT4FS_DBG("error in block allocation"); 842 return rc; 843 } 844 845 block_t *block; 846 rc = block_get(&block, inode_ref->fs->device, 847 new_fblock, BLOCK_FLAGS_NOREAD); 848 if (rc != EOK) { 849 EXT4FS_DBG("error in block_get"); 850 return rc; 851 } 852 853 /* Initialize newly allocated block */ 854 memset(block->data, 0, block_size); 855 856 /* Move data from root to the new block */ 857 memcpy(block->data, inode_ref->inode->blocks, 858 EXT4_INODE_BLOCKS * sizeof(uint32_t)); 859 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; 865 866 /* Make space for tree growing */ 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) { 892 limit = (block_size - sizeof(ext4_extent_header_t)) / 893 sizeof(ext4_extent_index_t); 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; 898 } else { 899 limit = (block_size - sizeof(ext4_extent_header_t)) / 900 sizeof(ext4_extent_t); 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; 925 830 831 uint16_t entries = ext4_extent_header_get_entries_count(path->header); 832 uint16_t limit = ext4_extent_header_get_max_entries_count(path->header); 833 834 if (entries == limit) { 835 836 uint32_t new_fblock; 837 rc = ext4_balloc_alloc_block(inode_ref, &new_fblock); 838 if (rc != EOK) { 839 EXT4FS_DBG("error in block allocation"); 840 return rc; 841 } 842 843 block_t *block; 844 rc = block_get(&block, inode_ref->fs->device, 845 new_fblock, BLOCK_FLAGS_NOREAD); 846 if (rc != EOK) { 847 EXT4FS_DBG("error in block_get"); 848 return rc; 849 } 850 851 /* Initialize newly allocated block */ 852 memset(block->data, 0, block_size); 853 854 /* Move data from root to the new block */ 855 memcpy(block->data, inode_ref->inode->blocks, 856 EXT4_INODE_BLOCKS * sizeof(uint32_t)); 857 858 // Data block initialized !!! 859 860 block_t *root_block = path->block; 861 uint16_t root_depth = path->depth; 862 ext4_extent_header_t *root_header = path->header; 863 864 /* Make space for tree growing */ 865 ext4_extent_path_t *new_root = path; 866 ext4_extent_path_t *old_root = path + 1; 867 868 size_t nbytes = sizeof(ext4_extent_path_t) * (path->depth + 1); 869 memmove(old_root, new_root, nbytes); 870 memset(new_root, 0, sizeof(ext4_extent_path_t)); 871 872 /* Update old root structure */ 873 old_root->block = block; 874 old_root->header = (ext4_extent_header_t *)block->data; 875 876 /* Add new entry and update limit for entries */ 877 if (old_root->depth) { 878 limit = (block_size - sizeof(ext4_extent_header_t)) / 879 sizeof(ext4_extent_index_t); 880 old_root->index = EXT4_EXTENT_FIRST_INDEX(old_root->header) + entries; 881 ext4_extent_index_set_first_block(old_root->index, iblock); 882 ext4_extent_index_set_leaf(old_root->index, (old_root + 1)->block->lba); 883 old_root->extent = NULL; 926 884 } else { 927 928 if (path->depth) { 929 path->index = EXT4_EXTENT_FIRST_INDEX(path->header) + entries; 930 ext4_extent_index_set_first_block(path->index, iblock); 931 ext4_extent_index_set_leaf(path->index, (path + 1)->block->lba); 932 } else { 933 path->extent = EXT4_EXTENT_FIRST(path->header) + entries; 934 ext4_extent_set_first_block(path->extent, iblock); 935 } 936 937 ext4_extent_header_set_entries_count(path->header, entries + 1); 938 path->block->dirty = true; 939 } 885 limit = (block_size - sizeof(ext4_extent_header_t)) / 886 sizeof(ext4_extent_t); 887 old_root->extent = EXT4_EXTENT_FIRST(old_root->header) + entries; 888 ext4_extent_set_first_block(old_root->extent, iblock); 889 old_root->index = NULL; 890 } 891 ext4_extent_header_set_entries_count(old_root->header, entries + 1); 892 ext4_extent_header_set_max_entries_count(old_root->header, limit); 893 894 old_root->block->dirty = true; 895 896 /* Re-initialize new root metadata */ 897 new_root->depth = root_depth + 1; 898 new_root->block = root_block; 899 new_root->header = root_header; 900 new_root->extent = NULL; 901 new_root->index = EXT4_EXTENT_FIRST_INDEX(new_root->header); 902 903 ext4_extent_header_set_depth(new_root->header, new_root->depth); 904 905 /* Create new entry in root */ 906 ext4_extent_header_set_entries_count(new_root->header, 1); 907 ext4_extent_index_set_first_block(new_root->index, 0); 908 ext4_extent_index_set_leaf(new_root->index, new_fblock); 909 910 new_root->block->dirty = true; 911 912 } else { 913 914 if (path->depth) { 915 path->index = EXT4_EXTENT_FIRST_INDEX(path->header) + entries; 916 ext4_extent_index_set_first_block(path->index, iblock); 917 ext4_extent_index_set_leaf(path->index, (path + 1)->block->lba); 918 } else { 919 path->extent = EXT4_EXTENT_FIRST(path->header) + entries; 920 ext4_extent_set_first_block(path->extent, iblock); 921 } 922 923 ext4_extent_header_set_entries_count(path->header, entries + 1); 924 path->block->dirty = true; 940 925 } 941 926
Note:
See TracChangeset
for help on using the changeset viewer.