Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset d9bbe45 in mainline


Ignore:
Timestamp:
2012-01-22T13:22:56Z (8 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
master
Children:
fcae007
Parents:
b7e0260
Message:

Refafctorization - principle of locality in variables declaration

Location:
uspace/lib/ext4
Files:
6 edited

Legend:

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

    rb7e0260 rd9bbe45  
    125125        int rc;
    126126
    127         uint64_t size;
    128         aoff64_t current_block_idx;
    129         aoff64_t next_block_idx;
    130         uint32_t next_block_phys_idx;
    131         uint32_t block_size;
    132 
    133         size = ext4_inode_get_size(it->fs->superblock, it->inode_ref->inode);
     127        uint64_t size = ext4_inode_get_size(it->fs->superblock, it->inode_ref->inode);
    134128
    135129        /* The iterator is not valid until we seek to the desired position */
     
    150144        }
    151145
    152         block_size = ext4_superblock_get_block_size(it->fs->superblock);
    153         current_block_idx = it->current_offset / block_size;
    154         next_block_idx = pos / block_size;
     146        uint32_t block_size = ext4_superblock_get_block_size(it->fs->superblock);
     147        aoff64_t current_block_idx = it->current_offset / block_size;
     148        aoff64_t next_block_idx = pos / block_size;
    155149
    156150        /* If we don't have a block or are moving accross block boundary,
     
    166160                }
    167161
     162                uint32_t next_block_phys_idx;
    168163                rc = ext4_filesystem_get_inode_data_block_index(it->fs,
    169164                    it->inode_ref->inode, next_block_idx, &next_block_phys_idx);
     
    188183    uint32_t block_size)
    189184{
     185
     186        it->current = NULL;
     187
    190188        uint32_t offset_in_block = it->current_offset % block_size;
    191 
    192         it->current = NULL;
    193189
    194190        /* Ensure proper alignment */
     
    439435{
    440436        int rc;
    441         ext4_directory_iterator_t it;
    442437
    443438        if (!ext4_inode_is_type(fs->superblock, parent->inode,
     
    446441        }
    447442
     443        ext4_directory_iterator_t it;
    448444        rc = ext4_directory_iterator_init(&it, fs, parent, 0);
    449445        if (rc != EOK) {
  • uspace/lib/ext4/libext4_directory_index.c

    rb7e0260 rd9bbe45  
    130130                ext4_superblock_t *sb, size_t name_len, const char *name)
    131131{
    132         uint32_t block_size, entry_space;
    133         uint16_t limit;
    134         ext4_directory_dx_root_t *root;
    135 
    136         root = (ext4_directory_dx_root_t *)root_block->data;
     132
     133        ext4_directory_dx_root_t *root = (ext4_directory_dx_root_t *)root_block->data;
    137134
    138135        if (root->info.hash_version != EXT4_HASH_VERSION_TEA &&
     
    154151        }
    155152
    156         block_size = ext4_superblock_get_block_size(sb);
    157 
    158         entry_space = block_size;
     153        uint32_t block_size = ext4_superblock_get_block_size(sb);
     154
     155        uint32_t entry_space = block_size;
    159156        entry_space -= 2 * sizeof(ext4_directory_dx_dot_entry_t);
    160157        entry_space -= sizeof(ext4_directory_dx_root_info_t);
    161158    entry_space = entry_space / sizeof(ext4_directory_dx_entry_t);
    162159
    163     limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)&root->entries);
     160    uint16_t limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)&root->entries);
    164161    if (limit != entry_space) {
    165162        return EXT4_ERR_BAD_DX_DIR;
     
    187184{
    188185        int rc;
    189         uint16_t count, limit, entry_space;
    190         uint8_t indirect_level;
    191         ext4_directory_dx_root_t *root;
     186
     187        ext4_directory_dx_block_t *tmp_dx_block = dx_blocks;
     188
     189        ext4_directory_dx_root_t *root = (ext4_directory_dx_root_t *)root_block->data;
     190        ext4_directory_dx_entry_t *entries = (ext4_directory_dx_entry_t *)&root->entries;
     191
     192        uint16_t limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)entries);
     193        uint8_t indirect_level = ext4_directory_dx_root_info_get_indirect_levels(&root->info);
     194
     195        block_t *tmp_block = root_block;
    192196        ext4_directory_dx_entry_t *p, *q, *m, *at;
    193         ext4_directory_dx_entry_t *entries;
    194         block_t *tmp_block = root_block;
    195         uint32_t fblock, next_block;
    196         ext4_directory_dx_block_t *tmp_dx_block = dx_blocks;
    197 
    198         root = (ext4_directory_dx_root_t *)root_block->data;
    199         entries = (ext4_directory_dx_entry_t *)&root->entries;
    200 
    201         limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)entries);
    202         indirect_level = ext4_directory_dx_root_info_get_indirect_levels(&root->info);
    203 
    204197        while (true) {
    205198
    206                 count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)entries);
     199                uint16_t count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)entries);
    207200                if ((count == 0) || (count > limit)) {
    208201                        return EXT4_ERR_BAD_DX_DIR;
     
    232225        }
    233226
    234                 next_block = ext4_directory_dx_entry_get_block(at);
     227                uint32_t next_block = ext4_directory_dx_entry_get_block(at);
    235228
    236229        indirect_level--;
    237230
     231        uint32_t fblock;
    238232        rc = ext4_filesystem_get_inode_data_block_index(fs, inode, next_block, &fblock);
    239233        if (rc != EOK) {
     
    249243                limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)entries);
    250244
    251         entry_space = ext4_superblock_get_block_size(fs->superblock) - sizeof(ext4_directory_dx_dot_entry_t);
     245        uint16_t entry_space = ext4_superblock_get_block_size(fs->superblock)
     246                        - sizeof(ext4_directory_dx_dot_entry_t);
    252247        entry_space = entry_space / sizeof(ext4_directory_dx_entry_t);
    253248
     
    266261
    267262
    268 static int ext4_dirextory_dx_find_dir_entry(block_t *block,
     263static int ext4_directory_dx_find_dir_entry(block_t *block,
    269264                ext4_superblock_t *sb, size_t name_len, const char *name,
    270265                ext4_directory_entry_ll_t **res_entry, aoff64_t *block_offset)
    271266{
    272         ext4_directory_entry_ll_t *dentry;
    273         uint16_t dentry_len;
    274         uint8_t *addr_limit;
     267
    275268        aoff64_t offset = 0;
    276 
    277         dentry = (ext4_directory_entry_ll_t *)block->data;
    278         addr_limit = block->data + ext4_superblock_get_block_size(sb);
     269        ext4_directory_entry_ll_t *dentry = (ext4_directory_entry_ll_t *)block->data;
     270        uint8_t *addr_limit = block->data + ext4_superblock_get_block_size(sb);
    279271
    280272        while ((uint8_t *)dentry < addr_limit) {
     
    297289
    298290                // Goto next entry
    299                 dentry_len = ext4_directory_entry_ll_get_entry_length(dentry);
     291                uint16_t dentry_len = ext4_directory_entry_ll_get_entry_length(dentry);
    300292
    301293        if (dentry_len == 0) {
     
    314306                ext4_directory_dx_block_t *handle, ext4_directory_dx_block_t *handles)
    315307{
    316         ext4_directory_dx_block_t *p;
    317         uint16_t count;
    318         uint32_t num_handles;
    319         uint32_t current_hash;
    320         block_t *block;
    321         uint32_t block_addr, block_idx;
    322     int rc;
    323 
    324     num_handles = 0;
    325     p = handle;
     308        int rc;
     309
     310
     311    uint32_t num_handles = 0;
     312    ext4_directory_dx_block_t *p = handle;
    326313
    327314    while (1) {
    328315
    329316        p->position++;
    330         count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)p->entries);
     317        uint16_t count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)p->entries);
    331318
    332319        if (p->position < p->entries + count) {
     
    342329    }
    343330
    344     current_hash = ext4_directory_dx_entry_get_hash(p->position);
     331    uint32_t current_hash = ext4_directory_dx_entry_get_hash(p->position);
    345332
    346333    if ((hash & 1) == 0) {
     
    350337    }
    351338
     339
    352340    while (num_handles--) {
    353341
    354         block_idx = ext4_directory_dx_entry_get_block(p->position);
     342        uint32_t block_idx = ext4_directory_dx_entry_get_block(p->position);
     343        uint32_t block_addr;
    355344        rc = ext4_filesystem_get_inode_data_block_index(fs, inode, block_idx, &block_addr);
    356345        if (rc != EOK) {
     
    358347        }
    359348
     349        block_t *block;
    360350        rc = block_get(&block, fs->device, block_addr, BLOCK_FLAGS_NONE);
    361351        if (rc != EOK) {
     
    379369{
    380370        int rc;
    381         uint32_t root_block_addr, leaf_block_addr, leaf_block_idx;
    382         aoff64_t block_offset;
    383         block_t *root_block, *leaf_block;
    384         ext4_hash_info_t hinfo;
    385         ext4_directory_entry_ll_t *res_dentry;
    386         ext4_directory_dx_block_t dx_blocks[2], *dx_block;
    387371
    388372        // get direct block 0 (index root)
     373        uint32_t root_block_addr;
    389374        rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref->inode, 0, &root_block_addr);
    390375        if (rc != EOK) {
     
    392377        }
    393378
     379        block_t *root_block;
    394380        rc = block_get(&root_block, fs->device, root_block_addr, BLOCK_FLAGS_NONE);
    395381        if (rc != EOK) {
     
    398384        }
    399385
     386        ext4_hash_info_t hinfo;
    400387        rc = ext4_directory_hinfo_init(&hinfo, root_block, fs->superblock, len, name);
    401388        if (rc != EOK) {
     
    404391        }
    405392
     393        ext4_directory_dx_block_t dx_blocks[2];
     394        ext4_directory_dx_block_t *dx_block;
    406395        rc = ext4_directory_dx_get_leaf(&hinfo, fs, inode_ref->inode, root_block, &dx_block, dx_blocks);
    407396        if (rc != EOK) {
     
    410399        }
    411400
     401
    412402        do {
    413403
    414                 leaf_block_idx = ext4_directory_dx_entry_get_block(dx_block->position);
    415 
     404                uint32_t leaf_block_idx = ext4_directory_dx_entry_get_block(dx_block->position);
     405                uint32_t leaf_block_addr;
    416406        rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref->inode, leaf_block_idx, &leaf_block_addr);
    417407        if (rc != EOK) {
     
    419409        }
    420410
     411        block_t *leaf_block;
    421412                rc = block_get(&leaf_block, fs->device, leaf_block_addr, BLOCK_FLAGS_NONE);
    422413                if (rc != EOK) {
     
    424415                }
    425416
    426                 rc = ext4_dirextory_dx_find_dir_entry(leaf_block, fs->superblock, len, name,
     417                aoff64_t block_offset;
     418                ext4_directory_entry_ll_t *res_dentry;
     419                rc = ext4_directory_dx_find_dir_entry(leaf_block, fs->superblock, len, name,
    427420                                &res_dentry, &block_offset);
    428421
  • uspace/lib/ext4/libext4_filesystem.c

    rb7e0260 rd9bbe45  
    4444{
    4545        int rc;
    46         ext4_superblock_t *temp_superblock;
    47         size_t block_size;
    48         uint32_t block_ids_per_block;
    49         int i;
    5046
    5147        fs->device = service_id;
     
    5854
    5955        /* Read superblock from device */
     56        ext4_superblock_t *temp_superblock;
    6057        rc = ext4_superblock_read_direct(fs->device, &temp_superblock);
    6158        if (rc != EOK) {
     
    6562
    6663        /* Read block size from superblock and check */
    67         block_size = ext4_superblock_get_block_size(temp_superblock);
     64        uint32_t block_size = ext4_superblock_get_block_size(temp_superblock);
    6865        if (block_size > EXT4_MAX_BLOCK_SIZE) {
    6966                block_fini(fs->device);
     
    7875        }
    7976
    80         block_ids_per_block = block_size / sizeof(uint32_t);
     77        uint32_t block_ids_per_block = block_size / sizeof(uint32_t);
    8178        fs->inode_block_limits[0] = EXT4_INODE_DIRECT_BLOCK_COUNT;
    8279        fs->inode_blocks_per_level[0] = 1;
    83         for (i = 1; i < 4; i++) {
     80        for (int i = 1; i < 4; i++) {
    8481                fs->inode_blocks_per_level[i] = fs->inode_blocks_per_level[i-1] *
    8582                    block_ids_per_block;
     
    9794{
    9895        int rc = EOK;
     96
    9997        if (write_sb) {
    10098                rc = ext4_superblock_write_direct(fs->device, fs->superblock);
     
    149147{
    150148        int rc;
    151         aoff64_t block_id;
    152         uint32_t descriptors_per_block;
    153         size_t offset;
    154         ext4_block_group_ref_t *newref;
    155 
    156         newref = malloc(sizeof(ext4_block_group_ref_t));
     149
     150        ext4_block_group_ref_t *newref = malloc(sizeof(ext4_block_group_ref_t));
    157151        if (newref == NULL) {
    158152                return ENOMEM;
    159153        }
    160154
    161         descriptors_per_block = ext4_superblock_get_block_size(fs->superblock)
     155        uint32_t descriptors_per_block = ext4_superblock_get_block_size(fs->superblock)
    162156            / ext4_superblock_get_desc_size(fs->superblock);
    163157
    164158        /* Block group descriptor table starts at the next block after superblock */
    165         block_id = ext4_superblock_get_first_data_block(fs->superblock) + 1;
     159        aoff64_t block_id = ext4_superblock_get_first_data_block(fs->superblock) + 1;
    166160
    167161        /* Find the block containing the descriptor we are looking for */
    168162        block_id += bgid / descriptors_per_block;
    169         offset = (bgid % descriptors_per_block) * ext4_superblock_get_desc_size(fs->superblock);
     163        uint32_t offset = (bgid % descriptors_per_block) * ext4_superblock_get_desc_size(fs->superblock);
    170164
    171165        rc = block_get(&newref->block, fs->device, block_id, 0);
     
    201195{
    202196        int rc;
    203         aoff64_t block_id;
    204         uint32_t block_group;
    205         uint32_t offset_in_group;
    206         uint32_t byte_offset_in_group;
    207         size_t offset_in_block;
    208         uint32_t inodes_per_group;
    209         uint32_t inode_table_start;
    210         uint16_t inode_size;
    211         uint32_t block_size;
    212         ext4_block_group_ref_t *bg_ref;
    213         ext4_inode_ref_t *newref;
    214 
    215         newref = malloc(sizeof(ext4_inode_ref_t));
     197
     198        ext4_inode_ref_t *newref = malloc(sizeof(ext4_inode_ref_t));
    216199        if (newref == NULL) {
    217200                return ENOMEM;
    218201        }
    219202
    220         inodes_per_group = ext4_superblock_get_inodes_per_group(fs->superblock);
     203        uint32_t inodes_per_group =
     204                        ext4_superblock_get_inodes_per_group(fs->superblock);
    221205
    222206        /* inode numbers are 1-based, but it is simpler to work with 0-based
     
    224208         */
    225209        index -= 1;
    226         block_group = index / inodes_per_group;
    227         offset_in_group = index % inodes_per_group;
    228 
     210        uint32_t block_group = index / inodes_per_group;
     211        uint32_t offset_in_group = index % inodes_per_group;
     212
     213        ext4_block_group_ref_t *bg_ref;
    229214        rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
    230215        if (rc != EOK) {
     
    233218        }
    234219
    235         inode_table_start = ext4_block_group_get_inode_table_first_block(
     220        uint32_t inode_table_start = ext4_block_group_get_inode_table_first_block(
    236221            bg_ref->block_group, fs->superblock);
    237222
     
    242227        }
    243228
    244         inode_size = ext4_superblock_get_inode_size(fs->superblock);
    245         block_size = ext4_superblock_get_block_size(fs->superblock);
    246 
    247         byte_offset_in_group = offset_in_group * inode_size;
    248 
    249         block_id = inode_table_start + (byte_offset_in_group / block_size);
    250         offset_in_block = byte_offset_in_group % block_size;
    251 
     229        uint16_t inode_size = ext4_superblock_get_inode_size(fs->superblock);
     230        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
     231        uint32_t byte_offset_in_group = offset_in_group * inode_size;
     232
     233        aoff64_t block_id = inode_table_start + (byte_offset_in_group / block_size);
    252234        rc = block_get(&newref->block, fs->device, block_id, 0);
    253235        if (rc != EOK) {
     
    256238        }
    257239
     240        uint32_t offset_in_block = byte_offset_in_group % block_size;
    258241        newref->inode = newref->block->data + offset_in_block;
    259242        /* we decremented index above, but need to store the original value
     
    322305{
    323306        int rc;
     307
    324308        // release all indirect blocks
    325309
    326         uint32_t fblock;
    327 
    328310        // 1) Single indirect
    329         fblock = ext4_inode_get_indirect_block(inode_ref->inode, 0);
     311        uint32_t fblock = ext4_inode_get_indirect_block(inode_ref->inode, 0);
    330312        if (fblock != 0) {
    331313                rc = ext4_balloc_free_block(fs, inode_ref, fblock);
     
    437419                ext4_inode_ref_t *inode_ref, aoff64_t new_size)
    438420{
    439         aoff64_t old_size;
    440         aoff64_t size_diff;
    441 
    442421        if (! ext4_inode_can_truncate(fs->superblock, inode_ref->inode)) {
    443422                // Unable to truncate
     
    445424        }
    446425
    447         old_size = ext4_inode_get_size(fs->superblock, inode_ref->inode);
    448 
     426        aoff64_t old_size = ext4_inode_get_size(fs->superblock, inode_ref->inode);
    449427        if (old_size == new_size) {
    450428                // Nothing to do
    451429                return EOK;
    452430        }
    453 
    454         uint32_t block_size;
    455         uint32_t blocks_count, total_blocks;
    456         uint32_t i;
    457 
    458         block_size  = ext4_superblock_get_block_size(fs->superblock);
    459431
    460432        if (old_size < new_size) {
     
    465437        }
    466438
    467         size_diff = old_size - new_size;
    468         blocks_count = size_diff / block_size;
     439        aoff64_t size_diff = old_size - new_size;
     440        uint32_t block_size  = ext4_superblock_get_block_size(fs->superblock);
     441        uint32_t blocks_count = size_diff / block_size;
    469442        if (size_diff % block_size != 0) {
    470443                blocks_count++;
    471444        }
    472445
    473         total_blocks = old_size / block_size;
     446        uint32_t total_blocks = old_size / block_size;
    474447        if (old_size % block_size != 0) {
    475448                total_blocks++;
     
    477450
    478451        // starting from 1 because of logical blocks are numbered from 0
    479         for (i = 1; i <= blocks_count; ++i) {
     452        for (uint32_t i = 1; i <= blocks_count; ++i) {
    480453                // TODO check retval
    481454                ext4_filesystem_release_inode_block(fs, inode_ref, total_blocks - i);
     
    493466{
    494467        int rc;
    495         uint32_t offset_in_block;
     468
     469
    496470        uint32_t current_block;
    497         aoff64_t block_offset_in_level;
    498         int i;
    499         int level;
    500         block_t *block;
    501471
    502472        /* Handle inode using extents */
     
    517487
    518488        /* Determine the indirection level needed to get the desired block */
    519         level = -1;
    520         for (i = 1; i < 4; i++) {
     489        int level = -1;
     490        for (int i = 1; i < 4; i++) {
    521491                if (iblock < fs->inode_block_limits[i]) {
    522492                        level = i;
     
    530500
    531501        /* Compute offsets for the topmost level */
    532         block_offset_in_level = iblock - fs->inode_block_limits[level-1];
     502        aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
    533503        current_block = ext4_inode_get_indirect_block(inode, level-1);
    534         offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
     504        uint32_t offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
    535505
    536506        if (current_block == 0) {
     
    538508                return EOK;
    539509        }
     510
     511        block_t *block;
    540512
    541513        /* Navigate through other levels, until we find the block number
     
    584556                ext4_inode_ref_t *inode_ref, aoff64_t iblock, uint32_t fblock)
    585557{
    586 
    587         int rc;
    588         uint32_t offset_in_block;
    589         uint32_t current_block, new_block_addr;
    590         uint32_t block_size;
    591         aoff64_t block_offset_in_level;
    592         int i;
    593         int level;
    594         block_t *block, *new_block;
     558        int rc;
     559
    595560
    596561        /* Handle inode using extents */
     
    609574
    610575        /* Determine the indirection level needed to get the desired block */
    611         level = -1;
    612         for (i = 1; i < 4; i++) {
     576        int level = -1;
     577        for (int i = 1; i < 4; i++) {
    613578                if (iblock < fs->inode_block_limits[i]) {
    614579                        level = i;
     
    621586        }
    622587
    623         block_size = ext4_superblock_get_block_size(fs->superblock);
     588
     589
     590        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
    624591
    625592        /* Compute offsets for the topmost level */
    626         block_offset_in_level = iblock - fs->inode_block_limits[level-1];
    627         current_block = ext4_inode_get_indirect_block(inode_ref->inode, level-1);
    628         offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
     593        aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
     594        uint32_t current_block = ext4_inode_get_indirect_block(inode_ref->inode, level-1);
     595        uint32_t offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
     596
     597        uint32_t new_block_addr;
     598        block_t *block, *new_block;
    629599
    630600        if (current_block == 0) {
     
    634604                        EXT4FS_DBG("error in allocation");
    635605                }
    636 //              EXT4FS_DBG("AAA: new addr \%u, level = \%u", new_block_addr, level);
    637606
    638607                ext4_inode_set_indirect_block(inode_ref->inode, level - 1, new_block_addr);
     
    677646                                EXT4FS_DBG("allocation error");
    678647                        }
    679 //                      EXT4FS_DBG("BBB: new addr \%u, offset = \%u, level = \%u", new_block_addr, offset_in_block, level);
    680648
    681649                        rc = block_get(&new_block, fs->device, new_block_addr, BLOCK_FLAGS_NOREAD);
     
    730698{
    731699        int rc;
     700
     701
     702        /* TODO handle extents */
     703
     704
    732705        uint32_t fblock;
    733         int i;
    734         int level;
    735         aoff64_t block_offset_in_level;
    736         uint32_t current_block;
    737         uint32_t offset_in_block;
    738         block_t *block;
    739706        ext4_inode_t *inode = inode_ref->inode;
    740 
    741         /* TODO handle extents */
    742 
    743707
    744708        /* Handle simple case when we are dealing with direct reference */
     
    756720
    757721        /* Determine the indirection level needed to get the desired block */
    758         level = -1;
    759         for (i = 1; i < 4; i++) {
     722        int level = -1;
     723        for (int i = 1; i < 4; i++) {
    760724                if (iblock < fs->inode_block_limits[i]) {
    761725                        level = i;
     
    769733
    770734        /* Compute offsets for the topmost level */
    771         block_offset_in_level = iblock - fs->inode_block_limits[level-1];
    772         current_block = ext4_inode_get_indirect_block(inode, level-1);
    773         offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
     735        aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
     736        uint32_t current_block = ext4_inode_get_indirect_block(inode, level-1);
     737        uint32_t offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
    774738
    775739        /* Navigate through other levels, until we find the block number
    776740         * or find null reference meaning we are dealing with sparse file
    777741         */
     742        block_t *block;
    778743        while (level > 0) {
    779744                rc = block_get(&block, fs->device, current_block, 0);
  • uspace/lib/ext4/libext4_ialloc.c

    rb7e0260 rd9bbe45  
    5959{
    6060        int rc;
     61
    6162        uint32_t block_group = ext4_ialloc_get_bgid_of_inode(
    62                         fs->superblock, inode_ref->index);
    63         uint32_t index_in_group = ext4_ialloc_inode2index_in_group(
    6463                        fs->superblock, inode_ref->index);
    6564
     
    8079        }
    8180
     81        uint32_t index_in_group = ext4_ialloc_inode2index_in_group(
     82                                fs->superblock, inode_ref->index);
    8283        ext4_bitmap_free_bit(bitmap_block->data, index_in_group);
    8384        bitmap_block->dirty = true;
  • uspace/lib/ext4/libext4_inode.c

    rb7e0260 rd9bbe45  
    160160uint64_t ext4_inode_get_blocks_count(ext4_superblock_t *sb, ext4_inode_t *inode)
    161161{
    162         uint64_t count;
    163 
    164162        if (ext4_superblock_has_feature_read_only(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
    165163
    166164                /* 48-bit field */
    167                 count = ((uint64_t)uint16_t_le2host(inode->osd2.linux2.blocks_high)) << 32 |
     165                uint64_t count = ((uint64_t)uint16_t_le2host(inode->osd2.linux2.blocks_high)) << 32 |
    168166                                uint32_t_le2host(inode->blocks_count_lo);
    169167
     
    283281uint32_t ext4_inode_get_extent_block(ext4_inode_t *inode, uint64_t idx, service_id_t service_id)
    284282{
     283        int rc;
     284
     285        block_t* block = NULL;
     286
    285287        ext4_extent_header_t *header = ext4_inode_get_extent_header(inode);
    286         ext4_extent_t *extent;
    287         ext4_extent_index_t *extent_index;
    288 
    289         uint32_t first_block;
    290         uint16_t block_count;
    291         uint64_t phys_block = 0;
    292         uint64_t child;
    293 
    294         int rc;
    295         block_t* block = NULL;
    296 
    297288        while (ext4_extent_header_get_depth(header) != 0) {
    298289
    299                 extent_index = EXT4_EXTENT_FIRST_INDEX(header);
     290                ext4_extent_index_t *extent_index = EXT4_EXTENT_FIRST_INDEX(header);
    300291
    301292                for (uint16_t i = 0; i < ext4_extent_header_get_entries_count(header); ++i) {
    302                         if(idx >= ext4_extent_index_get_first_block(extent_index)) {
    303 
    304                                 child = ext4_extent_index_get_leaf(extent_index);
     293                        if (idx >= ext4_extent_index_get_first_block(extent_index)) {
     294
     295                                uint64_t child = ext4_extent_index_get_leaf(extent_index);
    305296
    306297                                if (block != NULL) {
     
    319310        }
    320311
    321         extent = EXT4_EXTENT_FIRST(header);
     312        ext4_extent_t *extent = EXT4_EXTENT_FIRST(header);
     313        uint64_t phys_block = 0;
    322314
    323315        for (uint16_t i = 0; i < ext4_extent_header_get_entries_count(header); ++i) {
    324316
    325                 first_block = ext4_extent_get_first_block(extent);
    326                 block_count = ext4_extent_get_block_count(extent);
     317                uint32_t first_block = ext4_extent_get_first_block(extent);
     318                uint16_t block_count = ext4_extent_get_block_count(extent);
    327319
    328320                if ((idx >= first_block) && (idx < first_block + block_count)) {
    329                         phys_block = ext4_extent_get_start(extent) + idx;
    330                         phys_block -= ext4_extent_get_first_block(extent);
    331 
    332                         // Memory leak prevention
    333                         if (block != NULL) {
    334                                 block_put(block);
    335                         }
    336                         return phys_block;
     321                         phys_block = ext4_extent_get_start(extent) + idx;
     322                         phys_block -= ext4_extent_get_first_block(extent);
     323
     324                         // Memory leak prevention
     325                         if (block != NULL) {
     326                                 block_put(block);
     327                         }
     328                         return phys_block;
    337329                }
    338330                // Go to the next extent
  • uspace/lib/ext4/libext4_superblock.c

    rb7e0260 rd9bbe45  
    437437    ext4_superblock_t **superblock)
    438438{
    439         void *data;
    440439        int rc;
    441440
    442         data = malloc(EXT4_SUPERBLOCK_SIZE);
     441        void *data = malloc(EXT4_SUPERBLOCK_SIZE);
    443442        if (data == NULL) {
    444443                return ENOMEM;
     
    463462        int rc;
    464463        uint32_t phys_block_size;
    465         uint64_t first_block;
    466         uint32_t block_count;
    467464
    468465        rc = block_get_bsize(service_id, &phys_block_size);
     
    472469        }
    473470
    474         first_block = EXT4_SUPERBLOCK_OFFSET / phys_block_size;
    475         block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;
     471        uint64_t first_block = EXT4_SUPERBLOCK_OFFSET / phys_block_size;
     472        uint32_t block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;
    476473
    477474        if (EXT4_SUPERBLOCK_SIZE % phys_block_size) {
Note: See TracChangeset for help on using the changeset viewer.