Changeset 06d85e5 in mainline for uspace/lib/ext4/libext4_directory.c


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.c

    r9a487cc r06d85e5  
    159159        }
    160160
    161         // else do nothing
     161        /* else do nothing */
    162162
    163163}
     
    237237        }
    238238
    239         // Compute next block address
     239        /* Compute next block address */
    240240        uint32_t block_size = ext4_superblock_get_block_size(
    241241                        it->inode_ref->fs->superblock);
     
    313313        }
    314314
    315         // Everything OK - "publish" the entry
     315        /* Everything OK - "publish" the entry */
    316316        it->current = entry;
    317317        return EOK;
     
    357357{
    358358
    359         // Check maximum entry length
     359        /* Check maximum entry length */
    360360        uint32_t block_size = ext4_superblock_get_block_size(sb);
    361361        assert(entry_len <= block_size);
    362362
    363         // Set basic attributes
     363        /* Set basic attributes */
    364364        ext4_directory_entry_ll_set_inode(entry, child->index);
    365365        ext4_directory_entry_ll_set_entry_length(entry, entry_len);
    366366        ext4_directory_entry_ll_set_name_length(sb, entry, name_len);
    367367
    368         // Write name
     368        /* Write name */
    369369        memcpy(entry->name, name, name_len);
    370370
    371         // Set type of entry
     371        /* Set type of entry */
    372372        if (ext4_inode_is_type(sb, child->inode, EXT4_INODE_MODE_DIRECTORY)) {
    373373                ext4_directory_entry_ll_set_inode_type(
     
    394394        ext4_filesystem_t *fs = parent->fs;
    395395
    396         // Index adding (if allowed)
     396        /* Index adding (if allowed) */
    397397        if (ext4_superblock_has_feature_compatible(fs->superblock, EXT4_FEATURE_COMPAT_DIR_INDEX) &&
    398398                        ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX)) {
     
    400400                rc = ext4_directory_dx_add_entry(parent, child, name);
    401401
    402                 // Check if index is not corrupted
     402                /* Check if index is not corrupted */
    403403                if (rc != EXT4_ERR_BAD_DX_DIR) {
    404404
     
    410410                }
    411411
    412                 // Needed to clear dir index flag if corrupted
     412                /* Needed to clear dir index flag if corrupted */
    413413                ext4_inode_clear_flag(parent->inode, EXT4_INODE_FLAG_INDEX);
    414414                parent->dirty = true;
     
    417417        }
    418418
    419         // Linear algorithm
     419        /* Linear algorithm */
    420420
    421421        uint32_t iblock = 0, fblock = 0;
     
    426426        uint32_t name_len = strlen(name);
    427427
    428         // Find block, where is space for new entry and try to add
     428        /* Find block, where is space for new entry and try to add */
    429429        bool success = false;
    430430        for (iblock = 0; iblock < total_blocks; ++iblock) {
     
    441441                }
    442442
    443                 // If adding is successful, function can finish
     443                /* If adding is successful, function can finish */
    444444                rc = ext4_directory_try_insert_entry(fs->superblock, block, child, name, name_len);
    445445                if (rc == EOK) {
     
    457457        }
    458458
    459         // No free block found - needed to allocate next data block
     459        /* No free block found - needed to allocate next data block */
    460460
    461461        iblock = 0;
     
    466466        }
    467467
    468         // Load new block
     468        /* Load new block */
    469469        block_t *new_block;
    470470        rc = block_get(&new_block, fs->device, fblock, BLOCK_FLAGS_NOREAD);
     
    473473        }
    474474
    475         // Fill block with zeroes
     475        /* Fill block with zeroes */
    476476        memset(new_block->data, 0, block_size);
    477477        ext4_directory_entry_ll_t *block_entry = new_block->data;
    478478        ext4_directory_write_entry(fs->superblock, block_entry, block_size, child, name, name_len);
    479479
    480         // Save new block
     480        /* Save new block */
    481481        new_block->dirty = true;
    482482        rc = block_put(new_block);
     
    503503        ext4_superblock_t *sb = parent->fs->superblock;
    504504
    505         // Index search
     505        /* Index search */
    506506        if (ext4_superblock_has_feature_compatible(sb, EXT4_FEATURE_COMPAT_DIR_INDEX) &&
    507507                        ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX)) {
     
    509509                rc = ext4_directory_dx_find_entry(result, parent, name_len, name);
    510510
    511                 // Check if index is not corrupted
     511                /* Check if index is not corrupted */
    512512                if (rc != EXT4_ERR_BAD_DX_DIR) {
    513513
     
    518518                }
    519519
    520                 // Needed to clear dir index flag if corrupted
     520                /* Needed to clear dir index flag if corrupted */
    521521                ext4_inode_clear_flag(parent->inode, EXT4_INODE_FLAG_INDEX);
    522522                parent->dirty = true;
     
    525525        }
    526526
    527         // Linear algorithm
     527        /* Linear algorithm */
    528528
    529529        uint32_t iblock, fblock;
     
    532532        uint32_t total_blocks = inode_size / block_size;
    533533
    534         // Walk through all data blocks
     534        /* Walk through all data blocks */
    535535        for (iblock = 0; iblock < total_blocks; ++iblock) {
    536536
    537                 // Load block address
     537                /* Load block address */
    538538                rc = ext4_filesystem_get_inode_data_block_index(parent, iblock, &fblock);
    539539                if (rc != EOK) {
     
    541541                }
    542542
    543                 // Load data block
     543                /* Load data block */
    544544                block_t *block;
    545545                rc = block_get(&block, parent->fs->device, fblock, BLOCK_FLAGS_NONE);
     
    548548                }
    549549
    550                 // Try to find entry in block
     550                /* Try to find entry in block */
    551551                ext4_directory_entry_ll_t *res_entry;
    552552                rc = ext4_directory_find_in_block(block, sb, name_len, name, &res_entry);
     
    557557                }
    558558
    559                 // Entry not found - put block and continue to the next block
     559                /* Entry not found - put block and continue to the next block */
    560560
    561561                rc = block_put(block);
     
    565565        }
    566566
    567         // Entry was not found
     567        /* Entry was not found */
    568568
    569569        result->block = NULL;
     
    584584        int rc;
    585585
    586         // Check if removing from directory
     586        /* Check if removing from directory */
    587587        if (!ext4_inode_is_type(parent->fs->superblock, parent->inode,
    588588            EXT4_INODE_MODE_DIRECTORY)) {
     
    590590        }
    591591
    592         // Try to find entry
     592        /* Try to find entry */
    593593        ext4_directory_search_result_t result;
    594594        rc  = ext4_directory_find_entry(&result, parent, name);
     
    597597        }
    598598
    599         // Invalidate entry
     599        /* Invalidate entry */
    600600        ext4_directory_entry_ll_set_inode(result.dentry, 0);
    601601
    602         // Store entry position in block
     602        /* Store entry position in block */
    603603        uint32_t pos = (void *)result.dentry - result.block->data;
    604604
    605         // If entry is not the first in block, it must be merged
    606         // with previous entry
     605        /* If entry is not the first in block, it must be merged
     606         * with previous entry
     607         */
    607608        if (pos != 0) {
    608609
    609610                uint32_t offset = 0;
    610611
    611                 // Start from the first entry in block
     612                /* Start from the first entry in block */
    612613                ext4_directory_entry_ll_t *tmp_dentry = result.block->data;
    613614                uint16_t tmp_dentry_length =
    614615                                ext4_directory_entry_ll_get_entry_length(tmp_dentry);
    615616
    616                 // Find direct predecessor of removed entry
     617                /* Find direct predecessor of removed entry */
    617618                while ((offset + tmp_dentry_length) < pos) {
    618619                        offset += ext4_directory_entry_ll_get_entry_length(tmp_dentry);
     
    624625                assert(tmp_dentry_length + offset == pos);
    625626
    626                 // Add to removed entry length to predecessor's length
     627                /* Add to removed entry length to predecessor's length */
    627628                uint16_t del_entry_length =
    628629                                ext4_directory_entry_ll_get_entry_length(result.dentry);
     
    650651                const char *name, uint32_t name_len)
    651652{
    652         // Compute required length entry and align it to 4 bytes
     653        /* Compute required length entry and align it to 4 bytes */
    653654        uint32_t block_size = ext4_superblock_get_block_size(sb);
    654655        uint16_t required_len = sizeof(ext4_fake_directory_entry_t) + name_len;
     
    657658        }
    658659
    659         // Initialize pointers, stop means to upper bound
     660        /* Initialize pointers, stop means to upper bound */
    660661        ext4_directory_entry_ll_t *dentry = target_block->data;
    661662        ext4_directory_entry_ll_t *stop = target_block->data + block_size;
    662663
    663         // Walk through the block and check for invalid entries
    664         // or entries with free space for new entry
     664        /* Walk through the block and check for invalid entries
     665         * or entries with free space for new entry
     666         */
    665667        while (dentry < stop) {
    666668
     
    668670                uint16_t rec_len = ext4_directory_entry_ll_get_entry_length(dentry);
    669671
    670                 // If invalid and large enough entry, use it
     672                /* If invalid and large enough entry, use it */
    671673                if ((inode == 0) && (rec_len >= required_len)) {
    672674                        ext4_directory_write_entry(sb, dentry, rec_len, child, name, name_len);
     
    675677                }
    676678
    677                 // Valid entry, try to split it
     679                /* Valid entry, try to split it */
    678680                if (inode != 0) {
    679681                        uint16_t used_name_len =
     
    687689                        uint16_t free_space = rec_len - used_space;
    688690
    689                         // There is free space for new entry
     691                        /* There is free space for new entry */
    690692                        if (free_space >= required_len) {
    691693
    692                                 // Cut tail of current entry
     694                                /* Cut tail of current entry */
    693695                                ext4_directory_entry_ll_set_entry_length(dentry, used_space);
    694696                                ext4_directory_entry_ll_t *new_entry =
     
    702704                }
    703705
    704                 // Jump to the next entry
     706                /* Jump to the next entry */
    705707                dentry = (void *)dentry + rec_len;
    706708        }
    707709
    708         // No free space found for new entry
     710        /* No free space found for new entry */
    709711
    710712        return ENOSPC;
     
    724726                ext4_directory_entry_ll_t **res_entry)
    725727{
    726         // Start from the first entry in block
     728        /* Start from the first entry in block */
    727729        ext4_directory_entry_ll_t *dentry = (ext4_directory_entry_ll_t *)block->data;
    728         //Set upper bound for cycling
     730        /*Set upper bound for cycling */
    729731        uint8_t *addr_limit = block->data + ext4_superblock_get_block_size(sb);
    730732
    731         // Walk through the block and check entries
     733        /* Walk through the block and check entries */
    732734        while ((uint8_t *)dentry < addr_limit) {
    733735
    734                 // Termination condition
     736                /* Termination condition */
    735737                if ((uint8_t*) dentry + name_len > addr_limit) {
    736738                        break;
    737739                }
    738740
    739                 // Valid entry - check it
     741                /* Valid entry - check it */
    740742                if (dentry->inode != 0) {
    741743
    742                         // For more effectivity compare firstly only lengths
     744                        /* For more effectivity compare firstly only lengths */
    743745                        if (name_len == ext4_directory_entry_ll_get_name_length(sb, dentry)) {
    744                                 // Compare names
     746                                /* Compare names */
    745747                                if (bcmp((uint8_t *)name, dentry->name, name_len) == 0) {
    746748                                        *res_entry = dentry;
     
    752754                uint16_t dentry_len = ext4_directory_entry_ll_get_entry_length(dentry);
    753755
    754                 // Corrupted entry
     756                /* Corrupted entry */
    755757                if (dentry_len == 0) {
    756758                        return EINVAL;
    757759                }
    758760
    759                 // Jump to next entry
     761                /* Jump to next entry */
    760762                dentry = (ext4_directory_entry_ll_t *)((uint8_t *)dentry + dentry_len);
    761763        }
    762764
    763         // Entry not found
     765        /* Entry not found */
    764766        return ENOENT;
    765767}
Note: See TracChangeset for help on using the changeset viewer.