Chapter Contents

Previous

Next
MVS Low-Level I/O Functions

DCBs and DCB Exit Routines

The BSAM interfaces require that you allocate and initialize a DCB (data control block) using osbdcb or osdcb . The address of the DCB is then passed to the other I/O routines as an argument. Many BSAM functions require you to extract or modify data in the DCB. The header file <osio.h> contains a C structure definition for the DCB defining all necessary fields and constants.

Advanced use of BSAM in assembler frequently requires the coding of DCB exit routines, which are routines called by BSAM during processing of the DCB. (For instance, the SYNAD exit is called during processing of I/O errors.) Both BSAM interfaces enable you to write DCB exit routines in C. When you do this, the library takes care of linkage details for you so that the exit routine is called as a normal C function and the full facilities of the SAS/C Library can be used. (For instance, an assembler DCB exit routine is always entered in 24-bit addressing mode. However, before calling a C exit routine, the library switches back to 31-bit addressing mode, for a program that runs in that mode, so that data allocated above the 16-megabyte line can be accessed.)

When you use BSAM in assembler, you specify DCB exits by creating an exit list. Each entry in the list contains an exit type code and an entry address. The list of exits is then accessed via the DCBEXLST field of the DCB. When you use the SAS/C BSAM interface, the process is similar but not identical. You create a list of exits in which each entry contains an exit type code and a function address. (The C exit list format is not the same as the assembler format because of the need to support 31-bit addressing.) The list of exits is passed to osbdcb or osdcb as an argument. This routine then transforms the C exit list into a similar assembler exit list, modifies the DCB, and actually performs the OPEN. (Note that some entries in an exit list are used as data addresses, such as a JFCB buffer address, rather than as function addresses. A different field name is used for storing a data pointer rather than a function pointer in an exit list.

When an exit routine is entered in assembler, parameters such as the address of the DCB or an I/O status block are passed in registers 0 and 1. When a corresponding C exit routine is called, it is passed two parameters, the first of which is the value that would be passed to the assembler exit in register 1, and the second is the register 0 contents. All exit functions should be declared as returning int , and the value returned is returned to BSAM in register 15.

Note that a C SYNAD exit requires slightly different linkage. When a C SYNAD exit is called, the library issues the SYNADAF macro before passing control to the exit routine. The address of the message constructed by SYNADAF is passed as the first argument, and the address of the DECB (data event control block) is the second argument. If the DCB address is required, it can be extracted from the SYNADAF message.

The BSAM interface supports escape from a DCB exit routine using the longjmp function. However, control is returned to data management with a value of 0 in register 15 before the longjmp is allowed to complete.

Note:    When a DCB exit routine is running, use of some system services may cause task interlocks or ABENDs. Dynamic allocation and open are examples of such services. This means that you should not open a file in a routine called from a DCB exit. Also, be careful performing I/O to stdin , stdout , or stderr from a DCB exit because an operating system OPEN will be issued for these files if they have not been previously used. Finally, when debugging a DCB exit with the source level debugger, use the auto nolist command to prevent debugger access to the program source because the debugger uses dynamic allocation to gain access to the program source.  [cautionend]


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.