Changeset a35b458 in mainline for uspace/lib/ext4/src/ialloc.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/src/ialloc.c
r3061bc1 ra35b458 100 100 { 101 101 ext4_superblock_t *sb = fs->superblock; 102 102 103 103 /* Compute index of block group and load it */ 104 104 uint32_t block_group = ext4_ialloc_get_bgid_of_inode(sb, index); 105 105 106 106 ext4_block_group_ref_t *bg_ref; 107 107 errno_t rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref); 108 108 if (rc != EOK) 109 109 return rc; 110 110 111 111 /* Load i-node bitmap */ 112 112 uint32_t bitmap_block_addr = ext4_block_group_get_inode_bitmap( … … 117 117 if (rc != EOK) 118 118 return rc; 119 119 120 120 /* Free i-node in the bitmap */ 121 121 uint32_t index_in_group = ext4_ialloc_inode2index_in_group(sb, index); 122 122 ext4_bitmap_free_bit(bitmap_block->data, index_in_group); 123 123 bitmap_block->dirty = true; 124 124 125 125 /* Put back the block with bitmap */ 126 126 rc = block_put(bitmap_block); … … 130 130 return rc; 131 131 } 132 132 133 133 /* If released i-node is a directory, decrement used directories count */ 134 134 if (is_dir) { … … 139 139 bg_used_dirs); 140 140 } 141 141 142 142 /* Update block group free inodes count */ 143 143 uint32_t free_inodes = ext4_block_group_get_free_inodes_count( … … 146 146 ext4_block_group_set_free_inodes_count(bg_ref->block_group, sb, 147 147 free_inodes); 148 148 149 149 bg_ref->dirty = true; 150 150 151 151 /* Put back the modified block group */ 152 152 rc = ext4_filesystem_put_block_group_ref(bg_ref); 153 153 if (rc != EOK) 154 154 return rc; 155 155 156 156 /* Update superblock free inodes count */ 157 157 uint32_t sb_free_inodes = … … 159 159 sb_free_inodes++; 160 160 ext4_superblock_set_free_inodes_count(sb, sb_free_inodes); 161 161 162 162 return EOK; 163 163 } … … 178 178 { 179 179 ext4_superblock_t *sb = fs->superblock; 180 180 181 181 uint32_t bgid = 0; 182 182 uint32_t bg_count = ext4_superblock_get_block_group_count(sb); 183 183 uint32_t sb_free_inodes = ext4_superblock_get_free_inodes_count(sb); 184 184 uint32_t avg_free_inodes = sb_free_inodes / bg_count; 185 185 186 186 /* Try to find free i-node in all block groups */ 187 187 while (bgid < bg_count) { … … 191 191 if (rc != EOK) 192 192 return rc; 193 193 194 194 ext4_block_group_t *bg = bg_ref->block_group; 195 195 196 196 /* Read necessary values for algorithm */ 197 197 uint32_t free_blocks = ext4_block_group_get_free_blocks_count(bg, sb); 198 198 uint32_t free_inodes = ext4_block_group_get_free_inodes_count(bg, sb); 199 199 uint32_t used_dirs = ext4_block_group_get_used_dirs_count(bg, sb); 200 200 201 201 /* 202 202 * Check if this block group is a good candidate … … 216 216 uint32_t bitmap_block_addr = ext4_block_group_get_inode_bitmap( 217 217 bg_ref->block_group, sb); 218 218 219 219 block_t *bitmap_block; 220 220 rc = block_get(&bitmap_block, fs->device, bitmap_block_addr, … … 224 224 return rc; 225 225 } 226 226 227 227 /* Try to allocate i-node in the bitmap */ 228 228 uint32_t inodes_in_group = ext4_superblock_get_inodes_in_group(sb, bgid); … … 230 230 rc = ext4_bitmap_find_free_bit_and_set(bitmap_block->data, 231 231 0, &index_in_group, inodes_in_group); 232 232 233 233 /* Block group has not any free i-node */ 234 234 if (rc == ENOSPC) { … … 246 246 continue; 247 247 } 248 248 249 249 /* Free i-node found, save the bitmap */ 250 250 bitmap_block->dirty = true; 251 251 252 252 rc = block_put(bitmap_block); 253 253 if (rc != EOK) { … … 255 255 return rc; 256 256 } 257 257 258 258 /* Modify filesystem counters */ 259 259 free_inodes--; 260 260 ext4_block_group_set_free_inodes_count(bg, sb, free_inodes); 261 261 262 262 /* Increment used directories counter */ 263 263 if (is_dir) { … … 265 265 ext4_block_group_set_used_dirs_count(bg, sb, used_dirs); 266 266 } 267 267 268 268 /* Decrease unused inodes count */ 269 269 if (ext4_block_group_has_flag(bg, … … 271 271 uint32_t unused = 272 272 ext4_block_group_get_itable_unused(bg, sb); 273 273 274 274 uint32_t inodes_in_group = 275 275 ext4_superblock_get_inodes_in_group(sb, bgid); 276 276 277 277 uint32_t free = inodes_in_group - unused; 278 278 279 279 if (index_in_group >= free) { 280 280 unused = inodes_in_group - (index_in_group + 1); … … 282 282 } 283 283 } 284 284 285 285 /* Save modified block group */ 286 286 bg_ref->dirty = true; 287 287 288 288 rc = ext4_filesystem_put_block_group_ref(bg_ref); 289 289 if (rc != EOK) 290 290 return rc; 291 291 292 292 /* Update superblock */ 293 293 sb_free_inodes--; 294 294 ext4_superblock_set_free_inodes_count(sb, sb_free_inodes); 295 295 296 296 /* Compute the absolute i-nodex number */ 297 297 *index = ext4_ialloc_index_in_group2inode(sb, index_in_group, bgid); 298 298 299 299 return EOK; 300 300 } 301 301 302 302 /* Block group not modified, put it and jump to the next block group */ 303 303 rc = ext4_filesystem_put_block_group_ref(bg_ref); … … 307 307 ++bgid; 308 308 } 309 309 310 310 return ENOSPC; 311 311 }
Note:
See TracChangeset
for help on using the changeset viewer.