Google
 

Trailing-Edge - PDP-10 Archives - BB-4170G-SM - sources/disc.mac
There are 53 other files named disc.mac in the archive. Click here to see a list.
;<3A.MONITOR>DISC.MAC.7, 31-May-78 14:35:02, EDIT BY BOSACK
;SET OFN2XB IN NEWLFB
;<3A.MONITOR>DISC.MAC.6, 26-May-78 19:11:37, Edit by DBELL
;STACK SHOULD NOT BE DIDDLED AT NEWFLL+2
;<3A.MONITOR>DISC.MAC.5, 24-May-78 12:31:50, Edit by PORCHER
;TCO # 1890 - DON'T COPY .FBBK0-4 ON RENAME
;<3A.MONITOR>DISC.MAC.4,  8-May-78 11:12:15, Edit by DBELL
;DON'T CHANGE FILWND WHEN CREATING PAGE OF ZEROES AT NEWWNA
;<3A.MONITOR>DISC.MAC.3, 23-Mar-78 08:18:32, EDIT BY MILLER
;MAKE ASLOFN DECISIONS IN PAGEM
;<3A.MONITOR>DISC.MAC.2, 28-Feb-78 09:05:50, EDIT BY MILLER
;ALLOW OPEN OF DIRECTORY FILE ONLY IF "THAWED"
;<3.SM10-RELEASE-3>DISC.MAC.1,  2-Dec-77 16:36:06, EDIT BY MILLER
;CREATE LONG FILE PT ON BIN IF HAVE WRITE ACCESS
;<3-MONITOR>DISC.MAC.279,  7-Nov-77 13:00:16, EDIT BY KIRSCHEN
;MORE COPYRIGHT UPDATING...
;<3-MONITOR>DISC.MAC.278, 14-Oct-77 12:32:35, EDIT BY MILLER
;PUT BACK CHECK FOR WNDF IN DSKCLZ ON EOF UPDATE
;<3-MONITOR>DISC.MAC.277, 12-Oct-77 13:41:30, EDIT BY KIRSCHEN
;UPDATE COPYRIGHT FOR RELEASE 3
;<3-MONITOR>DISC.MAC.276,  4-Oct-77 23:20:54, EDIT BY CROSSLAND
;GO OKSKED BEFORE CALLING UPDOFN IN NEWLFT INCASE PTT IS LOCKED
;<3-MONITOR>DISC.MAC.275,  3-Oct-77 14:56:41, EDIT BY MILLER
;FIX NEWWNA WHEN PT NOT IN EXISTANCE, FIX DSKCLZ TO GET FDBLEN RIGHT
;<3-MONITOR>DISC.MAC.274, 14-Sep-77 10:43:07, EDIT BY HURLEY
;<3-MONITOR>DISC.MAC.273, 14-Sep-77 09:07:49, EDIT BY HURLEY
;<3-MONITOR>DISC.MAC.272, 13-Sep-77 12:36:53, EDIT BY P.HURLEY
;ADD ROUTINE TO SET THE LENGTH OF A FILE - CALLED BY CHFDB
;<3-MONITOR>DISC.MAC.271,  1-Sep-77 13:17:42, EDIT BY HURLEY
;MAKE CLOSF SET BYTE SIZE AND EOF ON ALL WRITE OPERATIONS (EVEN PMAP)
;<3-MONITOR>DISC.MAC.270, 22-Aug-77 16:06:23, EDIT BY BOSACK
;<3-MONITOR>DISC.MAC.269,  5-Aug-77 08:39:34, EDIT BY MILLER
;SET ERRF IF PT CREATE FAILS
;<3-MONITOR>DISC.MAC.268, 27-Jul-77 17:32:42, EDIT BY HURLEY
;MAKE DELETING OF DIRECTORIES WORK
;<3-MONITOR>DISC.MAC.267, 19-Jul-77 16:23:58, EDIT BY HURLEY
;ADD SUPPORT FOR SUBDIRECTORY RECONSTRUCTION
;<3-MONITOR>DISC.MAC.266,  6-Jul-77 17:41:16, EDIT BY HALL
;MAKE DELFIL RETURN DLFX11 FOR DIRECTORY FILE
;<3-MONITOR>DISC.MAC.265, 24-Jun-77 12:17:00, EDIT BY MILLER
;FIX CNTLNG NOT TO CAL JFNOF1 FOR PT0
;<3-MONITOR>DISC.MAC.264, 23-Jun-77 19:21:42, EDIT BY HURLEY
;<3-MONITOR>DISC.MAC.263, 23-Jun-77 10:56:22, EDIT BY HURLEY
;MAKE SPLOPN GET ENOUGH WORDS FOR A LONG FILE SPEC
;<3-MONITOR>DISC.MAC.262, 16-Jun-77 18:25:57, EDIT BY HURLEY
;MAKE NFACHK ALLOW ACCESS IF FILE IS NON-EXISTENT
;<3-MONITOR>DISC.MAC.261, 11-Jun-77 16:53:15, Edit by MCLEAN
;FIX DUMPI/DUMPO FOR EXTENDED ADDRESSING
;<3-MONITOR>DISC.MAC.260, 10-May-77 13:12:04, EDIT BY HURLEY
;<3-MONITOR>DISC.MAC.259,  8-May-77 00:42:51, Edit by MCLEAN
;ADD RECOUT TO SPLDTB ENTRY
;<3-MONITOR>DISC.MAC.258,  6-May-77 11:54:27, EDIT BY HURLEY
;ADD SET INPUT/OUTPUT AND ATTRIBUTE CHECK ENTRIES IN DISPATCH TABLE
;<3-MONITOR>DISC.MAC.257,  2-May-77 20:31:17, EDIT BY BOSACK
;<3-MONITOR>DISC.MAC.256,  2-May-77 19:49:33, EDIT BY BOSACK
;<3-MONITOR>DISC.MAC.255, 28-Apr-77 16:57:42, EDIT BY BOSACK
;TCO 1785 - FIX RACE IN DSKCL2
;<2-MONITOR>DISC.MAC.241, 11-Mar-77 16:57:25, EDIT BY MURPHY
;TCO #1756 - LONG FILE BUG
;<3-MONITOR>DISC.MAC.253,  8-Mar-77 14:03:21, Edit by MCLEAN
;<3-MONITOR>DISC.MAC.252, 28-Feb-77 11:41:40, EDIT BY HURLEY
;FIX DUMP MODE TO DISC
;<3-MONITOR>DISC.MAC.251,  7-Feb-77 21:04:53, Edit by HESS
;<3-MONITOR>DISC.MAC.250, 31-Jan-77 14:35:45, Edit by MCLEAN
;TCO 1726 - FIX FILE EOF FOR SIMULTANEOUS UPDATE
;<3-MONITOR>DISC.MAC.249, 11-Jan-77 16:14:26, Edit by MCLEAN
;<3-MONITOR>DISC.MAC.248, 30-Dec-76 13:56:35, Edit by HESS
;<3-MONITOR>DISC.MAC.247, 27-Dec-76 17:31:30, EDIT BY HURLEY
;<3-MONITOR>DISC.MAC.246, 27-Dec-76 12:53:57, Edit by HESS
;TCO 1689 - FIX <ROOT-DIRECTORY> ALLOCATION ENTRY (ASROFN)
;<3-MONITOR>DISC.MAC.245,  6-Dec-76 00:50:34, Edit by MCLEAN
;<3-MONITOR>DISC.MAC.244,  4-Dec-76 16:51:10, Edit by MCLEAN
;<3-MONITOR>DISC.MAC.243,  1-Dec-76 22:31:58, Edit by MCLEAN
;<3-MONITOR>DISC.MAC.242,  1-Dec-76 01:56:13, Edit by MCLEAN
;<3-MONITOR>DISC.MAC.241, 30-Nov-76 13:00:15, Edit by HESS
;FIX RENAME TO OMIT QUOTA CHECKING IF IN SAME DIRECTORY
;<3-MONITOR>DISC.MAC.240, 30-Nov-76 11:21:46, EDIT BY MILLER
;DON'T CALL RELOFN IF CLOSING A FILE ON A DISMOUNTED STRUCTURE
;<3-MONITOR>DISC.MAC.239, 28-Nov-76 13:13:38, Edit by MCLEAN
;<3-MONITOR>DISC.MAC.238, 26-Nov-76 15:58:21, Edit by MCLEAN
;<3-MONITOR>DISC.MAC.237, 25-Nov-76 01:54:22, Edit by MCLEAN
;TCO 1669 EXTENDED ADDRESSING
;<2-MONITOR>DISC.MAC.236, 24-Nov-76 15:03:38, EDIT BY HURLEY
;MAKE CLOSF FAIL IF STR IS DISMOUNTED AND CZ%ABT NOT SET
;<2-MONITOR>DISC.MAC.235, 23-Nov-76 16:59:07, EDIT BY HALL
;COMMENTS IN DSKDTB
;<2-MONITOR>DISC.MAC.234, 23-Nov-76 16:45:06, Edit by HESS
;DON'T SET DELETED BIT ON A DIRECTORY FILE (DSKDEL)
;<2-MONITOR>DISC.MAC.233, 15-Nov-76 15:03:44, EDIT BY MILLER
;CALL RELOFN INSTEAD OF DWNSHR AT CNTLNG
;<2-MONITOR>DISC.MAC.232, 15-Nov-76 13:55:38, Edit by HESS
;FIX TO DSKDLD TO CHECK IF DIRECTORY IS STILL MAPPED, (ALSO DO FORGET)
;<2-MONITOR>DISC.MAC.231, 10-Nov-76 10:12:30, Edit by HESS
;CHANGE TO DSKCLZ TO DECREMENT O/F COUNT IF FDB IS GONE
;<2-MONITOR>DISC.MAC.230,  1-Nov-76 10:07:49, Edit by HESS
;ALLOW OPENF IF OVER QUOTA ON A NEW FILE (WILL TRAP ON FIRST WRITE)
;<2-MONITOR>DISC.MAC.229, 29-Oct-76 11:33:40, EDIT BY HURLEY
;MORE FIXES TO OPEN FILE COUNT DECREMENTING
;<2-MONITOR>DISC.MAC.228, 26-Oct-76 14:54:04, EDIT BY MILLER
;CALL LUNLK0 IN OFNJFN
;<2-MONITOR>DISC.MAC.227, 26-Oct-76 14:45:20, EDIT BY MILLER
;FIX OKINT AT OFNJF6
;<2-MONITOR>DISC.MAC.226, 26-Oct-76 14:27:26, EDIT BY MILLER
;TCO 1628. CHANGE OFNJFN TO WAIT FOR JFN TO BE UNLOCKED.
;<2-MONITOR>DISC.MAC.225, 26-Oct-76 12:44:17, EDIT BY MILLER
;MOVE DECR OF OPEN FILE COUNT TO INCLUDE ALL CLOSES
;<2-MONITOR>DISC.MAC.224, 20-Oct-76 18:34:52, EDIT BY HURLEY
;ADD SUPPORT OF THE OPEN FILE COUNT IN THE SDB
;<2-MONITOR>DISC.MAC.223, 19-Oct-76 12:03:47, Edit by HESS
;CHANGE ASLOFN ERROR CODE TO MONX01
;<2-MONITOR>DISC.MAC.222,  6-Oct-76 16:17:51, Edit by HESS
;FIX RENAME TO CLEAR BACKUP INFO
;CHANGE UPDATE OF FBCRE AND FBCRV TO BE DIFFERENT
;CLEAR FB%NXF BIT AFTER RENAME OF A PERM FILE (FB%PRM)
;<2-MONITOR>DISC.MAC.221,  5-Oct-76 14:46:46, EDIT BY HURLEY
;MORE EDITS FOR SEQUENTIAL INPUT
;<2-MONITOR>DISC.MAC.220,  5-Oct-76 14:25:33, EDIT BY HURLEY
;MAKE SEQUENTIAL INPUT BEYOND LAST PT WORK. RETURNS ZEROES
;<2-MONITOR>DISC.MAC.219,  4-Oct-76 13:58:54, EDIT BY MILLER
;MORE TCO 1555 EDITS. FIX ALL SEQUENTIAL STUFF
;<2-MONITOR>DISC.MAC.218,  1-Oct-76 08:56:44, EDIT BY MILLER
;MORE TCO 1555 EDITS
;<2-MONITOR>DISC.MAC.217, 30-Sep-76 15:14:16, EDIT BY MILLER
;TCO 1555. PREVENT PT CREATES
;<2-MONITOR>DISC.MAC.216, 23-Sep-76 08:51:18, Edit by HESS
;<HESS>DISC.MAC.8, 26-Aug-76 17:08:07, Edit by HESS
;TCO 1496 - ADD AUTHOR/LAST-WRITE STRINGS TO FDB
;<2-MONITOR>DISC.MAC.214, 19-Aug-76 16:53:27, Edit by HESS
;<2-MONITOR>DISC.MAC.213, 16-Aug-76 13:38:15, Edit by HESS
;REMOVE REFERENCES TO OLD FDB SYMBOLS (FDBXXX AND FD.XXX)
;<2-MONITOR>DISC.MAC.212, 13-Aug-76 18:33:21, Edit by HESS
;ADDED ASFOFN, ASLOFN, ASROFN (JFN AC USED)
;<2-MONITOR>DISC.MAC.211, 13-Aug-76 10:25:23, Edit by HESS
;CHECK ENABLED CAPS ON RENAME QUOTA CHECKING
;<2-MONITOR>DISC.MAC.210, 11-Aug-76 12:18:59, EDIT BY HURLEY
;FIX SPOOLING TO TAKE 36 BIT DIR NUMBER FOR SPOOLING AREA
;<2-MONITOR>DISC.MAC.209, 10-Aug-76 17:12:02, Edit by HESS
;ADDED PAGEM ERJMP TRAP STUFF
;<2-MONITOR>DISC.MAC.208,  4-Aug-76 17:21:14, EDIT BY HALL
;CHANGED CALLS TO DIRCHK AND ACCCHK TO USE NEW BITS
;<2-MONITOR>DISC.MAC.207,  4-Aug-76 14:15:36, EDIT BY HURLEY
;<HESS>DISC.MAC.8,  3-Aug-76 16:59:07, Edit by HESS
;TCO 1478 - QUOTA CHECKING
;<2-MONITOR>DISC.MAC.205, 29-Jul-76 13:18:21, EDIT BY MILLER
;DISALLOW DUD ACTION IF OPENING FOR READ ONLY
;<1MILLER>DISC.MAC.2, 26-Jul-76 18:58:28, EDIT BY MILLER
;<1MILLER>DISC.MAC.1, 26-Jul-76 15:42:46, EDIT BY MILLER
;DISALLOW DUD IF A NEW FILE
;<2-MONITOR>DISC.MAC.203, 20-Jul-76 12:43:50, EDIT BY MILLER
;FIX CHKDUD
;<2-MONITOR>DISC.MAC.202, 20-Jul-76 12:40:09, EDIT BY MILLER
;SET OFNDUD BIT IN CALLS TO ASOFN WHEN APPROPRIATE
;<2-MONITOR>DISC.MAC.201, 16-Jul-76 18:03:55, EDIT BY HURLEY
;TCO # 1471 - UNLOCK DIR IF DELETE OF DIRECTORY FILE FAILS
;<1MILLER>DISC.MAC.4,  8-Jul-76 08:02:59, EDIT BY MILLER
;<1MILLER>DISC.MAC.3,  7-Jul-76 14:43:14, EDIT BY MILLER
;ADD FILP0 STRUCTURE
;<1MILLER>DISC.MAC.2,  7-Jul-76 12:13:01, EDIT BY MILLER
;MAKE JFNOF1 CHECK FOR DISMOUNTED STRUCTURE
;<1MILLER>DISC.MAC.1,  6-Jul-76 15:56:28, EDIT BY MILLER
;ADD DISMOUNT CHECKS
;<1B-MONITOR>DISC.MAC.197, 21-Jun-76 15:36:10, EDIT BY MURPHY
;TCO #1449 - EXTRA SHARE COUNT FOR PT0 OF LONG FILES
;<2-MONITOR>DISC.NEW.2, 21-Jun-76 12:01:40, EDIT BY MILLER
;DO REST OF MERGE MANUALLY
;<1B-MONITOR>DISC.MAC.196, 15-JUN-76 17:22:04, EDIT BY HURLEY
;TCO # 1425 - MOVE APPEND ACCESS CHECK FROM JFNOFN TO .PMAP
;<1B-MONITOR>DISC.MAC.195, 15-JUN-76 15:45:27, EDIT BY HURLEY
;TCO #1422 - CHECK JFN LOCK IN OFNJFN
;<1B-MONITOR>DISC.MAC.194, 11-JUN-76 15:34:23, EDIT BY HURLEY
;MORE OF TCO 1388
;<1B-MONITOR>DISC.MAC.193, 11-JUN-76 12:13:41, EDIT BY HALL
;TCO 1388 - ALLOW DELETING OF SICK  DIRECTORIES
;<1B-MONITOR>DISC.MAC.192, 17-MAY-76 17:07:57, EDIT BY MILLER
;<1B-MONITOR>DISC.MAC.192, 17-MAY-76 16:59:37, EDIT BY MILLER
;TCO 1293 AGAIN. TEMP HACK TO PREVENT BUGHLT ON NON-EX PAGE TABLE
;<1B-MONITOR>DISC.MAC.191, 17-MAY-76 12:02:18, EDIT BY MILLER
;TCO 1293. PREVENT DSKSQI FROM CREATING PAGES
;<1B-MONITOR>DISC.MAC.2, 10-MAY-76 12:57:51, EDIT BY MILLER
;TCO 1286. ADD DEWNDW ROUTINE.
;<1B-MONITOR>DISC.MAC.1,  3-MAY-76 15:28:37, EDIT BY HELLIWELL
;TCO # 1276 - FIX SFTAD BUG
;<2-MONITOR>DISC.MAC.12, 17-Jun-76 13:52:29, EDIT BY MILLER
;<2-MONITOR>DISC.MAC.11, 17-Jun-76 11:39:37, EDIT BY MILLER
;REPLACE SFJN WITH MLJFN
;<2-MONITOR>DISC.MAC.10, 17-MAY-76 12:05:59, EDIT BY MILLER
;TCO 1293. PREVENT DSKSQI FROM CREATING PAGES
;<2-MONITOR>DISC.MAC.9,  8-MAY-76 12:28:49, EDIT BY HALL
;CHANGED SETZ'S OF STRUCTURE NUMBER TO LOADS FROM FILDEV
;<2-MONITOR>DISC.MAC.8,  8-MAY-76 12:26:27, EDIT BY HALL
;<2-MONITOR>DISC.MAC.7,  6-MAY-76 10:54:02, EDIT BY MILLER
;ADD SETZ B, TO ALL CALLS TO DEDSK
;<2-MONITOR>DISC.MAC.6,  6-MAY-76 09:21:34, EDIT BY MILLER
;ADD SETZ B, IN FRONT OF ALL CALLS TO DSKASN
;<2-MONITOR>DISC.MAC.5, 20-APR-76 13:03:35, EDIT BY MILLER
;ADD CALL TO GSTRPG TO TEST DISK SPACE
;<2-MONITOR>DISC.MAC.4, 20-APR-76 10:36:31, EDIT BY MILLER
;<2-MONITOR>DISC.MAC.3, 20-APR-76 09:29:12, EDIT BY MILLER
;<2-MONITOR>DISC.MAC.2, 18-APR-76 18:21:11, EDIT BY MILLER
;<2-MONITOR>DISC.MAC.1, 18-APR-76 18:07:51, EDIT BY MILLER
;<1A-MONITOR>DISC.MAC.189,  1-APR-76 13:52:50, EDIT BY HURLEY
;TCO # 1230 - FIX SPELLING ERRORS IN BUGCHK MESSAGES
;<1MONITOR>DISC.MAC.188, 23-MAR-76 18:21:20, EDIT BY HURLEY
;<1MONITOR>DISC.MAC.187, 23-MAR-76 17:24:29, EDIT BY HURLEY
;TCO 1216 - MAKE ALL UNSUPPORTED DISPATCH ENTRIES RETURN AN ERROR CODE
;<1MONITOR>DISC.MAC.186, 23-MAR-76 16:52:59, EDIT BY HURLEY
;<1MONITOR>DISC.MAC.185, 23-MAR-76 15:16:56, EDIT BY HURLEY
;TCO 1206 - CHANGE ERROR CODE OF DSKJFN FROM PMAPX1 TO DESX8
;<2MONITOR>DISC.MAC.184,  9-FEB-76 10:34:21, EDIT BY HURLEY
;TCO 51 - FIX UP SPELLING OF GJFX32
;<2MONITOR>DISC.MAC.183,  3-FEB-76 17:13:46, EDIT BY CROSSLAND
;MCO 51 - GIVE ERROR ON SET DIRECTORY FOR SPOOLED DEVICE HANDLER
;<2MONITOR>DISC.MAC.182, 27-JAN-76 18:19:29, EDIT BY HURLEY
;MCO 20 - ALLOW OPERATOR TO OVERIDE QUOTA CHECKS WHEN ENABLED
;<2MONITOR>DISC.MAC.181, 16-JAN-76 17:43:29, EDIT BY MURPHY
;<2MONITOR>DISC.MAC.180,  8-JAN-76 15:05:24, EDIT BY HURLEY


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

	SEARCH PROLOG
	TTITLE DISC
	SWAPCD

