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

Inconsistent fat id and and media type not checked in fsck.fat #164

Open
ghost opened this issue May 28, 2021 · 3 comments
Open

Inconsistent fat id and and media type not checked in fsck.fat #164

ghost opened this issue May 28, 2021 · 3 comments

Comments

@ghost
Copy link

ghost commented May 28, 2021

Grub and some UEFI loaders will not recognise a FAT 32 file system if the media descriptor in the BIOS parameters does not match the least significant 8bits of the fat id in entry 0 (zero) of the file allocation table. However fsck.fat does not warn of this as a potential error. Should fsck be making this check?

@pali
Copy link
Member

pali commented May 28, 2021

It is checked by fsck.fat and there is even (unit) test that fsck.fat can repair media type descriptor in first cluster in file allocation table.

If fsck.fat is not able to repair this inconsistency for some of your filesystems, please provide image of such filesystem so I can look at it and investigate it.

@ghost
Copy link
Author

ghost commented May 28, 2021

I've put a copy of the image here:

https://www.dropbox.com/s/u0kysbkvawyhqe2/fat32.image.bz2?dl=0

this is the output from fsck on fedora 34

fsck.fat 4.2 (2021-01-31)
Checking we can access the last sector of the filesystem
Boot sector contents:
System ID "amst.fat"
Media byte 0xf8 (hard disk)
512 bytes per logical sector
512 bytes per cluster
4 reserved sectors
First FAT starts at byte 2048 (sector 4)
1 FATs, 32 bit entries
2095104 bytes per FAT (= 4092 sectors)
Root directory start at cluster 2 (arbitrary size)
Data area starts at byte 2097152 (sector 4096)
520192 data clusters (266338304 bytes)
63 sectors/track, 255 heads
2048 hidden sectors
524288 sectors total
Reclaiming unconnected clusters.
Checking free cluster summary.
/dev/sdf1: 1 files, 1/520192 clusters

EDIT: file reuploaded to github: fat32.image.gz

@pali
Copy link
Member

pali commented May 28, 2021

Thank you! Now I see where is the issue. fsck.fat code checks that first fat cluster contains valid media type description. But it does not check if this media type descriptor is same as one stored in boot sector. In case media type is invalid, fsck.fat can copy/repair it from boot sector. Seems that all reports for media type was about invalid media type (which implies also that was different from boot sector).

So if there is already requirement not only for validity of media type descriptor but also that it is same, then this type of repair in fsck.fat is something really useful.

If I find some time I can try to prepare patches for it (unless somebody is not faster).

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

No branches or pull requests

1 participant