Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!munnari.oz.au!deakin.OZ.AU!rand!rdb From: rdb@rand.mel.cocam.oz.au (Rodney Brown) Newsgroups: comp.os.msdos.programmer Subject: Re: Opening more files in C Message-ID: <182@rand.mel.cocam.oz.au> Date: 4 Mar 91 11:51:41 GMT References: <1991Feb19.043755.1109@cerberus.bhpese.oz.au> Organization: Co-Cam Computer Group, Melbourne, OZ Lines: 104 In article <1991Feb19.043755.1109@cerberus.bhpese.oz.au> georgez@soafy.bhpese.oz.au (George Zarev) writes: > I am currently writing a large program in microsoft C (6.00) and need >to open more files.My program is spread over 4 separate source code files.The >program needs to operate with around 26 files open simultaneously. > I have redefined FOPEN_MAX=40 and > SYS_OPEN =40 and > _NFILES =40. > Also in config.sys I have set > files = 40 >The program runs normally save for the fact that it won't recognise the >new file open limit and still only lets me open the default limit of 20. My understanding of the limits on the number of files handles a process can open on MS-DOS. DOS 2.11 Remaining number of files left from CONFIG FILES = by other processes DOS 3.0 Minimum of above remainder and 20 DOS 3.3 As DOS 3.0 but a process may expand the 20 maximum by using the Set Handle Count function. The MS-DOS Encyclopedia pp 1448-1449 New file-management functions MS-DOS version 3.3 includes two new Interrupt 21H file-management functions: Set Handle Count (Function 67H) and Commit File (Function 68H) Set Handle Count The Set Handle Count function (Interrupt 21H Function 67H) allows a single process to have more than 20 handles for files or devices open simultaneously. Function 67H is invoked by issuing a software interrupt 21H with AH = 67H BX = number of desired handles On return, If function is successful: Carry flag is clear. If function is not successful: Carry flag is set. AX = error code For each process the operating system maintains a table that relates file handle numbers for the process to MS-DOS's internal global table for all open files in the system. In MS-DOS 3.0 and later, the per-process table is ordinarily stored within the reserved area of the program segment prefix (PSP) and has only enough room for 20 handle entries. If 20 or fewer handles are requested in register BX, Function 67H takes no action and returns a success signal. If more than 20 handles are requested however, Function 67H allocates on behalf of the calling program a new block of memory that is large enough to hole the expanded table of handle numbers and then copies the process's old handle table to the new table. Because the function will fail if the system does not have sufficient free memory to allocate the new block most programs need to make a call to Interrupt 21H Function 4AH (Resize Memory Block) to "shrink" their initial memory block allocations before calling Function 67H. Function 67H does not fail if the number requested is larger than the available entries in the system's global table for file and device handles. However a subsequent attempt to open a file or device or to create a new file will fail if all the entries in the system's global file table are in use, even if the requesting process has not used up all its own handles. (The size of the global table is controlled by the FILES entry in the CONFIG.SYS file. See USER COMMANDS:CONFIG.SYS: FILES; PROGRAMMING IN THE MS-DOS ENVIRONMENT: PROGRAMMING FOR MS-DOS: File and Record Management.) Example: Set the maximum handle count for the current process to 30, so that the process can have as many as 25 files or devices open simultaneously (5 of the handles are already expended by the MS-DOS standard devices when the process starts up). Note that a FILES=30 (or greater value) entry in the CONFIG.SYS file also is required for the process to successfully open 30 files or devices. . . . mov ah,67h ; Function 67H = set handle count mov bx,30 ; Maxiumum number of handles. int 21h ; Transfer to MS-DOS jc error ; Jump if function failed. . . . <> If you can justify it's $A105, $US70 cost the MS-DOS Encyclopedia is worth having for this kind of esoterica. I haven't tried this function yet - we are watching for the NFILE? error and closing & reopening files. NB there is nothing to stop you closing some of the 5 standard devices - closing stdprn loses you Ctl-P logging and the Ctl-PrtScn stuff.