;SPECIAL AC DEFINITIONS USED HEREIN

DEFAC (STS,P1)			;SEE GTJFN FOR FUNCTIONS
DEFAC (JFN,P2)
DEFAC (DEV,P4)
DEFAC (F1,P5)

;DEVICE DEPENDENT ROUTINES. TO DO CERTAIN FUNCTIONS, THE RH OF DEV
;CONTAINS THE NAME OF A TABLE SUCH AS DSKDTB, AND A ROUTINE IS CALLED
;VIA 'CALL @FOO(DEV)', WHERE FOO IS A SYMBOL FOR AN OFFSET INTO THE 
;TABLE. THE SYMBOLS ARE DEFINED IN PROLOG. IN THE COMMENTS BELOW,
;THE OFFSET IS INDICATED ALONG WITH THE PURPOSE OF THE ROUTINE

DSKDTB::IFIW!MDDDIR		;DLUKD - DIRECTORY SETUP
	IFIW!MDDNAM		;NLUKD - NAME LOOKUP
	IFIW!MDDEXT		;ELUKD - EXTENSION LOOKUP
	IFIW!MDDVER		;VLUKD - VERSION LOOKUP
	IFIW!INSPRT		;PLUKD - PROTECTION INSERTION
	IFIW!INSACT		;ALUKD - ACCOUNT INSERTION
	IFIW!DSKINS		;SLUKD - STATUS INSERTION
	IFIW!DSKOPN		;OPEND - OPEN FILE
	IFIW!DSKSQI		;BIND - BYTE INPUT
	IFIW!DSKSQO		;BOUTD - BYTE OUTPUT
	IFIW!DSKCLZ		;CLOSD - CLOSE FILE
	IFIW!DSKREN		;REND - RENAME
	IFIW!DSKDEL		;DELD - DELETE FILE
	IFIW!DSKDMI		;DMPID - DUMP MODE INPUT
	IFIW!DSKDMO		;DMPOD - DUMP MODE OUTPUT
	DTBBAD (DESX9)		;MNTD - MOUNT DEVICE
	DTBBAD (DESX9)		;DSMD - DISMOUNT DEVICE
	DTBBAD (DESX9)		;INDD - INITIALIZE DIRECTORY OF DEVICE
	DTBBAD (MTOX1)		;MTPD - DO MTAPE OPERATION
	DTBBAD (DESX9)		;GDSTD - GET DEVICE STATUS
	DTBBAD (DESX9)		;SDSTD - SET DEVICE STATUS
	DTBSKP			;RECOUT - FORCE RECORD OUT (SOUTR)
	IFIW!DSKRFT		;RFTADD - READ FILE TIME AND DATE
	IFIW!DSKSFT		;SFTADD - SET FILE TIME AND DATE
	DTBDSP (BIOINP)		;SET JFN FOR INPUT
	DTBDSP (BIOOUT)		;SET JFN FOR OUTPUT
	DTBBAD (GJFX49)		;CHECK ATTRIBUTE

	DTBLEN==:.-DSKDTB	;GLOBAL LENGTH OF DISPATCH TABLE
;RFTAD/SFTAD DEVICE ROUTINES FOR DISK

;RFTAD
DSKRFT:	SE1CAL
	TQNE <ASTF>		;OUTPUT STARS?
	RETBAD(DESX7)		;YES, LOSE
	CALL GETFDB		;GET FDB IN
	 RETBAD(DESX3)		;LOSE
	MOVE B,.FBCRV(A)	;GET CREATION DATE AND TIME
	CAILE Q1,.RSCRV		;DOES CREATION WORD EXIST?
	XCTU [MOVEM B,.RSCRV(Q3)] ;YES, RETURN TO USER
	MOVE B,.FBWRT(A)	;GET WRITTEN DATE AND TIME
	CAILE Q1,.RSWRT		;DOES WRITTEN WORD EXIST?
	XCTU [MOVEM B,.RSWRT(Q3)] ;YES, RETURN TO USER
	MOVE B,.FBREF(A)	;GET REFERENCE DATE AND TIME
	CAILE Q1,.RSREF		;DOES REFERENCE WORD EXIST?
	XCTU [MOVEM B,.RSREF(Q3)] ;YES, RETURN TO USER
	MOVE B,.FBCRE(A)	;GET INTERNAL WRITTEN DATE AND TIME
	CAILE Q1,.RSCRE		;DOES INTERNAL SYSTEM WRITTEN WORD EXIST?
	XCTU [MOVEM B,.RSCRE(Q3)] ;YES, RETURN TO USER
	CALL USTDIR
	RETSKP

;SFTAD
DSKSFT:	SE1CAL
	STKVAR <FDBSAV>
	TQNE <ASTF>
	RETBAD(DESX7)
	MOVNI A,1
	MOVN B,Q1
	HRLZ B,B
	HRR B,Q3
DSKSF0:	XCTU [CAMN A,(B)]
	AOBJN B,DSKSF0
	JUMPGE B,RSKP		;NOOP IF ALL -1
	CALL GETFDB		;GET FDB IN
	 RETBAD(DESX3)
	MOVEM A,FDBSAV
	MOVE B,CAPENB		;GET CAPABILITIES
	TQNN WRTF		;ALWAYS SUCCEED IF OPEN FOR WRITE
	TRNE B,SC%WHL!SC%OPR	;WHEEL AND OPERATOR
	JRST DSKSF1		;CAN CHANGE ANYTHING
	CAIG Q1,.RSCRE		;CAN'T CHANGE INTERNAL DATE AND TIME
	JRST DSKSF4		;NOT GIVEN
	XCTU [MOVE B,.RSCRE(Q3)] ;GIVEN, GET IT
	CAME B,[-1]		;OK IF NOT CHANGING
	RETBAD(CFDBX2,<CALL USTDIR>)
DSKSF4:	MOVX B,FC%WR		;B/WRITE ACCESS
	CALL ACCCHK		;CHECK FOR WRITE ACCESS TO THIS FILE
	 JRST DSKSF2		;CHECK FOR OWNER
	JRST DSKSF1

DSKSF2:	MOVX B,DC%CN		;B/CONNECT ACCESS
	CALL DIRCHK		;CHECK FOR ABILITY TO CONNECT TO 
				; THIS DIRECTORY (AND THUS BECOME LIKE OWNER)
	 RETBAD (CFDBX2,<CALL USTDIR>)
DSKSF1:	MOVE A,FDBSAV
	CAIG Q1,.RSCRV
	JRST DSKSF5
	XCTU [MOVE B,.RSCRV(Q3)]
	CAME B,[-1]
	MOVEM B,.FBCRV(A)	;CREATION DATE AND TIME
DSKSF5:	CAIG Q1,.RSWRT
	JRST DSKSF6
	XCTU [MOVE B,.RSWRT(Q3)]
	CAME B,[-1]
	MOVEM B,.FBWRT(A)	;WRITE DATE AND TIME
DSKSF6:	CAIG Q1,.RSREF
	JRST DSKSF7
	XCTU [MOVE B,.RSREF(Q3)]
	CAME B,[-1]
	MOVEM B,.FBREF(A)	;READ DATE AND TIME
DSKSF7:	CAIG Q1,.RSCRE
	JRST DSKSF8
	XCTU [MOVE B,.RSCRE(Q3)]
	CAME B,[-1]
	MOVEM B,.FBCRE(A)	;INTERNAL WRITE DATE AND TIME
DSKSF8:	CALL UPDDIR
	CALL USTDIR
	RETSKP
DSKDEL:	SE1CAL
	CALL GETFDB
	RETSKP
	UMOVE C,1		;GET USER FLAGS
	TXNE C,DF%DIR		;DELETING A DIRECTORY?
	JRST DSKDLD		;YES - SPECIAL
	PUSH P,A
	MOVX B,FC%WR		;B/WRITE ACCESS
	CALL ACCCHK		;CHECK FOR ABILITY TO WRITE THIS FILE
				; (NEEDED FOR DELETING)
	JRST [	SUB P,BHC+1
		CALL USTDIR
		MOVEI A,DELFX1
		RET]
	POP P,A			;RESTORE FDB ADDRS
	UMOVE C,1		;GET USER FLAGS
	JN FBDIR,(A),[RETBAD (DLFX11,<CALL USTDIR>)]
	MOVX B,FB%DEL
	IORB B,.FBCTL(A)
	TXNE B,FB%PRM
	SETZM .FBSIZ(A)		; Zero size when deleting permanent files
	TXNE C,DF%FGT		;FORGET FILE?
	JRST [	MOVE C,CAPENB	;YES, CHECK FOR REQUIRED CAPABILITIES
		TXNN C,SC%WHL+SC%OPR+SC%MNT
		RETBAD (WHELX1,<CALL USTDIR>)
		JN FBDIR,(A),.+1 ;IF THIS IS A DIRECTORY FILE, DONT
		SETZM .FBADR(A)	;FLUSH XB ADR
		JRST .+1]
	MOVE D,A		;GET FDB ADR FOR DELFIL
	UMOVE A,A
	TXNN B,FB%PRM		;PERMANENT FILES GET EXPUNGED ON DELETE
	TLNE A,(DF%EXP)		;EXPUNGE CONTENTS WANTED?
	JRST [	CALL DELFIL	;YES, DO IT
		 JRST DSKDL1	;FAILED, LEAVE ERROR IN A
		JRST .+1]
	SETZ A,			;NO ERRORS
DSKDL1:	PUSH P,A		;SAVE ERROR CODE
	CALL UPDDIR		;UPDATE DIR ON DSK
	CALL USTDIR
	POP P,A
	JUMPE A,RSKP		;IF NO ERROR, TAKE SKIP RETURN
	RETBAD ()
;DELETE A DIRECTORY FILE.  (SHOULD ONLY BE DONE IF DIR IS SICK)

DSKDLD:	MOVE C,CAPENB		;MAKE SURE THIS JOB IS PRIVILEGED
	TXNN C,SC%WHL!SC%OPR
	RETBAD (WHELX1,<CALL USTDIR>)	;NO, DONT ALLOW THIS
	JE FBDIR,(A),<[RETBAD (DELFX9,<CALL USTDIR>)]>
	PUSH P,A		;SAVE THE FDB ADDRESS
	MOVE A,.FBADR(A)	;GET INDEX BLOCK ADDRS
	LOAD B,CURSTR		; AND STR #
	CALL CHKOFN		;SEE IF FILE OPEN
	 RETBAD (DLFX10,<POP P,A
			 CALL USTDIR>)
	MOVE A,0(P)		;NO - GET FDB ADDRS BACK
	SETZRO <FBPRM,FBDIR>,(A) ;TURN OFF DIRECTORY FLAG
	SETONE FBDEL,(A)	;MARK FILE DELETED
	SETZM .FBADR(A)		;FORGET FILE SPACE
	LOAD A,FBDRN,(A)	;GET THE DIRECTORY NUMBER OF THE FILE
	CALL INVIDX		;DELETE IDXTAB ENTRY
	POP P,D			;GET BACK ADR OF FDB
	CALL DELFIL		;DELETE THE FILE
	 SKIPA			;FAILED TO DELETE IT (CODE IN A)
	SETZ A,			;MARK THAT IT WAS SUCCESSFUL
	JRST DSKDL1		;RETURN

