MEGA65 / mega65-core

MEGA65 FPGA core
Other
245 stars 88 forks source link

Virtual disk DOS same-device "copy" command allows same source and filename once #842

Open dansanderson opened 1 month ago

dansanderson commented 1 month ago

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

Describe the bug Migrated from https://github.com/MEGA65/mega65-rom-public/issues/174 filed against the ROM. This is actually a bug in the virtual disk driver.

The DOS "copy" command can duplicate a file on the same disk by providing the original file name and the new file name. If the new file name exists, including in the case where the new file name is the same as the original file name, DOS returns a File Exists error.

This does not work correctly for D81 disk images and the internal floppy drive. When the new name is the same as the original name, the virtual disk device will allow duplicating the file into a new entry with the same name the first time. It only reports File Exists when this process is repeated.

To Reproduce This was noticed with the BASIC COPY command, but it can also be reproduced by issuing the "C" command directly to the device command channel. The BASIC COPY command delegates to the device DOS for same-device copies.

  1. Mount a D81 disk image (MOUNT "DISK.D81"), or mount the internal floppy drive with a disk inserted (MOUNT), on unit 8.
  2. Create a file, e.g. 10 PRINT "HI" / DSAVE "TEST". Use DIR to confirm that only one copy of this file appears in the directory.
  3. COPY "TEST" TO "TEST"

Expected: The command prints a File Exists disk error, and does not perform the copy. Actual: The command succeeds. DIR reports that there are two copies of the file with the same name on the disk. Repeating step #3 subsequently has the expected behavior.

This can also be reproduced by issuing a command to the disk command channel: OPEN 15,8,15,"C0:TEST=TEST"

I confirmed that this does not happen on an external IEC disk drive, e.g. OPEN 15,11,15,"C0:TEST=TEST" returned the File Exists error the first time.