Changeset d0d7afb in mainline for uspace/lib/ext4/libext4_directory_index.c
- Timestamp:
- 2012-03-01T19:56:31Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c30a015
- Parents:
- d8269dc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_directory_index.c
rd8269dc rd0d7afb 503 503 block_t *old_data_block, ext4_directory_dx_block_t *index_block, block_t **new_data_block) 504 504 { 505 int rc ;505 int rc = EOK; 506 506 507 507 uint32_t block_size = ext4_superblock_get_block_size(fs->superblock); … … 652 652 653 653 int ext4_directory_dx_add_entry(ext4_filesystem_t *fs, 654 ext4_inode_ref_t *parent, ext4_inode_ref_t *child, 655 size_t name_size, const char *name) 656 { 657 int rc ;654 ext4_inode_ref_t *parent, ext4_inode_ref_t *child, const char *name) 655 { 656 int rc = EOK; 657 int rc2; 658 658 659 659 // get direct block 0 (index root) … … 670 670 } 671 671 672 uint32_t name_len = strlen(name); 672 673 ext4_hash_info_t hinfo; 673 rc = ext4_directory_hinfo_init(&hinfo, root_block, fs->superblock, name_ size, name);674 rc = ext4_directory_hinfo_init(&hinfo, root_block, fs->superblock, name_len, name); 674 675 if (rc != EOK) { 675 676 block_put(root_block); … … 702 703 } 703 704 704 uint32_t block_size = ext4_superblock_get_block_size(fs->superblock); 705 uint16_t required_len = 8 + name_size + (4 - name_size % 4); 706 707 ext4_directory_entry_ll_t *de = target_block->data; 708 ext4_directory_entry_ll_t *stop = target_block->data + block_size; 709 710 while (de < stop) { 711 712 uint32_t de_inode = ext4_directory_entry_ll_get_inode(de); 713 uint16_t de_rec_len = ext4_directory_entry_ll_get_entry_length(de); 714 715 if ((de_inode == 0) && (de_rec_len >= required_len)) { 716 ext4_directory_write_entry(fs->superblock, de, de_rec_len, 717 child, name, name_size); 718 719 // TODO cleanup 720 target_block->dirty = true; 721 rc = block_put(target_block); 722 if (rc != EOK) { 723 return EXT4_ERR_BAD_DX_DIR; 724 } 725 return EOK; 726 } 727 728 if (de_inode != 0) { 729 uint16_t used_name_len = ext4_directory_entry_ll_get_name_length( 730 fs->superblock, de); 731 732 uint16_t used_space = 8 + used_name_len; 733 if ((used_name_len % 4) != 0) { 734 used_space += 4 - (used_name_len % 4); 735 } 736 uint16_t free_space = de_rec_len - used_space; 737 738 if (free_space >= required_len) { 739 740 // Cut tail of current entry 741 ext4_directory_entry_ll_set_entry_length(de, used_space); 742 ext4_directory_entry_ll_t *new_entry = (void *)de + used_space; 743 ext4_directory_write_entry(fs->superblock, new_entry, 744 free_space, child, name, name_size); 745 746 // TODO cleanup 747 target_block->dirty = true; 748 rc = block_put(target_block); 749 if (rc != EOK) { 750 return EXT4_ERR_BAD_DX_DIR; 751 } 752 return EOK; 753 754 } 755 756 } 757 758 de = (void *)de + de_rec_len; 705 rc = ext4_directory_try_insert_entry(fs->superblock, target_block, child, name, name_len); 706 if (rc == EOK) { 707 goto cleanup; 708 759 709 } 760 710 761 711 EXT4FS_DBG("no free space found"); 712 713 uint32_t block_size = ext4_superblock_get_block_size(fs->superblock); 762 714 763 715 ext4_directory_dx_entry_t *entries = ((ext4_directory_dx_node_t *) dx_block->block->data)->entries; … … 786 738 rc = ext4_directory_append_block(fs, parent, &new_fblock, &new_iblock); 787 739 if (rc != EOK) { 788 // TODO error740 goto cleanup; 789 741 } 790 742 … … 793 745 rc = block_get(&new_block, fs->device, new_fblock, BLOCK_FLAGS_NOREAD); 794 746 if (rc != EOK) { 795 // TODO error747 goto cleanup; 796 748 } 797 749 … … 873 825 } 874 826 875 // TODOWhere to save new entry827 // Where to save new entry 876 828 uint32_t new_block_hash = ext4_directory_dx_entry_get_hash(dx_block->position + 1); 877 829 if (hinfo.hash >= new_block_hash) { 878 de = new_block->data; 879 stop = new_block->data + block_size; 830 rc = ext4_directory_try_insert_entry(fs->superblock, new_block, child, name, name_len); 880 831 } else { 881 de = target_block->data; 882 stop = target_block->data + block_size; 883 } 884 885 while (de < stop) { 886 887 uint32_t de_inode = ext4_directory_entry_ll_get_inode(de); 888 uint16_t de_rec_len = ext4_directory_entry_ll_get_entry_length(de); 889 890 if ((de_inode == 0) && (de_rec_len >= required_len)) { 891 ext4_directory_write_entry(fs->superblock, de, de_rec_len, 892 child, name, name_size); 893 goto success; 894 } 895 896 if (de_inode != 0) { 897 uint16_t used_name_len = ext4_directory_entry_ll_get_name_length( 898 fs->superblock, de); 899 900 uint16_t used_space = 8 + used_name_len; 901 if ((used_name_len % 4) != 0) { 902 used_space += 4 - (used_name_len % 4); 903 } 904 uint16_t free_space = de_rec_len - used_space; 905 906 if (free_space >= required_len) { 907 908 // Cut tail of current entry 909 ext4_directory_entry_ll_set_entry_length(de, used_space); 910 ext4_directory_entry_ll_t *new_entry = (void *)de + used_space; 911 ext4_directory_write_entry(fs->superblock, new_entry, 912 free_space, child, name, name_size); 913 914 goto success; 915 } 916 917 } 918 919 de = (void *)de + de_rec_len; 920 } 921 922 success: 832 rc = ext4_directory_try_insert_entry(fs->superblock, target_block, child, name, name_len); 833 } 834 835 if (rc != EOK) { 836 goto terminate; 837 } 838 839 840 terminate: 841 rc = block_put(new_block); 842 if (rc != EOK) { 843 EXT4FS_DBG("error writing new block"); 844 } 845 846 847 cleanup: 848 849 rc2 = rc; 923 850 924 851 rc = block_put(target_block); 925 852 if (rc != EOK) { 926 EXT4FS_DBG("error writing target block"); 927 } 928 rc = block_put(new_block); 929 if (rc != EOK) { 930 EXT4FS_DBG("error writing new block"); 853 return rc; 931 854 } 932 855 … … 936 859 rc = block_put(dx_it->block); 937 860 if (rc != EOK) { 938 EXT4FS_DBG("error writing index block \%u", (uint32_t)dx_it->block->pba);861 return rc; 939 862 } 940 863 dx_it++; 941 864 } 942 865 943 return EOK;866 return rc2; 944 867 } 945 868
Note:
See TracChangeset
for help on using the changeset viewer.