Ignore:
Timestamp:
2012-06-18T11:09:34Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2616a75b
Parents:
9a487cc
Message:

Most of comments modified by current coding style

File:
1 edited

Legend:

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

    r9a487cc r06d85e5  
    218218        int rc;
    219219
    220         // Load block 0, where will be index root located
     220        /* Load block 0, where will be index root located */
    221221        uint32_t fblock;
    222222        rc = ext4_filesystem_get_inode_data_block_index(dir, 0, &fblock);
     
    231231        }
    232232
    233         // Initialize pointers to data structures
     233        /* Initialize pointers to data structures */
    234234        ext4_directory_dx_root_t *root = block->data;
    235235        ext4_directory_dx_root_info_t *info = &(root->info);
    236236
    237         // Initialize root info structure
     237        /* Initialize root info structure */
    238238        uint8_t hash_version =
    239239                        ext4_superblock_get_default_hash_version(dir->fs->superblock);
     
    243243        ext4_directory_dx_root_info_set_info_length(info, 8);
    244244
    245         // Set limit and current number of entries
     245        /* Set limit and current number of entries */
    246246        ext4_directory_dx_countlimit_t *countlimit =
    247247                        (ext4_directory_dx_countlimit_t *)&root->entries;
     
    254254        ext4_directory_dx_countlimit_set_limit(countlimit, root_limit);
    255255
    256         // Append new block, where will be new entries inserted in the future
     256        /* Append new block, where will be new entries inserted in the future */
    257257        uint32_t iblock;
    258258        rc = ext4_filesystem_append_inode_block(dir, &fblock, &iblock);
     
    269269        }
    270270
    271         // Fill the whole block with empty entry
     271        /* Fill the whole block with empty entry */
    272272        ext4_directory_entry_ll_t *block_entry = new_block->data;
    273273        ext4_directory_entry_ll_set_entry_length(block_entry, block_size);
     
    281281        }
    282282
    283         // Connect new block to the only entry in index
     283        /* Connect new block to the only entry in index */
    284284        ext4_directory_dx_entry_t *entry = root->entries;
    285285        ext4_directory_dx_entry_set_block(entry, iblock);
     
    316316        }
    317317
    318         // Check unused flags
     318        /* Check unused flags */
    319319        if (root->info.unused_flags != 0) {
    320320                EXT4FS_DBG("ERR: unused_flags = \%u", root->info.unused_flags);
     
    322322        }
    323323
    324         // Check indirect levels
     324        /* Check indirect levels */
    325325        if (root->info.indirect_levels > 1) {
    326326                EXT4FS_DBG("ERR: indirect_levels = \%u", root->info.indirect_levels);
     
    328328        }
    329329
    330         // Check if node limit is correct
     330        /* Check if node limit is correct */
    331331        uint32_t block_size = ext4_superblock_get_block_size(sb);
    332332        uint32_t entry_space = block_size;
     
    340340        }
    341341
    342     // Check hash version and modify if necessary
     342    /* Check hash version and modify if necessary */
    343343        hinfo->hash_version = ext4_directory_dx_root_info_get_hash_version(&root->info);
    344344        if ((hinfo->hash_version <= EXT4_HASH_VERSION_TEA)
    345345                        && (ext4_superblock_has_flag(sb, EXT4_SUPERBLOCK_FLAGS_UNSIGNED_HASH))) {
    346                 // 3 is magic from ext4 linux implementation
     346                /* 3 is magic from ext4 linux implementation */
    347347                hinfo->hash_version += 3;
    348348        }
    349349
    350         // Load hash seed from superblock
     350        /* Load hash seed from superblock */
    351351        hinfo->seed = ext4_superblock_get_hash_seed(sb);
    352352
    353         // Compute hash value of name
     353        /* Compute hash value of name */
    354354        if (name) {
    355355                ext4_hash_string(hinfo, name_len, name);
     
    385385        ext4_directory_dx_entry_t *p, *q, *m, *at;
    386386
    387         // Walk through the index tree
     387        /* Walk through the index tree */
    388388        while (true) {
    389389
     
    394394
    395395
    396                 // Do binary search in every node
     396                /* Do binary search in every node */
    397397                p = entries + 1;
    398398                q = entries + count - 1;
     
    409409                at = p - 1;
    410410
    411                 // Write results
     411                /* Write results */
    412412                tmp_dx_block->block = tmp_block;
    413413                tmp_dx_block->entries = entries;
    414414                tmp_dx_block->position = at;
    415415
    416                 // Is algorithm in the leaf?
     416                /* Is algorithm in the leaf? */
    417417        if (indirect_level == 0) {
    418418                *dx_block = tmp_dx_block;
     
    420420        }
    421421
    422         // Goto child node
     422        /* Goto child node */
    423423                uint32_t next_block = ext4_directory_dx_entry_get_block(at);
    424424
     
    454454        }
    455455
    456         // Unreachable
     456        /* Unreachable */
    457457        return EOK;
    458458}
     
    475475    ext4_directory_dx_block_t *p = dx_block;
    476476
    477     // Try to find data block with next bunch of entries
     477    /* Try to find data block with next bunch of entries */
    478478    while (1) {
    479479
     
    494494    }
    495495
    496     // Check hash collision (if not occured - no next block cannot be used)
     496    /* Check hash collision (if not occured - no next block cannot be used) */
    497497    uint32_t current_hash = ext4_directory_dx_entry_get_hash(p->position);
    498498    if ((hash & 1) == 0) {
     
    502502    }
    503503
    504     // Fill new path
     504    /* Fill new path */
    505505    while (num_handles--) {
    506506
     
    520520        p++;
    521521
    522         // Don't forget to put old block (prevent memory leak)
     522        /* Don't forget to put old block (prevent memory leak) */
    523523        block_put(p->block);
    524524
     
    546546        int rc;
    547547
    548         // Load direct block 0 (index root)
     548        /* Load direct block 0 (index root) */
    549549        uint32_t root_block_addr;
    550550        rc = ext4_filesystem_get_inode_data_block_index(inode_ref, 0, &root_block_addr);
     
    561561        }
    562562
    563         // Initialize hash info (compute hash value)
     563        /* Initialize hash info (compute hash value) */
    564564        ext4_hash_info_t hinfo;
    565565        rc = ext4_directory_hinfo_init(&hinfo, root_block, fs->superblock, name_len, name);
     
    569569        }
    570570
    571         // Hardcoded number 2 means maximum height of index tree, specified in linux driver
     571        /* Hardcoded number 2 means maximum height of index tree, specified in linux driver */
    572572        ext4_directory_dx_block_t dx_blocks[2];
    573573        ext4_directory_dx_block_t *dx_block, *tmp;
     
    579579
    580580        do {
    581                 // Load leaf block
     581                /* Load leaf block */
    582582                uint32_t leaf_block_idx = ext4_directory_dx_entry_get_block(dx_block->position);
    583583                uint32_t leaf_block_addr;
     
    593593                }
    594594
    595                 // Linear search inside block
     595                /* Linear search inside block */
    596596                ext4_directory_entry_ll_t *res_dentry;
    597597                rc = ext4_directory_find_in_block(leaf_block, fs->superblock, name_len, name, &res_dentry);
    598598
    599                 // Found => return it
     599                /* Found => return it */
    600600                if (rc == EOK) {
    601601                        result->block = leaf_block;
     
    604604                }
    605605
    606                 // Not found, leave untouched
     606                /* Not found, leave untouched */
    607607                block_put(leaf_block);
    608608
     
    611611                }
    612612
    613                 // check if the next block could be checked
     613                /* check if the next block could be checked */
    614614                rc = ext4_directory_dx_next_block(inode_ref, hinfo.hash, dx_block, &dx_blocks[0]);
    615615                if (rc < 0) {
     
    619619        } while (rc == 1);
    620620
    621         // Entry not found
     621        /* Entry not found */
    622622        rc = ENOENT;
    623623
    624624cleanup:
    625625
    626         // The whole path must be released (preventing memory leak)
     626        /* The whole path must be released (preventing memory leak) */
    627627        tmp = dx_blocks;
    628628        while (tmp <= dx_block) {
     
    705705        int rc = EOK;
    706706
    707         // Allocate buffer for directory entries
     707        /* Allocate buffer for directory entries */
    708708        uint32_t block_size =
    709709                        ext4_superblock_get_block_size(inode_ref->fs->superblock);
     
    713713        }
    714714
    715         // dot entry has the smallest size available
     715        /* dot entry has the smallest size available */
    716716        uint32_t max_entry_count =  block_size / sizeof(ext4_directory_dx_dot_entry_t);
    717717
    718         // Allocate sort entry
     718        /* Allocate sort entry */
    719719        ext4_dx_sort_entry_t *sort_array = malloc(max_entry_count * sizeof(ext4_dx_sort_entry_t));
    720720        if (sort_array == NULL) {
     
    726726        uint32_t real_size = 0;
    727727
    728         // Initialize hinfo
     728        /* Initialize hinfo */
    729729        ext4_hash_info_t tmp_hinfo;
    730730        memcpy(&tmp_hinfo, hinfo, sizeof(ext4_hash_info_t));
    731731
    732         // Load all valid entries to the buffer
     732        /* Load all valid entries to the buffer */
    733733        ext4_directory_entry_ll_t *dentry = old_data_block->data;
    734734        void *entry_buffer_ptr = entry_buffer;
    735735        while ((void *)dentry < old_data_block->data + block_size) {
    736736
    737                 // Read only valid entries
     737                /* Read only valid entries */
    738738                if (ext4_directory_entry_ll_get_inode(dentry) != 0) {
    739739
     
    762762        }
    763763
    764         // Sort all entries
     764        /* Sort all entries */
    765765        qsort(sort_array, idx, sizeof(ext4_dx_sort_entry_t),
    766766                        ext4_directory_dx_entry_comparator, NULL);
    767767
    768         // Allocate new block for store the second part of entries
     768        /* Allocate new block for store the second part of entries */
    769769        uint32_t new_fblock;
    770770        uint32_t new_iblock;
     
    776776        }
    777777
    778         // Load new block
     778        /* Load new block */
    779779        block_t *new_data_block_tmp;
    780780        rc = block_get(&new_data_block_tmp, inode_ref->fs->device,
     
    786786        }
    787787
    788         // Distribute entries to two blocks (by size)
    789         // Compute the half
     788        /* Distribute entries to two blocks (by size)
     789         * - compute the half
     790         */
    790791        uint32_t new_hash = 0;
    791792        uint32_t current_size = 0;
     
    801802        }
    802803
    803         // Check hash collision
     804        /* Check hash collision */
    804805        uint32_t continued = 0;
    805806        if (new_hash == sort_array[mid-1].hash) {
     
    810811        void *ptr;
    811812
    812         // First part - to the old block
     813        /* First part - to the old block */
    813814        for (uint32_t i = 0; i < mid; ++i) {
    814815                ptr = old_data_block->data + offset;
     
    825826        }
    826827
    827         // Second part - to the new block
     828        /* Second part - to the new block */
    828829        offset = 0;
    829830        for (uint32_t i = mid; i < idx; ++i) {
     
    841842        }
    842843
    843         // Do some steps to finish operation
     844        /* Do some steps to finish operation */
    844845        old_data_block->dirty = true;
    845846        new_data_block_tmp->dirty = true;
     
    879880        uint16_t leaf_count = ext4_directory_dx_countlimit_get_count(countlimit);
    880881
    881         // Check if is necessary to split index block
     882        /* Check if is necessary to split index block */
    882883        if (leaf_limit == leaf_count) {
    883884
     
    894895                                ext4_directory_dx_countlimit_get_count(root_countlimit);
    895896
    896                 // Linux limitation
     897                /* Linux limitation */
    897898                if ((levels > 0) && (root_limit == root_count)) {
    898899                        EXT4FS_DBG("Directory index is full");
     
    900901                }
    901902
    902                 // Add new block to directory
     903                /* Add new block to directory */
    903904                uint32_t new_fblock;
    904905                uint32_t new_iblock;
     
    909910                }
    910911
    911                 // load new block
     912                /* load new block */
    912913                block_t * new_block;
    913914                rc = block_get(&new_block, inode_ref->fs->device,
     
    923924                                inode_ref->fs->superblock);
    924925
    925                 // Split leaf node
     926                /* Split leaf node */
    926927                if (levels > 0) {
    927928
     
    931932                                        ext4_directory_dx_entry_get_hash(entries + count_left);
    932933
    933                         // Copy data to new node
     934                        /* Copy data to new node */
    934935                        memcpy((void *) new_entries, (void *) (entries + count_left),
    935936                                        count_right * sizeof(ext4_directory_dx_entry_t));
    936937
    937                         // Initialize new node
     938                        /* Initialize new node */
    938939                        ext4_directory_dx_countlimit_t *left_countlimit =
    939940                                        (ext4_directory_dx_countlimit_t *)entries;
     
    948949                        ext4_directory_dx_countlimit_set_limit(right_countlimit, node_limit);
    949950
    950                         // Which index block is target for new entry
     951                        /* Which index block is target for new entry */
    951952                        uint32_t position_index = (dx_block->position - dx_block->entries);
    952953                        if (position_index >= count_left) {
     
    963964                        }
    964965
    965                         // Finally insert new entry
     966                        /* Finally insert new entry */
    966967                        ext4_directory_dx_insert_entry(dx_blocks, hash_right, new_iblock);
    967968
     
    970971                } else {
    971972
    972                         // Create second level index
    973 
    974                         // Copy data from root to child block
     973                        /* Create second level index */
     974
     975                        /* Copy data from root to child block */
    975976                        memcpy((void *) new_entries, (void *) entries,
    976977                                        leaf_count * sizeof(ext4_directory_dx_entry_t));
     
    983984                        ext4_directory_dx_countlimit_set_limit(new_countlimit, node_limit);
    984985
    985                         // Set values in root node
     986                        /* Set values in root node */
    986987                        ext4_directory_dx_countlimit_t *new_root_countlimit =
    987988                                        (ext4_directory_dx_countlimit_t *)entries;
     
    992993                        ((ext4_directory_dx_root_t *)dx_blocks[0].block->data)->info.indirect_levels = 1;
    993994
    994                         // Add new entry to the path
     995                        /* Add new entry to the path */
    995996                        dx_block = dx_blocks + 1;
    996997                        dx_block->position = dx_block->position - entries + new_entries;
     
    10171018        int rc2 = EOK;
    10181019
    1019         // get direct block 0 (index root)
     1020        /* get direct block 0 (index root) */
    10201021        uint32_t root_block_addr;
    10211022        rc = ext4_filesystem_get_inode_data_block_index(parent, 0, &root_block_addr);
     
    10321033        }
    10331034
    1034         // Initialize hinfo structure (mainly compute hash)
     1035        /* Initialize hinfo structure (mainly compute hash) */
    10351036        uint32_t name_len = strlen(name);
    10361037        ext4_hash_info_t hinfo;
     
    10421043        }
    10431044
    1044         // Hardcoded number 2 means maximum height of index tree defined in linux
     1045        /* Hardcoded number 2 means maximum height of index tree defined in linux */
    10451046        ext4_directory_dx_block_t dx_blocks[2];
    10461047        ext4_directory_dx_block_t *dx_block, *dx_it;
     
    10531054
    10541055
    1055         // Try to insert to existing data block
     1056        /* Try to insert to existing data block */
    10561057        uint32_t leaf_block_idx = ext4_directory_dx_entry_get_block(dx_block->position);
    10571058        uint32_t leaf_block_addr;
     
    10681069        }
    10691070
    1070         // Check if insert operation passed
     1071        /* Check if insert operation passed */
    10711072        rc = ext4_directory_try_insert_entry(fs->superblock, target_block, child, name, name_len);
    10721073        if (rc == EOK) {
     
    10741075        }
    10751076
    1076         // Check if there is needed to split index node
    1077         // (and recursively also parent nodes)
     1077        /* Check if there is needed to split index node
     1078         * (and recursively also parent nodes)
     1079         */
    10781080        rc = ext4_directory_dx_split_index(parent, dx_blocks, dx_block);
    10791081        if (rc != EOK) {
     
    10811083        }
    10821084
    1083         // Split entries to two blocks (includes sorting by hash value)
     1085        /* Split entries to two blocks (includes sorting by hash value) */
    10841086        block_t *new_block = NULL;
    10851087        rc = ext4_directory_dx_split_data(parent, &hinfo, target_block, dx_block, &new_block);
     
    10891091        }
    10901092
    1091         // Where to save new entry
     1093        /* Where to save new entry */
    10921094        uint32_t new_block_hash = ext4_directory_dx_entry_get_hash(dx_block->position + 1);
    10931095        if (hinfo.hash >= new_block_hash) {
     
    10971099        }
    10981100
    1099         // Cleanup
     1101        /* Cleanup */
    11001102        rc = block_put(new_block);
    11011103        if (rc != EOK) {
     
    11041106        }
    11051107
    1106         // Cleanup operations
     1108        /* Cleanup operations */
    11071109
    11081110release_target_index:
Note: See TracChangeset for help on using the changeset viewer.