www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/06/26/23:48:23

Date: Tue, 27 Jun 1995 15:11:38 +1100
From: Bill Currie <BILLC AT teleng1 DOT tait DOT co DOT nz>
Subject: Re: Problems opening > 20 files when using FOPEN
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Organization: Tait Electronics Ltd.

There is a way to open more that 20 files under dos (total system
files up to 256 or files=, whichever is less). I not certain of the
details, but what you do is set up an array of 256 file handles
(chars I think) in _DOS_ memory, copy the 20 file handles in the PSP
to the new array and initialize the rest to closed (-1?) you then
update the FD pointer in the PSP to point to the new file handle
table and the FD array size field to reflect the size of the new
array.  I have included the PSP page from HelpPC (David Jurgens) and
marked the relevant fields.

[copied from HelpPC]
                    PSP - DOS Program Segment Prefix Layout

      Offset Size             Description

        00   word       machine code INT 20 instruction (CDh 20h)
        02   word       top of memory in segment (paragraph) form
        04   byte       reserved for DOS, usually 0
        05  5bytes      machine code instruction long call to the DOS
                        function dispatcher (obsolete CP/M)
        06   word       .COM programs bytes available in segment (CP/M)
        0A   dword      INT 22 terminate address;  DOS loader jumps to this
                        address upon exit;  the EXEC function forces a child
                        process to return to the parent by setting this
                        vector to code within the parent (IP,CS)
        0E   dword      INT 23 Ctrl-Break exit address; the original INT 23
                        vector is NOT restored from this pointer (IP,CS)
        12   dword      INT 24 critical error exit address; the original
                        INT 24 vector is NOT restored from this field (IP,CS)
        16   word       parent process segment addr (Undoc. DOS 2.x+)
                        COMMAND.COM has a parent id of zero, or its own PSP
        18  20bytes     file handle array (Undocumented DOS 2.x+); if handle
                        array element is FF then handle is available.  Network
                        redirectors often indicate remotes files by setting
                        these to values between 80-FE.
        2C   word       segment address of the environment, or zero (DOS 2.x+)
        2E   dword      SS:SP on entry to last INT 21 function (Undoc. 2.x+) +
****    32   word       handle array size (Undocumented DOS 3.x+)
****    34   dword      handle array pointer (Undocumented DOS 3.x+)
        38   dword      pointer to previous PSP (deflt FFFF:FFFF, Undoc 3.x+) +
        3C  20bytes     unused in DOS before 4.01  +
        50   3bytes     DOS function dispatcher CDh 21h CBh (Undoc. 3.x+) +
        53   9bytes     unused
        5C  36bytes     default unopened FCB #1 (parts overlayed by FCB #2)
        6C  20bytes     default unopened FCB #2 (overlays part of FCB #1)
        80   byte       count of characters in command tail;  all bytes
                        following command name;  also default DTA (128 bytes)
        81 127bytes     all characters entered after the program name followed
                        by a CR byte



        - offset 5 contains a jump address which is 2 bytes too low for
          PSP's created by the DOS EXEC function in DOS 2.x+  +
        - program name and complete path can be found after the environment
          in DOS versions after 3.0.  See offset 2Ch.

        + see Bibliography for reference to "Undocumented DOS"

This hack has been known for a while and I first encountered it while 
I still used BC++ :(-

Hope this helps
Bill

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019