DSKINS:	SE1CAL
	CALL GETFDB
	 JRST DSKINB		;GETFDB FAILURE, GO COMPLAIN
	MOVX B,FB%TMP
	IORM B,.FBCTL(A)
	CALL USTDIR
	RET

DSKINB:	BUG(CHK,GTFDB1,<DSKINS: GETFDB FAILURE.>)
	RET
; Disk open routine
; Call:	LH(STS)	; Access desired
;	F1	; DEVICE DEPENDENT ACCESS BITS FROM USER
;	JFN	; Job file number
;	CALL DSKOPN
; Return
;	+1	; Cannot open, reason in a
;	+2	; Success

DSKOPN:	SE1CAL
	CALL GETFDB		; Get pointer to fdb
	 JRST [	MOVEI A,OPNX2
		RET]		; File has been deleted
	SAVEQ			;SAVE PERMANENT REGISTERS
	MOVE Q1,STS		;AND SAVE ORIGINAL USER REQUEST
	CALL NFACHK		;ACCESS OK BECAUSE NEW FILE?
	 SKIPA			;NO
	JRST [	TQNN <READF>	;YES. WANT READ?
		TQNN <WRTF>	;NO. WANT WRITE
		JRST DSKOPA	;ALL IS GOOD AS IS
		TQO <READF>	;IF WANT WRITE, GICVE READ ALSO
		JRST DSKOPA]	;AND DONE
	PUSH P,A
	TQNN <READF>		;WANT READ?
	TQNN <WRTF>		;NO. WANT WRITE?
	SKIPA			;OK AS IS
	JRST [	HLLZ B,STS	;REQUESTED ACCESS
		TXO B,FC%RD	;PLUS READ IF POSSIBLE
		CALL ACCCHK	;WILL IT GO?
		 SKIPA		;NO. DON'T ASK FO IT THEN
		TQO <READF>	;YES. SO DO IT
		MOVE A,0(P)	;GET BACK IDENTIFIER
		JRST .+1]	;AND GO ON
	HLLZ B,STS
	CALL ACCCHK		; Check access
	JRST [	CALL USTDIR	; Access not allowed
		SUB P,BHC+1
		RET]
	POP P,A
	JE FBDIR,(A),DSKOPA	;IF NOT DIR FILE, OKAY
	TXNN F1,OF%THW		;IS DIR FILE. OPEN FOR THAW?
	RETBAD (OPNX13,<CALL USTDIR>) ;NO. ERROR
DSKOPA:	TQCE <RNDF>		; Change flag from "append" to "random"
	TQO <WRTF>		; And if append, allow writing
	TQNN <WRTF>
	JRST OPENF1		; Not write
	TRNE F1,OF%PDT		;SUPPRESS REFERENCE UPDATE?
	JRST OPENF0		;YES
	; ..
;DSKOPN, WRITE...

	PUSH P,A		;SAVE FDB ADDRS
	LOAD B,FBVER,(A)	;CHECK FDB VERSION
	CAIGE B,1		;LATER THAN VER #1
	JRST [	MOVE B,JOBNO	;VER 0 - SET DIR #
		HRRZ B,JOBDIR(B)
		STOR B,FBLW0,(A) ;INTO FDB
		JRST DSKOPB]	;CONTIUNE
	MOVEI B,USRNAM		;POINT TO USER NAME
	MOVEI C,.FBLWR		;UPDATE LAST-WRITER
	CALL INSUNS		;INSERT NAME STRING
	MOVE A,0(P)		;RESTORE FDB ADDRS
DSKOPB:	MOVSI B,1
	ADDM B,.FBCNT(A)	; Count number of writes
	CALL UPDDTM		;GET TIME OF DAY AND UPDATE DIR TIME
	MOVE B,A		;SAVE TIME
	POP P,A			;GET BACK FDB ADR
	CAMN B,[-1]		;TIME SET YET?
	JRST OPENF0		;NO, DONT SET TIME
	STOR B,FBWRT,(A)	;SET DATE OF LAST USER WRITE
OPENF0:	SKIPE B,.FBADR(A)	; Get disc address
	JRST [	TXNN B,FILNB	;NEW FILE?
		JRST DSKOP3	;NO. GO SEE IF DELETE NEEDED FIRST
		PUSH P,A	;YES, EITHER BEING WRITTEN NOW OR 
		MOVE A,B	; LEFT OVER FROM A CRASH
		LOAD B,STR,(JFN) ;GET STRUCTURE NUMBER FROM JFN BLOCK
		CALL CHKOFN	;SEE IF ASOFN WOULD WORK
		 JRST [	POP P,(P)	;NO, FILE BUSY
			MOVEI A,OPNX9
			CALLRET USTDIR]
		POP P,A		;FILE NOT OPEN, MUST BE LEFT FROM CRASH
		SETZM .FBADR(A)	;FORGET IT
		MOVX B,FB%LNG	;AND BE SURE NO LEFT OVER LONGNESS
		ANDCAM B,.FBCTL(A)
		JRST .+1]	;ASSIGN NEW ADDRESS
	PUSH P,A		; No disc address, must get one
	MOVEI A,0
	LOAD B,STR,(JFN)	;GET STRUCTURE NUMBER FROM JFN BLOCK
	CALL DSKASN		; Assign a disc address
	 JRST [	POP P,A
		MOVEI A,OPNX10
		CALL USTDIR
		RET]
	PUSH P,A
	LOAD A,STR,(JFN)	;GET STRUCTURE NUMBER FROM JFN BLOCK
	CALL UPDBTB		;UPDATE BIT TABLE BEFORE STORING ADDRESS
	POP P,A
	TXO A,FILNB		;NOTE NEW FILE
	MOVE B,A
	POP P,A
	MOVEM B,.FBADR(A)
	JRST OPENF4		;CONTINUE WITH WRITE

;OPENING OLD FILE FOR WRITE. SEE IF DELETE CONTENTS IS NEEDED

DSKOP3:	MOVX B,FB%DEL		;DELETED BIT
	TDNE B,.FBCTL(A)	;IS THIS FILE NOW DELETED?
	JRST DSKOP4		;YES. MUST DO DELETE THEN
	TQNE <RNDF>		;OPENED FOR APPEND ONLY?
	TXNE Q1,READF		;NO. ORIGINAL ACCESS INCLUDE READ?
	JRST OPENF4		;YES. NO DELETE THEN
DSKOP4:	PUSH P,A		;SAVE FDB ADDRESS
	MOVE D,A		;MOVE IT
	CALL DELFL1		;GO EXPUNGE CONTENTS
	 JRST [	POP P,0(P)	;CLEAN UP STACK
		CALLRET USTDIR]	;A CONTAINS APPROPRIATE CODE
	POP P,A			;GET BACK FDB ADDRESS
	JRST OPENF0		;DONE. GO ASSIGN NEW XB
;HERE ON NOT WRITE

OPENF1:	TXZ F1,OF%DUD		;DISALLOW DUD IF NOT WRITING
	MOVE B,.FBCTL(A)
	TXNE B,FB%NXF		;DOES THIS FILE EXIST?
	ERRJMP(OPNX2,USTDIR)	;NO, CANNOT OPEN
	SKIPE B,.FBADR(A)	;HAVE GOOD ADDRESS?
	TXNE B,FILNB
	ERRJMP(OPNX2,USTDIR)	;NO, CANNOT OPEN
	TRNE F1,OF%PDT		;SUPPRESS REFERENCE UPDATE?
	JRST OPENF4		;YES
	PUSH P,A
	CALL LGTAD		;GET NOW
	MOVE B,A
	POP P,A
	SKIPL B			;SYSTEM HAS TOD SET?
	MOVEM B,.FBREF(A)	;YES, UPDATE LAST READ DATE
	AOS .FBCNT(A)
	; ..
;DSKOPN, READ AND WRITE CASES JOIN HERE

OPENF4:	MOVEI B,0
	TQNE <RNDF>
	TQNE <READF,XCTF>
	MOVE B,.FBSIZ(A)	; Get size of file
	MOVEM B,FILLEN(JFN)	; To open file length
	MOVEM B,FILBYN(JFN)
	TQNE <RNDF>
	SETZM FILBYN(JFN)
	SETZM FILWND(JFN)	; CLEAR THE WINDOW
	PUSH P,A
	LOAD A,FBBSZ,(A)	; GET BYTE SIZE
	SKIPN A
	MOVEI A,^D36
	LDB B,[POINT 4,STS,35]
	CAIN B,17
	SKIPA B,[^D36]		; Dump mode always 36 bit bytes
	LDB B,PBYTSZ
	CAILE B,^D36
	JRST [	POP P,A
		MOVEI A,SFBSX2
		JRST OPENF6]
	CALL NFBSZ
	POP P,B
OPENF9:	MOVE A,.FBADR(B)	;GET XB ADR
	MOVE C,.FBCTL(B)
	TRNE F1,OF%RTD		;RESTRICTED ACCESS REQUESTED?
	JRST [	TXO A,THAWB	;YES, MEANS THAWB ON, FILWB OFF
		JRST OPENA2]
	TRNE F1,OF%THW		; Thawed access?
	JRST [	TXO A,THAWB+FILWB ;YES, MEANS BOTH ON
		JRST OPENA2]
	TQNE <WRTF>
	TLO A,(FILWB)
OPENA2:	TXNN A,FILNB		;A NEW FILE?
	TXNN F1,OF%DUD		;NO. DON'T WANT DUD ACTION?
	JRST OPENA1		;YES. GO DO THE OPEN
	TXO A,OFNDUD		;SET DUD ACTION IN THE OFN
	TQO <FILDUD>		;SET DUD IN FILSTS FOR LATER
OPENA1:	TXNE C,FB%LNG
	JRST OPNLNG		; Long files are opened peculiarly
	TLNN A,(FILNB)		;NEW FILE
	JRST OPENF2		; NO
	; ..
;HERE TO OPEN A NEW FILE

	PUSH P,B		;SAVE FDB ADR
	LOAD B,STR,(JFN)	;GET STRUCTURE NUMBER FROM JFN BLOCK
	CALL ASFOFN		; Get an ofn for the file
	 JRST OPENF5
BP$003:				;BREAKPOINT FOR OPEN NEW FILE
				;ASSUMPTIONS: JOB CONTEXT, STACK, OFN IN T1
				;OFFSET FOR JOB'S OFN TABLE IN  11
				;THESE ASSUMPTIONS HOLD FOR BP$003-BP$009
	HRLM A,FILOFN(JFN)
	TRNN F1,OF%THW		;THAWED OPEN?
	JRST [	POP P,B		;NO, RECOVER FDB ADR
		JRST OPENF3]
	CALL UPDOFN		;YES, MUST WRITE NEW XB ON DISK
	POP P,B			;RECOVER FDB ADR
	MOVX C,FILNB
	ANDCAM C,.FBADR(B)	;CLEAR NEW FILE AND NONX BITS
	MOVX C,FB%NXF
	ANDCAM C,.FBCTL(B)
	TQZ <NONXF>		;REMEMBER IN STS THAT FILE EXISTS
	JRST OPENF3

;HERE TO OPEN AN EXISTING FILE

OPENF2:
	LOAD B,STR,(JFN)	;GET STRUCTURE NUMBER FROM JFN BLOCK
	CALL ASFOFN		; Get an ofN for this file
	 JRST OPENF6
BP$004:				;BREAKPOINT FOR OPEN EXISTING FILE
				;SEE ASSUMPTIONS FOR BP$003
	HRLM A,FILOFN(JFN)
OPENF3:	TQO <WNDF>		; No windows yet, and allow size change
	LOAD B,STR,(JFN)	;GET INDEX INTO STRTAB
	MOVE B,STRTAB(B)	;GET POINTER TO SDB
	INCR STROF,(B)		;INCREMENT OPEN FILE COUNT
	CALL GETLEN		;SETUP FILLEN FROM OFN
	CALL USTDIR
	RETSKP

OPENF5:	POP P,B
OPENF6:	CALL USTDIR
	RET
;HERE TO OPEN A LONG FILE

OPNLNG:
	LOAD B,STR,(JFN)	;GET STRUCTURE NUMBER FROM JFN BLOCK
	CALL ASFOFN		; Assign ofn for pt table
	 JRST OPENF6		; Busy
BP$005:				;BREAKPOINT FOR  GET EXISTING PTT
				;SEE ASSUMPTIONS FOR BP$003
	HRRM A,FILOFN(JFN)	; Save ofn
	CALL ASGPAG		; Assign a page to map the pt table
	 JRST OPNLN1		; None available
	HRRM A,FILLFW(JFN)	; Save long file pt location
	MOVE B,A
	HRLI B,(PTRW)
	HRRZ A,FILOFN(JFN)
	CALL SETMPG		; Map the pt table
	MOVE C,A
	HRRZS B			;REMOVE HIGH ORDER JUNK
	LOAD A,STGADR,0(B)	;GET PT 0 ADDRESS
	SKIPN A			;BE SURE THERE IS ONE
	BUG(HLT,NOPGT0,<OPNLNG: NO PAGE TABLE 0 IN LONG FILE.>)
	LOAD B,STR,(JFN)	;GET STRUCTURE NUMBER FROM JFN BLOCK
	TXNE F1,OF%DUD		;WANT TO SUPPRESS DDMP?
	TXO A,OFNDUD		;YES. REQUEST IT THEN
	CALL ASFOFN		; Assign an ofn for it
	 JRST OPNLN2		;HAPPENS ONLY IF DATA ERROR IN PT
BP$007:				;BREAKPOINT FOR PT-0 OF LONG FILE
				;SEE ASSUMPTIONS FOR BP$003
	HRLM A,FILOFN(JFN)	; Save as ofn of current pt
	STOR A,FILP0,(JFN)	;SAVE IT IN THE JFN BLOCK
	CALL UPSHR		;EXTRA COUNT ON PT0 TO PREVENT RELEASE
	TQO <LONGF>
	JRST OPENF3		; Set bits and exit

OPNLN2:	PUSH P,A		; Save error code
	HRRZ B,FILLFW(JFN)
	MOVEI A,0
	CALL SETMPG
	HRRZ A,B
	CALL RELPAG
	JRST OPNLN3

OPNLN1:	PUSH P,[OPNX17]
OPNLN3:	HRRZ A,FILOFN(JFN)
	TQNE <WRTF>		;FILE OPEN FOR WRITE?
	TXO A,FILWB		;YES, PROPAGATE BIT
	CALL RELOFN
	POP P,A
	JRST OPENF6
; Disc sequential input
; Call:	JFN	; Job file number
;	STS	; File status
;	FILBYT ETC. SETUP PROPERLY FOR NEXT BYTE
;	CALL DSKSQI
; Returns +1 with a byte in a

DSKSQI:	SE1CAL
	MOVE B,FILBYN(JFN)
	CAML B,FILLEN(JFN)
	JRST DSKSEI		;CHECK FOR EOF
	TQNE <WNDF>		; Has window been set up yet?
	CALL SETWND		; No, set it up
	SOSGE FILCNT(JFN)
	 JRST DSKSI1		;TRY FOR NEW WINDOW
	ILDB A,FILBYT(JFN)	; Get next byte
	AOS FILBYN(JFN)		; Count bytes
	RET

; Disc sequential output
; Call:	JFN	; Job file number
;	STS	; File status
;	FIL BYT ETC SET UP
;	A	; A byte
;	CALL DSKSQO

DSKSQO:	SE1CAL
	TQNE <WNDF>		; Has a window been set up?
	CALL SETWND		; No, set it up
	SOSGE FILCNT(JFN)
	JRST [	CALL NEWWND	;SETUP NEW WINDOW
		 RET		;LOST - RETURN ERROR INFO
		SOS FILCNT(JFN)	;COUNT THIS BYTE
		JRST .+1]
	IDPB A,FILBYT(JFN)	; Deposit the byte
	AOS B,FILBYN(JFN)	; Count bytes
	CAMGE B,FILLEN(JFN)	; Beyond the end?
	RET			; No, done.
	TQO <EOFF>		; Yes, set eoff
	MOVEM B,FILLEN(JFN)	; Update new length
	CALLRET UPDLEN		; UPDATE OFN LENGTH
