Changeset b73530a in mainline for uspace/lib/ext4/libext4_extent.c
- Timestamp:
- 2012-04-08T14:01:49Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 82cb6768
- Parents:
- 936132f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_extent.c
r936132f rb73530a 223 223 int rc; 224 224 225 uint64_t inode_size = ext4_inode_get_size( 226 inode_ref->fs->superblock, inode_ref->inode); 227 228 uint32_t block_size = ext4_superblock_get_block_size( 229 inode_ref->fs->superblock); 230 231 uint32_t last_idx = (inode_size - 1) / block_size; 232 233 if (iblock > last_idx) { 234 *fblock = 0; 235 return EOK; 236 } 237 225 238 block_t* block = NULL; 226 239 … … 549 562 ext4_superblock_t *sb = inode_ref->fs->superblock; 550 563 uint64_t inode_size = ext4_inode_get_size(sb, inode_ref->inode); 551 552 564 uint32_t block_size = ext4_superblock_get_block_size(sb); 553 uint32_t new_block_idx = inode_size / block_size; 565 566 uint32_t new_block_idx = 0; 567 if (inode_size > 0) { 568 if ((inode_size % block_size) != 0) { 569 inode_size += block_size - (inode_size % block_size); 570 } 571 new_block_idx = inode_size / block_size; 572 } 554 573 555 574 ext4_extent_path_t *path; … … 565 584 } 566 585 567 // if extent == NULL -> add extent to leaf586 // if extent == NULL -> add extent to empty leaf 568 587 if (path_ptr->extent == NULL) { 588 589 EXT4FS_DBG("NULL extent"); 590 569 591 ext4_extent_t *ext = EXT4_EXTENT_FIRST(path_ptr->header); 570 592 ext4_extent_set_block_count(ext, 0); … … 579 601 if (ext4_extent_get_block_count(path_ptr->extent) == 0) { 580 602 603 EXT4FS_DBG("no blocks in extent"); 604 581 605 // Add first block to the extent 582 606 583 607 rc = ext4_balloc_alloc_block(inode_ref, &phys_block); 584 608 if (rc != EOK) { 609 EXT4FS_DBG("error in allocation"); 585 610 goto finish; 586 611 } … … 588 613 ext4_extent_set_block_count(path_ptr->extent, 1); 589 614 ext4_extent_set_start(path_ptr->extent, phys_block); 615 ext4_extent_set_first_block(path_ptr->extent, new_block_idx); 590 616 591 617 path_ptr->block->dirty = true; … … 594 620 595 621 } else { 596 // try allocate scceeding extent block 597 622 // try allocate succeeding extent block 623 624 EXT4FS_DBG("existing extent"); 625 626 uint16_t blocks = ext4_extent_get_block_count(path_ptr->extent); 627 628 if (blocks < (1 << 15)) { 629 // there is place for more blocks 630 631 EXT4FS_DBG("appending block to existing extent"); 632 633 uint64_t last = ext4_extent_get_start(path_ptr->extent) + blocks - 1; 634 635 rc = ext4_balloc_try_alloc_block(inode_ref, last + 1); 636 if (rc == EOK) { 637 path_ptr->block->dirty = true; 638 ext4_extent_set_block_count(path_ptr->extent, blocks + 1); 639 phys_block = last + 1; 640 goto finish; 641 } 642 643 if (rc != EINVAL) { 644 goto finish; 645 } 646 } 647 648 // Add new extent 598 649 // TODO 599 650 assert(false); 600 601 651 } 602 652
Note:
See TracChangeset
for help on using the changeset viewer.