Changeset 7eb033ce in mainline


Ignore:
Timestamp:
2012-04-12T03:03:36Z (13 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1fff583
Parents:
81ee87cd
Message:

not debugged version of dir index initialization

Location:
uspace
Files:
8 edited

Legend:

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

    r81ee87cd r7eb033ce  
    264264                ext4_inode_ref_t *child, const char *name, size_t name_len)
    265265{
     266
     267        EXT4FS_DBG("writing entry \%s, len \%u, addr = \%u", name, entry_len, (uint32_t)entry);
     268
    266269        ext4_directory_entry_ll_set_inode(entry, child->index);
    267270        ext4_directory_entry_ll_set_entry_length(entry, entry_len);
     
    291294                        ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX)) {
    292295
     296                EXT4FS_DBG("index");
     297
    293298                rc = ext4_directory_dx_add_entry(parent, child, name);
    294299
     
    312317        // Linear algorithm
    313318
    314         uint32_t iblock, fblock;
     319        uint32_t iblock = 0, fblock = 0;
    315320        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
    316321        uint32_t inode_size = ext4_inode_get_size(fs->superblock, parent->inode);
     
    351356        // No free block found - needed to allocate next block
    352357
     358        iblock = 0;
     359        fblock = 0;
    353360        rc = ext4_filesystem_append_inode_block(parent, &fblock, &iblock);
    354361        if (rc != EOK) {
    355362                return rc;
    356363        }
     364
     365        EXT4FS_DBG("using iblock \%u fblock \%u", iblock, fblock);
    357366
    358367        // Load new block
     
    363372        }
    364373
     374        EXT4FS_DBG("loaded");
     375
    365376        // Fill block with zeroes
    366377        memset(new_block->data, 0, block_size);
    367378        ext4_directory_entry_ll_t *block_entry = new_block->data;
    368379        ext4_directory_write_entry(fs->superblock, block_entry, block_size, child, name, name_len);
     380
     381        EXT4FS_DBG("written");
    369382
    370383        // Save new block
     
    374387                return rc;
    375388        }
     389
     390        EXT4FS_DBG("returning");
    376391
    377392        return EOK;
  • uspace/lib/ext4/libext4_directory_index.c

    r81ee87cd r7eb033ce  
    135135/**************************************************************************/
    136136
     137int ext4_directory_dx_init(ext4_inode_ref_t *dir)
     138{
     139        int rc;
     140
     141        uint32_t fblock;
     142        rc = ext4_filesystem_get_inode_data_block_index(dir, 0, &fblock);
     143        if (rc != EOK) {
     144                return rc;
     145        }
     146
     147        block_t *block;
     148        rc = block_get(&block, dir->fs->device, fblock, BLOCK_FLAGS_NONE);
     149        if (rc != EOK) {
     150                return rc;
     151        }
     152
     153        EXT4FS_DBG("fblock = \%u", fblock);
     154
     155        ext4_directory_dx_root_t *root = block->data;
     156
     157        ext4_directory_entry_ll_t *dot = (ext4_directory_entry_ll_t *)&root->dots[0];
     158        ext4_directory_entry_ll_t *dot_dot = (ext4_directory_entry_ll_t *)&root->dots[1];
     159
     160        EXT4FS_DBG("dot len = \%u, dotdot len = \%u", ext4_directory_entry_ll_get_entry_length(dot), ext4_directory_entry_ll_get_entry_length(dot_dot));
     161
     162//      uint32_t block_size = ext4_superblock_get_block_size(dir->fs->superblock);
     163//      uint16_t len = block_size - sizeof(ext4_directory_dx_dot_entry_t);
     164
     165//      ext4_directory_entry_ll_set_entry_length(dot_dot, len);
     166
     167        ext4_directory_dx_root_info_t *info = &(root->info);
     168
     169        uint8_t hash_version =
     170                        ext4_superblock_get_default_hash_version(dir->fs->superblock);
     171
     172        ext4_directory_dx_root_info_set_hash_version(info, hash_version);
     173        ext4_directory_dx_root_info_set_indirect_levels(info, 0);
     174        ext4_directory_dx_root_info_set_info_length(info, 8);
     175
     176        ext4_directory_dx_countlimit_t *countlimit =
     177                        (ext4_directory_dx_countlimit_t *)&root->entries;
     178        ext4_directory_dx_countlimit_set_count(countlimit, 1);
     179
     180        uint32_t block_size = ext4_superblock_get_block_size(dir->fs->superblock);
     181        uint32_t entry_space = block_size - 2 * sizeof(ext4_directory_dx_dot_entry_t)
     182                - sizeof(ext4_directory_dx_root_info_t);
     183        uint16_t root_limit = entry_space / sizeof(ext4_directory_dx_entry_t);
     184        ext4_directory_dx_countlimit_set_limit(countlimit, root_limit);
     185
     186        uint32_t iblock;
     187        rc = ext4_filesystem_append_inode_block(dir, &fblock, &iblock);
     188        if (rc != EOK) {
     189                block_put(block);
     190                return rc;
     191        }
     192
     193        block_t *new_block;
     194        rc = block_get(&new_block, dir->fs->device, fblock, BLOCK_FLAGS_NOREAD);
     195        if (rc != EOK) {
     196                block_put(block);
     197                return rc;
     198        }
     199
     200        ext4_directory_entry_ll_t *block_entry = new_block->data;
     201        ext4_directory_entry_ll_set_entry_length(block_entry, block_size);
     202        ext4_directory_entry_ll_set_inode(block_entry, 0);
     203
     204        new_block->dirty = true;
     205        rc = block_put(new_block);
     206        if (rc != EOK) {
     207                block_put(block);
     208                return rc;
     209        }
     210
     211        ext4_directory_dx_entry_t *entry = root->entries;
     212        ext4_directory_dx_entry_set_block(entry, iblock);
     213
     214        block->dirty = true;
     215
     216        rc = block_put(block);
     217        if (rc != EOK) {
     218                return rc;
     219        }
     220
     221        return EOK;
     222}
    137223
    138224static int ext4_directory_hinfo_init(ext4_hash_info_t *hinfo, block_t *root_block,
     
    771857        if (rc != EOK) {
    772858                block_put(root_block);
     859                EXT4FS_DBG("hinfo initialization error");
    773860                return EXT4_ERR_BAD_DX_DIR;
    774861        }
     
    779866        rc = ext4_directory_dx_get_leaf(&hinfo, parent, root_block, &dx_block, dx_blocks);
    780867        if (rc != EOK) {
     868                EXT4FS_DBG("get leaf error");
    781869                rc = EXT4_ERR_BAD_DX_DIR;
    782870                goto release_index;
  • uspace/lib/ext4/libext4_directory_index.h

    r81ee87cd r7eb033ce  
    6666/*********************************************************************************/
    6767
     68extern int ext4_directory_dx_init(ext4_inode_ref_t *);
    6869extern int ext4_directory_dx_find_entry(ext4_directory_search_result_t *,
    6970                ext4_inode_ref_t *, size_t, const char *);
  • uspace/lib/ext4/libext4_extent.c

    r81ee87cd r7eb033ce  
    559559                uint32_t iblock)
    560560{
     561        EXT4FS_DBG("");
    561562        int rc;
    562563
     
    568569        // Trivial way - no splitting
    569570        if (entries < limit) {
     571                EXT4FS_DBG("adding extent entry");
     572
    570573                ext4_extent_header_set_entries_count(path_ptr->header, entries + 1);
    571574                path_ptr->extent = EXT4_EXTENT_FIRST(path_ptr->header) + entries;
     
    581584                        ext4_superblock_get_block_size(inode_ref->fs->superblock);
    582585
    583         // Trivial tree - grow
     586        // Trivial tree - grow (extents were in root node)
    584587        if (path_ptr == path) {
    585 
    586 //              EXT4FS_DBG("splitting extent root");
    587588
    588589                uint32_t new_fblock;
     
    592593                        return rc;
    593594                }
    594 
    595 //              EXT4FS_DBG("allocated new node \%u", new_fblock);
    596595
    597596                block_t *block;
     
    641640        }
    642641
     642        assert(false);
     643
    643644        // start splitting
    644645        uint32_t fblock = 0;
    645 
    646         path_ptr--;
    647 
    648646        while (path_ptr > path) {
     647
     648                // TODO
    649649
    650650                rc = ext4_balloc_alloc_block(inode_ref, &fblock);
     
    674674                        path_ptr->extent = EXT4_EXTENT_FIRST(path_ptr->header);
    675675                }
     676
     677                path_ptr--;
     678        }
     679
     680        // If splitting reached root node
     681        if (path_ptr == path) {
     682
     683                uint32_t new_fblock;
     684                rc = ext4_balloc_alloc_block(inode_ref, &new_fblock);
     685                if (rc != EOK) {
     686                        EXT4FS_DBG("error in block allocation");
     687                        return rc;
     688                }
     689
     690                block_t *block;
     691                rc = block_get(&block, inode_ref->fs->device,
     692                                new_fblock, BLOCK_FLAGS_NOREAD);
     693                if (rc != EOK) {
     694                        EXT4FS_DBG("error in block_get");
     695                        return rc;
     696                }
     697
     698                memset(block->data, 0, block_size);
     699
     700                // Move data from root to the new block
     701                memcpy(block->data, inode_ref->inode->blocks,
     702                                EXT4_INODE_BLOCKS * sizeof(uint32_t));
     703
     704                path_ptr++;
     705                path_ptr->block = block;
     706                path_ptr->header = (ext4_extent_header_t *)block->data;
     707                path_ptr->depth = ext4_extent_header_get_depth(path_ptr->header);
     708                path_ptr->index = NULL;
     709
     710                uint16_t entries = ext4_extent_header_get_entries_count(path_ptr->header);
     711                path_ptr->extent = EXT4_EXTENT_FIRST(path_ptr->header) + entries;
     712                ext4_extent_header_set_entries_count(path_ptr->header, entries + 1);
     713                uint16_t limit = (block_size - sizeof(ext4_extent_header_t)) /
     714                                sizeof(ext4_extent_t);
     715                ext4_extent_header_set_max_entries_count(path_ptr->header, limit);
     716
     717                // Modify root (in inode)
     718                path->depth = 1;
     719                path->extent = NULL;
     720                path->index = EXT4_EXTENT_FIRST_INDEX(path->header);
     721
     722                ext4_extent_header_set_depth(path->header, path_ptr->depth + 1);
     723                ext4_extent_header_set_entries_count(path->header, 1);
     724
     725                ext4_extent_index_set_first_block(path->index, 0);
     726                ext4_extent_index_set_leaf(path->index, new_fblock);
     727
     728                path_ptr->block->dirty = true;
     729                path->block->dirty = true;
     730
     731                *last_path_item = path_ptr;
     732
     733                return EOK;
    676734        }
    677735
     
    682740                uint32_t *iblock, uint32_t *fblock)
    683741{
     742        EXT4FS_DBG("");
    684743        int rc = EOK;
    685744
     
    726785                        rc = ext4_balloc_alloc_block(inode_ref, &phys_block);
    727786                        if (rc != EOK) {
    728                         // TODO error, cleanup
    729                                 assert(false);
     787                                goto finish;
    730788                        }
    731789
     
    745803                        rc = ext4_balloc_try_alloc_block(inode_ref, phys_block, &free);
    746804                        if (rc != EOK) {
    747                                 // TODO error
    748                                 assert(false);
     805                                goto finish;
    749806                        }
    750807
    751808                        if (! free) {
    752809                                // target is not free
    753 //                              EXT4FS_DBG("target not free, \%u", phys_block);
    754810                                goto append_extent;
    755811                        }
     
    763819                }
    764820        }
    765 
    766         assert(false);
    767821
    768822append_extent:
     
    776830        }
    777831
    778 //      EXT4FS_DBG("allocated \%u", phys_block);
    779 
    780832        rc = ext4_extent_append_extent(inode_ref, path, &path_ptr, new_block_idx);
    781833        if (rc != EOK) {
     
    794846        *iblock = new_block_idx;
    795847        *fblock = phys_block;
    796 
    797 //      EXT4FS_DBG("iblock = \%u, fblock = \%u", new_block_idx, phys_block);
    798848
    799849        // Put loaded blocks
  • uspace/lib/ext4/libext4_filesystem.c

    r81ee87cd r7eb033ce  
    323323        }
    324324
    325         // TODO dir_index initialization
    326 
    327325        rc = ext4_filesystem_get_inode_ref(fs, index, inode_ref);
    328326        if (rc != EOK) {
     
    596594                rc = ext4_extent_find_block(inode_ref, iblock, &current_block);
    597595
     596                EXT4FS_DBG("ext: loading iblock \%u, address \%u", (uint32_t)iblock, current_block);
     597
    598598                if (rc != EOK) {
    599599                        return rc;
     
    917917        int rc;
    918918
     919        EXT4FS_DBG("");
     920
    919921        // Handle extents separately
    920922        if (ext4_superblock_has_feature_incompatible(
     
    932934        uint32_t block_size = ext4_superblock_get_block_size(sb);
    933935
     936        // TODO zarovnat inode size a ne assert!!!
    934937        assert(inode_size % block_size == 0);
    935938
  • uspace/lib/ext4/libext4_superblock.c

    r81ee87cd r7eb033ce  
    369369}
    370370
     371uint8_t ext4_superblock_get_default_hash_version(ext4_superblock_t *sb)
     372{
     373        return sb->default_hash_version;
     374}
     375
     376void ext4_superblock_set_default_hash_version(ext4_superblock_t *sb, uint8_t version)
     377{
     378        sb->default_hash_version = version;
     379}
     380
    371381uint16_t ext4_superblock_get_desc_size(ext4_superblock_t *sb)
    372382{
  • uspace/lib/ext4/libext4_superblock.h

    r81ee87cd r7eb033ce  
    114114extern void ext4_superblock_set_last_orphan(ext4_superblock_t *, uint32_t);
    115115extern uint32_t* ext4_superblock_get_hash_seed(ext4_superblock_t *);
     116extern uint8_t ext4_superblock_get_default_hash_version(ext4_superblock_t *);
     117extern void ext4_superblock_set_default_hash_version(ext4_superblock_t *, uint8_t);
    116118/*
    117 uint8_t s_def_hash_version; // Default hash version to use
    118119uint8_t s_jnl_backup_type;
    119120*/
  • uspace/srv/fs/ext4fs/ext4fs_ops.c

    r81ee87cd r7eb033ce  
    510510                }
    511511
     512//              if (ext4_superblock_has_feature_compatible(
     513//                              fs->superblock, EXT4_FEATURE_COMPAT_DIR_INDEX)) {
     514//
     515//                      rc = ext4_directory_dx_init(child->inode_ref);
     516//                      if (rc != EOK) {
     517//                              return rc;
     518//                      }
     519//
     520//                      ext4_inode_set_flag(child->inode_ref->inode, EXT4_INODE_FLAG_INDEX);
     521//                      child->inode_ref->dirty = true;
     522//              }
     523
    512524                uint16_t parent_links = ext4_inode_get_links_count(parent->inode_ref->inode);
    513525                parent_links++;
Note: See TracChangeset for help on using the changeset viewer.