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

found a bug in function fat_read and give a fix #5

Open
leo-frank opened this issue Feb 2, 2022 · 0 comments
Open

found a bug in function fat_read and give a fix #5

leo-frank opened this issue Feb 2, 2022 · 0 comments
Assignees
Labels

Comments

@leo-frank
Copy link

Firstly, thanks to the great work of openfat. I am using it in my own project.

Along my work with openfat, I met a error which was caused by bug here:

if((sector % h->fat->sectors_per_cluster) == 0) {

When "sector % h->fat->sectors_per_cluster == 0" is true, we want to get the next cluster, then get the first sector of that cluster. However, this condition is broken when h->fat->first_data_sector is not zero. For example, sector = 208, h->fat->sectors_per_cluster = 4 , h->fat->first_data_sector = 1, where "sector % h->fat->sectors_per_cluster == 0" is true, but we can't say this sector(208) is the end of cluster, right?

so we need to minus the offset. Bug fix seems like this:

uint32 tmpoff = h->fat->first_data_sector % h->fat->sectors_per_cluster;
if (((sector % h->fat->sectors_per_cluster) - tmpoff) == 0) {
  // .....
}

And I test above fix successfuly.

@tmolteno tmolteno self-assigned this Feb 4, 2022
@tmolteno tmolteno added the Bug label Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants