Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext4: support bigger blkdev block size #241

Merged
merged 3 commits into from
Feb 24, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions uspace/lib/ext4/src/superblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,8 @@ errno_t ext4_superblock_read_direct(service_id_t service_id, ext4_superblock_t *
*/
errno_t ext4_superblock_write_direct(service_id_t service_id, ext4_superblock_t *sb)
{
void *tmp_sb = sb;

/* Load physical block size from block device */
size_t phys_block_size;
errno_t rc = block_get_bsize(service_id, &phys_block_size);
Expand All @@ -1215,14 +1217,33 @@ errno_t ext4_superblock_write_direct(service_id_t service_id, ext4_superblock_t
uint64_t first_block = EXT4_SUPERBLOCK_OFFSET / phys_block_size;

/* Compute number of block to write */
size_t block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;

/* Check alignment */
if (EXT4_SUPERBLOCK_SIZE % phys_block_size)
block_count++;
size_t block_count;
if (phys_block_size <= EXT4_SUPERBLOCK_SIZE) {
block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;
/* Check alignment */
if (EXT4_SUPERBLOCK_SIZE % phys_block_size)
block_count++;
} else {
block_count = 1;
tmp_sb = malloc(phys_block_size);
if (tmp_sb == NULL)
return ENOMEM;
/* Preserve block data */
rc = block_read_direct(service_id, first_block, 1, tmp_sb);
if (rc != EOK) {
free(tmp_sb);
return rc;
}
void *sb_pos = (uint8_t *)tmp_sb + EXT4_SUPERBLOCK_OFFSET;
memcpy(sb_pos, sb, EXT4_SUPERBLOCK_SIZE);
}

/* Write data */
return block_write_direct(service_id, first_block, block_count, sb);
rc = block_write_direct(service_id, first_block, block_count, tmp_sb);

if (phys_block_size > EXT4_SUPERBLOCK_SIZE)
free(tmp_sb);
return rc;
}

/** Release the memory allocated for the superblock structure
Expand Down