[NEWSLN.TXT]

	LUN ALLOCATION FOR RSX USING DECUS-C

These routines where developed because of the need
to access devices directly through QIO's under
DECUS-C. The problem at the time was that we
wished to access graphics terminals from C
programmes, without opening the device as a file. 

The normal way of opening a file (or device) in
DECUS-C, fopen(), involves large buffer overheads.

One solution is to select an arbitrary LUN (using
a magic number generation program), and use this
as a constant in the program. The problems with
this are: 

 - Depending upon the program, the 'C run-time
   library may allocate that same lun to a file
   you open

 - Many modules using the same allocation scheme
   used in the same program, could have
   conflicting LUNs, and might be hard to get
   working together, if lun schems don't line up.

The obvious solution is to allocate the lun to use
from the run-time library's table. 

Easy solution ? I thought so, so I started reading
through code !!! Starting with fopen(), and then
going through code for lots of associated modules,
I eventually came accross the wanted table. While
working out how this table worked ,I descoverd
that the number of luns is hard-wired to 20 luns
only (another symptom of RSTS). To get the full
quota of LUNs available to RSX, You would have to
re-build the module [5,5]IOV.MAC, with $$lmax as
the new lun table size. Also I found that the lun
table for rsx starts at LUN 2, so that stderr is
kept from harm. To get at this, access it as lun
1. (C run-time libraries won't let you access it).

Functions which emerged include:

LUNOPN()

Open and assign a device on a LUN. This by-passes
the C buffered IO system therfore not assigning
any FILE type structures. The LUN is marked as
used in the LUN table however, so as not to stir
up the C environment Returns 0 on error or LUN
number. If an error occurs, the lun will be
de-allocated 

LUNCLS()

Close a device opened by lunopn(). Returns 0 if
successful or -1 if problem encounted 

ALOLUN()

Find a free LUN in the lun table, and allocate it
Returns the LUN number or 0 on error

DEALUN()

De-allocate the specified lun, returning it to the
LUN table Returns 0 on OK or -1 on error 


ELTNUM()

Get the element number of an integer in a list of
integers terminated with 0. (0 is the first
element). Returns element number on success, or -1
on no entry 

CLOSEST()

Return the element in the table that's closest to
the number specified returns -1 if table is empty 

These functions should be included in [273,201]
of this Tape.


Bruce Cook (Wittenoom and Associates)
