From 86db573347a775c3e17e7e88a0b24e8ae3136c7c Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Fri, 10 Oct 2025 18:52:13 +0200 Subject: [PATCH] sys.c: in _dos_findfirst set DTA rather than copying from PSP:80h Running prior to this commit, a /K switch with a name at a certain position will write all-blanks into the boot sector loader. If that happens, lDOS instsect will not detect a valid load file name: C:\>sys a: /bootonly /k ldos.com System transferred. C:\>instsect /bo a: Detected FAT12 FS. Keeping original sector loader. Sector valid, FS ID match and proper jump. Type heuristic: "FreeDOS (FreeDOS)" No name detected. Unit selection code not found in sector. Keeping as is. Part info code not found in sector. Keeping as is. Query geometry code not found in sector. Keeping as is. Auto LBA detection (HDD only) found in sector. Keeping as is. Previous geometry: 2 CHS Heads, 18 CHS Sectors, 0 Hidden Writing boot sector to sector. C:\> Running after this commit sets the name as desired: C:\>sys a: /bootonly /k ldos.com System transferred. C:\>instsect /bo a: Detected FAT12 FS. Keeping original sector loader. Sector valid, FS ID match and proper jump. Type heuristic: "FreeDOS (FreeDOS)" 1st name: "LDOS.COM" Unit selection code not found in sector. Keeping as is. Part info code not found in sector. Keeping as is. Query geometry code not found in sector. Keeping as is. Auto LBA detection (HDD only) found in sector. Keeping as is. Previous geometry: 2 CHS Heads, 18 CHS Sectors, 0 Hidden Writing boot sector to sector. C:\> For reference, the libi86 implementation of _dos_findfirst also sets the DTA to the user buffer rather than copying around the resulting search record. So it is likely that Turbo C or Watcom do it similarly to this: https://gitlab.com/tkchia/libi86/-/blob/3ecc4164999a5807c40cf2c159dc94dd07f7df03/host-gcc/dos/dos-findfirst.c#L43 --- sys/sys.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/sys.c b/sys/sys.c index a3ea645..604b8de 100644 --- a/sys/sys.c +++ b/sys/sys.c @@ -197,13 +197,19 @@ int _dos_findfirst(const char *file_name, unsigned int attr, struct find_t *find_tbuf) { union REGS in, out; + struct SREGS sr; + in.h.ah = 0x1A; /* set DTA */ + in.x.dx = FP_OFF(find_tbuf); + sr.ds = FP_SEG(find_tbuf); + intdosx(&in, &out, &sr); in.h.ah = 0x4e; in.x.dx = FP_OFF(file_name); in.x.cx = attr; intdos(&in, &out); if (out.x.cflag) return out.x.ax; - memcpy(find_tbuf, (void *)0x80, sizeof(*find_tbuf)); + /* memcpy(find_tbuf, (void *)0x80, sizeof(*find_tbuf)); */ + /* did set DTA to find_tbuf prior */ return 0; } #else