Changeset 3c8b0a8 in mainline for uspace/lib/ext4/src/ialloc.c


Ignore:
Timestamp:
2018-12-15T15:48:59Z (7 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4bb4cf88
Parents:
b6d5e31 (diff), 6ea5e7a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Maurizio Lombardi <m.lombardi85@…> (2018-12-15 15:48:59)
git-committer:
GitHub <noreply@…> (2018-12-15 15:48:59)
Message:

Merge pull request #143 from maurizio-lombardi/ext4_fixes_v2

Ext4 fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/src/ialloc.c

    rb6d5e31 r3c8b0a8  
    176176errno_t ext4_ialloc_alloc_inode(ext4_filesystem_t *fs, uint32_t *index, bool is_dir)
    177177{
     178        int pick_first_free = 0;
    178179        ext4_superblock_t *sb = fs->superblock;
    179 
    180         uint32_t bgid = 0;
    181         uint32_t bg_count = ext4_superblock_get_block_group_count(sb);
    182         uint32_t sb_free_inodes = ext4_superblock_get_free_inodes_count(sb);
    183         uint32_t avg_free_inodes = sb_free_inodes / bg_count;
     180        uint32_t bgid;
     181        uint32_t sb_free_inodes;
     182        uint32_t avg_free_inodes;
     183        uint32_t const bg_count = ext4_superblock_get_block_group_count(sb);
     184
     185retry:
     186
     187        bgid = 0;
     188        sb_free_inodes = ext4_superblock_get_free_inodes_count(sb);
     189        avg_free_inodes = sb_free_inodes / bg_count;
    184190
    185191        /* Try to find free i-node in all block groups */
     
    210216                 * blocks.
    211217                 */
    212                 if (((free_inodes >= avg_free_inodes) || (bgid == bg_count - 1)) &&
    213                     (free_blocks > 0)) {
     218                if (((free_inodes >= avg_free_inodes) ||
     219                    (bgid == bg_count - 1) || pick_first_free) && (free_blocks > 0)) {
    214220                        /* Load block with bitmap */
    215221                        uint32_t bitmap_block_addr = ext4_block_group_get_inode_bitmap(
     
    307313        }
    308314
     315        /* Try again with less strict conditions */
     316        if (pick_first_free == 0) {
     317                pick_first_free = 1;
     318                goto retry;
     319        }
     320
    309321        return ENOSPC;
    310322}
Note: See TracChangeset for help on using the changeset viewer.