Changeset 36d2c6f in mainline


Ignore:
Timestamp:
2011-10-20T09:53:35Z (13 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e3ca824
Parents:
246a5af
Message:

successful reading indexed directory if item is in the first leaf block

Location:
uspace
Files:
2 edited

Legend:

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

    r246a5af r36d2c6f  
    312312        ext4_directory_dx_entry_t *entries;
    313313        block_t *tmp_block = NULL;
    314         uint32_t fblock;
     314        uint32_t fblock, next_block;
    315315
    316316        root = (ext4_directory_dx_root_t *)root_block->data;
     
    341341                at = p - 1;
    342342
     343                next_block = ext4_directory_dx_entry_get_block(at);
     344
     345                if (tmp_block) {
     346                block_put(tmp_block);
     347        }
     348
    343349        if (indirect_level == 0) {
    344                 *leaf_block_idx = ext4_directory_dx_entry_get_block(at);
    345                 return EOK;
     350                return ext4_filesystem_get_inode_data_block_index(fs, inode, next_block, leaf_block_idx);
    346351        }
    347352
    348353        indirect_level--;
    349354
    350         rc = ext4_filesystem_get_inode_data_block_index(fs, inode, ext4_directory_dx_entry_get_block(at), &fblock);
     355        rc = ext4_filesystem_get_inode_data_block_index(fs, inode, next_block, &fblock);
    351356        if (rc != EOK) {
    352357                return rc;
    353358        }
    354359
    355         if (tmp_block) {
    356                 block_put(tmp_block);
    357         }
    358 
    359360        rc = block_get(&tmp_block, fs->device, fblock, BLOCK_FLAGS_NONE);
    360361        if (rc != EOK) {
    361                 // TODO
    362362                return rc;
    363363        }
     
    376376        }
    377377
    378         if (tmp_block) {
    379                 block_put(tmp_block);
    380         }
    381 
     378        // Unreachable
    382379        return EOK;
     380}
     381
     382
     383static int ext4_dirextory_dx_find_dir_entry(block_t *block,
     384                ext4_superblock_t *sb, size_t name_len, const char *name,
     385                ext4_directory_entry_ll_t **res_entry, aoff64_t *block_offset)
     386{
     387        ext4_directory_entry_ll_t *dentry;
     388        uint16_t dentry_len;
     389        uint8_t *addr_limit;
     390        aoff64_t offset = 0;
     391
     392        dentry = (ext4_directory_entry_ll_t *)block->data;
     393        addr_limit = block->data + ext4_superblock_get_block_size(sb);
     394
     395        while ((uint8_t *)dentry < addr_limit) {
     396
     397                if ((uint8_t*) dentry + name_len > addr_limit) {
     398                        break;
     399                }
     400
     401                if (name_len == ext4_directory_entry_ll_get_name_length(sb, dentry)) {
     402
     403                        if (bcmp((uint8_t *)name, dentry->name, name_len)) {
     404                                // TODO check entry ??
     405                                *block_offset = offset;
     406                                *res_entry = dentry;
     407                                return EOK;
     408                        }
     409                }
     410
     411                // Goto next entry
     412                dentry_len = ext4_directory_entry_ll_get_entry_length(dentry);
     413        if (dentry_len <= 0) {
     414                // TODO
     415                return -1;
     416        }
     417
     418                offset += dentry_len;
     419                dentry = (ext4_directory_entry_ll_t *)((uint8_t *)dentry + dentry_len);
     420        }
     421
     422        return ENOENT;
    383423}
    384424
     
    389429        int rc;
    390430        uint32_t root_block_addr, leaf_block_addr;
    391         block_t *root_block;
     431        aoff64_t block_offset;
     432        block_t *root_block, *leaf_block;
    392433        ext4_hash_info_t hinfo;
     434        ext4_directory_entry_ll_t *res_dentry;
    393435
    394436        // get direct block 0 (index root)
     
    406448        rc = ext4_directory_hinfo_init(&hinfo, root_block, fs->superblock, len, name);
    407449        if (rc != EOK) {
    408                 EXT4FS_DBG("ERR: leaf block not found");
    409450                block_put(root_block);
    410451                return EXT4_ERR_BAD_DX_DIR;
     
    416457        }
    417458
    418         // TODO now having block - do directory entry search
     459        rc = block_get(&leaf_block, fs->device, leaf_block_addr, BLOCK_FLAGS_NONE);
     460        if (rc != EOK) {
     461                return EXT4_ERR_BAD_DX_DIR;
     462        }
     463
     464        rc = ext4_dirextory_dx_find_dir_entry(leaf_block, fs->superblock, len, name,
     465                        &res_dentry, &block_offset);
     466
     467        // Found = return it
     468        if (rc == EOK) {
     469                it->fs = fs;
     470                it->inode_ref = inode_ref;
     471                it->current_block = leaf_block;
     472                it->current_offset = block_offset;
     473                it->current = res_dentry;
     474                return EOK;
     475        }
    419476
    420477        // TODO delete it !!!
  • uspace/srv/fs/ext4fs/ext4fs_ops.c

    r246a5af r36d2c6f  
    238238
    239239                        inode = ext4_directory_entry_ll_get_inode(it.current);
    240                         return ext4fs_node_get_core(rfn, eparent->instance, inode);
     240
     241                        rc = ext4fs_node_get_core(rfn, eparent->instance, inode);
     242                        ext4_directory_iterator_fini(&it);
     243                        return rc;
    241244                }
    242245
Note: See TracChangeset for help on using the changeset viewer.