MEGA65 / mega65-core

MEGA65 FPGA core
Other
239 stars 84 forks source link

mega65-fdisk pre-populated sdcards prone to fragmentation of manually copied .d81 files #670

Closed gurcei closed 1 year ago

gurcei commented 1 year ago

Test Environment (required) Reported by mpryon who I believe is using a standard batch#2 machine

Describe the bug Much is described in mpryon's discord thread (as well as my assessment of root cause), but will copy/paste his steps below anyway

To Reproduce 1) Format brand new SD card on Mega65 and copy files from slot #0 on the mega. 2) Take SD card to linux box, copy on .d81 file to card. 3) Back to Mega65 and yes, the Freezer says d81 is fragmented and refuses to mount. 4) Back to linux to run the defrag. It took several tries. It would say it was done but on subsequent runs, it still claimed the file was fragmented. 5) I copied the .d81 to .d81.bak and ran again. 6) This time it worked and said it defragged both files and a second run of the defrag tool said the directory was fine, no defrag neded. 7) back to M65 and indeeed, the freezer said the file was OK and it mounted and ran.

8) back to linux to copy many more .d81. 9) back to Mega65 and now the freezer says all the files are good. Previously, at step #2, if I copied several .d81 files, Freezer said they were all fragmented.

Expected behavior Manually copying .d81 files onto a freshly formatted/pre-populated sd-card shouldn't instantly result in fragmented files.

gurcei commented 1 year ago

To summarise my findings from the discord thread:

This is why manually copied .d81 files are getting fragmented, portions of them are residing within the gaps between these pre-populated files.

Feel like this is the part that will need to be scrutinised:

Within the fat32_create_contiguous_file() function.

gurcei commented 1 year ago

My goal will be to: