Changeset 8060341a in mainline
- Timestamp:
- 2012-05-15T13:27:43Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 15b794d
- Parents:
- f2eece1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_filesystem.c
rf2eece1 r8060341a 821 821 } 822 822 823 /** TODO comment 824 * 823 /** Set physical block address for the block logical address into the i-node. 824 * 825 * @param inode_ref i-node to set block address to 826 * @param iblock logical index of block 827 * @param fblock physical block address 828 * @return error code 825 829 */ 826 830 int ext4_filesystem_set_inode_data_block_index(ext4_inode_ref_t *inode_ref, … … 831 835 ext4_filesystem_t *fs = inode_ref->fs; 832 836 833 / * Handle inode using extents */837 // Handle inode using extents 834 838 if (ext4_superblock_has_feature_compatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) && 835 839 ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) { … … 838 842 } 839 843 840 / * Handle simple case when we are dealing with direct reference */844 // Handle simple case when we are dealing with direct reference 841 845 if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) { 842 846 ext4_inode_set_direct_block(inode_ref->inode, (uint32_t)iblock, fblock); … … 845 849 } 846 850 847 / * Determine the indirection level needed to get the desired block */851 // Determine the indirection level needed to get the desired block 848 852 int level = -1; 849 853 for (int i = 1; i < 4; i++) { … … 860 864 uint32_t block_size = ext4_superblock_get_block_size(fs->superblock); 861 865 862 / * Compute offsets for the topmost level */866 // Compute offsets for the topmost level 863 867 aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1]; 864 868 uint32_t current_block = ext4_inode_get_indirect_block(inode_ref->inode, level-1); … … 868 872 block_t *block, *new_block; 869 873 874 // Is needed to allocate indirect block on the i-node level 870 875 if (current_block == 0) { 876 877 // Allocate new indirect block 871 878 rc = ext4_balloc_alloc_block(inode_ref, &new_block_addr); 872 879 if (rc != EOK) { … … 874 881 } 875 882 883 // Update i-node 876 884 ext4_inode_set_indirect_block(inode_ref->inode, level - 1, new_block_addr); 877 878 885 inode_ref->dirty = true; 879 886 887 // Load newly allocated block 880 888 rc = block_get(&new_block, fs->device, new_block_addr, BLOCK_FLAGS_NOREAD); 881 889 if (rc != EOK) { … … 884 892 } 885 893 894 // Initialize new block 886 895 memset(new_block->data, 0, block_size); 887 896 new_block->dirty = true; 888 897 898 // Put back the allocated block 889 899 rc = block_put(new_block); 890 900 if (rc != EOK) { … … 908 918 909 919 if ((level > 1) && (current_block == 0)) { 920 921 // Allocate new block 910 922 rc = ext4_balloc_alloc_block(inode_ref, &new_block_addr); 911 923 if (rc != EOK) { … … 914 926 } 915 927 928 // Load newly allocated block 916 929 rc = block_get(&new_block, fs->device, new_block_addr, BLOCK_FLAGS_NOREAD); 917 930 if (rc != EOK) { … … 920 933 } 921 934 935 // Initialize allocated block 922 936 memset(new_block->data, 0, block_size); 923 937 new_block->dirty = true; … … 929 943 } 930 944 945 // Write block address to the parent 931 946 ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(new_block_addr); 932 947 block->dirty = true; … … 934 949 } 935 950 951 // Will be finished, write the fblock address 936 952 if (level == 1) { 937 953 ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(fblock); … … 961 977 } 962 978 963 /** TODO comment 964 * 979 /** Release data block from i-node 980 * 981 * @param inode_ref i-node to release block from 982 * @param iblock logical block to be released 983 * @return error code 965 984 */ 966 985 int ext4_filesystem_release_inode_block( … … 973 992 ext4_filesystem_t *fs = inode_ref->fs; 974 993 975 // EXTENTS are handled otherwise 994 // EXTENTS are handled otherwise = there is not support in this function 976 995 assert(! (ext4_superblock_has_feature_incompatible(fs->superblock, 977 996 EXT4_FEATURE_INCOMPAT_EXTENTS) && … … 980 999 ext4_inode_t *inode = inode_ref->inode; 981 1000 982 / * Handle simple case when we are dealing with direct reference */1001 // Handle simple case when we are dealing with direct reference 983 1002 if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) { 984 1003 fblock = ext4_inode_get_direct_block(inode, iblock); … … 993 1012 994 1013 995 / * Determine the indirection level needed to get the desired block */1014 // Determine the indirection level needed to get the desired block 996 1015 int level = -1; 997 1016 for (int i = 1; i < 4; i++) { … … 1006 1025 } 1007 1026 1008 / * Compute offsets for the topmost level */1027 // Compute offsets for the topmost level 1009 1028 aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1]; 1010 1029 uint32_t current_block = ext4_inode_get_indirect_block(inode, level-1); … … 1023 1042 current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]); 1024 1043 1025 // Set zero 1044 // Set zero if physical data block address found 1026 1045 if (level == 1) { 1027 1046 ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(0); … … 1053 1072 return EOK; 1054 1073 } 1074 1075 // Physical block is not referenced, it can be released 1055 1076 1056 1077 return ext4_balloc_free_block(inode_ref, fblock);
Note:
See TracChangeset
for help on using the changeset viewer.