[comp.os.msdos.misc] Max files open

elev66@castle.ed.ac.uk (G Gaston) (10/02/90)

Hi there,

I've a quick question concerning the maximum number of files that can be
open at any one time in DOS. No matter what I set "FILES=" in CONFIG.SYS
the maximum files that I can open is 15. Is there any way in which this
can be increased. Apologies if this is a rather noddy question.

Regards
G. Gaston

elev66@castle.ed.ac.uk

kdq@demott.COM (Kevin D. Quitt) (10/03/90)

In article <6548@castle.ed.ac.uk> elev66@castle.ed.ac.uk (G Gaston) writes:
>Hi there,
>
> No matter what I set "FILES=" in CONFIG.SYS
>the maximum files that I can open is 15. Is there any way in which this
>can be increased.

    It rather depends where you're trying to open them.  From a
pre-existing utility?  From C (whose)?  A little more detail will help.

-- 
 _
Kevin D. Quitt         demott!kdq   kdq@demott.com
DeMott Electronics Co. 14707 Keswick St.   Van Nuys, CA 91405-1266
VOICE (818) 988-4975   FAX (818) 997-1190  MODEM (818) 997-4496 PEP last

                96.37% of all statistics are made up.

prk@planet.bt.co.uk (Peter Knight) (10/03/90)

elev66@castle.ed.ac.uk (G Gaston) writes:

>Hi there,

>I've a quick question concerning the maximum number of files that can be
>open at any one time in DOS. No matter what I set "FILES=" in CONFIG.SYS
>the maximum files that I can open is 15. Is there any way in which this
>can be increased. Apologies if this is a rather noddy question.

You do not say if this is a problem you are having with 

1)	A purchased application or
2)	A program that you wrote yourself.

If (1), then there is little you can do about it.

If (2), then there is a gotcha in that the start-up code supplied with
your compiler sets the maximum number of open files.  If you have something
like Microsoft C, then the source for the relevant bits of start-up is 
supplied, and you can modify and re-assemble this.  If not, then you are
largely on your own.


Peter Knight

BT Research

#include <std.disclaimer>

akes@mcshh.hanse.de (Andreas Kessemeier) (10/05/90)

elev66@castle.ed.ac.uk (G Gaston) writes:
>[Question about more then 20 Files in one Process under MSDOS]

The Value of FILE= is not the only Value, which restricts the max. Number
of open Files. There is a 'per Prozess' Table of open Files in the
PSP (Programm Specifikation Block) of an executing Programm. This Table
is initialized to 20 Entrys on Startup. There is not Way to tell MSDOS,
to setup a larger Table, but you can do this on Startup in your Programm.

- At Offset 28 in the PSP there is a Table of 20 Bytes. Each Byte
  has the Value 255, if the File is not open.

- At Offset 56 in the PSP there is a Word containing the maximum
  Number of open Files. In the normal case the Value of this Word is
  20 (see above).

- At Offset 58 in the PSP there is a Doubleword - Pointer to the
  Table of open Files. This Pointer points initially to the above
  mentioned Table.


To expand the Table of open Files, do the following:

- Allocate a new Table, large enough to hold the Number of Entrys you
  want.

- Copy the old Table (all 20 Entrys) into the new Table and initialize
  the remaining Entrys to 255.

- Redirect the Pointer at Offset 58 to your new Table an update the
  Word at Offset 56 to the Size of yout new Table.


Please Note:
	I have never tested this extensively, but it's same Way
	some Network - Shells are setting Things up. I have never
	heard of Problems with that.


OOPS, before i forget: All Numbers are in Dezimal.


Greets,
	Andreas

-->
Andreas Kessemeier 
Smart  : akes@mcshh.hanse.de
Bang   : Need no steenking Bangs!
Spruch : Wenn alles laeuft, dann haben wir irgendwas vergessen (Murphy)

hovdesta@herald.usask.ca (Alfred Hovdestad) (10/06/90)

From article <659@demott.COM>, by kdq@demott.COM (Kevin D. Quitt):
> In article <6548@castle.ed.ac.uk> elev66@castle.ed.ac.uk (G Gaston) writes:
>>Hi there,
>>
>> No matter what I set "FILES=" in CONFIG.SYS
>>the maximum files that I can open is 15. Is there any way in which this
>>can be increased.
> 
It also depends on your DOS version.  Some versions of DOS (as recently
as 3.20) allow FILES=[>20] but in reality could only accomodate 20
files.  After allowing 5 for stdin, stdout, stderr, com1 and lpt1, you
are left with 15.  Your best bet would be to upgrade your version of
DOS.

Ralf.Brown@B.GP.CS.CMU.EDU (10/06/90)

In article <1990Oct5.223922.2798@herald.usask.ca>, hovdesta@herald.usask.ca (Alfred Hovdestad) wrote:
}From article <659@demott.COM>, by kdq@demott.COM (Kevin D. Quitt):
}> In article <6548@castle.ed.ac.uk> elev66@castle.ed.ac.uk (G Gaston) writes:
}>> No matter what I set "FILES=" in CONFIG.SYS
}>>the maximum files that I can open is 15. Is there any way in which this
}>>can be increased.
}> 
}It also depends on your DOS version.  Some versions of DOS (as recently
}as 3.20) allow FILES=[>20] but in reality could only accomodate 20
}files.  After allowing 5 for stdin, stdout, stderr, com1 and lpt1, you
}are left with 15.  Your best bet would be to upgrade your version of
}DOS.

[if this isn't already in the Frequently-Asked Questions list, it should be]

There are no fewer than THREE different open-file limits: system-wide, per-
process, and runtime-library.

The system-wide limit is set by FILES=, and may be up to 255 in all versions
of DOS since 2.00.  Each time a file is opened, one of the tables reserved
by the FILES= statement is used; multiple file handles may point at the
same table either through inheritance on EXEC or explicit duplication with
the DUP or FORCEDUP INT 21h calls.

The per-process limit is set by the open file table in the process's PSP;
versions 2.xx are hardwired with a 20-byte OFT in the PSP (although it is
possible to get more than 20 open files by messing directly with the OFT).
Versions 3.00 and up contain a pointer and length field, allowing you to
copy the open file table elsewhere and increase its length; versions 3.30 and
up include a documented system call to let you do so.

The runtime-library limit is enforced in languages such as C/C++ which need
to keep information about the file such as text vs. binary mode.  Both Turbo C
and Microsoft C use an array of size 20 for that information, and the only
way to break that limit without recompiling parts of the runtime library
is to provide your own replacement file I/O routines.

--
UUCP: {ucbvax,harvard}!cs.cmu.edu!ralf -=- 412-268-3053 (school) -=- FAX: ask
ARPA: ralf@cs.cmu.edu  BIT: ralf%cs.cmu.edu@CMUCCVMA  FIDO: 1:129/3.1
Disclaimer?    |   I was gratified to be able to answer promptly, and I did.
What's that?   |   I said I didn't know.  --Mark Twain

jpn@genrad.com (John P. Nelson) (10/09/90)

>>> No matter what I set "FILES=" in CONFIG.SYS
>>>the maximum files that I can open is 15. Is there any way in which this
>>>can be increased.
>> 
>It also depends on your DOS version.  Some versions of DOS (as recently
>as 3.20) allow FILES=[>20] but in reality could only accomodate 20
>files.

This answer is VERY misleading.

Every version of DOS (at least since 2.0, I don't know about 1.0)
allows you to set FILES greater than 20.  This has no effect on the
per-application file limit of 20:  FILES is a system-wide parameter.
The FILES parameter was primarily intended to allow more file
descriptors on systems that use lots of TSRs or multitaskers.

On the other hand, it has always (since DOS 2.0) been possible to
increase the size of the per-task file descriptor limit, on a task by
task basis.  The per-task limit of 20 files is caused by the fact that
the default file descriptor table is located in the PSP, which itself
is a fixed length item.  However, the PSP contains both the
fixed-length table, and a pointer to that table (and a length
variable).  It is possible to create a larger task file descriptor
table by 1.  allocating a block of memory for it, 2.  copying the
contents of the fixed-length file descriptor table from the PSP,  3.
changing the pointer in the PSP to point to the new table, and 4.
changing the length in the PSP to the new length.

All that happened in DOS 3.3 is that Microsoft sanctioned this
technique by adding a new DOS service that does the above 4 steps for
you.  (As I recall, though, at least some copies of DOS 3.3 do not
implement this correctly, and will fail for certain table size
requests).  However, the default application file descriptor table size
is still 20 (since the PSP hasn't changed) and the old technique of
doing the 4 steps manually still works.

>Your best bet would be to upgrade your version of DOS.

Actually, I doubt that this will help very much.

First, unless an application is written to check the version of DOS,
and to USE the table-size function, you don't gain any benefit from
upgrading to a new version of DOS.  Since applications which use the
"manual" technique work with ANY version of DOS, this is a much more
attractive technique for the programmer to use.

In any case, this doesn't help someone who is using a binary executable,
not a program he has written himself.

Even for the programmer who wants to use this technique, there are
pitfalls.  For instance, high level language libraries may assume that
the fixed-length table is being used, and may not be able to handle the
larger table.

     john nelson

uucp:	{decvax,mit-eddie}!genrad!jpn
domain:	jpn@genrad.com