;DSK:<FOONEX>FILINI.MAC;14 19-Sep-80 14:25:11, Edit by DANG
; Added versatec device VTC
;DSK:<PEFMON>FILINI.MAC;1 12-Jun-80 19:56:55, Edit by FRENCH
;ADDED SNSOFN FOR SYS OFNS SENSITIVE TO DISK ERRORS
;DSK:<PEFMON>FILINI.MAC;21 22-Apr-80 22:53:46, Edit by FRENCH
;SEPARATED CLLS FOR ASSIGNING DRUM AND DISK ADRS FROM BATS
;DSK:<PEFMON>FILINI.MAC;17 22-Apr-80 20:45:17, Edit by FRENCH
;CALL MAPBTF HERE INSTEAD OF IN SYSINI
;NEED IT TO DO BAT BLOCK ASSIGNING
;DSK:<PEFMON>FILINI.MAC;14 21-Apr-80 16:57:24, Edit by FRENCH
;READ DIDSCA FROM HOME BLOCKS IF NOT SYSLODING
;DSK:<PEFMON>FILINI.MAC;10 17-Apr-80 15:34:15, Edit by FRENCH
;DO SETBTF WHEN FILINI DONE FOR SYSLOD
;DSK:<PEFMON>FILINI.MAC;6 17-Apr-80 13:46:45, Edit by FRENCH
;ADDED CLEARING AND SETTING OF FILIFG
;DSK:<PEFMON>FILINI.MAC;5 17-Apr-80 13:31:40, Edit by FRENCH
;CLEAR AC 0 FOR GETFDB
;DSK:<PEFWRK>FILINI.MAC;3  8-Apr-80 16:14:06, Edit by FRENCH
;ADDED CALL TO CRTBFA
;DSK:<PEFWRK>FILINI.MAC;3  2-Apr-80 13:00:23, Edit by FRENCH
;ADDED HOME AND BAT STUFF
;DSK:<PEFWRK>FILINI.MAC;1 26-Mar-80 16:27:59, Edit by FRENCH
;SAVE FILE DIRECTORY DISK ADR IN FDDSCA
;<134-TENEX>FILINI.MAC;11    17-Feb-80 18:47:27    EDIT BY LYNCH
; MADE SYSJOB BE THE TRUE DEFAULT INSTEAD OF SYSJ !
;<134-TENEX>FILINI.MAC;10     3-DEC-77 16:28:11    EDIT BY PETERS
;<134-TENEX>FILINI.MAC;9    22-Mar-77 23:01:56    EDIT BY LYNCH
;<134-TENEX>FILINI.MAC;8    22-Mar-77 18:43:11    EDIT BY LYNCH
; TOOK OUT TV
;<134-TENEX>FILINI.MAC;7    24-JUL-76 17:05:12    EDIT BY UNTULIS
;ADDED CHECK FOR SPECIAL FILES WHEN RELOADING 
;<134-TENEX>FILINI.MAC;3    23-MAR-76 22:54:53    EDIT BY UNTULIS
;<134-TENEX>FILINI.MAC;2     5-FEB-76 15:17:41    EDIT BY UNTULIS
;ADDED ALPAHANUMERIC ACCOUNTS STUFF,SYSTEM PASSWORD,FILE FORMAT FLAG
;<134-TENEX>FILINI.MAC;38    28-APR-75 12:40:37    EDIT BY CLEMENTS
;<134-TENEX>FILINI.MAC;37    28-APR-75 11:38:15    EDIT BY CLEMENTS
;<134-TENEX>FILINI.MAC;36    24-APR-75 14:19:17    EDIT BY CLEMENTS
;<134-TENEX>FILINI.MAC;35    14-APR-75 13:32:30    EDIT BY ALLEN
; INIT JBCLCK WITH SETOM, NOT UNLOCK
;<133-TENEX>FILINI.MAC;34    25-OCT-74 10:48:21    EDIT BY TOMLINSON
;<133-TENEX>FILINI.MAC;33    25-OCT-74 10:36:25    EDIT BY TOMLINSON
; Initialize DIRECTORY and INDEX files to have FDBPRM&FDBUND set
;<TENEX-132>FILINI.MAC;32    11-JUN-74 12:43:46    EDIT BY TOMLINSON
; ELIMINATED VARIABLE FDFMTF. NOW MUST BE SET AS DESIRED.
;<TENEX-132>FILINI.MAC;31    20-MAY-74 12:30:03    EDIT BY TOMLINSON
; CHANGE INITIAL PROTECTION OF DIRECTORY TO 404000
;<TENEX-132>FILINI.MAC;30    13-MAY-74 08:50:39    EDIT BY TOMLINSON
; Changed JFCL after CRDIR to BUGHLT
;<TENEX-132>FILINI.MAC;29     9-MAY-74 23:40:52    EDIT BY CLEMENTS
; JFCL AFTER CRDIR WHICH NOW SKIPS
;<TENEX-132>FILINI.MAC;28     3-MAY-74 08:44:53	EDIT BY TOMLINSON
; CHECK DIRECTORY PTT FOR EMPTY ENTRIES DURING FILINI
;<TENEX-132>FILINI.MAC;27    13-APR-74 11:46:48	EDIT BY TOMLINSON
; INITIALIZE PASSWORD FAILURE COUNTER
;<TENEX-132>FILINI.MAC;26     1-APR-74 20:12:15	EDIT BY TOMLINSON
; ADDED CODE IN FILINI TO UNLOCK ANY SUBINDEX AND SYSTEM DIRECTORY
;<TENEX-132>FILINI.MAC;24    19-MAR-74 13:52:02	EDIT BY TOMLINSON
; MORE BUG FIXES TO CVTFD AND RELATIVES
;<TENEX-132>FILINI.MAC;23    19-MAR-74 10:56:51	EDIT BY TOMLINSON
; BUG FIX IN CVTFD
;<TENEX-132>FILINI.MAC;22    18-MAR-74 21:01:14	EDIT BY TOMLINSON
; INSERTED FD FORMAT CONVERTER ROUTINE (CVTFD)
;<TENEX-132>FILINI.MAC;21    18-MAR-74 18:57:24	EDIT BY TOMLINSON
; ADDED CHECKS FOR NEW FD FORMAT (CONTIGUOUS PAGES FOR ONE DIRECTORY)
;<TRAP>FILINI.MAC;1     4-MAR-74 15:04:39	EDIT BY BTHOMAS
;<TENEX-132>FILINI.MAC;20    30-NOV-73 16:50:36	EDIT BY TOMLINSON
;<TENEX-132>FILINI.MAC;19    27-NOV-73 17:43:22	EDIT BY CLEMENTS
; MADE INITIAL ACCOUNT, AT JBFINI, BE A PARAMETER "INIACT"
;<TENEX-132>FILINI.MAC;16     2-NOV-73 13:12:46	EDIT BY TOMLINSON
; SUBROUTINIZED SUBINDEX INITIALIZED AND REDID INITIAL SUBINDEX COUNT
;<TENEX-132>FILINI.MAC;15     2-NOV-73 11:51:37	EDIT BY TOMLINSON
;<TENEX-132>FILINI.MAC;14    13-JUN-73 21:07:24	EDIT BY CLEMENTS
;<TENEX-132>FILINI.MAC;13     6-MAR-73 18:14:18	EDIT BY CLEMENTS
;<TENEX-132>FILINI.MAC;12    13-FEB-73 19:00:13	EDIT BY CLEMENTS
;ADDED INITIAL UNLOCK OF JBCLCK
;<TENEX-132>FILINI.MAC;11    19-JAN-73 09:51:02	EDIT BY TOMLINSON
; ADDED ADC/DAC INITIALIZATION
;<DLM/TEMP>FILINI.MAC;10    31-OCT-72 10:54:47	EDIT BY CHIPMAN
; FIX PAGE STORAGE END CHECK AND INIT JOBUNT
;<DLM/TEMP>FILINI.MAC;9    21-AUG-72 20:08:25	EDIT BY MURPHY
;<FILESYSTEM>FILINI.MAC;8    29-JUN-72  9:54:41	EDIT BY TOMLINSON

	SEARCH	STENEX,PROLOG
	TITLE	FILINI

