Changeset 06d85e5 in mainline for uspace/lib/ext4/libext4_ialloc.c
- Timestamp:
- 2012-06-18T11:09:34Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2616a75b
- Parents:
- 9a487cc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_ialloc.c
r9a487cc r06d85e5 94 94 ext4_superblock_t *sb = fs->superblock; 95 95 96 / / Compute index of block group and load it96 /* Compute index of block group and load it */ 97 97 uint32_t block_group = ext4_ialloc_get_bgid_of_inode(sb, index); 98 98 … … 103 103 } 104 104 105 / / Load i-node bitmap105 /* Load i-node bitmap */ 106 106 uint32_t bitmap_block_addr = ext4_block_group_get_inode_bitmap( 107 107 bg_ref->block_group, sb); … … 112 112 } 113 113 114 / / Free i-node in the bitmap114 /* Free i-node in the bitmap */ 115 115 uint32_t index_in_group = ext4_ialloc_inode2index_in_group(sb, index); 116 116 ext4_bitmap_free_bit(bitmap_block->data, index_in_group); 117 117 bitmap_block->dirty = true; 118 118 119 / / Put back the block with bitmap119 /* Put back the block with bitmap */ 120 120 rc = block_put(bitmap_block); 121 121 if (rc != EOK) { 122 / / Error in saving bitmap122 /* Error in saving bitmap */ 123 123 ext4_filesystem_put_block_group_ref(bg_ref); 124 124 return rc; 125 125 } 126 126 127 / / If released i-node is a directory, decrement used directories count127 /* If released i-node is a directory, decrement used directories count */ 128 128 if (is_dir) { 129 129 uint32_t bg_used_dirs = ext4_block_group_get_used_dirs_count( … … 134 134 } 135 135 136 / / Update block group free inodes count136 /* Update block group free inodes count */ 137 137 uint32_t free_inodes = ext4_block_group_get_free_inodes_count( 138 138 bg_ref->block_group, sb); … … 141 141 sb, free_inodes); 142 142 143 / / Set unused i-nodes count if supported143 /* Set unused i-nodes count if supported */ 144 144 if (ext4_block_group_has_flag(bg_ref->block_group, EXT4_BLOCK_GROUP_INODE_UNINIT)) { 145 145 uint32_t unused_inodes = ext4_block_group_get_itable_unused( … … 151 151 bg_ref->dirty = true; 152 152 153 / / Put back the modified block group153 /* Put back the modified block group */ 154 154 rc = ext4_filesystem_put_block_group_ref(bg_ref); 155 155 if (rc != EOK) { … … 157 157 } 158 158 159 / / Update superblock free inodes count159 /* Update superblock free inodes count */ 160 160 uint32_t sb_free_inodes = ext4_superblock_get_free_inodes_count(sb); 161 161 sb_free_inodes++; … … 185 185 uint32_t avg_free_inodes = sb_free_inodes / bg_count; 186 186 187 / / Try to find free i-node in all block groups187 /* Try to find free i-node in all block groups */ 188 188 while (bgid < bg_count) { 189 189 190 / / Load block group to check190 /* Load block group to check */ 191 191 ext4_block_group_ref_t *bg_ref; 192 192 rc = ext4_filesystem_get_block_group_ref(fs, bgid, &bg_ref); … … 197 197 ext4_block_group_t *bg = bg_ref->block_group; 198 198 199 / / Read necessary values for algorithm199 /* Read necessary values for algorithm */ 200 200 uint32_t free_blocks = ext4_block_group_get_free_blocks_count(bg, sb); 201 201 uint32_t free_inodes = ext4_block_group_get_free_inodes_count(bg, sb); 202 202 uint32_t used_dirs = ext4_block_group_get_used_dirs_count(bg, sb); 203 203 204 / / Check if this block group is good candidate for allocation204 /* Check if this block group is good candidate for allocation */ 205 205 if ((free_inodes >= avg_free_inodes) && (free_blocks > 0)) { 206 206 207 / / Load block with bitmap207 /* Load block with bitmap */ 208 208 uint32_t bitmap_block_addr = ext4_block_group_get_inode_bitmap( 209 209 bg_ref->block_group, sb); … … 216 216 } 217 217 218 / / Try to allocate i-node in the bitmap218 /* Try to allocate i-node in the bitmap */ 219 219 uint32_t inodes_in_group = ext4_superblock_get_inodes_in_group(sb, bgid); 220 220 uint32_t index_in_group; … … 222 222 bitmap_block->data, 0, &index_in_group, inodes_in_group); 223 223 224 / / Block group has not any free i-node224 /* Block group has not any free i-node */ 225 225 if (rc == ENOSPC) { 226 226 block_put(bitmap_block); … … 229 229 } 230 230 231 / / Free i-node found, save the bitmap231 /* Free i-node found, save the bitmap */ 232 232 bitmap_block->dirty = true; 233 233 … … 237 237 } 238 238 239 / / Modify filesystem counters239 /* Modify filesystem counters */ 240 240 free_inodes--; 241 241 ext4_block_group_set_free_inodes_count(bg, sb, free_inodes); 242 242 243 / / Decrement unused i-nodes counter if supported243 /* Decrement unused i-nodes counter if supported */ 244 244 if (ext4_block_group_has_flag(bg, EXT4_BLOCK_GROUP_INODE_UNINIT)) { 245 245 uint16_t unused_inodes = ext4_block_group_get_itable_unused(bg, sb); … … 248 248 } 249 249 250 / / Increment used directories counter250 /* Increment used directories counter */ 251 251 if (is_dir) { 252 252 used_dirs++; … … 254 254 } 255 255 256 / / Save modified block group256 /* Save modified block group */ 257 257 bg_ref->dirty = true; 258 258 … … 263 263 } 264 264 265 / / Update superblock265 /* Update superblock */ 266 266 sb_free_inodes--; 267 267 ext4_superblock_set_free_inodes_count(sb, sb_free_inodes); 268 268 269 / / Compute the absolute i-nodex number269 /* Compute the absolute i-nodex number */ 270 270 *index = ext4_ialloc_index_in_group2inode(sb, index_in_group, bgid); 271 271 … … 274 274 } 275 275 276 / / Block group not modified, put it and jump to the next block group276 /* Block group not modified, put it and jump to the next block group */ 277 277 ext4_filesystem_put_block_group_ref(bg_ref); 278 278 ++bgid;
Note:
See TracChangeset
for help on using the changeset viewer.