Changeset 9faba42 in mainline for uspace/lib/ext4/src/superblock.c


Ignore:
Timestamp:
2025-02-24T11:08:26Z (29 hours ago)
Author:
GitHub <noreply@…>
Branches:
master
Children:
be62ebc
Parents:
32254d6 (diff), 4a3a5a0 (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:
Jiří Zárevúcky <zarevucky.jiri@…> (2025-02-24 11:08:26)
git-committer:
GitHub <noreply@…> (2025-02-24 11:08:26)
Message:

Merge pull request #241 from mcimerman/ext4-big-blkdev-bsize

ext4: support bigger blkdev block size

File:
1 edited

Legend:

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

    r32254d6 r9faba42  
    12151215        uint64_t first_block = EXT4_SUPERBLOCK_OFFSET / phys_block_size;
    12161216
    1217         /* 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++;
    1223 
    1224         /* Write data */
    1225         return block_write_direct(service_id, first_block, block_count, sb);
     1217        if (phys_block_size <= EXT4_SUPERBLOCK_SIZE) {
     1218                /* Superblock is a multiple of physical block sizes */
     1219                size_t block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;
     1220                return block_write_direct(service_id, first_block, block_count, sb);
     1221        }
     1222
     1223        /*
     1224         * Superblock fills only a part of the physical block,
     1225         * but we can only overwrite an entire physical block.
     1226         */
     1227        void *tmp_sb = malloc(phys_block_size);
     1228        if (tmp_sb == NULL)
     1229                return ENOMEM;
     1230
     1231        /* Preserve physical block data */
     1232        rc = block_read_direct(service_id, first_block, 1, tmp_sb);
     1233        if (rc == EOK) {
     1234                /* Write the superblock */
     1235                void *sb_pos = tmp_sb + EXT4_SUPERBLOCK_OFFSET % phys_block_size;
     1236                memcpy(sb_pos, sb, EXT4_SUPERBLOCK_SIZE);
     1237
     1238                /* Write physical block to device */
     1239                rc = block_write_direct(service_id, first_block, 1, tmp_sb);
     1240        }
     1241
     1242        free(tmp_sb);
     1243        return rc;
    12261244}
    12271245
Note: See TracChangeset for help on using the changeset viewer.