Changes in / [f455de0:32254d6] in mainline


Ignore:
File:
1 edited

Legend:

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

    rf455de0 r32254d6  
    12151215        uint64_t first_block = EXT4_SUPERBLOCK_OFFSET / phys_block_size;
    12161216
    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;
     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);
    12441226}
    12451227
Note: See TracChangeset for help on using the changeset viewer.