EXTERN	CHKDEV,CLASS,DEVDSP,DSKDTB,GETFDB,INIBLK,MAPDIR,TODCLK,USTDIR
EXTERN	MAXLW,RELPAG,ASGPAG,ACCTPT,DIDSCA,DIDSCI,BHC,FDDSCA,FILIFG
EXTERN	JOBDIR,FORKX,FKDIR,FKGRPS,PASFCT
EXTERN	DISKP,DIOFN,FDLOFN,BUGCHK,BUGHLT,FDOFN,SETMPG,ASOFN,DSKASN
EXTERN	PRIMRY,CAPENB,CAPMSK
EXTERN  ACCTSL,ACCTSR						;***SRI-AIC***
EXTERN  CRTBAA,CRTBFA,CRTSFA,CRTHMA,DOBDRA,DOBDSA,DOBDDA,DEFDIA
EXTERN	SETBTF,MAPBTF,DSKBTI
EXTERN	SNSOFN

INTERN	FILINI,JBFINI

; Initialize file stuff

	USE	RESPC

JBFINI::MOVEI A,JSFREE		; Origin of free area in jsb
	HRLOM A,JSBFRE		; To header
	MOVEI A,IJSFRE
	HRRZM A,JSFREE		; One big block free
	MOVEM A,JSBFRE+2
	SETOM JSBFRE+1
	MOVE A,[XWD JSFREE+IJSFRE,JSFREE]
	MOVEM A,JSBFRE+4
	MOVEI A,MAXLW+1
	MOVEM A,JSBFRE+3
	SETOM JBCLCK
	MOVE A,[XWD JBCOR,JBCOR+1]
	SETZM JBCOR
	BLT A,JBCOR+3
	MOVEI C,FREJP		; Start with frejp page
