Changeset 81a7858 in mainline for uspace/lib/ext4/libext4_extent.c
- Timestamp:
- 2012-05-10T08:47:06Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f2eece1
- Parents:
- bed78cb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_extent.c
rbed78cb r81a7858 933 933 } 934 934 935 /** TODO comment 936 * 935 /** Append data block to the i-node. 936 * 937 * This function allocates data block, tries to append it 938 * to some existing extent or creates new extents. 939 * It includes possible extent tree modifications (splitting). 940 * 941 * @param inode_ref i-node to append block to 942 * @param iblock output logical number of newly allocated block 943 * @param fblock output physical block address of newly allocated block 944 * @return error code 937 945 */ 938 946 int ext4_extent_append_block(ext4_inode_ref_t *inode_ref, … … 968 976 } 969 977 970 // Add new extent to the node 978 // Add new extent to the node if not present 971 979 if (path_ptr->extent == NULL) { 972 980 goto append_extent; … … 979 987 if (block_count < block_limit) { 980 988 989 // There is space for new block in the extent 990 981 991 if (block_count == 0) { 992 993 // Existing extent is empty 982 994 983 995 rc = ext4_balloc_alloc_block(inode_ref, &phys_block); … … 986 998 } 987 999 1000 // Initialize extent 988 1001 ext4_extent_set_first_block(path_ptr->extent, new_block_idx); 989 1002 ext4_extent_set_start(path_ptr->extent, phys_block); 990 1003 ext4_extent_set_block_count(path_ptr->extent, 1); 991 1004 1005 // Update i-node 992 1006 ext4_inode_set_size(inode_ref->inode, inode_size + block_size); 993 1007 inode_ref->dirty = true; … … 998 1012 } else { 999 1013 1014 // Existing extent contains some blocks 1015 1000 1016 phys_block = ext4_extent_get_start(path_ptr->extent); 1001 1017 phys_block += ext4_extent_get_block_count(path_ptr->extent); 1002 1018 1019 // Check if the following block is free for allocation 1003 1020 bool free; 1004 1021 rc = ext4_balloc_try_alloc_block(inode_ref, phys_block, &free); … … 1008 1025 1009 1026 if (! free) { 1010 // target is not free 1027 // target is not free, new block must be appended to new extent 1011 1028 goto append_extent; 1012 1029 } 1013 1030 1014 1031 1032 // Update extent 1015 1033 ext4_extent_set_block_count(path_ptr->extent, block_count + 1); 1016 1034 1035 // Update i-node 1017 1036 ext4_inode_set_size(inode_ref->inode, inode_size + block_size); 1018 1037 inode_ref->dirty = true; … … 1024 1043 } 1025 1044 1045 // Append new extent to the tree 1026 1046 append_extent: 1027 1047 1028 1048 phys_block = 0; 1029 // Allocate and insert insert new block 1049 1050 // Allocate new data block 1030 1051 rc = ext4_balloc_alloc_block(inode_ref, &phys_block); 1031 1052 if (rc != EOK) { … … 1034 1055 } 1035 1056 1057 // Append extent for new block (includes tree splitting if needed) 1036 1058 rc = ext4_extent_append_extent(inode_ref, path, &path_ptr, new_block_idx); 1037 1059 if (rc != EOK) { … … 1040 1062 } 1041 1063 1064 // Initialize newly created extent 1042 1065 ext4_extent_set_block_count(path_ptr->extent, 1); 1043 1066 ext4_extent_set_first_block(path_ptr->extent, new_block_idx); 1044 1067 ext4_extent_set_start(path_ptr->extent, phys_block); 1045 1068 1069 // Update i-node 1046 1070 ext4_inode_set_size(inode_ref->inode, inode_size + block_size); 1047 1071 inode_ref->dirty = true; … … 1049 1073 path_ptr->block->dirty = true; 1050 1074 1075 1051 1076 finish: 1052 1077 // Set return values 1053 1078 *iblock = new_block_idx; 1054 1079 *fblock = phys_block;
Note:
See TracChangeset
for help on using the changeset viewer.