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

libfatx: Fix corruption when fatx_read size>bytes_per_cluster #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ryzee119
Copy link

@Ryzee119 Ryzee119 commented Oct 22, 2024

Im interacting with libfatx directly reading in a file ~4Mb then doing a CRC.

// Works okay
size_t offset = 0;
do {
  bytes_read = fatx_read(fs, "myfile.bin", offset , 16384, &buffer[offset]);`
  offset  += bytes_read
while (bytes_read > 0);

however

// CRC mismatch
size_t offset = 0;
do {
  bytes_read = fatx_read(fs, "myfile.bin", offset, 16384+1, &buffer[offset]);`
  offset  += bytes_read
while (bytes_read > 0);

We appear to be doing it right in fatx_write()

bytes_to_write = MIN(fs->bytes_per_cluster - cluster_offset, size - total_bytes_written);

This change fixes is.

The root causes it probably closer to doing reads that are not aligned on cluster boundaries.

Partition info below:

Device Path:         /C
  Partition Offset:    0x8ca80000 bytes
  Partition Size:      0x1f400000 bytes
  Volume Id:           5b206ddb
  Bytes per Sector:    512
  # of Sectors:        1024000
  Sectors per Cluster: 32
  # of Clusters:       31996
  Bytes per Cluster:   16384
  FAT Offset:          0x8ca81000 bytes
  FAT Size:            0x10000 bytes
  FAT Type:            16
  Root Cluster:        1
  Cluster Offset:      0x8ca91000 bytes

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