IJFRLP:	MOVE A,C
	LSH A,9
	PUSH P,C
	PUSHJ P,RELPAG
	POP P,C
	CAIGE C,PPMPG-1
	AOJA C,IJFRLP
	SETOM PRIMRY		; Primary io to controlling tty
	SETOM JFNLCK		; Unlock jfnlck
	SETZM PASFCT		; CLEAR PASSWORD FAILURE COUNTER
	SETZM MAXJFN
	MOVEI A,1
	MOVE B,FORKX		; Set connected directory, assume
	HRLZM A,FKDIR(B)	; this code in top job fork only
	SETZM FKGRPS(B)
	MOVE B,JOBNO
	HRLZM A,JOBDIR(B)	; Connect to directory 1, no log in
	SETOM JOBUNT		; DEFAULT DSK UNIT
IFDEF NDP,<	SETZM JOBDC##>	; No display consoles assigned
	MOVE A,[XWD 777000,-1]
	MOVEM A,CAPMSK
	MOVEM A,CAPENB
	MOVE A,[ASCII /SYSJO/]	;SETUP DEFAULT ACCOUNT STRING	***SRI-AIC***
	MOVEM A,ACCTSR		;PLACE WHERE MONITOR CAN GET TO INT ***SRI-AIC***
	MOVE A,[ASCIZ /B/]	; FINISH OFF SYSJOB
	MOVEM A,ACCTSR+1
	MOVEI A,3	;SET LENGTH OF SAME			***SRI-AIC***
	MOVEM A,ACCTSL						;***SRI-AIC***
	MOVE A,[POINT 7,ACCTSR, ]	;ESTABLISH A POINTER TO IT ***SRI-AIC***

	MOVEM A,ACCTPT
	POPJ P,

; File system initialization

FILINI:	SETZM FILIFG			;FILSYSTEM NOT READY FOR USE YET
	SKIPE DIDSCA
	JRST FILINW
	SKIPN DISKP
	 JRST FILINW
	HRROI A,[ASCIZ /
DO YOU REALLY WANT TO CLOBBER THE DISC BY RE-INITIALIZING? /]
FILINQ:	PSOUT
	PBIN
	PUSH P,A
	MOVEI A,37
	PBOUT
	POP P,A
	CAIN A,"Y"
	JRST [	HRROI A,[ASCIZ /OK, YOU ASKED FOR IT./]
		PSOUT
		JRST FILINW]
	CAIE A,"N"
	JRST [	HRROI A,[ASCIZ /PLEASE TYPE Y OR N: /]
		JRST FILINQ]
	HRROI 1,[ASCIZ/
I THOUGHT NOT.  PLEASE BE MORE CAREFUL IN THE FUTURE./]
	PSOUT
	MOVE 1,DIDSCI
	MOVEM 1,DIDSCA			;SAY WE KNOW WHERE IT IS
