MONPROC  SET      1
DISCBPROC SET     2                                                     DISCB
         SYSTEM   UTS
         PCC      0
         DEF      PV
PV       EQU      %
         PAGE
         PAGE
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
R8       EQU      8
R9       EQU      9
R10      EQU      10
R11      EQU      11
R12      EQU      12
R13      EQU      13
R14      EQU      14
R15      EQU      15
SR1      EQU      8
SR2      EQU      9
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
         PAGE
         SPACE    2
         DEF      CLOSEPV
         DEF      PVERR
         DEF      CLSVNO
         DEF      SWXPV
         DEF      OPV
         PAGE
         SPACE    2
         REF      MSROCTY
         REF      SETPVI
         REF      CLRBBUF
         REF      GETFUN
         REF      GETORG
         REF      GETSEC
         REF      GETSNADR
         REF      CHKCUR
         REF      CLEARHI
         REF      GETBBUF
         REF      GETVDCTX
         REF      IOSPIN
         REF      PULLEXIT
         REF      PVQUEUE
         REF      QUEUE
         REF      RESBLK
         REF      RWREX
         REF      SETBLK
         REF      SETVNO
         REF      USECHK2
         REF      GETOVC
         REF      GETVNO
         REF      T:REG
*
         REF      AVRNOU
         REF      AVRTBL
         REF      AVRID
         REF      BATAPE
         REF      AVRTBLSIZ
         REF      AVRTBLNE
         REF      SOLICIT
*
         REF      J:BASE
         REF      J:DCBLINK
         REF      J:JIT
         REF      JB:CUR
         REF,1    JB:SLNK
         REF,1    JB:XLNK
*
         REF      RAT:DCT4
         REF      ASPIN
         REF      HOWALO
         REF      DHHIT
         REF      DEALL
*
         REF      S:MBSF
         REF      U:MISC
         REF      E:SL
         REF      DCT3
         REF      DCT4
         REF      UH:DL
         REF      DCT16
         REF      ACNCFU
         REF      BGRCFU
         REF      CFUSIZE
         REF      HGP
         REF      LSERIAL
         REF      RSERIAL
         REF      S:CUN
         REF      SH:RBCU
         REF      TSERIAL
*
         REF      M17
         REF      YFF
         REF      M16
         REF      Y8
         REF      Y0A
         REF      Y002
         REF      Y01
         REF      Y02
         REF      Y06
         REF      Y08
         REF      Y2
*
K0       EQU      0
K2       EQU      2
KA       EQU      10
K1FFFF   EQU      X'1FFFF'
         TITLE    '**** CLOSEPV ****'
*        PURPOSE: TO TERMINATE A DCB'S USE OF A PRIVATE VOLUME
*
*        INPUT:   R6=DCB ADR
*                 DCB:VNO=THE VOLUME NO. OF THE VOLUME BEING CLOSED
*                 DCB:PAT AND DCB:VDCTX MAY NOT POINT TO THE VOLUME
*                         IN VNO
*                 DCB:OVC=A COUNT OF THE NO. OF OPENED VOLUMES
*                 ALL DATA HAS BEEN WRITTEN TO THE VOLUME (BBUD,MIUD=0)
*
*        CALL:    BAL,R0  CLOSEPV
*
*        OUTPUT:  DCB:OVC DECREMENTED
*                 AVRNOU  (OF THE AVRTBL ENTRY ASSOCIATED WITH THE VOL)
*                         IS DECREMENTED
*                 THE VOLUME'S CYLINDER BIT MAP IS WRITTEN ONTO THE VTOC
*
*        REGS:    ALL REGISTERS NONVOLATILE
*
CLOSEPV0 OR,0     Y8                ENTRY FROM SWITCH
CLOSEPV  EQU      %
         PUSH     16,R0
         BAL,D4   SETPVI           *LOCATE AVRTBL ENTRY AND SET
*                                   DCB:PAT AND DCB:VDCTX
*                                   UPDATE VTOC CYLINDER BIT MAP
         PUSH     R2                SAVE VOLUME'S DCT INDEX
         LW,R3    Y8                IF NOT UPDATED, DONT
         EOR,R3   6,R7
         BLZ      CPV25
         STW,R3   6,R7
         BAL,R0   RDVTOC                READ VTOC INTO BUF1
         LW,R7    PAT,R6                R7=AT ADR
         LI,R5    BUFF1
         INT,R3   VTOC:MAPWL,R5        *MOVE ALLOCATION TABLE BIT MAP
         LI,R2    9                     AND NVAT TO VTOC
         CH,R3    *R7,R2
         BLE      CPV10
         LI,R2    -16               DISPLACEMENT FOR STACK
         LI,R7    CLSVNOERR         SET RETURN FOR CLOSING REST OF VOLUMES
         STW,R7   *TSTACK,R2        SAVE RETURN
         B        CPV25
CPV10    AI,R3    VTOC:BITMAP-VTOC:NVAT R3=NO. OF WORDS BEING MOVED
         AI,R5    VTOC:NVAT-1           R5=ADR OF VTOC:NVAT-1
         AI,R7    AT:NVAT-1             R7=ADR OF AT:NVAT-1
CPV20    LW,R0    *R7,R3
         CW,0     *R5,R3            DONT WRITE IF NOT CHANGED
         BE       %+2
         OR,R5    Y8                SET UPDATED BIT
         STW,R0   *R5,R3
         BDR,R3   CPV20
         STS,R5   BUFF1             SET UPDATED FLAG IF UPDATED
         BAL,R0   WRVTOC            WRITE IF UPDATED
         BAL,0    CLRBBUF           AND RELEASE BUFFER
CPV25    EQU      %
         PULL     R2                R2=ADR OF VOLUME'S AVRTBL ENTRY
         AI,R2    -BATAPE           GET AVRX
         LI,R3    BAOVC
         MTH,-1   AVRNOU,2             *DECREMENT THE VOLUME'S NO. OF
         BGZ      CPV40                 USERS COUNT AND THE DCB'S # OF
CPV35    EQU      %                     OPEN VOLUME'S COUNT
         BAL,SR4  PVERR0
CPV40    MTB,-2   *R6,R3               (NOTE:DCB:OVC HAS ONLY 7 BITS)
         BNC      CPV35
         LW,7     TSTACK            GO LOOK AT THE PLIST
         AI,7     -16               IF THE CAL IS A CLOSE
         LW,8     1,7               CEHCK IF CALLED BY SWXPV
         BLZ      CPV50             YES, ALWAYS REMOVE
         AI,7     -1
         CW,7     1,7
         BNE      %-2               FIND THE PUSHALL
         LW,8     -3,7              OP CODE
         CI,8     X'15'             IS IT CLOSE
         BNE      CPV50             ALWAYS DISMOUNT IF NOT CLOSE
         LW,7     -4,7              PLIST+1 ADDR
         LW,7     0,7
         CI,7     X'20'             REM OPTION
         BAZ      CPV80             NO, LEAVE IN USE
CPV50    LD,14    AVRTBL,2          GET AVR ENTRY
         LC       J:JIT
         BCS,12   CPV55             ONLINE, GHOST OK
         MTH,0    AVRID,2           IS IT EXCLUSIVE
         BGZ      CPV55             YES, OK
         AI,15    0                 NO, IS IT PUBLIC
         BGEZ     CPV80             NO, DON'T RELEASE
CPV55    RES      0
         LW,15    6                 NOT THIS ONE
         LW,5     Y002              MUST BE OPEN
         AI,5     DCBPRIVBIT        AND PRIV
         LW,8     J:DCBLINK
         LW,7     *8                END OF CHAIN
         SW,7     8                 LENGTH OF CHAIN
         AI,7     -1
         LW,4     2                 SAVE AVRX
CPV60    LW,6     *8,7
         CW,6     YFF               IS THIS A DCB ADDRESS
         BANZ     CPV70             NO
         CW,15    6                 IS IT THE ONE WERE TRYING TO CLOSE
         BE       CPV70             IGNORE IT
         CS,5     0,6               IS IT OPEN AND PRIV
         BNE      CPV70             NO
         BAL,0    GETSNADR          13=SN TBL
         BAL,0    GETOVC            3=# OPEN
         CI,3     1                 ONLY ONE IF CONSEC
         BNE      %+3
         BAL,0    GETVNO            3= WHICH ONE
         MTB,-3   3                 SET FLAG TO CHECK ONLY ONE
         CW,14    *13,3             ANY THE SAME ONE
         BE       CPV80             YES, DONT RELEASE
         BDR,3    %-2
CPV70    BDR,7    CPV60             NEXT DCB ADDR
         LW,2     4
         AI,2     BATAPE
         LW,3     4
         BAL,11   RAT:DCT4
         B        SC31              INVALID RESOURCE TYPE
         LI,14    0
*                                   1 = RESOURCE TYPE INDEX
*                                   2 = DCT INDEX
*                                   3 = AVR INDEX
*                                   6 = DCB ADR
*                                   14 = RESET SPIN BITS
         LH,7     AVRID,3           TEST HOW ALLOCATED
         BGZ      EXC11
         LI,11    X'F'
         AND,11   J:RNST            LINKED?
         BGZ      CPV80             YES-IGNORE
*                                   ONLINE OR GHOST OR BATCH SHARED
         LC       J:JIT
         BCR,12   CPV72             BATCH
*                                   ONLINE - GHOST
CPV71    EQU      %                 EXCLUSIVE  IE. BATCH
         MTB,-1   JB:CUR,1
CPV72    EQU      %                 BATCH-SHARED
         BAL,11   ASPIN             RESET SPIN BIT IN JIT
CPV73    EQU      %
         MTH,-1   AVRNOU,3          DECREMENT 1 FOR THE USER
         BNEZ     CPV80             STILL IN USE IF NON ZERO
*                                   EXCLUSIVE WILL BE TAKEN CARE OF IN
*                                   T:DSMNT BY SUBTRACTING JB:MAX FROM CU
         BAL,11   HOWALO            FIND OUT WHO ORIGINALLY GOT THE DRIVE
*                                   AND RETURN IT IN 0;
*                                   RESET GLOBAL SPIN BIT
         CI,7     0                 TEST FOR EXCLUSIVE
         BGZ      CPV80             YES
         MTH,-1   *0,1              DECREMENT GLOBAL COUNT
         STW,11   S:MBSF
CPV80    EQU      %
         PULL     16,R0
         B        *R0
EXC11    LI,11    1
         CH,11    AVRNOU,3          IN USE BY DCBS
         BE       CPV71             NO - DEALLOCATE
         B        CPV80             YES - IGNORE
         TITLE    '**** OPENPV ****'
*
*        PURPOSE: TO BEGIN A DCBS USE OF A PRIVATE VOLUME
*
*        INPUT:   R6=DCB ADDRESS
*                 DCB:VNO=VOLUME NO.
*
*        CALL:    BAL,R11 OPENPV
*
*        OUTPUT:  DCB:VNO=0, IF UNABLE TO MOUNT THE VOLUME
*                            DCB:VDCTX,PAT=0: IF RNST ESCAPE
*                            DCB:PAT=0,VDCTX=VOLUME# IF FOREIGN VOL
*                            DCB:VDCTX=0,PAT=ABNORMAL CODE IF RESOURCE EERR
*                 DCB:VNO UNCHANGED IF VOLUME MOUNTED
*                            DCB:VDCTX,PAT POINT TO MOUNTED VOLUME
*                            AVRNOU,DCB:OVC INCREMENTED
*
*        REGS:    ALL VOLATILE EXCEPT R6,R8-R11
*
OPENPV   RES      0
         PUSH     4,8               SAVE REGS
AV10     RES      0
         BAL,R0   GETVNO
         BEZ      AVX               JOB ALREADY ABORTED
         BAL,R0   GETSNADR
         SD,R4    R4                FIND THE SN ANYWHERE
         BAL,R0   S:DAVR
         B        AV30SN            NOT THERE, GO REQUEST IT
         LW,R5    R2
         AI,R2    BATAPE            AND DCT INDEX
         BAL,R11  RAT:DCT4          GET RAT INDEX
         B        SC31              THAT'S A BIT SCREWY
         LD,14    AVRTBL,5
         CW,15    Y08               VER
         BANZ     AV13              WAIT A BIT
         CW,15    Y2
         BANZ     AVR98
         AI,15    0                 PUB
         BGEZ     AV30SN              NO
         LC       J:JIT
         BCS,12   AV40              O/G
         LW,R3    *R13,R3           SERIAL #
         BAL,0    S:TSER            CHECK ONLY
         BNEZ     AV40              YEP
*        AVR'D---IF PREMOUNT PUBLIC AVRNOU=1
AVR95    BAL,0    S:TSERX           IS IT EXCLUSIVE
         BNEZ     AVE2003           YES, ERROR
         B        AV40              NO, GIVE IT TO HIM
         PAGE
*        AVR'D
AVR98    RES      0
         CI,R3    1                 IF NOT PRIMARY REQUEST,
         BE       %+3               MUST NOT BE A PRIMARY VOLUME
         CW,R15   Y02
         BANZ     AVE2005           THERE'S MORE THAN ONE PRIMARY IN SET
         BAL,R11  DHHIT
         BANZ     AV29              IF HES ALREADY GOT IT, GIVE IT TO HIMM
         LW,3     *D2,3             GET SERIAL #
         LH,0     AVRNOU,5
         BEZ      PRENOTPUB
         LH,0     AVRID,5
         BLZ      AVE2001           LOCKED OUT
         BGZ      AVE2002           EXCLUSIVE, NOT THIS USER
         LC       J:JIT
         BCS,12   AV27              ONLINE OR GHOST,NO REQUEST REQUIRED
         BAL,0    S:TSERS           DID HE ASK FOR IT
         BNEZ     AVR99             YEP, GIVE IT TO HIM
         AI,15    0                 PUBLIC
         BGEZ     AVE2003           NO, ERROR
         BAL,0    S:TSERX           CHECK EXCLUSIVE
         BEZ      AV26              NOT EXCLUSIVE, OK
         B        AVE2003           IS EXCLUSIVE, ERROR
         SPACE 4
AVR99    RES      0
*                                   RESET ALLOCATION IN PROGRESS AND
*                                     SET J:ASPIN BIT
*                                   SH:RBCU COUNTED UP FOR EACH BATCH JOB
*                                   DESCRIBED AS SHARED
*                              THIS COUNTS IT DOWN IF PACK IS ALREADY IN USE
         MTH,-1   SH:RBCU,1         GIVE IT BACK
         STW,11   S:MBSF            SET RES REL FLAG
AV26     BAL,11   CLEARHI
         REF      SSPIN
         MTH,0    AVRNOU,5
         BNEZ     NOTS
*                                   SET GLOBAL SPIN BIT BASED ON JOB TYPE
*                                   FOR FIRST USER ON DRIVE
         BAL,11   SSPIN
NOTS     RES      0
         MTH,1    AVRNOU,5          COUNT IT
AV29     RES      0
         MTH,1    AVRNOU,5          INCREMENT FOR DCB
         LI,R7    BAOVC             AND IN DCB
         MTB,2    *R6,R7
         BAL,R15  SETPVI            SET DCB POINTERS
