Changeset 662bd71 in mainline for uspace/lib/ext4/libext4_balloc.c


Ignore:
Timestamp:
2012-04-04T18:05:46Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e7ed26be
Parents:
81092ce
Message:

added support for releasing more blocks in one operation

File:
1 edited

Legend:

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

    r81092ce r662bd71  
    123123        // Update superblock free blocks count
    124124        uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count(sb);
    125         sb_free_blocks--;
     125        sb_free_blocks++;
    126126        ext4_superblock_set_free_blocks_count(sb, sb_free_blocks);
    127127
     
    136136                        bg_ref->block_group, sb);
    137137        free_blocks++;
     138        ext4_block_group_set_free_blocks_count(bg_ref->block_group,
     139                        sb, free_blocks);
     140        bg_ref->dirty = true;
     141
     142        rc = ext4_filesystem_put_block_group_ref(bg_ref);
     143        if (rc != EOK) {
     144                EXT4FS_DBG("error in saving bg_ref \%d", rc);
     145                // TODO error
     146                return rc;
     147        }
     148
     149        return EOK;
     150}
     151
     152int ext4_balloc_free_blocks(ext4_inode_ref_t *inode_ref,
     153                uint32_t first, uint32_t count)
     154{
     155        int rc;
     156
     157        ext4_filesystem_t *fs = inode_ref->fs;
     158        ext4_superblock_t *sb = fs->superblock;
     159
     160        uint32_t block_group_first =
     161                        ext4_balloc_get_bgid_of_block(sb, first);
     162        uint32_t block_group_last =
     163                        ext4_balloc_get_bgid_of_block(sb, first + count);
     164
     165        assert(block_group_first == block_group_last);
     166
     167        ext4_block_group_ref_t *bg_ref;
     168        rc = ext4_filesystem_get_block_group_ref(fs, block_group_first, &bg_ref);
     169        if (rc != EOK) {
     170                EXT4FS_DBG("error in loading bg_ref \%d", rc);
     171                return rc;
     172        }
     173
     174        uint32_t index_in_group_first =
     175                        ext4_balloc_blockaddr2_index_in_group(sb, first);
     176
     177        uint32_t bitmap_block_addr = ext4_block_group_get_block_bitmap(
     178                        bg_ref->block_group, sb);
     179
     180        block_t *bitmap_block;
     181        rc = block_get(&bitmap_block, fs->device, bitmap_block_addr, 0);
     182        if (rc != EOK) {
     183                EXT4FS_DBG("error in loading bitmap \%d", rc);
     184                return rc;
     185        }
     186
     187        ext4_bitmap_free_bits(bitmap_block->data, index_in_group_first, count);
     188
     189        bitmap_block->dirty = true;
     190
     191        rc = block_put(bitmap_block);
     192        if (rc != EOK) {
     193                // Error in saving bitmap
     194                ext4_filesystem_put_block_group_ref(bg_ref);
     195                EXT4FS_DBG("error in saving bitmap \%d", rc);
     196                return rc;
     197        }
     198
     199        uint32_t block_size = ext4_superblock_get_block_size(sb);
     200
     201        // Update superblock free blocks count
     202        uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count(sb);
     203        sb_free_blocks += count;
     204        ext4_superblock_set_free_blocks_count(sb, sb_free_blocks);
     205
     206        // Update inode blocks count
     207        uint64_t ino_blocks = ext4_inode_get_blocks_count(sb, inode_ref->inode);
     208        ino_blocks -= count * (block_size / EXT4_INODE_BLOCK_SIZE);
     209        ext4_inode_set_blocks_count(sb, inode_ref->inode, ino_blocks);
     210        inode_ref->dirty = true;
     211
     212        // Update block group free blocks count
     213        uint32_t free_blocks = ext4_block_group_get_free_blocks_count(
     214                        bg_ref->block_group, sb);
     215        free_blocks += count;
    138216        ext4_block_group_set_free_blocks_count(bg_ref->block_group,
    139217                        sb, free_blocks);
Note: See TracChangeset for help on using the changeset viewer.