FILINS:	HRROI A,[ASCIZ /
DO SPECIAL FILES EXIST ? /]
	PSOUT
	PBIN
	CAIN A,"N"
	JRST FILINW
	CAIE A,"Y"
	JRST FILINS
	SETOM ACCIFG##		;SIGNAL EXISTENCE OF SPECIAL FILES
	MOVEI A,37
	PBOUT

FILINW:	SKIPN DIDSCA		; Dont init bit table if not fresh start
	PUSHJ P,DSKBTI		; SETUP FRESH BITTABLE
	PUSHJ P,DEVINI##
IFDEF MTAN,<	PUSHJ P,MTAINI##>
IFDEF LPTN,<	PUSHJ P,LPTINI##>
IFDEF PLTN,<	PUSHJ P,PLTINI##>
IFDEF PTPN,<	PUSHJ P,PTPINI##>
IFDEF PTRN,<	PUSHJ P,PTRINI##>
IFDEF DTAN,<	PUSHJ P,DTAINI##>
IFDEF NETN,<	PUSHJ P,NETINI##>
IFDEF NDP,<	PUSHJ P,DSPINI##>
IFDEF VTCN,<	PUSHJ P,VTCINI##>
	PUSHJ P,DMPINI##
	MOVE A,TODCLK
	ANDI A,777
	MOVEM A,CLASS
	SKIPN DIDSCA		;FRESH START?
	 CALL CRTBAA		;YES-INIT BAT BLKS, POSSIBLY GET NEW ONES
	SKIPN DIDSCA		;DO WE THINK WE KNOW START OF WORLD?
	 JRST FILI1W		;NO-NOTHING TO ADJUST
	CALL DEFDIA		;YES-LETS READ IT FROM HOME BLOCKS TO BE SURE
	MOVEM 1,DIDSCA		;USE THAT VALUE AS GOD, NOW DIDSCA IS CORRECT
	JRST FILIN1		;NOW USE IT

;HERE THE DISK BITTABLE IS JUST IN CORE AND THATS WHAT
;DOBDDA USES FOR DISK ASSIGNS
;CALL TO SETBTF GETS IT OUT TO DISK

FILI1W:	CALL DOBDDA		;ASSIGN ALL BAT BLOCK SPOTS IN BITTABLES
	PUSHJ P,NEWIB		;get an ib ofn
	HRLM A,SNSOFN		;REMEMBER SENSITIVE OFN RANGE START
	MOVEM B,DIDSCA		;WE CAN BELIEVE THIS ONE CAUSE BITTABLE SET UP
	MOVEM A,DIOFN		;HOME BLOCKS WILL BE WRITTEN WITH IT
	PUSHJ P,NEWIB
	MOVEM B,FDDSCA		; SAVE FILE DIRECTORY XB ADR
	PUSH P,A
	HRLOI A,600000
	PUSHJ P,CHKDEV
	BUG(HLT,<FILINI: CHKDEV FAILED TO FIND DEVICE DSK:.>)
	POP P,A
	MOVEM A,FDLOFN
	PUSHJ P,ASGPAG
	BUG(HLT,<FILINI: ASGPAG FAILURE.>)
	MOVE B,A
	HRLI B,140000
	MOVE A,FDLOFN
	PUSHJ P,SETMPG
	HRLI B,C
	MOVSI C,-NFDIB

FILIN9:	PUSH P,B
	PUSH P,C
	PUSHJ P,NEWFD
	TLO B,40
	TLZ B,20
	EXCH B,-1(P)
	POP P,C
	MOVEM A,FDOFN(C)
	POP P,@B
	AOBJN C,FILIN9
	HRRM A,SNSOFN		;REMEMBER SENSITIVE OFN RANGE END
	MOVEI A,0
	PUSHJ P,SETMPG
	HRRZ A,B
	PUSHJ P,RELPAG
	MOVE A,FDDSCA		; DISC ADDRESS OF FD
	PUSHJ P,IDXINI		; INITIALIZE THE SUBINDEX
	MOVSI 1,200001
	HRROI 2,[ASCIZ /<SYSTEM>DIRECTORY;1;P404000/]
	GTJFN
	BUG(HLT,<FILINI: GTJFN FAILURE FOR <SYSTEM>DIRECTORY.>)
	MOVE JFN,A
	LSH JFN,SJFN
	HRROI DEV,DSKDTB
	SETZ 0,			;CLEAR FLAGS
	PUSHJ P,GETFDB
	BUG(HLT,<FILINI: GETFDB FAILURE FOR <SYSTEM>DIRECTORY.>)
	MOVE B,FDDSCA
	MOVEM B,FDBADR(A)		; Put fd disc address into fdb
	MOVSI B,FDBNXF
	ANDCAM B,FDBCTL(A)
	MOVSI B,FDBLNG!FDBPRM!FDBUND
	IORM B,FDBCTL(A)
	PUSHJ P,USTDIR
	MOVSI 1,200001
	HRROI 2,[ASCIZ /<SYSTEM>INDEX;1;P404000/]
	GTJFN
	BUG(HLT,<FILINI: GTJFN FAILURE FOR <SYSTEM>INDEX.>)
	MOVE JFN,A
	LSH JFN,SJFN
	HRROI DEV,DSKDTB
	SETZ 0,			;CLEAR FLAGS
	PUSHJ P,GETFDB
	BUG(HLT,<FILINI: GETFDB FAILURE FOR <SYSTEM>INDEX.>)
	MOVE B,DIDSCA
	MOVEM B,FDBADR(A)
	MOVSI B,FDBNXF
	ANDCAM B,FDBCTL(A)
	MOVSI B,FDBPRM!FDBUND
	IORM B,FDBCTL(A)
	PUSHJ P,USTDIR
	MOVNI 1,1
	RLJFN
	JFCL
	AOS FILIFG			;FILESYSTEM OK TO USE NOW
	CALL CRTBFA			;MAKE ALL BAT BLKS PART OF FILE SYS
	CALL CRTSFA			;CREATE SPECIAL FILES
	CALL CRTHMA			;AND HOME BLOCKS FOR ALL PACKS
	CALL SETBTF			;GET THE MOTHER OUT THERE
	POPJ P,

MKFDBK:	0
	0
	0
	700000
	XWD 200000,0	;ALPHANUMERIC ACCOUNTS			***SRI-AIC***

; INITIALIZE THE WHOLE SUBINDEX

NDIRHT==NFDIB*47	; HASH TABLE SIZE 20% MORE THAN MAX DIR'S

IDXINI:	PUSH P,A		; SAVE FD DISC ADDRESS
	MOVEI A,0
	PUSHJ P,MAPDIR
	SETZM DIRORG
	MOVE A,[XWD DIRORG,DIRORG+1]
	BLT A,ESBIDT+NDIRHT-1
	POP P,FDADR		; Store disc address of fd in di
	MOVEI A,ESBIDT-DIRORG	; End of sbidtb is beginning of hash
	MOVEM A,DIRHTO
	MOVEI A,NDIRHT
	MOVEM A,DIRHTL		; Hash table length
	SETZ C,			; START WITH LETTER NULL
	MOVE B,[POINT 7,SBIDTB]	; POINTER TO SUBINDEX DISPATCH TABLE
	MOVEI A,1		; FIRST LETTERS GOINTO SUBINDEX 1
	MOVEI D,[EXP "A","B","D","F","I","L","M","O","R","S","T",177]+^D<12/NSUBI - 1>
		; LETTERS DELIMITING 8.333 PERCENTILES OF USER NAMES
FILINZ:	IDPB A,B		; DEPOSIT CORRECT SUBINDEX IN DISPATCH TABLE
	CAML C,0(D)		; REACHED PERCENTILE BOUNDARY?
	JRST [	ADDI D,^D<12/NSUBI>
		AOJA A,.+1]
	CAIGE C,177
	 AOJA C,FILINZ
	PUSH P,A