;DISK SEQUENTIAL INPUT EOF CHECK
;C(B) := FILBYN

DSKSEI:	CALL GETLEN		;GET ACTUAL LENGTH
	CAML B,FILLEN(JFN)	;OVER REAL EOF?
	JRST [	TQO <EOFF>	;YEP, RETURN FLAG
		RET]
	SETZM FILCNT(JFN)	;CLEAR COUNT
	JRST DSKSQI		;AND TRY AGAIN

DSKSI1:	CALL NEWWND		;GET NEW WINDOW
	 RET			;LOST, ERROR ALREADY SET
	MOVE B,FILLEN(JFN)
	SUB B,FILBYN(JFN)	;COMPUTE BYTES LEFT IN FILE
	CAMGE B,FILCNT(JFN)	;THIS BUFFER PASSES EOF?
	MOVEM B,FILCNT(JFN)	;YES, REDUCE BUFFER COUNT
	JRST DSKSQI		;TRY AGAIN

;ROUTINE TO CALCULATE CORRECT # OF BYTES IN THIS PAGE

ADJCNT:	LDB A,PBYTSZ		; Get current byte size
	MOVEI C,^D36
	IDIV C,A		; Get bytes per word
	IMULI C,1000		; Get bytes per page
	MOVEM C,FILCNT(JFN)	; Save as count
	MOVN B,FILBYN(JFN)	; Get byte number
	IDIV B,C		; Remainder is negative
	ADDM C,FILCNT(JFN)	; Adjust if not at beginning of page
	RET
; Disk dump io
; A/ IOWD FOR XFER

DSKDMI:	TDZA B,B
DSKDMO:	MOVEI B,1
	SE1CAL
	STKVAR <SVIOWD,SVFLGS,SVIOW1>
	TQNE <NWTF>		;NO-WAIT REQUESTED?
	JRST [	TQO <ERRF>	;NOT SUPPORTED, ERROR
		RETBAD (DUMPX5)] ;ILLEGAL MODE
	MOVEM A,SVIOWD		;SAVE ORIGINAL IOWD
	MOVEM A,SVIOW1		;WORK WORD
	MOVEM B,SVFLGS		;SAVE FLAG
	TQNE <WNDF>
	 CALL SETWND
DMPLP:	SKIPL SVIOW1
	JRST [	MOVE A,SVIOWD	;RECOVER ORIGINAL WORD
		RETSKP]
	MOVE B,FILBYN(JFN)
	SKIPN SVFLGS		;WRITING?
	CAMGE B,FILLEN(JFN)	; Or not past eof
	SKIPA			; Is ok
	 JRST DSKDEI		;CHECK REAL EOF
	SOSGE FILCNT(JFN)
	 JRST DSKDI1		;NEW WINDOW
	AOS FILCNT(JFN)
	HLRE A,SVIOW1		; IOWD COUNT
	MOVMS A			; Magnitude
	CAML A,FILCNT(JFN)
	 MOVE A,FILCNT(JFN)	; Keep lesser of the two
	MOVE C,A		; Keep copy of count
	ADDB A,FILBYN(JFN)	; Update filbyn
	CAML A,FILLEN(JFN)
	 CALL [	MOVEM A,FILLEN(JFN)
		CALLRET UPDLEN]	;UPDATE LENGTH
	MOVN A,C		; Neg of count
	ADDM A,FILCNT(JFN)	; Decrease filcnt
	MOVE A,FILBYT(JFN)	; Get copy of byte pointer
	ADDM C,FILBYT(JFN)	; Update byte pointer
	IBP A			; Gets loc of first word of file
	HRRZ B,SVIOW1		; GET CORE LOC
	HRRZI B,1(B)		; ADD 1 TO POINTER ;MUST BE HLLI WHEN AVAILABLE
	HRRZS A			; GET RID OF HIGH ORDER BYTE POINTER
	EXCH A,C		; PUT COUNT IN A AND END ADDRESS IN C
	HLRE D,SVIOW1		; GET COUNT
	ADD D,A			; UPDATE THE COUNT
	ADDM A,SVIOW1		; UPDATE IOWD
	HRLM D,SVIOW1		; UPDATE THE COUNT
	SKIPN SVFLGS		; WRITE?
	JRST DMPRED		; NO
	CALL BLTUM
	JRST DMPLP

DMPRED:	EXCH B,C		; GET SOURCE/DEST CORRECT
	CALL BLTMU
	JRST DMPLP

;CHECK ACTUAL EOF FOR DUMP INPUT
;C(B) := FILBYN

DSKDEI:	CALL GETLEN		;GET ACTUAL OFN LEN
	CAML B,FILLEN(JFN)	;OVER EOF
	JRST [	TQO <EOFF>
		RETBAD (IOX4)]	;YES, RETURN EOF
	SETZM FILCNT(JFN)	;CLEAR COUNT
	JRST DMPLP

DSKDI1:	CALL NEWWND		;NEED NEW WINDOW
	 RET			;LOST, RETURN ERROR
	SKIPE SVFLGS		;WRITING?
	JRST DMPLP		;YES, PROCEED
	MOVE B,FILLEN(JFN)
	SUB B,FILBYN(JFN)	;COMPUTE BYTES LEFT IN FILE
	CAMGE B,FILCNT(JFN)	;THIS BUFFER PASSES EOF?
	MOVEM B,FILCNT(JFN)	;YES, REDUCE BUFFER COUNT
	JRST DMPLP		;NO TRY AGAIN
; Set up a window for a file
; Call:	CALL SETWND

SETWND:	PUSH P,A
	CALL ASGPAG		; Assign a job page
	JRST [	TQO <ERRF>
		POP P,A
		POP P,0(P)	; Pop return off stack
		RET]		; And return one level back
	HRRM A,FILWND(JFN)
	TQZ <WNDF>
	SETZM FILCNT(JFN)	; FORCE NEW WINDOW NEXT OPERATION
	POP P,A
	RET

; Set up pointers to a file , PRESERVES AC(A)
; Call:	FILBYN(JFN)	; File byte number
;	FILBYT(JFN)	; Byte size bits
;	LH(FILWND(JFN))	; Current page number
;	RH(FILWND(JFN))	; File window location
;	ETC.
;	CALL NEWWND	;WILL CREATE LONG FILE PT IF NECESSARY
;OR	CALL NEWWNB	;WILL GIVE ERROR IF LONG FILE PT MUST BE CREATED
;RETURNS +1 ERROR - ENDF OR XQTAF ON
;RETURNS +2 OK

NEWWNB:	TDZA B,B		;NO PT CREATES
NEWWND:	SETO B,			;ALLOW PT CREATES
	SE1CAL
	TQNE <WNDF>
	RETSKP			; Do nothing if no window yet
	STKVAR <NWSAVA,NWSAVB,NWSAVW,NWSAVI>
	MOVEM A,NWSAVA		;PRESERVE A
	MOVEM B,NWSAVB		;SAVE PT FLAG
	LDB A,PBYTSZ		; Get current byte size
	MOVEI C,^D36
	IDIV C,A		; Get bytes per word
	MOVE B,FILBYN(JFN)	; Get current byte number
	CAMLE B,FILLEN(JFN)
	 CALL [	MOVEM B,FILLEN(JFN)
		CALLRET UPDLEN]	;UPDATE OFN LENGTH
	IDIV B,C		; Current word in b, offset in b+1
	IMUL C,A		; Offset times byte size
	MOVN C,C
	ADDI C,^D36
	DPB C,PBYTPO		; Yields byte pointer position
	MOVE C,B
	MOVEM C,NWSAVW		;SAVE FOR LATER
	LSH C,-9		; Get page number
	HLRZ B,FILWND(JFN)	; Get current page number
	TRNE B,777
	CAME B,C
	JRST NEWWNA		; Need to set up a new window
	; ..
NEWWNZ:	MOVE C,NWSAVW		;RESTORE WORD NUMBER
	ANDI C,777		; Get relative to page origin
	HRRZ B,FILWND(JFN)
	IOR B,C			; Get absolute address
	HRRM B,FILBYT(JFN)	; Put into byte pointer
	CALL ADJCNT		; ADJUST FILCNT
	MOVE A,NWSAVA		;RESTORE A
	RETSKP

NEWWNA:	HRRZ B,FILWND(JFN)	;UNMAP WINDOW BEFORE POSSIBLY RELEASING OFN
	SETZ A,
	CALL SETMPG
	HRRZ A,C
	MOVE B,NWSAVB		;GET PT CREATE FLAG
	CALL JFNOF5		; Get ofn.pn for this page
	 JRST [	TQNE <WRTF>	;HAVE WRITE ACCESS?
		SKIPN NWSAVB	;ALLOWING PT CREATES?
		CAIE A,LNGFX1	;NO. OTHER THAN PT CREATE?
		TQOA <ERRF>	;YES. GIVE ERROR
		JRST [	HRRZ B,FILWND(JFN) ;NO.
			SETZM 0(B) ;INVENT A PAGE OF ZEROES
			JRST NEWWNZ] ;AND GO ON, BUT DON'T CHNAGE PN
		MOVE C,NWSAVW	;GET WORD
		MOVE A,NWSAVA	;RESTORE A
		RET]
	MOVEM A,NWSAVI		;SAVE IDENT
	TQNN <WRTF>		;HAVE WRITE ACCESS?
	JRST [	CALL MRPT	;GET ACCESS INFO
		 JFCL		;DON'T CARE YET
		TXNE B,PA%PEX	;DOES THIS PAGE EXIST?
		JRST .+1	;YES. ALLOW MAPPING THEN
		HRRZ B,FILWND(JFN) ;NO. GET WINDOW ADDRESS
		SETZM 0(B)	;CREATE A PAGE OF ZEROES
		JRST NEWNA1]	;AND PROCEED
	HRRZ B,FILWND(JFN)
	HRLI B,(PTRW)
	MOVE A,NWSAVI		;GET IDENT
	CALL SETMPG		; Map the the page
	TQNN <WRTF>		;WRITING?
	JRST NEWNA1		;NO - PROCEED
	HRRZ A,FILWND(JFN)	;YES - CHECK EXISTENT PAGE
;TCO 1855 - DONT WRITE THE FILE PAGE AT NEWWNA
	SKIP 0(A)		;TOUCH IT
	ERJMP NEWWNQ		;JUMP IF ACCESS ERROR
NEWNA1:	MOVE C,NWSAVW		;GET DESIRED WORD
	LSH C,-9		;MAKE INTO PAGE #
	HRLM C,FILWND(JFN)
	JRST NEWWNZ		; And finish up

;HERE ON ERROR - CHECK REASON

NEWWNQ:	MOVE A,NWSAVI		;GET IDENT
	CALL MRPACS		;GET ACCESS INFO
	MOVE C,NWSAVW		;RESTORE WORD NUMBER
	TXNE A,PA%PEX		;DOES PAGE EXIST
	TQOA <ERRF>		;YES - ILLEGAL WRITE THEN
	TQO <XQTAF>		;NO - QUOTA EXCEEDED
	HRRZI A,JSKP		;SCHEDULER NO-OP
	RET			;RETURN
; New page table for long file
; C/ DESIRED PT NUMBER
;A/ PT CREATE FLAG

NEWLFP:	SE1CAL
	TRVAR <NLFPN,NLFT1,NLFT2,NLFLG> ;PAGE NO, TEMPS
	MOVEM A,NLFLG		;SAVE ENTRY FLAG
	MOVEM C,NLFPN
	TQNE <LONGF>		; Is this file already long?
	JRST NEWLFT		; Yes, no sweat
	SKIPE NLFLG		;ALLOWED TO CREATE PAGE TABLES?
	TQNN <WRTF>		;FILE OPEN FOR WRITE?
	RETBAD LNGFX1		;NO, WRONG
	CALL GETFDB		; No, let's get the fdb
	BUG(HLT,GTFDB2,<NEWLFP: GETFDB FAILURE FOR OPEN FILE.>)
	MOVE C,.FBCTL(A)	; And see if it's become long
	TXNE C,FB%LNG		; Since we opened it
	JRST NEWFLL		; Yes, it has
	TXNE C,FB%DIR		; IS THIS A DIRECTORY FILE?
	JRST [	CALL USTDIR	; YES, DO NOT ALLOW IT TO BECOME LONG
		RET]
	MOVEM A,NLFT1		;SAVE FDB LOCATION
	MOVE A,.FBADR(A)	; Get disc address of pt 0
	TXNN A,FILNB		;NEW FILE?
	JRST NEWLP1		;NO
	HLRZ A,FILOFN(JFN)	;YES, FIX ON DISK BEFORE MAKING LONG
	CALL UPDOFN
	MOVE B,NLFT1		;RECOVER FDB ADR
	MOVX A,FILNB
	ANDCAB A,.FBADR(B)	;CLEAR NEW FILE STATUS
NEWLP1:
	LOAD B,STR,(JFN)	;GET STRUCTURE NUMBER FROM JFN BLOCK
	CALL DSKASN		; Assign a page for the pt table
	 JRST [	CALLRET USTDIR]	;NO ROOM
	MOVEM A,NLFT2		;SAVE IT
	TLO A,(FILNB)		; Mark as new
	CALL NEWLFS		; Assign ofn etc
	 JRST [	MOVE A,NLFT2	;GET DISK ADDRESS
		LOAD B,STR,(JFN) ;GET STRUCTURE NUMBER FROM JFN BLOCK
		CALL DEDSK	; RELEASE IT
		CALL USTDIR
		RET]		; AND GIVE FAIL RETURN
	HRRZ A,FILOFN(JFN)	;GET OFN JUST ASSIGNED
	CALL UPDOFN		;WRITE IT TO DISK
	HLRZ A,FILOFN(JFN)	; GET OFN OF PT
	CALL UPSHR		;DO THE EXTRA COUNT ON PT0
	STOR A,FILP0,(JFN)	;REMEBER OFN OF PT0
	MOVSI C,(FILWB+THAWB)	; WRITE AND THAW
	ANDCAM C,SPTH(A)	; REMOVE FROM SPTH
	MOVE C,NLFT2		;GET DISK ADDRESS
	MOVE A,NLFT1		;GET FDB ADR
	EXCH C,.FBADR(A)	; Store new disc address, get old
	HRRZ B,FILLFW(JFN)	;GET PTT WINDOW ADDRESS
	ANDX C,STGADM		;EXTRACT STG ADDRESS
	IOR C,IMMPTR		;CONSTRUCT STANDARD PTR
	MOVEM C,0(B)		; Store old disc address as pt 0
	HRRZ C,FILOFN(JFN)	;GET PTT OFN
	MOVX D,OFNWRB
	IORM D,SPTH(C)		;NOTE OFN MODIFIED
	MOVX D,FB%LNG
	IORM D,.FBCTL(A)	; Mark .FB as long file
	JRST NEWLF1		; Continue with rest
;NOTE: SUB-PTS IN LONG FILES ARE ALWAYS OPENED WITH THAWB AND FILWB
;=0.  ACCESS IS CONTROLLED BY THE PTT ONLY.

NEWLFS:
	CALL CHKDUD		;CHECK IF DDMP BEING SUPPRESSED
	HLRZ B,FILOFN(JFN)	;GET OLD OFN
	MOVE B,SPTH(B)		;GET SPTH ENTRY (FOR FLAGS)
	ANDX B,THAWB+FILWB	;PRESERVE THESE
	IOR A,B			;IN NEW OFN
	LOAD B,STR,(JFN)	;GET STRUCTURE NUMBER FROM JFN BLOCK
	CALL ASFOFN		; Assign ofn for new disc address
	 RET			; FAIL
BP$006:				;BREAKPOINT FOR  MAKE NEW PTT FOR LONG FILE
				;SEE ASSUMPTIONS FOR BP$003
	HRRM A,FILOFN(JFN)	; Save
	CALL ASGPAG		; Get a page to map the pt table
	 JRST [	HRRZ A,FILOFN(JFN)
		HLLZS FILOFN(JFN)
		CALL RELOFN
		RET]
	HRRM A,FILLFW(JFN)	; Store location of pt table
	MOVE B,A
	HRLI B,(PTRW)
	HRRZ A,FILOFN(JFN)
	CALL SETMPG
	HLRZ B,FILOFN(JFN)	;OLD JFN
	MOVE B,OFNLEN(B)	;COPY OFN LENGTH ENTRY
	MOVEM B,OFNLEN(A)	; TO PTT ENTRY
	RETSKP