AVX      RES      0
         PULL     4,8
         B        *11
         SPACE 4
AV27     RES      0
*                 ON LINE CHECK  CUR:MAX
*                 SHARED
         BAL,11   CHKCUR
         B        AV26              BEEN HERE BEFORE(ALLOC)
         BLE      AVE4902           OVER/JOB
         B        AV26
         PAGE
AV30SN   EQU      %
         LW,3     *D2,3             SERIAL#
         BAL,11   ISITX            CK SERIAL NR FOR EXCULSIVE
         B        AV35             ON-LINE/GHOST AND OK
*                                  BATCH -OK
         BAL,0    S:TSER            CHK SHARED DON'T UNLINK
         BNEZ     AV40              ALL ACCOUNTED FOR
         BAL,0    S:TSERX
         BEZ      AVE2003           NO REQUEST
AV35 RES 0
         BAL,12   CANHE             NO=ERR EXIT
AV40     RES      0
         B        MTPV              GO REQUEST A MOUNT
*
*        ERROR RETURNS
*
AVE20    AI,4     X'1000'-AVE2001   CNVT TO 20 MIT SUBCODE
         REF      RSETSPIN
AVEXX    ENABLE
         LI,5     X'1FFFF'
         STS,4    PAT,6             PUT IT AWAY
         REF      DEPACK
         BAL,11   RSETSPIN          DCTX IN 2
         BAL,5    DEPACK
AVEXX1   RES
         LI,4     0
         LI,5     BAVDCTX           ZAP VDCTX TOO
         STB,4    *6,5
         LI,5     BAVNO             ZAP VNO TOO
         STB,4    *6,5
         PULL     4,8
         B        *R11              ABORT RETURN FROM OPENPV
         PAGE
CANHE    LI,4     BARNDEV
         LB,4     *6,4              TYPE
         BAL,9    USECHK2
         B        AVE4902
         B        AVE4901           GLOBALLY OVER
         B        *12
AVE49    AI,4     X'2480'-AVE4901
         B        AVEXX
AVE4901  BAL,4    AVE49
AVE4902  BAL,4    AVE49
AVE2001  BAL,4    AVE20
AVE2002  BAL,4    AVE20
AVE2003  BAL,4    AVE20
AVE2004  BAL,4    AVE20
AVE2005  BAL,11   DHHIT             DEALLOCATE ONLY IF NOT HIS YET
         LI,4     X'1005'           (SET ABN CODE)
         BAZ      AVEXX
         LI,5     X'1FFFF'
         STS,4    PAT,6             ONLY SET CODE IF ITS HIS
         B        AVEXX1
PRENOTPUB RES 0
         BAL,11   ISITX
         B        JAV11            ON-LINE/GHOST AND OK
*         BATCH
         BAL,0    S:TSERS           UNK IF THERE
         BNEZ   AV26                IT WAS
         BAL,0    S:TSERX           EXCL?
         BEZ      AVE2003           NOT REQUESTED
JAV11    RES      0
*        INC CUR AND GLOBAL
         BAL,12   CANHE             NO =ERR EXIT
         LC       J:JIT
         BCS,12   AV26
         LW,0     S:CUN
         STH,0    AVRID,5           SET ID   EXCLUSIVE
         B        AV26
         SPACE    2
AV13     EQU      %                 WAIT A BIT
         PUSH     R6
         LW,R6    S:CUN
         LI,SR4   10                SLEEP FOR 12 SECONDS
         STW,SR4  U:MISC,R6
         LI,R6    E:SL
         BAL,SR4  T:REG
         PULL     R6
         B        AV10              TRY AGAIN
         TITLE    '**** ISITX ****'
*        PURPOSE : TO CHECK SERIAL NR AGAINST EXCLUSIVE BATCH LIIST
*                 IF BATCH REQUESTED EXCLUSIVE ,ABN = 2002
*
*        INPUT:   R3=SERIAL NR
*        CALL:    BAL,11 ISITX
*                 +1 GHOST/ON-LINE AND NOT IN EXCLUSIVE LIST
*                 +2 BATCH -OK RABBIT HAS CHECKED IT
*
*
         REF      PLX1SR4,SV:RSIZ
         REF      MBSOP#           SV:RSIZ*LPART
         REF      LPART,PLB:MIN
         REF      J:RNST
*
ISITX    LC       J:JIT
         BCR,12   PLX1SR4          BATCH -RABBIT CHECKED
         LI,4     MBSOP#+LPART
ISITXL   LB,1     PLB:MIN,4        PARTITION CHAIN FOR EXCLUSIVE LIST
         BEZ      ISITXN
ISITXL1  CW,3     TSERIAL,1
         BE       AVE2002          CAN'T HAVE IT(BATCH REQUESTED)
         LB,1     LSERIAL,1
         BNEZ     ISITXL1
ISITXN   AI,4     -(SV:RSIZ+1)
         BGZ      ISITXL
         B        *11              OK TO REQUEST
         TITLE    '**** PVERR ****'
PVERR    PSW,11   TSTACK            SAVE ADDRESS OF ERROR
         BAL,SR4  CLSVNO            TRY TO CLOSE AS MUCH AS POSIBLE ANY
*                                   ANY OPEN VOLUMES
         PULL     11
PVERR0   EQU      %
         SUA      X'46',X'21'
*
*                 CLEAN UP OPEN VOLUME COUNTS IF POSSIBLE
*
CLSVNOERR EQU     %                 ERROR GO TO PVERR1 WHEN DONE
         LI,11    PVERR0
CLSVNO   EQU      %                 CLOSE VOLUME NUMBER
         BAL,R0   GETOVC            GET OPEN VOLUME COUNT
         BEZ      *11               RETURN--NONE OPEN
         BAL,0    GETORG            IF CONSEC, WHATEVER IT SAYS
         BL       %+2               IS RIGHT
         BAL,R0   SETVNO            SET VOLUME NUMBER
         BAL,R0   CLOSEPV           CLOSE VOLUME POINTED TO BY VNO
         BDR,3    %-2               CLOSE UNTIL NONE OPEN
         B        *11               AND RETURN
         TITLE    '**** RDVTOC **** WRVTOC ****'
*        PURPOSE: TO READ OR WRITE PRIVATE VOLUME'S VTOC
*
*        INPUT:   R6=DCB ADR
*                 DCB:VDCTX=VOLUME'S DCT INDEX
*                 (WRVTOC ONLY) VTOC IN BUFF1 - WORD 0 NEGATIVE IF UPDATED
*                 NO WRITE WILL OCCUR IF VTOC NOT UPDATED
*
*        CALL:    BAL,R0 RDVTOC
*                 BAL,R0 WRVTOC
*
*        OUTPUT:  DCB:BUF1=ADR OF VTOC BUFFER
*                 D3=BUF1 ADR
*
*        REGS:    ALL REGISTERS USED BY REDSECB + R2,R3,D1 VOLATILE
*                 IF NO WRITE OCCURS, ONLY R11 IS CHANGED
*
WRVTOC   RES      0
         LW,SR4   T:LBL             CHECK UPDATED FLAG
         XW,SR4   BUFF1
         BGZ      *0                NO, EXIT
         OR,R0    Y8                SET WRITE FLAG
         OR,R6    Y06               SET QRITE CODE
