Google
 

Trailing-Edge - PDP-10 Archives - AP-4178E-RM - swskit-sources/mstr.mac
There are 55 other files named mstr.mac in the archive. Click here to see a list.
;<OSMAN>MSTR.MAC.3, 17-May-78 11:19:12, EDIT BY OSMAN
;<OSMAN>MSTR.MAC.2, 16-May-78 16:54:42, EDIT BY OSMAN
;ADD .MSHOM FUNCTION OF MSTR
;<3A.MONITOR>MSTR.MAC.3,  4-May-78 07:44:56, EDIT BY MILLER
;CHECK FOR TOO MANY UNITS IN STRUCTURE ON MOUNT
;<3A.MONITOR>MSTR.MAC.2,  7-Mar-78 13:31:12, Edit by MCLEAN
;REMOVE STRMES BUGINF BECAUSE IT WAS CAUSED BY SHUTDOWN
;<3A.MONITOR>MSTR.MAC.1, 17-Feb-78 06:47:37, Edit by GILBERT
;MAKE .MSRUS/.MSRNU FUNCTIONS RETURN DISK SIZE INFO EVEN IF UNIT OFF LINE
;<3.SM10-RELEASE-3>MSTR.MAC.2, 30-Jan-78 20:59:39, Edit by MCLEAN
;FIX EXTENDED ADDRESSING BUG IN CALL TO GETSTR
;<3-MONITOR>MSTR.MAC.49,  7-Nov-77 13:04:14, EDIT BY KIRSCHEN
;MORE COPYRIGHT UPDATING...
;<3-MONITOR>MSTR.MAC.48, 26-Oct-77 10:45:20, EDIT BY KIRSCHEN
;FIX UNICHK FOR NEW GETSTR CALLING SEQ, SO .MSRUS WILL WORK ON W/L UNITS
;<3-MONITOR>MSTR.MAC.47, 12-Oct-77 14:00:11, EDIT BY KIRSCHEN
;UPDATE COPYRIGHT FOR RELEASE 3
;<3-MONITOR>MSTR.MAC.46, 27-Sep-77 12:55:33, EDIT BY MILLER
;CHANGE DISMOUNT CODE TO UPDPGS OF OFN BEFORE CALLING MRKOFN AND
; TO RELOFN THE OFN AFTER CALLING MRKOFN
;<3-MONITOR>MSTR.MAC.45, 20-Sep-77 14:22:52, EDIT BY HURLEY
;MAKE THE STR NUMBER PART OF THE STRUCTURE UNIQUE CODE
;<3-MONITOR>MSTR.MAC.44, 31-Aug-77 15:21:55, EDIT BY HALL
;MOVE DEFINITION OF .MSRIX TO MONSYM
;<3-MONITOR>MSTR.MAC.43, 12-Aug-77 15:14:05, EDIT BY KIRSCHEN
;FIX BUG IN MSTIMC/MSTDMC - DON'T USE STRING PTR INSTEAD OF STR UNIQUE CODE
;<3-MONITOR>MSTR.MAC.42,  6-Aug-77 20:57:29, Edit by MCLEAN
;<3-MONITOR>MSTR.MAC.41,  3-Aug-77 12:58:23, EDIT BY KIRSCHEN
;FIX RACE AT MSGU10, CALL MAPJSB INSTEAD OF SETJSB
;<3-MONITOR>MSTR.MAC.40, 28-Jul-77 00:04:35, Edit by MCLEAN
;ADD TCO 1845 MSTX35
;<3-MONITOR>MSTR.MAC.39, 27-Jul-77 11:31:03, EDIT BY HURLEY
;<3-MONITOR>MSTR.MAC.38, 27-Jul-77 10:58:41, EDIT BY HURLEY
;ASSIGN SDB BLOCKS FROM RESIDENT FREE POOL
;<3-MONITOR>MSTR.MAC.37, 21-Jul-77 16:40:38, EDIT BY HALL
;TCO 1813 - CHANGE CALL TO CREIDX TO FNDIDX
;<3-MONITOR>MSTR.MAC.36, 20-Jul-77 20:08:07, EDIT BY HALL
;TCO 1813 - CHANGE MSTR TO PARALLEL FILINI -- DON'T CALL IDXINI ON
;	MOUNT. DO CALL IT ON REFRESH.  ADD NEW SUBFUNCTION OF INIT
;	FOR REBUILDING IDXTAB
;<3-MONITOR>MSTR.MAC.35,  6-Jul-77 14:35:33, Edit by MCLEAN
;<3-MONITOR>MSTR.MAC.34,  6-Jul-77 14:03:46, Edit by MCLEAN
;<3-MONITOR>MSTR.MAC.33,  3-Jul-77 12:37:50, Edit by MCLEAN
;<3-MONITOR>MSTR.MAC.32,  2-Jul-77 18:43:08, Edit by MCLEAN
;FIX IDX GENERATION IN STRIDX SO IT HAS ITS OWN PAGE
;<3-MONITOR>MSTR.MAC.31, 23-Jun-77 10:57:54, EDIT BY HURLEY
;MOVE THE MARKING OF THE OFN'S TO BE AFTER ALL THE RELOFN'S IN DISMOUNT
;<3-MONITOR>MSTR.MAC.30,  2-May-77 18:47:09, EDIT BY HURLEY
;<3-MONITOR>MSTR.MAC.29,  2-May-77 15:49:48, EDIT BY KIRSCHEN
;TCO 1790 - DO NOT MOUNT STRUCTURES WITH WRITE-LOCKED UNITS
;<3-MONITOR>MSTR.MAC.28,  6-Apr-77 10:01:34, EDIT BY HALL
;CHANGED MS%ASG TO MI%ASG
;<3-MONITOR>MSTR.MAC.27, 26-Mar-77 19:46:20, Edit by MCLEAN
;<3-MONITOR>MSTR.MAC.26, 20-Mar-77 17:42:50, Edit by MCLEAN
;MAKE DEFAULT SIZE OF BOOTSTRAP.BIN USE NPGSBT INSTEAD OF CONSTANT
;<3-MONITOR>MSTR.MAC.25,  7-Feb-77 22:57:23, Edit by MCLEAN
;<3-MONITOR>MSTR.MAC.24, 31-Jan-77 17:26:14, Edit by MCLEAN
;<3-MONITOR>MSTR.MAC.23, 31-Jan-77 01:31:04, Edit by MCLEAN
;<3-MONITOR>MSTR.MAC.22, 31-Jan-77 01:19:33, Edit by MCLEAN
;<3-MONITOR>MSTR.MAC.21, 29-Jan-77 18:08:15, Edit by MCLEAN
;TCO 1720 ADD BOOTSTRAP.BIN
;<3-MONITOR>MSTR.MAC.19, 21-Jan-77 17:12:57, EDIT BY BOSACK
;<3-MONITOR>MSTR.MAC.18, 20-Jan-77 14:39:00, EDIT BY HURLEY
;MAKE IT ILLEGAL TO SET PS FOREIGN
;<3-MONITOR>MSTR.MAC.17, 11-Jan-77 14:37:03, Edit by MCLEAN
;<3-MONITOR>MSTR.MAC.16, 27-Dec-76 17:35:09, EDIT BY HURLEY
;<3-MONITOR>MSTR.MAC.15, 27-Dec-76 17:27:06, EDIT BY HURLEY
;<2-MONITOR>MSTR.MAC.15, 19-Dec-76 15:15:56, EDIT BY KIRSCHEN
;FIX T2 CLOBBERAGE IN MSTRUS WHEN BLT'ING ID INFO
;<3-MONITOR>MSTR.MAC.13, 10-Dec-76 11:34:50, EDIT BY KIRSCHEN
;<2-MONITOR>MSTR.MAC.14,  8-Dec-76 10:43:16, EDIT BY KIRSCHEN
;<2-MONITOR>MSTR.MAC.13,  7-Dec-76 14:20:50, EDIT BY KIRSCHEN
;<2-MONITOR>MSTR.MAC.10,  3-Dec-76 13:28:16, EDIT BY KIRSCHEN
;<2-MONITOR>MSTR.MAC.9,  2-Dec-76 13:47:51, EDIT BY KIRSCHEN
;<2-MONITOR>MSTR.MAC.8,  1-Dec-76 10:12:23, EDIT BY KIRSCHEN
;<2-MONITOR>MSTR.MAC.7, 30-Nov-76 13:53:54, EDIT BY KIRSCHEN
; MAKE .MSGSS FUNCTION RETURN STRUCTURE NAME
;<2-MONITOR>MSTR.MAC.6, 30-Nov-76 13:38:24, EDIT BY KIRSCHEN
;STORE MEDIA ID IN HOME BLOCKS WHEN WRITING NEW HOME BLOCKS OR INITIALIZING
;<2-MONITOR>MSTR.MAC.5, 24-Nov-76 17:01:44, EDIT BY KIRSCHEN
;GET CORRECT DESTINATION ADR FOR FORMING PDP-11 ASCII OWNER ID FIELD
;<2-MONITOR>MSTR.MAC.4, 24-Nov-76 15:31:38, EDIT BY KIRSCHEN
;CHECK FOR A NON-ZERO DISK ADDRESS FOR THE ROOT-DIR IN THE HOME BLOCKS
;<2-MONITOR>MSTR.MAC.3, 24-Nov-76 11:45:49, EDIT BY KIRSCHEN
;IF A HOME BLOCK IS BAD, FIX IT BEFORE BUILDING SDB FOR THE STRUCTURE
;<2-MONITOR>MSTR.MAC.1, 18-Nov-76 20:22:45, EDIT BY KIRSCHEN


;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
;  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (C) 1976, 1977, 1978 BY DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.

	SEARCH PROLOG
	TTITLE (MSTR,,< - MOUNTABLE STRUCTURE MONITOR CALL>)
	SWAPCD


; THIS FILE CONTAINS THE CODE TO IMPLEMENT THE MSTR JSYS
; NO SPECIAL AC DEFINITIONS ARE REQUIRED FOR THIS MODULE.

EXTN <HOMRXB,HOMSNM,HM1BLK,HM2BLK>
; MSTR - STRUCTURE MANIPULATION CALL


.MSTR::	MCENT			;MONITOR CONTEXT ENTRY

; GET AND VERIFY FUNCTION CODE, AND DISPATCH

	XCTU [ HRRZ T1,1 ]	;GET FUNCTION CODE FROM USER
	CAIL T1,0		;MAKE SURE FUNCTION IN RANGE
	CAILE T1,HGHFCN		; AND .LE. HIGHEST VALID FUNCTION CODE ?
	ITERR (MSTRX1)		;NO, RETURN "INVALID FUNCTION"
	HRRZ T2,MSTRTB(T1)	;YES, GET DISPATCH ADDRESS
	CALL (T2)		;GO PROCESS REQUESTED FUNCTION
	 ITERR ()		;FAILED, RETURN ERROR CODE TO USER
	MRETNG			;SUCCESS, RETURN TO USER

; TABLE OF DISPATCH ADDRESSES

MSTRTB:
%%X==.
	MSTRUS		;READ STATUS OF NEXT UNIT
	MSTRUS		;READ STATUS OF A UNIT
	MSTMNT		;MOUNT A STRUCTURE
	MSTDIS		;DISMOUNT A STRUCTURE
	MSTGSS		;GET STATUS OF A STRUCTURE
	MSTSSS		;SET STATUS OF A STRUCTURE
	MSTMNT		;INITIALIZE A STRUCTURE
	MSTIMC		;INCREMENT MOUNT COUNT
	MSTDMC		;DECREMENT MOUNT COUNT
	MSTGSU		;GET STRUCTURE USERS
	MSTHOM		;MODIFY HOME BLOCK
HGHFCN==.-%%X-1		;HIGHEST DEFINED FUNCTION
; .MSMNT/.MSINI - MOUNT/INITIALIZE A FILE STRUCTURE


; LOCAL VARIABLES --

MSTMNP==1		;PHYSICAL PAGE # OF PAGE USED TO READ HOME BLOCKS
MSTMNA==2		;VIRTUAL ADDRESS OF PAGE USED TO READ HOME BLOCKS
MSTMNE==3		;TEMPORARILY HOLDS CODE ON ERRORS, USED AS A LOCAL FLAG
MSTMNS==4		;STRUCTURE NUMBER
MSTMNB==5		;ADDRESS OF STRUCTURE DATA BLOCK
MSTMND==6		;SIXBIT STRUCTURE NAME
MDATSZ==7		;SIZE OF FREE BLOCK USED FOR LOCAL STORAGE

; ACCUMULATOR USAGE --
;
; Q1/ ADDRESS OF USER'S ARGUMENT BLOCK IN USER SPACE
; Q2/ FUNCTION TO PERFORM (.MSMNT OR .MSINI)
; Q3/ ADDRESS OF BLOCK HOLDING LOCAL VARIABLES
; P3/ ADDRESS OF USER'S ARGUMENT BLOCK IN MONITOR SPACE
; P4/ SIZE OF USER'S NON-OPTIONAL ARGUMENT BLOCK

; VERIFY THAT USER HAS REQUIRED CAPABILITIES ENABLED

MSTMNT:	MOVE T1,CAPENB		;GET ENABLED CAPABILITIES
	TXNN T1,SC%WHL!SC%OPR	;WHEEL OR OPERATOR ENABLED NOW ?
	RETBAD (MSTRX2)		;NO, RETURN "WHEEL OR OPERATOR REQUIRED"

; COPY USER ARGUMENT BLOCK INTO MONITOR SPACE

	XCTU [ HLRZ P2,1 ]	;GET SIZE OF USER'S ARGUMENT BLOCK
	MOVEI T2,1(P2)		;ALLOW ONE WORD FOR FREE BLOCK HEADER
	CALL ASGJFR		;ASSIGN FREE SPACE TO HOLD BLOCK
	 RETBAD (MONX01)	;RETURN "INSUFFICIENT RESOURCES" ERROR CODE
	MOVEM T1,P1		;SAVE ADDRESS OF FREE BLOCK
	MOVEI P3,1(T1)		;COMPUTE STARTING ADDRESS OF ARG BLOCK
	UMOVE T2,T2		;GET ADDRESS OF ARG BLOCK IN USER SPACE (SOURCE)
	XMOVEI T3,0(P3)		;GET ADDRESS OF ARG BLOCK IN MONITOR (DEST)
	MOVE T1,P2		;GET COUNT TO TRANSFER
	CALL BLTUM		;COPY USER'S ARGUMENT BLOCK INTO MONITOR SPACE
	; ..
	; ..

; CHECK SIZE OF ARGUMENT BLOCK

	XCTU [HRRZ Q2,1]	;GET FUNCTION TO PERFORM FROM THE USER
	UMOVE Q1,2		;GET ADDRESS OF USER ARGUMENT BLOCK
	HRRZ P4,.MSTNU(P3)	;GET NUMBER OF UNITS IN STRUCTURE
	SKIPG P4		;AT LEAST ONE UNIT SPECIFIED ?
	JRST [	MOVX T1,MSTRX3	;NO, GET "ARG BLOCK TOO SMALL" ERROR CODE
		JRST MNTER1 ]	;GO RELEASE ARG BLOCK SPACE AND RETURN ERROR
	CAILE P4,HOMTBL		;REASONABLE # OF UNITS?
	JRST [	MOVEI T1,MSTX35	;NO. GIVE ERROR
		JRST MNTER1]
	IMULI P4,.MSTNO		;COMPUTE LENGTH OF UNIT SPECIFIC INFO
	ADDI P4,.MSTUI		;ADD NUMBER OF OTHER WORDS
	CAIN Q2,.MSINI		;INITIALIZING THIS STRUCTURE ?
	JRST [	LOAD T4,MS%FCN,.MSTFL(P3) ;YES, GET REQUESTED FUNCTION
		CAIE T4,.MSCRE	;CREATING NEW FILE SYSTEM ?
		CAIN T4,.MSWHB	; OR WRITING HOME BLOCKS ?
		ADDI P4,<.MSIOI+2>-.MSIST+1 ;YES, INCLUDE ID INFO IN COMPARISON
		JRST .+1]	;CONTINUE
	CAMGE P2,P4		;IS USER ARGUMENT BLOCK BIG ENOUGH ?
	JRST [	MOVX T1,MSTRX3	;NO, GET "ARG BLOCK TOO SMALL" ERROR CODE
		JRST MNTER1 ]	;GO RELEASE ARG BLOCK SPACE AND RETURN ERROR

; IF INITIALIZING, CHECK REQUESTED FUNCTION

	CAIE Q2,.MSINI		;INITIALIZING ?
	JRST MSTM10		;NO, GO ALLOCATE SPACE FOR LOCAL VARIABLES
	LOAD T1,MS%FCN,.MSIFL(P3) ;YES, GET FUNCTION REQUESTED
	CAIL T1,.MSCRE		;IS REQUESTED FUNCTION WITHIN
	CAILE T1,.MSRIX		; VALID RANGE ?
	JRST [	MOVX T1,MSTRX1	;NO, GET "INVALID FUNCTION" ERROR CODE
		JRST MNTER1 ]	;GO RELEASE ARG BLOCK SPACE AND RETURN ERROR

; CHECK THAT MOUNT IS EXCLUSIVE IF ERRORS WILL BE IGNORED

MSTM10:	MOVE T1,.MSTFL(P3)	;GET FLAGS FROM USER ARGUMENT BLOCK
	TXNE T1,MS%IGN		;IGNORING ERRORS ?
	TXNE T1,MS%XCL		; BUT NOT MOUNTED EXCLUSIVE ?
	SKIPA			;NO, PROCEED
	JRST [	MOVX T1,MSTRX1	;YES, GET "ILLEGAL FUNCTION" ERROR CODE
		JRST MNTER1]	;GO RELEASE SPACE AND RETURN ERROR

; ALLOCATE SPACE FOR LOCAL VARIABLES

	MOVEI T2,MDATSZ		;GET SIZE OF DATA BLOCK REQUIRED
	CALL ASGJFR		;ASSIGN JSB FREE SPACE
	 JRST [	MOVX T1,MONX01	;NO, GET "INSUFFICIENT RESOURCES" ERROR CODE
		JRST MNTER1 ]	;GO RELEASE ARG BLOCK SPACE AND RETURN ERROR
	MOVEM T1,Q3		;SAVE ADDRESS OF BLOCK RETURNED
	; ..
	; ..

; CHECK FOR A VALID STRUCTURE NAME

	CALL LCKDVL		;LOCK DEVICE LOCK UNTIL DEVICE TABLES MODIFIED
	SKIPN T1,.MSTAL(P3)	;GET ALIAS FOR STRUCTURE
	MOVE T1,.MSTNM(P3)	;NO ALIAS, GET STRUCTURE ID
	CALL CHKNAM		;GO CHECK NAME AND CONVERT TO SIXBIT
	 JRST MNTER3		;FAILED, RETURN ERROR
	MOVEM T1,MSTMND(Q3)	;SAVE SIXBIT DEVICE NAME

	CALL UNICHK		;GO CHECK THE UNIT SPECIFICATIONS
	 JRST MNTER3		;FAILED, UNLOCK DEVICE TABLE LOCK, RETURN ERROR
	CAIE Q2,.MSINI		;ARE WE INITIALIZING THIS STRUCTURE ?
	JRST MSTM30		;NO, GO CHECK THE HOME BLOCKS
	LOAD T1,MS%FCN,.MSIFL(P3) ;YES, GET PARTICULAR FUNCTION REQUESTED
	CAIE T1,.MSCRE		;CREATING NEW FILE SYSTEM ?
	CAIN T1,.MSWHB		; OR WRITING NEW HOME BLOCKS ?
	JRST [	CALL MAKHOM	;YES, GO CREATE A PAIR OF NEW HOME BLOCKS
		 JRST MNTER3 	;FAILED, RETURN ERROR
		JRST .+1 ]	;NOW CHECK THE NEW HOME BLOCKS
MSTM30:	CALL HOMCHK		;GO READ THE HOME BLOCKS, FIX UP IF NEEDED
	 JRST MNTER3		;FAILED, UNLOCK DEVICE TABLE LOCK, RETURN ERROR
	MOVEM T1,MSTMNS(Q3)	;SAVE STRUCTURE NUMBER
	MOVE T2,STRTAB(T1)	;GET ADDRESS OF SDB OF THIS STRUCTURE
	MOVEM T2,MSTMNB(Q3)	;SAVE ADDRESS OF SDB

; SET UP THE UNIQUE CODE FOR THIS STRUCTURE

	CALL LGTAD		;GET TIME AND DATE
	LSH T1,-8		;RIGHT JUSTIFY 5 DATE BITS, 10 TIME BITS
	SKIPN UCSEED		;IS THERE A SEED FOR THIS UNIQUE CODE ?
	HRRZM T1,UCSEED		;NO, STORE AN INITIAL UNIQUE CODE SEED
	AOS T1,UCSEED		;INCREMENT UNIQUE CODE
	LSH T1,STRNS		;SHIFT TO CORRECT POSITION
	ANDI T1,37777		;INSURE CODE IS LESS THAN 40000
				; (CODES ABOVE 40000 ARE FOR STRUCTURES MOUNTED
				;  AT SYSTEM STARTUP TIME)
	TRO T1,500000		;ADD "5B2" FIELD TO UNIQUE CODE
	MOVE T2,MSTMNB(Q3)	;GET ADDRESS OF SDB FOR THIS STRUCTURE
	STOR T1,STRUC,(T2)	;STORE UNIQUE CODE IN SDB
	MOVE T1,MSTMNS(Q3)	;GET THE STR NUMBER
	STOR T1,STRUS,(T2)	;PUT THE STRUCTURE NUMBER INTO STRUC ALSO
	; ..
	; ..

; ADD STRUCTURE TO DEVICE TABLES

	MOVEI T1,DVXST0		;GET OFFSET TO STRUCTURE PART OF TABLES
	ADD T1,MSTMNS(Q3)	;COMPUTE OFFSET FOR THIS STRUCTURE
	MOVX T3,D1%INI		;INDICATE STRUCTURE BEING INITED
	IORM T3,DEVCH1(T1)	;MARK THIS TEMPORARY STATUS OF STRUCTURE
	MOVE T2,MSTMND(Q3)	;GET SIXBIT STRUCTURE NAME
	MOVEM T2,DEVNAM(T1)	;STORE STRUCTURE NAME
	MOVE T2,MSTMNS(Q3)	;GET STRUCTURE NUMBER
	HRRM T2,DEVUNT(T1)	;SAVE "UNIT" NUMBER
	MOVX T3,D1%NIU		;CLEAR INDICATOR THAT THIS SLOT IS NOT
	ANDCAM T3,DEVCH1(T1)	;  NOW IN USE
	MOVE T3,JOBNO		;GET CURRENT JOB NUMBER
	MOVE T4,MSTMNB(Q3)	;GET ADDRESS OF SDB FOR THIS STRUCTURE
	STOR T3,STRJB,(T4)	;INDICATE INITING JOB

; IF INITIALIZING, ASSIGN THE INDEX BLOCK ADDRESSES AND GET ROOT-DIR OFN

	CAIE Q2,.MSINI		;INITIALIZING THIS STRUCTURE ?
	JRST MSTM50		;NO, GO GET AN OFN FOR THE ROOT-DIRECTORY
	LOAD T1,MS%FCN,.MSIFL(P3) ;YES, GET PARTICULAR FUNCTION REQUESTED
	CAIN T1,.MSRRD		;RECONSTRUCT ROOT-DIRECTORY ?
	JRST [	MOVE T1,MSTMNS(Q3) ;YES, GET STRUCTURE NUMBER
		CALL FILREC	;GO RECONSTRUCT THE ROOT-DIR
		 JRST [MOVX T1,MSTX29 ;FAILED, GET ERROR CODE
			JRST MNTER4 ] ;GO RETURN ERROR TO USER
		JRST MSTM50]	;GO FINISH MOUNTING STRUCTURE
	CAIE T1,.MSCRE		;CREATE NEW FILE-SYSTEM ?
	JRST MSTM50		;NO, GO FINISH MOUNTING STRUCTURE
	HRRZ T3,.MSINU(P3)	;YES, GET # OF UNITS IN STRUCTURE
	MOVEI T4,-1(T3)		;GET # OF UNITS - 1
	IMULI T4,.MSINO		;COMPUTE # OF ADDITIONAL PER-UNIT WORDS
	ADDI T4,.MSIFE(P3)	;ADD BASE OFFSET TO FE FILE SYSTEM ARGUMENT
	MOVE T2,(T4)		;GET # OF PAGES TO ALLOCATE FOR FE FILE SYSTEM
	MOVE T3,P4		;FIND NON-OPTIONAL PARAMTERE SIZE
	ADDI T3,.MSIFB-.MSIFI-2	;CHECK TO SEE IF BOOTSTRAP.BIN LIVES
	CAMGE P2,T3
	SKIPA T3,[NPGSBT]	;NOT SPECIFIED -- GET DEFAULT
	MOVE T3,.MSIFB-.MSIFE-2(T4) ;SPECIFIED GET USER'S REQUESTED SIZE
	MOVE T1,MSTMNS(Q3)	;GET THE STRUCTURE NUMBER
	CALL STRINI		;GO SET UP DIRECTORIES AND BIT TABLE ON NEW STR
	 JRST MNTER4		;FAILED, GO RELEASE SDB AND RETURN ERROR CODE
	JRST MSTM70		;GO GET A HANDLE ON THE INDEX TABLE
	; ..
	; ..

; GET AN OFN FOR THE ROOT-DIRECTORY ON THIS STRUCTURE

MSTM50:	MOVE T1,MSTMNS(Q3)	;GET STRUCTURE NUMBER
	CALL SETRDO		;GET AN OFN FOR THE ROOT-DIRECTORY
	 JRST [	MOVX T1,MSTRX8	;ERROR, GET "CANNOT GET OFN" ERROR CODE
		JRST MNTER4 ]	;GO RELEASE SDB AND RETUURN ERROR TO USER
	MOVE T1,MSTMNS(Q3)	;GET STRUCTURE NUMBER
	CALL MNTBTB		;OPEN THE BIT TABLE FILE
	 JRST [	MOVE T1,.MSTFL(P3) ;GET USER'S FLAGS
		TXNN T1,MS%IGN	;MOUNT DESPITE ERRORS ?
		JRST [	MOVX T1,MSTX12 ;GET "CANNOT OPEN BIT TABLE" ERROR CODE
			JRST MNTER5] ;RELEASE OFN OF ROOT-DIR AND RETURN ERROR
		MOVE T1,MSTMNS(Q3) ;YES, GET STRUCTURE NUMBER
		HRRZ T2,STRTAB(T1) ;POINT TO ITS SDB
		MOVX T4,MI%ASG	;FORBID ASSIGNING PAGES UNTIL CHECKD CAN
		IORM T4,SDBSTS(T2) ; RUN AND REBUILD THE BIT TABLE
		JRST .+1]	;CONTINUE TO MOUNT STRUCTURE

;IF IDXTAB EXISTS, GET AN OFN ON IT.  OTHERWISE, CREATE ONE AND
;GET AN OFN ON IT

MSTM70:	MOVE T1,MSTMNS(Q3)	;GET THE STRUCTURE NUMBER
	MOVE T4,[CALL FNDIDX]	;ASSUME IDXTAB EXISTS
	CAIN Q2,.MSINI		;ARE WE INITIALIZING THE STRUCTURE?
	JRST [	LOAD T2,MS%FCN,.MSIFL(P3) ;YES. WHAT ARE WE DOING?
		CAIE T2,.MSRIX	;REBUILDING IDXTAB?
		CAIN T2,.MSCRE	;NO. CREATING NEW FILE SYSTEM?
		MOVE T4,[CALL MAKIDX] ;YES. MAKE A NEW IDXTAB
		JRST .+1]
	XCT T4			;GET OR CREATE IDXTAB FILE
	 JRST MNTER6		;FAILURE. GO RETURN ERROR TO CALLER

;CHECK ROOT-DIRECTORY

	MOVEI T1,ROOTDN		;GET NUMBER OF ROOT-DIRECTORY
	MOVE T2,MSTMNB(Q3)	;GET ADDRESS OF SDB FOR THIS STRUCTURE
	LOAD T3,STRUC,(T2)	;GET UNIQUE CODE
	HRL T1,T3		;BUILD DIR NUMBER
	CALL SETDIR		;MAP IN THE ROOT-DIRECTORY
	 JRST [	MOVX T1,MSTRX9	;COULD NOT MAP DIRECTORY, GET ERROR CODE
		JRST MNTER7 ]	;GO RELEASE SDB AND RETURN ERROR TO USER
	CALL BLKSCN		;CHECK DIRECTORY FOR CONSISTENCY
	 JRST [	CALL USTDIR	;ROOT-DIRECTORY BAD, UNLOCK THE DIRECTORY
		MOVX T1,MSTX10	;GET ERROR CODE
		JRST MNTER7 ]	;GO CLEAN UP AND RETURN ERROR TO USER
	CALL USTDIR		;GO UPDATE AND UNLOCK THE DIRECTORY

; SET UP THE INDEX TABLE

	CAIE Q2,.MSINI		;ARE WE INITIALIZING THE STRUCTURE?
	JRST MSTM75		;NO. SKIP THIS
	LOAD T1,MS%FCN,.MSIFL(P3) ;YES. SEE WHAT WE ARE DOING
	CAIE T1,.MSRIX		;REBUILDING IDXTAB?
	CAIN T1,.MSCRE		;NO. CREATING A NEW FILE SYSTEM?
	SKIPA			;REBUILD IDXTAB OR REFRESH
	JRST MSTM75		;NEITHER. DON'T INITIALIZE IDXTAB
	MOVE T1,MSTMNS(Q3)	;GET STRUCTURE NUMBER
	CALL IDXINI		;INITIALIZE INDEX TABLE
	 JRST [	MOVX T1,MSTX11	;COULD NOT INITIALIZE INDEX TABLE
		JRST MNTER7 ]	;RELEASE SDB AND RETURN ERROR CODE TO USER
	;..
	;..

; CHECK THE BIT TABLE, THE BACKUP ROOT-DIRECTORY, AND THE BAT BLOCKS

MSTM75:	MOVE T1,MSTMNS(Q3)	;GET STRUCTURE NUMBER
	MOVEI T2,0		;NO FLAGS (DON'T TYPE CTY MESSAGES)
	CALL CHKBT		;GO CHECK THE BIT TABLE
	JRST [	MOVX T1,MSTX30	;GET "BIT-TABLE-ERRORS" ERROR CODE
		MOVE T4,.MSTFL(P3) ;GET FLAGS FROM USER ARGUMENT BLOCK
		TXNN T4,MS%IGN	;IGNORE NON-FATAL ERRORS ?
		JRST MNTER7	;NO, RETURN ERROR CODE TO USER
		JRST .+1]	;YES, CONTINUE WITH MOUNT
	CAIE Q2,.MSINI		;ARE WE INITIALIZING THIS STR IN SOME WAY ?
	JRST MSTM80		;NO, GO CHECK THE BACKUP ROOT-DIR
	LOAD T1,MS%FCN,.MSIFL(P3) ;YES, GET THE PARTICULAR FUNCTION REQUESTED
	CAIN T1,.MSRRD		;RECONSTRUCTING ROOT-DIR ?
	JRST MSTM90		;YES, DO NOT CHECK BACKUP ROOT-DIR (NOT THERE!)
MSTM80:	MOVE T1,MSTMNS(Q3)	;GET STRUCTURE NUMBER
	CALL CHKBAK		;CHECK BACKUP COPY OF ROOT-DIRECTORY
	 JRST [	MOVX T1,MSTX13	;GET "BAD BACKUP ROOT-DIRECTORY" ERROR CODE
		JRST MNTER7 ]	;GO RELEASE BIT TABLE OFN AND RETURN ERROR
MSTM90:	CALL ASGPAG		;GET A PAGE FOR READING BAT BLOCKS
	 JRST [	MOVX T1,MONX01	;GET "INSUFFICIENT RESOURCES" ERROR CODE
		JRST MNTER7 ]	;GO RELEASE BIT TABLE OFN AND RETURN ERROR
	MOVEM T1,MSTMNA(Q3)	;SAVE ADDRESS OF BAT BLOCK PAGE
	MOVE T2,T1		;COPY ADDRESS OF BAT BLOCK PAGE
	MOVE T1,MSTMNS(Q3)	;GET STRUCTURE NUMBER
	MOVE T3,.MSTFL(P3)	;GET FLAGS FROM USER ARGUMENT BLOCK
	AND T3,[MS%NFB]		;KEEP ONLY THE NO-FIX-BAT-BLOCK BIT IF SET
	CALL CHKBAT		;GO CHECK THE BAT BLOCKS
	MOVE T1,MSTMNA(Q3)	;GET ADDRESS OF BAT BLOCK PAGE
	CALL RELPAG		;RELEASE THE BAT BLOCK PAGE

; IF ONLY ACTION WAS TO WRITE HOME BLOCKS, GO INSERT FE-FILE SYSTEM POINTER

	CAIE Q2,.MSINI		;ARE WE INITIALIZING THE STR ?
	JRST MSTM92		;NO, GO FIX UP DEVICE TABLES
	LOAD T1,MS%FCN,.MSIFL(P3) ;YES, GET REQUESTED FUNCTION
	CAIE T1,.MSWHB		;WAS REQUEST TO WRITE HOME BLOCKS ONLY ?
	JRST MSTM92		;NO, GO FIX UP DEVICE TABLES
	MOVE T1,MSTMNS(Q3)	;YES, GET STRUCTURE NUMBER
	CALL FIXFES		;GO ADD FE-FILESYSTEM POINTER TO HOME BLOCKS
	 JFCL			;FAILED, OR NO FE FILE SYSTEM ON STR
	MOVE T1,MSTMNS(Q3)	;GET STRUCTURE NUMBER
	CALL FIXBOT		;GO ADD BOOTSTRAP.BIN POINTER TO HOME BLOCKS
	JFCL			;FAILED, OR NO BOOTSTRAP.BIN ON STR

; MARK THAT THE STRUCTURE IS NOW AVAILABLE FOR USE

MSTM92:	MOVE T4,.MSTFL(P3)	;GET FLAGS FROM USER ARG BLOCK
	MOVE T1,MSTMNS(Q3)	;GET STRUCTURE NUMBER
	ADDI T1,DVXST0		;GET OFFSET TO START OF STR INFORMATION
	MOVX T2,D1%INI		;GET "STRUCTURE BEING INITED" FLAG
	TXNN T4,MS%XCL		;LEAVE STRUCTURE "EXCLUSIVE" IF REQUESTED
	ANDCAM T2,DEVCH1(T1)	;MARK THAT STRUCTURE NOT BEING INITED
	HRROS DEVUNT(T1)	;INDICATE STRUCTURE AVAILABLE TO ALL JOBS
	UNLOCK DEVLCK		;UNLOCK THE DEVICE TABLE LOCK
	TXNN T4,MS%XCL		;IS STRUCTURE MOUNTED FOR EXCLUSIVE USE ?
	JRST MSTM95		;NO, GO RELEASE FREE SPACE AND RETURN
	MOVE T1,MSTMNB(Q3)	;YES, GET ADDRESS OF SDB FOR THIS STRUCTURE
	LOAD T1,STRUC,(T1)	;GET UNIQUE CODE FOR THE STRUCTURE
	CALL GTSTOF		;GET STRUCTURE OFFSET IN JSB BLOCKS
	 JRST MSTM95		;FAILED, JUST GO ON
	SETONE JSXCL,(T2)	;NOTE THAT THIS JOB MOUNTED STR EXCLUSIVELY
MSTM95:	MOVEI T1,JSBFRE		;GET FREE HEADER
	MOVE T2,Q3		;GET ADDRESS OF FREE BLOCK
	CALL RELFRE		;RELEASE FREE SPACE FOR LOCAL VARIABLES
	MOVEI T1,JSBFRE		;GET FREE HEADER
	MOVE T2,P1		;GET ADDRESS OF FREE BLOCK
	CALL RELFRE		;RELEASE FREE SPACE HOLDING USER ARG BLOCK
	RETSKP			;RETURN TO USER
; HERE ON ERROR TO RELEASE OFNS AND SDB, AND RETURN ERROR TO USER

MNTER7:	MOVEM T1,MSTMNE(Q3)	;SAVE ERROR CODE
	MOVE T1,MSTMNB(Q3)	;GET ADDRESS OF SDB
	LOAD T1,STRIDX,(T1)	;GET OFN OF INDEX TABLE FILE
	CALL RELOFN		;GO RELEASE THE ROOT-DIRECTORY OFN
	MOVE T1,MSTMNE(Q3)	;RESTORE ERROR CODE
				;FALL INTO MNTER6 TO RELEASE THE BIT TABLE OFN

MNTER6:	MOVEM T1,MSTMNE(Q3)	;SAVE ERROR CODE
	MOVE T1,MSTMNB(Q3)	;GET ADDRESS OF SDB
	LOAD T1,STRBTB,(T1)	;GET OFN OF BIT TABLE FILE
	SKIPE T1		;IF EXCLUSIVE MOUNT, THERE MIGHT NOT BE AN OFN
	CALL RELOFN		;RELEASE THE BIT TABLE OFN
	MOVE T1,MSTMNE(Q3)	;RESTORE ERROR CODE
				;FALL INTO MNTER5 TO RELEASE OFN AND SDB


; HERE ON ERROR TO RELEASE OFN OF ROOT-DIRECTORY, FREE SDB, AND RETURN

MNTER5:	MOVEM T1,MSTMNE(Q3)	;SAVE ERROR CODE
	CALL UNMAPD		;GO UNMAP CURRENTLY MAPPED DIRECTORY
	MOVE T1,MSTMNB(Q3)	;GET ADDRESS OF SDB
	LOAD T1,STRRDO,(T1)	;GET OFN OF ROOT-DIRECTORY
	CALL RELOFN		;GO RELEASE THE ROOT-DIRECTORY OFN
	MOVE T1,MSTMNE(Q3)	;RESTORE ERROR CODE
				;FALL INTO MNTER4 TO RELEASE THE SDB

; HERE ON ERROR TO RELEASE THE SDB AND RETURN ERROR CODE TO USER

MNTER4:	MOVEM T1,MSTMNE(Q3)	;SAVE ERROR CODE
	MOVE T1,MSTMNS(Q3)	;GET STRUCTURE NUMBER
	CALL DEVSTR		;GO FIX UP DEVICE TABLES
	MOVE T1,MSTMNS(Q3)	;GET STRUCTURE NUMBER
	CALL MRKOFN		;MARK OFN'S ON THIS STR AS ON A DISMOUNTED STR
	SKIPE T1,MSTMNB(Q3)	;GET ADDRESS OF SDB
	CALL CLRSTR		;GO CLEAR STRUCTURE INFO IN UDB'S
	MOVE T1,MSTMNS(Q3)	;GET STRUCTURE NUMBER
	CALL CLRSTB		;CLEAR THE STRTAB ENTRY
	MOVE T1,MSTMNE(Q3)	;GET ERROR CODE AGAIN

MNTER3:	MOVEM T1,MSTMNE(Q3)	;SAVE ERROR CODE
	UNLOCK DEVLCK		;UNLOCK THE DEVICE TABLE LOCK
	MOVE T1,MSTMNE(Q3)	;GET ERROR CODE AGAIN

MNTER2:	EXCH T1,Q3		;SAVE ERROR CODE IN Q3, GET ADR OF BLOCK
	MOVE T2,T1		;GET ADDRESS OF BLOCK TO RELEASE
	MOVEI T1,JSBFRE		;GET FREE HEADER
	CALL RELFRE		;RELEASE FREE BLOCK
	MOVE T1,Q3		;GET ERROR CODE BACK AGAIN

MNTER1:	MOVEM T1,Q3		;SAVE ERROR CODE
	MOVEI T1,JSBFRE		;GET FREE HEADER
	MOVE T2,P1		;GET ADDRESS OF FREE BLOCK
	CALL RELFRE		;RELEASE FREE BLOCK
	MOVE T1,Q3		;RESTORE ERROR CODE
	RETBAD ()		;ERROR, CODE IS STILL IN T1
;CHKNAM - ROUTINE TO VALIDATE THE ALIAS FOR THE STRUCTURE AND CONVERT THE
;	  ASCIZ STRING TO SIXBIT FOR INSERTION INTO THE DEVICE TABLES.
;
;ACCEPTS IN T1/	POINTER TO ASCIZ STRING IN USER SPACE
;		CALL CHKNAM
;RETURNS: +1	 FAILURE, ERROR CODE IN T1
;	  +2	SUCCESS, T1/ SIXBIT STRUCTURE ALIAS FOR DEVNAM TABLE

CHKNAM:	STKVAR <CKNERR,CKNBLK,CKNNAM>
	SETZM CKNERR		;INITIALIZE ERROR FLAG
	CALL CPYFUS		;COPY STRING FROM USER SPACE
	 RETBAD (MONX01)	;FAILED, RETURN "INSUFFICIENT RESOURCES" ERROR
	MOVEM T1,CKNBLK		;SAVE ADDRESS OF BLOCK CONTAINING ASCIZ STRING
	CALL ASCSIX		;GO CONVERT THE ASCIZ INTO SIXBIT
	 JRST [	SETOM CKNERR	;FAILED, INVALID SIXBIT NAME. SET ERROR FLAG
		JRST CKNM30 ]	;GO RELEASE FREE BLOCK AND RETURN ERROR CODE
	MOVEM T1,CKNNAM		;SAVE SIXBIT ALIAS
	JUMPE T1,[SETOM CKNERR	;NULL NAME, SET ERROR FLAG
		  JRST CKNM30]	;GO RELEASE FREE BLOCK AND RETURN ERROR
	HRRZ T2,CKNBLK		;GET ADDRESS OF BLOCK CONTAINING ASCIZ NAME
	HRLI T2,(POINT 7,0,35)	;FORM POINTER TO ASCIZ STRING

CKNM10:	ILDB T1,T2		;GET A CHARACTER FROM THE STRUCTURE NAME STRING
	JUMPE T1,CKNM20		;END, SEE IF NAME ALREADY IN DEVICE TABLE
	CALL CHRCHK		;GO CHECK THIS  CHARACTER
	 SETOM CKNERR		;FAILED, BAD CHARACTER. SET ERROR FLAG
	JRST CKNM10		;GO CHECK NEXT CHARACTER IN STRING

; HERE TO SEE IF THE NAME IS ALREADY IN THE DEVICE TABLES

CKNM20:	HRRZ T1,CKNBLK		;GET ADDRESS OF BLOCK CONTAINING ASCIZ STRING
	CALL DEVLUX		;CHECK DEVICE TABLES
	 JRST CKNM30		;OK, NAME NOT YET IN TABLES
	SETOM CKNERR		;NAME ALREADY IN DEVICE TABLES. SET ERROR FLAG.

; HERE TO RELEASE FREE BLOCK AND RETURN TO CALLER

CKNM30:	MOVEI T1,JSBFRE		;GET FREE HEADER
	MOVE T2,CKNBLK		;GET ADDRESS OF FREE BLOCK
	CALL RELFRE		;RELEASE THE FREE BLOCK
	SKIPE CKNERR		;ANY ERRORS FOUND ?
	RETBAD (MSTRX7)		;YES, RETURN ERROR CODE
	MOVE T1,CKNNAM		;NO, GET SIXBIT NAME
	RETSKP			;RETURN SUCCESS
;MAKHOM - ROUTINE TO CREATE THE HOME BLOCKS FOR ONE UNIT OF A STRUCTURE
;
;ACCEPTS IN P3/	ADDRESS OF USER ARGUMENT BLOCK IN MONITOR SPACE
;		CALL MAKHOM
;RETURNS: +1	 FAILURE, ERROR CODE IN T1
;		SUCCESS, HOME BLOCKS CREATED

IDLEN== .MSIFI-.MSIUI		;LENGTH OF ID INFO FIELDS IN HOME BLOCK

MAKHOM:	SAVEP
	JSVAR <MKHERR,MKHNAM,MKHNUM,MKHBLK,MKHMID,<MKHINF,IDLEN>>,R
	CALL LGTAD		;GET THE CURRENT TIME AND DATE
	MOVEM T1,MKHMID		;SAVE TIME AND DATE AS MEDIA ID
	SETZM MKHERR		;INITIALIZE ERROR REGISTER

; SET UP TO LOOP OVER ALL UNITS IN STRUCTURE

	MOVEI P5,.MSTUI(P3)	;COMPUTE ADDRESS OF INFO FOR FIRST UNIT
	HRRZ T1,.MSTNU(P3)	;GET NUMBER OF UNITS IN STRUCTURE
	MOVN T1,T1		;GET -<NUMBER OF UNITS IN STRUCTURE>
	MOVSI P4,(T1)		;FORM AOBJN POINTER

; COPY ASCIZ STRUCTURE ID FROM USER SPACE

	MOVE T1,.MSINM(P3)	;GET POINTER TO STRUCTURE NAME IN USER SPACE
	CALL CPYFUS		;COPY STRING FROM USER SPACE
	 RETBAD (MONX01)	;RETURN "INSUFFICIENT RESOURCES" ERROR CODE
	MOVEM T1,MKHBLK		;SAVE ADDRESS OF BLOCK HOLDING STRING
	CALL ASCSIX		;CONVERT NAME TO SIXBIT
	 SETOM MKHERR		;FAILED, NOTE THAT AN ERROR OCCURRED
	MOVEM T1,MKHNAM		;SAVE SIXBIT STRUCTURE ID

; RELEASE FREE BLOCK AND RETURN FAILURE IF AN ERROR OCCURRED

	MOVEI T1,JSBFRE		;GET FREE HEADER
	MOVE T2,MKHBLK		;GET ADDRESS OF BLOCK HOLDING ASCIZ STRING
	CALL RELFRE		;RELEASE FREE BLOCK
	SKIPE MKHERR		;ANY ERRORS DETECTED ?
	RETBAD (MSTX23)		;YES, RETURN "ERROR WRITING HOME BLOCKS"

; CONVERT ID FIELDS FROM ASCII TO PDP-11 "REVERSED-ASCII"

	HRRZ T1,.MSINU(P3)	;GET NUMBER OF UNITS IN STRUCTURE
	IMULI T1,.MSINO		;COMPUTE NUMBER OF PER-UNIT WORDS IN ARG BLOCK
	ADDI T1,.MSIUI-.MSINO(P3) ;FORM SOURCE ADDRESS OF 12 ASCII CHARACTERS
	MOVEI T2,MKHINF		;GET DESTINATION FOR PDP-11 ASCII
	CALL CNVINF		;GO CONVERT UNIT ID INTO PDP-11 ASCII
	HRRZ T1,.MSINU(P3)	;GET NUMBER OF UNITS IN STRUCTURE
	IMULI T1,.MSINO		;COMPUTE NUMBER OF PER-UNIT WORDS IN ARG BLOCK
	ADDI T1,.MSIOI-.MSINO(P3) ;FORM SOURCE ADDRESS OF 12 ASCII CHARACTERS
	MOVEI T2,.MSIOI-.MSIUI+MKHINF ;GET DESTINATION FOR PDP-11 ASCII
	CALL CNVINF		;GO CONVERT UNIT ID INTO PDP-11 ASCII
	; ..
	; ..

; GET # OF PAGES TO ALLOCATE FOR SWAPPING FROM USER ARGUMENT BLOCK

	HRRZ T3,.MSINU(P3)	;GET # OF UNITS IN STRUCTURE
	IMULI T3,.MSINO		;COMPUTE # OF PER-UNIT WORDS
	ADDI T3,.MSISW-.MSINO(P3) ;ADD OFFSET TO SWAPPING SPACE ARGUMENT
	MOVE P1,(T3)		;GET # OF PAGES TO ALLOCATE FOR SWAPPING

; SET UP TO CREATE THE HOME BLOCKS ON THIS UNIT (P1 IS ALREADY SET UP)

MKHOM1:	HRL T4,.MSINU(P3)	;GET NUMBER OF UNITS IN STRUCTURE
	HRR T4,P4		;GET UNIT # WITHIN STRUCTURE
	HRR T3,.MSIUN(P5)	;GET PHYSICAL UNIT NUMBER
	HRL T3,.MSICH(P5)	;GET PHYSICAL CHANNEL NUMBER
	MOVE T2,MKHNAM		;GET SIXBIT STRUCTURE ID
	MOVEI T1,MKHINF		;GET ADDRESS OF ID INFO
	MOVE P2,MKHMID		;GET MEDIA ID (PACK UNIQUE CODE)
	CALL CRTHOM		;CREATE THE HOME BLOCKS
	 RETBAD (MSTX23)	;FAILED, RETURN "ERROR WRITING HOME BLOCKS"

; GO BACK AND WRITE THE HOME BLOCKS FOR THE NEXT UNIT

	ADDI P5,.MSTNO		;POINT TO NEXT SET OF PER-UNIT ARGUMENTS
	AOBJN P4,MKHOM1		;LOOP OVER ALL UNITS IN THE STRUCTURE
	RETSKP			;RETURN SUCCESS
;CNVINF - ROUTINE TO CONVERT 12 ASCII CHARACTERS TO PDP-11 ASCII
;
;ACCEPTS IN T1/	ADR OF SOURCE (12 ASCII CHARACTERS)
;	    T2/	ADR OF DESTINATION FOR PDP-11 ASCII
;		CALL CNVINF
;RETURNS: +1	ALWAYS, PDP-11 ASCII PLACED AT DESTINATION

CNVINF:	STKVAR <CNVCHR>
	MOVSI T4,<-^D12/4>	;ID INFO FIELDS CONTAIN 12 CHARACTERS
	SUBI T1,1		;POINT TO <SOURCE-ADDRESS>-1
	HRLI T1,(POINT 7,0,35)	;FORM ILDB POINTER TO SOURCE ASCII CHARACTERS

; LOOP OVER EACH WORD IN THE DESTINATION AREA

CNVIN2:	HRLI T2,(POINT 8,0,9)	;FORM POINTER TO FIRST PDP-11 CHAR IN WORD
	ILDB T3,T1		;GET A CHARACTER FROM ASCII SOURCE STRING
	MOVEM T3,CNVCHR		;SAVE CHARACTER
	ILDB T3,T1		;GET NEXT CHARACTER FROM SOURCE STRING
	DPB T3,T2		;STORE FIRST CHARACTER INTO DESTINATION STRING
	MOVE T3,CNVCHR		;RESTORE FIRST SOURCE CHARACTER
	IDPB T3,T2		;STORE NEXT PDP-11 CHARACTER INTO DESTINATION
	HRLI T2,(POINT 8,0,27)	;FORM POINTER TO THIRD CHARACTER IN DEST WORD
	ILDB T3,T1		;GET NEXT CHARACTER FROM SOURCE STRING
	MOVEM T3,CNVCHR		;SAVE CHARACTER
	ILDB T3,T1		;GET NEXT CHARACTER FROM SOURCE STRING
	DPB T3,T2		;STORE THIRD CHARACTER IN DESTINATION WORD
	MOVE T3,CNVCHR		;RESTORE FIRST SOURCE CHARACTER
	IDPB T3,T2		;STORE FOURTH (LAST) CHARACTER IN DEST WORD
	ADDI T2,1		;POINT TO NEXT WORD IN DESTINATION
	AOBJN T4,CNVIN2		;LOOP OVER ALL WORDS IN DESTINATION
	RET			;RETURN
;STRINI - SET UP DIRECTORIES, BIT TABLE, AND FRONT-END FILE-SYSTEM FOR
;	  A STRUCTURE BEING INITIALIZED.
;ACCEPTS IN T1/	STRUCTURE NUMBER
;	    T2/	# OF PAGES TO ALLOCATE FOR THE FE FILE-SYSTEM
;	    T3/ # OF PAGES TO ALLOCATE FOR THE BOOTSTRAP.BIN FILE
;		CALL STRINI
;RETURNS: +1	 FAILURE, ERROR CODE IN T1
;	  +2	SUCCESS

STRINI:	SAVEP
	STKVAR <STINIS,STINIB,STINIF,STINIE,STINIT,SAVIDX>
	MOVEM T1,STINIS		;SAVE STRUCTURE NUMBER
	MOVEM T2,STINIF		;SAVE # OF PAGES FOR FE FILE-SYSTEM
	MOVEM T3,STINIT		;SAVE # OF PAGES FOR BOOTSTRAP.BIN
	MOVE T3,STRTAB(T1)	;GET ADDRESS OF SDB FOR THIS STRUCTURE
	MOVEM T3,STINIB		;SAVE SDB ADDRESS
	MOVE T1,STINIS		;YES, GET THE STRUCTURE NUMBER
	CALL CRTBTB		;GO CREATE THE BIT TABLE FOR THIS STRUCTURE
	 RETBAD (MSTX12)	;FAILED, RETURN ERROR
	MOVE T1,STINIB		;GET ADDRESS OF SDB FOR THIS STRUCTURE
	LOAD T1,STRRXB,(T1)	;GET DISK ADDRESS OF ROOT-DIRECTORY INDEX BLOCK
	MOVE T2,STINIS		;GET THE STRUCTURE NUMBER
	CALL NEWIB		;GO SET UP A NEW ROOT-DIRECTORY INDEX BLOCK
	 RETBAD (MSTRX8)	;FAILED, COULD NOT GET OFN FOR ROOT-DIRECTORY
	CALL RELOFN		;RELEASE THE OFN
	MOVE T3,STINIB		;GET ADDRESS OF SDB
	LOAD T1,STRBXB,(T3)	;GET THE BACKUP ROOT-DIR INDEX BLOCK ADDRESS
	MOVE T2,STINIS		;GET THE STRUCTURE NUMBER
	CALL NEWIB		;ASSIGN THE BACKUP ROOT-DIR INDEX BLOCK ADDRESS
	 JRST [	MOVX T1,MSTX13	;FAILED, GET "BAD BACKUP ROOT-DIR" ERROR CODE
		JRST STIER1 ]	;GO RELEASE ROOT-DIR OFN AND RETURN ERROR
	CALL RELOFN		;RELEASE THE OFN OF THE BACKUP ROOT-DIR
	MOVE T1,STINIS		;GET THE STRUCTURE NUMBER
	CALL SETRDO		;GO GET AN OFN FOR THE ROOT-DIRECTORY
	 RETBAD (MSTRX8)	;FAILED, COULD NOT GET AN OFN FOR ROOT-DIRECTORY
	MOVE T1,IDXORA		;GET ORIGIN
	MOVEM T1,SAVIDX		;OF IDXTAB AND SAVE IT
	NOSKED
	CALL ASGPAG		;GET PAGE
	JRST [	MOVX T1,MSTX11	;CAN'T INIT INDEX TABLE
		JRST STIER1]
	MOVEM T1,IDXORA		;SET NEW ORIGIN
	MOVEI T4,ROOTDN		;SUPERIOR DIR IS SELF
	MOVE T3,STINIB		;YES, GET ADDRESS OF SDB
	LOAD T3,STRRXB,(T3)	;GET ADDRESS OF ROOT-DIR INDEX BLOCK
	MOVEI T2,0		;NO FDB ADDRESS YET
	MOVEI T1,ROOTDN		;GET ROOT-DIRECTORY DIRECTORY NUMBER
	CALL SETIDX		;GO SET UP ENTRY FOR ROOT-DIR  IN INDEX TABLE
	 JRST [	MOVX T1,MSTX11	;COULD NOT SET UP INDEX TABLE
		JRST STIER2 ]	;RETURN ERROR TO USER
	MOVEI T1,ROOTDN		;GET ROOT-DIRECTORY NUMBER
	MOVE T2,STINIS		;GET STRUCTURE NUMBER
	CALL DIRINI		;GO INITIALIZE THE ROOT-DIRECTORY
	 JRST [	MOVX T1,MSTX10	;ROOT-DIRECTORY BAD
		JRST STIER2 ]	;GO RETURN ERROR CODE TO USER
	MOVE T1,STINIS		;GET THE STRUCTURE NUMBER
	CALL FILCRD		;GO SET UP THE STANDARD SYSTEM DIRECTORIES
	MOVE T1,STINIS		;GET THE STRUCTURE NUMBER
	CALL WRTBTB		;GO SET UP THE BIT TABLE
	 JRST [ MOVX T1,MSTX12	;ERROR, GET CODE
		JRST STIER2]	;RETURN ERROR CODE TO USER
	MOVE T1,STINIS		;GET STRUCTURE NUMBER
	MOVE T2,STINIF		;GET # OF PAGES FOR FE FILE-SYSTEM
	CALL FEFSYS		;IF A PUBLIC STRUCTURE, SET UP FRONT-END STUFF
	 JFCL			;FAILED, IGNORE FAILURE
	MOVE T1,STINIS		;GET STRUCTURE NUMBER
	MOVE T2,STINIT		;GERT # OF PAGES FOR BOOTSTRAP.BIN
	CALL BOTSYS		;SET UP BOOTSTRAP.BIN
	JFCL			;FAILED? IGNORE?
	MOVE T1,STINIB		;SDB ADDRESS
	LOAD T1,STRRDO,(T1)	;GET OFN OF <ROOT-DIRECTORY>
	HRLZS T1		;OFN,,0
	MOVEI T2,1000
	CALL UPDPGS		;UPDATE FILE PAGES
	MOVE T1,STINIB		;SDB ADDRS
	LOAD T1,STRRDO,(T1)	;OFN AGAIN
	CALL UPDOFN		;FIX INDEX BLOCK ALSO
	MOVE T1,IDXORA		;IDX ORIGIN
	MOVE T4,SAVIDX		;GET OLD IDX
	MOVEM T4,IDXORA		;AND RESTORE IT
	OKSKED
	CALL RELPAG		;FREE PAGE
	RETSKP			;RETURN SUCCESS


; HERE ON AN ERROR TO RELEASE OFN OF ROOT-DIR AND RETURN ERROR CODE

STIER2:	MOVEM T1,STINIE		;SAVE ERROR CODE
	MOVE T1,IDXORA		;IDX ORIGIN
	MOVE T4,SAVIDX		;GET OLD IDX
	MOVEM T4,IDXORA		;AND RESTORE IT
	OKSKED
	CALL RELPAG		;FREE PAGE
	SKIPA			;DON'T RESAVE ERROR CODE
STIER1:	MOVEM T1,STINIE		;SAVE ERROR CODE
	MOVE T1,STINIB		;GET ADDRESS OF SDB
	LOAD T1,STRRDO,(T1)	;GET OFN OF ROOT-DIRECTORY
	CALL RELOFN		;RELEASE THE OFN
	MOVE T1,STINIE		;RESTORE THE ERROR CODE
	RETBAD			;GIVE FAIL RETURN

; ROUTINE TO RELEASE IDX TABLE PAGE
;UNICHK - ROUTINE TO CHECK THAT EACH UNIT SPECIFIED AS PART OF THE STRUCTURE
;	  IS OF THE CORRECT TYPE.
;
;ACCEPTS IN P3/	ADDRESS OF USER'S ARGUMENT BLOCK IN MONITOR SPACE
;		CALL UNICHK
;RETURNS: +1	 FAILED, ONE OF THE UNITS SPECIFIED IS INVALID
;	  +2	SUCCESS, ALL OF THE CHANNEL, CONTROLLER, AND UNIT #'S ARE OK

UNICHK:	SAVEP
	STKVAR <UCKTYP>		;UNIT TYPE
	MOVEI P2,.MSTUI(P3)	;COMPUTE ADDRESS OF INFO FOR FIRST UNIT
	HRRZ T1,.MSTNU(P3)	;GET NUMBER OF UNITS IN STRUCTURE
	MOVN P1,T1		;GET -<NUMBER OF UNITS IN STRUCTURE>
	MOVSI P1,(P1)		;FORM AOBJN POINTER

; TOP OF LOOP OVER ALL UNIT SPECIFICATIONS

UNICK1:	MOVE T1,.MSTCH(P2)	;GET CHANNEL NNUMBER FROM USER
	MOVE T2,.MSTCT(P2)	;GET CONTROLLER NUMBER FROM USER
	MOVE T3,.MSTUN(P2)	;GET UNIT NUMBER FROM USER
	CALL STRCHK		;GO CHECK CHANNEL, CONTROLLER, AND UNIT #'S
	 RETBAD ()		;INVALID UNIT SPECIFIED, RETURN ERROR CODE
	TRNN P1,-1		;DOING FIRST UNIT IN THE STRUCTURE ?
	JRST UNICK2		;YES, DO NOT CHECK UNIT TYPE, JUST SAVE IT
	CAME T1,UCKTYP		;NO, IS UNIT TYPE CORRECT ?
	 RETBAD (MSTX17)	;NO, RETURN "MIXED UNITS IN STRUCTURE" ERROR
UNICK2:	MOVEM T1,UCKTYP		;SAVE UNIT TYPE
	HRRZ T1,.MSTCH(P2)	;GET CHANNEL NNUMBER FROM USER
	HRRZ T2,.MSTCT(P2)	;GET CONTROLLER NUMBER FROM USER
	HRRZ T3,.MSTUN(P2)	;GET UNIT NUMBER FROM USER
	CALL GETSTR		;GET STRUCTURE INFORMATION FOR UNIT
	 JRST [	MOVE T2,T1	;FAILED, COPY ERROR FLAGS
		TXNE T2,MS%OFL	;IS UNIT OFF-LINE ?
		RETBAD (MSTRX5)	;YES, RETURN "UNIT OFF LINE" ERROR
		RETBAD (MSTX15)] ;RETURN "UNIT BEING DIAGNOSED" ERROR
	TXNE T3,MS%WLK		;UNIT WRITE LOCKED ?
	RETBAD (MSTX34)		;YES, RETURN "WRITE LOCKED UNIT" ERROR
	CAME T1,[-1]		;IS UNIT ALREADY PART OF A STRUCTURE ?
	RETBAD (MSTX19)		;YES, RETURN "UNIT ALREADY IN STRUCTURE" ERROR
	ADDI P2,.MSTNO		;POINT TO NEXT BLOCK OF PER-UNIT INFORMATION
	AOBJN P1,UNICK1		;LOOP OVER ALL UNITS IN STRUCTURE

; HERE IF ALL UNIT SPECIFICATIONS CHECKED OUT OK - RETURN SUCCESS

	RETSKP			;RETURN SUCCESS, ALL UNITS OK
;HOMCHK - ROUTINE TO CHECK AND, IF NECESSARY, FIX THE HOME BLOCKS
;
;ACCEPTS IN Q1/	ADDRESS OF USER'S ARGUMENT BLOCK IN USER SPACE
;	    Q2/	FUNCTION CODE (.MSMNT OR .MSINI)
;	    P3/ ADDRESS OF USER'S ARGUMENT BLOCK IN MONITOR SPACE
;		CALL HOMCHK
;RETURNS: +1	 FAILURE, ERROR CODE IN T1
;	  +2	SUCCESS, T1/ STRUCTURE NUMBER

HOMCHK:	SAVEP
	STKVAR <HCKSTR,HCKSDB,HCKADR,HCKPAG,HCKUNI,HCKBLK,HCKERR>
	SETZM HCKSDB		;INITIALIZE ADDRESS OF SDB
	MOVEI P2,.MSTUI(P3)	;COMPUTE ADDRESS OF INFO FOR FIRST UNIT
	HRRZ T1,.MSTNU(P3)	;GET NUMBER OF UNITS IN STRUCTURE
	MOVN P1,T1		;GET -<NUMBER OF UNITS IN STRUCTURE>
	MOVSI P1,(P1)		;FORM AOBJN POINTER

; HERE TO READ AND CHECK THE HOME BLOCKS FOR THE CURRENT UNIT

HOMCK1:	MOVE T1,.MSTCH(P2)	;GET CHANEL NNUMBER FROM USER
	MOVE T2,.MSTCT(P2)	;GET CONTROLLER NUMBER FROM USER
	MOVE T3,.MSTUN(P2)	;GET UNIT NUMBER FROM USER
	HRLM T1,HCKUNI		;SAVE CHANNEL NUMBER
	HRRM T3,HCKUNI		;SAVE UNIT NUMBER
	CALL MSTRHB		;GO READ THE HOME BLOCKS FOR THIS UNIT
	 JRST HCKER2		;FAILED, GO RETURN ERROR CODE
	MOVEM T1,HCKADR		;SUCCESS, SAVE VIRTUAL ADDRESS OF HOME BLOCKS
	MOVEM T2,HCKPAG		;SAVE PHYSICAL PAGE NUMBER OF HOME BLOCKS
	;..
	;..

; CHECK THE HOME BLOCKS FOR THIS UNIT

	CALL MSTHBC		;GO CHECK THE HOME BLOCKS
	MOVE Q1,T1		;COPY FLAGS INDICATING GOOD HOME BLOCKS
	MOVE T1,.MSTNM(P3)	;GET STRUCTURE NAME FROM USER
	CALL CPYFUS		;COPY STRING FROM USER SPACE
	 JRST [	MOVX T1,MSTRX4	;FAILED, GET "INSUFFICIENT RESOURCES" ERROR
		JRST HCKER1 ]	;GO RELEASE HOME BLOCK PAGE AND RETURN ERROR
	MOVEM T1,HCKBLK		;SAVE ADDRESS OF BLOCK HOLDING STRING
	CALL ASCSIX		;CONVERT ASCIZ STRING TO SIXBIT
	 JRST [	MOVE T2,HCKBLK	;FAILED, GET ADDRESS OF BLOCK
		MOVEI T1,JSBFRE	;GET FREE HEADER
		CALL RELFRE	;RELEASE FREE BLOCK
		MOVX T1,MSTRX7	;GET "INVALID STRUCTURE NAME" ERROR
		JRST HCKER1 ]	;GO RETURN ERROR TO USER
	MOVE T2,HCKADR		;GET VIRTUAL ADDRESS OF FIRST HOME BLOCK
	HRLZ T3,.MSTNU(P3)	;GET NUMBER OF UNITS IN STRUCTURE
	HRR T3,P1		;GET LOGICAL UNIT NUMBER OF THIS UNIT IN STR
	CAMN T3,HOMLUN(T2)	;CORRECT LOGICAL UNIT ?
	CAME T1,HOMSNM(T2)	;STRUCTURE NAME OK FOR HOME BLOCK 1 ?
	TXZ Q1,HB%1OK		;NO, MARK THAT FIRST HOME BLOCK IS BAD
	SKIPN HOMRXB(T2)	;IS THERE A DISK ADDRESS FOR THE ROOT-DIR XB ?
	TXZ Q1,HB%1OK		;NO, FIRST HOME BLOCK IS BAD
	ADDI T2,HBLEN		;GET ADDRESS OF SECOND HOME BLOCK
	CAMN T3,HOMLUN(T2)	;CORRECT LOGICAL UNIT NUMBER ?
	CAME T1,HOMSNM(T2)	;STRUCTURE NAME OF SECOND HOME BLOCK OK ?
	TXZ Q1,HB%2OK		;NO, MARK SECOND HOME BLOCK IS BAD
	SKIPN HOMRXB(T2)	;IS THERE A DISK ADDRESS FOR THE ROOT-DIR XB ?
	TXZ Q1,HB%2OK		;NO, SECOND HOME BLOCK IS BAD
	MOVE T2,HCKBLK		;GET ADDRESS OF BLOCK HOLDING STRING
	MOVEI T1,JSBFRE		;GET FREE HEADER
	CALL RELFRE		;RELEASE BLOCK HOLDING NAME STRING
	JUMPE Q1,[MOVX T1,MSTRX6 ;IF BOTH HOME BLKS BAD, GET ERROR CODE
		JRST HCKER1 ]	;GO RELEASE HOME BLOCK PAGE AND RETURN ERROR

; CHECK FOR ONE BAD HOME BLOCK, FIX UP IF NEEDED

	TXNE Q1,HB%1OK		;FIRST HOME BLOCK OK ?
	TXNN Q1,HB%2OK		;  AND ALSO SECOND HOME BLOCK ?
	SKIPA			;NO, AT LEAST ONE IS BAD
	JRST HOMCK4		;YES, GO ON TO NEXT UNIT
	MOVE T1,.MSTFL(P3)	;GET FLAGS FROM USER
	TXNE T1,MS%NFH		;USER WANT A BAD HOME BLOCK REPAIRED ?
	JRST [ MOVX T1,MSTRX6	;NO, GET "BAD HOME BLOCKS" ERROR CODE
		JRST HCKER1 ]	;RELEASE HOME BLOCK PAGE AND SDB, RETURN ERROR
	HRRZ T1,HCKADR		;GET VIRTUAL ADDRESS OF FIRST HOME BLOCK
	HRRZ T2,HCKPAG		;GET PHYSICAL PAGE NUMBER OF HOME BLOCK PAGE
	LSH T2,PGSFT		;FORM PHYSICAL ADDRESS OF FIRST HOME BLOCK
	MOVE T3,HCKUNI		;GET CHANNEL,,UNIT NUMBERS
	MOVE P5,HCKSTR		;GET STRUCTURE NUMBER
	MOVE P4,HCKSDB		;GET ADDRESS OF SDB FOR THIS STRUCTURE
	ADDI P4,SDBUDB(P1)	;FORM SDBUDB POINTER
	TXNN Q1,HB%1OK		;IS HOME BLOCK 1 THE GOOD ONE ?
	JRST HOMCK3		;NO, GO COPY SECONDARY TO PRIMARY
	CALL CPYH1		;YES, COPY PRIMARY HOME BLOCK TO SECONDARY
	 JRST HCKER1		;FAILED, RETURN ERROR TO USER
	JRST HOMCK4		;SUCCESS, HOME BLOCK FIXED. GO ON TO NEXT UNIT
HOMCK3:	ADDI T1,HBLEN		;GET VIRTUAL ADDRESS OF SECOND HOME BLOCK
	ADDI T2,HBLEN		;GET PHYSICAL ADDRESS OF SECOND HOME BLOCK
	CALL CPYH2		;COPY SECONDARY HOME BLOCK OVER PRIMARY
	 JRST HCKER1		;FAILED, RETURN ERROR TO USER
	; ..
	; ..

; SET UP AND CHECK STRTAB AND SDB FOR THIS STRUCTURE

HOMCK4:	TRNE P1,-1		;IS THIS FIRST UNIT IN STRUCTURE ?
	JRST HOMCK2		;NO, GO ADD THIS UNIT TO STRUCTURE
	MOVE T1,HCKADR		;YES, GET ADDRESS OF HOME BLOCK PAGE
	MOVE T2,.MSTCH(P2)	;GET CHANEL NUMBER FROM USER
	MOVE T3,.MSTUN(P2)	;GET UNIT NUMBER FROM USER
	CALL MAKSDB		;GO CREATE AN SDB FOR THIS STRUCTURE
	 JRST HCKER1		;FAILED, NO STRTAB SLOTS LEFT
	MOVEM T1,HCKSDB		;SAVE ADDRESS OF SDB
	MOVEM T2,HCKSTR		;SAVE STRUCTURE NUMBER
HOMCK2:	MOVE T1,.MSTCH(P2)	;GET CHANEL NUMBER FROM USER
	MOVE T2,.MSTUN(P2)	;GET UNIT NUMBER FROM USER
	MOVE T3,HCKADR		;GET ADDRESS OF HOME BLOCK PAGE
	MOVE T4,HCKSDB		;GET ADDRESS OF SDB
	CALL BLDSDB		;GO ADD THIS UNIT TO THE STRUCTURE
	 JRST HCKER1		;FAILED,  RELEASE PAGE AND RETURN ERROR

; SET UP UDBSTR AND SDBUDB WORDS FOR UNIT AND STRUCTURE

	MOVS T1,HCKUNI		;GET UNIT,,CHANNEL NUMBERS
	HRR T2,HCKSTR		;GET STRUCTURE NUMBER
	HRL T2,P1		;GET UNIT IN STRUCTURE,,STRUCTURE NUMBERS
	MOVE T3,HCKSDB		;GET SDB ADDRESS
	CALL SETSTR		;GO SETUP UDBSTR AND SDBUDB WORDS
	;..
	;..

; UNLOCK AND RELEASE THE PAGE USED FOR READING THE HOME BLOCKS

	MOVE T1,HCKPAG		;GET ADDRESS OF HOME BLOCK PAGE
	CALL MULKCR		;UNLOCK THE PAGE
	MOVE T1,HCKADR		;GET ADDRESS OF PAGE AGAIN
	CALL RELPAG		;RELEASE THE PAGE

; LOOP BACK TO PROCESS ALL UNITS IN THE STRUCTURE

	ADDI P2,.MSTNO		;STEP TO NEXT CHANNEL, CONTROLLER, AND UNIT
	AOBJN P1,HOMCK1		;LOOP OVER ALL UNITS IN STRUCTURE
	MOVE T1,HCKSTR		;GET STRUCTURE NUMBER
	RETSKP			;RETURN SUCCESS
; HERE ON AN ERROR TO RELEASE HOME BLOCK PAGE AND RETURN ERROR

HCKER1:	MOVEM T1,HCKERR		;SAVE ERROR CODE
	MOVE T1,HCKPAG		;GET PHYSICAL PAGE NUMBER NOW LOCKED
	CALL MULKCR		;GO UNLOCK THE PAGE
	MOVE T1,HCKADR		;GET ADDRESS OF HOME BLOCK PAGE
	CALL RELPAG		;RELEASE THE PAGE
	MOVE T1,HCKERR		;RESTORE ERROR CODE AGAIN
				;FALL INTO HCKER2

HCKER2:	MOVEM T1,HCKERR		;SAVE ERROR CODE
	SKIPE T1,HCKSDB		;IS THERE AN SDB YET ?
	CALL CLRSTR		;YES, GO REMOVE PHYSIO POINTERS IN UDB'S
	MOVE T1,HCKSTR		;GET STRUCTURE NUMBER
	SKIPE HCKSDB		;WAS STRTAB SET UP YET ?
	CALL CLRSTB		;CLEAR THE STRTAB ENTRY
	MOVE T1,HCKERR		;GET ERROR CODE BACK
	RETBAD ()		;RETURN ERROR CODE TO CALLER
;MAKSDB - ROUTINE TO CREATE A NEW SDB FOR A STRUCTURE
;
;ACCEPTS IN T1/	ADDRESS OF PAGE CONTAINING HOME BLOCKS FOR THIS UNIT
;	    T2/	CHANNEL NUMBER
;	    T3/ UNIT NUMBER
;		CALL MAKSDB
;RETURNS: +1	 FAILURE, ERROR CODE IN T1 (I.E., NO SDB'S AVAILABLE)
;	  +2	SUCCESS, WITH:
;		T1/ ADDRESS OF SDB
;		T2/ STRUCTURE NUMBER

MAKSDB:	STKVAR <MKSHOM,MKSSTR,MKSCHN,MKSUNI>
	MOVEM T1,MKSHOM		;SAVE HOME BLOCK PAGE ADDRESS
	MOVEM T2,MKSCHN		;SAVE CHANNEL NUMBER
	MOVEM T3,MKSUNI		;SAVE UNIT NUMBER
	MOVSI T4,-STRN		;SET UP TO LOOP THROUGH STRTAB
	NOINT			;DO NOT PERMIT INTERRUPTS
	NOSKED			;INSURE THAT STRTAB IS NOT CHANGED WHILE WE LOOK

; TOP OF LOOP THROUGH STRTAB TO LOOK FOR A FREE SDB

MKSDB2:	SKIPE STRTAB(T4)	;FOUND A FREE SDB ?
	JRST MKSDB4		;NO, GO CHECK NEXT SDB
	MOVEM T4,MKSSTR		;YES, SAVE STRUCTURE NUMBER
	MOVE T3,MKSHOM		;GET ADDRESS OF HOME BLOCK PAGE
	MOVE T2,MKSUNI		;GET UNIT NUMBER
	MOVE T1,MKSCHN		;GET CHANNEL NUMBER
	CALL BLDNEW		;GO CREATE THE SDB FOR THE NEW STRUCTURE
	 JRST MKSDB6		;FAILED, GO OKSKED AND RETURN ERROR
	HRRZ T2,MKSSTR		;GET STR NUMBER AGAIN (SDB ADR ALREADY IN T1)
	OKSKED			;PERMIT SCHEDULING AGAIN
	OKINT			;PERMIT INTERRUPTS AGAIN
	RETSKP			;RETURN
MKSDB4:	AOBJN T4,MKSDB2		;GO CHECK NEXT SDB

; NO FREE SDB'S WERE FOUND

MKSDB6:	OKSKED			;PERMIT SCHEDULING AGAIN
	OKINT			;PERMIT INTERRUPTS AGAIN
	RETBAD (MONX01)		;RETURN "INSUFICIENT RESOURCES"
; .MSDIS - DISMOUNT A FILE STRUCTURE

; LOCAL VARIABLE USAGE --
;
; MSTDMS - STRUCTURE NUMBER OF STRUCTURE BEING DISMOUNTED
; MSTDMB - ADDRESS OF SDB FOR STRUCTURE BEING DISMOUNTED
; MSTDMN - ASCIZ STRUCTURE NAME STRING FOR USE IN MESSAGES
; MSTDME - TEMPORARILY HOLDS ERROR CODE

MSTDIS:	STKVAR <MSTDMS,MSTDMB,MSTDME,<MSTDMN,2>>

; VERIFY THAT THE USER HAS THE REQUIRED CAPABILITIES TO DISMOUNT THE STRUCTURE

	MOVE T1,CAPENB		;GET CURRENTLY ENABLED CAPABILITIES
	TXNN T1,SC%WHL!SC%OPR	;WHEEL OR OPERATOR ?
	RETBAD (MSTRX2)		;NO, RETURN ERROR CODE TO USER

; CHECK THE SIZE OF THE ARGUMENT BLOCK

	XCTU [HLRZ T1,1]	;GET SIZE OF BLOCK FROM USER
	CAIGE T1,1		;AT LEAST ONE WORD SPECIFIED ?
	RETBAD (MSTRX3)		;NO, RETURN "ARG BLOCK TOO SMALL" ERROR CODE

; VERIFY THAT THE SPECIFIED STRUCTURE IS MOUNTED

	UMOVE T1,2		;GET ADDRESS OF ARGUMENT BLOCK FROM USER
	UMOVE T1,.MSDNM(T1)	;GET NAME OF STRUCTURE TO DISMOUNT
	CALL FNDSTR		;IS STRUCTURE NOW MOUNTED ?
	 RETBAD (MSTX21)	;NO, RETURN "STRUCTURE NOT MOUNTED" ERROR CODE
	MOVEM T1,MSTDMS		;YES, SAVE STRUCTURE NUMBER
	CAIN T1,PSNUM		;TRYING TO DISMOUNT THE PUBLIC STRUCTURE ?
	JRST [	MOVX T1,MSTX24	;YES, GET "ILLEGAL TO DISMOUNT PS:" ERROR
		JRST MSDER1 ]	;GO UNLOCK THE STRUCTURE AND RETURN ERROR
	MOVE T2,STRTAB(T1)	;GET ADDRESS OF SDB FOR THIS STRUCTURE
	MOVEM T2,MSTDMB		;SAVE ADDRESS OF SDB

; SAVE THE STRUCTURE NAME FOR LATER USE IN ADVISORY MESSAGE

	HRROI T1,MSTDMN		;GET POINTER TO WHERE NAME WILL GO
	MOVE T2,MSTDMS		;GET STRUCTURE NUMBER
	MOVX T3,.NULIO		;NO FILENAME TO APPEND
	CALL STRST		;GET STRUCTURE NAME
	 JRST [	MOVX T1,MSTX21	;FAILED, GET "STRUCTURE NOT MOUNTED" ERROR
		JRST MSDER1 ]	;GO UNLOCK STRUCTURE AND RETURN
	MOVE T1,MSTDMS		;GET STRUCTURE NUMBER
	CALL STRCNV		;GET UNIQUE CODE FOR THIS STRUCTURE
	 JFCL			;CANNOT FAIL WHILE STRUCTURE IS LOCKED
	MOVEI T2,MSTDMN		;GET ADDRESS OF STRUCTURE NAME
	CALL FIXJOB		;GO FIX JSB'S OF ALL JOBS ON SYSTEM
	; ..
	; ..

; THE DATABASE PERTINENT TO THE STRUCTURE TO BE DISMOUNTED MAY CURRENTLY
; BE IN USE, E.G. BY ANOTHER JSYS.  IT IS NECESSARY TO WAIT UNTIL THE
; STRUCTURE IS AVAILABLE (THE LOCK IS FREE), AND THEN TO PREVENT ANY
; ADDITIONAL USE OF THE STRUCTURE.  THIS IS DONE NOSKED TO PREVENT RACES.
; NOTE: SINCE THIS JSYS HAS LOCKED THE STRUCTURE, THE LOCK WILL BE 'FREE'
;	WHEN THE LOCK COUNT IS 1, NOT 0.

MSTD10:	CALL LCKDVL		;LOCK THE DEVICE TABLE LOCK
	NOSKED			;DO NOT PERMIT DATABASE TO CHANGE
				; DURING THIS TEST !
	MOVE T1,MSTDMB		;GET ADDRESS OF SDB FOR THIS STRUCTURE
	LOAD T2,STRLK,(T1)	;GET THE LOCK COUNT
	CAIN T2,1		;IS THE LOCK FREE ?
	JRST MSTD20		;YES, GO PREVENT FURTHER ACCESS TO THE STR
	UNLOCK DEVLCK		;UNLOCK THE DEVICE TABLE LOCK
	HRLZ T1,T1		;STRUCTURE LOCKED, SET UP FOR SCHEDULER TEST
	HRRI T1,STRTST		;GO OKSKED AND WAIT UNTIL THE LOCK BECOMES FREE,
	RDISMS			; THEN GO NOSKED AND CHECK LOCK ONCE MORE TO
	JRST MSTD10		; PREVENT ANY RACES.

; SCHEDULER TEST TO SEE IF THE STRUCTURE LOCK IS FREE
; 1/ ADDRESS OF SDB FOR THIS STRUCTURE

	RESCD
STRTST:	LOAD T1,STRLK,(T1)	;GET THE LOCK COUNT
	CAIE T1,1		;IS THE LOCK FREE ?
	JRST 0(4)		;LOCK STILL INCREMENTED, FAIL
	JRST 1(4)		;LOCK FREE, SUCCEED
	SWAPCD

; HERE WHEN THE LOCK IS FREE - CLEAR THE UNIQUE CODE TO PREVENT FURTHER ACCESS

MSTD20:	MOVE T2,HCKSDB		;GET ADDRESS OF SDB FOR THIS STRUCTURE
	SETZRO STRUC,(T2)	;CLEAR THE UNIQUE CODE FOR THIS STRUCTURE
	SETONE STDIS,(T2)	;MARK THAT STRUCTURE IS BEING DISMOUNTED
	MOVE T1,MSTDMS		;GET STRUCTURE NUMBER
	CALL DEVSTR		;FIX DEVICE TABLES AS THEY WERE PRIOR TO MOUNT
	OKSKED			;PERMIT SCHEDULING AGAIN
	UNLOCK DEVLCK		;UNLOCK THE DEVICE TABLE LOCK
	; ..
	; ..

; UNMAP CURRENTLY MAPPED DIRECTORY AND RELEASE STRUCTURE-RELATED OFN'S

	CALL UNMAPD		;UNMAP CURRENTLY MAPPED DIRECTORY
	MOVE T1,MSTDMB		;GET ADDRESS OF SDB FOR THIS STRUCTURE
	CALL MSTUPO		;UPDATE ALL OF THE OFNS
	MOVE T1,MSTDMS		;GET STRUCTURE NUMBER
	CALL MRKOFN		;GO MARK OFN'S ON THIS STRUCTURE
	MOVE T1,MSTDMB		;GET SDB ADDRESS FOR THIS STRUCTURE
	CALL MSTRLO		;RELEASE ALL OF THE OFN'S

; RETURN THE PHYSIO DATABASE TO ITS ORIGINAL STATE, BREAK PATH TO THIS SDB

MSTD50:	MOVE T1,MSTDMB		;GET ADDRESS OF SDB
	CALL CLRSTR		;FIX UP POINTERS IN UDB'S
	MOVE T1,MSTDMS		;GET STRUCTURE NUMBER
	CALL CLRSTB		;CLEAR THE STRTAB ENTRY

; DATABASE IS NOW CONSISTENT AGAIN - RETURN TO USER

	UNLOCK STRLOK		;UNLOCK THE DISMOUNTING LOCK
	OKINT			;PERMIT INTERRUPTS AGAIN
	RETSKP			;RETURN TO USER


; HERE ON ERRORS FOR WHICH THE STRUCTURE IS LOCKED

MSDER1:	MOVEM T1,MSTDME		;SAVE ERROR CODE
	MOVE T1,MSTDMS		;GET STRUCTURE NUMBER
	CALL ULKSTR		;UNLOCK THE STRUCTURE
	MOVE T1,MSTDME		;GET ERROR CODE BACK
	RETBAD ()		;FAIL

;LOCAL ROUTINE TO UPDATE OR RELEASE ALL OF THE OFN'S POINTED TO
;BY AN SDB.
;	T1/ ADDRESS OF SDB
;RETURNS +1 ALWAYS

MSTUPO:	XMOVEI T2,[HRLZS T1	;MAKE OFN.PN
		MOVEI T2,PGSIZ	;DO ALL PAGES
		CALLRET UPDPGS] ;AND GO DO THE UPDTAE
	SKIPA
MSTRLO:	XMOVEI T2,RELOFN	;ENTRY TO RELEASE OFN'S
	ASUBR <MSTDB1,MSTRTN>	;SAVE SDB ADDRESS AND ROUTINE
	LOAD T1,STRIDX,(T1)	;GET OFN FOR INDEX TABLE
	CALL @MSTRTN		;DO THE ROUTINE
	MOVE T1,MSTDB1		;GET ADDRESSS OF SDB
	LOAD T1,STRBTB,(T1)	;GET OFN OF BIT TABLE FILE
	CALL @MSTRTN		;DO THE ROUTINE
	MOVE T1,MSTDB1		;GET ADDRESS OF SDB
	LOAD T1,STRRDO,(T1)	;GET OFN OF ROOT-DIRECTORY FILE
	CALLRET @MSTRTN		;DO THE ROUTINE AND RETURN
;FIXJOB - ROUTINE TO PURGE STR INFO FROM ALL JSB'S, AND TO
;	   ISSUE A MESSAGE TO ALL USERS WHO HAVE:
;	1.	ACCESS'ED THIS STRUCTURE
;	2.	MOUNTED THIS STRUCTURE
;	3.	CONNECTED TO A DIRECTORY ON THIS STRUCTURE
;
;ACCEPTS IN T1/	STRUCTURE UNIQUE CODE
;	    T2/	ADDRESS OF ASCIZ STRUCTURE NAME
;		CALL FIXJOB
;RETURNS: +1 ALWAYS, STR INFO PURGED AND REQUIRED MESSAGES ISSUED

FIXJOB:	STKVAR <FXJOBC,FXJOBN>
	SAVEP
	MOVEM T1,FXJOBC		;SAVE STRUCTURE UNIQUE CODE
	MOVEM T2,FXJOBN		;SAVE ADDRESS OF STRUCTURE NAME STRING
	MOVSI P1,-NJOBS		;SET UP TO LOOP OVER ALL JOBS IN SYSTEM

; TOP OF LOOP OVER ALL JOBS - MAP THE NEXT JOB'S JSB IF THE JOB EXISTS

FXJB10:	SKIPGE JOBRT(P1)	;DOES THIS JOB EXIST ?
	JRST FXJB60		;NO, GO CHECK NEXT JOB
	HRRZ T1,P1		;YES, GET JOB NUMBER
	CALL SETJSB		;MAP THE OBJECT JOB'S JSB
	MOVEM T1,P2		;SAVE OFFSET TO JOB'S JSB
	SETZM P3		;INITIALIZE "MESSAGE-NEEDED" FLAG
	LOCK JSSTLK(P2)		;LOCK THE STRUCTURE INFO BLOCKS IN JSB
	MOVE T1,FXJOBC		;GET STRUCTURE NUMBER
	MOVE T2,P2		;GET OFFSET TO JSB FOR OBJECT JOB
	CALL FNDSTM		;GO GET OFFSET TO BLOCK FOR THIS STRUCTURE
	 JRST FXJB40		;NOT USING THAT STR, GO CHECK CONNECTED DIR

; HERE TO SEE IF A MESSAGE IS NEEDED DUE TO A MOUNT OR ACCESS COMMAND

	SETONE JSSDM,(T2)	;MARK THAT STRUCTURE IS DISMOUNTED
	JE JSADN,(T2),FXJB20	;WAS ANY DIRECTORY ON THIS STR ACCESSED ?
	SETOM P3		;YES, MARK THAT A MESSAGE IS NEEDED
	LOAD T1,JSADN,(T2)	;GET DIRECTORY NUMBER THAT WAS ACCESSED
	LOAD T2,JSSTN,(T2)	;GET STRUCTURE UNIQUE CODE
	HRL T1,T2		;FORM DIRECTORY DESIGNATOR
	CALL SETDIR		;MAP THE ACCESSED DIRECTORY
	 JRST FXJB40		;FAILED, GO UNMAP JSB AND GO ON TO NEXT JOB
	MOVE T1,P2		;GET OFFSET TO MAPPED JSB
	CALL UNACC		;GO "UN-ACCESS" THE DIRECTORY
	 JFCL			;SHOULD NOT FAIL
	CALL USTDIR		;UNLOCK THE DIRECTORY
FXJB20:	JE JSMCI,(T2),FXJB30	;WAS THIS STRUCTURE MOUNTED ?
	SETOM P3		;YES, MARK THAT A MESSAGE IS NEEDED
	SETZRO <JSMCI,JSXCL>,(T2) ;CLEAR STATUS FLAGS
	;..

; HERE TO SEE IF THE SLOT FOR THIS STRUCTURE IN THIS JSB MAY BE FREED

FXJB30:	MOVE T1,FXJOBC		;GET UNIQUE CODE
	MOVE T2,P2		;GET OFFSET TO MAPPED JSB
	CALL FRJSSO		;GO FREE STR BLOCK IN JSB IF NOW FREE
FXJB40:	UNLOCK JSSTLK(P2)	;UNLOCK STRUCTURE INFO BLOCK LOCK IN JSB

; SEE IF MESSAGE NEEDED BECAUSE JOB CONNECTED TO STRUCTURE

	MOVE T1,P2		;GET OFFSET TO JSB OF OBJECT JOB
	CALL GTOJCD		;GET CONNECTED STR UNIQUE CODE FOR THIS JOB
	HLRZ T1,T1		;KEEP JUST THE STRUCTURE UNIQUE CODE
	CAMN T1,FXJOBC		;WAS USER CONNECTED TO A DIRECTORY ON THIS STR ?
	SETOM P3		;YES, MARK THAT A MESSAGE IS NEEDED
FXJB50:	CALL CLRJSB		;UNMAP THE JSB FOR THE OBJECT JOB

; ISSUE A MESSAGE IF NECESSARY

	SKIPN P3		;IS A MESSAGE REQUIRED ?
	JRST FXJB60		;NO, GO CHECK NEXT JOB
	HLRE T1,JOBPT(P1)	;YES, GET CONTROLLING LINE #
	JUMPL T1,FXJB60		;DETACHED, SKIP MESSAGE
	TXO T1,.TTDES		;FORM DEVICE DESIGNATOR
	HRROI T2,[ASCIZ/[Structure /]
	SETZM T3		;STOP ON A NULL
	SOUT			;OUTPUT FIRST PART OF MESSAGE
	HRRO T2,FXJOBN		;GET POINTER TO ASCIZ STRUCTURE NAME
	SOUT			;OUTPUT STRUCTURE NAME
	HRROI T2,[ASCIZ/ has been dismounted]
/]				;GET REMAINDER OF MESSAGE
	SOUT			;OUTPUT FINAL PART OF MESSAGE

FXJB60:	AOBJN P1,FXJB10		;LOOP OVER ALL JOBS
	RET			;RETURN
;DEVSTR - ROUTINE TO INITIALIZE DEVICE TABLES FOR A FILE STRUCTURE
;
; ACCEPTS IN T1/ STRUCTURE #
;		CALL DEVSTR
; RETURNS: +1 ALWAYS
; NOTE: DEVLCK IS ASSUMED TO BE LOCKED BY CALLER.

DEVSTR:	STKVAR <DVSSTR>
	MOVEM T1,DVSSTR		;SAVE STRUCTURE NUMBER
	MOVSI T4,'STR'		;INITIALIZE FIRST PART OF DEVICE NAME
	IDIVI T1,100		;ISOLATE HIGH ORDER DIGIT OF STRUCTURE NUMBER
	ADDI T1,'0'		;CONVERT DIGIT TO SIXBIT
	LSH T1,^D12		;POSITION DIGIT IN HIGH ORDER POSITION
	IOR T4,T1		;ADD HIGH ORDER DIGIT TO DEVICE NAME
	MOVE T1,T2		;GET REMAINDER (SECOND, THIRD DIGITS)
	IDIVI T1,10		;ISOLATE SECOND AND THIRD DIGITS
	ADDI T1,'0'		;CONVERT SECOND  DIGIT TO SIXBIT
	LSH T1,6		;MOVE DIGIT TO MIDDLE POSITION
	IOR T4,T1		;ADD SECOND DIGIT TO NAME
	ADDI T2,'0'		;CONVERT LOW ORDER DIGIT TO SIXBIT
	IOR T4,T2		;ADD THIRD DIGIT TO NAME
	MOVE T1,DVSSTR		;GET STRUCTURE NUMBER AGAIN
	MOVEM T4,DEVNAM+DVXST0(T1) ;SAVE INITIAL STRUCTURE NAME
	MOVX T2,D1%NIU		;GET "STRUCTURE NOT IN USE" FLAG
	IORM T2,DEVCH1+DVXST0(T1) ;MARK THAT STRUCTURE IS NOT IN USE
	RET			;RETURN
; .MSRUS/.MSRNU - READ STATUS OF A UNIT

; ARGUMENT BLOCK DEFINITIONS

MSKSTR (MSTYP,.MSRST,MS%TYP)	;UNIT TYPE IN STATUS WORD

MSTRUS:	STKVAR <MSTRSA,MSTRSP,MSTRSS,<MSTRSB,.MSRLN>,<MSTRSN,2>>

; LOCAL VARIABLES --
;
; MSTRSA - VIRTUAL ADDRESS OF PAGE USED FOR READING HOME BLOCKS
; MSTRSP - PHYSICAL PAGE NUMBER OF PAGE USED FOR READING HOME BLOCKS
; MSTRSS - STRUCTURE NUMBER
; MSTRSB - ARGUMENT BLOCK TO BE RETURNED TO THE USER
; MSTRSN - ASCIZ STRUCTURE NAME


; ACCUMULATOR USAGE --
;
; P1/ ADDRESS OF ARGUMENT BLOCK IN USER SPACE
; P2/ ADDRESS OF ARGUMENT BLOCK IN MONITOR SPACE
; P3/ STATUS TO BE RETURNED

; VERIFY THAT THE USER HAS THE REQUIRED CAPABILITIES ENABLED

	MOVE T1,CAPENB		;GET ENABLED CAPABILITIES
	TXNN T1,SC%WHL!SC%OPR!SC%MNT	;IS USER CURRENTLY A WHEEL, OR OPERATOR OR MAINT?
	RETBAD (CAPX2)		;NO, RETURN ERROR CODE

; CHECK SIZE OF ARGUMENT BLOCK

	XCTU [ HLRZ T1,1 ]	;GET SIZE OF BLOCK FROM USER
	SKIPG T1		;AT LEAST ONE ITEM REQUESTED ?
	RETBAD (MSTRX3)		;NO, RETURN "ARG BLOCK TOO SMALL" ERROR

; INITIALIZE THE ARGUMENT BLOCK TO BE RETURNED

	MOVEI T2,MSTRSB		;GET ADDRESS OF ARGUMENT BLOCK
	MOVEI T1,1(T2)		;GET DESTINATION ADDRESS
	HRLI T1,(T2)		;GET SOURCE ADDRESS
	SETZM MSTRSB		;CLEAR FIRST WORD OF BLOCK
	BLT T1,.MSRLN-1(T2)	;INITIALIZE ARGUMENT BLOCK

; SET UP CHANNEL, CONTROLLER, AND UNIT NUMBERS IN ARG BLOCK TO BE RETURNED

	UMOVE P1,2		;GET ADDRESS OF ARGUMENT BLOCK IN USER SPACE
	MOVEI P2,MSTRSB		;GET ADDRESS OF ARGUMENT BLOCK IN MONITOR SPACE
	UMOVE T1,.MSRCH(P1)	;GET CHANNEL NUMBER FROM USER
	MOVEM T1,.MSRCH(P2)	;STORE INITIAL CHANNEL NUMBER
	UMOVE T1,.MSRCT(P1)	;GET CONTROLLER NUMBER FROM USER
	MOVEM T1,.MSRCT(P2)	;STORE CONTROLLER NUMBER
	UMOVE T1,.MSRUN(P1)	;GET UNIT NUMBER FROM USER
	MOVEM T1,.MSRUN(P2)	;STORE INITIAL UNIT NUMBER
	;..
	;..

; DETERMINE IF IT IS NECESSARY TO STEP TO THE NEXT UNIT

	XCTU [HRRZ T1,1]	;GET FUNCTION CODE FROM USER
	CAIE T1,.MSRNU		;IS FUNCTION READ STATUS OF NEXT UNIT ?
	JRST MSTRS2		;NO, GO READ STATUS OF THIS UNIT

; TRY STEPPING JUST THE UNIT NUMBER ON THIS CHANNEL

	MOVE T1,.MSRCH(P2)	;GET CHANNEL NUMBER
	CAMN T1,[-1]		;FIRST CHANNEL SPECIFIED ?
	JRST MSTRS1		;YES, STEP TO FIRST UNIT ON FIRST CHANNEL
	MOVE T2,.MSRUN(P2)	;GET UNIT NUMBER
	CALL STPUNI		;STEP TO THE NEXT UNIT
	 JRST MSTRS1		;NO MORE UNITS ON THIS CHANNEL
	MOVEM T2,.MSRUN(P2)	;GOT NEXT UNIT NUMBER, SAVE IN ARG BLOCK
	JRST MSTRS2		;GO READ STATUS

; HERE TO STEP TO THE FIRST UNIT ON THE NEXT CHANNEL

MSTRS1:	MOVE T1,.MSRCH(P2)	;GET CHANNEL NUMBER
	CALL STPCHN		;STEP TO THE NEXT CHANNEL
	 RETBAD (MSTX18)		;NO MORE UNITS IN SYSTEM
	MOVEM T1,.MSRCH(P2)	;SAVE STEPPED CHANNEL NUMBER
	SETOM T2		;START WITH FIRST UNIT ON CHANNEL
	CALL STPUNI		;GET UNIT NUMBER OF FIRST UNIT
	 JRST MSTRS1		;NO UNITS ON THIS CHANNEL, TRY NEXT
	MOVEM T2,.MSRUN(P2)	;SAVE STEPPED UNIT NUMBER IN ARG BLOCK

; CHECK TO SEE IF UNIT IS OFF-LINE OR IN MAINTENANCE MODE

MSTRS2:	SETZM P3		;INITIALIZE STATUS TO BE RETURNED
	HRRZ T1,.MSRCH(P2)	;GET CHANNEL NUMBER
	HRRZ T2,.MSRCT(P2)	;GET CONTROLLER NUMBER
	HRRZ T3,.MSRUN(P2)	;GET UNIT NUMBER
	CALL GETSTR		;GET THE STRUCTURE NUMBER FOR THIS UNIT
	 JRST [	IOR P3,T1	;FAILED, UNIT OFFLINE OR USED FOR MAINTENANCE
		JRST MSTRS3]	;GO COPY DISK TYPE INFO
	MOVEM T1,MSTRSS		;SAVE UNIT IN STRUCTURE,,STRUCTURE NUMBER
	CAME T1,[-1]		;IS THIS UNIT IN A STRUCTURE ?
	TXO P3,MS%MNT		;YES, MARK THAT THIS UNIT IS PART OF A STRUCTURE
	;..
	;..

; HERE TO COPY THE DISK SIZE TABLE FOR THIS DISK TYPE

MSTRS3:	STOR T2,MSTYP,(P2)	;SAVE UNIT TYPE FOR USER
	MOVSI T1,-NDSKUT	;PREPARE TO FIND TYPE IN DSKUTP
MSTRS4:	CAME T2,DSKUTP(T1)	;FOUND IT?
	AOBJN T1,MSTRS4		;NO, KEEP LOOKING (SURE TO FIND IT)
	MOVE T1,DSKSIZ(T1)	;GET ADDRESS OF DISK SIZE TABLE
	HRLI T1,SECPAG(T1)	;GET SOURCE ADDRESS FOR COPY
	HRRI T1,.MSRSP(P2)	;GET DESTINATION (ARG BLOCK)
	BLT T1,.MSRBT(P2)	;COPY SIZE DATA FOR USER
	TXNE P3,MS%OFL!MS%DIA	;IS UNIT UNAVAILABLE (GETSTR CALL FAILED)?
	JRST MSTRS6		;YES, JUST GO STORE WHAT WE HAVE

; HERE TO READ THE HOME BLOCKS FOR THE SPECIFIED UNIT

	MOVE T1,.MSRCH(P2)	;GET CHANNEL NUMBER
	MOVE T2,.MSRCT(P2)	;GET CONTROLLER NUMBER
	MOVE T3,.MSRUN(P2)	;GET UNIT NUMBER
	CALL STRCHK		;GO CHECK CHANNEL, CONTROLLER, AND UNIT #'S
	 RETBAD ()		;FAILED, RETURN ERROR CODE TO USER
	MOVE T1,.MSRCH(P2)	;GET CHANNEL NUMBER
	MOVE T2,.MSRCT(P2)	;GET CONTROLLER NUMBER
	MOVE T3,.MSRUN(P2)	;GET UNIT NUMBER
	CALL MSTRHB		;GO READ THE HOME BLOCKS
	 JRST [	CAIN T1,MSTRX5	;UNIT OFF-LINE ?
		TXO P3,MS%OFL	;YES, MARK STATUS
		CAIN T1,MSTX20	;DATA ERROR READING HOME BLOCKS ?
		TXO P3,MS%ERR	;YES, MARK STATUS
		JRST MSTRS6 ]	;GO RETURN VALUES TO USER
	MOVEM T1,MSTRSA		;SAVE VIRTUAL ADDRESS OF HOME BLOCK PAGE
	MOVEM T2,MSTRSP		;SAVE PHYSICAL PAGE NUMBER

; CHECK THE HOME BLOCKS FOR THIS UNIT

	CALL MSTHBC		;GO CHECK THE HOME BLOCKS
	JUMPE T1,[TXO P3,MS%HBB	;IF BOTH HOME BLOCKS BAD, MARK STATUS
		  JRST MSTRS5]	;GO CHECK THE BAT BLOCKS
	;..
	;..

; GET THE STRUCTURE NAME AND UNIT INFO FROM THE HOME BLOCK

	MOVE T2,MSTRSA		;GET VIRTUAL ADDRESS OF FIRST HOME BLOCK
	TXNN T1,HB%1OK		;IS THE FIRST HOME BLOCK OK ?
	ADDI T2,HBLEN		;NO, USE THE SECOND HOME BLOCK
	MOVS T3,HOMLUN(T2)	;GET UNIT INFO FROM HOME BLOCK
	MOVEM T3,.MSRNS(P2)	;SAVE UNIT INFO IN ARG BLOCK TO BE RETURNED
	MOVE T1,HOMSNM(T2)	;GET STRUCTURE NAME FROM HOME BLOCK
	MOVEI T2,MSTRSN		;GET ADDRESS DESTINATION FOR STRING
	CALL SIXASC		;CONVERT STRING TO SIXBIT
	MOVEI T1,.MSRSN(P1)	;GET ADDRESS IN USER SPACE OF PTR TO DESTINATION
	MOVEI T2,MSTRSN		;GET ADDRESS OF STRUCTURE NAME STRING
	CALL STOSTR		;STORE NAME STRING IN USER SPACE
	MOVEM T1,.MSRSN(P2)	;SAVE UPDATED POINTER IN ARGUMENT BLOCK

; COPY THE UNIT-, OWNER-, AND FILE-SYSTEM-ID FIELDS FROM THE HOME BLOCK

	MOVE T2,MSTRSA		;GET START ADR OF HOME BLOCK PAGE
	HRLI T1,HOMUID(T2)	;GET SOURCE ADDRESS
	HRRI T1,.MSRUI(P2)	;GET DESTINATION ADDRESS
	BLT T1,.MSRFI+2(P2)	;COPY ID DATA FROM HOME BLOCK

; CHECK THE BAT BLOCKS ON THIS UNIT

MSTRS5:	MOVE T1,.MSRCH(P2)	;GET CHANNEL NUMBER
	MOVE T2,.MSRCT(P2)	;GET CONTROLLER NUMBER
	MOVE T3,.MSRUN(P2)	;GET UNIT NUMBER
	HRL T4,MSTRSA		;GET VIRTUAL ADDRESS OF HOME BLOCK PAGE
	HRR T4,MSTRSP		;GET PHYSICAL PAGE NUMBER OF BAT BLOCK PAGE
	CALL UNIBAT		;CHECK THE BAT BLOCKS FOR THIS UNIT
	 TXO P3,MS%BBB		;BAT BLOCKS BAD, MARK STATUS

; UNLOCK THE HOME BLOCK PAGE AND RELEASE THE PAGE

	MOVE T1,MSTRSP		;GET PHYSICAL CORE PAGE NUMBER
	CALL MULKCR		;UNLOCK THE HOME BLOCK PAGE
	MOVE T1,MSTRSA		;GET VIRTUAL ADDRESS OF HOME BLOCK PAGE
	CALL RELPAG		;RELEASE THE PAGE
	OKINT			;PERMIT INTERRUPT AGAIN
	;..
	;..

; COPY STRUCTURE INFORMATION FROM THE SDB

	MOVE T1,MSTRSS		;GET STRUCTURE NUMBER
	CAMN T1,[-1]		;IS UNIT PART OF A STRUCTURE ?
	JRST MSTRS6		;NO, IGNORE STRUCTURE INFORMATION
	MOVE T2,STRTAB(T1)	;GET ADDRESS OF SDB FOR THIS STRUCTURE
	LOAD T1,STRNSS,(T2)	;GET NUMBER OF SECTORS FOR SWAPPING
	MOVEM T1,.MSRSW(P2)	;SAVE NUMBER OF SWAPPING SECTORS
	HRRZ T1,MSTRSS		;GET STRUCTURE NUMBER
	MOVE T1,DEVNAM+DVXST0(T1) ;GET ALIAS OF THIS STRUCTURE
	MOVEI T2,MSTRSN		;GET ADDRESS OF DESTINATION OF ASCIZ STRING
	CALL SIXASC		;CONVERT SIXBIT TO ASCIZ
	MOVEI T1,.MSRSA(P1)	;GET ADR IN USER SPACE OF POINTER TO DESTINATION
	MOVEI T2,MSTRSN		;GET ADDRESS OF ASCIZ STRUCTURE NAME
	CALL STOSTR		;GO STORE THE STRUCTURE NAME
	MOVEM T1,.MSRSA(P2)	;STORE UPDATED POINTER IN ARGUMENT BLOCK

; RETURN ARGUMENTS TO THE USER ARGUMENT BLOCK

MSTRS6:	IORM P3,.MSRST(P2)	;STORE STATUS IN ARGUMENT BLOCK
	MOVE T3,P1		;COPY ADDRESS OF USER ARGUMENT BLOCK
	MOVE T2,P2		;GET SOURCE
	XCTU [ HLRZ T1,1 ]	;GET SIZE OF USER ARGUMENT BLOCK
	CAILE T1,.MSRLN		;BIGGER THAN MAX ALLOWED ?
	MOVEI T1,.MSRLN		;YES, RETURN ONLY MAX # OF WORDS
	CALL BLTMU		;COPY RESULTS TO USER SPACE
	RETSKP			;RETURN TO USER
; .MSSSS - SET STRUCTURE STATUS

; MASK OF BITS WHICH USER IS PERMITTED TO CHANGE --

MSTMSK== MS%DIS!MS%DOM

MSTSSS:	MOVE T1,CAPENB		;GET ENABLED CAPABILITIES
	TXNN T1,SC%WHL!SC%OPR	;REQUIRED PRIVILEGES ENABLED ?
	RETBAD (MSTRX2)		;NO, RETURN "INSUFFICIENT CAPABILITIES" ERROR

; CHECK SIZE OF ARGUMENT BLOCK

	XCTU [ HLRZ T1,1 ]	;GET SIZE OF USER'S ARGUMENT BLOCK
	CAIGE T1,.MSSLN		;BLOCK BIG ENOUGH ?
	RETBAD (MSTRX3)		;NO, RETURN "ARG BLOCK TOO SMALL" ERROR

; GET STRUCTURE NUMBER AND SDB ADDRESS

	UMOVE P1,2		;GET ADDRESS OF USER'S ARGUMENT BLOCK
	UMOVE T1,.MSSSN(P1)	;GET STRUCTURE NAME FROM ARGUMENT BLOCK
	CALL FNDSTR		;GET THE STRUCTURE NUMBER
	 RETBAD (MSTX21)	;STRUCTURE NOT MOUNTED WITH THAT NAME
	MOVE P2,STRTAB(T1)	;GET ADDRESS OF SDB FOR THIS STRUCTURE

; SET REQUESTED STATUS BITS

	UMOVE T3,.MSSST(P1)	;GET NEW STATUS BITS
	UMOVE T4,.MSSMW(P1)	;GET MASK WORD FROM ARGUMENT BLOCK
	CAIN T1,PSNUM		;CHANGING STATUS OF PUBLIC STRUCTURE ?
	TXZA T4,MSTMSK&<^-<MS%DOM!MS%DIS>> ;YES, DO NOT ALLOW PS: TO BE DISMOUNTED
	TXZ T4,MSTMSK		;CLEAR BITS WHICH USER IS ALLOWED TO CHANGE
	JUMPN T4,[CALL ULKSTR	;IF CHANGING ILLEGAL BITS, UNLOCK THE STRUCTURE
		  RETBAD (MSTX22)] ;RETURN "ILLEGAL TO CHANGE SPECIFIED BITS"
	UMOVE T4,.MSSMW(P1)	;GET MASK WORD AGAIN
	AND T3,T4		;GET JUST THE BITS TO BE SET
	IORM T3,SDBSTS(P2)	;SET THE BITS
	UMOVE T3,.MSSST(P1)	;GET THE STATUS AGAIN
	ANDCA T3,T4		;GET JUST THE BITS TO BE CLEARED
	ANDCAM T3,SDBSTS(P2)	;CLEAR THE BITS
	CALL ULKSTR		;UNLOCK THE STRUCTURE
	RETSKP			;RETURN TO USER
; .MSHOM - MODIFY HOME BLOCK

MSTHOM:	STKVAR <HSTRNM,MSHERR>
	MOVE A,CAPENB		;MAKE SURE USER PRIVILEGED
	TXNN A,SC%WHL!SC%OPR
	RETBAD (MSTRX2)		;"INSUFFICIENT PRIVS"
	XCTU [HLRZ A,1]		;GET USER'S ARG BLOCK LENGTH
	CAIGE A,4		;ENOUGH INFO SUPPLIED?
	RETBAD (MSTRX3)		;NO, "ARG BLOCK TOO SMALL"
	UMOVE P1,2		;GET ADDRESS OF ARGUMENT BLOCK
	UMOVE A,.MSHNM(P1)	;GET DESIGNATOR FOR STRUCTURE
	CALL FNDSTR		;LOCATE THE STRUCTURE
	 RETBAD (MSTX21)	;"STRUCTURE NOT MOUNTED"
	MOVEM A,HSTRNM		;REMEMBER STRUCTURE NUMBER
	UMOVE B,.MSHOF(P1)	;GET OFFSET INTO HOMEBLOCK
	UMOVE C,.MSHVL(P1)	;GET NEW DATA
	UMOVE D,.MSHMK(P1)	;GET MASK SHOWING WHICH PARTS OF WORD ARE TO CHANGE
	CALL MODHOM		;MODIFY HOME BLOCKS
	 JRST MSH1		;FAILED
	MOVE A,HSTRNM		;SUCCEEDED, GET STR NUMBER AGAIN
	CALL ULKSTR		;RELEASE THE STRUCTURE
	RETSKP			;GIVE GOOD RETURN

MSH1:	MOVEM A,MSHERR		;REMEMBER ERROR CODE
	MOVE A,HSTRNM		;GET STRUCTURE NUMBER
	CALL ULKSTR		;RELEASE STRUCTURE
	MOVE A,MSHERR		;GET REASON FOR FAILURE
	RETBAD			;ANNOUNCE FAILURE

; .MSSGS - GET STRUCTURE STATUS

; BITS WHICH CAN BE OBTAINED BY THE USER --

MSGMSK==MS%INI!MS%PPS!MS%DIS!MS%DOM

MSTGSS:	STKVAR <MSGSTR,<MSTGSB,.MSGLN>,<MSTGSI,2>>

; CHECK SIZE OF ARGUMENT BLOCK

	XCTU [HLRZ P4,1]	;GET SIZE OF USER'S ARGUMENT BLOCK
	CAIGE T1,1		;AT LEAST THE STRUCTURE NAME GIVEN ?
	RETBAD (MSTRX3)		;NO, RETURN "ARG BLOCK TOO SMALL" ERROR

; SEE IF DESIRED STRUCTURE IS MOUNTED

	UMOVE P1,2		;GET ADDRESS OF USER'S ARGUMENT BLOCK
	MOVEI P2,MSTGSB		;GET ADDRESS OF ARGUMENT BLOCK IN MONITOR SPACE
	SETZM P2,.MSGSI(P2)	;INITIALIZE POINTER TO STR NAME STRING
	UMOVE T1,.MSGSN(P1)	;GET STRUCTURE NAME FROM USER
	MOVEM T1,.MSGSN(P2)	;SAVE STRUCTURE NAME IN BLOCK TO BE RETURNED
	CALL FNDSTR		;SEE IF STRUCTURE IS MOUNTED
	 RETBAD (MSTX21)	;NO STRUCTURE WITH THAT NAME IS MOUNTED
	MOVEM T1,MSGSTR		;SAVE STRUCTURE NUMBER

; GET THE STATUS BITS FOR THE STRUCTURE

	MOVE T2,STRTAB(T1)	;GET ADDRESS OF SDB FOR THIS STRUCTURE
	MOVX P3,MSGMSK		;GET MASK OF BITS THAT CAN BE RETURNED
	AND P3,SDBSTS(T2)	;GET STRUCTURE STATUS TO RETURN
	SKIPN T1		;IS IT CURRENTLY THE PRIMARY PUBLIC STRUCTURE ?
	TXO P3,MS%PPS		;YES, MARK THAT THIS IS PRIMARY PUBLIC STRUCTURE
	MOVEM P3,.MSGST(P2)	;SAVE STATUS IN ARGUMENT BLOCK

; GET STRUCTURE INFORMATION

	LOAD T4,STRNUM,(T2)	;GET NUMBER OF UNITS IN STRUCTURE
	MOVEM T4,.MSGNU(P2)	;SAVE NUMBER OF UNITS IN ARG BLOCK TO RETURN
	LOAD T4,STRMC,(T2)	;GET MOUNT COUNT FOR THIS STRUCTURE
	MOVEM T4,.MSGMC(P2)	;SAVE MOUNT COUNT IN ARGUMENT BLOCK
	LOAD T4,STROF,(T2)	;GET OPEN FILE COUNT
	MOVEM T4,.MSGFC(P2)	;SAVE OPEN FILE COUNT IN ARGUMENT BLOCK
	LOAD T1,STRNAM,(T2)	;GET SIXBIT STRUCTURE NAME
	MOVEI T2,MSTGSI		;GET ADDRESS WHERE ASCIZ NAME WILL GO
	CALL SIXASC		;CONVERT SIXBIT TO ASCII
	MOVEI T1,.MSGSI(P1)	;GET ADDRESS OF USER'S POINTER
	MOVEI T2,MSTGSI		;GET ADDRESS OF ASCIZ STR NAME IN MONITOR SPACE
	CAILE P4,.MSGSI		;USER PROVIDE ENOUGH SPACE FOR STR NAME PTR ?
	CALL STOSTR		;YES, USE POINTER TO STORE STRUCTURE NAME
	XCTU [SKIPE .MSGSI(P1)]	;DID USER SUPPLY A POINTER ?
	MOVEM T1,.MSGSI(P2)	;YES, SAVE POINTER TO NAME IN ARG BLOCK
	; ..
	; ..

; RETURN ARGUMENT BLOCK TO THE USER

	MOVE T3,P1		;COPY ADDRESS OF USER ARGUMENT BLOCK
	MOVE T2,P2		;GET SOURCE
	CAILE P4,.MSGLN		;BIGGER THAN MAX ALLOWED ?
	MOVEI P4,.MSGLN		;YES, RETURN ONLY MAX # OF WORDS
	MOVE T1,P4		;GET LENGTH
	CALL BLTMU		;COPY RESULTS TO USER SPACE
	MOVE T1,MSGSTR		;GET THE STRUCTURE NUMBER
	CALL ULKSTR		;UNLOCK THE STRUCTURE
	RETSKP			;RETURN TO USER
; .MSIMC/.MSDMC - INCREMENT/DECREMENT MOUNT COUNT

MSTIMC:	TDZA T1,T1		;MARK THAT COUNT SHOULD BE INCREMENTED
MSTDMC:	SETOM T1		;MARK THAT COUNT SHOULD BE DECREMENTED
	ASUBR <MSTMCF,MSTMUC>

; CHECK SIZE OF USER ARGUMENT BLOCK

	XCTU [HLRZ T1,1]	;GET SIZE OF USER ARGUMENT BLOCK
	CAIGE T1,1		;AT LEAST ONE ITEM SPECIFIED ?
	RETBAD (MSTRX3)		;NO, ARGUMENT BLOCK TOO SMALL

; CHECK THAT THE STRUCTURE IS MOUNTED

	UMOVE P1,2		;GET ADDRESS OF USER'S ARGUMENT BLOCK
	UMOVE T1,.MSDEV(P1)	;GET DEVICE DESIGNATOR OF STRUCTURE
	CALL FNDSTR		;GO SEE IF STRUCTURE IS MOUNTED
	 RETBAD ()		;FAILED, STRUCTURE NOT MOUNTED
	MOVEM T1,P2		;SAVE STRUCTURE NUMBER
	CALL STRCNV		;GET STRUCTURE UNIQUE CODE
	 JRST MCTERR		;FAILED, UNLOCK STRUCTURE AND RETURN
	MOVEM T1,MSTMUC		;SAVE UNIQUE CODE

; INCREMENT OR DECREMENT THE MOUNT COUNT AS APPROPRIATE

	LOCK JSSTLK		;LOCK THE STRUCTURE INFO LOCK IN THE JSB
	MOVE T1,MSTMUC		;GET UNIQUE CODE AGAIN
	CALL GTSTOF		;GET OFFSET FOR THIS STRUCTURE IN JSB
	 JRST MCTERR		;FAILED, UNLOCK STRUCTURE AND RETURN ERROR
	MOVE T1,P2		;GET STRUCTURE NUMBER AGAIN
	MOVE T3,MSTMCF		;GET INCREMENT/DECREMENT FLAG
	ADDI T3,1		;FORM OFFSET TO PROPER CALL INSTRUCTION
	XCT [CALL DECMNT	;GO INCREMENT THE MOUNT COUNT
	     CALL INCMNT](T3)	;GO DECREMENT THE MOUNT COUNT
	 JRST [	UNLOCK JSSTLK	;UNLOCK THE JSB STRUCTURE LOCK
		JRST MCTERR ]	;GO UNLOCK STRUCTURE AND RETURN ERROR
	MOVE T1,MSTMUC		;GET UNIQUE CODE AGAIN
	CALL FRJSST		;FREE JSB STR STORAGE IF NOW UNUSED
	UNLOCK JSSTLK		;UNLOCK THE STRUCTURE INFO LOCK
	MOVE T1,P2		;GET THE STRUCTURE NUMBER
	CALL ULKSTR		;UNLOCK THE STRUCTURE
	RETSKP			;SUCCESS, RETURN

; HERE ON AN ERROR

MCTERR:	EXCH P2,T1		;SAVE ERROR CODE, GET STRUCTURE NUMBER
	CALL ULKSTR		;UNLOCK THE STRUCTURE
	MOVE T1,P2		;RESTORE THE ERROR CODE
	RETBAD ()			;RETURN ERROR TO USER
;INCMNT - ROUTINE TO INCREMENT THE MOUNT COUNT FOR A STRUCTURE
;
;ACCEPTS IN T1/	STRUCTURE NUMBER
;	    T2/ OFFSET TO JSB DATA FOR THIS STRUCTURE
;		CALL INCMNT
;RETURNS: +1	 FAILED, ERROR CODE IN T1
;	  +2	SUCCESS, COUNT INCREMENTED IF NOT PREVIOUSLY INCREMENTED
;			 BY THIS JOB.
;
; NOTE: STRUCTURE MUST BE LOCKED DURING THIS ROUTINE

INCMNT::JN JSMCI,(T2),[RETBAD (MSTX31)]	;YES, RETURN IF ALREADY INCREMENTED BY THIS JOB
	MOVE T1,STRTAB(T1)	;GET ADDRESS OF STRUCTURE DATA BLOCK TO THIS STR
	JE STDIS,(T1),INCMN2	;IS STRUCTURE BEING DISMOUNTED ?
	RETBAD (MSTX33)		;YES, ALLOW NO FURTHER INCREMENTS
INCMN2:	NOINT			;DON'T PERMIT INTERRUPTS WHEN CHANGING DATA BASE
	NOSKED			;MUST CHANGE JSB AND SDB "SIMULTANEOUSLY"
	SETONE JSMCI,(T2)	;MARK THAT COUNT HAS BEEN INCREMENTED
	INCR STRMC,(T1)		;BUMP THE MOUNT COUNT
	OKSKED			;BOTH CHANGED, PERMIT SCHEDULING AGAIN
	OKINT			;PERMIT INTERRUPTS AGAIN
	RETSKP			;RETURN SUCCESS
;DECMNT - ROUTINE TO DECREMENT THE MOUNT COUNT FOR A STRUCTURE
;
;ACCEPTS IN T1/	STRUCTURE NUMBER
;	    T2/ OFFSET TO JSB DATA FOR THIS STRUCTURE
;		CALL DECMNT
;RETURNS: +1	 FAILED, ERROR CODE IN T1
;	  +2	SUCCESS, MOUNT COUNT DECREMENTED IF PREVIOUSLY INCREMENTED
;			 BY THIS JOB, AND A MESSAGE SENT TO THE MOUNTABLE
;			 DEVICE ALLOCATOR.
;
; NOTE: STRUCTURE MUST BE LOCKED DURING THIS ROUTINE
; THIS ROUTINE IS CALLED FROM BOTH THE MSTR AND LGOUT JSYS'ES

DECMNT::JE JSMCI,(T2),[RETBAD (MSTX32)]	;RETURN IF THE COUNT HAS NEVER BEEN INCREMENTED
	MOVE T3,STRTAB(T1)	;GET ADDRESS OF STRUCTURE DATA BLOCK
	NOINT			;DO NOT PERMIT INTERRUPTS
	NOSKED			;JSB AND SDB MUST BE CHANGED "SIMULTANEOUSLY"
	DECR STRMC,(T3)		;DECREMENT THE MOUNT COUNT FOR THIS STRUCTURE
	SETZRO JSMCI,(T2)	;MARK THAT MOUNT COUNT CAN BE INCREMENTED AGAIN
	OKSKED			;BOTH CHANGED, PERMIT SCHEDULING AGAIN
	CALL DISMES		;SEND A MESSAGE TO THE DEVICE ALLOCATOR
	JFCL			;IGNORE IF MESSAGE FAILED (USUALLY CAUSED BY SHUTDOWN)
	OKINT			;PERMIT INTERRUPTS AGAIN
	RETSKP			;RETURN SUCCESS
; .MSGSU - GET STRUCTURE USERS

MSTGSU:	STKVAR <MSUBLK,MSUSTR>

; CHECK THE SIZE OF THE ARGUMENT BLOCK

	XCTU [HLRZ Q1,1]	;GET SIZE OF ARGUMENT BLOCK FROM USER
	CAIG Q1,.MSUJ1		;ROOM FOR AT LEAST ONE JOB NUMBER ?
	RETBAD (MSTRX3)		;NO, ARGUMENT BLOCK TOO SMALL

; CHECK FOR A VALID FUNCTION CODE

	UMOVE P1,2		;GET ADDRESS OF USER'S ARGUMENT BLOCK
	UMOVE Q2,.MSUFL(P1)	;GET THE FLAGS FROM THE USER
	TXNN Q2,MS%GTA!MS%GTC!MS%GTM ;VALID FUNCTION REQUESTED ?
	RETBAD (MSTRX1)		;NO, RETURN INVALID FUNCTION

; GO CHECK THE STRUCTURE NAME AND GET THE UNIQUE CODE

	UMOVE T1,.MSUAL(P1)	;GET POINTER TO NAME STRING IN USER SPACE
	CALL FNDSTR		;GO CHECK THE STRUCTURE NAME
	 RETBAD ()			;FAILED, STRUCTURE NOT MOUNTED
	MOVEM T1,Q3		;SAVE STRUCTURE NUMBER
	CALL STRCNV		;GET THE UNIQUE CODE FOR THIS STRUCTURE
	 JRST [	MOVE T1,Q3	;GET STRUCTURE NUMBER
		CALL ULKSTR	;UNLOCK THE STRUCTURE
		RETBAD (STRX01)] ;RETURN ERROR TO USER
	MOVEM T1,MSUSTR		;SAVE UNIQUE CODE
	MOVE T1,Q3		;RESTORE STRUCTURE NUMBER
	CALL ULKSTR		;UNLOCK THE STRUCTURE

; SET UP TO CHECK EACH JOB ON THE SYSTEM

	ADDI Q1,-1(P1)		;COMPUTE HIGHEST ADR TO STORE INTO IN USER SPACE
	MOVEI P4,.MSUJ1(P1)	;GET USER ADDRESS OF NEXT WORD TO STORE INTO
	MOVSI P2,-NJOBS		;SET UP AOBJN POINTER TO LOOP OVER ALL JOBS
	;..
	;..

; TOP OF LOOP OVER ALL JOBS - IF JOB EXISTS, MAP IT'S JSB

MSGU10:	HRRZ T1,JOBDIR(P2)	;GET RIGHT HALF OF USER NUMBER
	JUMPE T1,MSGU70		;DO NOT CONSIDER JOBS NOT LOGGED IN
	HRRZ T1,P2		;YES, GET THE JOB NUMBER
	CALL MAPJSB		;MAP THE JSB FOR THAT JOB
	 JRST MSGU70		;JOB MUST HAVE LOGGED OUT, GO ON
	MOVEM T1,P3		;SAVE OFFSET TO MAPPED JSB
	MOVE T2,T1		;GET OFFSET TO WHERE JSB IS MAPPED
	HRRZ T1,MSUSTR		;GET UNIQUE CODE FOR THIS STRUCTURE
	CALL FNDSTM		;FIND THE OFFSET IN JSB FOR THIS STRUCTURE
	 TDZA T1,T1		;STRUCTURE NOT IN USE BY THIS JOB
	SETO T1,		;MARK THAT STR IS IN USE
	HRRZ T3,P2		;GET JOB #
	JUMPE T1,MSGU40		;IF STR NOT IN USE, ONLY LOOK AT CONNECTION
	JE MS%GTM,Q2,MSGU20	;USER ASKING FOR LIST OF JOBS THAT MOUNTED STR ?
	JE JSMCI,(T2),MSGU20	;YES. DID THIS JOB MOUNT THE STRUCTURE ?
	TXO T3,MS%GTM		;YES, SET THIS BIT FOR USER
MSGU20:	JE MS%GTA,Q2,MSGU40	;USER WANT LIST OF JOBS THAT ACCESSED STR ?
	JE JSADN,(T2),MSGU40	;YES. DID THIS JOB ACCESS THE STRUCTURE ?
	TXO T3,MS%GTA		;YES, GIVE BIT TO USER
MSGU40:	JE MS%GTC,Q2,MSGU50	;NO. USER WANT LIST OF JOBS CONNECTED TO STR ?
	LOAD T4,JSUC,(P3)	;GET CONNECTED STRUCTURE UNIQUE CODE
	CAMN T4,MSUSTR		;SAME AS REQUESTED STRUCTURE ?
	TXO T3,MS%GTC		;YES, GIVE BIT TO USER
MSGU50:	TLNN T3,-1		;ANY BITS ON?
	JRST MSGU60		;NO, DONT GIVE THIS TO USER
	CAMLE P4,Q1		;ENOUGH ROOM TO STORE ANOTHER JOB # ?
	JRST [	CALL CLRJSB	;NO- UNMAP THE JSB NOW MAPPED
		JRST MSGU80]	;GO RETURN # OF JOB NUMBERS STORED
	UMOVEM T3,0(P4)		;STORE THIS JOB NUMBER AND FLAGS
	ADDI P4,1		;POINT TO NEXT ENTRY IN USER ARG BLOCK
MSGU60:	CALL CLRJSB		;UNMAP THE CURRENTLY MAPPED JSB
MSGU70:	AOBJN P2,MSGU10		;GO CHECK NEXT JOB

; DONE STORING INDIVIDUAL JOB NUMBERS - RETURN # OF ITEMS STORED

MSGU80:	SUBI P4,.MSUJ1(P1)	;COMPUTE # OF ITEMS STORED
	XCTU [HRRM P4,.MSUFL(P1)] ;STORE # OF ITEMS RETURNED
	RETSKP			;RETURN TO USER
; ROUTINE TO READ THE HOME BLOCKS ON A UNIT AND RETURN THE UNIT TYPE
;
; ACCEPTS:	T1/ CHANNEL NUMBER
;		T2/ CONTROLLER NUMBER (CURRENTLY MUST BE -1)
;		T3/ UNIT NUMBER
;		CALL MSTRHB
; RETURNS: +1	 FAILED,  RETURNS OKINT WITH ERROR CODE IN T1
;	   +2	SUCCESS, RETURNS NOINT WITH:
;		T1/ VIRTUAL ADDRESS OF HOME BLOCK PAGE
;		T2/ PHYSICAL CORE PAGE NUMBER OF HOME BLOCK PAGE
;
; NOTE: RETURNS NOINT ON SUCCESS, WITH HOME BLOCK PAGE LOCKED

MSTRHB:	ASUBR <RHBCHN,RHBCTL,RHBUNI>
	STKVAR <RHBADR,RHBPAG,RHBERR>
	NOINT			;DO NOT PERMIT INTERRUPTS WITH SPACE ASSIGNED
	CALL ASGPAG		;ASSIGN A JSB PAGE FOR READING HOME BLOCKS
	 RETBAD (MSTRX4,<OKINT>) ;FAILED, RETURN "INSUFFICIENT RESOURCES" ERROR
	MOVEM T1,RHBADR		;SAVE VIRTUAL ADDRESS OF HOME BLOCK PAGE
	CALL MLKMA		;LOCK DOWN THE PAGE SO THAT I/O CAN BE DONE
	MOVEM T1,RHBPAG		;SAVE PHYSICAL PAGE NUMBER OF HOME BLOCK PAGE
	HRL T1,RHBCHN		;GET CHANNEL NUMBER
	HRR T1,RHBUNI		;GET UNIT NUMBER
	MOVE T2,RHBPAG		;GET PHYSICAL PAGE NUMBER
	LSH T2,PGSFT		;COMPUTE PHYSICAL ADDRESS
	MOVEI T3,HM1BLK		;GET BLOCK NUMBER OF FIRST HOME BLOCK
	MOVE T4,RHBADR		;GET VIRTUAL ADDRESS OF HOME BLOCK PAGE
	CALL REDHOM		;READ THE TWO HOME BLOCKS
	 JRST [	MOVEM T1,RHBERR	;FAILED, SAVE ERROR BITS
		MOVE T1,RHBPAG	;GET PHYSICAL PAGE NUMBER BACK
		CALL MULKCR	;UNLOCK THE PAGE
		MOVE T1,RHBADR	;GET VIRTUAL ADDRESS OF PAGE
		CALL RELPAG	;RELEASE THE PAGE
		MOVE T1,RHBERR	;GET ERROR CODE BACK
		CAME T1,[-1]	;WAS UNIT OFF-LINE ?
		RETBAD (MSTX20,<OKINT>) ;NO, RETURN DATA ERROR CODE
		RETBAD (MSTRX5,<OKINT>) ] ;YES, RETURN "DRIVE OFF LINE" ERROR
	MOVE T1,RHBADR		;SUCCESS, GET VIRTUAL ADDRESS OF HOME BLOCKS
	MOVE T2,RHBPAG		;GET PHYSICAL PAGE NUMBER OF HOME BLOCK PAGE
	RETSKP			;RETURN (NOINT)
; ROUTINE TO CHECK THE HOME BLOCKS
;
; ACCEPTS IN T1/ VIRTUAL ADDRESS OF HOME BLOCK PAGE
;		CALL MSTHBC
; RETURNS: +1 ALWAYS, WITH P3/ FLAGS:
;		HB%1OK IF FIRST HOME BLOCK IS OK
;		HB%2OK IF SECOND HOME BLOCK IS OK

MSTHBC:	SAVEP			;SAVE PRESERVED AC'S
	ASUBR <HBCVIR>		;SAVE VIRTUAL ADDRESS OF HOME BLOCK PAGE
	SETZM P3		;INITIALIZE FLAGS FOR THIS UNIT
	MOVE T1,HBCVIR		;GET VIRTUAL ADDRESS OF FIRST HOME BLOCK
	MOVEI T2,HM1BLK		;GET # OF THIS HOME BLOCK
	CALL HBCCHK		;CHECK FIRST HOME BLOCK
	 TXZA P3,HB%1OK		;FIRST HOME BLOCK IS NO GOOD
	TXO P3,HB%1OK		;FIRST HOME BLOCK IS FINE AND DANDY
	MOVE T1,HBCVIR		;GET VIRTUAL ADDRESS OF FIRST HOME BLOCK
	ADDI T1,HBLEN		;FORM ADDRESS OF SECOND HOME BLOCK
	MOVEI T2,HM2BLK		;GET BLOCK ADDRESS OF SECOND HOME BLOCK
	CALL HBCCHK		;GO CHECK SECOND HOME BLOCK
	 TXZA P3,HB%2OK		;MARK THAT SECOND HOME BLOCK IS NO GOOD
	TXO P3,HB%2OK		;INDICATE SECOND HOME BLOCK IS FINE
	MOVE T1,P3		;COPY FLAGS TO RETURN
	RET			;RETURN


;SIXASC - ROUTINE TO CONVERT SIXBIT TO ASCII
;
;ACC