MEGA65 / mega65-core

MEGA65 FPGA core
Other
238 stars 84 forks source link

Images in sub-folders get unmounted when exiting freezer #729

Open ki-bo opened 10 months ago

ki-bo commented 10 months ago

Test Environment (required) You can use MEGA65INFO to retrieve this.

Describe the bug The currently mounted image gets unmounted if it is located in a sub-directory and freezer is entered and exited again. Everything works fine if the image is located in the root directory.

To Reproduce Steps to reproduce the behavior:

  1. Place a d81 image in a subdirectory on the sd card
  2. Go to freezer
  3. Mount the d81 file from the sub-directory
  4. exit freezer
  5. enter freezer again
  6. exit freezer
  7. Try to access the image (eg. via DIR)
  8. Error "Drive not ready" -> the image is not mounted anymore

Expected behavior Freezer should keep mounted images.

Additional context The problem is in hypervisor which tries to remount the d81 image of the freeze-slot just unfreezed. A comment indicates that this is done to verify whether the image file is still there and hasn't been moved (which is important since a moved file would mean we access random sectors on the sd when writing to the image, which potentially don't belong to the image file anymore). As the directory of the d81 is not saved in the process control block, but just the filename, we can't know in which folder the d81 was when it was mounted. Therefore, just the current folder (which is the root) is actually tried. If the filename is not available in the root, no image will be mounted on exit.

ki-bo commented 10 months ago

This is related to https://github.com/MEGA65/mega65-core/issues/677

ki-bo commented 9 months ago

The only feasible solution will be to store the sector number representing the sub-folder in the FAT structure. The current approach is trying to re-mount the image with the filename saved in the process control block. This can still be done that way, but we first chdir to the directory of the saved FAT cluster. Even if someone changed the SD card in the meantime, it would be no problem if we try to re-mount that image with that filename in the sub-directory. If that succeeds, we at least know there is a valid disk image and we can safely access it. And by doing it that way, this issue is also solved.