Changeset ce6de59 in mainline
- Timestamp:
- 2012-04-07T14:41:19Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3b5c119
- Parents:
- 5b16912
- Location:
- uspace/lib/ext4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_extent.c
r5b16912 rce6de59 539 539 } 540 540 541 int ext4_extent_append_block(ext4_inode_ref_t *inode_ref, 542 uint32_t *iblock, uint32_t *fblock) 543 { 544 int rc; 545 546 ext4_superblock_t *sb = inode_ref->fs->superblock; 547 uint64_t inode_size = ext4_inode_get_size(sb, inode_ref->inode); 548 549 ext4_extent_header_t *header = 550 ext4_inode_get_extent_header(inode_ref->inode); 551 552 // Initialize if empty inode 553 if (inode_size == 0) { 554 ext4_extent_t *first = EXT4_EXTENT_FIRST(header); 555 ext4_extent_set_block_count(first, 0); 556 ext4_extent_set_first_block(first, 0); 557 ext4_extent_set_start(first, 0); 558 559 ext4_extent_header_set_depth(header, 0); 560 ext4_extent_header_set_entries_count(header, 1); 561 } 562 563 uint32_t block_size = ext4_superblock_get_block_size(sb); 564 uint32_t new_block_idx = inode_size / block_size; 565 566 ext4_extent_path_t *path; 567 rc = ext4_extent_find_extent(inode_ref, new_block_idx, &path); 568 if (rc != EOK) { 569 EXT4FS_DBG("find extent ERROR"); 570 return rc; 571 } 572 573 // Jump to last item of the path (extent) 574 ext4_extent_path_t *path_ptr = path; 575 while (path_ptr->depth != 0) { 576 path_ptr++; 577 } 578 579 // Check if extent exists 580 assert(path_ptr->extent != NULL); 581 582 uint32_t phys_block; 583 584 if (ext4_extent_get_block_count(path_ptr->extent) == 0) { 585 586 // Add first block to the extent 587 588 rc = ext4_balloc_alloc_block(inode_ref, &phys_block); 589 if (rc != EOK) { 590 EXT4FS_DBG("ERRO in balloc"); 591 return rc; 592 } 593 594 ext4_extent_set_block_count(path_ptr->extent, 1); 595 ext4_extent_set_start(path_ptr->extent, phys_block); 596 597 path_ptr->block->dirty = true; 598 599 goto finish; 600 601 } else { 602 // try allocate succeeding extent block 603 604 // TODO 605 assert(false); 606 607 } 608 609 610 finish: 611 // Put loaded blocks 612 // From 1 -> 0 is a block with inode data 613 for (uint16_t i = 1; i < path->depth; ++i) { 614 if (path[i].block) { 615 block_put(path[i].block); 616 } 617 } 618 619 // Destroy temporary data structure 620 free(path); 621 622 return EOK; 623 } 624 541 625 /** 542 626 * @} -
uspace/lib/ext4/libext4_extent.h
r5b16912 rce6de59 64 64 extern int ext4_extent_release_blocks_from(ext4_inode_ref_t *, uint32_t); 65 65 66 extern int ext4_extent_append_block(ext4_inode_ref_t *, uint32_t *, uint32_t *); 67 66 68 #endif 67 69 -
uspace/lib/ext4/libext4_filesystem.c
r5b16912 rce6de59 323 323 } 324 324 325 // TODO extents, dir_index etc...325 // TODO dir_index initialization 326 326 327 327 rc = ext4_filesystem_get_inode_ref(fs, index, inode_ref); … … 340 340 ext4_inode_set_mode(fs->superblock, inode, EXT4_INODE_MODE_FILE); 341 341 ext4_inode_set_links_count(inode, 0); 342 } 343 344 if (ext4_superblock_has_feature_incompatible( 345 fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS)) { 346 ext4_inode_set_flag(inode, EXT4_INODE_FLAG_EXTENTS); 342 347 } 343 348 … … 666 671 if (ext4_superblock_has_feature_compatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) && 667 672 ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) { 668 // TODO673 // not reachable !!! 669 674 return ENOTSUP; 670 675 } … … 802 807 ext4_filesystem_t *fs = inode_ref->fs; 803 808 804 // EXTENTS are handled 809 // EXTENTS are handled otherwise 805 810 assert(! (ext4_superblock_has_feature_incompatible(fs->superblock, 806 811 EXT4_FEATURE_INCOMPAT_EXTENTS) && … … 890 895 uint32_t *fblock, uint32_t *iblock) 891 896 { 892 893 // TODO append to extent 894 895 int rc; 897 int rc; 898 899 // Handle extents separately 900 if (ext4_superblock_has_feature_incompatible( 901 inode_ref->fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) && 902 ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) { 903 904 return ext4_extent_append_block(inode_ref, iblock, fblock); 905 906 } 896 907 897 908 ext4_superblock_t *sb = inode_ref->fs->superblock;
Note:
See TracChangeset
for help on using the changeset viewer.