Ignore:
Timestamp:
2012-03-03T17:44:38Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e63ce679
Parents:
c30a015
Message:

Code refactoring (for dentry searching)

File:
1 edited

Legend:

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

    rc30a015 r7689590  
    264264
    265265
    266 static int ext4_directory_dx_find_dir_entry(block_t *block,
    267                 ext4_superblock_t *sb, size_t name_len, const char *name,
    268                 ext4_directory_entry_ll_t **res_entry, aoff64_t *block_offset)
    269 {
    270 
    271         aoff64_t offset = 0;
    272         ext4_directory_entry_ll_t *dentry = (ext4_directory_entry_ll_t *)block->data;
    273         uint8_t *addr_limit = block->data + ext4_superblock_get_block_size(sb);
    274 
    275         while ((uint8_t *)dentry < addr_limit) {
    276 
    277                 if ((uint8_t*) dentry + name_len > addr_limit) {
    278                         break;
    279                 }
    280 
    281                 if (dentry->inode != 0) {
    282                         if (name_len == ext4_directory_entry_ll_get_name_length(sb, dentry)) {
    283                                 // Compare names
    284                                 if (bcmp((uint8_t *)name, dentry->name, name_len) == 0) {
    285                                         *block_offset = offset;
    286                                         *res_entry = dentry;
    287                                         return 1;
    288                                 }
    289                         }
    290                 }
    291 
    292 
    293                 // Goto next entry
    294                 uint16_t dentry_len = ext4_directory_entry_ll_get_entry_length(dentry);
    295 
    296         if (dentry_len == 0) {
    297                 // Error
    298                 return -1;
    299         }
    300 
    301                 offset += dentry_len;
    302                 dentry = (ext4_directory_entry_ll_t *)((uint8_t *)dentry + dentry_len);
    303         }
    304 
    305         return 0;
    306 }
    307 
    308266static int ext4_directory_dx_next_block(ext4_filesystem_t *fs, ext4_inode_t *inode, uint32_t hash,
    309267                ext4_directory_dx_block_t *handle, ext4_directory_dx_block_t *handles)
     
    368326}
    369327
    370 int ext4_directory_dx_find_entry(ext4_directory_iterator_t *it,
    371                 ext4_filesystem_t *fs, ext4_inode_ref_t *inode_ref, size_t len, const char *name)
     328int ext4_directory_dx_find_entry(ext4_directory_search_result_t *result,
     329                ext4_filesystem_t *fs, ext4_inode_ref_t *inode_ref, size_t name_len, const char *name)
    372330{
    373331        int rc;
     
    383341        rc = block_get(&root_block, fs->device, root_block_addr, BLOCK_FLAGS_NONE);
    384342        if (rc != EOK) {
    385                 it->current_block = NULL;
    386343                return rc;
    387344        }
    388345
    389346        ext4_hash_info_t hinfo;
    390         rc = ext4_directory_hinfo_init(&hinfo, root_block, fs->superblock, len, name);
     347        rc = ext4_directory_hinfo_init(&hinfo, root_block, fs->superblock, name_len, name);
    391348        if (rc != EOK) {
    392349                block_put(root_block);
     
    419376                }
    420377
    421                 aoff64_t block_offset;
    422378                ext4_directory_entry_ll_t *res_dentry;
    423                 rc = ext4_directory_dx_find_dir_entry(leaf_block, fs->superblock, len, name,
    424                                 &res_dentry, &block_offset);
     379                rc = ext4_directory_find_in_block(leaf_block, fs->superblock, name_len, name, &res_dentry);
     380
    425381
    426382                // Found => return it
    427                 if (rc == 1) {
    428                         it->fs = fs;
    429                         it->inode_ref = inode_ref;
    430                         it->current_block = leaf_block;
    431                         it->current_offset = block_offset;
    432                         it->current = res_dentry;
     383                if (rc == EOK) {
     384                        result->block = leaf_block;
     385                        result->dentry = res_dentry;
    433386                        return EOK;
    434387                }
     
    572525        }
    573526
    574 //      EXT4FS_DBG("new block appended (iblock = \%u, fblock = \%u)", new_iblock, new_fblock);
    575 
    576527        // Load new block
    577528        block_t *new_data_block_tmp;
     
    584535
    585536        // Distribute entries to splitted blocks (by size)
    586 
    587537        uint32_t new_hash = 0;
    588538        uint32_t current_size = 0;
Note: See TracChangeset for help on using the changeset viewer.