Scanning UCBs

You can use the UCBSCAN macro with the COPY keyword to scan UCBs. On each invocation, UCBSCAN may return, in caller-supplied storage areas, a copy of one or more of the following UCB segments:

The scan can include all UCBs in the system, or be restricted to a specific device class. For example, you could use UCBSCAN to find all DASD devices currently defined to the configuration. It is also possible to restrict the scan to UCBs for static and installation-static devices, or to include UCBs for dynamic devices as well.

Example of a Program That Obtains Copies of All the UCBs: This example program obtains copies of all UCBs, including those for devices defined as dynamic. It uses the MVS™ I/O configuration token to determine if the I/O configuration changes during the scan, and it restarts the scan if the I/O configuration has changed. On each invocation of UCBSCAN, the system returns a copy of a UCB at the address specified by UCBAREA and return the current MVS I/O configuration token.
SCANEXMP CSECT
SCANEXMP AMODE 31
SCANEXMP RMODE ANY
         DS    0H
         BAKR  R14,0                         Save regs on linkage stack
         LR    R12,R15                       Set up code reg
         USING SCANEXMP,R12
         LA    R13,SAVEAREA                  Get save area address
         MVC   SAVEAREA+4(4),FIRSTSAV        First save area in chain
*
*        ...
*
RESCANLP DS    0H
         IOCINFO IOCTOKEN=TOKEN              Get current IOCTOKEN
         XC    SCANWORK,SCANWORK             Clear scan work area
SCANLOOP DS    0H
         UCBSCAN UCBAREA=UCBCOPY,WORKAREA=SCANWORK,DYNAMIC=YES,        +
               RANGE=ALL,IOCTOKEN=TOKEN
         LTR   R15,R15                       Was a UCB returned?
         BNZ   SCANDONE                      No, either a configuration
*                                            change has occurred
*                                            or no more UCBs
*
*    Process  UCB
*
         B     SCANLOOP
SCANDONE DS    0H
         LA    R02,12                        Return code for a
*                                            configuration change
         CR    R15,R02                       Did a configuration change
*                                            occur?
         BE    RESCANLP                      Yes, start scan again
FINISHED DS    0H
*
*        ...
*
ENDIT    DS    0H
         PR                                  Return to caller
         EJECT
*
*   Register equates
*
R02      EQU   2
R03      EQU   3
R09      EQU   9
R12      EQU   12
R13      EQU   13
R14      EQU   14
R15      EQU   15
         DS    0F
FIRSTSAV DC    CL4'F1SA'                     First save area ID
SAVEAREA DS    18F                           Save area
TOKEN    DS    48C                           IOCTOKEN area
UCBCOPY  DS    48C                           UCB Copy returned by
*                                            SCAN
SCANWORK DS    CL100                         Work area for SCAN
         END   SCANEXMP