IBM Metal C

Examples

Example 2. VTOC OBTAIN

This example is a bit less trivial than the first. This routine, named obtain, executes the MVS OBTAIN routine in order to retrieve the format 1 and format 3 DSCBs for a data set and volume, specified as parameters to the routine. The format-1 DSCB contains space information for the first 3 extents, while the first format-3 can contain (up to) the next 13 extents for the data set on the specified volume. Using the field ds1lstar and the extent information allows for an approximate calculation of used and allocated pace for the data set. Details of the OBTAIN SVC can be found in z/OS DFSMSdfp Advanced Services© Chapter 1. Using the Volume Table of Contents. To use the OBTAIN routine the OBTAIN and CAMLST macros are coded.

The OBTAIN macro allows for more than one DSCB to be read at one invocation, with a maximum of 12 DSCBs. This number is supplied to the macro with the NUMBERDSCB parameter. Each returned DSCB entry requires 140 bytes, therefore the C program shown here defines a work area of 1680 bytes. The OBTAIN macro parameter EADSCB specifies whether a program supports data sets with format-8 and format-9 DSCBs, which can occur on extended address volumes, and is set to EADSCB=OK for this routine.

The signature line for this routine is:

extern int obtain(char *dsname, char *volume, struct format1 *_dscb)

The struct that maps the DSCB, which is the output from this routine is not shown here. It was generated from the DSCB mapping macro IECSDSL1, using the IBM supplied program CCNEDSCT, which converts Assembler storage definitions into C structs.

The OBTAIN macro loads the address of the CAMLST parameter list into R1 and then invokes SVC 27. To do this in C, I coded the expanded macro statements as __asm statements. The input constraint "r"(&_work), tells the compiler to load a register with the address of the C variable _work. The clobber list specifies R1 not be used, since the OBTAIN routine will use it.

The second __asm statement saves the return code from the OBTAIN routine into the C variable rc, which is the returned value from the C routine.

The HLASM code produced from the compilation of the C source is shown below.

References

  1. z/OS DFSMSdfp Advanced Services©
  2. z/OS Metal C Programming Guide and Reference
  3. z/OS XL C/C++ Language Reference

All references copyright© IBM Corporation.