Skip to content

Commit

Permalink
Rolled back the change (don't always read before writing) to fat_writ…
Browse files Browse the repository at this point in the history
…e.c in 1c19a3 (05/09/2014).

There have been a couple of cases where data does not seem to get written properly to the USB device, which I once traced to this commit.
I suspect that it is due to the design of scache because it has no way of knowing whether a block has sectors that are in use or not.
As scache caches sectors in blocks of 4096 bytes, isn't it possible for a block in the cache to cross between multiple clusters because a partition may not be aligned to 4096-byte boundaries?
If fat_WriteFile deems that a sector would be entirely replaced, the cache would mark the 4096 bytes that the sector belongs to as "allocated" but will not read in any of its sectors. If there are sectors within that block that should retain their content, that content is lost.
  • Loading branch information
sp193 committed Dec 15, 2016
1 parent 63fa825 commit a9494c2
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions iop/usb/usbhdfsd/src/fat_write.c
Expand Up @@ -2198,12 +2198,7 @@ int fat_writeFile(fat_driver* fatd, fat_dir* fatDir, int* updateClusterIndices,
bufSize = mass_device->sectorSize;
}

/* SP193: By right, the sector's content should be retained if it has already been allocated and is going to be partially written-to.
Since this function wasn't designed to be able to tell allocated sectors from unallocated sectors, assume that all partial writes are to allocated sectors. */
if((bufSize - dataSkip) != mass_device->sectorSize)
ret = READ_SECTOR(fatd->dev, startSector + j, sbuf);
else
ret = ALLOC_SECTOR(fatd->dev, startSector + j, sbuf);
ret = READ_SECTOR(fatd->dev, startSector + j, sbuf);
if (ret < 0) {
XPRINTF("USBHDFSD: Read sector failed ! sector=%u\n", startSector + j);
return bufferPos; //return number of bytes already written
Expand Down

0 comments on commit a9494c2

Please sign in to comment.