tomm / fab-agon-emulator

Agon Light, Agon Light 2, Agon Console8 Emulator for Linux, Windows, any system with libSDL
GNU General Public License v3.0
82 stars 19 forks source link

Inconsistent handling of f_open #52

Open stevesims opened 5 months ago

stevesims commented 5 months ago

It's been observed that the emulator can overwrite files, where on a real Agon you will see an Access denied error being reported.

This applies to saving files from BASIC, and copying or renaming files where the destination file already exists. Other applications that are using the mos_save API are also affected (it is strongly suggested that nano exhibits this behaviour too).

The underlying cause of this seems to incorrect behaviour of the fatfs f_open function.

Specifically when the MOS API uses f_open to create new files up to write them, it sets the flags FA_WRITE and FA_CREATE_NEW. When FA_CREATE_NEW is set and the file already exists, fatfs is supposed to return FR_EXISTS. It seems that in the emulator it must be returning FR_OK.

Essentially it seems that calling f_open with the FA_CREATE_NEW is currently behaving identically as if the FA_CREATE_ALWAYS flag was set, which is incorrect.

stevesims commented 5 months ago

related to this, I believe that f_opendir is succeeding in the emulator for non-existent paths instead of reporting FR_NOPATH