Changeset 7eb033ce in mainline
- Timestamp:
- 2012-04-12T03:03:36Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1fff583
- Parents:
- 81ee87cd
- Location:
- uspace
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_directory.c
r81ee87cd r7eb033ce 264 264 ext4_inode_ref_t *child, const char *name, size_t name_len) 265 265 { 266 267 EXT4FS_DBG("writing entry \%s, len \%u, addr = \%u", name, entry_len, (uint32_t)entry); 268 266 269 ext4_directory_entry_ll_set_inode(entry, child->index); 267 270 ext4_directory_entry_ll_set_entry_length(entry, entry_len); … … 291 294 ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX)) { 292 295 296 EXT4FS_DBG("index"); 297 293 298 rc = ext4_directory_dx_add_entry(parent, child, name); 294 299 … … 312 317 // Linear algorithm 313 318 314 uint32_t iblock , fblock;319 uint32_t iblock = 0, fblock = 0; 315 320 uint32_t block_size = ext4_superblock_get_block_size(fs->superblock); 316 321 uint32_t inode_size = ext4_inode_get_size(fs->superblock, parent->inode); … … 351 356 // No free block found - needed to allocate next block 352 357 358 iblock = 0; 359 fblock = 0; 353 360 rc = ext4_filesystem_append_inode_block(parent, &fblock, &iblock); 354 361 if (rc != EOK) { 355 362 return rc; 356 363 } 364 365 EXT4FS_DBG("using iblock \%u fblock \%u", iblock, fblock); 357 366 358 367 // Load new block … … 363 372 } 364 373 374 EXT4FS_DBG("loaded"); 375 365 376 // Fill block with zeroes 366 377 memset(new_block->data, 0, block_size); 367 378 ext4_directory_entry_ll_t *block_entry = new_block->data; 368 379 ext4_directory_write_entry(fs->superblock, block_entry, block_size, child, name, name_len); 380 381 EXT4FS_DBG("written"); 369 382 370 383 // Save new block … … 374 387 return rc; 375 388 } 389 390 EXT4FS_DBG("returning"); 376 391 377 392 return EOK; -
uspace/lib/ext4/libext4_directory_index.c
r81ee87cd r7eb033ce 135 135 /**************************************************************************/ 136 136 137 int 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 } 137 223 138 224 static int ext4_directory_hinfo_init(ext4_hash_info_t *hinfo, block_t *root_block, … … 771 857 if (rc != EOK) { 772 858 block_put(root_block); 859 EXT4FS_DBG("hinfo initialization error"); 773 860 return EXT4_ERR_BAD_DX_DIR; 774 861 } … … 779 866 rc = ext4_directory_dx_get_leaf(&hinfo, parent, root_block, &dx_block, dx_blocks); 780 867 if (rc != EOK) { 868 EXT4FS_DBG("get leaf error"); 781 869 rc = EXT4_ERR_BAD_DX_DIR; 782 870 goto release_index; -
uspace/lib/ext4/libext4_directory_index.h
r81ee87cd r7eb033ce 66 66 /*********************************************************************************/ 67 67 68 extern int ext4_directory_dx_init(ext4_inode_ref_t *); 68 69 extern int ext4_directory_dx_find_entry(ext4_directory_search_result_t *, 69 70 ext4_inode_ref_t *, size_t, const char *); -
uspace/lib/ext4/libext4_extent.c
r81ee87cd r7eb033ce 559 559 uint32_t iblock) 560 560 { 561 EXT4FS_DBG(""); 561 562 int rc; 562 563 … … 568 569 // Trivial way - no splitting 569 570 if (entries < limit) { 571 EXT4FS_DBG("adding extent entry"); 572 570 573 ext4_extent_header_set_entries_count(path_ptr->header, entries + 1); 571 574 path_ptr->extent = EXT4_EXTENT_FIRST(path_ptr->header) + entries; … … 581 584 ext4_superblock_get_block_size(inode_ref->fs->superblock); 582 585 583 // Trivial tree - grow 586 // Trivial tree - grow (extents were in root node) 584 587 if (path_ptr == path) { 585 586 // EXT4FS_DBG("splitting extent root");587 588 588 589 uint32_t new_fblock; … … 592 593 return rc; 593 594 } 594 595 // EXT4FS_DBG("allocated new node \%u", new_fblock);596 595 597 596 block_t *block; … … 641 640 } 642 641 642 assert(false); 643 643 644 // start splitting 644 645 uint32_t fblock = 0; 645 646 path_ptr--;647 648 646 while (path_ptr > path) { 647 648 // TODO 649 649 650 650 rc = ext4_balloc_alloc_block(inode_ref, &fblock); … … 674 674 path_ptr->extent = EXT4_EXTENT_FIRST(path_ptr->header); 675 675 } 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; 676 734 } 677 735 … … 682 740 uint32_t *iblock, uint32_t *fblock) 683 741 { 742 EXT4FS_DBG(""); 684 743 int rc = EOK; 685 744 … … 726 785 rc = ext4_balloc_alloc_block(inode_ref, &phys_block); 727 786 if (rc != EOK) { 728 // TODO error, cleanup 729 assert(false); 787 goto finish; 730 788 } 731 789 … … 745 803 rc = ext4_balloc_try_alloc_block(inode_ref, phys_block, &free); 746 804 if (rc != EOK) { 747 // TODO error 748 assert(false); 805 goto finish; 749 806 } 750 807 751 808 if (! free) { 752 809 // target is not free 753 // EXT4FS_DBG("target not free, \%u", phys_block);754 810 goto append_extent; 755 811 } … … 763 819 } 764 820 } 765 766 assert(false);767 821 768 822 append_extent: … … 776 830 } 777 831 778 // EXT4FS_DBG("allocated \%u", phys_block);779 780 832 rc = ext4_extent_append_extent(inode_ref, path, &path_ptr, new_block_idx); 781 833 if (rc != EOK) { … … 794 846 *iblock = new_block_idx; 795 847 *fblock = phys_block; 796 797 // EXT4FS_DBG("iblock = \%u, fblock = \%u", new_block_idx, phys_block);798 848 799 849 // Put loaded blocks -
uspace/lib/ext4/libext4_filesystem.c
r81ee87cd r7eb033ce 323 323 } 324 324 325 // TODO dir_index initialization326 327 325 rc = ext4_filesystem_get_inode_ref(fs, index, inode_ref); 328 326 if (rc != EOK) { … … 596 594 rc = ext4_extent_find_block(inode_ref, iblock, ¤t_block); 597 595 596 EXT4FS_DBG("ext: loading iblock \%u, address \%u", (uint32_t)iblock, current_block); 597 598 598 if (rc != EOK) { 599 599 return rc; … … 917 917 int rc; 918 918 919 EXT4FS_DBG(""); 920 919 921 // Handle extents separately 920 922 if (ext4_superblock_has_feature_incompatible( … … 932 934 uint32_t block_size = ext4_superblock_get_block_size(sb); 933 935 936 // TODO zarovnat inode size a ne assert!!! 934 937 assert(inode_size % block_size == 0); 935 938 -
uspace/lib/ext4/libext4_superblock.c
r81ee87cd r7eb033ce 369 369 } 370 370 371 uint8_t ext4_superblock_get_default_hash_version(ext4_superblock_t *sb) 372 { 373 return sb->default_hash_version; 374 } 375 376 void ext4_superblock_set_default_hash_version(ext4_superblock_t *sb, uint8_t version) 377 { 378 sb->default_hash_version = version; 379 } 380 371 381 uint16_t ext4_superblock_get_desc_size(ext4_superblock_t *sb) 372 382 { -
uspace/lib/ext4/libext4_superblock.h
r81ee87cd r7eb033ce 114 114 extern void ext4_superblock_set_last_orphan(ext4_superblock_t *, uint32_t); 115 115 extern uint32_t* ext4_superblock_get_hash_seed(ext4_superblock_t *); 116 extern uint8_t ext4_superblock_get_default_hash_version(ext4_superblock_t *); 117 extern void ext4_superblock_set_default_hash_version(ext4_superblock_t *, uint8_t); 116 118 /* 117 uint8_t s_def_hash_version; // Default hash version to use118 119 uint8_t s_jnl_backup_type; 119 120 */ -
uspace/srv/fs/ext4fs/ext4fs_ops.c
r81ee87cd r7eb033ce 510 510 } 511 511 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 512 524 uint16_t parent_links = ext4_inode_get_links_count(parent->inode_ref->inode); 513 525 parent_links++;
Note:
See TracChangeset
for help on using the changeset viewer.