NEWFLL:	MOVE A,.FBADR(A)	; File became long since we opened
	CALL NEWLFS		; Map the pt table
	 CALLRET USTDIR		;FAILED
	HLRZ T1,FILOFN(JFN)	;DO THE EXTRA COUNT ON PT0
	CALL UPSHR
	STOR A,FILP0,(JFN)	;REMEMBER PT0
NEWLF1:	CALL USTDIR		; Finished with directory
	TQO <LONGF>

;HERE IF PTT EXISTS

NEWLFT:	HRRZ B,FILLFW(JFN)	; Get location of pt table
	ADD B,NLFPN		; Offset by pt # to get disc addr
	NOSKED			; To prevent others from tampering
	LOAD A,STGADR,0(B)	;GET ADR OF DESIRED PT
	JUMPN A,NEWLFA		;JUMP IF EXISTENT
	SKIPE NLFLG		;ALLOWED TO CREATE PT'S?
	TQNN <WRTF>		;FILE OPEN FOR WRITE?
	RETBAD (LNGFX1,<OKSKED>) ;NO. PREVENT PAGE TABLE CREATION
	MOVEM B,NLFT2		;SAVE PTR ADDRESS
	HLRZ A,FILOFN(JFN)	; Get ofn of pt table
	MOVE A,SPTH(A)		; Get disc address of pt table
	LOAD B,STR,(JFN)	;GET STRUCTURE NUMBER FROM JFN BLOCK
	CALL DSKASN		; Get a new disc address
	 JRST [	OKSKED
		RET]
	MOVEM A,NLFT1		;SAVE DISK ADR
	TXO A,FILNB		;NOTE NEW XB
	CALL CHKDUD		;CHECK IF DDMP BEING SUPPRESSED
	LOAD B,STR,(JFN)	;GET STRUCTURE NUMBER FROM JFN BLOCK
	CALL ASFOFN		; Assign ofn for new ib
	 JRST [	MOVE A,NLFT1	;GET DISK ADDRESS
		LOAD B,STR,(JFN) ;GET STRUCTURE NUMBER FROM JFN BLOCK
		CALL DEDSK	;GIVE IT BACK
		OKSKED
		RET]
	; ..
;NEWLFT...

BP$008:				;BREAKPOINT FOR MAKE NEW PT IN LONG FILE
				;ASSUMES PT-# IN  -2(P)
				;SEE ASSUMPTIONS FOR BP$003

	CALL UPDOFN		;WRITE IT TO DISK
	CALL RELOFN
	MOVE A,NLFT1		;GET DISK ADDRESS
	MOVE B,NLFT2		;GET PTR ADDRESS
	IOR A,IMMPTR		;CONSTRUCT STANDARD PTR
	MOVEM A,(B)
	MOVEM A,NLFT1		;SAVE PTR
	HRRZ A,FILOFN(JFN)	;GET PTT OFN
	MOVX B,OFNWRB
	IORM B,SPTH(A)		;NOTE IT CHANGED
	OKSKED			;INCASE PTT IS LOCK AND WE HAVE TO WAIT
	CALL UPDOFN		;UPDATE PTT FOR NEW PT WITHIN IT
	MOVE A,NLFT1		;GET PTR
	JRST NEWLFB		;SKIP OKSKED

;HERE IF NEW PT EXISTS

NEWLFA:	OKSKED
NEWLFB:	MOVEM A,NLFT1		;SAVE DSK ADR
	HLRZ A,FILOFN(JFN)	;GET OFN OF OLD PT
	CALL UPDOFN		;WRITE IT TO DISK BEFORE RELEASING
	MOVE A,NLFT1		;GET DISK ADR
	ANDX A,STGADM		;EXTRACT STG ADDRESS
	CALL CHKDUD		;CHECK IF DDMP BEING SUPPRESSED
	LOAD B,STR,(JFN)	;GET STRUCTURE NUMBER FROM JFN BLOCK
	TXO A,OFN2XB		;FLAG AS SECOND LEVEL XB (TEMP)
	CALL ASLOFN		;ASSIGN LONG PT OFN
	 RET			;FAIL
	HLRZ B,FILOFN(JFN)	;GET OFN FOR OLD PAGE
BP$009:				;BREAKPOINT FOR GET EXISTING PT IN LONG FILE
				;ASSUMES  PT-# IN 0(P)
				;SEE ASSUMPTIONS FOR BP$003
	HRLM A,FILOFN(JFN)	;SET NEW OFN
	MOVE A,B		;RELEASE OLD OFN
	CALL RELOFN
	MOVE C,NLFPN		;RESTORE PN TO C
	RETSKP

;ROUTINE TO CHECK IF THIS FILE OPENING IS SUPPRESSING DDMP. WILL
;SET OFNDUD BIT IN A IF SO

CHKDUD:	TQNE <FILDUD>		;WAS OF%DUD SET ON OPEN?
	TXO A,OFNDUD		;YES. REQUEST IT IN THE ASOFN CALL
	RET			;AND DONE
; Convert jfn.pn to ofn.pn
; Call:	LH(A)	; Jfn
;	RH(A)	; Page number
;	B	; PT CREATE FLAG IF ENTRY IS AT JFNOF4
;	CALL JFNOFN
;OR	CALL JFNOF4
; Return
;	+1	; Error, illegal jfn or page number too big
;	+2	; Ok
;	LH(A)	; Ofn
;	RH(A)	; Page number
;	B/ JFN STATUS

JFNOFN::SETO B,			;ASSUME CAN CREATE PT OF USER HAS WRITE ACCESS
JFNOF4::SAVEP
	SE1CAL
	CALL JFNOF0		;DO THE ACTUAL WORK
	 RET			;FAILED
	MOVE B,STS		;RETURN STS IN B
	RETSKP			;DO SKIP RETURN UNLESS SOS ABOVE

JFNOF0:	HLRZ JFN,A
	PUSH P,B		;SAVE PT CREATE FLAG
	PUSH P,A
	CALL DSKJFN		;CHECK FOR A DISK JFN
	 JRST [	POP P,ERRSAV	;WASN'T
		POP P,0(P)	;CLEAN UP THE STACK
		RETBAD()]
	POP P,A
	POP P,B			;GET BACK PT CREATE FLAG
	TQNN <OPNF>
	JRST [	MOVEI A,DESX5
		JRST UNLCKF]
	HRRZS A
	CALL JFNOF5
	 JRST .+2
	AOS (P)
	JRST UNLCKF
;ROUTINES TO CONVERT FROM JFN.PN TO OFN.PN AS FOLLOWS:
;	JFNOF3		;ERROR IF LONG FILE PT MUST BE CREATED
;	JFNOF1		;WILL CREATE LONG FILE PT IF NECESSARY
;	JFNOF5		;B= 0 IF LONG FILE PT SHOULD BE AN ERROR
			;B=NON-ZERO IF LONG FILE PAGE TABLE MAY BE
			; CREATED

JFNOF3::TDZA B,B		;REMEBER NO PAGE TABLE CREATE
JFNOF1::SETO B,			;CAN CREATE PAGE TABLE
	SE1CAL
JFNOF5:	TLNE A,777777
	RET
	PUSH P,B		;SAVE ENTRY FLAG
	PUSH P,A
	MOVEI A,0(JFN)		;GET JFN
	CALL DMOCHK		;MAKE SURE STILL MOUNTED
	 JRST [	SUB P,BHC+2	;CLEAN UP STACK
		RET]		;AND GIVE ERROR
	MOVE A,0(P)		;RESTORE ARG
	HLRZ B,FILWND(JFN)	; Get current page number
	XOR B,A
	TRNN B,777000		; If different page tables
	JRST JFNOF2
	LSH A,-9		; Need special action
	MOVE C,A
	MOVE A,-1(P)		;GET ENTRY FLAG
	CALL NEWLFP		; Change current page
	 JRST [	SUB P,BHC+2
		RET]
	SETZM FILCNT(JFN)	; Force any sequential io to remap
JFNOF2:	MOVE A,(P)
	TRZ A,777
	HRLM A,FILWND(JFN)
	POP P,A
	POP P,0(P)		;CLEAN UP STACK
	HLL A,FILOFN(JFN)
	ANDCMI A,777000		; Mask out pt number
	RETSKP
; Convert ofn.pn to jfn.pn
; Call:	LH(A)	; Ofn, 1B0 SAYS FIND ONLY JFN WITH PAGES MAPPED
;	RH(A)	; Pn
;	CALL OFNJFN
; Return
;	+1	; No jfn found
;	+2	; Ok
;	A	; Jfn.pn
; CALL OFNJFX  TO FIND ONLY JFN WITH PAGES MAPPED

OFNJFX::TLO A,400000		;SAY ONLY JFN'S WITH MAPCOUNT .G. 0
OFNJFN:: SE1CAL
	PUSH P,JFN		;SAVE PRESERVED AC'S
	PUSH P,STS
	CALL OFNJF0		;DO THE ACTUAL WORK
	 SOS -2(P)		;HANDLE FAIL RETURN
	POP P,STS
	POP P,JFN		;RESTORE PRESERVED AC'S
	RETSKP			;DO SKIP RETURN UNLESS SOS ABOVE

OFNJF0:	PUSH P,A
	HLRZS A
	ANDI A,377777
	MOVE B,A		;GET OFN IN B
	CALL CHKDMO		;SEE IF THIS OFN HAS BEEN DISMOUNTED
	 JRST [	POP P,0(P)	;CLEAN UP STACK
		RETBAD (PMAPX7)] ;DISMOUNTED
	PUSH P,A
OFNJF7:	NOINT
	LOCK(JFNLCK,<JRST [
		OKINT
		MOVEI A,^D500
		DISMS
		JRST .-2]>)
	MOVE JFN,MAXJFN
	SOS JFN
	IMULI JFN,MLJFN		; CONVERT TO INTERNAL VALUE
OFNJF1:	MOVEI A,0(JFN)		;GET JFN
	CALL STRDMO		;CHECK IF DISMOUNTED AND BUMP SDB LOCK
	 JRST OFNJF2		;IT IS DISMOUNTED
	MOVE STS,FILSTS(JFN)
	HRRZ A,FILDEV(JFN)
	CAIE A,DSKDTB
	JRST OFJF22		;NOT USABLE
	MOVE A,FILLFW(JFN)
	TLNN A,777776		;IF PAGE MAP CNT .G. 0, CHECK OPNF
	SKIPL -1(P)		;OTHERWISE, CHECK OPNF ONLY IF B0=0
	TQNN <OPNF>
	JRST OFJF22		;NOT USABLE
	TQNE <LONGF>
	JRST OFNJF3
	HLRZ A,FILOFN(JFN)
	CAME A,(P)
	JRST OFJF22		;NOT USABLE
OFNJF6:	PUSH P,B		;SAVE B
	MOVE A,JFN		; MOVE JFN
	CALL LUNLK0		;DECR SDB LOCK
	IDIVI A,MLJFN		;CONVERT TO EXTERNAL INDEX
	POP P,B			;RESTORE B
	SKIPN NSKED		;IS THIS PROCESS NOSKED?
	SKIPGE FILLCK(JFN)	;NO. IS JFN LOCK FREE?
	SKIPA			;OK TO DO IT
	JRST [	UNLOCK JFNLCK	;FREE UP JFN LOCK
		LOCK FILLCK(JFN) ;WAIT FOR JFN LOCK TO BE AVAIALBLE
		UNLOCK FILLCK(JFN) ;FREE IT
		OKINT		;ALLOW INTS JUST IN CASE
		JRST OFNJF7]	;AND TRY AGAIN
	MOVE JFN,A		;BACK TO JFN
	POP P,A			;CLEAN UP THE STACK
	POP P,A
	HRL A,JFN
	UNLOCK JFNLCK
	OKINT
	RETSKP
;THIS JFN HAS LONG FILE OPEN.  MUST SCAN PTT TO SEE IF IT CONTAINS
;SAME PT ADDRESS AS REQUESTED OFN

OFNJF3:	MOVE A,(P)		; Get ofn
	PUSH P,B
	PUSH P,C
	LOAD C,STGADR,SPTH(A)	;GET DISK ADR OF XB FOR OFN
	MOVSI B,-PGSIZ
	HRR B,FILLFW(JFN)
OFNJF4:	LOAD A,STGADR,0(B)	;GET XB ADR FOR PT
	CAMN A,C		;SAME AS REQUESTED OFN?
	JRST OFNJF5
	AOBJN B,OFNJF4
	POP P,C
	POP P,B
	JRST OFJF22		;NOT USABLE

OFNJF5:	POP P,C
	SUB B,FILLFW(JFN)	; Get pt number
	HRRZS B
	LSH B,9			; Convert to page offset
	ADDM B,-2(P)		; Augment page number
	POP P,B
	JRST OFNJF6

OFJF22:	MOVEI A,0(JFN)		;GET THE JFN
	CALL LUNLK0		;FREE SDB LOCK
OFNJF2:	SUBI JFN,MLJFN		; To next jfn index
	JUMPGE JFN,OFNJF1
	POP P,A
	POP P,A
	UNLOCK JFNLCK
	OKINT
	RET
;SPECIAL ROUTINE CALLED FROM CLOSF LOGIC TO UNMAP WINDOW PAGES OF
;A FILE IF IT WON'T CLOSE PROPERLY. SPECIFICALLY AIMED AT PREVENTING
;EXE FILES FROM TYING UP SWAPPING SPACE WHEN THEY CAN'T BE CLOSED
;BECAUSE PAGES ARE STILL MAPPED.
;ACCEPTS:	JFN/ THE JFN

DEWNDW::SE1CAL
	TQOE <WNDF>		;THIS FILE HAVE A WINDOW PAGE?
	RET			;NO
	HRRZ A,FILWND(JFN)	;YES. GET THE ADDRESS
	HLLZS FILWND(JFN)	;CLEAR WINDOW PAGE INDICATION
	CALLRET RELPAG		;RELEASE IT AND RETURN
; Disk close
; Call:	A/ CZ%ABT - DELETE NONX FILE
;	JFN	; Job file number
;	CALL DSKCLZ

DSKCLZ:	SE1CAL
	TRVAR <DMFLG,DSKCFD>	;REMEMBER OF STRUCTURE IS DISMOUNTED
	PUSH P,F		;PRESERVE F
	MOVEM A,F		;SAVE FLAG ARG
	SETZM DMFLG		;ASSUME NOT DISMOUNTED
	MOVEI A,0(JFN)
	CALL DMOCHK		;SEE IF DISMOUNTED
	 JRST [	SETOM DMFLG	;IT IS. REMEBER THIS
		TXNE F,CZ%ABT	;WANT AN ABORT CLOSE?
		JRST .+1	;YES. PROCEED
		MOVE A,F	;NO
		POP P,F		;RESTORE FLAGS
		RETBAD (DESX10)] ;AND GIVE ERROR
DSKCL9:	HRRZ A,FILWND(JFN)	; If window page exists
	JUMPE A,DSKCL2
	CALL RELPAG		; Return page to free list
DSKCL2:	CALL GETLEN		;UPDATE FILLEN BEFORE CLOSE
	SKIPE DMFLG		;DISMOUNTED STRUCTURE?
	JRST DSKCL6		;YES. GO AROUND UPDATE
	CALL GETFDB		;NO. FIND THE FDB
	 JRST [	SETZM DSKCFD	;FDB IS GONE.
		JRST DSKCL6]
	MOVEM A,DSKCFD		;SAVE FDB ADDRESS FOR LATER
	TQNN <WNDF>		;HAVE A WINDOW YET?
	TQNN <WRTF>		;OPEN FOR WRITE?
	JRST DSKCL6		;NO. NO UPDATE OF EOF THEN
	LDB B,PBYTSZ		;GET OPEN BYTE SIZE
	STOR B,FBBSZ,(A)	;SAVE IT IN FDB
	LDB B,PFLMOD		;GET MODE
	STOR B,FBMOD,(A)	;SAVE IN THE FDB
	SKIPE B,FILLEN(JFN)	;HAVE SOME BYTES?
	MOVEM B,.FBSIZ(A)	;YES. COPY IT TO THE FDB