RDVTOC   EQU      %
         PUSH     R0
         BIR,0    %+2               DONT CLEAR FOR WRITE
         BAL,R0   CLRBBUF           WRITE OUT BUFF1 IF NECESSARY
         BAL,R0   GETBBUF           GET NEW ONE
         BAL,R0   GETVDCTX          GET DCTX TO READ
         LW,D1    R3                IN D1
         SLS,D1   16
         BAL,SR3  RWREX             SAVE AND SETUP DCB
         LW,SR4   Y01               INCR FCN
         AWM,SR4  FCN,R6
         AND,R6   M17               SCRUB WRITE CODE
         BAL,SR4  QUEUE
         BAL,SR4  IOSPIN
         BAL,R0   RESBLK            RESTORE DCB
         LI,D3    BUFF1             RESTORE BUFF1 ADDRESS
         B        PULLEXIT
         TITLE    '**** SWXPV(1) **** SWXNXTPV ****'
*        PURPOSE: TO SWITCH A CONSECUTIVE FILE FROM THE CURRENT
*                 PRIVATE VOLUME TO THE VOLUME REFERENCED IN R3
*
*        INPUT:   R6=DCB ADR
*                 R3=NEW VOLUME NUMBER
*
*        CALL:    BAL,R0
*
*        OUTPUT:  DCB:VNO,DCB:PAT,DCB:SWXV POINT TO THE REQUESTED VOLUME
*                 OR DCB:VNO=0 AND VDCTX,PAT INDICATE WHY (SEE OPENPV)
*
*        REGS:    VOLATILE: R0,R2-R5,R7,SR4,D2
*                 NONVOLATILE: R1,R6,SR1-SR3,D1,D3,D4
*
SWXPV    RES      0
         PUSH     R0
         LW,R2    R3                REMEMBER NEW VOL #
         BAL,R0   SETBLK            SAVE DCB:BLK -> CDA
         LW,R3    R2
         LI,2     BAVNO             IF NONE OPEN, DONT CLOSE
         LB,2     *6,2
         BEZ      %+2
         BAL,0    CLOSEPV0          CLOSE/REMOVE THE CURRENT OPEN VOLUME
         BAL,R0   SETVNO            SET DCB:VNO=REQUESTED VOLUME
         PUSH     4,D1              SAVE SOME REGS
         BAL,R11  OPENPV            OPEN THE REQUESTED VOLUME
         PULL     4,D1
         BAL,R0   RESBLK            RESTORE DCB:BLK->CDA
         BAL,R0   GETVNO            WAS THE VOLUME MOUNTED
         BNEZ     PULLEXIT              YES,EXIT
         LI,SR3   K1FFFF           *WAS THE VOLUME NOT MOUNTED BECAUSE
         AND,SR3  PAT,R6            THE UNIT WAS UNAVAILABLE
         BNEZ     %+2               GOT ONE
         LI,10    X'1406'**-1       MUST BE RNST ABORT
         SCS,10   -7
         B        PULLEXIT          RETURN TO CALLER FOR FIXIT
         TITLE    '**** OPV ****'
*        PURPOSE: TO OPEN A FILE ON A PRIVATE VOLUME SET
*
*        INPUT:   R6=DCB ADDRESS
*                 R9=VSND VALUE
*
*        CALL:    BAL,R11  OPV
*
*        OUTPUT:  R3=0,IF ERROR RETURN AND SR3 CONTAINS AN ERROR CODE
*                   =2,IF NORMAL  RETURN
*                 DCB:VSND=WORD DISPLACEMENT TO DCB SERIAL NO. TABLE
*                          (THE INSN/OUTSN LIST)
*                          NOTE: VSND POINTS TO THE INSN/OUTSN CONTROL
*                          WORD,NOT TO THE FIRST SERIAL NO
*                 DCB:PRIV SET; DCB:SWXV RESET
*
*        REGS:    ALL REGS VOLATILE EXCEPT R6
*
         REF      NXTVOL
         REF      SETVNO1
         REF      SAVCBD
         REF      WRTSEC10
*
OPV      EQU      %
         PUSH     SR4
         LI,R2    BAVSND           *SET DCB:VSND EQUAL TO WORD
         AI,9     -1                DISPLACEMENT OF PRIVATE VOLUME
         BLZ      OPV10             CALLED FROM SETACOG, DONT SET VSND
         STB,9    *R6,R2            SERIAL NO TABLE
OPV10    LI,R3    DCBPRIVBIT+DCBSWXVBIT
         LI,R2    DCBPRIVBIT
         STS,R2   PRIV,R6           SET DCB:PRIV; RESET DCB:SWXV
*
OPV25    LI,R3    0                *OPEN THE FIRST VOLUME
OPV30    AI,R3    1
         BAL,R0   SETVNO
         BAL,R11  OPENPV            *OPEN THE VOLUME SPECIFIED IN VNO
         BAL,R0   GETVNO
         BNEZ     OPV70
         LI,SR3   K1FFFF           *WAS VOLUME UNABLE TO BE MOUNTED
         AND,SR3  PAT,R6            BECAUSE UNIT UNAVAILABLE
         SCS,10   -7                GET SUBCODE PROPERLY PLACED
         BNEZ     OPV220                YES
*                                       NO,VOL NOT MOUNTED BECAUSE
*                                          JOB ABORTED
         BAL,R0   GETVDCTX         *WAS THE JOB ABORTED BECAUSE A
*                                   FOREIGN VOLUME WAS MOUNTED
         BEZ      OPV50                 NO
         PUSH     R3                    YES,SAVE FOREIGN VOLUME NO
         BAL,R0   SETVNO1           SET DCB FOR PRIMARY VOLUME
         BAL,R15  SETPVI
         BAL,R0   RDVTOC            READ PRIMARY VOLUME VTOC INTO BUF1
         LI,R4    VTOC:SNTD
         LW,R4    *D3,R4
         PULL     R3
         CW,R3    *D3,R4
         BLE      OPV45
OPV44    BAL,SR4  PVERR                 ERROR,FOREIGN VOL NOT IN SNT
OPV45    AI,R3    -1
         BEZ      OPV44                 ERROR,FOREIGN VOL IS PRIM  VOL
         STW,R3   *D3,R4           *REMOVE FOREIGN VOL FROM VTOC
*                                   SERIAL NO. TABLE
         LI,3     -1
         STW,3    BUFF1             SET UPDATED FLAG
         BAL,0    WRVTOC            AND WRITE IT
OPV50    EQU      %                *CANNOT OPEN FILE ON PRIVATE VOLUME,
         LI,10    X'1406'
         SCS,10   -8
         B        OPV220
OPV70    RES      0
         BIR,9    OPV131            SETACOG CALL, ALREADY HAVE SN LIST
         CI,R3    1                 WAS THE PRIMARY VOLUME JUST OPENED
         BNE      OPV130                NO
         LI,D3    BUFF1
         LI,R0    BUF1MSK
         AND,R0   BUFX,R6           IS VTOC IN BUF1
         BNEZ     OPV75                 YES
         BAL,R0   RDVTOC                NO,READ VTOC INTO BUF1
OPV75    EQU      %                 MUST VERIFY THAT THIS VOLUME
*                                   IS INDEED THE PRIMARY VOLUME.
*                                   IF IT IS NOT, WE MUST MOUNT THE
*                                   PRIMARY VOLUME.
*
         BAL,R0   GETSNT            R7 = VTOC:SNT
         LW,R7    1,R7              GET PRIMARY SN
         CW,R7    BUFF1+1           IS THIS IT
         BE       OPV79             YES
         PUSH     R7                REMEMBER PRIMARY SN
         BAL,R0   WRVTOC            CLEAR DCB:BBUD
         BAL,R0   CLOSEPV           CLOSE VOLUME
         BAL,R0   GETSNADR
         AI,D2    1
         PULL     R7
         STW,R7   *D2               PRIMARY SN TO DCB:SNT
         B        OPV25             REOPEN PRIMARY VOLUME
OPV79    BAL,D2   GETFUN
         BAL,R0   GETSNADR
         CI,D1    1                 IS THIS AN INPUT-ONLY FILE
         BE       OPV110                YES
