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

Fix calculation of cluster amount for FAT16 filesystems in FDISK #70

Merged
merged 1 commit into from
Aug 23, 2020

Conversation

Konamiman
Copy link
Owner

The routine that calculates the amount of clusters for a new FAT16 filesystem in FDSIK has a bug that appears when creating a filesystem with a maximum amount of clusters possible: a 16-bit variable overflows and turns into 0 when it should actually be 65536.

This causes the sector count in the boot sector to be higher than the actual size of the filesystem, and thus when writing to an almost full partition a "Disk error writing" error may appear if this is the only partition on the device or the last one. If there are more partitions after the one being written to, those could be overwritten.

This commit fixes this by adding an intermediate calculation that prevents the variable from overflowing.

Fixing existing partitions

A filesystem is at fault if the "big sector count" field in its boot sector (at offset 20h) is higher than the partition size as declared in its partition table entry. Below you can see an example: the partition size is in yellow and the bad sector count is in red.

To fix, it's enough to set the sector count as equal to the partition size.

If partitions aren't fixed it's recommended not to fill them to their maximum capacity, leave about 1MB free to be safe.

image

The routine that calculates the amount of clusters for a new FAT16
filesystem in FDSIK has a bug that appears when creating a filesystem
with a maximum amount of clusters possible: a 16-bit variable overflows
and turns into 0 when it should actually be 65536.

This causes the sector count in the boot sector to be higher than
the actual size of the filesystem, and thus when writing to an almost
full partition a "Disk error writing" error may appear.

This commit fixes this by adding an intermediate calculation that
prevents the variable from overflowing.
@Konamiman Konamiman added this to the v2.1.1 alpha 1 milestone Aug 21, 2020
@Konamiman Konamiman changed the title Fix calculation of cluster amount for FAT16 filesystems in fdisk Fix calculation of cluster amount for FAT16 filesystems in FDISK Aug 21, 2020
@Konamiman Konamiman merged commit 2a358b6 into v2.1 Aug 23, 2020
@Konamiman Konamiman deleted the fix-fat16-cluster-count-in-fdisk branch August 23, 2020 16:00
Konamiman added a commit that referenced this pull request Aug 23, 2020
The routine that calculates the amount of clusters for a new FAT16
filesystem in FDSIK has a bug that appears when creating a filesystem
with a maximum amount of clusters possible: a 16-bit variable overflows
and turns into 0 when it should actually be 65536.

This causes the sector count in the boot sector to be higher than
the actual size of the filesystem, and thus when writing to an almost
full partition a "Disk error writing" error may appear.

This commit fixes this by adding an intermediate calculation that
prevents the variable from overflowing.
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