Changeset f455de0 in mainline


Ignore:
Timestamp:
2025-02-13T20:22:38Z (2 days ago)
Author:
GitHub <noreply@…>
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:
Miroslav Cimerman <70661600+mcimerman@…> (2025-02-13 20:22:38)
git-committer:
GitHub <noreply@…> (2025-02-13 20:22:38)
Message:

Merge 4a3a5a0bef135a6de53fbdafff893157b3296753 into 32254d6ae36aa180fa53338ca60684a9c87d7947

File:
1 edited

Legend:

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

    r32254d6 rf455de0  
    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.