OPV80    LW,SR1   *D2,R2                NO,CHECK TO SEE IF ANY NEW
         BAL,R0   GETSNT  R7=VTOC:SNT ADR  VOLUMES ARE  BEING ADDED
*                         R4=SN COUNT      TO  THE  SET
         ANLZ,SR4 OPV90             IF NO MORE WILL FIT
         CI,SR4   BUFF1+511         DONT ADD ANY
         BGE      OPV100
OPV90    CW,SR1   *R7,R4
         BE       OPV100
         BDR,R4   OPV90
         LI,SR4   -1                NEW VOLUME,ADD SERIAL NO. TO
         STW,SR4  BUFF1              LIST AND SET UPDATED FLAG
         MTW,1    0,R7
         LW,R4    0,R7
         STW,SR1  *R7,R4
OPV100   BDR,R2   OPV80
OPV110   BAL,R0   GETSNT            MOVE VT0C:SNT TO  DCB:SNT
         LI,R2    3
         CB,R4    *D2,R2
         BG       OPV190                ERROR,NOT ENOUGH ROOM IN THE
*                                             DCB FOR VT0C:SNT
         LI,R2    2
         STB,R4   *D2,R2
OPV120   LW,SR1   *R7,R4
         STW,SR1  *D2,R4
         BDR,R4   OPV120
OPV130   BAL,R0   WRVTOC           *UPDATE VOLUME TABLE OF CONTENTS,IF
*                                   CHANGED AND RELEASE BUF1
OPV131   RES      0                 MAKE SURE THAT THE PROPER # OF VOLS IS OPEN
         BAL,R0   GETORG
         BL       OPV140            CONSECUTIVE FILE,ONLY OPEN THE
*                                                    PRIMARY VOLUME
         BAL,SR4  NXTVOL           *KEYED OR RANDOM FILE,DOES THE NEXT
*                                                         VOLUME EXIST
         BL       OPV30                 YES,OPEN NEXT VOLUME IN SET
         BAL,R0   SETVNO1               NO,ALL VOLUMES IN SET OPENED
         BAL,D4   SETPVI                   POINT DCB TO PRIMARY VOLUME
OPV140   BIR,9    OPV170            SETACOG CALL: ALREADY CHECKED ACCN
         BAL,R0   GETSEC            *GET INDEX BUFFER (D3=BUF2 ADR)
         LI,D1    DPADFDA          *D1=DISC ADR OF PRIVATE VOL ACCOUNT D
OPV150   BAL,SR3  RWREX
         BAL,SR4  PVQUEUE          *READ ACCOUNT DIRECTORY INTO BUF2
         BAL,SR4  IOSPIN           *WAIT UNTIL READ COMPLETED
         BAL,R0   RESBLK
         LI,R7    J:JIT+ACCN
         LW,R0    FLD,R6
         REF      ACCN
         BEZ      %+2               IT'S A SCRATCH
         BAL,R0   GETACNADR         R7=DCB:ACN ADR
         LW,SR3   0,R7
         LW,SR4   1,R7              SR3,SR4=DCB:ACN
         LW,R0    BUFF2+4           *DOES THE VOL HAVE AN ACCOUNT
         BNEZ     OPV160                YES
         BAL,D2   GETFUN                NO,VOLUME NOT OWNED
         CI,D1    KA
         BAZ      OPV200                  *ERROR,IN/INOUT FILE DOES NOT
*                                                EXIST ON UNOWNED VOL
         STD,SR3  BUFF2+4           SET ACCOUNT
         LI,D1    DPADFDA              D1=DISC ADDR OF PRIV AD
         LI,R0    OPV170            RETURN TO 'OPV170' FROM WRTSEC
         PUSH     9,D1                     (PARALLEL PULL IN WRTSEC)
         LI,D3    BUFF2             BUFFER ADDRESS
         B        WRTSEC10          UPDATE PRIVATE ACCOUNT DIRECTORY
OPV160   CD,SR3   BUFF2+4           ACCOUNTS MUST BE SAME
         BNE      OPV200                NO
OPV170   LI,R3    K2               *SET R3 EQUAL TO NORMAL RETURN AND
         B        OPVX              EXIT
OPV190   LI,SR3   X'D'             *ERROR CODE=NOT ENOUGH ROOM IN
         B        OPV220            DCB:INSN FOR PRIVATE VOLUME SNT
OPV200   LI,SR3   X'14'             ERROR CODE DCB:ACN NOT EQUAL
OPV220   LI,R3    K0                PRIVATE VOLUME ACCOUNT NO.
OPVX     XW,R3    *TSTACK           EXIT
         B        0,R3
         TITLE    '**** GETSNT ****'
*        PURPOSE: TO CALCULATE THE ADDRESS OF A PRIVATE VOLUME'S
*                 SERIAL NO. TABLE (WITHIN VTOC)
*
*        INPUT:   D3=VTOC BUF ADR
*
*        CALL:    BAL,R0  GETSNT
*
*        OUTPUT:  R7=ADR OF VTOC SERIAL NO. TABLE
*                 R4=NO. OF SERIAL NOS IN THE TABLE
*
*        REGS:    ONLY R7,R4 VOLATILE
*
GETSNT   EQU      %
         LI,R7    VTOC:SNTD
         LW,R7    *D3,R7
         AW,R7    D3
         LW,R4    0,R7
         B        *R0
         SPACE    3
GETACNADR EQU     %
         LI,R2    HAACD
         LH,R7    *R6,R2
         AW,R7    FLP,R6
         B        *R0
         TITLE    '**** S:DAVR ****'
*        PURPOSE: TO SEARCH THE DAVRTBL SUBTABLE OF THE AVRTBL FOR A
*                 DEVICE OF THE SAME TYPE AS SPECIFIED FOR THE FILE,
*                 GIVEN A SEARCH CRITERIA
*
*        INPUT:   R3=VOLUME NO,IF SEARCHING FOR A SERIAL NO.
*                   =0,IF LOOKING FOR AN UNUSED DAVRTBL ENTRY
*                   =-1,IF DAVRTBL SERIAL NO. TO BE IGNORED
*                 R4 (BYTE-0)=AVRTBL FLAGS TO SEARCH FOR
*                 R4 (RIGHT HWD)=FFFF IF AVRNOU MUST BE 0
*                               =0    IF ANY AVRNOU IS OK
*                 R5 (BYTE-0)=MASK FOR FLAG SEARCH
*                 R6=DCB ADR
*                 D2=ADR OF DCB PRIVATE VOLUME SERIAL NO. TABLE,
*                    IF R3 IS GREATER THAN ZERO
*
*        CALL:    BAL,R0 S:DAVR
*
*        OUTPUT:  (ONLY IF ENTRY LOCATED)
*                 R2=AVRTBL INDEX OF ENTRY
*                 R5=ADDRESS OF AVRTBL ENTRY
*
*        RETURN:  (R0),IF ENTRY NOT LOCATED
*                 (R0)+1,IF ENTRY LOCATED
*
*        REGS:    ALL NONVOLATILE EXCEPT R2,R7,R14,R15
*                 AND R5 IF ENTRY LOCATED
DAVRFE   EQU      AVRTBLSIZ         FIRST DIRECT ACCESS AVRX
DAVRLE   EQU      AVRTBLNE          LAST+1 AVRX
*
S:DAVR   EQU      %
         LI,R2    DAVRFE-1          R2=INDEX OF DAVRTBL ENTRY
DA10     AI,R2    1
         CI,R2    DAVRLE
         BGE      DA25              END OF DAVRTBL ENCOUNTERED
