Ignore:
Timestamp:
2012-01-22T13:22:56Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fcae007
Parents:
b7e0260
Message:

Refafctorization - principle of locality in variables declaration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.