Changeset 528e5b3 in mainline for uspace/lib/ext4/libext4_balloc.c


Ignore:
Timestamp:
2011-11-18T17:06:12Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ae3d4f8
Parents:
d5ba17f
Message:

New bugs solved

File:
1 edited

Legend:

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

    rd5ba17f r528e5b3  
    136136        }
    137137
    138 //      EXT4FS_DBG("released block \%u (idx = \%u)", block_addr, index_in_group);
    139138        return EOK;
    140139}
     
    191190
    192191                goal++;
    193 
    194 //              EXT4FS_DBG("goal = \%u, inode_block_count == \%u", goal, inode_block_count);
    195 
    196192                return goal;
    197193        }
    198 
    199 //      EXT4FS_DBG("Inode has no blocks");
    200194
    201195        // Identify block group of inode
     
    243237        uint32_t allocated_block = 0;
    244238
    245         uint32_t bitmap_block;
    246         block_t *block;
     239        uint32_t bitmap_block_addr;
     240        block_t *bitmap_block;
    247241        uint32_t rel_block_idx = 0;
    248242
     
    258252        uint32_t block_group = ext4_balloc_get_bgid_of_block(fs->superblock, goal);
    259253        uint32_t index_in_group = ext4_balloc_blockaddr2_index_in_group(fs->superblock, goal);
    260 //      EXT4FS_DBG("block_group = \%u, index_in_group = \%u", block_group, index_in_group);
    261 
    262254
    263255
     
    273265                                        bg_ref->block_group, block_group);
    274266
    275         if (index_in_group < first_in_group) {
    276                 index_in_group = first_in_group;
     267        uint32_t first_in_group_index = ext4_balloc_blockaddr2_index_in_group(
     268                        fs->superblock, first_in_group);
     269
     270        if (index_in_group < first_in_group_index) {
     271                index_in_group = first_in_group_index;
    277272        }
    278273
    279274        // Load bitmap
    280         bitmap_block = ext4_block_group_get_block_bitmap(bg_ref->block_group);
    281 
    282         rc = block_get(&block, fs->device, bitmap_block, 0);
     275        bitmap_block_addr = ext4_block_group_get_block_bitmap(bg_ref->block_group);
     276
     277        rc = block_get(&bitmap_block, fs->device, bitmap_block_addr, 0);
    283278        if (rc != EOK) {
    284279                ext4_filesystem_put_block_group_ref(bg_ref);
     
    287282        }
    288283
    289 //      EXT4FS_DBG("bitmap loaded");
    290 
    291284        // Check if goal is free
    292         if (ext4_bitmap_is_free_bit(block->data, index_in_group)) {
    293                 ext4_bitmap_set_bit(block->data, index_in_group);
    294                 block->dirty = true;
    295                 rc = block_put(block);
     285        if (ext4_bitmap_is_free_bit(bitmap_block->data, index_in_group)) {
     286                ext4_bitmap_set_bit(bitmap_block->data, index_in_group);
     287                bitmap_block->dirty = true;
     288                rc = block_put(bitmap_block);
    296289                if (rc != EOK) {
    297290                        // TODO error
     
    308301        uint32_t blocks_in_group = ext4_superblock_get_blocks_in_group(fs->superblock, block_group);
    309302
    310 //      EXT4FS_DBG("index = \%u (goal = \%u), blocks_in_group = \%u", index_in_group, goal, blocks_in_group);
    311 
    312303        uint32_t end_idx = (index_in_group + 63) & ~63;
    313304        if (end_idx > blocks_in_group) {
     
    317308        // Try to find free block near to goal
    318309        for (uint32_t tmp_idx = index_in_group + 1; tmp_idx < end_idx; ++tmp_idx) {
    319                 if (ext4_bitmap_is_free_bit(block->data, tmp_idx)) {
    320 
    321                         ext4_bitmap_set_bit(block->data, tmp_idx);
    322                         block->dirty = true;
    323                         rc = block_put(block);
     310                if (ext4_bitmap_is_free_bit(bitmap_block->data, tmp_idx)) {
     311
     312                        ext4_bitmap_set_bit(bitmap_block->data, tmp_idx);
     313                        bitmap_block->dirty = true;
     314                        rc = block_put(bitmap_block);
    324315                        if (rc != EOK) {
    325316                                // TODO error
     
    330321                                        fs->superblock, tmp_idx, block_group);
    331322
    332 
    333 //                      EXT4FS_DBG("block \%u (idx = \%u) allocated, goal = \%u", allocated_block, tmp_idx, goal);
    334 
    335323                        goto success;
    336324                }
     
    339327
    340328        // Find free BYTE in bitmap
    341 //      EXT4FS_DBG("try find free byte in own BG");
    342         rc = ext4_bitmap_find_free_byte_and_set_bit(block->data, index_in_group, &rel_block_idx, blocks_in_group);
     329        rc = ext4_bitmap_find_free_byte_and_set_bit(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group);
    343330        if (rc == EOK) {
    344                 block->dirty = true;
    345                 rc = block_put(block);
     331                bitmap_block->dirty = true;
     332                rc = block_put(bitmap_block);
    346333                if (rc != EOK) {
    347334                        // TODO error
     
    352339                                fs->superblock, rel_block_idx, block_group);
    353340
    354 //              EXT4FS_DBG("block \%u allocated, index = \%u, goal = \%u", allocated_block, rel_block_idx, goal);
    355 
    356341                goto success;
    357342        }
    358343
    359344        // Find free bit in bitmap
    360         EXT4FS_DBG("find free bit");
    361         rc = ext4_bitmap_find_free_bit_and_set(block->data, index_in_group, &rel_block_idx, blocks_in_group);
     345        rc = ext4_bitmap_find_free_bit_and_set(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group);
    362346        if (rc == EOK) {
    363                 block->dirty = true;
    364                 rc = block_put(block);
     347                bitmap_block->dirty = true;
     348                rc = block_put(bitmap_block);
    365349                if (rc != EOK) {
    366350                        // TODO error
     
    371355                                fs->superblock, rel_block_idx, block_group);
    372356
    373                 EXT4FS_DBG("find free bit: block \%u allocated, index = \%u, goal = \%u", allocated_block, rel_block_idx, goal);
    374 
    375357                goto success;
    376358        }
    377359
    378         block_put(block);
     360        block_put(bitmap_block);
    379361        ext4_filesystem_put_block_group_ref(bg_ref);
    380362
     
    386368
    387369        while (count > 0) {
    388                 EXT4FS_DBG("trying group \%u", bgid);
    389 
    390370                rc = ext4_filesystem_get_block_group_ref(fs, bgid, &bg_ref);
    391371                if (rc != EOK) {
     
    395375
    396376                // Load bitmap
    397                 bitmap_block = ext4_block_group_get_block_bitmap(bg_ref->block_group);
    398 
    399                 rc = block_get(&block, fs->device, bitmap_block, 0);
     377                bitmap_block_addr = ext4_block_group_get_block_bitmap(bg_ref->block_group);
     378
     379                rc = block_get(&bitmap_block, fs->device, bitmap_block_addr, 0);
    400380                if (rc != EOK) {
    401381                        ext4_filesystem_put_block_group_ref(bg_ref);
     
    410390                blocks_in_group = ext4_superblock_get_blocks_in_group(fs->superblock, bgid);
    411391
    412                 if (index_in_group < first_in_group) {
    413                         index_in_group = first_in_group;
    414                 }
    415 
    416 //              EXT4FS_DBG("trying free byte in bg \%u", bgid);
    417                 rc = ext4_bitmap_find_free_byte_and_set_bit(block->data, index_in_group, &rel_block_idx, blocks_in_group);
     392                first_in_group_index = ext4_balloc_blockaddr2_index_in_group(
     393                        fs->superblock, first_in_group);
     394
     395                if (index_in_group < first_in_group_index) {
     396                        index_in_group = first_in_group_index;
     397                }
     398
     399
     400                rc = ext4_bitmap_find_free_byte_and_set_bit(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group);
    418401                if (rc == EOK) {
    419                         block->dirty = true;
    420                         rc = block_put(block);
     402                        bitmap_block->dirty = true;
     403                        rc = block_put(bitmap_block);
    421404                        if (rc != EOK) {
    422405                                // TODO error
     
    427410                                        fs->superblock, rel_block_idx, bgid);
    428411
    429                         EXT4FS_DBG("byte: block \%u allocated, index = \%u, goal = \%u", allocated_block, rel_block_idx, goal);
    430 
    431412                        goto success;
    432413                }
    433414
    434415                // Find free bit in bitmap
    435                 rc = ext4_bitmap_find_free_bit_and_set(block->data, index_in_group, &rel_block_idx, blocks_in_group);
    436 //              EXT4FS_DBG("trying free bit in bg \%u", bgid);
     416                rc = ext4_bitmap_find_free_bit_and_set(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group);
    437417                if (rc == EOK) {
    438                         block->dirty = true;
    439                         rc = block_put(block);
     418                        bitmap_block->dirty = true;
     419                        rc = block_put(bitmap_block);
    440420                        if (rc != EOK) {
    441421                                // TODO error
     
    446426                                        fs->superblock, rel_block_idx, bgid);
    447427
    448                         EXT4FS_DBG("bit: block \%u allocated, index = \%u, goal = \%u", allocated_block, rel_block_idx, goal);
    449 
    450428                        goto success;
    451429                }
     
    453431
    454432                // Next group
    455                 block_put(block);
     433                block_put(bitmap_block);
    456434                ext4_filesystem_put_block_group_ref(bg_ref);
    457435                bgid = (bgid + 1) % block_group_count;
     
    459437        }
    460438
    461         EXT4FS_DBG("No free block found");
    462439        return ENOSPC;
    463440
    464441success:
    465 
    466         ;
    467 //      EXT4FS_DBG("returning block \%u", allocated_block);
    468 
     442        ;       // Empty command - because of syntax
     443       
    469444        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
    470445
     
    486461        ext4_filesystem_put_block_group_ref(bg_ref);
    487462
    488 //      if (goal > 1980)
    489 //              EXT4FS_DBG("block \%u allocated", allocated_block);
    490 
    491463        *fblock = allocated_block;
    492464        return EOK;
Note: See TracChangeset for help on using the changeset viewer.