DAAD     LD,D3    AVRTBL,R2
         CI,R3    0                 IS THE SERIAL NO TO BE IGNORED
         BL       DA20                  YES
         BNE      DA15                  NO,LOOK FOR MATCHING SERIAL NO.
         CI,D4    0                     NO,LOOK FOR UNUSED AVRTBL ENTRY
         BLZ      DA10              IS PUBLIC, CAN'T BE 0 SER#
         CI,D3    0
         BNE      DA10              NOPE
         B        DA20              YUP
DA15     CW,D3    *D2,R3            ARE THE SERIAL NOS EQUAL
         BNE      DA10                  NO
DA20     CS,R4    D4                    YES,IS THIS ENTRY WANTED
         BNE      DA10                          NO
         CH,R4    AVRNOU,R2         IS AVRNOU     O K
         BANZ     AV10              NO
         LW,R7    R2                GET DCT INDEX FOR
         AI,R7    BATAPE            PARTITIONED DEVICE AND RESOURCE TYPE
         LC       DCT3,R7           CHECKS
         BCS,2    DA10              PARTITIONED, CANT USE THIS ONE
         LB,R14   DCT4,R7           GET DEVICE TYPE
*  CHECK DEVICE TYPES AND SET IF DCB=0--ERR IF HGP NOT SAME
         LI,7     BARNDEV
         MTB,0    *6,7
         BNEZ     DAJD
         STB,14   *6,7              SET TYPE
DAJD     CB,14    *6,7
         BNE      DA10              DON'T MATCH
         ANLZ,R5  DAAD              DWD ADDRESS OF ENTRY
         SLS,R5   1                 WORD ADDRESS
         AI,R0    1                             YES,ENTRY LOCATED
DA25     RES
         B        *R0
         TITLE    '**** S:TSERS, S:TSERX ****'
S:TSERX  EQU      %
         PUSH     5                 SAVE ID
         LI,5     JB:XLNK-BA(LSERIAL)    BYTE DISP TO LINK IN JIT
STSER    EQU      %
         LB,5     LSERIAL,5
         BEZ      TSEXIT
         CW,3     TSERIAL,5
         BNE      %-3
         PUSH     0
         B        SETTYPE           IN DCB
*
*
S:TSERS  EQU      %                 UNLINK SHARED SERAIL #
         PUSH     5                 SAVE USER ID
         LI,5     JB:SLNK-BA(LSERIAL)   BYTE DISP TO LINK IN JIT
         PUSH     0
TSER1    LW,0     5                 SAVE PREV INDEX FOR DELINKING
         LB,5     LSERIAL,5
         BEZ      TSER2
         CW,3     TSERIAL,5
         BNE      TSER1
         PUSH     5
         LB,5     LSERIAL,5         FOUND, DELINK IT
         XW,0     5
         STB,0    LSERIAL,5
         PULL     5
         DISABLE
         LB,0     LSERIAL           HEAD OF FREE ENTRIES
         STB,0    LSERIAL,5
         STB,5    LSERIAL
SETTYPE  LB,0     RSERIAL,5         SET TYPE IN DCB
         LI,5     BARNDEV
         STB,0    *6,5
         ENABLE
TSER2    PULL     0                 RESETS CC1
TSEXIT   EQU      %
         AI,5     0                 CHK END OF CHAIN
         STCF     0                 SAVE RETURN COND CODES
         PULL     5                 RESTORE USER #
         LC       0                 RESTORE COND CODES
         B        *0                RETURN
*  DON'T UNLINK THE SHARED SERIAL ENTRY
S:TSER   EQU      %
         PUSH     5                 SAVE USER #
         LI,5     JB:SLNK-BA(LSERIAL)   BYTE DISP TO LINK IN JIT
         B        STSER
         SPACE    2
SC31     SCREECH  X'31'
MOUNTMES EQU      %
         DATA,6   'MOUNT '
         DATA,2   X'0000'
COUNT    DATA     X'13404040'
DISMES   DATA,6   'DISMT '
         DATA,2   X'0000'
SAVMES   DATA,6   'SAVE  '
         DATA,2   0
         TITLE    '**** MOUNDISMT  MOUNT1 ****'
*        PURPOSE: TO CONSTRUCT (MOUNDISMT) AND OUTPUT A
*                 MOUNT, DISMT, OR ERROR MESSAGE TO THE
*                 OPERATOR FOR PRIVATE VOLUME MOUNTING FUNCTIONS
*
*        INPUT:
*         MOUNDISMT R2=AVR INDEX (BIT0 SET IF DISMT)
*                   R3=EBCDIC SERIAL NUMBER
*
*         MOUNT1    R0-R4 TEXTC MESSAGE (R1 MUST NOT BE 'MOUN')
*
*        CALL:    BAL,R11
*
*        OUTPUT:  AVR ENTRY CLEARED IF ERROR MESSAGE
*                 OR IF USER YC,BREAK OR OPER ERR,ABRT
*                 MOUNT WAITS FOR OPERATOR KEYIN
*                 DISMT JUST RETURNS IMMEDIATELY
*                 R0=2 IF OPERATOR KEYIN RECEIVED
*                 R0=-2 IF ESCAPE FROM WAIT
*                 AVRID=0 ALWAYS (MOUNT,DISMT, ERRS)
*
*        REGS:    R2,R5-R11 NON-VOLATILE
*
MOUNDISMT RES     0
         LW,R1    MOUNTMES          ASSUME MOUNT
         LW,R4    R3                R4=SERIAL NO
         LW,15    2                 SAVE AVR INDEX
         BGEZ     MDSM3
         LI,R1    BGRCFU            IF ANY INACTIVE CFU POINT HERE,
         LI,R3    X'F0000'          ZAP THEM
         AI,R2    X'3C00'+BATAPE
         SLS,R2   16
         LI,R0    X'10000'          PRIV BIT
MDSM1    LC       *R1
         BCS,12   MDSM2             ACTIVE
         CW,R0    0,R1
         BAZ      MDSM2             NOT PRIVATE
         CS,R2    2,R1
         BNE      MDSM2
         STW,R1   2,R1
MDSM2    AI,R1    CFUSIZE
         CW,R1    ACNCFU+13
         BLE      MDSM1
         LW,R2    R15               RESTORE AVR INDEX
         LW,R1    DISMES            NO, DISMT
MDSM3    AI,R2    BATAPE
         LD,R2    DCT16,R2
         LW,R0    COUNT             MOUNT,SAVE,OR DISMT MESSAGE
         SLD,R2   8
         AND,R2   M16
         AI,3     ','
         OR,R2    MOUNTMES+1
MOUNT1   RES      0
         LCI      5
         STM,0    J:BASE+1
         LW,R12   Y8                MAKE PLIST
         LI,R13   J:BASE+1
         PUSH     9,R5              SAVE REGS AND PLIST IN STACK
MOUNT10  EQU      %
         LW,R7    TSTACK
         AI,R7    -1                R7 POINTS TO PLIST
         LI,SR1   K2
         LI,R5    J:JIT
         PUSH     15                SAVE AVR INDEX
         BAL,11   MSROCTY
         PULL     15                RESTORE AVR INDEX
         LW,2     15
         BLZ      MOUNT3            IF DISMT, JUST EXIT
         LW,3     S:CUN
         LW,R1    J:BASE+2          GET 'MOUN','DISM'
*                                   SEE IF WAIT IS NECESSARY
*
         CW,R1    MOUNTMES          MOUNT
         BE       AVRWT
AVRCLEAR EQU      %
         LD,4     AVRTBL,2
         LI,4     0                 CLEAR SER #
         AND,5    M16               CLEAR FLAGS
         STD,4    AVRTBL,2
         STB,4    SOLICIT,2
         STH,4    AVRNOU,2          HAD BETTER ALREADY BE 0
