Hi
Since I use utFAT on the Coldifre V2 and not the V1 I can't offer a direct solution, but you can get a good reference in the FATFS code too. Deleting a file is quite easy to add if there is not yet code available to do it.
For files with short file names you need to locate the file entry (other functions will do this) and then write the first letter of its name to 0xe5 (free directory name). This will mean that the file no longer appears, but its content is still there occupying space.
To delete the content it must be located (the file entry has a reference to the first cluster that it is occupying via the FAT) and then each cluster in the cluster chain freed by marking it either as empty or as dead (the exact method is implementation dependent and can aid in undeletes if not totally removed). This is a modification in the FAT and the data is still there in the clusters (unless it is desired to also delete the cluster content for some security purposes).
Additional details which are probably not directly relevant for a small FAT16 implementation:
- If FAT32 you would need up update the info sector accordingly and, depending on implementation, you may have two coipes of the FAT to keep in sync.
- Deleting long file named files is a bit complicated since also the name is linked in a directory object list and the complete list needs to be deleted, which means running backward through the list (extremely inefficient on a large card...and I believe that Windows will keep a copy of the FAT in RAM so that it can do this without needing to access the card itself - not really practical in embedded systems).
- Deleting a directory means deleting all files in it (one at a time) and then finally deleting the directory. A directory is pretty much a file without any content so the method is practically identical.
For details of FAT in general and utFAT in particular there is a comprehensive guide here: http://www.utasker.com/docs/uTasker/uTasker_utFAT.PDF
This may be available for the V1 in the future but nothing concrete at the moment.
Regards
Mark
www.uTasker.com