-
Notifications
You must be signed in to change notification settings - Fork 93
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
Ensure superblock always fits SIMPLEFS_BLOCK_SIZE #49
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Read https://cbea.ms/git-commit/ carefully and rework the git commit message.
In the commit message, instead of stating that "This commit ensures...," you should explain the issues or limitations present in the current implementation, such as poor cache locality. Additionally, if the proposed changes aim to enhance performance and/or improve the memory layout, utilize the term "improve" in the git commit message to accurately reflect the intended improvements. |
c68ef1a
to
0c041d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the generated file mkfs
.
|
Consider the following changes: --- a/mkfs.c
+++ b/mkfs.c
@@ -17,6 +17,8 @@ struct superblock {
};
};
+_Static_assert(sizeof(struct superblock) == SIMPLEFS_BLOCK_SIZE);
+
/**
* DIV_ROUND_UP - round up a division
* @n: dividend
@@ -239,7 +241,6 @@ static int write_data_blocks(int fd, struct superblock *sb)
int main(int argc, char **argv)
{
- _Static_assert(sizeof(struct superblock) == SIMPLEFS_BLOCK_SIZE);
if (argc != 2) {
fprintf(stderr, "Usage: %s disk\n", argv[0]);
return EXIT_FAILURE; In git commit message, you should explain why union does matter. |
In current implementation, the struct superblock used padding via subtraction to match the SIMPLEFS_BLOCK_SIZE, which could lead to the need for recalculating the padding when the data structure changed. This commit introduces a union that allocates the largest size among its members to set the struct superblock size, ensuring that it is at least SIMPLEFS_BLOCK_SIZE. Additionally, it utilizes the _Static_assert keyword to verify whether the size matches SIMPLEFS_BLOCK_SIZE.
Thank @HotMercury for contributing! |
This commit ensures that the padding size always matches the block size defined by SIMPLEFS_BLOCK_SIZE.