MOUNT3   EQU      %
         PULL     9,R5              RESTORE REGS
         STH,R12  AVRID,R2          ZAP AVRID (12 HAS Y8 FROM PLIST)
         B        *R11
*
*
AVRWT    EQU      %
         BAL,11   AVRWTCHK          DID WE MISS KEYIN
         LI,6     60                SLEEP FOR 60*1.2 SECONDS
         STW,6    U:MISC,3          ASSUMES E:SL IS ABOUT 18
         LI,6     E:SL
         BAL,11   T:REG
         BAL,11   AVRWTCHK          IS IT TIME TO GO BACK
         B        MOUNT10           NO, PUT OUT MOUNT AGAIN
AVRWTCHK EQU      %
         LI,0     -2                SET ERR FLAG FOR USECHECK
         LH,R6    UH:DL,R3          GET ERR,ABRT,BRK, & EC FLAGS
         CI,R6    X'F000'
         BANZ     AVRCLEAR          YES
         LI,0     2
         MTB,0    SOLICIT,2         DID WE GET AVR OR KEYIN
         BEZ      MOUNT3
         LH,R6    AVRID,R2
         BEZ      *R11              OK, NOT ASSIGNED
         CW,R6    S:CUN             IS IT SOMEONE ELSES
         BE       *R11              NO, KEEP WAITING
         B        MOUNT3
         TITLE    '**** MTPV ****'
*        PURPOSE: TO MOUNT A PRIVATE VOLUME AND TO VERIFY THE SERIAL NO
*
*        INPUT:   R6=DCB:ADR
*                 DCB:VNO=VOLUME NO. OF THE VOLUME TO BE MOUNTED
*
*        ENTERED FROM AV40 IN OPENPV
*        RETURNS TO AV10 IN OPENPV
*
*        OUTPUT:  DCB:VNO=0, IF UNABLE TO MOUNT THE VOLUME
*                            DCB:VDCTX,PAT=0: IF RNST ESCAPE
*                            DCB:PAT=0,VDCTX=VOLUME# IF FOREIGN VOL
*                 DCB:VNO UNCHANGED IF VOLUME MOUNTED
*                 AVR:SN=SERIAL NO. OF THE REQUESTED VOLUME
*                 AVR:AVR SET
*                 AVRID=0
*                 J:ASPIN,S:BSPIN OR S:OSPIN SET
*                 AVR:PRIM SET,IF DCB:VNO=1
*                 AVR:VER SET WHILE THE SERIAL NO IS BEING VERIFIED AND
*                     THE BIT MAP IS BEING MOVED TO THE ALLOCATION
*                     TABLE. THIS FIELD GETS RESET WHEN AVR GETS SET
*
*        REGS:    ALL VOLATILE EXCEPT R6
*
MTPV     RES      0
         AND,R6   M17               CLEAR FOREIGN VOLUME FLAG (BIT 14)
MT10     BAL,R0   GETVNO                R3=DCB:VNO
         BAL,R0   GETSNADR              D2=DCB:SNT,R2=SN COUNT
         LI,R4    0
         LW,5     BTYC              CLEAR TYC FIRST
         STS,4    TYC,6
         LW,R5    Y18               INIT & VER BITS MUST BE OFF
         BAL,R0   S:DAVR            LOOK FOR SN IN AVRTBL
         B        MT30              NO ENTRY
         LH,0     AVRID,2           GET CURRENT USER,IF ANY
         BLZ      MT30              LOCKED OUT, TRY ANOTHER
         BEZ      MT27              NOT EXCL BY ANYONE
         CW,0     S:CUN             XCL,IS IT US?
         BE       MT27              YES
         CW,0     J:JIT             ONL,PREMOUNT BY ID?
         BE       MT27              YES
         B        MT30
MT27     LW,0     1,5               GET AVR FLAGS
         CW,0     Y2                IS PACK AVR'D
         BANZ     MT160             YES, JUST ASSOCIATE THIS GUY
         LW,R3    Y08               NO, SET VER FLAG
         STS,R3   1,R5
         B        MT88              AND GO VERIFY THE PACK
MT30     LI,R3    0                *SEARCH AVRTBL FOR ENTRY WITH ZERO
         LW,R5    YB8               SERIAL NO AND PUB=0,AVR=0,INIT=0,
         LI,R4    X'FFFF'           VER=0,NOU=0,NON-PARTITIONED
         BAL,R0   S:DAVR
         B        MT40                  EMPTY ENTRY NOT LOCATED
         B        MT80                  ENTRY LOCATED,OUTPUT MOUNT MSG
MT40     LI,R3    -1               *SEARCH AVRTBL FOR ENTRY WITH ANY
*                                   SERIAL NO AND PUB=0,AVR=0,INIT=0,
         BAL,R0   S:DAVR            VER=0,NOU=0,NON-PARTITIONED
         B        MT50                  ENTRY NOT LOCATED
         B        MT80                  ENTRY LOCATED,OUTPUT MOUNT MSG
MT50     OR,R4    Y2               *SEARCH AVRTBL FOR ENTRY WITH ANY
         LW,R5    YBE               SERIAL NO  AND PUB=0,AVR=1,INIT=0,
         BAL,R0   S:DAVR            VER=0,MTD=0,PRIM=0,NOU=0
*                                   & NON-PARTITIONED
         B        MT60                  ENTRY NOT LOCATED
         B        MT70                  ENTRY FOUND,OUTPUT DISMOUNT MSG
MT60     OR,R4    Y02              *SEARCH AVRTBL FOR ENTRY WITH ANY
         BAL,R0   S:DAVR            SERIAL NO AND PUB=0,AVR=1,INIT=0,
*                                   VER=0,PRIM=1,NOU=0,NON-PARTITIONED
         BAL,R11  PVERR22           UNIT UNAVAILABLE FOR MOUNT
MT70     LW,R3    0,R5              OUTPUT A DISMOUNT MESSAGE
         LW,1     Y08               GRAB ENTRY WITH VER BIT
         STS,1    1,5
         OR,R2    Y8                SET NEGATIVE TO NOT AVRCLEAR
         STW,1    0,5               ZAP SO NOBODY WAITS FOR IT
         BAL,SR4  MOUNDISMT         *OUTPUT A DISMT MESSAGE
         B        MT80
MT80     RES      0                 OUTPUT A MOUNT MESSAGE
         BAL,R0   GETVNO                R3=DCB:VNO
         BAL,R0   GETSNADR              D2=DCB SERIAL NO TABLE ADR
         LW,R3    *D2,R3                R3=VOLUME SERIAL NO
         LW,R0    Y08              *PUT SERIAL NO IN AVRTBL ENTRY;
         LI,R1    KF0000            SET VER AND XCL ONLY
         STW,R3   0,R5
         STS,R0   1,R5
         LW,R2    R5                RECALCULATE AVR INDEX
         AI,R2    -AVRTBL
         SLS,R2   -1
         MTB,1    SOLICIT,2         MARK DRIVE AS SOLICITED
         LW,4     S:CUN
         STH,4    AVRID,2           ID TO AVR TABLE
         BAL,SR4  MOUNDISMT
         BIR,R0   MT164             WAS THE JOB ABORTED BY THE OPERATOR
         CW,R3    0,R5              WAS THE REQUESTED VOLUME MOUNTED
         BE       MT88                  YES
         LW,R1    Y08                      DAVRTBL AGAIN
         STS,R0   1,R5
         B        MT10
