Changeset 1d68621 in mainline
- Timestamp:
- 2012-02-26T14:08:44Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 41998ec
- Parents:
- a61ddcf4
- Location:
- uspace/lib/ext4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_directory.c
ra61ddcf4 r1d68621 323 323 ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX)) { 324 324 325 EXT4FS_DBG("trying INDEX");326 327 325 rc = ext4_directory_dx_add_entry(fs, parent, child, name_len, entry_name); 328 326 … … 464 462 465 463 EXT4FS_DBG("index is corrupted - doing linear search"); 466 467 // TODO Needed to clear dir index flag468 //ext4_inode_clear_flag(parent->inode, EXT4_INODE_FLAG_INDEX);469 //parent->dirty = true;470 464 471 465 } -
uspace/lib/ext4/libext4_directory_index.c
ra61ddcf4 r1d68621 491 491 memcpy(entry_buffer, old_data_block->data, block_size); 492 492 493 // dot entry has the smal est size available494 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)); 497 497 if (sort_array == NULL) { 498 498 free(entry_buffer); … … 500 500 } 501 501 502 EXT4FS_DBG("sort_array allocated addr = \%u, size = \%u", (uint32_t)sort_array, entry_count * sizeof(ext4_dx_sort_entry_t));503 504 502 ext4_directory_entry_ll_t *dentry = old_data_block->data; 505 503 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; 511 505 uint32_t real_size = 0; 512 506 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 513 511 while ((void *)dentry < old_data_block->data + block_size) { 514 512 char *name = (char *)dentry->name; 515 513 516 514 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); 518 516 519 517 uint32_t rec_len = 8 + len; … … 527 525 sort_array[idx].dentry = entry_buffer_ptr; 528 526 sort_array[idx].rec_len = rec_len; 529 sort_array[idx].hash = hash;527 sort_array[idx].hash = tmp_hinfo.hash; 530 528 531 529 entry_buffer_ptr += rec_len; … … 536 534 } 537 535 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); 539 537 540 538 uint32_t new_fblock; … … 547 545 } 548 546 549 EXT4FS_DBG("new block appended (iblock = \%u)", new_iblock);547 // EXT4FS_DBG("new block appended (iblock = \%u, fblock = \%u)", new_iblock, new_fblock); 550 548 551 549 // Load new block … … 562 560 uint32_t new_hash = 0; 563 561 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)) { 567 565 new_hash = sort_array[i].hash; 568 566 mid = i; … … 577 575 578 576 // First part - to the old block 579 for ( int i = 0; i < mid; ++i) {577 for (uint32_t i = 0; i < mid; ++i) { 580 578 ptr = old_data_block->data + offset; 581 579 memcpy(ptr, sort_array[i].dentry, sort_array[i].rec_len); … … 593 591 // Second part - to the new block 594 592 offset = 0; 595 for ( int i = mid; i < idx; ++i) {593 for (uint32_t i = mid; i < idx; ++i) { 596 594 ptr = new_data_block_tmp->data + offset; 597 595 memcpy(ptr, sort_array[i].dentry, sort_array[i].rec_len); … … 613 611 free(entry_buffer); 614 612 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 615 616 ext4_directory_dx_countlimit_t *countlimit = 616 617 (ext4_directory_dx_countlimit_t *)index_block->entries; 617 618 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); 625 629 626 630 index_block->block->dirty = true; … … 792 796 793 797 // 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); 796 799 if (hinfo.hash >= new_block_hash) { 797 800 de = new_block->data; … … 825 828 if (free_space >= required_len) { 826 829 827 EXT4FS_DBG("rec_len = \%u, used_space = \%u, free space = \%u", de_rec_len, used_space, free_space);828 829 830 // Cut tail of current entry 830 831 ext4_directory_entry_ll_set_entry_length(de, used_space);
Note:
See TracChangeset
for help on using the changeset viewer.