Skip to content
9 changes: 9 additions & 0 deletions rp/src/emul.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,15 @@ void emul_resetRunnerSession(void) {
runnerLastCdErrno = 0;
runnerLastHasResErrno = false;
runnerLastResErrno = 0;
// The session resets on the Runner's HELLO, which means the ST has cold
// booted and owns nothing: no basepage, no failed unload to report. Keeping
// the mirror across that left the RP certain a program was still loaded, so
// every later load answered 409 and the unload that would have cleared it
// answered 422 -- the ST rightly refuses to Mfree a basepage from a previous
// life (EPIC-13 STORY-08).
runnerPendingBasepage = 0;
runnerLoadHasErrno = false;
runnerLoadErrno = 0;
runnerMeminfoPending = false;
runnerMeminfoHasSnapshot = false;
runnerAdvancedInstalled = false;
Expand Down
7 changes: 6 additions & 1 deletion rp/src/ff/ffconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,12 @@ number.
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
*/

#define FF_FS_LOCK 8
/* 28 = the worst case this firmware can reach at once (EPIC-13 STORY-06):
/ GEMDRIVE_MAX_OPEN_FILES 8 open files, plus GEMDRIVE_MAX_DTAS 16 searches that
/ each keep a DIR open between Fsfirst and Fsnext, plus the HTTP server's
/ HTTP_SERVER_MAX_CONNECTIONS 2 connections holding a FIL and a DIR each.
/ Each entry is a 16-byte FILESEM, so the table costs 448 bytes of .bss. */
#define FF_FS_LOCK 28
/* The option FF_FS_LOCK switches file lock function to control duplicated file
open / and illegal operation to open objects. This option must be 0 when
FF_FS_READONLY / is 1.
Expand Down
17 changes: 13 additions & 4 deletions rp/src/gemdrive.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,9 @@ static void __not_in_flash_func(handleFcreateCall)(uint16_t *payload) {
if (res != FR_OK) {
DPRINTF("GEMDRIVE Fcreate: '%s' -> fr=%d\n", sdPath, (int)res);
releaseFileSlot(slotIdx);
writeAppFreeWord(GEMDRIVE_FCREATE_HANDLE_OFFSET, (uint16_t)-34); // EPTHNF
uint16_t err = (res == FR_TOO_MANY_OPEN_FILES) ? (uint16_t)-35 // ENHNDL
: (uint16_t)-34; // EPTHNF
writeAppFreeWord(GEMDRIVE_FCREATE_HANDLE_OFFSET, err);
return;
}
// Match source: apply the GEMDOS attrib mode via f_chmod immediately
Expand Down Expand Up @@ -976,7 +978,11 @@ static void __not_in_flash_func(handleFopenCall)(uint16_t *payload) {
DPRINTF("GEMDRIVE Fopen: '%s' (mode=%lu) failed (%d)\n", sdPath,
(unsigned long)mode, (int)res);
releaseFileSlot(slotIdx);
writeAppFreeLong(GEMDRIVE_FOPEN_HANDLE_OFFSET, (uint32_t)-33); // EFILNF
// FatFs's lock table is shared with the HTTP server; a full one is out of
// handles, not a missing file (EPIC-13 STORY-06).
uint32_t err = (res == FR_TOO_MANY_OPEN_FILES) ? (uint32_t)-35 // ENHNDL
: (uint32_t)-33; // EFILNF
writeAppFreeLong(GEMDRIVE_FOPEN_HANDLE_OFFSET, err);
return;
}
int handle = handleFromSlotIndex(slotIdx);
Expand Down Expand Up @@ -1262,8 +1268,11 @@ static void __not_in_flash_func(handleFsfirstCall)(uint16_t *payload) {
pattern, (int)res);
releaseDtaSlot(dtaAddr);
// Match md-drives-emulator: EPTHNF (-34) when path doesn't exist,
// EFILNF (-33) when path exists but no entries match.
uint16_t err = (res == FR_NO_PATH) ? 0xFFDE : 0xFFDF;
// EFILNF (-33) when path exists but no entries match. A full lock table
// is neither -- it is out of handles (EPIC-13 STORY-06).
uint16_t err = (res == FR_TOO_MANY_OPEN_FILES) ? 0xFFDD // ENHNDL (-35)
: (res == FR_NO_PATH) ? 0xFFDE
: 0xFFDF;
clearDtaFound(err);
return;
}
Expand Down
Loading
Loading