Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 4f38ad77 in mainline


Ignore:
Timestamp:
2018-12-12T18:11:04Z (3 years ago)
Author:
Maurizio Lombardi <mlombard@…>
Children:
be912f5
Parents:
c9c1ccd
Message:

libext4: fs creation should support different block sizes, not only 1k

This was not possible before because of some wrong assumptions in
ext4_superblock_get_blocks_in_group() and
ext4_superblock_get_group_backup_blocks()
and hardcoded values in ext4_superblock_create()

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/mkext4/mkext4.c

    rc9c1ccd r4f38ad77  
    159159
    160160        cfg.volume_name = label;
     161        cfg.bsize = 4096;
    161162        (void) nblocks;
    162163
  • uspace/lib/ext4/include/ext4/cfg.h

    rc9c1ccd r4f38ad77  
    5353        /** Volume name encoded as UTF-8 string */
    5454        const char *volume_name;
     55        /** Filesystem block size */
     56        size_t bsize;
    5557} ext4_cfg_t;
    5658
  • uspace/lib/ext4/src/filesystem.c

    rc9c1ccd r4f38ad77  
    714714                /* One for block bitmap one for inode bitmap */
    715715                free_blocks = free_blocks - reserved - 2 - inode_table_blocks;
    716                 if (bg_index == 0)
    717                         ++free_blocks; /* XXX Why? */
    718716
    719717                ext4_block_group_set_free_blocks_count(bg_ref->block_group,
  • uspace/lib/ext4/src/superblock.c

    rc9c1ccd r4f38ad77  
    13151315            ext4_superblock_get_blocks_per_group(sb);
    13161316        uint64_t total_blocks =
    1317             ext4_superblock_get_blocks_count(sb) - 1;
     1317            ext4_superblock_get_blocks_count(sb);
     1318        uint32_t first_block=
     1319            ext4_superblock_get_first_data_block(sb);
    13181320
    13191321        if (bgid < block_group_count - 1)
    13201322                return blocks_per_group;
    13211323        else
    1322                 return (total_blocks - ((block_group_count - 1) * blocks_per_group));
     1324                return (total_blocks - ((block_group_count - 1) * blocks_per_group)) - first_block;
    13231325}
    13241326
     
    14651467                 */
    14661468
    1467                 if (idx == 0 && block_size == 1024) {
    1468                         /*
    1469                          * Special case for first group were the boot block
    1470                          * resides
    1471                          */
    1472                         r++;
    1473                 }
    1474 
    14751469                /* This accounts for the superblock */
    14761470                r++;
     
    15051499        uuid_t uuid;
    15061500        uint32_t cur_ts;
    1507         uint64_t first_block;
     1501        uint64_t first_block = 0;
    15081502        uint64_t fs_blocks;
    15091503        uint32_t blocks_count;
     
    15181512        uint32_t idx;
    15191513        size_t fs_bsize;
     1514        size_t fs_bsize_log;
    15201515        errno_t rc;
    15211516        struct timespec ts;
     
    15331528        cur_ts = ts.tv_sec;
    15341529
    1535         fs_bsize = 1024;
    1536         first_block = 1; /* 1 for 1k block size, 0 otherwise */
     1530        fs_bsize = cfg->bsize;
     1531        switch (fs_bsize) {
     1532                case 1024:
     1533                        first_block = 1;
     1534                        fs_bsize_log = 0;
     1535                        blocks_group = 8192;
     1536                        break;
     1537                case 2048:
     1538                        fs_bsize_log = 1;
     1539                        blocks_group = 8192 * 2;
     1540                        break;
     1541                case 4096:
     1542                        fs_bsize_log = 2;
     1543                        blocks_group = 8192 * 4;
     1544                        break;
     1545                default:
     1546                        return ENOTSUP;
     1547        }
    15371548
    15381549        if (fs_bsize % dev_bsize == 0) {
     
    15431554                fs_blocks = dev_bcnt * (dev_bsize / fs_bsize);
    15441555        }
    1545 
    1546         /* FS blocks per group */
    1547         blocks_group = 8 * fs_bsize;
    15481556
    15491557        /* Inodes per group */
     
    15811589        ext4_superblock_set_free_inodes_count(sb, inodes_count);
    15821590        ext4_superblock_set_first_data_block(sb, first_block);
    1583         /* Block size will be 1024 bytes */
    1584         ext4_superblock_set_log_block_size(sb, 0);
     1591        ext4_superblock_set_log_block_size(sb, fs_bsize_log);
    15851592        /* Fragment size should be equal to block size */
    1586         ext4_superblock_set_log_frag_size(sb, 0);
     1593        ext4_superblock_set_log_frag_size(sb, fs_bsize_log);
    15871594        ext4_superblock_set_blocks_per_group(sb, blocks_group);
    15881595        /* Should be the same as blocks per group. */
     
    16341641        /* Compute free blocks */
    16351642        free_blocks = blocks_count;
    1636         ++free_blocks; // XXX Why?
    16371643        for (idx = 0; idx < ngroups; idx++) {
    16381644                free_blocks -= ext4_superblock_get_group_backup_blocks(sb, idx);
Note: See TracChangeset for help on using the changeset viewer.