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

Ensure superblock always fits SIMPLEFS_BLOCK_SIZE #49

Merged
merged 1 commit into from
May 7, 2024

Conversation

HotMercury
Copy link
Collaborator

This commit ensures that the padding size always matches the block size defined by SIMPLEFS_BLOCK_SIZE.

Copy link
Collaborator

@jserv jserv left a 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.

@jserv
Copy link
Collaborator

jserv commented May 7, 2024

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.

@HotMercury HotMercury force-pushed the master branch 2 times, most recently from c68ef1a to 0c041d1 Compare May 7, 2024 13:39
@jserv jserv changed the title Refactor struct superblock for improved code clarity. Ensure superblock always fits SIMPLEFS_BLOCK_SIZE May 7, 2024
mkfs.c Outdated Show resolved Hide resolved
mkfs.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@jserv jserv left a 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.

@jserv
Copy link
Collaborator

jserv commented May 7, 2024

_Static_assert is not a macro. It is a keyword in C11.

@jserv
Copy link
Collaborator

jserv commented May 7, 2024

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.
@jserv jserv merged commit d852783 into sysprog21:master May 7, 2024
2 checks passed
@jserv
Copy link
Collaborator

jserv commented May 7, 2024

Thank @HotMercury for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants