Google
 

Trailing-Edge - PDP-10 Archives - tops20-v7-ft-dist2-clock - galaxy-sources/mtrddb.mac
There are 8 other files named mtrddb.mac in the archive. Click here to see a list.
TITLE	MTRDDB - Device Data Base for MOUNTR
SUBTTL	Preliminaries

;	COPYRIGHT (c) DIGITAL EQUIPMENT CORPORATION 1984, 1988.
;	ALL RIGHTS RESERVED.
;
;	THIS SOFTWARE IS FURNISHED UNDER A  LICENSE AND MAY BE USED AND  COPIED
;	ONLY IN  ACCORDANCE  WITH  THE  TERMS OF  SUCH  LICENSE  AND  WITH  THE
;	INCLUSION OF THE ABOVE  COPYRIGHT NOTICE.  THIS  SOFTWARE OR ANY  OTHER
;	COPIES THEREOF MAY NOT BE PROVIDED  OR OTHERWISE MADE AVAILABLE TO  ANY
;	OTHER PERSON.  NO  TITLE TO  AND OWNERSHIP  OF THE  SOFTWARE IS  HEREBY
;	TRANSFERRED.
;
;	THE INFORMATION IN THIS  SOFTWARE IS SUBJECT  TO CHANGE WITHOUT  NOTICE
;	AND SHOULD  NOT  BE CONSTRUED  AS  A COMMITMENT  BY  DIGITAL  EQUIPMENT
;	CORPORATION.
;
;	DIGITAL ASSUMES NO  RESPONSIBILITY FOR  THE USE OR  RELIABILITY OF  ITS
;	SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY DIGITAL.
SUBTTL	Required files 

	SEARCH MTRMAC
	SEARCH MONSYM
	SEARCH MACSYM
	.REQUIRE SYS:MACREL

	SALL				;Want clean listings

SUBTTL	Version Information

	DDBMAN==:0			;Maintenance edit number
	DDBDEV==:32			;Development edit number
	VERSIN (DDB)			;Generate edit number

IF2,<
	PRINTX [Assembling MTRDDB]
> ;End IF2
	SUBTTL	Table of Contents


;		Table of Contents for MTRDDB
;
;
;			   Section			      Page
;   1. Preliminaries. . . . . . . . . . . . . . . . . . . . .    1
;   2. Required files . . . . . . . . . . . . . . . . . . . .    2
;   3. Version Information. . . . . . . . . . . . . . . . . .    3
;   4. Table of Contents. . . . . . . . . . . . . . . . . . .    4
;   5. Revision History . . . . . . . . . . . . . . . . . . .    5
;   6. External Symbols . . . . . . . . . . . . . . . . . . .    6
;   7. Modifyable data area . . . . . . . . . . . . . . . . .    7
;   8. Initialize
;        8.1.   DSFINI - setup device status file . . . . . .    8
;        8.2.   DSFISQ - garbage collect. . . . . . . . . . .    9
;        8.3.   DSFIRS - Reset device file. . . . . . . . . .   10
;   9. Global routines
;        9.1.   DSFCRE - Create an entry. . . . . . . . . . .   11
;        9.2.   DSFGET - Get an entry . . . . . . . . . . . .   12
;        9.3.   DSFUDE - Update an entry. . . . . . . . . . .   13
;        9.4.   DSFGNX - Get next entry of specified type . .   14
;        9.5.   DSFDLE - Delete entry and put on free list. .   15
;        9.6.   DSFNUP - Set No UPdate of DDB . . . . . . . .   16
;        9.7.   DSFYUP - Set Yes UPdate of DDB. . . . . . . .   16
;  10. Utility routines
;       10.1.   CHKPTR - Check pointer for validity . . . . .   17
;       10.2.   DSFLOC - locate entry for specified device. .   18
;       10.3.   DSFUPD - update device file . . . . . . . . .   19
;       10.4.   DSFCKS - Compute checksum of dev. file. . . .   20
;       10.5.   DSFGTF - Get a free entry . . . . . . . . . .   21
SUBTTL 	Revision History

COMMENT \

*****	Release 5.0 -- Begin Development edits *****

1	5.1068		9-Dec-83
	Create Disk DataBase module from already existing routines
in MOUNTR.

2	5.1077		4-Feb-84
	Lots of changes:
1.  Remove most of the library searches
2.  Simplify the initialization code
3.  Create a reasonable set of routines to manage the disk data base:
    DSFCRE - Create an entry
    DSFGET - Get an entry
    DSFUDE - Update an entry
    DSFGNX - Get next entry of a given type
    DSFDLE - Delete entry and put on free list
    DSFNUP - Set no update of DDB
    DSFYUP - Set Yes Update of DDB

3	5.1083		6-Feb-84
	Add skip return on success in DSFDLE.

4	5.1089		11-Feb-84
	Base the checksum on the device status file version number, not
on the edit version number.  Also, check for correct device status file
version number before checksum so the error message may be a little more
meaningful.  Fix compare bug to compare with memory @DSFIS1+2.  Finally,
have CHKPTR also check to see if entry is unused as part of its check.
DSFGNX now calls that so next entry is always legit.

5	5.1157		6-Sept-84
	In routine DSFIS3, save the address of the last valid entry in the DDB
in DSB.NE.

6	5.1158		6-Sept-84
	In routine DSFDLE:, write DSBUF out to disk after deleting a structure
entry from the DDB.

7	5.1201		4-Feb-85
	Use device-status.bin in DSK: if debugging

10	5.1206		18-Mar-85
	If there is no space for a new DDB entry, make room by deleting all
DDB entries that are currently not in use and have a zero flag word.  Also
in MTRMAC, increase DSFPGS to two.

11	5.1207		20-Mar-85
	In routine DSFINI: look for PS:<SYSTEM>DEVICE-STATUS.BIN.
*****	Release 5.0 -- begin maintenance edits	*****

20	Increment maintenance edit level for version 5 of GALAXY.

*****	Release 6.0 -- begin development edits	*****

30	6.1037		26-Oct-87
	Move sources from G5: to G6:

31	6.1057		4-Nov-87
	Change PS: to BS: and PS:[SPOOL] to SPOOL: for Non PS: login feature.

32	6.1225		8-Mar-88
	Update copyright notice.

\	;End of Revision History
SUBTTL	External Symbols

	EXTERNAL TSTF		;debug word
	EXTERNAL LVERS		;Version number used to calc checksum
	EXTERNAL STOP,STOPNW	;Stop routines
	EXTERNAL BTWTO,TMCT0	;Operator message routines
	EXTERNAL BTNFO
SUBTTL	Modifyable data area

DSFJFN:	BLOCK 1			;DISK-STATUS FILE JFN
DSFE::	BLOCK DSFESZ		;CURRENT DEVICE-STATUS FILE ENTRY
DSFREE:	BLOCK 1			;Address of first in free list
				; 0 if no free list
DSFEND:	BLOCK 1			;Address of next available entry (at end)
DSFUPF:	BLOCK 1			;Update flag for DDB to disk
				;  0 if update DDB
				; -1 if no update DDB
	SUBTTL	Initialize -- DSFINI - setup device status file

; DSFINI - MAPS DEVICE-STATUS FILE INTO DSBUF
; RETURNS +1: ALWAYS

DSFINI:: MOVX T1,GJ%SHT+GJ%ACC	;FLAGS
	SKIPE TSTF		;If debugging use file in users connected dir
	SKIPA T2,[XWD -1,[ASCIZ/DSK:DEVICE-STATUS.BIN/]] ;Debug, use DSK: 
	HRROI T2,[ASCIZ/BS:<SYSTEM>DEVICE-STATUS.BIN/] ;[31]Use system file
	GTJFN			;GET JFN ON DEVICE-STATUS FILE
	 ERCAL STOP		;Shouldn't happen!

	MOVEM T1,DSFJFN		;SAVE JFN (just for grins)
	MOVX T2,OF%RD+OF%WR+OF%DUD ;FLAGS FOR OPENF
	OPENF			;Try to open
	 ERCAL STOP		;Shouldn't happen!

	HRLZ T1,DSFJFN		;GET JFN ,, FILE PAGE #
	MOVE T2,[.FHSLF,,DSBUF_-9] ;FORK HANDLE ,, FORK PAGE #
	MOVE T3,[PM%CNT+PM%RWX+PM%PLD+DSFPGS] ;FLAGS,,#PAGES
	PMAP			;MAP THE FILE IN
	 ERCAL STOP		;Shouldn't happen!

