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

[FAT32] fix corruption when appending to empty file #369

Conversation

mooinglemur
Copy link
Collaborator

@mooinglemur mooinglemur commented Oct 5, 2024

When creating a new file, the start cluster in the directory entry is set to all zeroes. However, the context's state is set up so that the first byte written to the file causes the driver to allocate a new cluster.
If no byte is written to the file, this is never changed.

Prior to this change, when opening an existing file, the start cluster was trusted to point to the sector that the file's data began on. Unfortunately since this was the value $00000000, which is an alias for the root directory's start cluster, the next write would clobber the root directory and trash the filesystem entirely.

Rather than unconditionally trusting that the file has data and opening the first cluster, we now handle the case correctly when the opened file's size is 0.

@mooinglemur mooinglemur merged commit 21b52d8 into X16Community:master Oct 5, 2024
1 check passed
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.

1 participant