Google
 

Trailing-Edge - PDP-10 Archives - BB-Y393Q-SM - monitor-sources/mstr.mac
There are 55 other files named mstr.mac in the archive. Click here to see a list.
; Edit= 8861 to MSTR.MAC on 13-Jul-88 by GSCOTT, for SPR #21933
;Do only 1 TTMSG instead of 3 to each user who has a structure mounted when a
;dismount is forced. 
; *** Edit 7430 to MSTR.MAC by MCCOLLUM on 31-Mar-87
; If the structure limit has been reached in MAKSDB, return the MSTX51 error. 
; *** Edit 7359 to MSTR.MAC by LOMARTIRE on 25-Aug-86
; Fix minor bug in edit 7352 
; *** Edit 7216 to MSTR.MAC by GRANT on 23-Dec-85, for SPR #20902
; Even if home blocks are not good, have MSTR% return data anyway 
; *** Edit 7190 to MSTR.MAC by GRANT on 12-Nov-85
; Within MSTR%, use TTMSG% instead of SOUT% to prevent blocking forever 
;Edit 3112 to MSTR.MAC by SHTIL on Fri 25-May-84, for SPR #20129
;		Fix HOMCHK to copy correctly the secondary home block
;;		over the primary
;Edit 2965 to MSTR.MAC by MOSER on Fri 10-Jun-83 - FIX MSTR HANG
;EDIT 2965 - REWRITE MSTR TO PREVENT HUNG JOBS DOING DISMOUNT
;Edit 2960 to MSTR.MAC by WEETON on Tue 10-May-83, for SPR #18539
;		Allow abortions of DA%INI without doing DA%WRTs
;Edit 2948 by MAYO on Fri 22-Apr-83, for SPR #18667
;		Fix for MSTR byte pointer handling (.MSRNU function)
; UPD ID= 288, FARK:<4-1-WORKING-SOURCES.MONITOR>MSTR.MAC.5,  13-Jan-83 16:34:16 by MOSER
;EDIT 2896 - ALLOW MOUNT IF IGNORING ERRORS AND BACKUP ROOT-DIRECTORY BAD
; UPD ID= 219, FARK:<4-1-WORKING-SOURCES.MONITOR>MSTR.MAC.3,   4-Nov-82 12:16:09 by MOSER
;EDIT 2856 - RETURN MS%PS WHEN APPROPRIATE
; UPD ID= 126, FARK:<4-1-WORKING-SOURCES.MONITOR>MSTR.MAC.2,   5-Aug-82 15:47:00 by MOSER
;EDIT 2644 - PREVENT MAPBT1.
;<4-1-FIELD-IMAGE.MONITOR>MSTR.MAC.2, 25-Feb-82 20:30:41, EDIT BY DONAHUE
;UPDATE COPYRIGHT DATE
; UPD ID= 917, FARK:<4-WORKING-SOURCES.MONITOR>MSTR.MAC.9,  10-Dec-81 13:31:17 by DONAHUE
;Edit 1966 - Remove previous edit, make change to routine CHKBAK in DIRECT
; UPD ID= 860, FARK:<4-WORKING-SOURCES.MONITOR>MSTR.MAC.8,  13-Oct-81 09:35:58 by DONAHUE
;Edit 1956 - Decrement share count on <ROOT-DIRECTORY> OFN when dismounting
; UPD ID= 727, FARK:<4-WORKING-SOURCES.MONITOR>MSTR.MAC.7,  19-Aug-81 13:32:33 by ZIMA
;Edit 1926 - put edit 1891 in standard form.  No code changes.
;Edit 1926 - put edit 1851 in standard form.  No code changes.
; UPD ID= 720, FARK:<4-WORKING-SOURCES.MONITOR>MSTR.MAC.6,  19-Aug-81 10:33:36 by ZIMA
;Edit 1925 - put edit 1828 in standard form.  No code changes.
; UPD ID= 600, FARK:<4-WORKING-SOURCES.MONITOR>MSTR.MAC.5,  12-Jun-81 12:08:56 by MOSER
;EDIT 1891 - When MS%XCL is set for a mount the assign the structure to
; the job instead of keeping the structure in initialize mode.
; UPD ID= 460, FARK:<4-WORKING-SOURCES.MONITOR>MSTR.MAC.4,  16-Apr-81 16:42:08 by MOSER
;Edit 1851 - Correctly send structure status to device allocator.
; Requires MOUNTR edit 116 to version 4.
; UPD ID= 375, FARK:<4-WORKING-SOURCES.MONITOR>MSTR.MAC.3,  21-Jan-81 10:52:30 by SCHMITT
;Edit 1828 - Check JOB number validity at MSTJOB.
; UPD ID= 241, FARK:<4-WORKING-SOURCES.MONITOR>MSTR.MAC.2,   7-Oct-80 16:11:44 by ZIMA
;Edit 1797 - Clean up properly if MSTR GETOK fails.
; UPD ID= 200, FARK:<4-WORKING-SOURCES.MONITOR>MSTR.MAC.5,   9-Sep-80 12:10:51 by MOSER
; UPD ID= 168, FARK:<4-WORKING-SOURCES.MONITOR>MSTR.MAC.4,  28-Aug-80 14:51:22 by ZIMA
;Edit 1772 - put 1750/53 into standard form, no code changes.
; UPD ID= 107, FARK:<4-WORKING-SOURCES.MONITOR>MSTR.MAC.3,  26-Jun-80 18:38:49 by SCHMITT
;Edit 1753 - Fix Emacs Ripoff
; UPD ID= 100, FARK:<4-WORKING-SOURCES.MONITOR>MSTR.MAC.2,  25-Jun-80 21:35:33 by SCHMITT
;Edit 1750 - Change error ret for GTSTOJ to unlock JSSTLK
;<4.MONITOR>MSTR.MAC.45,  3-Jan-80 08:09:37, EDIT BY R.ACE
;UPDATE COPYRIGHT DATE
;<4.MONITOR>MSTR.MAC.44, 30-Oct-79 13:41:01, Edit by KONEN
;CORRECT STRUCTURE ACCOUNTING RECORD
;<4.MONITOR>MSTR.MAC.43, 29-Oct-79 15:26:18, Edit by KONEN
;BAD IDEA, CHANGE TIMES BACK TO GTAD UNITS
;<4.MONITOR>MSTR.MAC.42, 20-Sep-79 17:07:41, EDIT BY HALL
;MSTMNT,MSTRUS,MSTGSS - CALL BLTMU1/BLTUM1 TO APPLY PCS IF NECESSARY
;<4.MONITOR>MSTR.MAC.41, 13-Sep-79 09:16:30, Edit by KONEN
;CHANGE TIMES FOR USAGE TO MILLISECONDS, RATHER THAN GTAD UNITS
;<4.MONITOR>MSTR.MAC.40, 11-Sep-79 10:39:01, Edit by KONEN
;CORRECT TCO 4.2431
;<4.MONITOR>MSTR.MAC.39,  7-Sep-79 04:52:52, EDIT BY R.ACE
;ADD COMMENT IN MSTDIS
;<4.MONITOR>MSTR.MAC.38, 30-Aug-79 14:22:50, EDIT BY SCHMITT
;TCO 4.2431 - CHANGE STRST CALL TO DEVST IN MSTDIS
;<4.MONITOR>MSTR.MAC.37, 27-Aug-79 16:02:22, EDIT BY ZIMA
;TCO 4.2423 - INCLUDE MS%LIM IN MSGMSK TO ALLOW RETURNING IT
;<4.MONITOR>MSTR.MAC.36, 23-Jul-79 16:51:00, Edit by KONEN
;ALLOW DISMOUNT OF REGULATED STRUCTURE EVEN IF USER ACCESS'ING IT
;<4.MONITOR>MSTR.MAC.35,  7-Jul-79 18:46:49, Edit by KONEN
;REMOVE NOSKED DURING SETTING UP OF DIRECTORIES
;<4.MONITOR>MSTR.MAC.34, 30-May-79 11:00:59, Edit by LCAMPBELL
; Check for C(FILSTS)=0, not just presence of NAMEF or ASGF
;<4.MONITOR>MSTR.MAC.33, 29-May-79 14:10:42, Edit by LCAMPBELL
; When decr mount count, only check JFNs with NAMEF or ASGF on
;<4.monitr>mstr.mac.32, 15-may-79 9:20:32, edit by schmitt
;fix for illegal read when .msrnu arg blk is less than 6 words
;<4.MONITOR>MSTR.MAC.29, 26-Apr-79 11:19:57, Edit by KONEN
;<4.MONITOR>MSTR.MAC.28, 23-Apr-79 16:46:17, Edit by KONEN
;CHANGE INITING JOB IN SDB TO INITING FORK, REMOVE DEVLCK IN STRINI
;<4.MONITOR>MSTR.MAC.26, 16-Apr-79 11:55:36, Edit by KONEN
;SEND STRUCTURE REMOVAL INFO CORRECTLY TO DEVICE ALLOCATOR
;<4.MONITOR>MSTR.MAC.25,  5-Apr-79 11:05:53, Edit by MCLEAN
;REMOVE FIRST ARGUMENT FROM GTOKM MACRO
;<4.MONITOR>MSTR.MAC.24, 29-Mar-79 09:03:06, Edit by KONEN
;<4.MONITOR>MSTR.MAC.23, 21-Mar-79 14:06:04, EDIT BY KIRSCHEN
;ADD TEMPORARY FIX FOR DEADLY EMBRACE IN STRINI
;<4.MONITOR>MSTR.MAC.22, 19-Mar-79 13:32:56, EDIT BY KIRSCHEN
;DO NOT PERMIT INTERRUPTS WITH FREE SPACE ASSIGNED IN MSTMNT
;<4.MONITOR>MSTR.MAC.21, 12-Mar-79 10:33:05, Edit by KONEN
;SEND ALL USAGE INFO TO DEVICE ALLOCATOR
;<4.MONITOR>MSTR.MAC.20,  7-Mar-79 15:32:18, Edit by MCLEAN
;FIX GETOK FOR INCREMENT STRUCTURE COUNT TO GIVE DEVICE DESIG CORRECTLY
;<4.MONITOR>MSTR.MAC.19,  4-Mar-79 18:34:48, EDIT BY KONEN
;UPDATE COPYRIGHT FOR RELEASE 4
;<4.MONITOR>MSTR.MAC.18,  8-Feb-79 13:42:29, Edit by KONEN
;PROHIBIT MOUNT OF STR WITH ALIAS WHICH IS IN SYSTEM LOGICAL NAMES TABLE
;<4.MONTOR>MSTR.MAC.17, 17-Jan-79 23:45:54, Edit by MCLEAN
;FIX GETOK SO IT IS DEVICE DESIGNATOR
;<4.MONITOR>MSTR.MAC.16, 15-Jan-79 22:33:38, EDIT BY GILBERT
;FIX VERSION SKEW BETWEEN MCLEAN AND KONEN.
;<4.MONITOR>MSTR.MAC.15, 15-Jan-79 14:08:52, Edit by KONEN
;ADD .MSIIC FUNCTION
;<4.MONITOR>MSTR.MAC.14, 14-Jan-79 20:02:09, Edit by MCLEAN
;FIX GETOK SO IT ONLY HAS ONE ARGUMENT
;<4.MONITOR>MSTR.MAC.13, 10-Jan-79 12:59:45, EDIT BY MILLER
;MAKE SIXASC INTERNAL (USED BY TAPE)
;<4.MONITOR>MSTR.MAC.12,  8-Jan-79 06:52:07, EDIT BY GILBERT
;TCO 4.2155 - Implement hidden symbol tables:
;	Change the JSVAR macro to JSBVAR.
;<4.MONITOR>MSTR.MAC.11,  5-Jan-79 12:49:03, Edit by KONEN
;FIX SECG37 FROM MSTRUS
;<4.MONITOR>MSTR.MAC.10, 21-Dec-78 10:18:03, Edit by KONEN
;<4.MONITOR>MSTR.MAC.9,  16-Nov-78 14:13:46, Edit by KONEN
;ADD MOUNT/DISMOUNT CODE AS ARGUMENT TO DISMES CALL
;<KONEN>MSTR.MAC.4, 11-Aug-78 12:06:49, Edit by KONEN
;<KONEN>MSTR.MAC.38,  2-Aug-78 18:17:27, Edit by KONEN
;ALLOW OPERATOR OR WHEEL TO INCREMENT MOUNT COUNT. ALLOW SETTING OF
; PUBLIC BIT OF STRUCTURE STATUS. DISALLOW DECREMENT OF MOUNT COUNT
; WHILE JFN'S ASSIGNED, CONNECTED OR ACCESSING THE STRUCTURE.
;<4.MONITOR>MSTR.MAC.7, 16-Sep-78 14:30:32, EDIT BY MILLER
;RELEASE STRLOK AS SOON AS SDB IS CLEANED UP ON A DISMOUNT
;<4.MONITOR>MSTR.MAC.6, 15-Sep-78 13:43:25, Edit by MCLEAN
;ANOTHER NOINT/NOSKED
;<4.MONITOR>MSTR.MAC.5, 15-Sep-78 13:39:27, Edit by MCLEAN
;INSERT MOUNT COUNT INCREMENT/DECREMENT GETOK
;<4.MONITOR>MSTR.MAC.4, 15-Sep-78 13:34:19, Edit by MCLEAN
;REMOVE EXTRANEOUS NOINT/OKINT IN INCMNT
;<4.MONITOR>MSTR.MAC.3, 14-Aug-78 16:39:37, Edit by HEMPHILL
;TCO 1984 -- FIX SECNX B PROCESSOR BUG
;<4.MONITOR>MSTR.MAC.2, 10-Jul-78 18:56:30, Edit by HEMPHILL
;TCO 1935--MAKE .MSRNU REPORT SWAPPING PAGES FOR STRUCTURE, NOT
; SWAPPING SECTORS PER UNIT
;<4.MONITOR>MSTR.MAC.1, 22-Jun-78 15:52:09, EDIT BY MILLER
;LOCK STRLOK DURING A DISMOUNT


;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,1979,1980,1981,1982 BY DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.

	SEARCH PROLOG,PHYPAR
	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 FOR THE JOB
	MSTDMC		;DECREMENT MOUNT COUNT FOR THE JOB
	MSTGSU		;GET STRUCTURE USERS
	MSTHOM		;MODIFY HOME BLOCK
	MSTICF		;INCREMENT MOUNT COUNT FOR A FORK
	MSTDCF		;DECREMENT MOUNT COUNT FOR A FORK
	MSTOFL		;ALLOWS MDA TO REQUEST INTERRUPT ON A CHANNEL
	MSTIIC		;IGNORE MOUNT COUNT CHECK
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
	NOINT			;PREVENT INTERRUPTS WITH SPACE ASSIGNED
	CALL ASGJFR		;ASSIGN FREE SPACE TO HOLD BLOCK
	 RETBAD (MONX01,<OKINT>) ;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 BLTUM1		;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,FORKX		;GET CURRENT FORK NUMBER
	MOVE T4,MSTMNB(Q3)	;GET ADDRESS OF SDB FOR THIS STRUCTURE
	STOR T3,STRJB,(T4)	;INDICATE INITING FORK

; 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
;**;[2644]MAKE CHANGES AT MSTM75:+1L	TAM	4-AUG-82
	MOVE T2,MSTMNB(Q3)	;[2644] ADDR OF SDB
	LOAD T3,STRBTB,(T2)	;[2644] OFN OF BITTABLE
	MOVEI T2,0		;NO FLAGS (DON'T TYPE CTY MESSAGES)
	SKIPE T3		;[2644] IF NO BITTABLE
	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
;**;[2896]REPLACE 2 LINES WITH 5 AT MSTM80:+2L	TAM	11-JAN-83
	 JRST [	MOVX T1,MSTX13	;[2896] GET "BAD BACKUP ROOT-DIRECTORY" ERROR
		MOVE T4,.MSTFL(P3) ;[2896] GET FLAGS FROM USER ARGUMENT BLOCK
		TXNN T4,MS%IGN	;[2896] IGNORE NON-FATAL ERRORS ?
		JRST MNTER7	;[2896] NO, RETURN ERROR CODE TO USER
		JRST .+1]	;[2896] YES, CONTINUE WITH MOUNT
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
	MOVE T3,MSTMNB(Q3)	;GET STRUCTURE DATA BLOCK ADDRESS
;**;[1926] Change 1891 lines at MSTM92: +5L	JGZ	19-AUG-81
;**;[1891] MAKE CHANGES AT MSTM92: +5L	TAM	12-JUN-81
	ANDCAM T2,DEVCH1(T1)	;[1891] MARK THAT STRUCTURE NOT BEING INITED
	SETZRO STRJB,(T3)	;[1891] ZERO INITING FORK
	HRROS DEVUNT(T1)	;INDICATE STRUCTURE AVAILABLE TO ALL JOBS
	MOVE T3,JOBNO		;[1891] GET OUR JOB NUMBER
	TXNE T4,MS%XCL		;[1891] EXCLUSIVE?
	HRLM T3,DEVUNT(T1)	;[1891] YES, SAVE JOB NUMBER.
	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
	OKINT			;PERMIT INTERRUPTS AGAIN
	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
	OKINT			;PERMIT INTERRUPTS AGAIN
	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 OR LOGICAL NAME TABLES

CKNM20:	HRRZ T1,CKNBLK		;GET ADDRESS OF BLOCK CONTAINING ASCIZ STRING
	CALL DEVLUX		;CHECK DEVICE TABLES
	 SKIPA			;OK, NAME NOT YET IN TABLES
	JRST [ SETOM CKNERR	;NAME IN DEVICE TABLES. SET ERROR FLAG.
		JRST CKNM30]	;GO RELEASE FREE BLOCK AND RETURN ERROR
	MOVE T1,CKNBLK		;GET ADDRESS OF BLOCK CONTAINING ASCIZ NAME
	MOVEI T2,1		;LOOK FOR SYSTEM-WIDE LOGICAL NAME
	CALL LNMLUK
	 JRST CKNM30		;OK, NO SUCH LOGICAL NAME
	SETOM CKNERR		;NAME IS LOGICAL NAME. 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
	JSBVAR <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>
	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
	CALL ASGPAG		;GET PAGE
	JRST [	MOVX T1,MSTX11	;CAN'T INIT INDEX TABLE
		JRST STIER1]
	MOVEM T1,FKXORA		;SET NEW ORIGIN FOR IDXORA
	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,FKXORA		;IDX ORIGIN
	CALL RELPAG		;FREE PAGE
	SETZM FKXORA		;ZERO SPECIAL FORK IDXORA
	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,FKXORA		;IDX ORIGIN
	CALL RELPAG		;FREE PAGE
	SETZM FKXORA		;ZERO SPECIAL FORK IDXORA
	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:
	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
				;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
	RETSKP			;RETURN
MKSDB4:	AOBJN T4,MKSDB2		;GO CHECK NEXT SDB

;[7430]Here if an SDB could not be built

;**;[7430] Replace 2 lines with 4 at MKSDB4: + 4L	JDM	31-Mar-87
	SKIPA T1,[MSTX51]	;[7430]STRUCTURE LIMIT EXCEEDED
MKSDB6:	MOVEI T1,MONX01		;[7430]NO RESIDENT FREE SPACE
	OKSKED			;[7430]PERMIT SCHEDULING AGAIN
	RETBAD ()		;[7430]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
; MSTDME - TEMPORARILY HOLDS ERROR CODE
; MSTDMU - STRUCTURE UNIQUE CODE
; MSTDMT - Text to TTMSG to users who have structure mounted [8861]

;**;[8861] Change 1 line at MSTDIS			GAS	13-Jul-88
MSTDIS:	STKVAR <MSTDMS,MSTDMB,MSTDME,MSTDMU,<MSTDMT,11>> ;[8861]

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

;**;[2965] ADD A LABEL AT MSTDIS:+4L	TAM	23-MAY-83
MSTD00:	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
;**;[2960]Add 6 lines at MSTDIS: +26L	RWW	10-MAY-83
	MOVE	T2,T1		;[2960]copy structure number
	ADDI	T2,DEVCH1+DVXST0 ;[2960]compute address in DEVCH1
	MOVE	T3,(T2)		;[2960]get device chearacterists
	TXNE	T3,D1%INI	;[2960]device begin initialized?
	 JRST	[MOVX	T1,MSTX43 ;[2960]Note error
		JRST	MSDER1]	;[2960]return +1
	MOVE T2,STRTAB(T1)	;GET ADDRESS OF SDB FOR THIS STRUCTURE
	MOVEM T2,MSTDMB		;SAVE ADDRESS OF SDB
	MOVE T1,MSTDMS		;GET STRUCTURE NUMBER
	CALL STRCNV		;GET UNIQUE CODE FOR THIS STRUCTURE
	 JFCL			;CANNOT FAIL WHILE STRUCTURE IS LOCKED
	MOVEM T1,MSTDMU		;STORE STRUCTURE UNIQUE CODE
	; ..
	; ..

;**;[8861] Replace 8 lines with 17 lines at MSTD00+34	GAS	13-Jul-88
;[8861] Create advisory message to TTMSG to users

	MOVEI T1,MSTDMT		;[8861] Point to place to construct message
	HRLI T1,(POINT 7)	;[8861] Make a byte pointer to it
	MOVE T2,[POINT 7,[ASCIZ/[Structure /]] ;[8861] Point to initial string
	CALL MSTASC		;[8861] (T1,T2/T1) Copy that first
	MOVE T2,MSTDMS		;[8861] Load structure number
	CALL MSTOUT		;[8861] (T1,T2/T1) Append that to the string
	MOVE T2,[POINT 7,[ASCIZ/ has been dismounted]
/]]				;[8861] Finish up the message
	CALL MSTASC		;[8861] (T1,T2/T1) Copy that to finish up

;[8861] Call routine to purge structure from all jobs and notify users.

	MOVE T1,MSTDMU		;GET STRUCTURE UNIQUE CODE
	MOVEI T2,MSTDMT		;[8861] Point to notification message
	CALL FIXJOB		;(T1,T2/) Go fix JSBs 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.

;**;[2965]REWRITE MSTD10:	TAM	23-MAY-83
MSTD10:	CALL LCKDVL		;[2965] LOCK THE DEVICE TABLE LOCK
	LOCK STRLOK,<JRST MSTD11> ;[2965] LOCK DISMOUNT 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 STRLOK		;[2965]
	UNLOCK DEVLCK		;[2965] UNLOCK THE DEVICE TABLE LOCK
	OKINT			;[2965] UNDO NOINT (FROM FNDSTR)
	MOVE T1,MSTDMS		;[2965] GET STRUCTURE NUMBER
	CALL ULKSTR		;[2965] UNLOCK THE STRUCTURE WHILE WE WAIT
	OKSKED			;[2965] OK FOR OTHERS TO RUN NOW
	HRLZ T1,MSTDMS		;[2965] SET UP FOR SCHEDULER TEST - STR NUMBER
	HRRI T1,STRTST		;GO OKSKED AND WAIT UNTIL THE LOCK BECOMES FREE
	MOVEI T2,^D200		;[2965] HOLD TIME
	HDISMS			;[2965] BYE BYE
	JRST MSTD00		;[2965] START OVER

; HERE WHEN WE CAN'T GET BOTH THE DEVICE AND STRUCTURE LOCKS

MSTD11:	UNLOCK DEVLCK		;[2965] UNLOCK THE DEVICE TABLE LOCK
	OKINT			;[2965] UNDO NOINT FROM FNDSTR
	MOVE T1,MSTDMS		;[2965] GET STRUCTURE NUMBER
	CALL ULKSTR		;[2965] UNLOCK THE STRUCTURE
	MOVEI T1,^D200		;[2965] WAIT FOR A LITTLE BIT
	DISMS			;[2965]
	JRST MSTD00		;[2965] AND START OVER

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

	RESCD
;**;[2965]REWRITE STRTST:	TAM	23-MAY-83
STRTST:	SKIPN T2,STRTAB(T1)	;[2965] GET SDB ADDRESS IF ANY
	JRST 1(4)		;[2965] NONE. ALREADY GONE
	JE STRLK,(T2),1(4)	;[2965] FREE, SUCCEED
	JRST 0(4)		;LOCK STILL INCREMENTED, FAIL
	SWAPCD

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

MSTD20:	MOVE T2,MSTDMB		;[2965] 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
	UNLOCK STRLOK		;RELEASE DISMOUNT LOCK AS WELL
	; ..
	; ..

; 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
;**;[1966] Delete 3 (1956) lines at MSTD50:-5l	PED	10-DEC-81
	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
;**;[2965] ADD 1 LINE AT MSTD50:+1L	TAM	23-MAY-83
	OKINT			;[2965] UNDO NOINT FROM FNDSTR
	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

	TRVAR <MSTHDR,<MSTRPC,3>>
	MOVEI T3,4		;LENGTH OF ARG BLOCK
	HRLI T3,.IPCRS		;SET UP STR REMOVAL CODE
	MOVEM T3,MSTHDR
	SETO T3,
	HLLZM T3,MSTRPC		;SET JOB NUMBER TO -1 & MOUNT COUNT TO 0
	MOVE T1,MSTDMU		;GET STRUCTURE UNIQUE CODE
	MOVEM T1,1+MSTRPC
	CALL LGTAD		;GET TIME AND DATE
	MOVEM T1,2+MSTRPC
	CALL DISMES		; THAT STRUCTURE IS BEING DISMOUNTED
	 JFCL			;FAILED

;RETURN TO USER

	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
;**;[2644] ADD 1 LINE AT MSTRLO:+6L	TAM	4-AUG-82
	SKIPE T1		;[2644]SKIP IF NONE
	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
;[8861]	    T2/	Address of ASCIZ "[Structure NAME dismounted]" message
;		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		;[8861] Save address of notification 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),FXJB25	;WAS THIS STRUCTURE MOUNTED ?
	SETOM P3		;YES, MARK THAT A MESSAGE IS NEEDED
	SETZRO <JSMCI,JSXCL>,(T2) ;CLEAR STATUS FLAGS
	;..

; CHECK IF ANY FORKS HAD STRUCTURE MOUNTED

FXJB25:	JE JSFMT,(T2),FXJB30	;DID FORK MOUNT STRUCTURE
	SETOM P3		;YES, MARK THAT A MESSAGE IS NEEDED
	SETZM JSFKMT(T2)	;ZERO FORK USERS

; 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
;**;[8861] Replace 10 lines with 3 at FXJB50+9		GAS	13-Jul-88
;**;[7190] Replace 7 lines with 9 at FXJB50+10		CEG 12-Nov-85
	HRRO T2,FXJOBN		;[8861] Get pointer to ASCIZ message
	TTMSG%			;[8861] Output structure name
	 ERJMP .+1		;[8861] Ignore error for now

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
	CAML T1,[-2]		;IS CHANNEL NUMBER IN LEGAL RANGE?
	CAIL T1,CHNN
	 RETBAD (MSTX14)	;NO, RETURN INVALID CHANNEL NUMBER
	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
	CAML T1,[-2]		;IS IT IN LEGAL RANGE?
	CAIL T1,MAXRH
	 RETBAD (MSTX15)	;NO, RETURN ERROR
	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
;**;[7216] Change 2 lines at MSTRS4+31	CEG 23-Dec-85
	SKIPN T1		;[7216] EVERYTHING OK?
	TXO P3,MS%HBB		;[7216] NO, BAD HOME 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
	XCTU [HLRZ T1,1]	; GET ARG BLK LENGTH
	CAIGE T1,.MSRSN+1	; DOES ARG BLK HAVE .MSRSN WORD?
	  JRST MSTRS7		; NO! SKIP STR NAME STRING XFER
	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

MSTRS7:	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

	HRRZ T1,MSTRSS		;GET STRUCTURE NUMBER
	CAIN 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
	LSH T1,-2		;CONVERT TO PAGES
	LOAD T3,STRNUM,(T2)	;GET NUMBER OF UNITS IN STRUCTURE
	IMUL T1,T3		;NUMBER OF SWAPPING PAGES ON STRUCTURE
	MOVEM T1,.MSRSW(P2)	;SAVE NUMBER OF SWAPPING SECTORS
	XCTU [HLRZ T1,1]	; GET ARG BLK SIZE
	CAIGE T1,.MSRSA+1	; DOES IT HAVE .MSRSA WORD
	  JRST MSTRS6		; NO- SKIP ALIAS STRING XFER
	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 BLTMU1		;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!MS%NRS

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!MS%NRS>> ;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 --

;**;[2856]CHANGE 1 LINE AT MSGMSK==+0L	TAM	3-NOV-82
MSGMSK==MS%INI!MS%PPS!MS%DIS!MS%DOM!MS%NRS!MS%LIM!MS%PS

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 ?
;**;[2856]CHANGE 1 LINE AT MSTGSS:+25L	TAM	3-NOV-82
	TXO P3,MS%PPS!MS%PS!MS%NRS ;[2856] 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 BLTMU1		;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

;ACCEPTS: SAME AS .MSTR

;RETURNS +1: FAILED, ERROR CODE IN AC1
;	 +2: SUCCEEDED
;REGISTER USAGE:
;	P1/ ADDRESS OF USER'S ARGUMENT BLOCK
;	P2/ STRUCTURE NUMBER
;	P3/ STRUCTURE UNIQUE CODE
;	P4/ JOB NUMBER
;	P5/ JSB OFFSET


MSTIMC:	TDZA T1,T1		;MARK THAT COUNT SHOULD BE INCREMENTED
MSTDMC:	SETOM T1		;MARK THAT COUNT SHOULD BE DECREMENTED
	ASUBR <MSTMCF>
	STKVAR <<MSTDMT,11>>	;[8861] Place to construct notification string

; CHECK SIZE OF USER ARGUMENT BLOCK

	XCTU [HLRZ P4,1]	;GET SIZE OF USER ARGUMENT BLOCK
	CAIGE P4,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,P3		;SAVE UNIQUE CODE
	HRLI T1,.DVDES+.DVDSK	;SET DEVICE DESIGNATOR
;**;[1797] Change one line at MSTDMC: +20L	JGZ	7-OCT-80
	GTOKM (.GOSMT,<T1>,MCTNOK) ;[1797] GETOK FOR MOUNT/DISMOUNT

;CHECK IF USER WANTS TO CHANGE MOUNT COUNT FOR ANOTHER JOB

	SETZ P5,		;SET JSB OFFSET TO ZERO
	CAILE P4,.MSJOB		;HAS ANOTHER JOB BEEN SPECIFIED
	JRST [ CALL MSTJOB	;YES, SEE IF VALID (OFFSET TO JSB IN T1)
		JRST MCTERR	;NOT A VALID REQUEST
		MOVE P5,T1	;STORE JSB OFFSET
		MOVE P4,T2	;SAVE JOB NUMBER
		JRST .+1]
	SKIPN P5		;IF THERE IS NO JSB OFFSET
	MOVE P4,JOBNO		; SET JOB NUMBER TO BE 'THIS JOB'

		; ...
		; ...

; INCREMENT OR DECREMENT THE MOUNT COUNT AS APPROPRIATE

	LOCK JSSTLK(P5)		;LOCK THE STRUCTURE INFO LOCK IN THE JSB
	MOVE T1,P3		;GET UNIQUE CODE AGAIN
	MOVE T2,P5		;GET OFFSET TO JSB
	CALL GTSTOJ		;GET OFFSET FOR THIS STRUCTURE IN JSB
;**;[1772] Revamp [1750/53] lines at MSTDMC: +44L	JGZ	28-AUG-80
;**;[1750] Change error ret at MSTDMC+44 l  RAS  25-JUN-80
	 JRST [	UNLOCK JSSTLK(P5) ;[1750] Unlock the STR Info lock
;**;[1753] Fix emacs ripoff at MSTDMC: +46L	RAS	26-JUN-80
		JRST MCTERR]	;[1750] Unlock the STR and return error
	MOVE T1,P2		;GET STRUCTURE NUMBER AGAIN
	MOVE T3,P4		;GET JOB # FOR WHICH THIS IS BEING DONE
	MOVE T4,MSTMCF		;GET INCREMENT/DECREMENT FLAG
	ADDI T4,1		;FORM OFFSET TO PROPER CALL INSTRUCTION
	XCT [CALL DECMNC	;GO INCREMENT THE MOUNT COUNT
	     CALL INCMNC](T4)	;GO DECREMENT THE MOUNT COUNT
	 JRST [	UNLOCK JSSTLK(P5) ;UNLOCK THE JSB STRUCTURE LOCK
		JRST MCTERR ]	;GO UNLOCK STRUCTURE AND RETURN ERROR
	MOVE T1,P3		;GET UNIQUE CODE AGAIN
	MOVE T2,P5		;GET JSB OFFSET AGAIN
	CALL FRJSSO		;FREE JSB STR STORAGE IF NOW UNUSED
	UNLOCK JSSTLK(P5)	;UNLOCK THE STRUCTURE INFO LOCK
	MOVE T1,P2		;GET THE STRUCTURE NUMBER
	CALL ULKSTR		;UNLOCK THE STRUCTURE
	SKIPN P5		;WAS THIS WORK FOR SOMEONE ELSE
	RETSKP			;NO, RETURN
	CALL CLRJSB		;UNMAP THE OBJECT JSB
;**;[8861] Add 15 lines at MSTDMC+63			GAS	13-Jul-88
;[8861] Construct notification message to send to user whose work was done.

	MOVEI T1,MSTDMT		;[8861] Point to place on stack to construct 
	HRLI T1,(POINT 7)	;[8861]  the message we send to user
	MOVE T2,[POINT 7,[ASCIZ/
[/]]				;[8861] Start message with CRLF and bracket
	CALL MSTASC		;[8861] (T1,T2/T1) Call quick string copy rtn
	MOVE T2,P2		;[8861] Get structure number
	CALL MSTOUT		;[8861] (T1,T1/T1) Insert structure name 
	SKIPE MSTMCF		;[8861] Structure being mounted or dismounted?
	SKIPA T2,[POINT 7,[ASCIZ / Dismounted]
/]]				;[8861] It was just dismounted
	MOVE T2,[POINT 7,[ASCIZ / Mounted]
/]]				;[8861] It was just mounted
	CALL MSTASC		;[8861] (T1,T2/T1) Finish up the string

	HLRE T1,JOBPT(P4)	;GET TTY OF OBJECT JOB
	SKIPGE T1		;IS IT DETACHED?
	RETSKP			;YES, FORGET MESSAGE

;SEND MESSAGE OF STRUCTURE MOUNT TO TTY, IF DONE TO ANOTHER JOB

;**;[7190] Replace 5 lines with 5 at MCTNOK-18		CEG 12-Nov-85
	TXO T1,.TTDES		;[7190] MAKE LINE NUMBER INTO DESIGNATOR
;**;[8861] Replace 12 lines with 1 at MSTNOC-8		GAS	13-Jul-88
	HRROI T2,MSTDMT		;[8861] Point to the text string we just built
	TTMSG%			;[7190] 
	 ERJMP .+1		;[7190] 
	RETSKP			;SUCCESSFUL RETURN

;**;[1797] Add 5 lines at MCTERR: -2L	JGZ	7-OCT-80
;[1797] HERE IF GETOK FAILS

MCTNOK:	CALL MCTERR		;[1797] CLEAN UP LOOSE ENDS, UNLOCK STR
	ITERR ()		;[1797] AND RETURN ERROR

; HERE ON AN ERROR

MCTERR:	EXCH P2,T1		;SAVE ERROR CODE, GET STRUCTURE NUMBER
	CALL ULKSTR		;UNLOCK THE STRUCTURE
	SKIPE P5		;WAS THIS WORK FOR SOMEONE ELSE?
	CALL CLRJSB		;YES, CLEAR MAPPED JSB
	MOVE T1,P2		;RESTORE THE ERROR CODE
	RETBAD ()			;RETURN ERROR TO USER
	ENDSV.			;[8861] End of STKVAR
;MSTJOB - ROUTINE TO SET UP MOUNT COUNT CHANGE FOR ANOTHER JOB
;
;ACCEPTS:
;	P1/ ADDRESS OF USER'S ARGUMENT BLOCK
;	CALL MSTJOB
;RETURNS: +1	FAILED, ERROR CODE IN T1
;	  +2	SUCCESS, JSB STRUCTURE FOR OTHER JOB SET UP
;			T1/ OFFSET TO JSB OR ZERO FOR THIS JOB
;			T2/ JOB #

MSTJOB:	STKVAR<MSTT2>
	UMOVE T1,.MSJOB(P1)	;GET JOB # FOR WHICH THIS IS TO BE DONE
	CAME T1,[-1]		;DID USER SPECIFY 'THIS JOB'
	CAMN T1,JOBNO		; OR JOB # SAME AS USER'S?
	JRST [ MOVE T2,T1	;YES, GET JOB # IN T2
		SETZ T1,	; THERE IS NO JSB OFFSET
		RETSKP]
	MOVE T2,CAPENB		;GET ENABLED CAPABILITIES
	TXNN T2,SC%WHL!SC%OPR	;WHEEL OR OPERATOR?
	RETBAD (CAPX1)		;NO. REQUIRED FOR THIS FUNCTION
;**;[1925] Change 1828 lines at MSTJOB: +10L	JGZ	19-AUG-81
;**;[1828] Add three lines at MSTJOB: +10L	RAS	21-JAN-81
	CAIGE T1,NJOBS		;[1825] IS JOB NUMBER VALID?
	SKIPGE T1		;[1825] ...
	 RETBAD (ARGX07)	;[1825] NO, RETURN ERROR
	MOVEM T1,MSTT2		;STORE JOB NUMBER
	CALL MAPJSB		;MAP JOB'S JSB (OFFSET IN T1)
;**;[1925] Change 1828 lines at MSTJOB: +12L	JGZ	19-AUG-81
;**;[1828] Change one line at MSTJOB: +12L	RAS	21-JAN-81
	 RETBAD	(ARGX08)	;[1825] JOB DOESN'T EXIST
	MOVE T2,MSTT2
	RETSKP			;SUCCESS
;INCMNT - ROUTINE TO INCREMENT THE MOUNT COUNT FOR A STRUCTURE
;
;ACCEPTS IN T1/	STRUCTURE NUMBER
;	    T2/ OFFSET TO JSB DATA FOR THIS STRUCTURE
;	    T3/ JOB # FOR WHICH INCREMENT BEING DONE(IF CALLING INCMNC)
;		CALL INCMNT/INCMNC
;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::MOVE T3,JOBNO		;INCREMENT FOR THIS JOB
INCMNC:	JN JSMCI,(T2),[RETBAD (MSTX31)]	;YES, RETURN IF ALREADY INCREMENTED BY THIS JOB
	MOVE T4,STRTAB(T1)	;GET ADDRESS OF STRUCTURE DATA BLOCK TO THIS STR
	JE STDIS,(T4),INCMN2	;IS STRUCTURE BEING DISMOUNTED ?
	RETBAD (MSTX33)		;YES, ALLOW NO FURTHER INCREMENTS
INCMN2:				;DON'T PERMIT INTERRUPTS WHEN CHANGING DATA BASE
	NOSKED			;MUST CHANGE JSB AND SDB "SIMULTANEOUSLY"
	SETONE JSMCI,(T2)	;MARK THAT COUNT HAS BEEN INCREMENTED
	JN JSFMT,(T2),INCMN3	;HAS A FORK ALREADY INCREMENTED COUNT
	INCR STRMC,(T4)		;BUMP THE MOUNT COUNT
	MOVE T1,T4		;SET UP SDB FOR CALL TO DISMES
	SETZ T4,		;SET FLAG THAT MESSAGE NEEDS TO BE SENT
INCMN3:	OKSKED			;BOTH CHANGED, PERMIT SCHEDULING AGAIN
	JUMPN T4,RSKP		;DOES A MESSAGE NEED TO BE SENT?
	SUBI T2,JSSTRT		;SET UP T2 TO CONTAIN THE JSB OFFSET
	TRZ T2,777
	CALL SNDUSG		;YES, SEND USAGE INFO TO DEVICE ALLOCATOR
	RETSKP			;RETURN SUCCESS
;DECMNC - ROUTINE TO CHECK LEGALITY OF DECREMENTING COUNT
;	  AND CALL DECMNT, IF LEGAL
;
;ACCEPTS IN T1/ STRUCTURE NUMBER
;	    T2/ OFFSET TO JSB DATA FOR THIS STRUCTURE
;	    T3/ JOB # FOR WHICH DECREMENT BEING DONE
;	    P3/ STRUCTURE UNIQUE CODE
;	    P5/ OFFSET TO JSB OBTAINED FROM SETJSB
;		CALL DECMNC
;RETURNS: +1	FAILED, ERROR CODE IN T1
;	  +2	SUCCESS, DECREMENT LEGAL AND DONE
;
;NOTE: STRUCTURE MUST BE LOCKED DURING THIS ROUTINE

;A USER IS PROHIBITED FROM DOING THE DECREMENT FUNCTION IF HE IS STILL
;CONNECTED TO THE STRUCTURE, OR IF ANY JFN'S ARE STILL IN USE FOR THAT
;STRUCTURE

DECMNC:	JUMPE T1,DECCAL		;FORGET CHECK IF THIS IS PS
	MOVE T4,STRTAB(T1)	;IS THIS STRUCTURE PUBLIC?
	JN STPS,(T4),DECCAL	;SKIP CHECKING IF STRUCTURE IS PUBLIC
	JN STNRS,(T4),DECCAL	; OR IF STRUCTURE IS NOT REGULATED
	LOAD T4,JSUC,(P5)	;GET CONNECTED STR UNIQUE CODE
	CAMN T4,P3		;IS STR BEING DECREMENTED SAME?
	RETBAD (MSTX37)		;YES, RETURN
	LOCK JFNLCK(P5)		;LOCK JFN'S WHILE CHECKING DEVICES
	MOVN T4,MAXJFN(P5)	;GET # OF USED JFN'S
	JUMPE T4,DECMN2		;JUMP IF NONE USED
	HRLZ T4,T4		;SET UP INDEX TO JFN'S
	HRR T4,P5		;GET JSB OFFSET
	STKVAR <MSTT3>
	MOVEM T3,MSTT3		;SAVE JOB #
DECMN1:	LOAD T3,STR,(T4)	;GET JFN'S STRUCTURE CODE
	SKIPE FILSTS(T4)	;JFN in use?
	CAME T3,T1		;yes, is it this structure?
	SKIPA			;no to either, OK
	JRST [ UNLOCK JFNLCK(P5) ;YES, UNLOCK JFN'S
		RETBAD (MSTX36)]  ; AND RETURN
	ADDI T4,MLJFN-1		;GET NEXT JFN BLOCK
	AOBJN T4,DECMN1		;CHECK NEXT JFN
	MOVE T3,MSTT3		;RESTORE JOB #
DECMN2:	CALL DECMNT		;DO ACTUAL DECREMENT
	 JRST [ UNLOCK JFNLCK(P5)
		RETBAD]
	UNLOCK JFNLCK(P5)	;PERMIT MODIFICATION OF JFN'S
	RETSKP			;SUCCESSFUL RETURN

;CALL DECMNT WITHOUT UNLOCKING JFNLCK AT FINISH

DECCAL:	CALL DECMNT		;DO ACTUAL DECREMENT
	RETBAD
	RETSKP			;SUCCESS
;DECMNT - ROUTINE TO DECREMENT THE MOUNT COUNT FOR A STRUCTURE
;
;ACCEPTS IN T1/	STRUCTURE NUMBER
;	    T2/ OFFSET TO JSB DATA FOR THIS STRUCTURE
;	    T3/ JOB # FOR WHICH DECREMENT BEING DONE
;		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 T4,STRTAB(T1)	;GET ADDRESS OF STRUCTURE DATA BLOCK
	NOINT			;DO NOT PERMIT INTERRUPTS
	NOSKED			;JSB AND SDB MUST BE CHANGED "SIMULTANEOUSLY"
	SETZRO JSMCI,(T2)	;MARK THAT MOUNT COUNT CAN BE INCREMENTED AGAIN
	JN JSFMT,(T2),DECM1	;DOES A FORK STILL HAVE STR MOUNTED
	DECR STRMC,(T4)		;NO, DECREMENT THE MOUNT COUNT
	MOVE T1,T4		;SET UP SDB FOR CALL TO DISMES
	SETZ T4,		;SET FLAG SAYING MESSAGE NEEDED
DECM1:	OKSKED			;BOTH CHANGED, PERMIT SCHEDULING AGAIN
	JUMPN T4,DECM2		;IS A MESSAGE NEEDED?
	MOVE T2,T3		;GET JOB NUMBER IN T2
	CALL SNDEND		;TELL DEVICE ALLOCATOR OF DECREMENT
DECM2:	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
; .MSICF/.MSDCF - INCREMENT/DECREMENT MOUNT COUNT FOR FORK

;ACCEPTS: SAME AS .MSTR

;RETURNS +1: FAILED, ERROR CODE IN AC1
;	 +2: SUCCEEDED
;REGISTER USAGE:
;	P1/ STRUCTURE UNIQUE CODE
;	P2/ STRUCTURE NUMBER

MSTICF: TDZA T1,T1		;MARK THAT COUNT SHOULD BE INCREMENTED
MSTDCF:	SETOM T1		;MARK THAT COUNT SHOULD BE DECREMENTED
	ASUBR<MSTCF>

;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 STURCTURE IS MOUNTED

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

;INCREMENT OR DECREMENT THE MOUNT COUNT AS APPROPRIATE

	LOCK JSSTLK		;LOCK THE STRUCTURE INFOR LOCK IN JSB
	CALL GTSTOF		;GET OFFSET FOR THIS STRUCTURE IN JSB
;**;[1750} Change error return at MSTDFC+15L  RAS  25-JUN-80
	 JRST [	UNLOCK JSSTLK	; Unlock the STR Info block
		JRST MCTERR]	; Unlock the Structure and ret Error
	MOVE T1,P2		;GET STRUCTURE NUMBER AGAIN
	MOVE T4,MSTCF		;GET INCREMENT/DECREMENT FLAG
	ADDI T4,1		;FORM OFFSET TO PROPER CALL INSTRUCTION
	XCT [ CALL DECFC	;GO DECREMENT FORK MOUNT COUNT
	      CALL INCFC](T4)	;GO INCREMENT FORK MOUNT COUNT
	 JRST [ UNLOCK JSSTLK	;UNLOCK THE JSB STRUCTURE LOCK
		JRST MCTERR]	;GO UNLOCK STRUCTURE AND RETURN ERROR
	MOVE T1,P1		;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
;INCFC - ROUTINE TO INCREMENT STRUCTURE MOUNT COUNT FOR A FORK
;
;ACCEPTS IN T1/ STRUCTURE NUMBER
;	    T2/ OFFSET TO JSB DATA FOR THIS STRUCTURE
;	CALL INCFC
;RETURNS: +1	FAILED, ERROR CODE IN T1
;	  +2	SUCCESS, COUNT INCREMENTED IF NOT PREVIOUSLY INCREMENTED
;			 BY THIS FORK.
;
;NOTE: STRUCTURE MUST BE LOCKED DURING THIS ROUTINE

INCFC:	STKVAR<INCF1,INCF2>
	MOVE T4,STRTAB(T1)	;GET ADDRESS OF STRUCTURE DATA BLOCK
				; TO THIS STR
	JE STDIS,(T4),INCFC2	;IS STRUCTURE BEING DISMOUNTED?
	RETBAD (MSTX33)		;YES, ALLOW NO FURTHER INCREMENTS
INCFC2:	MOVEM T2,INCF1		;SAVE JSB OFFSET
	MOVEM T4,INCF2		;SAVE SDB ADDRESS
	CALL FRKSTO		;SEE IF FORK ALREADY MOUNTED STRUCTURE
	 SKIPA			;NO, CONTINUE
	RETBAD (MSTX31)		;FINDING STRUCTURE IS ERROR
	MOVE T2,INCF1		;RESTORE JSB OFFSET
	MOVE T4,INCF2		;RESTORE SDB ADDRESS

;SET MOUNT FOR THIS FORK, AND INCREMENT SYSTEM MOUNT COUNT IF NOT DONE
; BY THIS JOB PREVIOUSLY

				;DON'T PERMIT INTERRUPTS WHEN CHANGING
				; DATA BASE
	NOSKED			;MUST CHANGE SDB,JSB "SIMULTANEOUSLY"
	JN JSFMT,(T2),INCF4	;SKIP SDB INCREMENT IF FORK FLAG ALREADY SET
	JN JSMCI,(T2),INCF4	;SKIP SDB INCREMENT IF JOB FLAG SET
	INCR STRMC,(T4)		;BUMP SDB MOUNT COUNT
	SETZ T4,		;MARK THAT WE NEED TO SEND MSSG
INCF4:	MOVEM T1,INCF1		;STORE STRUCTURE NUMBER
	MOVE T1,FORKN		;GET JOB RELATIVE FORK NUMBER
	MOVEI T3,1		;SET UP MASK FOR SETTING FORK
	LSH T3,(T1)		; MOUNT IN STRUCTURE
	MOVE T1,JSFKMT(T2)	;GET FORK MOUNT FLAG WORD
	TDO T1,T3		;SET THIS STRUCTURE IN USE
	MOVEM T1,JSFKMT(T2)	; AND REPLACE IN JSB
	INCR NOSTR		;INCREMENT NUMBER OF STRUCTURES MOUNTED

;IF INCREMENTING SYSTEM MOUNT COUNT WAS DONE, SEND MSSG TO MDA

	OKSKED			;PERMIT SCHEDULING AGAIN
	JUMPN T4,RSKP		;SKIP SENDING MSSG IF SDB NOT INCREMENTED
	MOVE T1,INCF2		;RESTORE STRUCTURE NUMBER
	MOVE T3,JOBNO		;GET OUR JOB NUMBER
	SUBI T2,JSSTRT		;SET UP T2 TO CONTAIN THE JSB OFFSET
	TRZ T2,777
	CALL SNDUSG		;SEND A MESSAGE TO THE DEVICE ALLOCATOR
	RETSKP			;RETURN SUCCESS
;DECFC - ROUTINE TO DECREMENT MOUNT COUNT FOR A FORK
;
;ACCEPTS IN T1/ STRUCTURE NUMBER
;	    T2/ OFFSET TO JSB DATA FOR THIS STRUCTURE
;	CALL DECFC
;RETURNS: +1	FAILED, ERROR CODE IN T1
;	  +2	SUCCESS, DECREMENT DONE
;
; NOTE: STRUCTURE MUST BE LOCK DURING THIS ROUTINE

;A USER IS PROHIBITED FROM DOING THIS FUNCTION IF ANY JFN'S FOR THIS
;FORK ARE FROM THE STRUCTURE

DECFC:	STKVAR<DECF1>
	JUMPE T1,DECFC3		;FORGET CHECK IF THIS IS PS
	MOVE T4,STRTAB(T1)	;IS THIS STRUCTURE PUBLIC?
	JN STPS,(T4),DECFC3	;SKIP CHECKING IF STRUCTURE IS PUBLIC
	LOCK JFNLCK		;LOCK JFN'S WHILE CHECKING DEVICES
	MOVN T4,MAXJFN		;GET # OF USED JFN'S
	JUMPE T4,DECFC2		;JUMP IF NONE USED
	HRLZ T4,T4		;SET UP INDEX TO JFN'S
	MOVEM T2,DECF1		;SAVE OFFSET
	HRRZ T2,FORKN		;GET THIS FORK NUMBER RELATIVE TO JOB
DECFC1:	LOAD T3,STR,(T4)	;GET JFN'S STRUCTURE CODE
	CAMN T3,T1		;IS IT THIS STRUCTURE?
	JRST [ LOAD T3,ORG,(T4)
		CAME T3,T2	;DOES IT BELONG TO THIS FORK
		JRST .+1	;NO, CONTINUE
		UNLOCK JFNLCK	;YES, UNLOCK JFN'S
		RETBAD (MSTX36)] ; AND RETURN
	ADDI T4,MLJFN-1		;GET NEXT JFN BLOCK
	AOBJN T4,DECFC1		;CHECK NEXT JFN
	MOVE T2,DECF1		;GET OFFSET TO JSB DATA
DECFC2:	CALL DECFMC		;DO DECREMENT
	 JRST [UNLOCK JFNLCK
		RETBAD]
	UNLOCK JFNLCK		;PERMIT MODIFICATION OF JFN'S
	RETSKP			;SUCCESSFUL RETURN

;CALL DECFMC WITHOUT UNLOCKING JFNLCK AT FINISH

DECFC3:	CALL DECFMC		;DO DECREMENT
	RETBAD
	RETSKP			;SUCCESS
;DECFMC - ROUTINE TO DECREMENT STRUCTURE MOUNT COUNT FOR A FORK
;
;ACCEPTS IN T1/ STRUCTURE NUMBER
;	    T2/ OFFSET TO JSB DATA FOR THIS STRUCTURE
;	CALL DECFMC
;RETURNS: +1	FAILED, ERROR CODE IN T1
;	  +2	SUCCESS, MOUNT COUNT DECREMENT IF PREVIOUSLY INCREMENTED
;		T1 AND T2 RETURN UNCHANGED
;
; NOTE: STRUCTURE MUST BE LOCKED DURING THIS ROUTINE

;THIS ROUTINE IS CALLED FROM THE MSTR JSYS AND THE KSELF CODE

DECFMC::ASUBR<DEC1,DEC2>
	JE JSFMT,(T2),[RETBAD (MSTX32)] ;RETURN IF NEVER INCREMENTED
	CALL FRKSTO		;SEE IF THIS FORK INCREMENTED COUNT
	 RETBAD (MSTX32)	;NO
	MOVE T2,DEC2		;RESTORE JSB OFFSET
	MOVEI T1,1		;SET UP MASK TO REMOVE STR FROM FORK
	MOVE T3,FORKN		;GET RELATIVE JOB FORK NUMBER
	LSH T1,(T3)
	MOVE T4,DEC1		;RESTORE STRUCTURE #
	MOVE T4,STRTAB(T4)	; IN ORDER TO GET ADDRESS OF SDB
	MOVEM T4,DEC1		;STORE SDB ADDRESS
	NOINT			;DO NOT PERMIT INTERRUPTS
	NOSKED			;JSB,SDB CHANGED SIMULTANEOUSLY
	MOVE T3,JSFKMT(T2)	;GET FORK FLAG WORD
	TDZ T3,T1		;REMOVE FORK
	MOVEM T3,JSFKMT(T2)	;PLACE WORD INTO JSB AGAIN
	DECR NOSTR		;DECREMENT NUMBER OF STRUCTURES MOUNTED
	JUMPN T3,DECFM1		;DO ANY MORE FORKS HAVE STR MOUNTED
	JN JSMCI,(T2),DECFM1	;NO, IS THERE A JOB-WIDE MOUNT IN EFFECT
	DECR STRMC,(T4)		;NO, DECREMENT SDB MOUNT COUNT
	SETZ T4,		;INDICATE A MESSAGE IS NEEDED
DECFM1:	OKSKED			;ALL CHANGED, PERMIT SCHEDULING AGAIN
	JUMPN T4,DECFM2		;SKIP MESSAGE IF NOT NEEDED
	MOVE T1,DEC1		;RESTORE STRUCTURE NUMBER
	MOVE T2,JOBNO		;GET OUR JOB NUMBER
	CALL SNDEND		;SEND A MESSAGE TO THE DEVICE ALLOCATOR
DECFM2:	DMOVE T1,DEC1
	OKINT			;PERMIT INTERRUPTS AGAIN
	RETSKP			;RETURN SUCCESS
;MSTOFL - ROUTINE TO ENABLE ONLINE/OFFLINE PSI INTERRUPTS

MSTOFL:	MOVX T1,SC%WHL!SC%OPR	;CHECK PRIVS
	TDNN T1,CAPENB
	RETBAD (CAPX2)		;NOT ENOUGHT CAPABILITIES
	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 CHANNEL IS VALID

	UMOVE T1,2		;GET ADDRESS OF USER'S ARGUMENT BLOCK
	UMOVE T1,.MSCHN(T1)	;GET CHANNEL NUMBER FOR INTERRUPTS
	CAMN T1,[-1]		;CHECK FOR -1 (CLEAR)
	JRST [ SETZM DSPSFK	;CLEAR PSI
		RETSKP]		;QUIT
	CAIL T1,0		;CHECK THAT GIVEN PSI CHANNEL IS
	CAILE T1,5		; ASSIGNABLE CHANNEL
	JRST [ CAIL T1,^D24	;CONTINUE CHECKING
		CAILE T1,^D35
		RETBAD (MSTX40)	;BAD PSI CHANNEL NUMBER GIVEN
		JRST .+1]	;PSI CHANNEL OK

;SET UP INTERRUPT WORD IN STG

	HRRM T1,DSPSFK		;SAVE PSI
	MOVE T1,FORKX		;GET FORK NUMBER
	HRLM T1,DSPSFK		;SAVE FORK NUMBER
	RETSKP			;SUCCESS RETURN

;KSELF CONTAINS CODE TO CLEAR INTERRUPT WORD WHEN FORK DIES
;MSTIIC - ROUTINE TO SET PSB FLAG BIT TO IGNORE MOUNT COUNT CHECK

MSTIIC:	MOVX T1,SC%WHL!SC%OPR	;CHECK PRIVS
	TDNN T1,CAPENB
	RETBAD (CAPX2)		;NOT ENOUGH CAPABILITIES
	LOAD T1,STRFLG		;GET STRUCTURE FLAGS
	TRO T1,ST%IMC		;SET IGNORE MOUNT COUNT FLAG
	STOR T1,STRFLG		;STORE FLAGS
	RETSKP
; 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
;**;[7359]  Replace 2 lines with 1 at MSTRHB:+21	DML	25-Aug-86
		SKIPL RHBERR	;[7359] Was unit offline?
		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
;
;ACCEPTS IN T1/	SIXBIT "NAME"
;	    T2/	ADDRESS OF DESTINATION FOR ASCIZ STRING
;		CALL SIXASC
;RETURNS: +1	ALWAYS

SIXASC::MOVEI T3,-1(T2)		;GET ADDRESS PRECEDING DESTINATION
	HRLI T3,(POINT 7,0,35)	;FORM IDPB POINTER TO DESTINATION
	MOVE T2,T1		;COPY SIXBIT NAME
	MOVSI T4,-6		;GET MAX # OF CHARACTERS TO CONVERT
SIXAS1:	SETZM T1		;INITIALIZE WORK AC
	LSHC T1,6		;GET ONE SIXBIT CHARACTER
	JUMPE T1,SIXAS2		;IF END OF NAME GO DEPOSIT A NULL
	ADDI T1,"A"-'A'		;CONVERT CHARACTER TO ASCII
	IDPB T1,T3		;STORE CHARACTER IN DESTINATION
	AOBJN T4,SIXAS1		;LOOP OVER ALL CHARACTERS IN NAME
SIXAS2:	MOVEI T1,.CHNUL		;GET A NULL
	IDPB T1,T3		;TERMINATE THE ASCIZ STRING
	RET			;RETURN
; ROUTINE TO FIND A FILE STRUCTURE IN THE DEVICE TABLES
; ACCEPTS IN T1/ POINTER TO ASCIZ STRUCTURE NAME IN USER SPACE
;		CALL FNDSTR
; RETURNS: +1	 FAILED, STRUCTURE NOT MOUNTED WITH THAT ALIAS
;	   +2	SUCCESS, WITH T1/ STRUCTURE NUMBER
;		RETURNS NOINT, WITH STRUCTURE LOCKED !

FNDSTR:	SAVEP
	STKVAR <FSTERR,FSTBLK,FSTSTR>
	SETZM FSTERR		;INITIALIZE ERROR FLAG
	SETZM FSTBLK		;INITIALIZE ADR OF FREE BLOCK
	MOVE T2,T1		;COPY DEVICE DESIGNATOR
	TLC T2,-1		;SEE IF LH = -1
	TLCN T2,-1
	HRLI T2,(<POINT 7,0>)	;YES, SET UP BYTE POINTER
	HLRZ T3,T2		;GET LEFT HALF OF DESIGNATOR OR POINTER
	CAIL T3,.DVDES		;WAS A DESIGNATOR PROVIDED ?
	JRST FNDST1		;YES, SKIP STDEV, JUST GO CHECK DESIGNATOR
	CALL CPYFUS		;COPY STRUCTURE NAME STRING FROM USER SPACE
	 RETBAD (MONX01)	;FAILED, RETURN "INSUFFICIENT RESOURCES"
	MOVEM T1,FSTBLK		;SAVE ADDRESS OF BLOCK
	HRROI T1,1(T1)		;FORM POINTER TO NAME STRING
	STDEV			;TRNASLATE STRING TO DEVICE DESIGNATOR
	 JRST [	MOVEM T2,FSTERR	;FAILED, SAVE ERROR CODE
		JRST FNDST2 ]	;GO RELEASE SPACE AND RETURN ERROR
FNDST1:	MOVEM T2,FSTSTR		;SAVE DEVICE DESIGNATOR
	HRRZ T4,T2		;GET UNIQUE CODE PART OF DESIGNATOR TO CHECK
	CAIN T4,-1		;IS DESIGNATOR TO BE CHECKED FOR "DSK:" ?
	JRST [	CALL GTCSCD	;YES, GET CONNECTED STRUCTURE UNIQUE CODE
		HLRM T1,FSTSTR	;SAVE UNIQUE CODE FOR CONNECTED STRUCTURE
		JRST .+1]	;CONTINUE
	HLRZ T3,FSTSTR		;GET DEVICE-TYPE PORTION OF DESIGNATOR
	CAIE T3,.DVDES+.DVDSK	;IS THIS A DISK ?
	JRST [	MOVX T1,ARGX18	;NO, GET ERROR CODE
		MOVEM T1,FSTERR	;SAVE ERROR CODE
		JRST FNDST2 ]	;GO RELEASE SPACE AND RETURN ERROR CODE
	MOVE T1,FSTSTR		;COPY DEVICE DESIGNATOR FOR CHKDEV
	CALL CHKDEV		;GO CHECK DEVICE DESIGNATOR
	 JRST [	MOVX T1,STRX01	;GET ERROR CODE
		MOVEM T1,FSTERR	;SAVE ERROR CODE
		JRST FNDST2 ]	;GO RELEASE SPACE AND RETURN ERROR CODE TO USER
	HRRZ T1,FSTSTR		;GET UNIQUE CODE FOR THIS STRUCTURE
	CALL CNVSTR		;CONVERT UNIQUE CODE TO A STRUCTURE NUMBER
	 JRST [	MOVEM T1,FSTERR	;SAVE ERROR CODE
		JRST FNDST2 ]	;GO RELEASE SPACE AND RETURN ERROR CODE
	MOVEM T1,FSTSTR		;SAVE STRUCTURE NUMBER
FNDST2:	MOVEI T1,JSBFRE		;GET FREE HEADER
	SKIPE T2,FSTBLK		;GET ADDRESS OF BLOCK CONTAINING NAME
;**;[2965] REPLACE 1 LINE WITH 3 AT FNDST2:+2L	TAM	23-MAY-83
	JRST [CALL RELFRE	;[2965] RELEASE FREE SPACE IF ANY
	      OKINT		;[2965] UNDO INT FROM ASGRES
	      JRST .+1]		;[2965] CONTINUE
	MOVE T1,FSTSTR		;GET STRUCTURE NUMBER
	SKIPN FSTERR		;ANY ERRORS ?
	RETSKP			;NO, RETURN SUCCESS (NOINT)
	MOVE T1,FSTERR		;YES, GET ERROR CODE
	RETBAD ()		;RETURN ERROR CODE
;STOSTR - ROUTINE TO STORE A STRUCTURE NAME STRING INTO USER SPACE
;
;ACCEPTS IN T1/	ADDRESS OF POINTER TO DESTINATION (ADR IN USER SPACE)
;	    T2/	ADDRESS OF STRUCTURE NAME STRING IN MONITOR SPACE
;		CALL STOSTR
;RETURNS: +1 ALWAYS, T1/ UPDATED POINTER INTO USER SPACE

STOSTR:	UMOVE T4,(T1)		;GET POINTER TO DESTINATION FROM USER
;**;[2948] At STOSTR: +1L, Replaced 7 lines with 5          SM 22-Apr-83
	TLCN T4,-1		;[2948] CHECK FOR -1 LH BYTEPOINTER
	JRST R			;[2948] THE LH WAS 0, NO REAL BYTE PNTR
	TLCN T4,-1		;[2948] CONVERT BACK; WAS IT -1?
	HRLI T4,(POINT 7)	;[2948] YES, MAKE A PROPER BYTE POINTER
	HRLI T2,(POINT 7)	;[2948] MAKE T2 PROPER AS WELL

STOST2:	ILDB T3,T2		;GET A CHARACTER FROM THE NAME STRING
	MOVEM T4,T1		;SAVE UPDATED POINTER
	XCTBU [IDPB T3,T4]	;STORE CHARACTER IN USER SPACE
	JUMPN T3,STOST2		;IF NOT NULL, GO COPY NEXT CHARACTER
	RET			;RETURN


; ROUTINE TO CHECK A CHARACTER OF A STRUCTURE NAME FOR VALIDITY
;
; ACCEPTS IN T1/ ASCII CHARACTER
;		CALL CHRCHK
; RETURNS: +1	 FAILED, CHARACTER IS ILLEGAL
;	   +2	SUCCESS, CHARACTER IS LEGAL

; MASK OF VALID CHARACTER CLASSES--

CHDASH==30			;DASH
CHUCA==24			;UPPER CASE A
CHUPCH==0			;UPPER CASE CHARACTERS IN GENERAL
CHUCP==23			;UPPER CASE P
CHUCT==22			;UPPER CASE T
CHDIG==21			;DIGITS

CHRMSK==1B<CHDASH>!1B<CHUCA>!1B<CHUPCH>!1B<CHUCP>!1B<CHUCT>!1B<CHDIG>

CHRCHK:	SAVET			;PRESERVE THE TEMPORARY AC'S
	MOVE T2,T1		;GET CHARACTER TO CHECK
	CALL GTCODE		;GET THE CHARACTER CLASS CODE
	 RETBAD ()		;FAILED, RETURN ILLEGAL CHARACTER
	MOVEI T1,1		;GET A BIT TO SHIFT INTO POSITION
	MOVEI T4,^D35		;GET NUMBER OF BITS/WORD - 1
	SUB T4,T2		;COMPUTE SHIFT REQUIRED
	LSH T1,(T4)		;POSITION BIT FOR THIS CHARACTER CLASS
	TXNN T1,CHRMSK		;IS THIS A VALID CHARACTER ?
	RETBAD ()		;NO, RETURN ILLEGAL CHARACTER
	RETSKP			;YES, RETURN SUCCESS
;ROUTINE TO TRANSFER SIXBIT STRUCTURE NAME TO SEVENBIT
;
;ACCEPTS: T1/ BYTE POINTER TO 7-BIT ASCII AREA
;	  T2/ STRUCTURE NUMBER
;		CALL MSTOUT
;RETURNS: +1  ALWAYS, T1 UPDATED
;**;[8861] Several changes in MSTOUT			GAS	13-Jul-88

MSTOUT:	MOVE T2,STRTAB(T2)	;GET STRUCTURE BLOCK ADDRESS
	MOVEI T2,SDBNAM(T2)	;GET ADDRESS OF STRUCTURE NAME
	HRLI T2,(POINT 6)	;[8861] Set up 6-bit pointer
	MOVEI T4,6		;THERE IS A MAXIMUM OF 6 BYTES
MSTOU1:	ILDB T3,T2		;[8861] Get 6-bit character
	JUMPE T3,MSTOU2		;[8861] Get out of loop if zero (space) byte
	ADDI T3,"A"-'A'		;[8861] Convert it to printable 7-bit byte
	IDPB T3,T1		;[8861] Store that in the destination string
	SOJG T4,MSTOU1		;LOOP IF MORE CHARACTERS
MSTOU2:	RET			;[8861] Return now if done

;**;[8861] Add routine MSTASC after MSTOUT		GAS	13-Jul-88
;[8861] Routine to quickly append one ASCIZ string to another.
;
;Accepts: T1/ destination byte pointer
;	  T2/ source byte pointer
;Returns +1 always, T1/ updated byte pointer, null at pointer for ASCIZ string

MSTASC:	ILDB T3,T2		;Load a character
	IDPB T3,T1		;Store one character
	JUMPN T3,MSTASC		;Loop for all characters
	MOVNI T3,1		;Load a -1
	ADJBP T3,T1		;Backup over the null
	MOVEM T3,T1		; and store the pointer back
	RET			;Return
;SNDUSG - ROUTINE TO SEND USAGE ACCOUNTING INFORMATION FOR STR MOUNTS
;
;ACCEPTS: T1/	STRUCTURE INDEX
;	  T2/	JSB OFFSET
;	  T3/	JOB NUMBER
;		CALL SNDUSG
;RETURNS: +1 ALWAYS, MESSAGE SENT TO DEVICE ALLOCATOR

SNDUSG:	TRVAR <MSTHDI,<MSTIPC,17>>
	MOVEI T4,20		;ARG BLOCK IS 20 WORDS LONG
	HRLI T4,.IPCMS		;SET UP MOUNT CODE
	MOVEM T4,MSTHDI
	HRLM T3,MSTIPC		;STORE JOB NUMBER
	HLR T4,JOBPT(T3)
	HRRM T4,MSTIPC		;STORE LINE NUMBER
	HRR T4,JOBDIR(T3)
	HRLI T4,USRLH		;SET UP USER NUMBER SYMBOL
	MOVEM T4,6+MSTIPC	;STORE USER NUMBER
	LOAD T3,STRUC,(T1)
	HRRM T3,1+MSTIPC	;STORE STR UNIQUE CODE
	LDB T3,[POINT STRNS,T3,35] ;GET STRUCTURE INDEX
	LOAD T4,STRMC,(T1)
	SOS T4
	HRLM T4,2+MSTIPC	;STORE PREVIOUS MOUNT COUNT
;**;[1926] Change 1851 lines at SNDUSG: +16L	JGZ	19-AUG-81
;**;[1851] CHANGE 2 LINES AT SNDUSG: + 16L	TAM	16-APR-81
	MOVE T4,SDBSTS(T1)	;[1851] GET STATUS BITS
	SKIPN T3		;IS THIS THE PRIMARY STRUCTURE?
	TXO T4,MS%PPS!MS%PS!MS%NRS!MS%DOM ;[1851] YES, MARK IT SO
;**;[1782] CHANGE 1 LINE AT SNDUSG: +19L	TAM	9-SEPT-80
	HLRM T4,2+MSTIPC	;[1782] STORE STR STATUS
	MOVE T4,SDBNUM(T1)
	HRLM T4,3+MSTIPC	;STORE NUMBER OF UNITS
	HRRZ T4,SDBUDB(T1)
	LOAD T4,USTYP,(T4)
	HRRM T4,3+MSTIPC	;STORE DRIVE TYPE
	MOVE T4,SDBNAM(T1)
	MOVEM T4,4+MSTIPC	;STORE STR NAME
	MOVEI T4,7+MSTIPC
	HRLI T4,ACCTSR(T2)
	BLT T4,16+MSTIPC	;STORE ACCOUNT STRING
	CALL LGTAD
	MOVEM T1,5+MSTIPC	;STORE TIME AND DATE
	CALL DISMES		;SEND A MESSAGE TO THE DEVICE ALLOCATOR
	 JFCL			;IGNORE IF MESSAGE FAILED
	RET
;SNDEND - ROUTINE TO SEND MESSAGE TO DEVICE ALLOCATOR FOR STR DECREMENT
;
;ACCEPTS: T1/	STRUCTURE INDEX
;	  T2/	JOB NUMBER
;		CALL SNDEND
;RETURNS  +1,	ALWAYS

SNDEND:	TRVAR <MSTHDD,<MSTPC,3>>
	MOVEI T3,4		;LENGTH OF ARG BLOCK
	HRLI T3,.IPCDS		;SET UP DISMOUNT CODE
	MOVEM T3,MSTHDD
	HRLM T2,MSTPC		;STORE JOB NUMBER
	LOAD T3,STRMC,(T1)
	HRRM T3,MSTPC		;STORE MOUNT COUNT
	LOAD T3,STRUC,(T1)
	MOVEM T3,1+MSTPC	;STORE STRUCTURE UNIQUE CODE
	CALL LGTAD
	MOVEM T1,2+MSTPC	;STORE TIME OF DAY
	CALL DISMES		;SEND MESSAGE TO DEVICE ALLOCATOR
	 JFCL			;IGNORE IF MESSAGE FAILED
	RET

	TNXEND

	END
; *** Edit 7190 to MSTR.MAC by GRANT on 12-Nov-85
; Within MSTR%, use TTMSG% instead of SOUT% to prevent blocking forever