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


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

Most of comments modified by current coding style

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/libext4_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);
Note: See TracChangeset for help on using the changeset viewer.