Changeset ce6de59 in mainline for uspace/lib/ext4/libext4_extent.c
- 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
- File:
-
- 1 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 * @}
Note:
See TracChangeset
for help on using the changeset viewer.