Changeset 7eb033ce in mainline for uspace/lib/ext4/libext4_extent.c
- Timestamp:
- 2012-04-12T03:03:36Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1fff583
- Parents:
- 81ee87cd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_extent.c
r81ee87cd r7eb033ce 559 559 uint32_t iblock) 560 560 { 561 EXT4FS_DBG(""); 561 562 int rc; 562 563 … … 568 569 // Trivial way - no splitting 569 570 if (entries < limit) { 571 EXT4FS_DBG("adding extent entry"); 572 570 573 ext4_extent_header_set_entries_count(path_ptr->header, entries + 1); 571 574 path_ptr->extent = EXT4_EXTENT_FIRST(path_ptr->header) + entries; … … 581 584 ext4_superblock_get_block_size(inode_ref->fs->superblock); 582 585 583 // Trivial tree - grow 586 // Trivial tree - grow (extents were in root node) 584 587 if (path_ptr == path) { 585 586 // EXT4FS_DBG("splitting extent root");587 588 588 589 uint32_t new_fblock; … … 592 593 return rc; 593 594 } 594 595 // EXT4FS_DBG("allocated new node \%u", new_fblock);596 595 597 596 block_t *block; … … 641 640 } 642 641 642 assert(false); 643 643 644 // start splitting 644 645 uint32_t fblock = 0; 645 646 path_ptr--;647 648 646 while (path_ptr > path) { 647 648 // TODO 649 649 650 650 rc = ext4_balloc_alloc_block(inode_ref, &fblock); … … 674 674 path_ptr->extent = EXT4_EXTENT_FIRST(path_ptr->header); 675 675 } 676 677 path_ptr--; 678 } 679 680 // If splitting reached root node 681 if (path_ptr == path) { 682 683 uint32_t new_fblock; 684 rc = ext4_balloc_alloc_block(inode_ref, &new_fblock); 685 if (rc != EOK) { 686 EXT4FS_DBG("error in block allocation"); 687 return rc; 688 } 689 690 block_t *block; 691 rc = block_get(&block, inode_ref->fs->device, 692 new_fblock, BLOCK_FLAGS_NOREAD); 693 if (rc != EOK) { 694 EXT4FS_DBG("error in block_get"); 695 return rc; 696 } 697 698 memset(block->data, 0, block_size); 699 700 // Move data from root to the new block 701 memcpy(block->data, inode_ref->inode->blocks, 702 EXT4_INODE_BLOCKS * sizeof(uint32_t)); 703 704 path_ptr++; 705 path_ptr->block = block; 706 path_ptr->header = (ext4_extent_header_t *)block->data; 707 path_ptr->depth = ext4_extent_header_get_depth(path_ptr->header); 708 path_ptr->index = NULL; 709 710 uint16_t entries = ext4_extent_header_get_entries_count(path_ptr->header); 711 path_ptr->extent = EXT4_EXTENT_FIRST(path_ptr->header) + entries; 712 ext4_extent_header_set_entries_count(path_ptr->header, entries + 1); 713 uint16_t limit = (block_size - sizeof(ext4_extent_header_t)) / 714 sizeof(ext4_extent_t); 715 ext4_extent_header_set_max_entries_count(path_ptr->header, limit); 716 717 // Modify root (in inode) 718 path->depth = 1; 719 path->extent = NULL; 720 path->index = EXT4_EXTENT_FIRST_INDEX(path->header); 721 722 ext4_extent_header_set_depth(path->header, path_ptr->depth + 1); 723 ext4_extent_header_set_entries_count(path->header, 1); 724 725 ext4_extent_index_set_first_block(path->index, 0); 726 ext4_extent_index_set_leaf(path->index, new_fblock); 727 728 path_ptr->block->dirty = true; 729 path->block->dirty = true; 730 731 *last_path_item = path_ptr; 732 733 return EOK; 676 734 } 677 735 … … 682 740 uint32_t *iblock, uint32_t *fblock) 683 741 { 742 EXT4FS_DBG(""); 684 743 int rc = EOK; 685 744 … … 726 785 rc = ext4_balloc_alloc_block(inode_ref, &phys_block); 727 786 if (rc != EOK) { 728 // TODO error, cleanup 729 assert(false); 787 goto finish; 730 788 } 731 789 … … 745 803 rc = ext4_balloc_try_alloc_block(inode_ref, phys_block, &free); 746 804 if (rc != EOK) { 747 // TODO error 748 assert(false); 805 goto finish; 749 806 } 750 807 751 808 if (! free) { 752 809 // target is not free 753 // EXT4FS_DBG("target not free, \%u", phys_block);754 810 goto append_extent; 755 811 } … … 763 819 } 764 820 } 765 766 assert(false);767 821 768 822 append_extent: … … 776 830 } 777 831 778 // EXT4FS_DBG("allocated \%u", phys_block);779 780 832 rc = ext4_extent_append_extent(inode_ref, path, &path_ptr, new_block_idx); 781 833 if (rc != EOK) { … … 794 846 *iblock = new_block_idx; 795 847 *fblock = phys_block; 796 797 // EXT4FS_DBG("iblock = \%u, fblock = \%u", new_block_idx, phys_block);798 848 799 849 // Put loaded blocks
Note:
See TracChangeset
for help on using the changeset viewer.