FILINP:	MOVN A,0(P)
	PUSHJ P,FILINX		; INITIALIZE EACH SUBINDEX
	SOSLE 0(P)
	 JRST FILINP
	POP P,A			; FLUSH STACK, CLEAR A
	PUSHJ P,MAPDIR
	SETOM DIRLCK
INLP1:	MOVEI A,[ASCIZ /SHAKEY/]
	HRROM A,MKFDBK+1
	HRROI 1,[ASCIZ /SYSTEM/]
	MOVE 2,[XWD 260000,MKFDBK]
	CRDIR
	 BUG(HLT,<FILINI: Could not create directory SYSTEM>)
	POPJ P,

FILINX:	PUSH P,A
	PUSHJ P,MAPDIR
	POP P,C
	MOVEI A,DDBLEN
	MOVEI B,7777
	PUSHJ P,INIBLK
	SETOM DIRLCK
	POPJ P,

; Initialize directory and index contents


; Make directory and index known to system
; CALL TO MAPBTF AND DOBDSA FOR DISK CAN BE DELAYED TIL
; AFTER FILESYSTEM EXISTS BECAUSE NO NEW DISK ADRS GET
; ASSIGNED HERE BUT DRUM ADRS MUST BE ASSIGNED IMMEDIATELY

FILIN1:	CALL DOBDRA		;ASSIGN DRUM ADRS VIA BATS
	MOVE A,DIDSCA
	TLO A,(1B2)
	PUSHJ P,ASOFN		; Get ofn for di
	BUG(HLT,<FILINI: ASOFN FAILURE FOR DIRECTORY INDEX.>)
	HRLM A,SNSOFN		;REMEMBER SENSITIVE OFN RANGE START
	MOVEM A,DIOFN
	MOVEI A,0
	PUSHJ P,MAPDIR
	MOVE A,FDADR
	MOVEM 1,FDDSCA		;NICE TO KNOW
	TLO A,(1B2)
	PUSHJ P,ASOFN		; Get ofn for fd
	BUG(HLT,<FILINI: ASOFN FAILURE FOR FD.>)
	MOVEM A,FDLOFN
	HRLOI A,600000
	PUSHJ P,CHKDEV
	BUG(HLT,<FILINI: CHKDEV FAILED TO FIND DEVICE DSK:.>)
	MOVE A,FDLOFN
	HRLM A,DEVDSP(B)
	PUSHJ P,ASGPAG
	BUG(HLT,<FILINI: ASGPAG FAILURE FOR PAGE TO INIT FD'S.>)
	MOVE B,A
	HRLI B,140000
	MOVE A,FDLOFN
	PUSHJ P,SETMPG
	HRLI B,F
	MOVSI F,-NFDIB
FILIN2:	SKIPN A,@B
	 BUG(HLT,<FILINI: DIRECTORY PTT HAS EMPTY ENTRY>)
	TLO A,20
	PUSH P,B
	TLZE A,40
	PUSHJ P,ASOFN
	BUG(HLT,<FILINI: ASOFN FAILURE FOR FD.>)
	POP P,B
	MOVEM A,FDOFN(F)
	AOBJN F,FILIN2
	HRRM A,SNSOFN		;REMEMBER SENSITIVE OFN RANGE END
	HRRZ A,B
	PUSHJ P,RELPAG
	SKIPA FDFMTF		; CHANGE TO SKIPE FDFMTF TO AUTO CONVERT
	 PUSHJ P,CVTFD
	MOVEI A,1
	SETO B,
	CALL MAPDIR		; MAP SYSTEM DIRECTORY
	SETO A,
	EXCH A,DIRLCK		; LOCK DIRECTORY
	CAME A,[-1]		; WAS IT PROPERLY LOCKED?
	 BUG(CHK,<SYSTEM DIRECTORY NOT UNLOCKED -- UNLOCKED>)
	SETZ A,
	CALL MAPDIR
	MOVE A,[POINT 7,SBIDTB]
	MOVEI B,200
	SETZ C,
FILIN6:	ILDB D,A
	CAML D,C
	MOVE C,D
	SOJG B,FILIN6
UNLDIL:	MOVNI 1,0(D)
	PUSH P,D
	PUSHJ P,MAPDIR
	SETO A,
	EXCH A,DIRLCK
	CAME A,[-1]
	 BUG(CHK,<SUBINDEX NOT LOCKED -- UNLOCKED>)
	POP P,D
	SOJGE D,UNLDIL
	AOS FILIFG		;FILE SYSTEM OK TO USE NOW
	CALL MAPBTF		;MAP IN EXISTANT BITTALBE
	CALL DOBDSA		;FORCE ASSIGNING OF BAD DISK SPOTS
	POPJ P,

FDFMTF::-1			; CHANGE TO -1 IF OLD STYLE FORMAT

; CONVERT OLD STYLE FD INTO NEW STYLE
; CALLED BY FILIN2 IF OLD STYLE ENCOUNTERED

CVTFD:	MOVSI D,-NFDIB
	MOVEI E,1(P)		; POINTER TO PAGE VECTOR
	HRLI E,D
	ADD P,[NFDIB,,NFDIB]
CVTFD0:	CALL ASGPAG		; ASSIGN A PAGE FOR EACH COPY
	 BUG(HLT,<CVTFD: ASGPAG FAILED>)
	HRLI A,140000		; SET RW BITS
	MOVEM A,@E
	AOBJN D,CVTFD0
	PUSHJ P,ASGPAG		; ASSIGN WINDOW PAGE FOR OLD PTS
	 BUG(HLT,<CVTFD: ASGPAG FAILED>)
	HRLI A,140000
	PUSH P,A
	SETZ C,
CVTFDL:	HRLI C,-1000
	HRRZ A,C
	LSH A,-9
	MOVE A,FDOFN(A)
	MOVE B,0(P)
	CALL SETMPG
CVTFD1:	HRRZ A,C
	ROT A,-3
	ADDI A,0(A)
	ROT A,3
	CAIL A,NFDIB*1000
	 SUBI A,NFDIB*1000-10
	MOVE D,A
	LSH D,-9
	ANDI A,777
	ADD A,@E
	PUSH P,0(B)
	POP P,0(A)
	AOS B
	AOBJN C,CVTFD1
	CAIGE C,NFDIB*1000
	 JRST CVTFDL
	MOVSI D,-NFDIB
CVTFD3:	MOVE B,0(P)
	MOVE A,FDOFN(D)
	PUSHJ P,SETMPG
	MOVS A,@E
	HRR A,B
	BLT A,777(B)
	HRRZ A,@E
	CALL RELPAG
	AOBJN D,CVTFD3
	SETZM FDFMTF
	POP P,A
	HRRZS A
	CALL RELPAG
	SUB P,[NFDIB,,NFDIB]
	POPJ P,

NEWFD:	TDZA A,A
NEWIB:	MOVSI A,(1B2 )
	TLO A,(1B3)
	PUSH P,A
	MOVE A,DIDSCI		; Parameter dependent on configuration
	PUSHJ P,DSKASN		; Get a blank disc address
	BUG(HLT,<NEWIB: DSKASN FAILURE FOR INITIAL SYSTEM PAGE TABLES.>)
	TLO A,20
	IORM A,(P)
	EXCH A,(P)
	PUSHJ P,ASOFN
	BUG(HLT,<NEWIB: ASOFN FAILURE FOR INITIAL SYSTEM BLOCKS.>)
	PUSH P,A		; Save the ofn
	PUSHJ P,ASGPAG		; Get a page in job area
	BUG(HLT,<NEWIB: ASGPAG FAILURE FOR INITIALIZING SYTEM PT'S.>)
	PUSH P,A
	MOVE B,A
	TLO B,140000
	MOVE A,-1(P)
	PUSHJ P,SETMPG
	MOVE A,(P)
	HRLZ B,A
	HRRI B,1(A)
	SETZM (A)
	BLT B,777(A)
	MOVE B,(P)
	MOVEI A,0
	PUSHJ P,SETMPG
	POP P,A
	PUSHJ P,RELPAG
	POP P,A
	POP P,B			; Get disc address
	POPJ P,

	END