DSKCL6:	TQNE <LONGF>		;THIS A LONG FILE?
	JRST CNTLNG		;YES
	HLRZ A,FILOFN(JFN)	; Get ofn
	TQNE <WRTF>		;WAS FILE OPEN FOR WRITE?
	TXO A,FILWB		;YES, PROPAGATE BIT
	CALL RELOFN
	; ..
;DSKCLZ...

DSKCL0:	SKIPE DMFLG		;A DISMOUNTED STRUCTURE?
	JRST DSKCL1		;YES. ALL DONE THEN
	PUSH P,A		; Save page count
	CAMN A,[-1]		; DID IT GET CLOSED?
	SETZ B,			; NO. IGNORE THE FLAGS THEN
	SKIPN A,DSKCFD		;HAVE AN FDB?
	JRST [	SUB P,BHC+1	;NO. CLEAN UP STACK
		JRST DSKCL5]	;AND GO FINISH UP
	MOVX C,FB%BAT		;THE BIT FOR A BAD FILE
	TXNE B,OFNBAT!OFNERR	;AN ERROR IN THIS FILE?
	IORM C,.FBCTL(A)	;YES. MARK IT THEN
	TQNN <WRTF>		;OPEN FOR WRITE?
	JRST DSKCL4		;NO
	CALL UPDDTM		;UPDATE THE LAST DIR CHANGE TIME
	MOVE B,A		;SAVE TIME
	MOVE A,DSKCFD		;GET BACK FDB ADDRESS
	CAME B,[-1]		;DATE SET YET?
	STOR B,FBCRE,(A)	;YES, SET WRITE DATE
DSKCL4:	POP P,B			;RECOVER PAGE COUNT
	SKIPL B
	JRST [	PUSH P,B
		PUSH P,C
		MOVE D,DIRORA	;GET BASE ADR OF DIRECTORY
		LOAD C,FBNPG,(A) ;GET OLD PAGE COUNT FOR THIS FILE
		SUB B,C		;COMPUTE NET CHANGE
		LOAD C,DRDCA,(D) ;GET CURRENT PAGE COUNT FOR DIR
		ADD B,C		;COMPUTE NEW PAGE COUNT FOR DIRECTORY
		STOR B,DRDCA,(D) ;STORE UPDATED COUNT
		POP P,C
		POP P,B
		STOR B,FBNPG,(A) ;SET PAGE COUNT FOR FILE
		JRST .+1]
	MOVX B,FILNB
	ANDCAM B,.FBADR(A)	;NOTE XB ADDRESS NOW VALID
	MOVX B,FB%NXF
	TDNN B,.FBCTL(A)	;DOES FILE ALREADY EXIST?
	JRST DSKCD2		;YES, NO FLUSH OR VERSIONS CHECK
	TXNE F,CZ%ABT		;CALLER WANTS FLUSH NONX FILES?
	JRST [	MOVE D,A	;YES, SET UP CALL DELFIL
		CALL DELFIL	;DELETE CONTENTS OF FILE
		 JFCL		;COULDN'T, IGNORE
		CALL USTDIR	;UNLOCK DIRECTORY
		JRST DSKCL5]	;FILE DELETED, NOTHING FURTHER TO DO
	ANDCAM B,.FBCTL(A)	;MAKE FILE EXISTENT
	TQZ <NONXF>		;MARK THAT THE FILE IS NOW EXISTENT
DSKCD2:	TQNE <WRTF>		;IF FILE WAS OPEN FOR WRITE,
	CALL DSKDV		;DELETE ANY EXCESS VERSIONS
DSKCL3:	TXNN F,CZ%NUD		;NO UPDATE DIR?
	CALL UPDDRR		;UPDATE DIRECTORY
	CALL USTDIR
DSKCL5:	LOAD B,STR,(JFN)	;GET INDEX INTO STRTAB
	MOVE B,STRTAB(B)	;GET POINTER TO SDB
	DECR STROF,(B)		;DECREMENT OPEN FILE COUNT
DSKCL1:	MOVE A,F		;GET BACK THE FLAGS
	POP P,F
	RETSKP			;YES, GIVE SUCCESS RETURN
;DELETE EXCESS VERSIONS AFTER CLOSE OR RENAME
; 1/ PTR TO FDB

DSKDV:	SAVEQ
	SE1CAL
	STKVAR <DSKDVA,DSKDVJ>
	LOAD Q1,FBGNR,(A)	;GET NUMBER OF VERSIONS TO RETAIN
	JUMPE Q1,R		;0 MEANS INFINITY
	MOVEM A,DSKDVA		;SAVE THE ORIGINAL FDB POINTER
DSKCD3:	MOVE C,.FBCTL(A)	;LOOK AT THIS VERSION
	TXNE C,FB%TMP+FB%NXF+FB%DEL ;THIS A 'GOOD' VERSION?
	JRST DSKCD1		;NO, DON'T COUNT IT
	SOJGE Q1,DSKCD1		;PASSED N GOOD VERSIONS?
	MOVEM A,DSKDVJ		;YES, SAVE THIS FDB ADR
	MOVX B,FC%WR		;B/WRITE ACCESS
	CALL ACCCHK		;CHECK FOR WRITE ACCESS ON THIS FILE
				; (NEEDED FOR DELETING)
	 JRST DSKCD4		;NOT PRIVILEGED TO DELETE THIS FILE
	MOVE A,DSKDVJ		;GET FDB ADR BACK AGAIN
	MOVX C,FB%DEL		;DELETE THIS ONE
	IORM C,.FBCTL(A)
DSKCD1:	LOAD A,FBGNL,(A)	;GET NEXT VERSION IN LIST
	JUMPE A,DSKCD4		;0 MEANS END OF LIST, RECOVER ORIG FDB
	ADD A,DIRORA		;INCLUDE OFFSET
	JRST DSKCD3		;LOOP OVER VERSIONS

DSKCD4:	MOVE A,DSKDVA		;GET ORIGINAL FDB ADR AGAIN
	RET			;AND EXIT
;CHECK IF ACCESS TO FILE IS LEGAL BECAUSE FILE IS NEW
; A/ PTR TO FDB
;RETURNS +1:	NO ACCESS 
;	 +2:	ACCESS IS LEGAL

NFACHK::JN FBNXF,(A),NFACK0	;IF FILE NON-EXISTENT, ALLOW OWNERSHIP
	SKIPE .FBADR(A)		;FILE EXISTS?
	RET			;YES - USE ACCESS BITS
NFACK0:	LOAD B,FBVER,(A)	;NO - CHECK FDB VERSION
	CAIGE B,1		;...
	JRST [	MOVE B,JOBNO	;OLD FDB - USE DIR #
		HRRZ B,JOBDIR(B)
		LOAD C,FBAT0,(A) ;VERSION #0 AUTHOR
		CAME B,C	;ARE WE THE CREATOR
		RET		;NO - USE ACCESS BITS
		RETSKP]		;YES - ACCESS ALLOWED
	LOAD B,FBLWR,(A)	;VER #1 OR LATER - USE LAST-WRITER
	JUMPE B,R		;USE ACCESS BITS IF NONE
	ADD B,DIRORA		;RELOCATE STRING PNTR
	LOAD C,UNLEN,(B)	;GET BLOCK LENGTH
	HRRZ D,USRNAM		;USER NAME STRING LENGTH
	CAIE C,1(D)		;SAME LENGTH?
	RET			;NO - NO FURTHER CHECKING REQ'D
	ADDI B,2		;POINT TO STRING BEG
	MOVNI C,-2(C)		;LENGTH OF STRING TO COMPARE
	HRLZS C			;MOVE TO LHS
	HRRI C,USRNAM+1		;FORM AOBJN PNTR
NFACK1:	MOVE D,0(C)		;FETCH A WORD
	CAME D,0(B)		;COMPARE
	RET			;FAIL IF NO MATCH
	AOS B			;STEP TO NEXT WORD
	AOBJN C,NFACK1		;LOOP TILL DONE
	RETSKP			;SUCCESS RETURN
;HERE TO CLOSE LONG FILE--FIRST COUNT PAGES

CNTLNG:	LOAD A,FILP0,(JFN)	;GET OFN OF PT0
	CALL RELOFN		;UNDO EXTRA COUNT
   REPEAT 0,<			;UNNEEDED INSTRUCTIONS FOLLOW
	SKIPE DMFLG		;A DISMOUNTED STRUCTURE?
	JRST CNTLN5		;YES
	SETZ A,			;GET BACK TO PT0
	CALL JFNOF1
	 BUG(HLT,DNOPT0,<DSKCLZ-JFNOFN FAILED FOR PAGE 0>)
   >				;END OF REPEAT 0
CNTLN5:	HLRZ A,FILOFN(JFN)	;GET PT0 OFN
	CALL RELOFN		; Release
	HRRZS FILOFN(JFN)
	SKIPE DMFLG		;A DISMOUNTED STRUCTURE?
	JRST CNTLN4		;YES
	JUMPL A,CNTLN4		; If still in use, skip counting
	MOVSI C,-PGSIZ		; Count thru 1000 page tables
	HRR C,FILLFW(JFN)	; At fillfw
	SETZ Q3,		; Total count
	SETZ B,			;NO FLAGS TO START
	PUSH P,B		;SAVE AACUMULATED FLAGS
CNTLNL:	LOAD A,STGADR,0(C)	;GET PT ADR
	JUMPE A,CNTLN1		;JUMP IF NO PT HERE
	PUSH P,C
	LOAD B,STR,(JFN)	;GET STRUCTURE NUMBER FROM JFN BLOCK
	CALL ASFOFN		; Have to assign ofn for it to map
	 JRST CNTLN2		; If failure, skip rest of counting
	CALL RELOFN		; Now release which will count pages
	JUMPL A,CNTLN2		; If any page table busy, stop
	ADD Q3,A		; Add into sum
	POP P,C
	IORM B,0(P)		; INCLUDE THESE FLAGS
CNTLN1:	AOBJN C,CNTLNL
	POP P,B			;THE FLAGS
	JRST CNTLN3

CNTLN2:	POP P,C
	POP P,B			; FLAGS
CNTLN4:	SETO Q3,		; Remember we have no valid page count
	SETZ B,			; NO FLAGS IF HERE
CNTLN3:	PUSH P,Q3		; Save
	PUSH P,B		; SAVE THE FLAGS
	HRRZ B,FILLFW(JFN)
	SETZ A,
	CALL SETMPG		; Remove ptt from map
	HRRZ A,FILLFW(JFN)
	CALL RELPAG		; And release storage
	HLLZS FILLFW(JFN)
	HRRZ A,FILOFN(JFN)
	TQNE <WRTF>		;WAS FILE OPEN FOR WRITE?
	TXO A,FILWB		;YES, PROPAGATE BIT
	CALL RELOFN		; Release ofn of ptt
	HLLZS FILOFN(JFN)
	POP P,B			; THE FLAGS
	POP P,A
	JRST DSKCL0
;DELETE PARTICULAR FILE
; D/ PTR TO FDB OF FILE (ABSOLUTE ADDRESS)
;	CALL DELFIL
;RETURNS +1:	AN ERROR OCCURED AND THE FDB WAS NOT DELETED
;	 +2:	SUCCESSFUL

DELFL1:	TDZA A,A		;ENTRY IS HERE
DELFIL::SETO A,			;ENTRY AT DELFIL
	SE1CAL
	JN FBDIR,(D),[RETBAD (DLFX11)] ;CAN'T DELETE DIRECTORY FILE
	TRVAR <DELFLG>		;REMEMBER ENTRY
	MOVEM A,DELFLG		;STORE ENTRY FLAG
	PUSH P,P3
	PUSH P,F
	PUSH P,Q3
	PUSH P,D
	OPSTR <SKIPN P3,>,FBADR,(D)	;GET INDEX BLOCK ADR
	JRST DELFI3		;WASN'T ONE
	SETZRO FBADR,(D)	;REMOVE XB ADR FROM DIR
	CALL UPDDIR		;UPDATE DIRECTORY, FILE IS EFFECTIVELY
	MOVE A,P3		; GONE AFTER THIS POINT.
	TXNE A,FILNB		;WAS IT A NEW FILE?
	JRST [	LOAD B,CURSTR	;GET STRUCTURE NUMBER FROM PSB
		CALL CHKOFN	;YES, STILL BUSY?
		 SKIPA D,0(P)	;YES, CAN'T EXPUNGE IT. RECOVER FDB ADR
		JRST DELFI3	;NOT BUSY, MUST BE LEFT FROM CRASH. 
		STOR P3,FBADR,(D) ;PUT ADR BACK INTO FDB
		MOVEI A,DELFX2	;FILE BUSY
		JRST DELFIX]	;SKIP THIS FILE
	TLO A,(THAWB)
	CALL GASOG		;GET ASOFN ARGS
	CALL ASGOFN		;OPEN SO NO OTHER ACCESS
	 JRST [	CAIN A,OPNX16
		JRST DELFI3	; Bad index block, forget it
		MOVE D,0(P)	;FILE IS OPEN, CANNOT EXP. GET FDB ADR.
		STOR P3,FBADR,(D) ;PUT ADR BACK INTO FDB
		MOVEI A,DELFX2	;FILE OPEN
		JRST DELFIX]	;SKIP THIS FILE
	MOVE D,(P)
	PUSH P,A
	MOVE A,D		;GET ADR OF FDB
	LOAD Q3,FBNPG,(A)	;GET PAGE COUNT OF FILE
	MOVE A,DIRORA		;GET BASE ADR OF DIR
	LOAD F,DRDCA,(A)	;GET CURRENT ALLOCATION
	SUB F,Q3		;REDUCE DIR COUNT BY FILE BEING DELETED
	STOR F,DRDCA,(A)	;UPDATE COUNT
	POP P,A
	MOVE Q3,.FBCTL(D)
	TXNE Q3,FB%LNG
	JRST DELFI4		; Long file
	CALL DELPT
DELFI3:	MOVE D,(P)
	SETZM .FBADR(D)
	SETZM .FBSIZ(D)
	HRLOI B,7777
	ANDCAM B,.FBBYV(D)
	MOVX B,FB%LNG+FB%SHT
	ANDCAB B,.FBCTL(D)
	SKIPE DELFLG		;WANT FDB PRESERVED?
	TXNE B,FB%PRM		;PERMANENT?
	SKIPA			;YES. DON'T DELETE FDB THEN
	JRST [	MOVE A,D	;GET FDB ADDRESS
		CALL DELFDB	;GO DELETE THIS FDB
		 SKIPA		;FAILED
		SETZ A,		;SAY SKIP RETURN
		JRST DELFIX]	;GO DO RETURN
	SETZ A,			;SAY SKIP RETURN
DELFIX:	POP P,D
	POP P,Q3
	POP P,F
	POP P,P3
	JUMPE A,RSKP		;DO SUCCESSFUL RETURN IF A NON-0
	RET			;OTHERWISE FAIL RETURN
;DELETE LONG FILE

DELFI4:	PUSH P,A
	CALL ASGPAG
	 JRST [	POP P,A
		CALL RELOFN
		MOVEI A,DELFX3	;NO ROOM IN JSB
		JRST DELFIX]
	PUSH P,A
	MOVE B,A
	HRLI B,(PTRW)
	MOVE A,-1(P)
	CALL SETMPG
	HRLI B,-PGSIZ
DELFI6:	LOAD A,STGADR,0(B)	;GET PT ADR
	JUMPE A,DELFI5		;JUMP IF NONE
	PUSH P,B
	CALL GASOG		;GET ARGS FOR ASGOFN
	CALL ASGOFN
	 JRST DELFI8
	CALL DELPT
DELFI7:	POP P,B
	SETZM (B)
DELFI5:	AOBJN B,DELFI6
	MOVE B,(P)
	MOVEI A,0
	CALL SETMPG
	POP P,A
	CALL RELPAG
	POP P,A
	CALL DELPT		;DELETE THE PTT
	JRST DELFI3

DELFI8:	CAIN A,OPNX16		;BAD INDEX BLOCK?
	JRST DELFI7		;YES, TREAT AS IF DELETED
	BUG(HLT,ASOFNF,<DELFIL: ASOFN GAVE FAIL RETURN FOR LONG FILE XB>)
;ROUTINE TO SETUP A-D FOR ASGOFN 
;ASSUMES A ALREADY HAS INDEX BLOCK ADDRS AND DIRECTORY MAPPED

GASOG:	PUSH P,A		;SAVE INDX BLOCK
	MOVE A,DIRORA		;DIRECTORY BASE ADDRS
	LOAD A,DRNUM,(A)	;DIRECTORY NUMBER
	LOAD B,CURSTR		;STR NUMBER
	CALL GETCAL		;GET ALLOCATION INFO
	 JRST [	MOVE C,DIRORA	;NO OPEN FILES - GET INFO FROM
		LOAD A,DRLIQ,(C) ; DIRECTORY
		OPSTR <SUB A,>,DRDCA,(C)
		JRST .+1]
	MOVE D,A		;PLACE PAGES LEFT IN D
	LOAD B,CURSTR		;STRUCTURE NUMBER INTO B
	MOVE C,DIRORA
	LOAD C,DRNUM,(C)	;DIRECTORY NUMBER INTO C
	POP P,A			;INDEX BLOCK ADDRS TO A
	RET			;RETURN

;UPDATE FILE LENGTH INFO IN SPT RELATED TABLE
;PRESERVES ALL AC'S, JFN MUST BE SETUP, ETC.

;UPDFLN - ROUTINE TO UPDATE THE LENGTH OF A FILE
;	ACCEPTS IN T1/	BYTE SIZE
;		   T2/	LENGTH
;		CALL UPDFLN
;	RETURNS +1:	ALWAYS - CLOBBERS T1-T4

UPDLEN::SAVET			;SAVE T1-T4
	LDB A,PBYTSZ		;GET THE BYTE SIZE OF THE OPEN
	MOVE B,FILLEN(JFN)	;GET THE LENGTH
	TDZA C,C		;DONT SHRINK THE FILE SIZE

UPDFLN::SETO C,			;SET THIS LENGTH ALWAYS
	STKVAR <UPDFLB,UPDFLL,UPDFLF,UPDFLT>
	SKIPN A			;BYTE SIZE = 0?
	MOVEI A,^D36		;YES, MAKE IT BE 36 BIT BYTES
	MOVEM A,UPDFLB		;SAVE THE BYTE SIZE 
	MOVEM B,UPDFLL		;SAVE LENGTH
	MOVEM C,UPDFLF		;SAVE FLAG
	HRRZ A,DEV		;GET DEVICE DISPATCH
	CAIE A,DSKDTB		;IS IT DISK
	 RET			;NO - JUST RETURN
	HLRZ D,FILOFN(JFN)	;GET OFN
	TQNE <LONGF>		;LONG FILE?
	HRRZ D,FILOFN(JFN)	;YES, USE THIS ONE
	SKIPN OFNLEN(D)		;SET UP YET?
	BUG (HLT,NOLEN,<UPDLEN: NO LENGTH INFO FOR OFN>)
	LOAD A,OFNBSZ,(D)	;GET FILE BYTE SIZE (AT FIRST OPEN)
	MOVE B,UPDFLB		;GET THE BYTE SIZE
	CAMN A,B		;SAME SIZE CAN BE HANDLED FAST
	JRST [	MOVE C,UPDFLL	;GET NEW LENGTH
		JRST UPDLN1]	;STORE IF LARGER
	MOVEM D,UPDFLT		;SAVE THE OFN
	MOVEI C,^D36
	IDIVM C,B		;JFN BYTES/WD
	MOVEI C,^D36
	IDIV C,A		;OFN BYTES/WD
	IMUL C,UPDFLL		;CALC NEW OFN LENGTH
	IDIV C,B
	SKIPE D			;ROUND IF RESIDUE
	ADDI C,1
	MOVE D,UPDFLT		;RESTORE OFN
UPDLN1:	LOAD B,OFNBC,(D)	;GET CURRENT VALUE
	SKIPN UPDFLF		;ALWAYS STORE THE NEW LENGTH?
	CAMGE B,C		;NO, DON'T MAKE SMALLER
	STOR C,OFNBC,(D)	;STORE VALUE
	RET			;RETURN
;ROUTINE TO SET UP NEW OFN LENGTH ENTRY (FDB MUST BE MAPPED)
;C(D) := OFN

OFNSET:	MOVE C,FILFDB(JFN)	;GET FDB ADDRS
	MOVE A,.FBSIZ(C)	;GET LENGTH
	STOR A,OFNBC,(D)	;SAVE IT
	LOAD A,FBBSZ,(C)	;GET FILE BYTE SIZE
	SKIPN A			;IF ZERO
	LDB A,PBYTSZ		; THEN USE JFN BYTE SIZE
	STOR A,OFNBSZ,(D)	;SAVE IT ALSO
	RET

;ROUTINE TO GET ACTUAL FILE LENGTH (IF DISK)

GETLEN::SAVET
	HRRZ A,DEV		;SEE IF DISK
	CAIE A,DSKDTB		;?
	 RET			;NO, RETURN
	HLRZ D,FILOFN(JFN)	;GET OFN
	TQNE <LONGF>		;LONG FILE?
	HRRZ D,FILOFN(JFN)	;YES, USE THIS INSTEAD
	SKIPN OFNLEN(D)		;ONE SETUP YET?
	CALL OFNSET		;NO - SET UP THEN
	LOAD A,OFNBSZ,(D)	;GET OFN BYTE SIZE
	LDB B,PBYTSZ		;GET JFN BYTE SIZE
	CAMN A,B		;FAST IF SAME
	JRST [	LOAD A,OFNBC,(D)
		MOVEM A,FILLEN(JFN)
		RET]		;SETUP FILLEN AND RETURN
	PUSH P,D		;SAVE OFN INDEX
	MOVEI C,^D36
	IDIVM C,A		;OFN BYTES/WD
	MOVEI C,^D36
	IDIV C,B		;JFN BYTES/WD
	POP P,D			;RESTORE OFN
	LOAD D,OFNBC,(D)	;GET FILE SIZE
	IMUL C,D		;CALC NEW FILE LENGTH
	IDIV C,A
	SKIPE D			;ROUND
	ADDI C,1
	MOVEM C,FILLEN(JFN)	;STORE IN JFN BLOCK
	RET			;RETURN
; Mutlitple directory rename
; Call:	JFN	; Jfn of new name
;	A	; Jfn of existing file
;	CALL DSKREN

DSKREN:	SE1CAL
	TRVAR <SRCJFN,SRCOFN,SRCFDB,DSTJFN,DSTOFN,DSTFDB,RENFDA>
	MOVEM A,SRCJFN		;SAVE SOURCE JFN
	CALL GETFDB		; GET FDB
	 RETBAD (RNAMX2)	; NAME GONE
	MOVEM A,DSTFDB		;SAVE DESTINATION FDB
	CALL NFACHK		;ACCESS ALLOWED BECAUSE NEW FILE?
	 SKIPA			;NO
	JRST DSKREA		;YES
	MOVX B,FC%WR		;B/WRITE ACCESS
	CALL ACCCHK		;CHECK FOR WRITE ACCESS TO THIS FILE
	 RETBAD (RNAMX3,<CALL USTDIR>)
DSKREA:	MOVE A,DSTFDB		; GET BACK FDB LOCATION
	SKIPE A,.FBADR(A)	;DEST HAS XB ADR?
	TXNE A,FILNB		;..
	JRST [	MOVEI A,0	; NO, WE'LL HAVE TO ASSIGN ONE
		LOAD B,STR,(JFN) ;GET STRUCTURE NUMBER FROM JFN BLOCK
		CALL DSKASN	; TO SERVE AS A PLACE HOLDER
		 RETBAD (RNAMX4,<CALL USTDIR>) ;NO SPACE ON DISK
		MOVE B,DSTFDB	;RECOVER FDB ADR
		TXO A,FILNB
		MOVEM A,.FBADR(B)
		JRST .+1]
	TXO A,THAWB
	LOAD B,STR,(JFN)	;GET STRUCTURE NUMBER FROM JFN BLOCK
	CALL ASFOFN		;OPEN DEST WITH RESTRICTED ACCESS
	JRST [	MOVE B,A
		SETO A,
		CAIN B,OPNX9	;BUSY?
		RETBAD (RNAMX5,<CALL USTDIR>) ;YES - CAN'T CONTINUE
		JRST .+1]	;NO, BAD PT, CONTINUE WITH RENAME
	MOVEM A,DSTOFN		;SAVE OFN JUST ASSIGNED
	CALL UPDOFN		;FIX OFN ON DISK
	MOVE B,DSTFDB		;GET FDB LOCATION
	MOVX A,FILNB		;MAKE XB ADR VALID
	ANDCAM A,.FBADR(B)
	CALL USTDIR		; THRU WITH DEST FOR NOW
	MOVEM JFN,DSTJFN	; SAVE DESTINATION JFN
	MOVE JFN,SRCJFN		; GET SOURCE JFN
	CALL GETFDB		; GET SOURCE FDB
	 RETBAD (RNAMX7,<CALL DSKRE8>) ;SOURCE WENT AWAY
	MOVEM A,SRCFDB		;SAVE SOURCE FDB
	MOVE B,CAPENB		;ENABLED CAPS
	TXNN B,SC%WHL!SC%OPR	;CHECK IF OK
	SKIPN USRSPC		; OR JUST NO CHECKING
	JRST DSKREO		;NO NEED TO CHECK FURTHER
	MOVE B,DSTJFN		;GET JFN OF DESTINATION
	HRRZ B,FILDDN(B)	;GET DIR # OF DESTINATION
	HRRZ C,FILDDN(JFN)	;GET DIR # OF SOURCE
	CAME C,B		;SAME DIRECTORIES?
	SKIPGE C,DSTOFN		;NO - GET OFN IF ANY
	JRST DSKREO		;DONT CHECK QUOTA IF SAME DIR
	LOAD B,FBNPG,(A)	;GET PAGE COUNT OF FILE
	LOAD C,ALOCX,(C)	;OFN QUOTA INDEX
	LOAD C,PGLFT,(C)	;COUNT OF REMAINING PAGES
	SUB C,B			;WILL FILE FIT?
	JUMPGE C,DSKREO		;JUMP IF OK
	RETBAD (RNAMX4,<CALL DSKRE8>) ;OVER QUOTA RETURN
DSKREO:	SE1CAL
	MOVE A,SRCFDB		; RESTORE SOURCE FDB
	MOVX B,FC%WR		;B/WRITE ACCESS
	CALL ACCCHK		;CHECK FOR WRITE ACCESS TO THIS FILE
				; (NEEDED TO DELETE)
	 RETBAD (RNAMX8,<CALL DSKRE8>) ;CANT RENAME
	MOVE A,SRCFDB		; GET BACK FDB LOC
	SKIPE A,.FBADR(A)
	TXNE A,FILNB		;CHECK NEW OR NO XB ADR
	 RETBAD (RNAMX9,<CALL DSKRE8>) ;NO DISK ADDRESS (SOURCE)
	TXO A,THAWB
	LOAD B,STR,(JFN)	;GET STRUCTURE NUMBER FROM JFN BLOCK
	CALL ASFOFN		;OPEN SOURCE WITH RESTRICTED ACCESS
	 JRST [	MOVE B,A	;BUSY OR BAD PT
		SETO A,
		CAIN B,OPNX9	;BUSY?
		RETBAD (RNMX10,<CALL DSKRE8>)
		JRST .+1]	;NO, CONTINUE WITH RENAME
	CAMN A,DSTOFN		; RENAME TO SELF?
	JRST [	SKIPL A
		CALL RELOFN	; Rename to self
		RETBAD (RNMX12,<CALL DSKRE8>)]
	MOVEM A,SRCOFN		;SAVE SOURCE OFN
	;..
;NOW GET ALL INFO FROM SOURCE FDB INTO TEMP BLOCK IN JSB

	;..
	MOVE JFN,DSTJFN		; GET DESTINATION JFN BACK
	MOVEI B,.FBLEN+1	;MAKE SOME SPACE FOR FDB COPY
	CALL ASGJFR		; IN THE JSB
	 JRST [	SKIPL A,SRCOFN	; NO ROOM - RELEASE STUFF
		CALL RELOFN
		RETBAD (RNMX13,<CALL DSKRE8>)]
	MOVEM A,RENFDA		;SAVE ADDRS OF FDB COPY
	XMOVEI C,1(A)		;TARGET OF XFER
	MOVE B,SRCFDB		;SOURCE FDB ADDRS
	MOVEI A,.FBLEN		;END OF XFER
	LOAD D,FBVER,(B)	;GET VERSION #
	CAIGE D,1
	MOVEI A,.FBLN0		;END OF VERSION #0
	CALL XBLTA		;MOVE FDB
	MOVE A,SRCFDB		;RESTORE  SOURCE FDB
	MOVX B,FB%PRM
	AND B,.FBCTL(A)		; RETAIN PERM BIT
	TXO B,FB%NXF+FB%DEL	; AND DELETE AND NON-EX IT
	HLLM B,.FBCTL(A)	; NEW CONTROL BITS
	SETZM .FBADR(A)		; NO DISC ADDRESS
	LOAD B,FBNPG,(A)	;GET PAGE COUNT OF SOURCE
	MOVNS B
	MOVE C,DIRORA		; GET BASE OF DIR AREA
	OPSTRM <ADDM B,>,DRDCA,(C) ;REDUCE SOURCE DIRECTORY PAGE COUNT
	SETZ B,
	STOR B,FBNPG,(A)	;RESET SOURCE FILE PAGE COUNT
	SETZRO FBSIZ,(A)	;CLEAR BYTE COUNT
	MOVE D,A		;NOW DELETE THE SOURCE FDB FROM DIR
	CALL DELFIL		;...
	 JFCL			;MIGHT COME HERE IF PERMANENT
	MOVE A,RENFDA		;(OLD FDB COPY)
	AOS A			;POINT TO FDB
	JN FBPRM,(A),<[MOVE A,SRCFDB	;POINTER TO FDB (STILL EXISTS)
			SETZRO FBNXF,(A) ;CLEAR NXF FLAG
			JRST .+1]>
	CALL UPDDIR		;UPDATE SOURCE DIRECTORY
	CALL USTDIR		; FINISHED WITH SOURCE
	; ..
	; ..
	CALL GETFDB		;GET DESTINATION FDB
	 BUG(HLT,GTFDB3,<DSKREN-GETFDB FAILURE FOR OPEN FILE>)
	MOVEM A,DSTFDB		; SAVE DESTINATION FDB LOC
	SKIPL A,SRCOFN		;SKIP IF DON'T HAVE A SOURCE OFN
	CALL RELOFN		; FLUSH IT
	SKIPGE B,DSTOFN		;GET OFN OF NEW FILE
	JRST DSKRE7		;NONE - GO ON
	MOVE A,DSTFDB		;OK - GET FDB ADDRS ALSO
	LOAD C,FBNPG,(A)	;SIZE OF FILE
	LOAD A,ALOCX,(B)	;OFN QUOTA INDEX
	OPSTRM <ADDM C,>,PGLFT,(A) ;ADJUST COUNT OF PAGES
	MOVE A,B		;PUT OFN IN A
	CALL RELOFN		;RELEASE IT
DSKRE7:	MOVE D,DSTFDB		; GET BACK TO FDB LOC
	PUSH P,.FBCTL(D)	; SAVE FLAGS
	SETONE FBPRM,(D)	; MAKE FDB PERMANENT TEMPORARILY
	CALL DELFIL		; DELETE OLD CONTENT OF DESTINATION
	 JFCL			; ALWAYS FAILS SINCE PERMANENT BIT SET
	POP P,A			; GET BACK OLD FLAGS
	MOVX B,FB%PRM		; GET PERMANENT BIT
	TXNN A,FB%PRM		; WAS FILE PERMANENT BEFORE?
	ANDCAM B,.FBCTL(D)	; NO, DONT LEAVE IT PERMANENT
	;..
; NOW READY TO PLANT THE OLD FDB INTO THE NEW

	;..
