[alt.msdos.programmer] ms-dos FILES=fd in config.sys parameter

curtin@cbnewse.ATT.COM (C.S.Curtin) (03/04/90)

i am having a problem using MS-DOS 4.01 with the number of file
descriptors available. i changed config.sys to files=100 but cannot
get ms-dos to exceed 20 (the pre-dos3.3 maximum).  i wrote a small
test program in msc5.1 to see the difference of changing my
config.sys and still cannot exceed the 20 open files.

is there a way for dos to tell me the current maximum number of
file descriptors available? (while ms-dos is running?)
(i know that you can "type c:\config.sys", but is there any other
way to dump the max_index_length of the fd table?)

in the example program the file being opened is the same one, i had a
version that in each loop created a unique file name. this version
obtained the same results.

please reply via e-mail, i will summarize if enough interest.

any help is greatly appreciated, thanks!

craig curtin
/\/\/\/\/\/\/\/\/\/\/\ fd.c /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
#include <stdio.h>
#include <fcntl.h>    	/* for open flags */
#include <sys/types.h>	/* needed for  stat.h */
#include <sys/stat.h>	/* needed for  S_IREAD/S_IWRITE */
void main()
{
int i,fd;
   for (i=0;i<300;i++)
   {
        /* create any old junk file */
	if((fd=open("xx",(int)(O_CREAT|O_TRUNC|O_WRONLY|O_BINARY),
		                                      S_IREAD|S_IWRITE)) < 0)
	{
             /* wow, something caused an error*/
             perror("failed on open");
	     exit();
        }     
        fprintf(stdout,"successfully opened %d\n",fd);
   }
}
/\/\/\/\/\/\/\/\/\/\/\ fd.exe output /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
successfully opened 5
successfully opened 6
successfully opened 7
successfully opened 8
successfully opened 9
successfully opened 10
successfully opened 11
successfully opened 12
successfully opened 13
successfully opened 14
successfully opened 15
successfully opened 16
successfully opened 17
successfully opened 18
successfully opened 19
failed on open:  Too many open files
/\/\/\/\/\/\/\/\/\/\/\ fd.exe output /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
i understand that msc opens fd 0-4 making the first available #5.
(btw: perror() sends output to stderr)

dixon@sagittarius.crd.ge.com (walt dixon) (03/04/90)

In a previous article Craig Curtin writes:

>i am having a problem using MS-DOS 4.01 with the number of file
>descriptors available. i changed config.sys to files=100 but cannot
>get ms-dos to exceed 20 (the pre-dos3.3 maximum).
[text deleted]
>is there a way for dos to tell me the current maximum number of
>file descriptors available? (while ms-dos is running?)
>(i know that you can "type c:\config.sys", but is there any other
>way to dump the max_index_length of the fd table?)

I can't say a whole lot about MS-DOS 4.01.  I can explain what is
going on in the context of DOS 3.x,  and I would be surprised if
things were done appreciably different in DOS 4.x.  DOS maintains
a table in low memory called the System File Table (or SFT).  This
table contains the current file position,  the end of file position,
owner PSP,  reference count,  pointer to the device driver,  status,
and some other information about every file/device opened by handle.
The files= config.sys entry specifies the maximum size of the SFT.

Within the PSP DOS maintains another table named the Job File Table
or JFT.  (Actually the size and address of the JFT must be here;
the default table is also in the PSP).  There is room in the default
JFT for 20 entries.  Indexed by file handle this table contains an
index into the SFT.  Since a program inherits some some handles from
COMMAND.COM,  a program cannot open 20 new files without closing
stdin,  stdout,  etc.

Under DOS 3.3 there is an int 21h request to change the address of the
JFT.  In previous DOS versions one could change the address and size
of the JFT in the PSP to increase the number of open files.  In order
to have more than 20 open file handles,  one must create a new JFT.

When working in a high level language such as C,  there are other data
structures which may limit the number of open files.  In particular
the C runtime library has a structure typically known as an iob for each
file descriptor.  Depending on the implementation of the run time
library,  you may have to do some work to increase the number of these
structures.

The ultimate limit on the number of open files in DOS 3.x was 255 because
the SFT index had to fit into a 1 byte JFT entry.

If you want a more complete description of what is going on,  take a look
at Chapter 10 of "The MS-DOS Papers", (Howard Sams,  1988) and Chapter 4
of "The MS-DOS Developer's Guide,  2nd Edition",  (Howard Sams,  1988).
BTW I am the author of those chapters.  I get no royalties from book sales;
I'm just citing a good reference.

Walt Dixon		{arpa:		dixon@crd.ge.com	}
			{us mail:	ge crd			}
			{		po box 8		}
			{		schenectady, ny 12301	}
			{phone:		518-387-5798		}

Walt Dixon dixon@crd.ge.com