Changeset 06d85e5 in mainline


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

Location:
uspace
Files:
10 edited

Legend:

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

    r9a487cc r06d85e5  
    5252        uint32_t first_block = ext4_superblock_get_first_data_block(sb);
    5353
    54         // First block == 0 or 1
     54        /* First block == 0 or 1 */
    5555        if (first_block == 0) {
    5656                return block_addr % blocks_per_group;
     
    9292        uint32_t first_block = ext4_superblock_get_first_data_block(sb);
    9393
    94         // First block == 0 or 1
     94        /* First block == 0 or 1 */
    9595        if (first_block == 0) {
    9696                return block_addr / blocks_per_group;
     
    114114        ext4_superblock_t *sb = fs->superblock;
    115115
    116         // Compute indexes
     116        /* Compute indexes */
    117117        uint32_t block_group = ext4_balloc_get_bgid_of_block(sb, block_addr);
    118118        uint32_t index_in_group = ext4_balloc_blockaddr2_index_in_group(sb, block_addr);
    119119
    120         // Load block group reference
     120        /* Load block group reference */
    121121        ext4_block_group_ref_t *bg_ref;
    122122        rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
     
    126126        }
    127127
    128         // Load block with bitmap
     128        /* Load block with bitmap */
    129129        uint32_t bitmap_block_addr = ext4_block_group_get_block_bitmap(
    130130                        bg_ref->block_group, sb);
     
    136136        }
    137137
    138         // Modify bitmap
     138        /* Modify bitmap */
    139139        ext4_bitmap_free_bit(bitmap_block->data, index_in_group);
    140140        bitmap_block->dirty = true;
    141141
    142142
    143         // Release block with bitmap
     143        /* Release block with bitmap */
    144144        rc = block_put(bitmap_block);
    145145        if (rc != EOK) {
    146                 // Error in saving bitmap
     146                /* Error in saving bitmap */
    147147                ext4_filesystem_put_block_group_ref(bg_ref);
    148148                EXT4FS_DBG("error in saving bitmap \%d", rc);
     
    152152        uint32_t block_size = ext4_superblock_get_block_size(sb);
    153153
    154         // Update superblock free blocks count
     154        /* Update superblock free blocks count */
    155155        uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count(sb);
    156156        sb_free_blocks++;
    157157        ext4_superblock_set_free_blocks_count(sb, sb_free_blocks);
    158158
    159         // Update inode blocks count
     159        /* Update inode blocks count */
    160160        uint64_t ino_blocks = ext4_inode_get_blocks_count(sb, inode_ref->inode);
    161161        ino_blocks -= block_size / EXT4_INODE_BLOCK_SIZE;
     
    163163        inode_ref->dirty = true;
    164164
    165         // Update block group free blocks count
     165        /* Update block group free blocks count */
    166166        uint32_t free_blocks = ext4_block_group_get_free_blocks_count(
    167167                        bg_ref->block_group, sb);
     
    171171        bg_ref->dirty = true;
    172172
    173         // Release block group reference
     173        /* Release block group reference */
    174174        rc = ext4_filesystem_put_block_group_ref(bg_ref);
    175175        if (rc != EOK) {
     
    196196        ext4_superblock_t *sb = fs->superblock;
    197197
    198         // Compute indexes
     198        /* Compute indexes */
    199199        uint32_t block_group_first =
    200200                        ext4_balloc_get_bgid_of_block(sb, first);
     
    204204        assert(block_group_first == block_group_last);
    205205
    206         // Load block group reference
     206        /* Load block group reference */
    207207        ext4_block_group_ref_t *bg_ref;
    208208        rc = ext4_filesystem_get_block_group_ref(fs, block_group_first, &bg_ref);
     
    216216
    217217
    218         // Load block with bitmap
     218        /* Load block with bitmap */
    219219        uint32_t bitmap_block_addr = ext4_block_group_get_block_bitmap(
    220220                        bg_ref->block_group, sb);
     
    227227        }
    228228
    229         // Modify bitmap
     229        /* Modify bitmap */
    230230        ext4_bitmap_free_bits(bitmap_block->data, index_in_group_first, count);
    231231        bitmap_block->dirty = true;
    232232
    233         // Release block with bitmap
     233        /* Release block with bitmap */
    234234        rc = block_put(bitmap_block);
    235235        if (rc != EOK) {
    236                 // Error in saving bitmap
     236                /* Error in saving bitmap */
    237237                ext4_filesystem_put_block_group_ref(bg_ref);
    238238                EXT4FS_DBG("error in saving bitmap \%d", rc);
     
    242242        uint32_t block_size = ext4_superblock_get_block_size(sb);
    243243
    244         // Update superblock free blocks count
     244        /* Update superblock free blocks count */
    245245        uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count(sb);
    246246        sb_free_blocks += count;
    247247        ext4_superblock_set_free_blocks_count(sb, sb_free_blocks);
    248248
    249         // Update inode blocks count
     249        /* Update inode blocks count */
    250250        uint64_t ino_blocks = ext4_inode_get_blocks_count(sb, inode_ref->inode);
    251251        ino_blocks -= count * (block_size / EXT4_INODE_BLOCK_SIZE);
     
    253253        inode_ref->dirty = true;
    254254
    255         // Update block group free blocks count
     255        /* Update block group free blocks count */
    256256        uint32_t free_blocks = ext4_block_group_get_free_blocks_count(
    257257                        bg_ref->block_group, sb);
     
    261261        bg_ref->dirty = true;
    262262
    263         // Release block group reference
     263        /* Release block group reference */
    264264        rc = ext4_filesystem_put_block_group_ref(bg_ref);
    265265        if (rc != EOK) {
     
    292292                inode_table_bytes = inodes_per_group * inode_table_item_size;
    293293        } else {
    294                 // last block group could be smaller
     294                /* last block group could be smaller */
    295295                uint32_t inodes_count_total = ext4_superblock_get_inodes_count(sb);
    296296                inode_table_bytes =
     
    328328        }
    329329
    330         // If inode has some blocks, get last block address + 1
     330        /* If inode has some blocks, get last block address + 1 */
    331331        if (inode_block_count > 0) {
    332332
     
    341341                }
    342342
    343                 // if goal == 0, sparse file -> continue
    344         }
    345 
    346         // Identify block group of inode
     343                /* if goal == 0, sparse file -> continue */
     344        }
     345
     346        /* Identify block group of inode */
    347347        uint32_t inodes_per_group = ext4_superblock_get_inodes_per_group(sb);
    348348        uint32_t block_group = (inode_ref->index - 1) / inodes_per_group;
    349349        block_size = ext4_superblock_get_block_size(sb);
    350350
    351         // Load block group reference
     351        /* Load block group reference */
    352352        ext4_block_group_ref_t *bg_ref;
    353353        rc = ext4_filesystem_get_block_group_ref(inode_ref->fs, block_group, &bg_ref);
     
    356356        }
    357357
    358         // Compute indexes
     358        /* Compute indexes */
    359359        uint32_t block_group_count = ext4_superblock_get_block_group_count(sb);
    360360        uint32_t inode_table_first_block = ext4_block_group_get_inode_table_first_block(
     
    363363        uint32_t inode_table_bytes;
    364364
    365         // Check for last block group
     365        /* Check for last block group */
    366366        if (block_group < block_group_count - 1) {
    367367                inode_table_bytes = inodes_per_group * inode_table_item_size;
    368368        } else {
    369                 // last block group could be smaller
     369                /* last block group could be smaller */
    370370                uint32_t inodes_count_total = ext4_superblock_get_inodes_count(sb);
    371371                inode_table_bytes =
     
    403403        uint32_t rel_block_idx = 0;
    404404
    405         // Find GOAL
     405        /* Find GOAL */
    406406        uint32_t goal = ext4_balloc_find_goal(inode_ref);
    407407        if (goal == 0) {
    408                 // no goal found => partition is full
    409                 EXT4FS_DBG("ERRORR (goal == 0)");
     408                /* no goal found => partition is full */
     409                EXT4FS_DBG("ERROR (goal == 0)");
    410410                return ENOSPC;
    411411        }
     
    413413        ext4_superblock_t *sb = inode_ref->fs->superblock;
    414414
    415         // Load block group number for goal and relative index
     415        /* Load block group number for goal and relative index */
    416416        uint32_t block_group = ext4_balloc_get_bgid_of_block(sb, goal);
    417417        uint32_t index_in_group = ext4_balloc_blockaddr2_index_in_group(sb, goal);
    418418
    419419
    420         // Load block group reference
     420        /* Load block group reference */
    421421        ext4_block_group_ref_t *bg_ref;
    422422        rc = ext4_filesystem_get_block_group_ref(inode_ref->fs, block_group, &bg_ref);
     
    426426        }
    427427
    428         // Compute indexes
     428        /* Compute indexes */
    429429        uint32_t first_in_group =
    430430                        ext4_balloc_get_first_data_block_in_group(sb,
     
    438438        }
    439439
    440         // Load block with bitmap
     440        /* Load block with bitmap */
    441441        bitmap_block_addr = ext4_block_group_get_block_bitmap(bg_ref->block_group,
    442442                        sb);
     
    449449        }
    450450
    451         // Check if goal is free
     451        /* Check if goal is free */
    452452        if (ext4_bitmap_is_free_bit(bitmap_block->data, index_in_group)) {
    453453                ext4_bitmap_set_bit(bitmap_block->data, index_in_group);
     
    472472        }
    473473
    474         // Try to find free block near to goal
     474        /* Try to find free block near to goal */
    475475        for (uint32_t tmp_idx = index_in_group + 1; tmp_idx < end_idx; ++tmp_idx) {
    476476                if (ext4_bitmap_is_free_bit(bitmap_block->data, tmp_idx)) {
     
    492492        }
    493493
    494         // Find free BYTE in bitmap
     494        /* Find free BYTE in bitmap */
    495495        rc = ext4_bitmap_find_free_byte_and_set_bit(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group);
    496496        if (rc == EOK) {
     
    508508        }
    509509
    510         // Find free bit in bitmap
     510        /* Find free bit in bitmap */
    511511        rc = ext4_bitmap_find_free_bit_and_set(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group);
    512512        if (rc == EOK) {
     
    524524        }
    525525
    526         // No free block found yet
     526        /* No free block found yet */
    527527        block_put(bitmap_block);
    528528        ext4_filesystem_put_block_group_ref(bg_ref);
    529529
    530         // Try other block groups
     530        /* Try other block groups */
    531531        uint32_t block_group_count = ext4_superblock_get_block_group_count(sb);
    532532
     
    541541                }
    542542
    543                 // Load block with bitmap
     543                /* Load block with bitmap */
    544544                bitmap_block_addr = ext4_block_group_get_block_bitmap(
    545545                                bg_ref->block_group, sb);
     
    552552                }
    553553
    554                 // Compute indexes
     554                /* Compute indexes */
    555555                first_in_group = ext4_balloc_get_first_data_block_in_group(
    556556                                sb, bg_ref->block_group, bgid);
     
    566566                }
    567567
    568                 // Try to find free byte in bitmap
     568                /* Try to find free byte in bitmap */
    569569                rc = ext4_bitmap_find_free_byte_and_set_bit(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group);
    570570                if (rc == EOK) {
     
    582582                }
    583583
    584                 // Try to find free bit in bitmap
     584                /* Try to find free bit in bitmap */
    585585                rc = ext4_bitmap_find_free_bit_and_set(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group);
    586586                if (rc == EOK) {
     
    601601                ext4_filesystem_put_block_group_ref(bg_ref);
    602602
    603                 // Goto next group
     603                /* Goto next group */
    604604                bgid = (bgid + 1) % block_group_count;
    605605                count--;
     
    609609
    610610success:
    611         ;       // Empty command - because of syntax
     611        ;       /* Empty command - because of syntax */
    612612       
    613613        uint32_t block_size = ext4_superblock_get_block_size(sb);
    614614
    615         // Update superblock free blocks count
     615        /* Update superblock free blocks count */
    616616        uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count(sb);
    617617        sb_free_blocks--;
    618618        ext4_superblock_set_free_blocks_count(sb, sb_free_blocks);
    619619
    620         // Update inode blocks (different block size!) count
     620        /* Update inode blocks (different block size!) count */
    621621        uint64_t ino_blocks = ext4_inode_get_blocks_count(sb, inode_ref->inode);
    622622        ino_blocks += block_size / EXT4_INODE_BLOCK_SIZE;
     
    624624        inode_ref->dirty = true;
    625625
    626         // Update block group free blocks count
     626        /* Update block group free blocks count */
    627627        uint32_t bg_free_blocks = ext4_block_group_get_free_blocks_count(
    628628                        bg_ref->block_group, sb);
     
    652652        ext4_superblock_t *sb = fs->superblock;
    653653
    654         // Compute indexes
     654        /* Compute indexes */
    655655        uint32_t block_group = ext4_balloc_get_bgid_of_block(sb, fblock);
    656656        uint32_t index_in_group = ext4_balloc_blockaddr2_index_in_group(sb, fblock);
    657657
    658         // Load block group reference
     658        /* Load block group reference */
    659659        ext4_block_group_ref_t *bg_ref;
    660660        rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
     
    664664        }
    665665
    666         // Load block with bitmap
     666        /* Load block with bitmap */
    667667        uint32_t bitmap_block_addr = ext4_block_group_get_block_bitmap(
    668668                        bg_ref->block_group, sb);
     
    674674        }
    675675
    676         // Check if block is free
     676        /* Check if block is free */
    677677        *free = ext4_bitmap_is_free_bit(bitmap_block->data, index_in_group);
    678678
    679         // Allocate block if possible
     679        /* Allocate block if possible */
    680680        if (*free) {
    681681                ext4_bitmap_set_bit(bitmap_block->data, index_in_group);
     
    683683        }
    684684
    685         // Release block with bitmap
     685        /* Release block with bitmap */
    686686        rc = block_put(bitmap_block);
    687687        if (rc != EOK) {
    688                 // Error in saving bitmap
     688                /* Error in saving bitmap */
    689689                ext4_filesystem_put_block_group_ref(bg_ref);
    690690                EXT4FS_DBG("error in saving bitmap \%d", rc);
     
    692692        }
    693693
    694         // If block is not free, return
     694        /* If block is not free, return */
    695695        if (!(*free)) {
    696696                goto terminate;
     
    699699        uint32_t block_size = ext4_superblock_get_block_size(sb);
    700700
    701         // Update superblock free blocks count
     701        /* Update superblock free blocks count */
    702702        uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count(sb);
    703703        sb_free_blocks--;
    704704        ext4_superblock_set_free_blocks_count(sb, sb_free_blocks);
    705705
    706         // Update inode blocks count
     706        /* Update inode blocks count */
    707707        uint64_t ino_blocks = ext4_inode_get_blocks_count(sb, inode_ref->inode);
    708708        ino_blocks += block_size / EXT4_INODE_BLOCK_SIZE;
     
    710710        inode_ref->dirty = true;
    711711
    712         // Update block group free blocks count
     712        /* Update block group free blocks count */
    713713        uint32_t free_blocks = ext4_block_group_get_free_blocks_count(
    714714                        bg_ref->block_group, sb);
  • uspace/lib/ext4/libext4_bitmap.c

    r9a487cc r06d85e5  
    7373        uint32_t byte_index;
    7474
    75         // Align index to multiple of 8
     75        /* Align index to multiple of 8 */
    7676        while (((idx % 8) != 0) && (remaining > 0)) {
    7777
     
    8787        }
    8888
    89         // For < 8 bits this check necessary
     89        /* For < 8 bits this check necessary */
    9090        if (remaining == 0) {
    9191                return;
     
    9797        target = bitmap + byte_index;
    9898
    99         // Zero the whole bytes
     99        /* Zero the whole bytes */
    100100        while (remaining >= 8) {
    101101                *target = 0;
     
    108108        assert(remaining < 8);
    109109
    110         // Zero remaining bytes
     110        /* Zero remaining bytes */
    111111        while (remaining != 0) {
    112112
     
    174174        uint32_t idx;
    175175
    176         // Align idx
     176        /* Align idx */
    177177        if (start % 8) {
    178178                idx = start + (8 - (start % 8));
     
    183183        uint8_t *pos = bitmap + (idx / 8);
    184184
    185         // Try to find free byte
     185        /* Try to find free byte */
    186186        while (idx < max) {
    187187
     
    197197        }
    198198
    199         // Free byte not found
     199        /* Free byte not found */
    200200        return ENOSPC;
    201201}
     
    218218        bool byte_part = false;
    219219
    220         // Check the rest of first byte
     220        /* Check the rest of first byte */
    221221        while ((idx % 8) != 0) {
    222222                byte_part = true;
     
    235235        }
    236236
    237         // Check the whole bytes (255 = 11111111 binary)
     237        /* Check the whole bytes (255 = 11111111 binary) */
    238238        while (idx < max) {
    239239
    240240                if ((*pos & 255) != 255) {
    241                         // free bit found
     241                        /* free bit found */
    242242                        break;
    243243                }
     
    247247        }
    248248
    249         // If idx < max, some free bit found
     249        /* If idx < max, some free bit found */
    250250        if (idx < max) {
    251251
    252                 // Check which bit from byte is free
     252                /* Check which bit from byte is free */
    253253                for (uint8_t i = 0; i < 8; ++i) {
    254254                        if ((*pos & (1 << i)) == 0) {
    255                                 // free bit found
     255                                /* free bit found */
    256256                                *pos |=  (1 << i);
    257257                                *index = idx;
     
    262262        }
    263263
    264         // Free bit not found
     264        /* Free bit not found */
    265265        return ENOSPC;
    266266}
  • 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}
  • 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:
  • uspace/lib/ext4/libext4_extent.c

    r9a487cc r06d85e5  
    262262        uint16_t entries_count = ext4_extent_header_get_entries_count(header);
    263263
    264         // Initialize bounds
     264        /* Initialize bounds */
    265265        l = EXT4_EXTENT_FIRST_INDEX(header) + 1;
    266266        r = EXT4_EXTENT_FIRST_INDEX(header) + entries_count - 1;
    267267
    268         // Do binary search
     268        /* Do binary search */
    269269        while (l <= r) {
    270270                m = l + (r - l) / 2;
     
    277277        }
    278278
    279         // Set output value
     279        /* Set output value */
    280280        *index = l - 1;
    281281}
     
    296296
    297297        if (entries_count == 0) {
    298                 // this leaf is empty
     298                /* this leaf is empty */
    299299                *extent = NULL;
    300300                return;
    301301        }
    302302
    303         // Initialize bounds
     303        /* Initialize bounds */
    304304        l = EXT4_EXTENT_FIRST(header) + 1;
    305305        r = EXT4_EXTENT_FIRST(header) + entries_count - 1;
    306306
    307         // Do binary search
     307        /* Do binary search */
    308308        while (l <= r) {
    309309                m = l + (r - l) / 2;
     
    316316        }
    317317
    318         // Set output value
     318        /* Set output value */
    319319        *extent = l - 1;
    320320}
     
    334334        int rc;
    335335
    336         // Compute bound defined by i-node size
     336        /* Compute bound defined by i-node size */
    337337        uint64_t inode_size = ext4_inode_get_size(
    338338                        inode_ref->fs->superblock, inode_ref->inode);
     
    343343        uint32_t last_idx = (inode_size - 1) / block_size;
    344344
    345         // Check if requested iblock is not over size of i-node
     345        /* Check if requested iblock is not over size of i-node */
    346346        if (iblock > last_idx) {
    347347                *fblock = 0;
     
    351351        block_t* block = NULL;
    352352
    353         // Walk through extent tree
     353        /* Walk through extent tree */
    354354        ext4_extent_header_t *header = ext4_inode_get_extent_header(inode_ref->inode);
    355355
    356 //      EXT4FS_DBG("inode = \%u", inode_ref->index);
    357 //      EXT4FS_DBG("count = \%u", ext4_extent_header_get_entries_count(header));
    358 
    359356        while (ext4_extent_header_get_depth(header) != 0) {
    360357
    361                 // Search index in node
     358                /* Search index in node */
    362359                ext4_extent_index_t *index;
    363360                ext4_extent_binsearch_idx(header, &index, iblock);
    364361
    365                 // Load child node and set values for the next iteration
     362                /* Load child node and set values for the next iteration */
    366363                uint64_t child = ext4_extent_index_get_leaf(index);
    367364
     
    378375        }
    379376
    380         // Search extent in the leaf block
     377        /* Search extent in the leaf block */
    381378        ext4_extent_t* extent = NULL;
    382379        ext4_extent_binsearch(header, &extent, iblock);
    383380
    384         // Prevent empty leaf
     381        /* Prevent empty leaf */
    385382        if (extent == NULL) {
    386383                *fblock = 0;
    387384        } else {
    388385
    389 //              EXT4FS_DBG("required = \%u, first = \%u, start = \%u, count = \%u", iblock, ext4_extent_get_first_block(extent), (uint32_t)ext4_extent_get_start(extent), ext4_extent_get_block_count(extent));
    390 
    391                 // Compute requested physical block address
     386                /* Compute requested physical block address */
    392387                uint32_t phys_block;
    393388                uint32_t first = ext4_extent_get_first_block(extent);
    394389                phys_block = ext4_extent_get_start(extent) + iblock - first;
    395390
    396 //              phys_block = ext4_extent_get_start(extent) + iblock;
    397 //              phys_block -= ext4_extent_get_first_block(extent);
    398 
    399391                *fblock = phys_block;
    400392        }
    401393
    402         // Cleanup
     394        /* Cleanup */
    403395        if (block != NULL) {
    404396                block_put(block);
     
    431423        ext4_extent_path_t *tmp_path;
    432424
    433         // Added 2 for possible tree growing
     425        /* Added 2 for possible tree growing */
    434426        tmp_path = malloc(sizeof(ext4_extent_path_t) * (depth + 2));
    435427        if (tmp_path == NULL) {
     
    437429        }
    438430
    439         // Initialize structure for algorithm start
     431        /* Initialize structure for algorithm start */
    440432        tmp_path[0].block = inode_ref->block;
    441433        tmp_path[0].header = eh;
    442434
    443         // Walk through the extent tree
     435        /* Walk through the extent tree */
    444436        uint16_t pos = 0;
    445437        while (ext4_extent_header_get_depth(eh) != 0) {
    446438
    447                 // Search index in index node by iblock
     439                /* Search index in index node by iblock */
    448440                ext4_extent_binsearch_idx(tmp_path[pos].header, &tmp_path[pos].index, iblock);
    449441
     
    453445                assert(tmp_path[pos].index != NULL);
    454446
    455                 // Load information for the next iteration
     447                /* Load information for the next iteration */
    456448                uint64_t fblock = ext4_extent_index_get_leaf(tmp_path[pos].index);
    457449
     
    474466        tmp_path[pos].index = NULL;
    475467
    476     // Find extent in the leaf node
     468    /* Find extent in the leaf node */
    477469        ext4_extent_binsearch(tmp_path[pos].header, &tmp_path[pos].extent, iblock);
    478470
     
    482474
    483475cleanup:
    484         // Put loaded blocks
    485         // From 1 -> 0 is a block with inode data
     476        /* Put loaded blocks
     477         * From 1: 0 is a block with inode data
     478         */
    486479        for (uint16_t i = 1; i < tmp_path->depth; ++i) {
    487480                if (tmp_path[i].block) {
     
    490483        }
    491484
    492         // Destroy temporary data structure
     485        /* Destroy temporary data structure */
    493486        free(tmp_path);
    494487
     
    507500        int rc;
    508501
    509         // Compute number of the first physical block to release
     502        /* Compute number of the first physical block to release */
    510503        uint64_t start = ext4_extent_get_start(extent);
    511504        uint16_t block_count = ext4_extent_get_block_count(extent);
     
    549542        if (ext4_extent_header_get_depth(header)) {
    550543
    551                 // The node is non-leaf, do recursion
     544                /* The node is non-leaf, do recursion */
    552545
    553546                ext4_extent_index_t *idx = EXT4_EXTENT_FIRST_INDEX(header);
    554547
    555                 // Release all subbranches
     548                /* Release all subbranches */
    556549                for (uint32_t i = 0; i < ext4_extent_header_get_entries_count(header); ++i, ++idx) {
    557550                        rc = ext4_extent_release_branch(inode_ref, idx);
     
    563556        } else {
    564557
    565                 // Leaf node reached
     558                /* Leaf node reached */
    566559                ext4_extent_t *ext = EXT4_EXTENT_FIRST(header);
    567560
    568                 // Release all extents and stop recursion
     561                /* Release all extents and stop recursion */
    569562
    570563                for (uint32_t i = 0; i < ext4_extent_header_get_entries_count(header); ++i, ++ext) {
     
    577570        }
    578571
    579         // Release data block where the node was stored
     572        /* Release data block where the node was stored */
    580573
    581574        rc = block_put(block);
     
    600593        int rc = EOK;
    601594
    602         // Find the first extent to modify
     595        /* Find the first extent to modify */
    603596        ext4_extent_path_t *path;
    604597        rc = ext4_extent_find_extent(inode_ref, iblock_from, &path);
     
    607600        }
    608601
    609         // Jump to last item of the path (extent)
     602        /* Jump to last item of the path (extent) */
    610603        ext4_extent_path_t *path_ptr = path;
    611604        while (path_ptr->depth != 0) {
     
    615608        assert(path_ptr->extent != NULL);
    616609
    617         // First extent maybe released partially
     610        /* First extent maybe released partially */
    618611        uint32_t first_iblock = ext4_extent_get_first_block(path_ptr->extent);
    619612        uint32_t first_fblock = ext4_extent_get_start(path_ptr->extent) + iblock_from - first_iblock;
     
    625618                        ext4_extent_get_start(path_ptr->extent) - first_fblock);
    626619
    627         // Release all blocks
     620        /* Release all blocks */
    628621        rc = ext4_balloc_free_blocks(inode_ref, first_fblock, delete_count);
    629622        if (rc != EOK) {
     
    631624        }
    632625
    633         // Correct counter
     626        /* Correct counter */
    634627        block_count -= delete_count;
    635628        ext4_extent_set_block_count(path_ptr->extent, block_count);
    636629
    637         // Initialize the following loop
     630        /* Initialize the following loop */
    638631        uint16_t entries = ext4_extent_header_get_entries_count(path_ptr->header);
    639632        ext4_extent_t *tmp_ext = path_ptr->extent + 1;
    640633        ext4_extent_t *stop_ext = EXT4_EXTENT_FIRST(path_ptr->header) + entries;
    641634
    642         // If first extent empty, release it
     635        /* If first extent empty, release it */
    643636        if (block_count == 0) {
    644637                entries--;
    645638        }
    646639
    647         // Release all successors of the first extent in the same node
     640        /* Release all successors of the first extent in the same node */
    648641        while (tmp_ext < stop_ext) {
    649642                first_fblock = ext4_extent_get_start(tmp_ext);
     
    662655        path_ptr->block->dirty = true;
    663656
    664         // If leaf node is empty, parent entry must be modified
     657        /* If leaf node is empty, parent entry must be modified */
    665658        bool remove_parent_record = false;
    666659
    667         // Don't release root block (including inode data) !!!
     660        /* Don't release root block (including inode data) !!! */
    668661        if ((path_ptr != path) && (entries == 0)) {
    669662                rc = ext4_balloc_free_block(inode_ref, path_ptr->block->lba);
     
    674667        }
    675668
    676         // Jump to the parent
     669        /* Jump to the parent */
    677670        --path_ptr;
    678671
    679         // release all successors in all tree levels
     672        /* Release all successors in all tree levels */
    680673        while (path_ptr >= path) {
    681674                entries = ext4_extent_header_get_entries_count(path_ptr->header);
     
    684677                                EXT4_EXTENT_FIRST_INDEX(path_ptr->header) + entries;
    685678
    686                 // Correct entries count because of changes in the previous iteration
     679                /* Correct entries count because of changes in the previous iteration */
    687680                if (remove_parent_record) {
    688681                        entries--;
    689682                }
    690683
    691                 // Iterate over all entries and release the whole subtrees
     684                /* Iterate over all entries and release the whole subtrees */
    692685                while (index < stop) {
    693686                        rc = ext4_extent_release_branch(inode_ref, index);
     
    702695                path_ptr->block->dirty = true;
    703696
    704                 // Free the node if it is empty
     697                /* Free the node if it is empty */
    705698                if ((entries == 0) && (path_ptr != path)) {
    706699                        rc = ext4_balloc_free_block(inode_ref, path_ptr->block->lba);
     
    709702                        }
    710703
    711                         // Mark parent to be checked
     704                        /* Mark parent to be checked */
    712705                        remove_parent_record = true;
    713706                } else {
     
    720713
    721714cleanup:
    722         // Put loaded blocks
    723         // From 1 -> 0 is a block with inode data
     715        /* Put loaded blocks
     716         * starting from 1: 0 is a block with inode data
     717         */
    724718        for (uint16_t i = 1; i <= path->depth; ++i) {
    725719                if (path[i].block) {
     
    728722        }
    729723
    730         // Destroy temporary data structure
     724        /* Destroy temporary data structure */
    731725        free(path);
    732726
     
    748742                uint32_t iblock)
    749743{
    750         EXT4FS_DBG("");
    751744        int rc;
    752745
     
    756749        uint16_t limit = ext4_extent_header_get_max_entries_count(path_ptr->header);
    757750
    758         // Trivial way - no splitting
     751        /* Trivial way - no splitting */
    759752        if (entries < limit) {
    760                 EXT4FS_DBG("adding extent entry");
    761753
    762754                ext4_extent_header_set_entries_count(path_ptr->header, entries + 1);
     
    773765                        ext4_superblock_get_block_size(inode_ref->fs->superblock);
    774766
    775         // Trivial tree - grow (extents were in root node)
     767        /* Trivial tree - grow (extents were in root node) */
    776768        if (path_ptr == path) {
    777769
     
    793785                memset(block->data, 0, block_size);
    794786
    795                 // Move data from root to the new block
     787                /* Move data from root to the new block */
    796788                memcpy(block->data, inode_ref->inode->blocks,
    797789                                EXT4_INODE_BLOCKS * sizeof(uint32_t));
     
    810802                ext4_extent_header_set_max_entries_count(path_ptr->header, limit);
    811803
    812                 // Modify root (in inode)
     804                /* Modify root (in inode) */
    813805                path->depth = 1;
    814806                path->extent = NULL;
     
    829821        }
    830822
    831         assert(false);
    832 
    833         // start splitting
     823        // TODO !!!
     824//      assert(false);
     825
     826        /* Start splitting */
    834827        uint32_t fblock = 0;
    835828        while (path_ptr > path) {
     
    849842                }
    850843
    851                 // Init block
     844                /* Init block */
    852845                memset(block->data, 0, block_size);
    853846
    854                 // Not modified
     847                /* Not modified */
    855848                block_put(path_ptr->block);
    856849                path_ptr->block = block;
     
    867860        }
    868861
    869         // If splitting reached root node
     862        /* If splitting reached root node */
    870863        if (path_ptr == path) {
    871864
     
    887880                memset(block->data, 0, block_size);
    888881
    889                 // Move data from root to the new block
     882                /* Move data from root to the new block */
    890883                memcpy(block->data, inode_ref->inode->blocks,
    891884                                EXT4_INODE_BLOCKS * sizeof(uint32_t));
     
    904897                ext4_extent_header_set_max_entries_count(path_ptr->header, limit);
    905898
    906                 // Modify root (in inode)
     899                /* Modify root (in inode) */
    907900                path->depth = 1;
    908901                path->extent = NULL;
     
    940933                uint32_t *iblock, uint32_t *fblock)
    941934{
    942         EXT4FS_DBG("");
    943935        int rc = EOK;
    944936
     
    947939        uint32_t block_size = ext4_superblock_get_block_size(sb);
    948940
    949         // Calculate number of new logical block
     941        /* Calculate number of new logical block */
    950942        uint32_t new_block_idx = 0;
    951943        if (inode_size > 0) {
     
    956948        }
    957949
    958         // Load the nearest leaf (with extent)
     950        /* Load the nearest leaf (with extent) */
    959951        ext4_extent_path_t *path;
    960952        rc = ext4_extent_find_extent(inode_ref, new_block_idx, &path);
     
    963955        }
    964956
    965         // Jump to last item of the path (extent)
     957        /* Jump to last item of the path (extent) */
    966958        ext4_extent_path_t *path_ptr = path;
    967959        while (path_ptr->depth != 0) {
     
    969961        }
    970962
    971         // Add new extent to the node if not present
     963        /* Add new extent to the node if not present */
    972964        if (path_ptr->extent == NULL) {
    973965                goto append_extent;
     
    980972        if (block_count < block_limit) {
    981973
    982                 // There is space for new block in the extent
     974                /* There is space for new block in the extent */
    983975
    984976                if (block_count == 0) {
    985977
    986                         // Existing extent is empty
     978                        /* Existing extent is empty */
    987979
    988980                        rc = ext4_balloc_alloc_block(inode_ref, &phys_block);
     
    991983                        }
    992984
    993                         // Initialize extent
     985                        /* Initialize extent */
    994986                        ext4_extent_set_first_block(path_ptr->extent, new_block_idx);
    995987                        ext4_extent_set_start(path_ptr->extent, phys_block);
    996988                        ext4_extent_set_block_count(path_ptr->extent, 1);
    997989
    998                         // Update i-node
     990                        /* Update i-node */
    999991                        ext4_inode_set_size(inode_ref->inode, inode_size + block_size);
    1000992                        inode_ref->dirty = true;
     
    1005997                } else {
    1006998
    1007                         // Existing extent contains some blocks
     999                        /* Existing extent contains some blocks */
    10081000
    10091001                        phys_block = ext4_extent_get_start(path_ptr->extent);
    10101002                        phys_block += ext4_extent_get_block_count(path_ptr->extent);
    10111003
    1012                         // Check if the following block is free for allocation
     1004                        /* Check if the following block is free for allocation */
    10131005                        bool free;
    10141006                        rc = ext4_balloc_try_alloc_block(inode_ref, phys_block, &free);
     
    10181010
    10191011                        if (! free) {
    1020                                 // target is not free, new block must be appended to new extent
     1012                                /* target is not free, new block must be appended to new extent */
    10211013                                goto append_extent;
    10221014                        }
    10231015
    10241016
    1025                         // Update extent
     1017                        /* Update extent */
    10261018                        ext4_extent_set_block_count(path_ptr->extent, block_count + 1);
    10271019
    1028                         // Update i-node
     1020                        /* Update i-node */
    10291021                        ext4_inode_set_size(inode_ref->inode, inode_size + block_size);
    10301022                        inode_ref->dirty = true;
     
    10361028        }
    10371029
    1038 // Append new extent to the tree
     1030/* Append new extent to the tree */
    10391031append_extent:
    10401032
    10411033        phys_block = 0;
    10421034
    1043         // Allocate new data block
     1035        /* Allocate new data block */
    10441036        rc = ext4_balloc_alloc_block(inode_ref, &phys_block);
    10451037        if (rc != EOK) {
     
    10481040        }
    10491041
    1050         // Append extent for new block (includes tree splitting if needed)
     1042        /* Append extent for new block (includes tree splitting if needed) */
    10511043        rc = ext4_extent_append_extent(inode_ref, path, &path_ptr, new_block_idx);
    10521044        if (rc != EOK) {
     
    10551047        }
    10561048
    1057         // Initialize newly created extent
     1049        /* Initialize newly created extent */
    10581050        ext4_extent_set_block_count(path_ptr->extent, 1);
    10591051        ext4_extent_set_first_block(path_ptr->extent, new_block_idx);
    10601052        ext4_extent_set_start(path_ptr->extent, phys_block);
    10611053
    1062         // Update i-node
     1054        /* Update i-node */
    10631055        ext4_inode_set_size(inode_ref->inode, inode_size + block_size);
    10641056        inode_ref->dirty = true;
     
    10681060
    10691061finish:
    1070         // Set return values
     1062        /* Set return values */
    10711063        *iblock = new_block_idx;
    10721064        *fblock = phys_block;
    10731065
    1074         // Put loaded blocks
    1075         // From 1 -> 0 is a block with inode data
     1066        /* Put loaded blocks
     1067         * starting from 1: 0 is a block with inode data
     1068         */
    10761069        for (uint16_t i = 1; i <= path->depth; ++i) {
    10771070                if (path[i].block) {
     
    10801073        }
    10811074
    1082         // Destroy temporary data structure
     1075        /* Destroy temporary data structure */
    10831076        free(path);
    10841077
  • uspace/lib/ext4/libext4_filesystem.c

    r9a487cc r06d85e5  
    5353        fs->device = service_id;
    5454
    55         // Initialize block library (4096 is size of communication channel)
     55        /* Initialize block library (4096 is size of communication channel) */
    5656        rc = block_init(EXCHANGE_SERIALIZE, fs->device, 4096);
    5757        if (rc != EOK) {
     
    6060        }
    6161
    62         // Read superblock from device to memory
     62        /* Read superblock from device to memory */
    6363        ext4_superblock_t *temp_superblock;
    6464        rc = ext4_superblock_read_direct(fs->device, &temp_superblock);
     
    6969        }
    7070
    71         // Read block size from superblock and check
     71        /* Read block size from superblock and check */
    7272        uint32_t block_size = ext4_superblock_get_block_size(temp_superblock);
    7373        if (block_size > EXT4_MAX_BLOCK_SIZE) {
     
    7777        }
    7878
    79         // Initialize block caching by libblock
     79        /* Initialize block caching by libblock */
    8080        rc = block_cache_init(service_id, block_size, 0, CACHE_MODE_WT);
    8181        if (rc != EOK) {
     
    8585        }
    8686
    87         // Compute limits for indirect block levels
     87        /* Compute limits for indirect block levels */
    8888        uint32_t block_ids_per_block = block_size / sizeof(uint32_t);
    8989        fs->inode_block_limits[0] = EXT4_INODE_DIRECT_BLOCK_COUNT;
     
    9696        }
    9797
    98         // Return loaded superblock
     98        /* Return loaded superblock */
    9999        fs->superblock = temp_superblock;
    100100
     
    108108        }
    109109
    110         // Mark system as mounted
     110        /* Mark system as mounted */
    111111        ext4_superblock_set_state(fs->superblock, EXT4_SUPERBLOCK_STATE_ERROR_FS);
    112112        rc = ext4_superblock_write_direct(fs->device, fs->superblock);
     
    131131        int rc = EOK;
    132132
    133         // Write the superblock to the device
     133        /* Write the superblock to the device */
    134134        ext4_superblock_set_state(fs->superblock, EXT4_SUPERBLOCK_STATE_VALID_FS);
    135135        rc = ext4_superblock_write_direct(fs->device, fs->superblock);
    136136
    137         // Release memory space for superblock
     137        /* Release memory space for superblock */
    138138        free(fs->superblock);
    139139
    140         // Finish work with block library
     140        /* Finish work with block library */
    141141        block_fini(fs->device);
    142142
     
    155155        int rc;
    156156
    157         // Check superblock
     157        /* Check superblock */
    158158        rc = ext4_superblock_check_sanity(fs->superblock);
    159159        if (rc != EOK) {
     
    176176int ext4_filesystem_check_features(ext4_filesystem_t *fs, bool *read_only)
    177177{
    178         // Feature flags are present only in higher revisions
     178        /* Feature flags are present only in higher revisions */
    179179        if (ext4_superblock_get_rev_level(fs->superblock) == 0) {
    180180                *read_only = false;
     
    182182        }
    183183
    184         // Check incompatible features - if filesystem has some,
    185         // volume can't be mounted
     184        /* Check incompatible features - if filesystem has some,
     185         * volume can't be mounted
     186         */
    186187        uint32_t incompatible_features;
    187188        incompatible_features = ext4_superblock_get_features_incompatible(fs->superblock);
     
    191192        }
    192193
    193         // Check read-only features, if filesystem has some,
    194         // volume can be mount only in read-only mode
     194        /* Check read-only features, if filesystem has some,
     195         * volume can be mount only in read-only mode
     196         */
    195197        uint32_t compatible_read_only;
    196198        compatible_read_only = ext4_superblock_get_features_read_only(fs->superblock);
     
    216218        int rc;
    217219
    218         // Allocate memory for new structure
     220        /* Allocate memory for new structure */
    219221        ext4_block_group_ref_t *newref = malloc(sizeof(ext4_block_group_ref_t));
    220222        if (newref == NULL) {
     
    222224        }
    223225
    224         // Compute number of descriptors, that fits in one data block
     226        /* Compute number of descriptors, that fits in one data block */
    225227        uint32_t descriptors_per_block = ext4_superblock_get_block_size(fs->superblock)
    226228            / ext4_superblock_get_desc_size(fs->superblock);
    227229
    228         // Block group descriptor table starts at the next block after superblock
     230        /* Block group descriptor table starts at the next block after superblock */
    229231        aoff64_t block_id = ext4_superblock_get_first_data_block(fs->superblock) + 1;
    230232
    231         // Find the block containing the descriptor we are looking for
     233        /* Find the block containing the descriptor we are looking for */
    232234        block_id += bgid / descriptors_per_block;
    233235        uint32_t offset = (bgid % descriptors_per_block) * ext4_superblock_get_desc_size(fs->superblock);
    234236
    235         // Load block with descriptors
     237        /* Load block with descriptors */
    236238        rc = block_get(&newref->block, fs->device, block_id, 0);
    237239        if (rc != EOK) {
     
    240242        }
    241243
    242         // Inititialize in-memory representation
     244        /* Inititialize in-memory representation */
    243245        newref->block_group = newref->block->data + offset;
    244246        newref->fs = fs;
     
    263265                            ext4_block_group_t *bg)
    264266{
    265         // If checksum not supported, 0 will be returned
     267        /* If checksum not supported, 0 will be returned */
    266268        uint16_t crc = 0;
    267269
    268         // Compute the checksum only if the filesystem supports it
     270        /* Compute the checksum only if the filesystem supports it */
    269271        if (ext4_superblock_has_feature_read_only(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
    270272
     
    274276                uint32_t offset = (uint32_t)(checksum - base);
    275277
    276                 // Convert block group index to little endian
     278                /* Convert block group index to little endian */
    277279                uint32_t le_group = host2uint32_t_le(bgid);
    278280
    279                 // Initialization
     281                /* Initialization */
    280282                crc = crc16(~0, sb->uuid, sizeof(sb->uuid));
    281283
    282                 // Include index of block group
     284                /* Include index of block group */
    283285                crc = crc16(crc, (uint8_t *)&le_group, sizeof(le_group));
    284286
    285                 // Compute crc from the first part (stop before checksum field)
     287                /* Compute crc from the first part (stop before checksum field) */
    286288                crc = crc16(crc, (uint8_t *)bg, offset);
    287289
    288                 // Skip checksum
     290                /* Skip checksum */
    289291                offset += sizeof(bg->checksum);
    290292
    291                 // Checksum of the rest of block group descriptor
     293                /* Checksum of the rest of block group descriptor */
    292294                if ((ext4_superblock_has_feature_incompatible(sb, EXT4_FEATURE_INCOMPAT_64BIT)) &&
    293295                        offset < ext4_superblock_get_desc_size(sb)) {
     
    310312        int rc;
    311313
    312         // Check if reference modified
     314        /* Check if reference modified */
    313315        if (ref->dirty) {
    314316
    315                 // Compute new checksum of block group
     317                /* Compute new checksum of block group */
    316318                uint16_t checksum = ext4_filesystem_bg_checksum(
    317319                                ref->fs->superblock, ref->index, ref->block_group);
    318320                ext4_block_group_set_checksum(ref->block_group, checksum);
    319321
    320                 // Mark block dirty for writing changes to physical device
     322                /* Mark block dirty for writing changes to physical device */
    321323                ref->block->dirty = true;
    322324        }
    323325
    324         // Put back block, that contains block group descriptor
     326        /* Put back block, that contains block group descriptor */
    325327        rc = block_put(ref->block);
    326328        free(ref);
     
    341343        int rc;
    342344
    343         // Allocate memory for new structure
     345        /* Allocate memory for new structure */
    344346        ext4_inode_ref_t *newref = malloc(sizeof(ext4_inode_ref_t));
    345347        if (newref == NULL) {
     
    347349        }
    348350
    349         // Compute number of i-nodes, that fits in one data block
     351        /* Compute number of i-nodes, that fits in one data block */
    350352        uint32_t inodes_per_group =
    351353                        ext4_superblock_get_inodes_per_group(fs->superblock);
    352354
    353         /*
    354          * inode numbers are 1-based, but it is simpler to work with 0-based
     355        /* Inode numbers are 1-based, but it is simpler to work with 0-based
    355356         * when computing indices
    356357         */
     
    359360        uint32_t offset_in_group = index % inodes_per_group;
    360361
    361         // Load block group, where i-node is located
     362        /* Load block group, where i-node is located */
    362363        ext4_block_group_ref_t *bg_ref;
    363364        rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
     
    367368        }
    368369
    369         // Load block address, where i-node table is located
     370        /* Load block address, where i-node table is located */
    370371        uint32_t inode_table_start = ext4_block_group_get_inode_table_first_block(
    371372            bg_ref->block_group, fs->superblock);
    372373
    373         // Put back block group reference (not needed more)
     374        /* Put back block group reference (not needed more) */
    374375        rc = ext4_filesystem_put_block_group_ref(bg_ref);
    375376        if (rc != EOK) {
     
    378379        }
    379380
    380         // Compute position of i-node in the block group
     381        /* Compute position of i-node in the block group */
    381382        uint16_t inode_size = ext4_superblock_get_inode_size(fs->superblock);
    382383        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
    383384        uint32_t byte_offset_in_group = offset_in_group * inode_size;
    384385
    385         // Compute block address
     386        /* Compute block address */
    386387        aoff64_t block_id = inode_table_start + (byte_offset_in_group / block_size);
    387388        rc = block_get(&newref->block, fs->device, block_id, 0);
     
    391392        }
    392393
    393         // Compute position of i-node in the data block
     394        /* Compute position of i-node in the data block */
    394395        uint32_t offset_in_block = byte_offset_in_group % block_size;
    395396        newref->inode = newref->block->data + offset_in_block;
    396397
    397         // We need to store the original value of index in the reference
     398        /* We need to store the original value of index in the reference */
    398399        newref->index = index + 1;
    399400        newref->fs = fs;
     
    414415        int rc;
    415416
    416         // Check if reference modified
     417        /* Check if reference modified */
    417418        if (ref->dirty) {
    418419
    419                 // Mark block dirty for writing changes to physical device
     420                /* Mark block dirty for writing changes to physical device */
    420421                ref->block->dirty = true;
    421422        }
    422423
    423         // Put back block, that contains i-node
     424        /* Put back block, that contains i-node */
    424425        rc = block_put(ref->block);
    425426        free(ref);
     
    440441        int rc;
    441442
    442         // Check if newly allocated i-node will be a directory
     443        /* Check if newly allocated i-node will be a directory */
    443444        bool is_dir = false;
    444445        if (flags & L_DIRECTORY) {
     
    446447        }
    447448
    448         // Allocate inode by allocation algorithm
     449        /* Allocate inode by allocation algorithm */
    449450        uint32_t index;
    450451        rc = ext4_ialloc_alloc_inode(fs, &index, is_dir);
     
    453454        }
    454455
    455         // Load i-node from on-disk i-node table
     456        /* Load i-node from on-disk i-node table */
    456457        rc = ext4_filesystem_get_inode_ref(fs, index, inode_ref);
    457458        if (rc != EOK) {
     
    460461        }
    461462
    462         // Initialize i-node
     463        /* Initialize i-node */
    463464        ext4_inode_t *inode = (*inode_ref)->inode;
    464465
    465466        if (is_dir) {
    466467                ext4_inode_set_mode(fs->superblock, inode, EXT4_INODE_MODE_DIRECTORY);
    467                 ext4_inode_set_links_count(inode, 1); // '.' entry
     468                ext4_inode_set_links_count(inode, 1); /* '.' entry */
    468469        } else {
    469470                ext4_inode_set_mode(fs->superblock, inode, EXT4_INODE_MODE_FILE);
     
    482483        ext4_inode_set_generation(inode, 0);
    483484
    484         // Reset blocks array
     485        /* Reset blocks array */
    485486        for (uint32_t i = 0; i < EXT4_INODE_BLOCKS; i++) {
    486487                inode->blocks[i] = 0;
    487488        }
    488489
    489         // Initialize extents if needed
     490        /* Initialize extents if needed */
    490491        if (ext4_superblock_has_feature_incompatible(
    491492                        fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS)) {
     
    493494                ext4_inode_set_flag(inode, EXT4_INODE_FLAG_EXTENTS);
    494495
    495                 // Initialize extent root header
     496                /* Initialize extent root header */
    496497                ext4_extent_header_t *header = ext4_inode_get_extent_header(inode);
    497498                ext4_extent_header_set_depth(header, 0);
     
    522523        ext4_filesystem_t *fs = inode_ref->fs;
    523524
    524         // For extents must be data block destroyed by other way
     525        /* For extents must be data block destroyed by other way */
    525526        if (ext4_superblock_has_feature_incompatible(
    526527                        fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) &&
    527528                                ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) {
    528529
    529                 // Data structures are released during truncate operation...
     530                /* Data structures are released during truncate operation... */
    530531                goto finish;
    531532        }
    532533
    533         // Release all indirect (no data) blocks
    534 
    535         // 1) Single indirect
     534        /* Release all indirect (no data) blocks */
     535
     536        /* 1) Single indirect */
    536537        uint32_t fblock = ext4_inode_get_indirect_block(inode_ref->inode, 0);
    537538        if (fblock != 0) {
     
    548549        uint32_t count = block_size / sizeof(uint32_t);
    549550
    550         // 2) Double indirect
     551        /* 2) Double indirect */
    551552        fblock = ext4_inode_get_indirect_block(inode_ref->inode, 1);
    552553        if (fblock != 0) {
     
    579580
    580581
    581         // 3) Tripple indirect
     582        /* 3) Tripple indirect */
    582583        block_t *subblock;
    583584        fblock = ext4_inode_get_indirect_block(inode_ref->inode, 2);
     
    637638finish:
    638639
    639         // Mark inode dirty for writing to the physical device
     640        /* Mark inode dirty for writing to the physical device */
    640641        inode_ref->dirty = true;
    641642
    642         // Free inode by allocator
     643        /* Free inode by allocator */
    643644        if (ext4_inode_is_type(fs->superblock, inode_ref->inode,
    644645                        EXT4_INODE_MODE_DIRECTORY)) {
     
    667668        ext4_superblock_t *sb = inode_ref->fs->superblock;
    668669
    669         // Check flags, if i-node can be truncated
     670        /* Check flags, if i-node can be truncated */
    670671        if (! ext4_inode_can_truncate(sb, inode_ref->inode)) {
    671672                return EINVAL;
    672673        }
    673674
    674         // If sizes are equal, nothing has to be done.
     675        /* If sizes are equal, nothing has to be done. */
    675676        aoff64_t old_size = ext4_inode_get_size(sb, inode_ref->inode);
    676677        if (old_size == new_size) {
     
    678679        }
    679680
    680         // It's not suppported to make the larger file by truncate operation
     681        /* It's not suppported to make the larger file by truncate operation */
    681682        if (old_size < new_size) {
    682683                return EINVAL;
    683684        }
    684685
    685         // Compute how many blocks will be released
     686        /* Compute how many blocks will be released */
    686687        aoff64_t size_diff = old_size - new_size;
    687688        uint32_t block_size  = ext4_superblock_get_block_size(sb);
     
    700701                                ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) {
    701702
    702                 // Extents require special operation
     703                /* Extents require special operation */
    703704
    704705                rc = ext4_extent_release_blocks_from(inode_ref,
     
    709710        } else {
    710711
    711                 // Release data blocks from the end of file
    712 
    713                 // Starting from 1 because of logical blocks are numbered from 0
     712                /* Release data blocks from the end of file */
     713
     714                /* Starting from 1 because of logical blocks are numbered from 0 */
    714715                for (uint32_t i = 1; i <= diff_blocks_count; ++i) {
    715716                        rc = ext4_filesystem_release_inode_block(inode_ref, old_blocks_count - i);
     
    720721        }
    721722
    722         // Update i-node
     723        /* Update i-node */
    723724        ext4_inode_set_size(inode_ref->inode, new_size);
    724725        inode_ref->dirty = true;
     
    741742        ext4_filesystem_t *fs = inode_ref->fs;
    742743
    743         // For empty file is situation simple
     744        /* For empty file is situation simple */
    744745        if (ext4_inode_get_size(fs->superblock, inode_ref->inode) == 0) {
    745746                *fblock = 0;
     
    749750        uint32_t current_block;
    750751
    751         // Handle i-node using extents
     752        /* Handle i-node using extents */
    752753        if (ext4_superblock_has_feature_incompatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) &&
    753754                        ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) {
     
    766767        ext4_inode_t *inode = inode_ref->inode;
    767768
    768         // Direct block are read directly from array in i-node structure
     769        /* Direct block are read directly from array in i-node structure */
    769770        if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
    770771                current_block = ext4_inode_get_direct_block(inode, (uint32_t)iblock);
     
    773774        }
    774775
    775         // Determine indirection level of the target block
     776        /* Determine indirection level of the target block */
    776777        int level = -1;
    777778        for (int i = 1; i < 4; i++) {
     
    786787        }
    787788
    788         // Compute offsets for the topmost level
     789        /* Compute offsets for the topmost level */
    789790        aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
    790791        current_block = ext4_inode_get_indirect_block(inode, level-1);
    791792        uint32_t offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
    792793
    793         // Sparse file
     794        /* Sparse file */
    794795        if (current_block == 0) {
    795796                *fblock = 0;
     
    804805        while (level > 0) {
    805806
    806                 // Load indirect block
     807                /* Load indirect block */
    807808                rc = block_get(&block, fs->device, current_block, 0);
    808809                if (rc != EOK) {
     
    810811                }
    811812
    812                 // Read block address from indirect block
     813                /* Read block address from indirect block */
    813814                current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]);
    814815
    815                 // Put back indirect block untouched
     816                /* Put back indirect block untouched */
    816817                rc = block_put(block);
    817818                if (rc != EOK) {
     
    819820                }
    820821
    821                 // Check for sparse file
     822                /* Check for sparse file */
    822823                if (current_block == 0) {
    823824                        *fblock = 0;
     
    825826                }
    826827
    827                 // Jump to the next level
     828                /* Jump to the next level */
    828829                level -= 1;
    829830
    830                 // Termination condition - we have address of data block loaded
     831                /* Termination condition - we have address of data block loaded */
    831832                if (level == 0) {
    832833                        break;
    833834                }
    834835
    835                 // Visit the next level
     836                /* Visit the next level */
    836837                block_offset_in_level %= fs->inode_blocks_per_level[level];
    837838                offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
     
    857858        ext4_filesystem_t *fs = inode_ref->fs;
    858859
    859         // Handle inode using extents
     860        /* Handle inode using extents */
    860861        if (ext4_superblock_has_feature_compatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) &&
    861862                        ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) {
    862                 // not reachable !!!
     863                /* not reachable !!! */
    863864                return ENOTSUP;
    864865        }
    865866
    866         // Handle simple case when we are dealing with direct reference
     867        /* Handle simple case when we are dealing with direct reference */
    867868        if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
    868869                ext4_inode_set_direct_block(inode_ref->inode, (uint32_t)iblock, fblock);
     
    871872        }
    872873
    873         // Determine the indirection level needed to get the desired block
     874        /* Determine the indirection level needed to get the desired block */
    874875        int level = -1;
    875876        for (int i = 1; i < 4; i++) {
     
    886887        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
    887888
    888         // Compute offsets for the topmost level
     889        /* Compute offsets for the topmost level */
    889890        aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
    890891        uint32_t current_block = ext4_inode_get_indirect_block(inode_ref->inode, level-1);
     
    894895        block_t *block, *new_block;
    895896
    896         // Is needed to allocate indirect block on the i-node level
     897        /* Is needed to allocate indirect block on the i-node level */
    897898        if (current_block == 0) {
    898899
    899                 // Allocate new indirect block
     900                /* Allocate new indirect block */
    900901                rc = ext4_balloc_alloc_block(inode_ref, &new_block_addr);
    901902                if (rc != EOK) {
     
    903904                }
    904905
    905                 // Update i-node
     906                /* Update i-node */
    906907                ext4_inode_set_indirect_block(inode_ref->inode, level - 1, new_block_addr);
    907908                inode_ref->dirty = true;
    908909
    909                 // Load newly allocated block
     910                /* Load newly allocated block */
    910911                rc = block_get(&new_block, fs->device, new_block_addr, BLOCK_FLAGS_NOREAD);
    911912                if (rc != EOK) {
     
    914915                }
    915916
    916                 // Initialize new block
     917                /* Initialize new block */
    917918                memset(new_block->data, 0, block_size);
    918919                new_block->dirty = true;
    919920
    920                 // Put back the allocated block
     921                /* Put back the allocated block */
    921922                rc = block_put(new_block);
    922923                if (rc != EOK) {
     
    941942                if ((level > 1) && (current_block == 0)) {
    942943
    943                         // Allocate new block
     944                        /* Allocate new block */
    944945                        rc = ext4_balloc_alloc_block(inode_ref, &new_block_addr);
    945946                        if (rc != EOK) {
     
    948949                        }
    949950
    950                         // Load newly allocated block
     951                        /* Load newly allocated block */
    951952                        rc = block_get(&new_block, fs->device, new_block_addr, BLOCK_FLAGS_NOREAD);
    952953                        if (rc != EOK) {
     
    955956                        }
    956957
    957                         // Initialize allocated block
     958                        /* Initialize allocated block */
    958959                        memset(new_block->data, 0, block_size);
    959960                        new_block->dirty = true;
     
    965966                        }
    966967
    967                         // Write block address to the parent
     968                        /* Write block address to the parent */
    968969                        ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(new_block_addr);
    969970                        block->dirty = true;
     
    971972                }
    972973
    973                 // Will be finished, write the fblock address
     974                /* Will be finished, write the fblock address */
    974975                if (level == 1) {
    975976                        ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(fblock);
     
    10141015        ext4_filesystem_t *fs = inode_ref->fs;
    10151016
    1016         // EXTENTS are handled otherwise = there is not support in this function
     1017        /* EXTENTS are handled otherwise = there is not support in this function */
    10171018        assert(! (ext4_superblock_has_feature_incompatible(fs->superblock,
    10181019                        EXT4_FEATURE_INCOMPAT_EXTENTS) &&
     
    10211022        ext4_inode_t *inode = inode_ref->inode;
    10221023
    1023         // Handle simple case when we are dealing with direct reference
     1024        /* Handle simple case when we are dealing with direct reference */
    10241025        if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
    10251026                fblock = ext4_inode_get_direct_block(inode, iblock);
    1026                 // Sparse file
     1027                /* Sparse file */
    10271028                if (fblock == 0) {
    10281029                        return EOK;
     
    10341035
    10351036
    1036         // Determine the indirection level needed to get the desired block
     1037        /* Determine the indirection level needed to get the desired block */
    10371038        int level = -1;
    10381039        for (int i = 1; i < 4; i++) {
     
    10471048        }
    10481049
    1049         // Compute offsets for the topmost level
     1050        /* Compute offsets for the topmost level */
    10501051        aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
    10511052        uint32_t current_block = ext4_inode_get_indirect_block(inode, level-1);
     
    10641065                current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]);
    10651066
    1066                 // Set zero if physical data block address found
     1067                /* Set zero if physical data block address found */
    10671068                if (level == 1) {
    10681069                        ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(0);
     
    10951096        }
    10961097
    1097         // Physical block is not referenced, it can be released
     1098        /* Physical block is not referenced, it can be released */
    10981099
    10991100        return ext4_balloc_free_block(inode_ref, fblock);
     
    11131114        int rc;
    11141115
    1115         // Handle extents separately
     1116        /* Handle extents separately */
    11161117        if (ext4_superblock_has_feature_incompatible(
    11171118                        inode_ref->fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) &&
     
    11241125        ext4_superblock_t *sb = inode_ref->fs->superblock;
    11251126
    1126         // Compute next block index and allocate data block
     1127        /* Compute next block index and allocate data block */
    11271128        uint64_t inode_size = ext4_inode_get_size(sb, inode_ref->inode);
    11281129        uint32_t block_size = ext4_superblock_get_block_size(sb);
    11291130
    1130         // Align size i-node size
     1131        /* Align size i-node size */
    11311132        if ((inode_size % block_size) != 0) {
    11321133                inode_size += block_size - (inode_size % block_size);
    11331134        }
    11341135
    1135         // Logical blocks are numbered from 0
     1136        /* Logical blocks are numbered from 0 */
    11361137        uint32_t new_block_idx = inode_size / block_size;
    11371138
    1138         // Allocate new physical block
     1139        /* Allocate new physical block */
    11391140        uint32_t phys_block;
    11401141        rc =  ext4_balloc_alloc_block(inode_ref, &phys_block);
     
    11431144        }
    11441145
    1145         // Add physical block address to the i-node
     1146        /* Add physical block address to the i-node */
    11461147        rc = ext4_filesystem_set_inode_data_block_index(inode_ref, new_block_idx, phys_block);
    11471148        if (rc != EOK) {
     
    11501151        }
    11511152
    1152         // Update i-node
     1153        /* Update i-node */
    11531154        ext4_inode_set_size(inode_ref->inode, inode_size + block_size);
    11541155        inode_ref->dirty = true;
     
    11731174                        inode_ref->fs->superblock);
    11741175
    1175         // Deletion time is used for holding next item of the list
     1176        /* Deletion time is used for holding next item of the list */
    11761177        ext4_inode_set_deletion_time(inode_ref->inode, next_orphan);
    11771178
    1178         // Head of the list is in the superblock
     1179        /* Head of the list is in the superblock */
    11791180        ext4_superblock_set_last_orphan(
    11801181                        inode_ref->fs->superblock, inode_ref->index);
     
    11961197        int rc;
    11971198
    1198         // Get head of the linked list
     1199        /* Get head of the linked list */
    11991200        uint32_t last_orphan = ext4_superblock_get_last_orphan(
    12001201                        inode_ref->fs->superblock);
     
    12101211        uint32_t next_orphan = ext4_inode_get_deletion_time(current->inode);
    12111212
    1212         // Check if the head is the target
     1213        /* Check if the head is the target */
    12131214        if (last_orphan == inode_ref->index) {
    12141215                ext4_superblock_set_last_orphan(inode_ref->fs->superblock, next_orphan);
    1215 //              ext4_inode_set_deletion_time(inode_ref->inode, 0);
    1216 //              inode_ref->dirty = true;
    12171216                return EOK;
    12181217        }
     
    12201219        bool found = false;
    12211220
    1222         // Walk thourgh the linked list
     1221        /* Walk thourgh the linked list */
    12231222        while (next_orphan != 0) {
    12241223
    1225                 // Found?
     1224                /* Found? */
    12261225                if (next_orphan == inode_ref->index) {
    12271226                        next_orphan = ext4_inode_get_deletion_time(inode_ref->inode);
    12281227                        ext4_inode_set_deletion_time(current->inode, next_orphan);
    1229 //                      ext4_inode_set_deletion_time(inode_ref->inode, 0);
    1230 //                      inode_ref->dirty = true;
    12311228                        current->dirty = true;
    12321229                        found = true;
  • uspace/lib/ext4/libext4_ialloc.c

    r9a487cc r06d85e5  
    9494        ext4_superblock_t *sb = fs->superblock;
    9595
    96         // Compute index of block group and load it
     96        /* Compute index of block group and load it */
    9797        uint32_t block_group = ext4_ialloc_get_bgid_of_inode(sb, index);
    9898
     
    103103        }
    104104
    105         // Load i-node bitmap
     105        /* Load i-node bitmap */
    106106        uint32_t bitmap_block_addr = ext4_block_group_get_inode_bitmap(
    107107                        bg_ref->block_group, sb);
     
    112112        }
    113113
    114         // Free i-node in the bitmap
     114        /* Free i-node in the bitmap */
    115115        uint32_t index_in_group = ext4_ialloc_inode2index_in_group(sb, index);
    116116        ext4_bitmap_free_bit(bitmap_block->data, index_in_group);
    117117        bitmap_block->dirty = true;
    118118
    119         // Put back the block with bitmap
     119        /* Put back the block with bitmap */
    120120        rc = block_put(bitmap_block);
    121121        if (rc != EOK) {
    122                 // Error in saving bitmap
     122                /* Error in saving bitmap */
    123123                ext4_filesystem_put_block_group_ref(bg_ref);
    124124                return rc;
    125125        }
    126126
    127         // If released i-node is a directory, decrement used directories count
     127        /* If released i-node is a directory, decrement used directories count */
    128128        if (is_dir) {
    129129                uint32_t bg_used_dirs = ext4_block_group_get_used_dirs_count(
     
    134134        }
    135135
    136         // Update block group free inodes count
     136        /* Update block group free inodes count */
    137137        uint32_t free_inodes = ext4_block_group_get_free_inodes_count(
    138138                        bg_ref->block_group, sb);
     
    141141                        sb, free_inodes);
    142142
    143         // Set unused i-nodes count if supported
     143        /* Set unused i-nodes count if supported */
    144144        if (ext4_block_group_has_flag(bg_ref->block_group, EXT4_BLOCK_GROUP_INODE_UNINIT)) {
    145145                uint32_t unused_inodes = ext4_block_group_get_itable_unused(
     
    151151        bg_ref->dirty = true;
    152152
    153         // Put back the modified block group
     153        /* Put back the modified block group */
    154154        rc = ext4_filesystem_put_block_group_ref(bg_ref);
    155155        if (rc != EOK) {
     
    157157        }
    158158
    159         // Update superblock free inodes count
     159        /* Update superblock free inodes count */
    160160        uint32_t sb_free_inodes = ext4_superblock_get_free_inodes_count(sb);
    161161        sb_free_inodes++;
     
    185185        uint32_t avg_free_inodes = sb_free_inodes / bg_count;
    186186
    187         // Try to find free i-node in all block groups
     187        /* Try to find free i-node in all block groups */
    188188        while (bgid < bg_count) {
    189189
    190                 // Load block group to check
     190                /* Load block group to check */
    191191                ext4_block_group_ref_t *bg_ref;
    192192                rc = ext4_filesystem_get_block_group_ref(fs, bgid, &bg_ref);
     
    197197                ext4_block_group_t *bg = bg_ref->block_group;
    198198
    199                 // Read necessary values for algorithm
     199                /* Read necessary values for algorithm */
    200200                uint32_t free_blocks = ext4_block_group_get_free_blocks_count(bg, sb);
    201201                uint32_t free_inodes = ext4_block_group_get_free_inodes_count(bg, sb);
    202202                uint32_t used_dirs = ext4_block_group_get_used_dirs_count(bg, sb);
    203203
    204                 // Check if this block group is good candidate for allocation
     204                /* Check if this block group is good candidate for allocation */
    205205                if ((free_inodes >= avg_free_inodes) && (free_blocks > 0)) {
    206206
    207                         // Load block with bitmap
     207                        /* Load block with bitmap */
    208208                        uint32_t bitmap_block_addr =  ext4_block_group_get_inode_bitmap(
    209209                                        bg_ref->block_group, sb);
     
    216216                        }
    217217
    218                         // Try to allocate i-node in the bitmap
     218                        /* Try to allocate i-node in the bitmap */
    219219                        uint32_t inodes_in_group = ext4_superblock_get_inodes_in_group(sb, bgid);
    220220                        uint32_t index_in_group;
     
    222222                                        bitmap_block->data, 0, &index_in_group, inodes_in_group);
    223223
    224                         // Block group has not any free i-node
     224                        /* Block group has not any free i-node */
    225225                        if (rc == ENOSPC) {
    226226                                block_put(bitmap_block);
     
    229229                        }
    230230
    231                         // Free i-node found, save the bitmap
     231                        /* Free i-node found, save the bitmap */
    232232                        bitmap_block->dirty = true;
    233233
     
    237237                        }
    238238
    239                         // Modify filesystem counters
     239                        /* Modify filesystem counters */
    240240                        free_inodes--;
    241241                        ext4_block_group_set_free_inodes_count(bg, sb, free_inodes);
    242242
    243                         // Decrement unused i-nodes counter if supported
     243                        /* Decrement unused i-nodes counter if supported */
    244244                        if (ext4_block_group_has_flag(bg, EXT4_BLOCK_GROUP_INODE_UNINIT)) {
    245245                                uint16_t unused_inodes = ext4_block_group_get_itable_unused(bg, sb);
     
    248248                        }
    249249
    250                         // Increment used directories counter
     250                        /* Increment used directories counter */
    251251                        if (is_dir) {
    252252                                used_dirs++;
     
    254254                        }
    255255
    256                         // Save modified block group
     256                        /* Save modified block group */
    257257                        bg_ref->dirty = true;
    258258
     
    263263                        }
    264264
    265                         // Update superblock
     265                        /* Update superblock */
    266266                        sb_free_inodes--;
    267267                        ext4_superblock_set_free_inodes_count(sb, sb_free_inodes);
    268268
    269                         // Compute the absolute i-nodex number
     269                        /* Compute the absolute i-nodex number */
    270270                        *index = ext4_ialloc_index_in_group2inode(sb, index_in_group, bgid);
    271271
     
    274274                }
    275275
    276                 // Block group not modified, put it and jump to the next block group
     276                /* Block group not modified, put it and jump to the next block group */
    277277                ext4_filesystem_put_block_group_ref(bg_ref);
    278278                ++bgid;
  • uspace/lib/ext4/libext4_inode.c

    r9a487cc r06d85e5  
    266266        if (ext4_superblock_has_feature_read_only(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
    267267
    268                 // 48-bit field
     268                /* 48-bit field */
    269269                uint64_t count = ((uint64_t)uint16_t_le2host(inode->osd2.linux2.blocks_high)) << 32 |
    270270                                uint32_t_le2host(inode->blocks_count_lo);
     
    292292                uint64_t count)
    293293{
    294     // 32-bit maximum
     294    /* 32-bit maximum */
    295295    uint64_t max = 0;
    296296    max = ~max >> 32;
     
    303303    }
    304304
    305     // Check if there can be used huge files (many blocks)
     305    /* Check if there can be used huge files (many blocks) */
    306306    if (!ext4_superblock_has_feature_read_only(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
    307307        return EINVAL;
    308308    }
    309309
    310     // 48-bit maximum
     310    /* 48-bit maximum */
    311311    max = 0;
    312312    max = ~max >> 16;
  • uspace/lib/ext4/libext4_superblock.c

    r9a487cc r06d85e5  
    981981        int rc;
    982982
    983         // Allocated memory for superblock structure
     983        /* Allocated memory for superblock structure */
    984984        void *data = malloc(EXT4_SUPERBLOCK_SIZE);
    985985        if (data == NULL) {
     
    987987        }
    988988
    989         // Read data from block device
     989        /* Read data from block device */
    990990        rc = block_read_bytes_direct(service_id, EXT4_SUPERBLOCK_OFFSET,
    991991            EXT4_SUPERBLOCK_SIZE, data);
     
    996996        }
    997997
    998         // Set output value
     998        /* Set output value */
    999999        (*sb) = data;
    10001000
     
    10141014        uint32_t phys_block_size;
    10151015
    1016         // Load physical block size from block device
     1016        /* Load physical block size from block device */
    10171017        rc = block_get_bsize(service_id, &phys_block_size);
    10181018        if (rc != EOK) {
     
    10201020        }
    10211021
    1022         // Compute address of the first block
     1022        /* Compute address of the first block */
    10231023        uint64_t first_block = EXT4_SUPERBLOCK_OFFSET / phys_block_size;
    1024         // Compute number of block to write
     1024        /* Compute number of block to write */
    10251025        uint32_t block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;
    10261026
    1027         // Check alignment
     1027        /* Check alignment */
    10281028        if (EXT4_SUPERBLOCK_SIZE % phys_block_size) {
    10291029                block_count++;
    10301030        }
    10311031
    1032         // Write data
     1032        /* Write data */
    10331033        return block_write_direct(service_id, first_block, block_count, sb);
    10341034
  • uspace/srv/fs/ext4fs/ext4fs_ops.c

    r9a487cc r06d85e5  
    7676} ext4fs_node_t;
    7777
    78 // Forward declarations of auxiliary functions
     78/* Forward declarations of auxiliary functions */
    7979
    8080static int ext4fs_read_directory(ipc_callid_t, aoff64_t, size_t,
     
    8787static int ext4fs_node_put_core(ext4fs_node_t *);
    8888
    89 // Forward declarations of EXT4 libfs operations.
     89/* Forward declarations of EXT4 libfs operations. */
    9090
    9191static int ext4fs_root_get(fs_node_t **, service_id_t);
     
    106106static service_id_t ext4fs_service_get(fs_node_t *node);
    107107
    108 // Static variables
     108/* Static variables */
    109109
    110110static LIST_INITIALIZE(instance_list);
     
    250250        }
    251251
    252         // Try to find entry
     252        /* Try to find entry */
    253253        ext4_directory_search_result_t result;
    254254        rc = ext4_directory_find_entry(&result, eparent->inode_ref, component);
     
    261261        }
    262262
    263         // Load node from search result
     263        /* Load node from search result */
    264264        uint32_t inode = ext4_directory_entry_ll_get_inode(result.dentry);
    265265        rc = ext4fs_node_get_core(rfn, eparent->instance, inode);
     
    268268        }
    269269
    270         // Destroy search result structure
     270        /* Destroy search result structure */
    271271        rc = ext4_directory_destroy_result(&result);
    272272        if (rc != EOK) {
     
    330330        }
    331331
    332         // Prepare new enode
     332        /* Prepare new enode */
    333333        enode = malloc(sizeof(ext4fs_node_t));
    334334        if (enode == NULL) {
     
    337337        }
    338338
    339         // Prepare new fs_node and initialize
     339        /* Prepare new fs_node and initialize */
    340340        fs_node_t *fs_node = malloc(sizeof(fs_node_t));
    341341        if (fs_node == NULL) {
     
    346346        fs_node_initialize(fs_node);
    347347
    348         // Load i-node from filesystem
     348        /* Load i-node from filesystem */
    349349        ext4_inode_ref_t *inode_ref;
    350350        rc = ext4_filesystem_get_inode_ref(inst->filesystem, index, &inode_ref);
     
    356356        }
    357357
    358         // Initialize enode
     358        /* Initialize enode */
    359359        enode->inode_ref = inode_ref;
    360360        enode->instance = inst;
     
    391391        enode->instance->open_nodes_count--;
    392392
    393         // Put inode back in filesystem
     393        /* Put inode back in filesystem */
    394394        rc = ext4_filesystem_put_inode_ref(enode->inode_ref);
    395395        if (rc != EOK) {
     
    397397        }
    398398
    399         // Destroy data structure
     399        /* Destroy data structure */
    400400        free(enode->fs_node);
    401401        free(enode);
     
    414414int ext4fs_node_open(fs_node_t *fn)
    415415{
    416         // Stateless operation
     416        /* Stateless operation */
    417417        return EOK;
    418418}
     
    460460        int rc;
    461461
    462         // Allocate enode
     462        /* Allocate enode */
    463463        ext4fs_node_t *enode;
    464464        enode = malloc(sizeof(ext4fs_node_t));
     
    467467        }
    468468
    469         // Allocate fs_node
     469        /* Allocate fs_node */
    470470        fs_node_t *fs_node;
    471471        fs_node = malloc(sizeof(fs_node_t));
     
    475475        }
    476476
    477         // Load instance
     477        /* Load instance */
    478478        ext4fs_instance_t *inst;
    479479        rc = ext4fs_instance_get(service_id, &inst);
     
    484484        }
    485485
    486         // Allocate new i-node in filesystem
     486        /* Allocate new i-node in filesystem */
    487487        ext4_inode_ref_t *inode_ref;
    488488        rc = ext4_filesystem_alloc_inode(inst->filesystem, &inode_ref, flags);
     
    493493        }
    494494
    495         // Do some interconnections in references
     495        /* Do some interconnections in references */
    496496        enode->inode_ref = inode_ref;
    497497        enode->instance = inst;
     
    530530        int rc;
    531531
    532         // If directory, check for children
     532        /* If directory, check for children */
    533533        bool has_children;
    534534        rc = ext4fs_has_children(&has_children, fn);
     
    546546        ext4_inode_ref_t *inode_ref = enode->inode_ref;
    547547
    548         // Release data blocks
     548        /* Release data blocks */
    549549        rc = ext4_filesystem_truncate_inode(inode_ref, 0);
    550550        if (rc != EOK) {
     
    553553        }
    554554
    555         // Handle orphans
     555        /* Handle orphans */
     556        // TODO this code should be deleted
    556557//      ext4_filesystem_t *fs = enode->instance->filesystem;
    557558//      uint32_t rev_level = ext4_superblock_get_rev_level(fs->superblock);
     
    564565//      }
    565566
    566         // TODO set real deletion time when it will be supported,
    567         // temporary set fake time
     567        // TODO set real deletion time when it will be supported, temporary set fake time
    568568//      time_t now = time(NULL);
    569569        ext4_inode_set_deletion_time(inode_ref->inode, 0xdeadbeef);
    570570        inode_ref->dirty = true;
    571571
    572         // Free inode
     572        /* Free inode */
    573573        rc = ext4_filesystem_free_inode(inode_ref);
    574574        if (rc != EOK) {
     
    592592        int rc;
    593593
    594         // Check maximum name length
     594        /* Check maximum name length */
    595595        if (strlen(name) > EXT4_DIRECTORY_FILENAME_LEN) {
    596596                return ENAMETOOLONG;
     
    600600        ext4_filesystem_t *fs = parent->instance->filesystem;
    601601
    602         // Add entry to parent directory
     602        /* Add entry to parent directory */
    603603        rc = ext4_directory_add_entry(parent->inode_ref, name, child->inode_ref);
    604604        if (rc != EOK) {
     
    606606        }
    607607
    608         // Fill new dir -> add '.' and '..' entries
     608        /* Fill new dir -> add '.' and '..' entries */
    609609        if (ext4_inode_is_type(fs->superblock, child->inode_ref->inode, EXT4_INODE_MODE_DIRECTORY)) {
    610610
     
    622622                }
    623623
    624                 // Initialize directory index if supported
     624                /* Initialize directory index if supported */
    625625                if (ext4_superblock_has_feature_compatible(
    626626                                fs->superblock, EXT4_FEATURE_COMPAT_DIR_INDEX)) {
     
    670670        }
    671671
    672         // Cannot unlink non-empty node
     672        /* Cannot unlink non-empty node */
    673673        if (has_children) {
    674674                return ENOTEMPTY;
    675675        }
    676676
    677         // Remove entry from parent directory
     677        /* Remove entry from parent directory */
    678678        ext4_inode_ref_t *parent = EXT4FS_NODE(pfn)->inode_ref;
    679679        rc = ext4_directory_remove_entry(parent, name);
     
    682682        }
    683683
    684         // Decrement links count
     684        /* Decrement links count */
    685685        ext4_inode_ref_t * child_inode_ref = EXT4FS_NODE(cfn)->inode_ref;
    686686
     
    688688        lnk_count--;
    689689
    690         // If directory - handle links from parent
     690        /* If directory - handle links from parent */
    691691        if (lnk_count <= 1 && ext4fs_is_directory(cfn)) {
    692692
     
    744744        ext4_filesystem_t *fs = enode->instance->filesystem;
    745745
    746         // Check if node is directory
     746        /* Check if node is directory */
    747747        if (!ext4_inode_is_type(fs->superblock, enode->inode_ref->inode,
    748748            EXT4_INODE_MODE_DIRECTORY)) {
     
    830830        }
    831831
    832         // For regular files return real links count
     832        /* For regular files return real links count */
    833833        return lnkcnt;
    834834}
     
    10551055        }
    10561056
    1057         // Load i-node
     1057        /* Load i-node */
    10581058        ext4_inode_ref_t *inode_ref;
    10591059        rc = ext4_filesystem_get_inode_ref(inst->filesystem, index, &inode_ref);
     
    10631063        }
    10641064
    1065         // Read from i-node by type
     1065        /* Read from i-node by type */
    10661066        if (ext4_inode_is_type(inst->filesystem->superblock, inode_ref->inode,
    10671067                        EXT4_INODE_MODE_FILE)) {
     
    11831183        }
    11841184
    1185         // Prepare return values
     1185        /* Prepare return values */
    11861186        if (found) {
    11871187                *rbytes = next - pos;
     
    13171317        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
    13181318
    1319         // Prevent writing to more than one block
     1319        /* Prevent writing to more than one block */
    13201320        uint32_t bytes = min(len, block_size - (pos % block_size));
    13211321
     
    13281328        uint32_t fblock;
    13291329
    1330         // Load inode
     1330        /* Load inode */
    13311331        ext4_inode_ref_t *inode_ref = enode->inode_ref;
    13321332        rc = ext4_filesystem_get_inode_data_block_index(inode_ref, iblock, &fblock);
     
    13371337        }
    13381338
    1339         // Check for sparse file
     1339        /* Check for sparse file */
    13401340        if (fblock == 0) {
    13411341
     
    13751375        }
    13761376
    1377         // Load target block
     1377        /* Load target block */
    13781378        block_t *write_block;
    13791379        rc = block_get(&write_block, service_id, fblock, flags);
     
    14021402        }
    14031403
    1404         // Do some counting
     1404        /* Do some counting */
    14051405        uint32_t old_inode_size = ext4_inode_get_size(fs->superblock, inode_ref->inode);
    14061406        if (pos + bytes > old_inode_size) {
Note: See TracChangeset for help on using the changeset viewer.