;  Check for proper checksum and CPU serial number.  If bad, go reset DDB

	CALL DSFCKS		;COMPUTE CHECKSUM
	MOVE T2,T1		;Save the checksum for a minute

	MOVEI T1,.APRID
	GETAB			;GET APR SERIAL #
	 JFCL			;SHOULD NEVER FAIL

	CAME T1,DSB.PS		;Same cpu?
	JRST [TMCT <%IChanged CPU>
	      JRST DSFIN3]	;No

	MOVE T3,DSB.VE		;Get the version for the device data base
	CAIE T3,DSBVER		;Is it the current?
	JRST [TMCT <%IIncorrect file format version>
	      JRST DSFIN3]	;No

	CAME T2,DSB.CK		;Correct checksum?
	JRST [TMCT <%IIncorrect Checksum>
	      JRST DSFIN3]	;No
	CALL DSFISQ		;If no problem, then setup ptrs. etc.

	RET			;Normal return

DSFIN3:	CALL DSFIRS		;Reset the file
	TMCT <%_SYSTEM:DEVICE-STATUS.BIN file will be reset>
	MOVEI T3,[ASCIZ/Device status file initialization error/]
	CALL BTWTO		;Send it off
	RET
	SUBTTL	Initialize -- DSFISQ - garbage collect

;  This routine wants to garbage collect and delete any free entries
;  then set up a couple of locations referencing DDB.
;  For this loop:
;	T1/	Address of currently examined entry
;	T2/	work
;	T3/	Address of first free entry
;	T4/	Number of entries left to peruse

DSFISQ:	SKIPN T4,DSB.NE		;Get # of entries to check
	JRST DSFIS4		;No entries??? should not happen

	SETZM DSB.NE		;No entries
	MOVEI T1,DSB.EO		;Get start of first entry
	MOVE T3,T1		;Current entry is first possible free
	
DSFIS1:	SETZM DSFPNT(T1)	;Clear the pointer field since it can't work
	MOVE T2,DSFSPC(T1)	;Get the spec field
	CAMN T2,[-1]		;Is it free?
	JRST DSFIS3		;Yes, go get next entry

;  Here to move entry if needed

	CAMN T3,T1		;Is it the current entry and no need to move?
	JRST [ADDI T3,DSFESZ	;Yes, just add to the first free entry
	      JRST DSFIS2]	;  and go get next entry

;  Need to move entry to squeeze.   T1 is the source, T3 is the destination.

	MOVE T2,T3		;Get destination
	HRL T2,T1		;Get source
	ADDI T3,DSFESZ-1	;Final destination
	BLT T2,(T3)		;Move the entry
	ADDI T3,1		;Finish updating to the next free entry

DSFIS2:	AOS DSB.NE		;Say we have another entry

;  Here to get next entry

DSFIS3:	ADDI T1,DSFESZ		;Point to the next entry
	SOJG T4,DSFIS1		;If more, go look at it

	SETZM DSFREE		;No free entries
	MOVEM T3,DSFEND		;Save next entry as the next free

	CALL DSFUPD		;Since we did all this work, update file

DSFIS4:	RET
	SUBTTL	Initialize -- DSFIRS - Reset device file