MT88     EQU      %
         PUSH     R5                (SAVE AVRTBL ENTRY ADR)
         AND,R6   M17               CLEAR FOREIGN VOLUME FLAG (BIT 14)
         AI,2     BATAPE            READ VTOC INTO BUF1
         LI,3     BAVDCTX           SET DCTX SO RDVTOC CAN FIND IT
         STB,2    *6,3
         BAL,0    RDVTOC
         PULL     R5                    R5=AVRTBL ENTRY ADR
         LW,1     TYC,6
         AND,1    BTYC              TYC CAN'T BE >1
         BNEZ     MT180             REPORT NOT INIT FOR ERROR
         LI,R1    BUFF1             VTOC BUFFER ADDRESS
         LCI      3
         LM,D2    *R1                   D2=:LBL (IF VOLUME INITIALIZED)
         CW,D2    T:LBL             IS THE VOLUME INITIALIZED
         BNE      MT180                 NO,OUTPUT ERROR MESSAGE
*                                       YES;D3,D4=VOLUME SERIAL NO
         CW,D3    0,R5             *DID THE OPERATOR MOUNT THE REQUESTED
*                                   VOLUME
         BNE      MT170                 NO,OUTPUT ERROR MESSAGE
*                                       YES
         LW,R7    7,R1
         BLZ      MT180             1ST CYL AVAIL, BAD NEWS
         LI,R7    K1FFFF           *MOVE THE VOLUME'S CYLINDER BIT MAP
         AND,R7   1,R5              TO ITS ALLOCATION  TABLE
         AI,R7    HGP                   R7=ADR OF VOLUME'S ALLOCATION TB
         LI,3     X'FFFF'           CHECK THAT BIT MAP WILL FIT FIRST
         LW,2     VTOC:MAPWL,R1     SIZE OF PACK BITMAP
         CS,2     4,7
         BG       VTOC%HGP%ERR      WONT FIT
         LH,3     2                 GET CYLSZ, IF THERE
         BNEZ     MT100
         LI,3     X'FF'             USE     CYLSZ IN CORE HGP
         STB,3    BUFF1             MAKE WRITE HAPPEN
         AND,3    1,7
         STH,3    2
         STW,2    VTOC:MAPWL,1
MT100    EQU      %
         LI,4     7                 SET CORE HGP TO SAME CYLSZ AS PACK
         STB,3    *7,4
         INT,3    4,7               GET SIZE OF CORE BITMAP
         AND,2    M16               SIZE OF PACK MAP
         SW,3     2                 #WORDS TO ZAP
         AI,3     1                 +1 FOR BDR
         AI,2     2                 MOVE NVAT TOO
         LI,4     5                 START AT WORD 5
         LW,0     *1,4
         STW,0    *7,4
         AI,4     1
         BDR,2    %-3               MOVE ALL PACK BITMAP
         LI,0     0
         BDR,3    %-4               THEN ZAP THE REST
MT110    LW,R4    R1
         AW,R4    VTOC:SNTD,R1          R4=ADR OF VTOC SERIAL NO. TABLE
         BAL,R0   GETVNO            WAS A PRIMARY VOLUME REQUESTED
         CI,R3    1     R3=VNO
         BNE      MT140                 NO
         LW,R3    Y02                   YES,SET AVR:PRIM
         STS,R3   1,R5
         LW,R3    0,R4              IS THIS AN UNUSED VOLUM&
         BEZ      MT140                 YES,PUT SERIAL NO IN SNT
MT130    LW,R3    1,R4                  NO,IS THIS THE PRIMARY VOLUME
         CW,R3    1,R1
         BE       MT150                        YES,CONTINUE
         LI,R2    0                            NO,RESET VER AND PRIM
         LW,R3    Y0A                             FLAGS IN AVRTBL ENTRY
         STS,R2   1,R5                            (LEAVE VOL PREMOUNTED)
         LW,R3    1,R4                            AND PUT PRIMARY VOLUME
         BAL,R0   GETSNADR                        NO IN DCB SERIAL NO
         LI,R2    1                               TABLE AND SEARCH
         STW,R3   *D2,R2                          DAVRTBL FOR PRIMARY
         B        MT10                            VOLUME
MT140    BAL,R0   GETSNADR         *SECONDARY VOLUME REQUESTED
         LI,R2    1
         LW,R3    *D2,R2                R3=SERIAL NO OF PRIMARY VOLUME
         LW,R0    0,R4                  IS THIS AN UNUSED VOLUME
         BEZ      MT145
*                                           NO,DOES THE VOLUME BELONG
         CW,R3    1,R4                         TO THE SET
         BE       MT150                            YES
         B        MT190                            NO,ERROR
MT145    LI,D2    -1                    YES,SET UPDATED FLAG
         STW,D2   BUFF1
         STW,R2   0,R4                          IN VTOC BUFFER
         STW,R3   *R4,R2
MT150    RES      0
*                                  *RESET AVR:VER,SET  AVR:AVR  TO
         LW,R2    Y2                INDICATE THAT VOLUME MOUNTED AND
         LW,R3    Y68               VERIFIED
         STS,R2   1,R5              SET FLAGS
         BAL,0    WRVTOC            UPDATE VTOC IF CHANGED
         SPACE    3
MT160    RES      0
         B        AV10
         SPACE    2
MT164    RES      0
*        GET TYPE FROM DCB IN BADEVTP
         BAL,5    DEPACK
         LI,R2    0
         LI,R3    K1FFFF
         STS,R2   PAT,R6
         LI,R2    0
         CI,R6    K20000  WAS JOB ABORTED BECAUSE FOREIGN VOLUME MOUNTED
         BAZ      MT168       NO,SET DCB:VDCTX=0
         AND,R6   M17         YES,SET DCB:VDCTX=FOREIGN VOLUME NO.
         LI,R2    BAVNO
         LB,R2    *R6,R2
MT168    LI,R3    BAVDCTX
         STB,R2   *R6,R3
         LI,R2    0
         LI,R3    BAVNO             SET DCB:VNO=0 AND EXIT
         STB,R2   *R6,R3
         B        MT160
MT170    BAL,R11  MT184             OUTPUT 'XXXX REEL NO. ERROR'
         TEXTC    'XXXX REEL NO. ERROR'
MT180    BAL,R11  MT184             OUTPUT 'XXXX NOT INIT'
         TEXTC    'XXXX NOT INIT'
MT184    LCI      5                 GET MESSAGE IN 0,1,2,3,4
         LM,R0    *R11
         SCD,0    8                 PUT SERIAL# IN BYTES 1,2,3,4
         LW,R0    0,R5
         SCD,0    -8
         LW,15    5                 GET AVR INDEX FOR CLRDAVR
         AI,15    -AVRTBL
         SLS,15   -1
         BAL,SR4  MOUNT1
         B        MT10
MT190    EQU      %                *A NEW VOLUME HAS BEEN ADDED TO
         AI,R6    K20000           *SET 'FOREIGN VOLUME' FLAG AND TYPE
         BAL,R11  MT184             'XXXX NOT IN SET' AND GIVE OPERATOR
         TEXTC    'XXXX NOT IN SET' A CHANCE TO MOUNT THE CORRECT VOLUME
*                                   (IF VOLUMES HAVE DUPLICATE SN'S) OR
*                                   ABORT THE JOB
*
VTOC%HGP%ERR EQU  %                 BAD VTOC SIZE                       DISCB
         BAL,R11  MT184             OUTPUT 'XXXX BAD VTOC'
         TEXTC    'XXXX BAD VTOC'
*
*
T:LBL    TEXT     ':LBL'
YB8      DATA     X'B8000000'
YBE      DATA     X'BE000000'
Y68      DATA     X'68000000'
Y18      DATA     X'18000000'
*
*
*
PVERR22  SUA      X'22'
BTYC     DATA     X'00FC0000'
KFF      EQU      X'FF'
KF0000   EQU      X'F0000'
K20000   EQU      X'20000'
         END