DSKRE9:	MOVSI D,-.FBLEN		; PREPARE TO DO ALL FDB ENTRIES
	MOVE A,DSTFDB		;POINT TO NEW FDB
	LOAD B,FBVER,(A)	;CHECK DESTINATION VERSION #
	CAIGE B,1
	MOVSI D,-.FBLN0		;USE CORRECT LENGTH
	LOAD B,FBNPG,(A)	;GET PAGES JUST FLUSHED
	MOVNS B
	MOVE C,DIRORA		;GET BASE ADR OF MAPPED DIR AREA
	OPSTRM <ADDM B,>,DRDCA,(C) ;REDUCE DIRECTORY PAGE COUNT
	HRRZ B,RENFDA		;ADDRESS OF SOURCE FDB
	AOS B			;...
	HRLI B,D+(IFIW)
DSKR9L:	MOVE C,@B		; GET SOURCE
	XOR C,0(A)		; BIT DIFFERENCE
	ANDCM C,RENMSK(D)	; BITS TO RETAIN FROM DESTINATION
	XORM C,0(A)
	AOS A			; STEP TO NEXT WORD IN FDB
	AOBJN D,DSKR9L		; DO ALL WORDS IN FDB
	MOVE A,DSTFDB		; GET BACK ADDRESS OF FDB
	MOVE D,DIRORA		; GET ADR OF DIR AREA
	LOAD B,FBNPG,(A)	;UPDATE DIRECTORY PAGE COUNT NOW THAT
	OPSTRM <ADDM B,>,DRDCA,(D) ;FILE HAS REACHED DESTINATION
	CALL DSKDV		;DELETE EXCESS VERSIONS
	MOVEI A,JSBFRE		;RETURN JSB STORAGE
	MOVE B,RENFDA
	CALL RELFRE		;...
	OKINT			;ALLOW INTS AGAIN
	CALL UPDDIR		;UPDATE DEST DIRECTORY
	CALL USTDIR
	RETSKP
; COMMON ERROR ROUTINE

DSKRE8:	CALL USTDIR		;UNLOCK STR & DIRECTORY
	SKIPL A,DSTOFN		;RELEASE OFN IF ANY
	CALL RELOFN
	RET			;EXIT

; MASKS OF BITS TO NOT COPY FROM SOURCE FILE

RENMSK:	-1			; .FBHDR
	FB%TMP+FB%PRM		; FLAGS
	-1			; POINTER TO NEXT EXT FDB
	0			; .FBADR
	-1			; .FBPRT
	0			; .FBCRE
	-1			; POINTER TO AUTHOR STRING
	-1,,0			; GENERATION # ,, DIR # (IF DIR FILE)
	-1			; .FBACT
	770000,,0		; .FBBYV
	0			; .FBSIZ
	0			; .FBCRV
	0			; .FBWRT
	0			; .FBREF
	0			; .FBCNT
	REPEAT 5,<0>		; .FBBK0-4
	0			; .FBUSW
	-1			; POINTER TO NEXT GENERATION FDB
	-1			; POINTER TO NAME STRING
	-1			; POINTER TO EXTENSION STRING
	-1			; POINTER TO LAST-WRITER STRING
;THE SPOOLED DEVICE HANDLER

	SWAPCD

RS SPLVER,1			;VERSION NUMBER TO USE ON GTJFN

SPLDTB::
	DTBBAD(GJFX32)		; Set directory
	DTBBAD (DESX9)		; Name lookup
	DTBBAD (DESX9)		; Extension
	DTBBAD (DESX9)		; Version
	DTBBAD (DESX9)		; Protection insertion
	DTBBAD (DESX9)		; Account
	DTBBAD (DESX9)		; STATUS INSERTION
	IFIW!SPLOPN		; OPEN
	DTBBAD (DESX9)		; INPUT
	DTBBAD (DESX9)		; Output
	DTBBAD (DESX9)		; CLOSE
	DTBBAD (DESX9)		; Rename
	DTBBAD (DESX9)		; Delete
	DTBBAD (DESX9)		; DUMPI
	DTBBAD (DESX9)		; DUMPO
	DTBBAD (DESX9)		; Mount
	DTBBAD (DESX9)		; Dismount
	DTBBAD (DESX9)		; Initialize directory
	DTBBAD (DESX9)		; Mtape
	DTBBAD (DESX9)		; Get status
	DTBBAD (DESX9)		; Set status
	DTBSKP			;RECOUT - FORCE RECORD OUT (SOUTR)
	IFIW!RFTADN		; READ TAD
	IFIW!SFTADN		; SET TAD
	DTBDSP (BIOINP)		;SET JFN FOR INPUT
	DTBDSP (BIOOUT)		;SET JFN FOR OUTPUT
	DTBBAD (GJFX49)		;CHECK ATTRIBUTE

	DTBLEN==:.-SPLDTB	;GLOBAL LENGTH OF DISPATCH TABLE
;ROUTINE TO OPEN THE SPOOLED DISK FILE AND SWAP THE JFNS

SPLOPN:	NOINT
	SE1CAL
	MOVEI A,SC%WHL		;TURN THIS JOB INTO A WHEEL FOR THE OPEN
	PUSH P,CAPENB		; Save current capenb
	IORM A,CAPENB		; Give ourselves wheel status
	MOVEI B,^D13		;GET WORDS FOR <SPOOL>DEVN-DIR#-0-
	HLRZ A,FILNEN(JFN)	;GET LENGTH OF NAME STRING
	SKIPE A			;IF ANY NAME WAS GIVEN
	HRRZ A,0(A)		;SIZE OF STRING IS IN RH OF 1ST WORD
	ADD B,A			;UPDATE COUNT OF WORDS NEEDED
	HRRZ A,FILNEN(JFN)	;GET LENGTH OF EXTENSION STRING
	SKIPE A			;IF ANY
	HRRZ A,0(A)
	ADD B,A			;NOW HAVE # OF WORDS TO HOLD GTJFN STRING
	CALL ASGJFR		; Get some job storage
	 RETBAD (,<POP P,CAPENB>) ;GIVE ERROR BACK TO USER
	PUSH P,A		;SAVE ADDRESS OF STRING
	HRLI A,(<POINT 7,0,35>)
	HRRZ B,FILIDX(JFN)	;GET DIRECTORY TO SPOOL INTO
	MOVE B,DEVCH2(B)	;...
	SKIPE B			;IF ZERO, USE DEFAULT DIRECTORY
	DIRST			;ADD IN NEW SPOOLING DIRECTORY
	 TDZA C,C		;NO SUCH DIRECTORY, USE DEFAULT
	JRST SPLOP1		;DONE
	HRROI B,[ASCIZ/PS:<SPOOL>/]	;USE DEFAULT DIRECTORY
	SOUT			;ADD IT INTO STRING
SPLOP1:	MOVE D,A		;REMEMBER BYTE POINTER
	ADDI D,MAXLW		;GET MAXIMUM SIZE OF NAME FIELD
	HLRZ B,FILDDN(JFN)	;GET DEVICE NAME STRING
	HRLI B,(POINT 7,0,35)	;MAKE IT A STRING POINTER
	SETZ C,
	SOUT			;PUT "DEV" ONTO NAME STRING
	MOVEI B,"-"		;FOLLOWED BY A "-"
	IDPB B,A
	MOVE B,JOBNO		;NOW GET LOGGED IN DIR #
	HRRZ B,JOBDIR(B)
	MOVEI C,10		;AND ADD IT IN OCTAL
	NOUT
	 BUG(CHK,NOUTF1,<SPLOPN: NOUT OF DIRECTORY NUMBER FAILED>)
	HRRZ B,FILIDX(JFN)	;GET INDEX INTO DEVICE TABLES
	LDB B,[POINT 9,DEVCHR(B),17] ;GET DEVICE TYPE
	CAIN B,.DVCDR		;IS THIS A CARD READER?
	JRST SPLCDR		;YES, HANDLE IT DIFFERENTLY
	HRROI B,[ASCIZ/-0-/]	;ADD IN STATION NUMBER
	SETZ C,
	SOUT
	HLRZ B,FILNEN(JFN)	;NOW ADD ON THE NAME
	HRLI B,(POINT 7,0,35)
	TRNE B,-1		;UNLESS THERE WASNT A NAME
	SOUT
	MOVEI B,0(D)		;GET MAX END OF NAME STRING
	CAILE B,0(A)		;IS THE NAME SHORT ENOUGH?
	JRST SPLOP3		;YES
	CAIE B,0(A)		;IS THE BYTE POINTER IN LAST WORD?
	JRST SPLOP2		;NO, THE STRING IS TOO LONG, TRUNCATE
	CAMLE D,A		;IS THE NAME STRING SHORT ENOUGH
SPLOP2:	MOVE A,D		;NO, TRUNCATE THE NAME TO 39 CHARS
SPLOP3:	MOVEI B,"."		;PUT SEPARATOR BETWEEN NAME AND EXT
	IDPB B,A
	HRRZ B,FILNEN(JFN)	;GET POINTER TO EXTENSION STRING
	HRLI B,(POINT 7,0,35)
	TRNE B,-1		;DONT ADD EXT IF NONE
	SOUT
	MOVEI B,PNCATT		;NOW SET UP THE PROTECTION OF THE FILE
	IDPB B,A		;PUT IN PUNCTUATION
	HRROI B,[ASCIZ/P777700/] ;DONT ALLOW USERS ANY RIGHTS
	SOUT
	MOVEI B,0		;ADD A NUL BYTE
	IDPB B,A
	;..
	;..
SPLGTL:	AOS A,SPLVER		;GET NEXT VERSION # TO USE
	ANDI A,377777		;DONT LET IT GET TOO BIG
	HRLI A,(GJ%FOU!GJ%NEW!GJ%DEL!GJ%PHY!GJ%SHT)
SPLGTA:	MOVE B,0(P)		;GET BACK STRING POINTER
	HRLI B,(POINT 7,0,35)	;TURN IT INTO A STRING POINTER
SPLGTJ:	GTJFN			;OPEN THIS FILE
	 JRST [	CAIN A,GJFX27	; FILE ALREADY EXISTS?
		JRST SPLGTL	;YES, TRY AGAIN
		HRRZ B,FILIDX(JFN)
		LDB B,[POINT 9,DEVCHR(B),17]
		CAIN B,.DVCDR	;IS THIS A CDR?
		JRST [	MOVEI A,JSBFRE	;YES, GO RELEASE SPACE IN JSB
			HRRZ B,JSCDR	;FOR NAME STRING
			CALL RELFRE
			SETZM JSCDR	;YES, NO MORE FILES TO BE READ
			JRST SPLCDR]	;GO OPEN THE NUL: DEVICE
		EXCH A,0(P)	;SAVE ERROR CODE, AND GET BACK STRING
		MOVE B,A	;GET ADDRESS OF STRING
		MOVEI A,JSBFRE
		CALL RELFRE	;GIVE BACK SPACE
		POP P,A		;GET BACK ERROR CODE
		RETBAD (,<POP P,CAPENB>)]
	POP P,B			;GET BACK STRING POINTER
	PUSH P,A		;SAVE JFN
	MOVEI A,JSBFRE
	CALL RELFRE		;RETURN STRING TO FREE POOL
	MOVE A,0(P)		;GET JFN OF DSK FILE
	MOVEI B,100000		;ASSUME WRITE
	HRRZ C,FILIDX(JFN)	;GET POINTER INTO DEVICE TABLES
	MOVE C,DEVCHR(C)	;GET CHARACTERISTICS
	TLNE C,(DV%IN)		;AN INPUT DEVICE?
	MOVEI B,200000		;YES, CHANGE MODE OF OPEN TO READ
	LDB C,PBYTSZ		;GET THE BYTE SIZE
	DPB C,[POINT 6,B,5]	;KEEP THE SAME BYTE SIZE IN FILE
	LDB C,PFLMOD		;DO THE SAME WITH THE MODE
	DPB C,[POINT 4,B,9]
	OPENF			;OPEN THE SPOOLED FILE
	 JRST [	EXCH A,0(P)	;FAILED, SAVE ERROR CODE AND GET JFN
		RLJFN		;RELEASE THE JFN OF THE DSK FILE
		 JFCL
		POP P,A		;GET BACK ERROR CODE
		RETBAD (,<POP P,CAPENB>)]
	CALL UNLCKF		;UNLOCK THE FILE LOCK
	POP P,A			;GET BACK THE JFN
	POP P,CAPENB		;RESTORE CORRECT CAPABILITIES
	PUSH P,FILIDX(JFN)	;SAVE INDEX INTO DEVICE TABLES
	MOVE B,JFN		;GET JFN OF SPOOLED DEVICE
	IDIVI B,MLJFN		; CONVERT TO EXTERNAL INDEX
	SWJFN			;MAKE JFN POINT TO DISK FILE
	RLJFN			;RELEASE THE OTHER JFN
	 JFCL
	POP P,A			;GET BACK INDEX
	HRRM A,FILIDX(JFN)	;KEEP ORIGINAL INDEX ACCROS SPOOLING
	MOVE P,MPP		;RESTORE STACK TO LEVEL AT JSYS ENTRY
	SMRETN			;RETURN TO USER
SPLCDR:	SKIPN B,JSCDR		;IS A SPOOL SET SET UP?
	JRST [	MOVSI A,(GJ%PHY!GJ%SHT)	;NO, USE NUL:
		HRROI B,[ASCIZ/NUL:/]
		JRST SPLGTJ]	;GO DO GTJFN
	MOVEI C,"."		;PUT IN PUNCTUATION AFTER NAME
	IDPB C,A
	HRLI B,(POINT 7,0,35)	;SET UP POINTER TO CDR NAME
	SETZ C,
	SOUT			;APPEND SPOOL SET NAME TO STRING
	HLRZ A,JSCDR		;NOW GET GENERATION NUMBER TO USE
	MOVEI A,1(A)		;INCREMENT IT
	ANDI A,377777		;DONT LET IT GET TOO LARGE
	HRLM A,JSCDR		;STORE UPDATED NUMBER
	HRLI A,(GJ%OLD!GJ%PHY!GJ%SHT)	;ACCEPT OLD FILES ONLY
	JRST SPLGTA		;GO DO GTJFN AND OPENF
;FILE SPECIFIC ENTRY POINTS FOR ASGOFN.
;MUST HAVE JFN SET UP AND THE CURRENT DIRECTORY MAPPED.
;   AC1/ FDB ADDRESS
;   AC2/ STR #

;ASSIGN OFN FOR LONG FILE PAGE TABLE - FAILS AT LOWER LEVEL OF OFN
;USAGE TO PREVENT ALL OFNS BEING TIED UP BY HEAVILY MAPPED LONG FILE.

ASLOFN::TDZA T3,T3		;REMEMBER THIS ENTRY

ASFOFN::MOVEI T3,1		;REMEMBER THIS ENTRY
	ACVAR <W1>		;GET A WORK REG
	MOVE W1,T3		;SAVE ENTRY FLAG
	PUSH P,T1		;SAVE T1,T2
	PUSH P,T2		;HAS STR #
	HRRZ T1,FILDDN(JFN)	;GET DIRECTORY NUMBER
	CALL GETCAL		;GET CURRENT ALLOCATION
	 JRST [	MOVE T3,DIRORA	;DIRECTORY NOT OPENED,
		LOAD T1,DRLIQ,(T3) ;  SO CALCULATE CURRENT
		OPSTR <SUB T1,>,DRDCA,(T3)  ;  ALLOCTION FROM DIR.
		JRST .+1]
	MOVE T4,T1		;SET UP ALLOCATION ARG
	HRRZ T3,FILDDN(JFN)	;SET UP DIR #
	POP P,T2		;RESTORE STR #
	POP P,T1		; AND FDB ADDRESS
	XCT [	CALLRET ASGOFL
		CALLRET ASGOFN](W1) ;CALL PROPER ROUTINE


;ASSIGN AN OFN FOR A FILE IN THE ROOT-DIRECTORY

ASROFN::MOVEI T3,ROOTDN		;DIRECTORY NUMBER
	HRLZI T4,377777		;INFINITE ALLOCATION
	CALLRET ASGOFN		;ENTER MAIN ROUTINE

	TNXEND
	END