Changeset cb747b3 in mainline


Ignore:
Timestamp:
2025-01-27T15:10:46Z (5 days ago)
Author:
Miroslav Cimerman <mc@…>
Children:
ea50e671
Parents:
eff458d
git-author:
Miroslav Cimerman <mc@…> (2025-01-25 18:23:55)
git-committer:
Miroslav Cimerman <mc@…> (2025-01-27 15:10:46)
Message:

ext4: support bigger blkdev block size

Allows ext4 to be used with block devices that have
block size > EXT4_SUPERBLOCK_SIZE (1K).

File:
1 edited

Legend:

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

    reff458d rcb747b3  
    12061206errno_t ext4_superblock_write_direct(service_id_t service_id, ext4_superblock_t *sb)
    12071207{
     1208        void *tmp_sb = sb;
     1209
    12081210        /* Load physical block size from block device */
    12091211        size_t phys_block_size;
     
    12161218
    12171219        /* Compute number of block to write */
    1218         size_t block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;
    1219 
    1220         /* Check alignment */
    1221         if (EXT4_SUPERBLOCK_SIZE % phys_block_size)
    1222                 block_count++;
     1220        size_t block_count;
     1221        if (phys_block_size <= EXT4_SUPERBLOCK_SIZE) {
     1222                block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;
     1223                /* Check alignment */
     1224                if (EXT4_SUPERBLOCK_SIZE % phys_block_size)
     1225                        block_count++;
     1226        } else {
     1227                block_count = 1;
     1228                tmp_sb = malloc(phys_block_size);
     1229                if (tmp_sb == NULL)
     1230                        return ENOMEM;
     1231                /* Preserve block data */
     1232                rc = block_read_direct(service_id, first_block, 1, tmp_sb);
     1233                if (rc != EOK) {
     1234                        free(tmp_sb);
     1235                        return rc;
     1236                }
     1237                void *sb_pos = (uint8_t *)tmp_sb + EXT4_SUPERBLOCK_OFFSET;
     1238                memcpy(sb_pos, sb, EXT4_SUPERBLOCK_SIZE);
     1239        }
    12231240
    12241241        /* Write data */
    1225         return block_write_direct(service_id, first_block, block_count, sb);
     1242        rc = block_write_direct(service_id, first_block, block_count, tmp_sb);
     1243
     1244        if (phys_block_size > EXT4_SUPERBLOCK_SIZE)
     1245                free(tmp_sb);
     1246        return rc;
    12261247}
    12271248
Note: See TracChangeset for help on using the changeset viewer.