Microsoft KB Archive/40434

Determining the Number of File Handles Free to an Application ID Number: Q40434

2.x 3.x 4.00 4.01 MS-DOS

Question:

We need to find a way to determine the value of the FILES command contained in the CONFIG.SYS file at system boot time. We need to ensure that the system has been booted with a certain minimum value. Is there a method of calling MS-DOS or examining the MS-DOS memory space to determine what this parameter was set at?

Response:

There is no MS-DOS system call for an application to determine the number of file handles (in the FILES statement in the CONFIG.SYS) that were available at boot-up, or are available at the current moment.

An application can look for the file CONFIG.SYS in the boot drive, but the application should not rely on its presence. A feature new to MS-DOS Version 4.00 is the ability to obtain the drive letter the system was booted from. Calling interrupt 21H, with AH=33H and AL=05H, will return the boot drive (A=1, B=2, etc.) in the DL register, if the CF is not set. Refer to the “Microsoft MS-DOS Programmer’s Reference” for more information on this system call. This boot drive information could be useful, but if the drive is a removable drive (there is an IOCtl service that can be made to determine if a drive is removable or fixed), the application cannot be sure that the boot disk is in the drive; the user may have changed the disk.

Examining the MS-DOS memory space is a very nonportable thing to do. The safest and easiest method to determine the number of file handles that are currently available to an application is to open a dummy file multiple times, until the application runs out of handles. The most convenient handle is something that you are SURE exists, such as the console I/O device “CON.” For each dummy file that is successfully opened, increment a count. Then, close all of these dummy file handles.

Related to this discussion is a system service introduced with MS-DOS Version 3.30 that will allow an application to set the maximum upper limit of file handles that the application can open. The default is 20, but this service can be called to allow up to 64K file handles to be made available. For more information on this service, interrupt 21H, AH=67H, refer to the “Microsoft MS-DOS Programmer’s Reference.”