; RESET CONTENTS OF DEVICE-STATUS FILE  (T1/ APR SERIAL #)
;  Might want to send notification of resetting of device file!

DSFIRS:	SETZM DSBUF
	MOVE T2,[DSBUF,,DSBUF+1] ;GET BLT POINTER
	BLT T2,DSBUF+DSFSZ-1	;CLEAR REMAINDER OF BUFFER
	MOVEM T1,DSB.PS		;STORE APR SERIAL #

	MOVEI T1,DSBVER		;Get file version number
	MOVEM T1,DSB.VE		;Save it

				;No need to update pages!
				;  o  Will happen anyway on first entry
				;  o  If we die, the old file is as good

;	CALL DSFUPD

	SETZM DSFREE		;No free entries
	MOVEI T1,DSB.EO		;Get beginning of entries
	MOVEM T1,DSFEND		;Save it as the end

	RET			;ALL DONE
	SUBTTL	Global routines -- DSFCRE - Create an entry

;  Create an entry based on DSFE.
;  RETURNS:	T1 / pointer to entry
;		+1 if entry already exists
;		+2 if entry created

DSFCRE:: CALL DSFLOC			;First try to see if entry exists
	SKIPA				;Want a bad return (doesn't exist)
	RET				;oops.  can't create that which exists

	CALL DSFGTF			;Get a free entry

	MOVE T3,T1			;Copy destination to set up blt
	HRLI T3,DSFE			;Set up source
	BLT T3,DSFESZ-1(T1)		;Copy the entry

	CALL DSFUPD			;Back it up on disk
	RETSKP				;And done
	SUBTTL	Global routines -- DSFGET - Get an entry

;  Get an entry T1 / pointer to entry
;		DSFE with type and specification word
;		    would eventually like to drop this part of validation
;  RETURNS:	+1 if pointer is invalid
;		+2 if entry found
;			DSFE contains entry

DSFGET:: CALL CHKPTR			;First check the pointer
	RET				;Bad news

	MOVEI T2,DSFE			;Get destination
	MOVE T3,T2			;Copy destination to set up blt
	HRL T3,T1			;Set up source
	BLT T3,DSFESZ-1(T2)		;Copy the entry

	RETSKP				;Return it all to the user
	SUBTTL	Global routines -- DSFUDE - Update an entry

;  Update an entry.
;		T1 / pointer to entry
;		DSFE / contains new entry
;  RETURNS:	+1 if entry not undated (bad pointer or data)
;		+2 if entry updated
;		T1 / pointer to entry (may be updated!)

DSFUDE:: CALL CHKPTR			;Check the pointer
	RET				;Bad pointer

	MOVE T2,DSFE+DSFSPC		;Get spec word
	CAME T2,DSFSPC(T1)		;Are they at least the same?
	RET				;No, bad update!

	MOVE T3,T1			;Copy destination to set up blt
	HRLI T3,DSFE			;Set up source
	BLT T3,DSFESZ-1(T1)		;Copy the entry

	CALL DSFUPD			;Update things
	RETSKP
	SUBTTL	Global routines -- DSFGNX - Get next entry of specified type

;  This routine finds the next entry of the type specified in DSFE
;		T1 / pointer to current (find the next)
;		     or 0 if want first
;		DSFE+DSFTYP / Type of entry
;  RETURNS:	+1 if no more entries
;		+2 if next entry found
;		T1 / pointer to next entry
;		DSFE / entry

DSFGNX:: MOVE T4,DSFE+DSFTYP		;Get the type
	SKIPG T1			;Initial run?
	JRST [MOVEI T1,DSB.EO		;Yes
	      JRST DSFGN1]		;Go to loop
DSFGN0:	ADDI T1,DSFESZ			;Add to get to next entry
DSFGN1:	CAML T1,DSFEND			;At the end?
	RET				;Yes, with no entry found

	CALL CHKPTR			;Go check the current pointer
	 JRST DSFGN0			;No good, probably free entry, another.

	CAME T4,DSFTYP(T1)		;Correct type?
	JRST DSFGN0			;No, go try another

;  Found a live one.

	MOVEI T2,DSFE			;Get destination
	MOVE T3,T2			;Copy destination to set up blt
	HRL T3,T1			;Set up source
	BLT T3,DSFESZ-1(T2)		;Copy the entry

	RETSKP				;And done
	SUBTTL	Global routines -- DSFDLE - Delete entry and put on free list

;  This routine takes entry and puts it on free list
;		T1 / pointer
;	RETURNS: +1 always

DSFDLE:: CALL CHKPTR			;Check the pointer
	RET				;Bad pointer, nothing to delete

	SETOM DSFSPC(T1)		;Say no good in entry
	MOVE T2,DSFREE			;Get the free list header
	MOVEM T2,DSFTYP(T1)		;Save pointer
	MOVEM T1,DSFREE			;Update header
	CALL DSFUPD			;Update file
	RETSKP				;And done
SUBTTL Global routines -- DSFNUP - Set No UPdate of DDB

;  This routine simply sets no update of the DDB.  For performance.
;  Returns: +1 always

DSFNUP:: AOS DSFUPF			;Set no update of file
	RET				;And return

SUBTTL Global routines -- DSFYUP - Set Yes UPdate of DDB

;  This routine sets update to occur and does an update for good measure
;  Returns: +1 always

DSFYUP:: SOSG DSFUPF			;One less NO, update file?
	CALL DSFUPD			;Yes, update the file
	RET				;And return
	SUBTTL	Utility routines -- CHKPTR - Check pointer for validity

;  This routine checks to validate that a pointer is reasonable.
;		T1 / pointer
;	RETURNS: +1 if pointer is bad
;		 +2 if pointer is ok

CHKPTR:	CAIL T1,DSBUF			;Is it below the data base?
	CAML T1,DSFEND			;No, is it below the end?
	RET				;Not in range

	SETO T2,			;Want to check against -1
	CAMN T2,DSFSPC(T1)		;Is entry in use?
	RET				;Entry not in use

	RETSKP				;In range, ok to use
	SUBTTL	Utility routines -- DSFLOC - locate entry for specified device

; DSFLOC - LOCATE ENTRY FOR SPECIFIED DEVICE IN DEVICE-STATUS FILE
;  DSFE + DSFTYP / DEVICE TYPE
;  DSFE + DSFSPC / DEVICE IDENTIFIER
; RETURNS +1: DEVICE NOT REPRESENTED IN FILE
;	  +2: DEVICE ENTRY FOUND, T1/ pointer to entry
;	  DSFE contains entry

DSFLOC:: SKIPN T4,DSB.NE	;GET # OF ENTRIES TO CHECK
	RET			;NONE, IT AIN'T HERE!

	SKIPN DSFE+DSFSPC	;Is the identifier equal to 0?
	  $STOP <Attempt to locate DDB entry with 0 DSFSPC> ; Yes, must be bad

	MOVEI T1,DSB.EO		;START SCAN HERE
	DMOVE T2,DSFE		;GET REQUESTED TYPE AND IDENTIFIER

;  Loop on the DDB entries looking for an entry of the same type and spc.

DSFLC1:	CAME T2,DSFTYP(T1)	;DO DEVICE TYPES MATCH?
	JRST DSFLC2		;NO, SKIP IT
	CAMN T3,DSFSPC(T1)	;DO IDENTIFIERS MATCH?
	JRST [CALL DSFGET	;Yes, go set DSFE
		CALL STOP	;Should never happen
	      RETSKP]
DSFLC2:	ADDI T1,DSFESZ		;POINT AT NEXT ENTRY
	SOJG T4,DSFLC1		;GO CHECK NEXT ENTRY IF THERE IS ONE
;  End of loop

	RET			;Not found
	SUBTTL	Utility routines -- DSFUPD - update device file

; DSFUPD - COMPUTES AND INSTALLS CHECKSUM IN DEVICE-STATUS FILE
;	   BUFFER, THEN WRITES BUFFER OUT TO DISK
; RETURNS +1: ALWAYS

DSFUPD:	SKIPLE DSFUPF		;Do we want an update on disk?
	RET			;No

	SAVEAC <T1>		;Save T1 for sure
	SETZM DSFUPF		;Make sure things haven't gotten confused
	CALL DSFCKS		;COMPUTE CHECKSUM OF BUFFER
	MOVEM T1,DSB.CK		;STORE IT
	HRLZ T1,DSFJFN		;GET JFN ,, FIRST PAGE #
	JUMPE T1,R		;OOPS, NO JFN... HEH HEH HEH... BYE!
	MOVEI T2,DSFPGS		;# OF PAGES TO UPDATE
	UFPGS			;WRITE 'EM OUT
	 JFCL			;IGNORE ERRORS
	RET
	SUBTTL	Utility routines -- DSFCKS - Compute checksum of dev. file

; DSFCKS - COMPUTE CHECKSUM OF DEVICE-STATUS FILE BUFFER
; RETURNS +1: ALWAYS, WITH CHECKSUM IN T1

DSFCKS:	MOVEI T1,DSBVER		;START WITH CURRENT VERSION
	MOVEI T3,DSFSZ-1	;INIT SCANNING POINTER
DSFCK1:	TLZ T1,400000		;POSITIVE
	TRO T1,1		; AND ODD
	MULI T1,400003		;RANDOMIZE
	MOVE T1,T2		;COPY BACK TO T1
	XOR T1,DSBUF(T3)	;MERGE NEXT WORD
	SOJG T3,DSFCK1		;LOOP THRU BUFFER
	RET			;RETURN TO CALLER
	SUBTTL	Utility routines -- DSFGTF - Get a free entry

;  Get a free entry to be created.  Internal only routine.
;  Entry is not initialized!
;  RETURNS	T1 / Address of entry
;		+1 always

DSFGTF:	SKIPE DSFREE			;Any free entries in list?
	JRST [MOVE T1,DSFREE		;Yes, get address into T1
	      MOVE T2,DSFTYP(T1)	;Get next link
	      MOVEM T2,DSFREE		;Save as the beginning of free
	      JRST DSFGT5]		;Go to finish

	MOVE T1,DSFEND			;Get end of entries
	CAILE T1,DSBUF+DSFSZ-DSFESZ	;Room for one more?
	JRST [CALL MKRM			;No, make room
	      $STOP <No free entry in DSBUF> ;No room left
	      JRST DSFGTF]		;Try again
	MOVE T2,T1			;Make copy of end
	ADDI T2,DSFESZ			;Add entry size
	MOVEM T2,DSFEND			;Save it as new end of entries
	AOS DSB.NE			;Remember we are using another entry

DSFGT5: RET
	SUBTTL	Utility routines -- MKRM - make room for DSFGTF

;This routine is called when there is no space in the DDB to create an
;entry.  It tries to delete entries that are of no use.
;	returns +1 still no space
;		+2 allocated some space.

MKRM:	STKVAR <MKSPAC>		;Counter for deleted entries
	TMCT <%I	The following unuse structure entries have been deleted
	in order to allocate space to create new entries.%_>
	SETZM MKSPAC		;No one deleted yet.
	SKIPN T4,DSB.NE		;Get # of entries to check
	JRST MKRMEX		;No entries??? should not happen
	MOVEI T1,DSB.EO		;Get start of first entry
	CALL DSFNUP		;No update
MKRM1:	SKIPN DSFFLG(T1)	;Is it the default case.
	JRST [SKIPE DSFPNT(T1)	;Yes, is it mounted
	      JRST MKRM2	;Yes, get the next
	      MOVE T2,DSFTYP(T1) ;Get the type
	      CAIE T2,.DVSTR	;Is this a structure?
	      JRST MKRM2	;No, get the next	      
	      AOS MKSPAC	;Got one
	      MOVEI T2,12	;Number of structures on one line.
	      IDIV T2,MKSPAC	;See if we are at end of line
	      SKIPN T3,		;Do we need a new line
	      TMCT <%_>		;Yes
	      MOVE T2,DSFSPC(T1) ;Get the structure name.
	      TMCT <%2S:	> ;Add the name
	      CALL DSFDLE	;Yes, get rid of it
	      JRST MKRMEX	;Bad pointer
	      JRST MKRM2]	;Get the next
MKRM2:	ADDI T1,DSFESZ		;Point to the next entry
	SOJG T4,MKRM1		;If more, go look at it
MKRM3:	CALL DSFYUP		;Time to update
MKRMEX:	SKIPN MKSPAC		;Did we delete any?
	RET			;No, error return
	MOVEI T3,[ASCIZ/DEVICE-STATUS.BIN has been exhausted./]
	CALL BTNFO		;Request no formatting
	CALL BTWTO		;Send it off
	RETSKP			;Yes, success

	END