MEGA65 / mega65-tools

Tools and Utilities for the MEGA65 Retro Computers
GNU General Public License v3.0
28 stars 31 forks source link

MEGA65_FTP: Add a 'defrag' command #52

Open gurcei opened 3 years ago

gurcei commented 3 years ago

A little Discord discussion on this recently:

My thoughts for it are:

1) For a future defrag MYFILE.D81 command, behind the scenes, I'd just be doing a get, delete and put behind the scenes.

2) For the case of trying to put MYFILE.D81 where it already exists on the sd-card in a fragmented state, I've added a function into mega65_ftp.c called is_fragmented(filename) to check if an existing file is fragmented. So the logic here could be:

On upload_file()
{
  If file exists on sd-card then
  {
    If `is_fragmented(filename)` then
      delete existing file
  }
  copy across the new file
}
lydon42 commented 1 year ago

Implemented in: 52a70474 c98499b1 9901cc80

is_fragmented can still be optimized a bit (no need to go through the whole file, if it finds the first non-consecutive cluster, it can return fragmentation directly). And it needs to be used, which is not done yet.

lydon42 commented 2 months ago

So this is no defrag command, but it will not reuse an existing files clusters if it was fragmented, and instead delete it, so that it is recreated in one continues clusterchain.

I think that should solve this issue.