Changeset b73530a in mainline for uspace/lib/ext4/libext4_extent.c


Ignore:
Timestamp:
2012-04-08T14:01:49Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
82cb6768
Parents:
936132f
Message:

appending fblock to existing extent

  • actually not solved situation, when extent is full !!!
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/libext4_extent.c

    r936132f rb73530a  
    223223        int rc;
    224224
     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
    225238        block_t* block = NULL;
    226239
     
    549562        ext4_superblock_t *sb = inode_ref->fs->superblock;
    550563        uint64_t inode_size = ext4_inode_get_size(sb, inode_ref->inode);
    551 
    552564        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        }
    554573
    555574        ext4_extent_path_t *path;
     
    565584        }
    566585
    567         // if extent == NULL -> add extent to leaf
     586        // if extent == NULL -> add extent to empty leaf
    568587        if (path_ptr->extent == NULL) {
     588
     589                EXT4FS_DBG("NULL extent");
     590
    569591                ext4_extent_t *ext = EXT4_EXTENT_FIRST(path_ptr->header);
    570592                ext4_extent_set_block_count(ext, 0);
     
    579601        if (ext4_extent_get_block_count(path_ptr->extent) == 0) {
    580602
     603                EXT4FS_DBG("no blocks in extent");
     604
    581605                // Add first block to the extent
    582606
    583607                rc = ext4_balloc_alloc_block(inode_ref, &phys_block);
    584608                if (rc != EOK) {
     609                        EXT4FS_DBG("error in allocation");
    585610                        goto finish;
    586611                }
     
    588613                ext4_extent_set_block_count(path_ptr->extent, 1);
    589614                ext4_extent_set_start(path_ptr->extent, phys_block);
     615                ext4_extent_set_first_block(path_ptr->extent, new_block_idx);
    590616
    591617                path_ptr->block->dirty = true;
     
    594620
    595621        } 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
    598649                // TODO
    599650                assert(false);
    600 
    601651        }
    602652
Note: See TracChangeset for help on using the changeset viewer.