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

Changeset 1d68621 in mainline


Ignore:
Timestamp:
2012-02-26T14:08:44Z (8 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
master
Children:
41998ec
Parents:
a61ddcf4
Message:

more debugged version of splitting data block

Location:
uspace/lib/ext4
Files:
2 edited

Legend:

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

    ra61ddcf4 r1d68621  
    323323                        ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX)) {
    324324
    325                 EXT4FS_DBG("trying INDEX");
    326 
    327325                rc = ext4_directory_dx_add_entry(fs, parent, child, name_len, entry_name);
    328326
     
    464462
    465463                EXT4FS_DBG("index is corrupted - doing linear search");
    466 
    467                 // TODO Needed to clear dir index flag
    468                 //ext4_inode_clear_flag(parent->inode, EXT4_INODE_FLAG_INDEX);
    469                 //parent->dirty = true;
    470464
    471465        }
  • uspace/lib/ext4/libext4_directory_index.c

    ra61ddcf4 r1d68621  
    491491        memcpy(entry_buffer, old_data_block->data, block_size);
    492492
    493         // dot entry has the smalest size available
    494         uint32_t entry_count =  block_size / sizeof(ext4_directory_dx_dot_entry_t);
    495 
    496         ext4_dx_sort_entry_t *sort_array = malloc(entry_count * sizeof(ext4_dx_sort_entry_t));
     493        // dot entry has the smallest size available
     494        uint32_t max_entry_count =  block_size / sizeof(ext4_directory_dx_dot_entry_t);
     495
     496        ext4_dx_sort_entry_t *sort_array = malloc(max_entry_count * sizeof(ext4_dx_sort_entry_t));
    497497        if (sort_array == NULL) {
    498498                free(entry_buffer);
     
    500500        }
    501501
    502         EXT4FS_DBG("sort_array allocated addr = \%u, size = \%u", (uint32_t)sort_array, entry_count * sizeof(ext4_dx_sort_entry_t));
    503 
    504502        ext4_directory_entry_ll_t *dentry = old_data_block->data;
    505503
    506         // TODO tady nekde je chyba
    507 
    508         EXT4FS_DBG("entry_buffer = \%u", (uint32_t)entry_buffer);
    509 
    510         int idx = 0;
     504        uint32_t idx = 0;
    511505        uint32_t real_size = 0;
    512506        void *entry_buffer_ptr = entry_buffer;
     507
     508        ext4_hash_info_t tmp_hinfo;
     509        memcpy(&tmp_hinfo, hinfo, sizeof(ext4_hash_info_t));
     510
    513511        while ((void *)dentry < old_data_block->data + block_size) {
    514512                char *name = (char *)dentry->name;
    515513
    516514                uint8_t len = ext4_directory_entry_ll_get_name_length(fs->superblock, dentry);
    517                 uint32_t hash = ext4_hash_string(hinfo, len, name);
     515                ext4_hash_string(&tmp_hinfo, len, name);
    518516
    519517                uint32_t rec_len = 8 + len;
     
    527525                sort_array[idx].dentry = entry_buffer_ptr;
    528526                sort_array[idx].rec_len = rec_len;
    529                 sort_array[idx].hash = hash;
     527                sort_array[idx].hash = tmp_hinfo.hash;
    530528
    531529                entry_buffer_ptr += rec_len;
     
    536534        }
    537535
    538         qsort(sort_array, entry_count, sizeof(ext4_dx_sort_entry_t), dx_entry_comparator, NULL);
     536        qsort(sort_array, idx, sizeof(ext4_dx_sort_entry_t), dx_entry_comparator, NULL);
    539537
    540538        uint32_t new_fblock;
     
    547545        }
    548546
    549         EXT4FS_DBG("new block appended (iblock = \%u)", new_iblock);
     547//      EXT4FS_DBG("new block appended (iblock = \%u, fblock = \%u)", new_iblock, new_fblock);
    550548
    551549        // Load new block
     
    562560        uint32_t new_hash = 0;
    563561        uint32_t current_size = 0;
    564         int mid = 0;
    565         for (int i = 0; i < idx; ++i) {
    566                 if (current_size > real_size / 2) {
     562        uint32_t mid = 0;
     563        for (uint32_t i = 0; i < idx; ++i) {
     564                if ((current_size + sort_array[i].rec_len) > (real_size / 2)) {
    567565                        new_hash = sort_array[i].hash;
    568566                        mid = i;
     
    577575
    578576        // First part - to the old block
    579         for (int i = 0; i < mid; ++i) {
     577        for (uint32_t i = 0; i < mid; ++i) {
    580578                ptr = old_data_block->data + offset;
    581579                memcpy(ptr, sort_array[i].dentry, sort_array[i].rec_len);
     
    593591        // Second part - to the new block
    594592        offset = 0;
    595         for (int i = mid; i < idx; ++i) {
     593        for (uint32_t i = mid; i < idx; ++i) {
    596594                ptr = new_data_block_tmp->data + offset;
    597595                memcpy(ptr, sort_array[i].dentry, sort_array[i].rec_len);
     
    613611        free(entry_buffer);
    614612
     613        ext4_directory_dx_entry_t *old_index_entry = index_block->position;
     614        ext4_directory_dx_entry_t *new_index_entry = old_index_entry + 1;
     615
    615616        ext4_directory_dx_countlimit_t *countlimit =
    616617                        (ext4_directory_dx_countlimit_t *)index_block->entries;
    617618        uint32_t count = ext4_directory_dx_countlimit_get_count(countlimit);
    618         count++;
    619         ext4_directory_dx_countlimit_set_count(countlimit, count);
    620 
    621         index_block->position++;
    622 
    623         ext4_directory_dx_entry_set_block(index_block->position, new_iblock);
    624         ext4_directory_dx_entry_set_hash(index_block->position, new_hash);
     619
     620        ext4_directory_dx_entry_t *start_index = index_block->entries;
     621        size_t bytes = (void *)(start_index + count) - (void *)(new_index_entry);
     622
     623        memmove(new_index_entry + 1, new_index_entry, bytes);
     624
     625        ext4_directory_dx_entry_set_block(new_index_entry, new_iblock);
     626        ext4_directory_dx_entry_set_hash(new_index_entry, new_hash);
     627
     628        ext4_directory_dx_countlimit_set_count(countlimit, count + 1);
    625629
    626630        index_block->block->dirty = true;
     
    792796
    793797        // TODO Where to save new entry
    794         // Position in dx_block is set to NEW block entry
    795         uint32_t new_block_hash = ext4_directory_dx_entry_get_hash(dx_block->position);
     798        uint32_t new_block_hash = ext4_directory_dx_entry_get_hash(dx_block->position + 1);
    796799        if (hinfo.hash >= new_block_hash) {
    797800                de = new_block->data;
     
    825828                        if (free_space >= required_len) {
    826829
    827                                 EXT4FS_DBG("rec_len = \%u, used_space = \%u, free space = \%u", de_rec_len, used_space, free_space);
    828 
    829830                                // Cut tail of current entry
    830831                                ext4_directory_entry_ll_set_entry_length(de, used_space);
Note: See TracChangeset for help on using the changeset viewer.