Changeset d9bbe45 in mainline
- Timestamp:
- 2012-01-22T13:22:56Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fcae007
- Parents:
- b7e0260
- Location:
- uspace/lib/ext4
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_directory.c
rb7e0260 rd9bbe45 125 125 int rc; 126 126 127 uint64_t size; 128 aoff64_t current_block_idx; 129 aoff64_t next_block_idx; 130 uint32_t next_block_phys_idx; 131 uint32_t block_size; 132 133 size = ext4_inode_get_size(it->fs->superblock, it->inode_ref->inode); 127 uint64_t size = ext4_inode_get_size(it->fs->superblock, it->inode_ref->inode); 134 128 135 129 /* The iterator is not valid until we seek to the desired position */ … … 150 144 } 151 145 152 block_size = ext4_superblock_get_block_size(it->fs->superblock);153 current_block_idx = it->current_offset / block_size;154 next_block_idx = pos / block_size;146 uint32_t block_size = ext4_superblock_get_block_size(it->fs->superblock); 147 aoff64_t current_block_idx = it->current_offset / block_size; 148 aoff64_t next_block_idx = pos / block_size; 155 149 156 150 /* If we don't have a block or are moving accross block boundary, … … 166 160 } 167 161 162 uint32_t next_block_phys_idx; 168 163 rc = ext4_filesystem_get_inode_data_block_index(it->fs, 169 164 it->inode_ref->inode, next_block_idx, &next_block_phys_idx); … … 188 183 uint32_t block_size) 189 184 { 185 186 it->current = NULL; 187 190 188 uint32_t offset_in_block = it->current_offset % block_size; 191 192 it->current = NULL;193 189 194 190 /* Ensure proper alignment */ … … 439 435 { 440 436 int rc; 441 ext4_directory_iterator_t it;442 437 443 438 if (!ext4_inode_is_type(fs->superblock, parent->inode, … … 446 441 } 447 442 443 ext4_directory_iterator_t it; 448 444 rc = ext4_directory_iterator_init(&it, fs, parent, 0); 449 445 if (rc != EOK) { -
uspace/lib/ext4/libext4_directory_index.c
rb7e0260 rd9bbe45 130 130 ext4_superblock_t *sb, size_t name_len, const char *name) 131 131 { 132 uint32_t block_size, entry_space; 133 uint16_t limit; 134 ext4_directory_dx_root_t *root; 135 136 root = (ext4_directory_dx_root_t *)root_block->data; 132 133 ext4_directory_dx_root_t *root = (ext4_directory_dx_root_t *)root_block->data; 137 134 138 135 if (root->info.hash_version != EXT4_HASH_VERSION_TEA && … … 154 151 } 155 152 156 block_size = ext4_superblock_get_block_size(sb);157 158 entry_space = block_size;153 uint32_t block_size = ext4_superblock_get_block_size(sb); 154 155 uint32_t entry_space = block_size; 159 156 entry_space -= 2 * sizeof(ext4_directory_dx_dot_entry_t); 160 157 entry_space -= sizeof(ext4_directory_dx_root_info_t); 161 158 entry_space = entry_space / sizeof(ext4_directory_dx_entry_t); 162 159 163 limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)&root->entries);160 uint16_t limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)&root->entries); 164 161 if (limit != entry_space) { 165 162 return EXT4_ERR_BAD_DX_DIR; … … 187 184 { 188 185 int rc; 189 uint16_t count, limit, entry_space; 190 uint8_t indirect_level; 191 ext4_directory_dx_root_t *root; 186 187 ext4_directory_dx_block_t *tmp_dx_block = dx_blocks; 188 189 ext4_directory_dx_root_t *root = (ext4_directory_dx_root_t *)root_block->data; 190 ext4_directory_dx_entry_t *entries = (ext4_directory_dx_entry_t *)&root->entries; 191 192 uint16_t limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)entries); 193 uint8_t indirect_level = ext4_directory_dx_root_info_get_indirect_levels(&root->info); 194 195 block_t *tmp_block = root_block; 192 196 ext4_directory_dx_entry_t *p, *q, *m, *at; 193 ext4_directory_dx_entry_t *entries;194 block_t *tmp_block = root_block;195 uint32_t fblock, next_block;196 ext4_directory_dx_block_t *tmp_dx_block = dx_blocks;197 198 root = (ext4_directory_dx_root_t *)root_block->data;199 entries = (ext4_directory_dx_entry_t *)&root->entries;200 201 limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)entries);202 indirect_level = ext4_directory_dx_root_info_get_indirect_levels(&root->info);203 204 197 while (true) { 205 198 206 count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)entries);199 uint16_t count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)entries); 207 200 if ((count == 0) || (count > limit)) { 208 201 return EXT4_ERR_BAD_DX_DIR; … … 232 225 } 233 226 234 next_block = ext4_directory_dx_entry_get_block(at);227 uint32_t next_block = ext4_directory_dx_entry_get_block(at); 235 228 236 229 indirect_level--; 237 230 231 uint32_t fblock; 238 232 rc = ext4_filesystem_get_inode_data_block_index(fs, inode, next_block, &fblock); 239 233 if (rc != EOK) { … … 249 243 limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)entries); 250 244 251 entry_space = ext4_superblock_get_block_size(fs->superblock) - sizeof(ext4_directory_dx_dot_entry_t); 245 uint16_t entry_space = ext4_superblock_get_block_size(fs->superblock) 246 - sizeof(ext4_directory_dx_dot_entry_t); 252 247 entry_space = entry_space / sizeof(ext4_directory_dx_entry_t); 253 248 … … 266 261 267 262 268 static int ext4_dire xtory_dx_find_dir_entry(block_t *block,263 static int ext4_directory_dx_find_dir_entry(block_t *block, 269 264 ext4_superblock_t *sb, size_t name_len, const char *name, 270 265 ext4_directory_entry_ll_t **res_entry, aoff64_t *block_offset) 271 266 { 272 ext4_directory_entry_ll_t *dentry; 273 uint16_t dentry_len; 274 uint8_t *addr_limit; 267 275 268 aoff64_t offset = 0; 276 277 dentry = (ext4_directory_entry_ll_t *)block->data; 278 addr_limit = block->data + ext4_superblock_get_block_size(sb); 269 ext4_directory_entry_ll_t *dentry = (ext4_directory_entry_ll_t *)block->data; 270 uint8_t *addr_limit = block->data + ext4_superblock_get_block_size(sb); 279 271 280 272 while ((uint8_t *)dentry < addr_limit) { … … 297 289 298 290 // Goto next entry 299 dentry_len = ext4_directory_entry_ll_get_entry_length(dentry);291 uint16_t dentry_len = ext4_directory_entry_ll_get_entry_length(dentry); 300 292 301 293 if (dentry_len == 0) { … … 314 306 ext4_directory_dx_block_t *handle, ext4_directory_dx_block_t *handles) 315 307 { 316 ext4_directory_dx_block_t *p; 317 uint16_t count; 318 uint32_t num_handles; 319 uint32_t current_hash; 320 block_t *block; 321 uint32_t block_addr, block_idx; 322 int rc; 323 324 num_handles = 0; 325 p = handle; 308 int rc; 309 310 311 uint32_t num_handles = 0; 312 ext4_directory_dx_block_t *p = handle; 326 313 327 314 while (1) { 328 315 329 316 p->position++; 330 count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)p->entries);317 uint16_t count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)p->entries); 331 318 332 319 if (p->position < p->entries + count) { … … 342 329 } 343 330 344 current_hash = ext4_directory_dx_entry_get_hash(p->position);331 uint32_t current_hash = ext4_directory_dx_entry_get_hash(p->position); 345 332 346 333 if ((hash & 1) == 0) { … … 350 337 } 351 338 339 352 340 while (num_handles--) { 353 341 354 block_idx = ext4_directory_dx_entry_get_block(p->position); 342 uint32_t block_idx = ext4_directory_dx_entry_get_block(p->position); 343 uint32_t block_addr; 355 344 rc = ext4_filesystem_get_inode_data_block_index(fs, inode, block_idx, &block_addr); 356 345 if (rc != EOK) { … … 358 347 } 359 348 349 block_t *block; 360 350 rc = block_get(&block, fs->device, block_addr, BLOCK_FLAGS_NONE); 361 351 if (rc != EOK) { … … 379 369 { 380 370 int rc; 381 uint32_t root_block_addr, leaf_block_addr, leaf_block_idx;382 aoff64_t block_offset;383 block_t *root_block, *leaf_block;384 ext4_hash_info_t hinfo;385 ext4_directory_entry_ll_t *res_dentry;386 ext4_directory_dx_block_t dx_blocks[2], *dx_block;387 371 388 372 // get direct block 0 (index root) 373 uint32_t root_block_addr; 389 374 rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref->inode, 0, &root_block_addr); 390 375 if (rc != EOK) { … … 392 377 } 393 378 379 block_t *root_block; 394 380 rc = block_get(&root_block, fs->device, root_block_addr, BLOCK_FLAGS_NONE); 395 381 if (rc != EOK) { … … 398 384 } 399 385 386 ext4_hash_info_t hinfo; 400 387 rc = ext4_directory_hinfo_init(&hinfo, root_block, fs->superblock, len, name); 401 388 if (rc != EOK) { … … 404 391 } 405 392 393 ext4_directory_dx_block_t dx_blocks[2]; 394 ext4_directory_dx_block_t *dx_block; 406 395 rc = ext4_directory_dx_get_leaf(&hinfo, fs, inode_ref->inode, root_block, &dx_block, dx_blocks); 407 396 if (rc != EOK) { … … 410 399 } 411 400 401 412 402 do { 413 403 414 leaf_block_idx = ext4_directory_dx_entry_get_block(dx_block->position);415 404 uint32_t leaf_block_idx = ext4_directory_dx_entry_get_block(dx_block->position); 405 uint32_t leaf_block_addr; 416 406 rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref->inode, leaf_block_idx, &leaf_block_addr); 417 407 if (rc != EOK) { … … 419 409 } 420 410 411 block_t *leaf_block; 421 412 rc = block_get(&leaf_block, fs->device, leaf_block_addr, BLOCK_FLAGS_NONE); 422 413 if (rc != EOK) { … … 424 415 } 425 416 426 rc = ext4_dirextory_dx_find_dir_entry(leaf_block, fs->superblock, len, name, 417 aoff64_t block_offset; 418 ext4_directory_entry_ll_t *res_dentry; 419 rc = ext4_directory_dx_find_dir_entry(leaf_block, fs->superblock, len, name, 427 420 &res_dentry, &block_offset); 428 421 -
uspace/lib/ext4/libext4_filesystem.c
rb7e0260 rd9bbe45 44 44 { 45 45 int rc; 46 ext4_superblock_t *temp_superblock;47 size_t block_size;48 uint32_t block_ids_per_block;49 int i;50 46 51 47 fs->device = service_id; … … 58 54 59 55 /* Read superblock from device */ 56 ext4_superblock_t *temp_superblock; 60 57 rc = ext4_superblock_read_direct(fs->device, &temp_superblock); 61 58 if (rc != EOK) { … … 65 62 66 63 /* Read block size from superblock and check */ 67 block_size = ext4_superblock_get_block_size(temp_superblock);64 uint32_t block_size = ext4_superblock_get_block_size(temp_superblock); 68 65 if (block_size > EXT4_MAX_BLOCK_SIZE) { 69 66 block_fini(fs->device); … … 78 75 } 79 76 80 block_ids_per_block = block_size / sizeof(uint32_t);77 uint32_t block_ids_per_block = block_size / sizeof(uint32_t); 81 78 fs->inode_block_limits[0] = EXT4_INODE_DIRECT_BLOCK_COUNT; 82 79 fs->inode_blocks_per_level[0] = 1; 83 for (i = 1; i < 4; i++) {80 for (int i = 1; i < 4; i++) { 84 81 fs->inode_blocks_per_level[i] = fs->inode_blocks_per_level[i-1] * 85 82 block_ids_per_block; … … 97 94 { 98 95 int rc = EOK; 96 99 97 if (write_sb) { 100 98 rc = ext4_superblock_write_direct(fs->device, fs->superblock); … … 149 147 { 150 148 int rc; 151 aoff64_t block_id; 152 uint32_t descriptors_per_block; 153 size_t offset; 154 ext4_block_group_ref_t *newref; 155 156 newref = malloc(sizeof(ext4_block_group_ref_t)); 149 150 ext4_block_group_ref_t *newref = malloc(sizeof(ext4_block_group_ref_t)); 157 151 if (newref == NULL) { 158 152 return ENOMEM; 159 153 } 160 154 161 descriptors_per_block = ext4_superblock_get_block_size(fs->superblock)155 uint32_t descriptors_per_block = ext4_superblock_get_block_size(fs->superblock) 162 156 / ext4_superblock_get_desc_size(fs->superblock); 163 157 164 158 /* Block group descriptor table starts at the next block after superblock */ 165 block_id = ext4_superblock_get_first_data_block(fs->superblock) + 1;159 aoff64_t block_id = ext4_superblock_get_first_data_block(fs->superblock) + 1; 166 160 167 161 /* Find the block containing the descriptor we are looking for */ 168 162 block_id += bgid / descriptors_per_block; 169 offset = (bgid % descriptors_per_block) * ext4_superblock_get_desc_size(fs->superblock);163 uint32_t offset = (bgid % descriptors_per_block) * ext4_superblock_get_desc_size(fs->superblock); 170 164 171 165 rc = block_get(&newref->block, fs->device, block_id, 0); … … 201 195 { 202 196 int rc; 203 aoff64_t block_id; 204 uint32_t block_group; 205 uint32_t offset_in_group; 206 uint32_t byte_offset_in_group; 207 size_t offset_in_block; 208 uint32_t inodes_per_group; 209 uint32_t inode_table_start; 210 uint16_t inode_size; 211 uint32_t block_size; 212 ext4_block_group_ref_t *bg_ref; 213 ext4_inode_ref_t *newref; 214 215 newref = malloc(sizeof(ext4_inode_ref_t)); 197 198 ext4_inode_ref_t *newref = malloc(sizeof(ext4_inode_ref_t)); 216 199 if (newref == NULL) { 217 200 return ENOMEM; 218 201 } 219 202 220 inodes_per_group = ext4_superblock_get_inodes_per_group(fs->superblock); 203 uint32_t inodes_per_group = 204 ext4_superblock_get_inodes_per_group(fs->superblock); 221 205 222 206 /* inode numbers are 1-based, but it is simpler to work with 0-based … … 224 208 */ 225 209 index -= 1; 226 block_group = index / inodes_per_group; 227 offset_in_group = index % inodes_per_group; 228 210 uint32_t block_group = index / inodes_per_group; 211 uint32_t offset_in_group = index % inodes_per_group; 212 213 ext4_block_group_ref_t *bg_ref; 229 214 rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref); 230 215 if (rc != EOK) { … … 233 218 } 234 219 235 inode_table_start = ext4_block_group_get_inode_table_first_block(220 uint32_t inode_table_start = ext4_block_group_get_inode_table_first_block( 236 221 bg_ref->block_group, fs->superblock); 237 222 … … 242 227 } 243 228 244 inode_size = ext4_superblock_get_inode_size(fs->superblock); 245 block_size = ext4_superblock_get_block_size(fs->superblock); 246 247 byte_offset_in_group = offset_in_group * inode_size; 248 249 block_id = inode_table_start + (byte_offset_in_group / block_size); 250 offset_in_block = byte_offset_in_group % block_size; 251 229 uint16_t inode_size = ext4_superblock_get_inode_size(fs->superblock); 230 uint32_t block_size = ext4_superblock_get_block_size(fs->superblock); 231 uint32_t byte_offset_in_group = offset_in_group * inode_size; 232 233 aoff64_t block_id = inode_table_start + (byte_offset_in_group / block_size); 252 234 rc = block_get(&newref->block, fs->device, block_id, 0); 253 235 if (rc != EOK) { … … 256 238 } 257 239 240 uint32_t offset_in_block = byte_offset_in_group % block_size; 258 241 newref->inode = newref->block->data + offset_in_block; 259 242 /* we decremented index above, but need to store the original value … … 322 305 { 323 306 int rc; 307 324 308 // release all indirect blocks 325 309 326 uint32_t fblock;327 328 310 // 1) Single indirect 329 fblock = ext4_inode_get_indirect_block(inode_ref->inode, 0);311 uint32_t fblock = ext4_inode_get_indirect_block(inode_ref->inode, 0); 330 312 if (fblock != 0) { 331 313 rc = ext4_balloc_free_block(fs, inode_ref, fblock); … … 437 419 ext4_inode_ref_t *inode_ref, aoff64_t new_size) 438 420 { 439 aoff64_t old_size;440 aoff64_t size_diff;441 442 421 if (! ext4_inode_can_truncate(fs->superblock, inode_ref->inode)) { 443 422 // Unable to truncate … … 445 424 } 446 425 447 old_size = ext4_inode_get_size(fs->superblock, inode_ref->inode); 448 426 aoff64_t old_size = ext4_inode_get_size(fs->superblock, inode_ref->inode); 449 427 if (old_size == new_size) { 450 428 // Nothing to do 451 429 return EOK; 452 430 } 453 454 uint32_t block_size;455 uint32_t blocks_count, total_blocks;456 uint32_t i;457 458 block_size = ext4_superblock_get_block_size(fs->superblock);459 431 460 432 if (old_size < new_size) { … … 465 437 } 466 438 467 size_diff = old_size - new_size; 468 blocks_count = size_diff / block_size; 439 aoff64_t size_diff = old_size - new_size; 440 uint32_t block_size = ext4_superblock_get_block_size(fs->superblock); 441 uint32_t blocks_count = size_diff / block_size; 469 442 if (size_diff % block_size != 0) { 470 443 blocks_count++; 471 444 } 472 445 473 total_blocks = old_size / block_size;446 uint32_t total_blocks = old_size / block_size; 474 447 if (old_size % block_size != 0) { 475 448 total_blocks++; … … 477 450 478 451 // starting from 1 because of logical blocks are numbered from 0 479 for ( i = 1; i <= blocks_count; ++i) {452 for (uint32_t i = 1; i <= blocks_count; ++i) { 480 453 // TODO check retval 481 454 ext4_filesystem_release_inode_block(fs, inode_ref, total_blocks - i); … … 493 466 { 494 467 int rc; 495 uint32_t offset_in_block; 468 469 496 470 uint32_t current_block; 497 aoff64_t block_offset_in_level;498 int i;499 int level;500 block_t *block;501 471 502 472 /* Handle inode using extents */ … … 517 487 518 488 /* Determine the indirection level needed to get the desired block */ 519 level = -1;520 for (i = 1; i < 4; i++) {489 int level = -1; 490 for (int i = 1; i < 4; i++) { 521 491 if (iblock < fs->inode_block_limits[i]) { 522 492 level = i; … … 530 500 531 501 /* Compute offsets for the topmost level */ 532 block_offset_in_level = iblock - fs->inode_block_limits[level-1];502 aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1]; 533 503 current_block = ext4_inode_get_indirect_block(inode, level-1); 534 offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];504 uint32_t offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1]; 535 505 536 506 if (current_block == 0) { … … 538 508 return EOK; 539 509 } 510 511 block_t *block; 540 512 541 513 /* Navigate through other levels, until we find the block number … … 584 556 ext4_inode_ref_t *inode_ref, aoff64_t iblock, uint32_t fblock) 585 557 { 586 587 int rc; 588 uint32_t offset_in_block; 589 uint32_t current_block, new_block_addr; 590 uint32_t block_size; 591 aoff64_t block_offset_in_level; 592 int i; 593 int level; 594 block_t *block, *new_block; 558 int rc; 559 595 560 596 561 /* Handle inode using extents */ … … 609 574 610 575 /* Determine the indirection level needed to get the desired block */ 611 level = -1;612 for (i = 1; i < 4; i++) {576 int level = -1; 577 for (int i = 1; i < 4; i++) { 613 578 if (iblock < fs->inode_block_limits[i]) { 614 579 level = i; … … 621 586 } 622 587 623 block_size = ext4_superblock_get_block_size(fs->superblock); 588 589 590 uint32_t block_size = ext4_superblock_get_block_size(fs->superblock); 624 591 625 592 /* Compute offsets for the topmost level */ 626 block_offset_in_level = iblock - fs->inode_block_limits[level-1]; 627 current_block = ext4_inode_get_indirect_block(inode_ref->inode, level-1); 628 offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1]; 593 aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1]; 594 uint32_t current_block = ext4_inode_get_indirect_block(inode_ref->inode, level-1); 595 uint32_t offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1]; 596 597 uint32_t new_block_addr; 598 block_t *block, *new_block; 629 599 630 600 if (current_block == 0) { … … 634 604 EXT4FS_DBG("error in allocation"); 635 605 } 636 // EXT4FS_DBG("AAA: new addr \%u, level = \%u", new_block_addr, level);637 606 638 607 ext4_inode_set_indirect_block(inode_ref->inode, level - 1, new_block_addr); … … 677 646 EXT4FS_DBG("allocation error"); 678 647 } 679 // EXT4FS_DBG("BBB: new addr \%u, offset = \%u, level = \%u", new_block_addr, offset_in_block, level);680 648 681 649 rc = block_get(&new_block, fs->device, new_block_addr, BLOCK_FLAGS_NOREAD); … … 730 698 { 731 699 int rc; 700 701 702 /* TODO handle extents */ 703 704 732 705 uint32_t fblock; 733 int i;734 int level;735 aoff64_t block_offset_in_level;736 uint32_t current_block;737 uint32_t offset_in_block;738 block_t *block;739 706 ext4_inode_t *inode = inode_ref->inode; 740 741 /* TODO handle extents */742 743 707 744 708 /* Handle simple case when we are dealing with direct reference */ … … 756 720 757 721 /* Determine the indirection level needed to get the desired block */ 758 level = -1;759 for (i = 1; i < 4; i++) {722 int level = -1; 723 for (int i = 1; i < 4; i++) { 760 724 if (iblock < fs->inode_block_limits[i]) { 761 725 level = i; … … 769 733 770 734 /* Compute offsets for the topmost level */ 771 block_offset_in_level = iblock - fs->inode_block_limits[level-1];772 current_block = ext4_inode_get_indirect_block(inode, level-1);773 offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];735 aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1]; 736 uint32_t current_block = ext4_inode_get_indirect_block(inode, level-1); 737 uint32_t offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1]; 774 738 775 739 /* Navigate through other levels, until we find the block number 776 740 * or find null reference meaning we are dealing with sparse file 777 741 */ 742 block_t *block; 778 743 while (level > 0) { 779 744 rc = block_get(&block, fs->device, current_block, 0); -
uspace/lib/ext4/libext4_ialloc.c
rb7e0260 rd9bbe45 59 59 { 60 60 int rc; 61 61 62 uint32_t block_group = ext4_ialloc_get_bgid_of_inode( 62 fs->superblock, inode_ref->index);63 uint32_t index_in_group = ext4_ialloc_inode2index_in_group(64 63 fs->superblock, inode_ref->index); 65 64 … … 80 79 } 81 80 81 uint32_t index_in_group = ext4_ialloc_inode2index_in_group( 82 fs->superblock, inode_ref->index); 82 83 ext4_bitmap_free_bit(bitmap_block->data, index_in_group); 83 84 bitmap_block->dirty = true; -
uspace/lib/ext4/libext4_inode.c
rb7e0260 rd9bbe45 160 160 uint64_t ext4_inode_get_blocks_count(ext4_superblock_t *sb, ext4_inode_t *inode) 161 161 { 162 uint64_t count;163 164 162 if (ext4_superblock_has_feature_read_only(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) { 165 163 166 164 /* 48-bit field */ 167 count = ((uint64_t)uint16_t_le2host(inode->osd2.linux2.blocks_high)) << 32 |165 uint64_t count = ((uint64_t)uint16_t_le2host(inode->osd2.linux2.blocks_high)) << 32 | 168 166 uint32_t_le2host(inode->blocks_count_lo); 169 167 … … 283 281 uint32_t ext4_inode_get_extent_block(ext4_inode_t *inode, uint64_t idx, service_id_t service_id) 284 282 { 283 int rc; 284 285 block_t* block = NULL; 286 285 287 ext4_extent_header_t *header = ext4_inode_get_extent_header(inode); 286 ext4_extent_t *extent;287 ext4_extent_index_t *extent_index;288 289 uint32_t first_block;290 uint16_t block_count;291 uint64_t phys_block = 0;292 uint64_t child;293 294 int rc;295 block_t* block = NULL;296 297 288 while (ext4_extent_header_get_depth(header) != 0) { 298 289 299 ext ent_index = EXT4_EXTENT_FIRST_INDEX(header);290 ext4_extent_index_t *extent_index = EXT4_EXTENT_FIRST_INDEX(header); 300 291 301 292 for (uint16_t i = 0; i < ext4_extent_header_get_entries_count(header); ++i) { 302 if (idx >= ext4_extent_index_get_first_block(extent_index)) {303 304 child = ext4_extent_index_get_leaf(extent_index);293 if (idx >= ext4_extent_index_get_first_block(extent_index)) { 294 295 uint64_t child = ext4_extent_index_get_leaf(extent_index); 305 296 306 297 if (block != NULL) { … … 319 310 } 320 311 321 extent = EXT4_EXTENT_FIRST(header); 312 ext4_extent_t *extent = EXT4_EXTENT_FIRST(header); 313 uint64_t phys_block = 0; 322 314 323 315 for (uint16_t i = 0; i < ext4_extent_header_get_entries_count(header); ++i) { 324 316 325 first_block = ext4_extent_get_first_block(extent);326 block_count = ext4_extent_get_block_count(extent);317 uint32_t first_block = ext4_extent_get_first_block(extent); 318 uint16_t block_count = ext4_extent_get_block_count(extent); 327 319 328 320 if ((idx >= first_block) && (idx < first_block + block_count)) { 329 phys_block = ext4_extent_get_start(extent) + idx;330 phys_block -= ext4_extent_get_first_block(extent);331 332 // Memory leak prevention333 if (block != NULL) {334 block_put(block);335 }336 return phys_block;321 phys_block = ext4_extent_get_start(extent) + idx; 322 phys_block -= ext4_extent_get_first_block(extent); 323 324 // Memory leak prevention 325 if (block != NULL) { 326 block_put(block); 327 } 328 return phys_block; 337 329 } 338 330 // Go to the next extent -
uspace/lib/ext4/libext4_superblock.c
rb7e0260 rd9bbe45 437 437 ext4_superblock_t **superblock) 438 438 { 439 void *data;440 439 int rc; 441 440 442 data = malloc(EXT4_SUPERBLOCK_SIZE);441 void *data = malloc(EXT4_SUPERBLOCK_SIZE); 443 442 if (data == NULL) { 444 443 return ENOMEM; … … 463 462 int rc; 464 463 uint32_t phys_block_size; 465 uint64_t first_block;466 uint32_t block_count;467 464 468 465 rc = block_get_bsize(service_id, &phys_block_size); … … 472 469 } 473 470 474 first_block = EXT4_SUPERBLOCK_OFFSET / phys_block_size;475 block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;471 uint64_t first_block = EXT4_SUPERBLOCK_OFFSET / phys_block_size; 472 uint32_t block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size; 476 473 477 474 if (EXT4_SUPERBLOCK_SIZE % phys_block_size) {
Note:
See TracChangeset
for help on using the changeset viewer.