C*	DSMCHK	- CHECK DISK ALLOCATION LIMITS
C
	SUBROUTINE DSMCHK
C
C 12/10/79	LEN	- ONLY FIRST UIC ON ALLLO-SPEC RECORD MUST
C		CONTAIN A DEVICE/UIC SPECIFICATION.
C 12/13/79	LEN	- LOG TO DSM.LOG ALL WARNING MESSAGES ISSUED.
C
C
C	THIS SUBROUTINE COMPARES THE FINDINGS OF DSM'S SCAN OF DIRECTORIES
C	WHICH GIVES TOTAL BLOCKS USED ON A DIRECTORY BASIS, WITH ALLOCATION
C	SPECIFICATION LIMITS DESCRIBED IN LB0:[1,1]DSMALSP.DAT.
C
C	DSMALSP.DAT IS A NORMAL ASCII EDITABLE FILE (RECORDS NO LONGER THAN 80
C	PLEASE) WHICH CONTAINS THE SPECIFICATION FOR ALLOCATION IN THE
C	FOLLOWING FORMAT -
C
C	DBN:[GROUP,OW] OR DBN:[GROUP,*] + DBN:[GROUP,OW] +.... = TOTAL BLOCKS
C
C	E.G.
C	DB0:[225,1] + DB1:[225,1] = 50000
C	DB0:[327,*] + DB0:[300,*] + DB2:[327,1] = 120000
C
C	THE SPECIFICATION RECORDS ARE READ IN AND THE TOTAL FOR ALL THE
C	UIC'S ARE SUMMED TO CHECK AGAINST LIMIT. IF THE TOTAL IS OVER THE
C	LIMIT, THE INFORMATION IS APPENDED TO DSMNOT.DAT IN THE FOLLOWING
C	FORMAT.
C
C	WORD  1	- # OF UIC'S INVOLVED IN FOR THIS ALLOCATION SPECIFICTION
C	WORD  2	- WARNING # FOR THIS MESSAGE.
C		  CURRENT WARNING IS CHECKED AGAINST PREVIOUS WARNING FILE,
C		  DSMMSG.DAT. IF THE SAME MESSAGE WAS THERE, THEN THE WARNING
C		  NUMBER IS INCREASED.
C	WORD 3,4- I*4 TOTAL BLOCKS SUMMED UP FOR THIS ALLO-SPEC RECORD
C	WORD 5,6- I*4 BLOCK LIMIT FOR THIS ALLO-SPEC RECORD
C	NEXT # OF UIC WORDS - ALL OFFENDING UIC'S FOR THIS ALLO-SPEC RECORD
C	NEXT 40 WORDS - THE ALLOCATION SPECIFICATION RECORD.
C
C	LAST WORD - 0 TO INDICATE END OF FILE (# UIC'S = 0)
C
	INCLUDE 'DSMCM.COM/NOLIST'
C
	DIMENSION CHKID(3), CHKBF(128), IBUF(40), BBUF(80)
	DIMENSION UPFID(3), UPFBUF(256)
	DIMENSION IUICV(1)
	EQUIVALENCE (CHKBF,RBMAP), (IBUF,BBUF)
	EQUIVALENCE (UPFBUF,RBMAP(1,2))
	EQUIVALENCE (IUICV,ISTAT)
C
D	DIMENSION BSTAT(14,1)
D	EQUIVALENCE (BSTAT,ISTAT)
	DATA ILCHK/1/, IRBCHK/1/, ILALSP/2/
	DATA ILUPF/3/, NRBUPF/2/
C
	LBITON(IBIT) = IAND(IBIT,IFLAGS) .NE. 0
C
C	TRY TO OPEN OLD ERROR MESSAGE FILE WHICH CONTAINS THE LAST WARNING
C	INFORMATION.
C
D	NRTB = 11
D 1	CALL X1DR (FIDTB, NRTB, 1, I)
D	IF (I.EQ.0) GO TO 2
D	NRTB = NRTB + I*NWSTAT + 2
D	GO TO 1
D 2	CONTINUE
	NFO = 0
	CALL SIVFL (0, ISTAT, NWSTAT*MAXUIC)
	NWARNR = 0			! # OF WARNING RECORDS
	NRSAV = NRTB
	I = NRTB
	CALL X1DW (FIDTB, I, 1, 0)		! EOF FOR MESSAGES
	I = 10					! START POINTER
	CALL X1DW (FIDTB, I, 1, NRSAV)
	CALL X1CL (FIDTB)
C
	CALL X1LU (CHKID, CHKBF, IRBCHK, 1, 0,
	1	ILCHK, 'O', 'LB0:[1,1]', -1, 'DSMMSG.DAT', NER)
	LMSGO = NER .EQ. 0
	IF (LMSGO) GO TO 50
C
C	OPEN NEW VERSION OF DSMMSG.DAT
C
	CALL X1LU (CHKID, CHKBF, IRBCHK, 1, 0,
	1	ILCHK, 'N', 'LB0:[1,1]', -1, 'DSMMSG.DAT', NER)
	IF (NER .NE. 0) CALL DSMER (ILCHK, NER)
	NRCHK = 1
	CALL X1DW (CHKID, NRCHK, 1, 0)	! # OF WARNINGS/CHECKSUMS
	CALL X1DW (CHKID, NRCHK, 1, 0)	! # OF USERS WITH REVOKED PRIVLEGES
	CALL X1CL (CHKID)		! CLEAR THE BUFFER JUST IN CASE
 50	CONTINUE
C
C	OPEN ALLOCATION SPECIFICATION FILE
C
	OPEN (UNIT=ILALSP, TYPE='OLD', NAME='LB0:[1,1]DSMALSP.DAT',
	1	READONLY, ERR=100)
	GO TO 125
 100	CALL DSMER (ILALSP, NER)
 125	CONTINUE
C
C	READ A RECORD FROM THE ALLOCATION SPECIFICATION FILE, DSMALSP.DAT
C
 200	CONTINUE
	LFIRST = .TRUE.
	READ (ILALSP, 505, END=900) IBUF
C
C	IF '!' IS IN COLUMN 1 THEN CONSIDER THIS A COMMENT LINE
C
	IF (BBUF(1) .EQ. '!') GO TO 200
 505	FORMAT (40A2)
D	WRITE (6, 9000) IBUF
D9000	FORMAT (' ',40A2)
C
	NFO = 0				! RESET BINARY SEARCH POINTER (DSMBS)
	NCH = 80
	KTBU = 0
	LNONEX = .FALSE.		! UIC'S NON-EXISTENT INITIALLLY
	CALL GETADR (IBFAD, IBUF)
C
C	PARSE THE ALLO-SPEC RECORD AND SUM THE REQUESTED DIRECTORIES
C
 220	CONTINUE
	IFLAGS = 0
	CALL DSMPR1 (IBFAD, NCH, NER)
	IF (NER .NE. 0) GO TO 300
C
C	MUST SPECIFIY UIC AND MUST NOT HAVE WILD GROUP
C	FIRST UIC MUST HAVE A DEVICE ASSOCIATED WITH IT. SUBSEQUENCT
C	UIC'S PERTAIN TO THE LAST SPECIFIED DEVICE -
C	DB2:[310,*] + [320,*] + DB0:[310,*] + [320,*]
C
	IF ((LFIRST.AND..NOT.LBITON(IDSDEV)) .OR. .NOT.LBITON(IDSUIC) .OR.
	1	LBITON(IDSWGR)) GO TO 300
	LFIRST = .FALSE.
C
C	FIND ALL BLOCKS ALLOCATED FOR THIS (THESE) UICS ON THE GIVEN DEVICE
C
	CALL DSMTUI (KTBU, LNONEX)
C
C	CHECK IF MORE ON THE ALLO-SPEC RECORD
C
	IF (LBITON(IDSPLU)) GO TO 220
	IF (LBITON(IDSEQU)) GO TO 310
C
C	ELSE ERROR
C
 300	CONTINUE
	WRITE (6, 510) IBUF
 510	FORMAT (' SYSTAX ERROR ON FOLLOWING ALLO-SPEC RECORD -',/
	1	' ',40A2)
	GO TO 200
C
C
C	CHECK THE LIMIT !!
C	IF LNONEX IS NOT TRUE, THEN NONE OF THE UIC'S WERE LOCATED FOR
C	THIS ALLO-SPEC RECORD. SKIP FURTHER PROCESSING AND GET THE NEXT
C	ALLO-SPEC RECORD
C
C
 310	CONTINUE
D	WRITE (6, 9010) KTBU, KTOT
D9010	FORMAT (' KTBU,KTOT',2I10)
	IF (.NOT.LNONEX) GO TO 200		! NON-EXISTENT UIC'S
	IF (KTBU .LT. KTOT) GO TO 200		! IT'S OK
C
C	IT'S OVER THE LIMIT. CHECK THE OLD MESSAGE FILE AND GET THE
C	WARNING NUMBER.
C
	NWARN = 1
	IF (LMSGO) CALL DSMOMS (CHKID, NWARN, IBUF)
C
C	FILL IN DSMNOT WITH THE WARNING INFORMATION
C
D	WRITE (6,9020) NFO,NWARN,KTBU,(BSTAT(2,I),BSTAT(1,I),I=1,NFO),
D9020	FORMAT (' NFO,NWARN,KTBU',3I7,/(' [',O3,',',O3,']'))
D	WRITE (6, 9000) IBUF
	NCHW = IRNSC (IBUF, 1, 80)
	WRITE (6, 515) NWARN, (BBUF(I),I=1,NCHW), KTBU
 515	FORMAT (' #',I2,5X,<NCHW>A1,'/',I6)
	CALL X1DW (FIDTB, NRTB, 1, NFO)
	CALL X1DW (FIDTB, NRTB, 1, NWARN)
	CALL X1DW (FIDTB, NRTB, 2, KTBU)
	CALL X1DW (FIDTB, NRTB, 2, KTOT)
	DO 340 I=1, NFO
	CALL X1DW (FIDTB, NRTB, 1, ISTAT(1,I))
 340	CONTINUE
	CALL X1DW (FIDTB, NRTB, 40, IBUF)
	CALL X1DW (FIDTB, NRTB, 1, 0)
	NRTB = NRTB - 1
	NWARNR = NWARNR + 1		! UPDATE # OF WARNING RECORDS
	GO TO 200
C
C
C	ALL DONE - COPY THE WARNING NUMBER AND ASSOCIATED CHECKSUM
C	TO DSMMSG.DAT
C	FIRST CHECK DSMMSG.DAT FOR USER WHO HAD PRIVS REVOKED AT LAST OUTING
C	AND RESTORE THEM TO NORMAL.
C
C
 900	CONTINUE
	CALL DSMRES (CHKID, UPFID, UPFBUF, NRBUPF, ILUPF, NERUPF)
	IF (NERUPF .NE. 0) CALL DSMER (ILUPF, NERUPF)
C
C	UPDATE THE TWO RECORD POINTERS BEFORE WE START
C	1) # OF WARNING/CHECKSUM RECORDS TO FOLLOW (2 WORDS EACH)
C	2) # OF USERS WITH MODIFIED PRIVS TO FOLLOW (AFTER WARN/CHKSUM RECS)
C
	NRCHK = 1
	CALL X1DW (CHKID, NRCHK, 1, NWARNR)
	I = NWARNR*2 + 2
	CALL X1DW (CHKID, I, 1, 0)
	NWARNT = 0			! DOUBLE CHECK ON # OR WARNING MSGS
C
 905	CONTINUE
	CALL X1DR (FIDTB, NRSAV, 1, ITNFO)
	IF (ITNFO .EQ. 0) GO TO 920		! END OF MESSAGES
	NWARNT = NWARNT + 1
	IF (NWARNT .GT. NWARNR) GO TO 915
	CALL X1DR (FIDTB, NRSAV, 1, NWARN)
	CALL X1DW (CHKID, NRCHK, 1, NWARN)	! WARNING # TO DSMMSG.DAT
C
C	CALCULATE THE CHECKSUM -
C	CHECKSUM = NFO + (ALL UICS) + 40 WORD ASCII MESSAGE
C
	ICKSUM = ITNFO
	NRSAV = NRSAV + 4		! GO PAST BLOCKS USED AND LIMIT
	CALL X1DR (FIDTB, NRSAV, ITNFO+40, IUICV)
	DO 910 I=1, ITNFO + 40
	ICKSUM = ICKSUM + IUICV(I)
 910	CONTINUE
C
C	WRITE OUT THE CHECKSUM
C
	CALL X1DW (CHKID, NRCHK, 1, ICKSUM)
C
C	CHECK IF WARNING # FOR THESE UIC'S IS GREATER THAN IRVLIM -
C	THE WARNING # AT WHICH TO REVOKE PRIVS.
C
	IF (NWARN .GT. IRVLIM) CALL DSMREV (CHKID, UPFID, IUICV, ITNFO)
	GO TO 905				! GET THE NEXT ONE
C
C	THE # OF WARNING MESSAGES DOES NOT CHECK
C
 915	CONTINUE
	WRITE (6, 520) NWARNR, NWARNT
 520	FORMAT (' # OF WARNING MESSAGES DO NOT MATCH ',
	1	'NWARNR=',I4,5X,'NWARNT=',I4)
	GO TO 925
C
C	CLOSE THE FILES
C
 920	CONTINUE
	IF (NWARNR .NE. NWARNT) GO TO 915
 925	CONTINUE
C
	CALL X1EF (UPFID)
	CALL X1EF (CHKID)
	CLOSE (UNIT=ILALSP)
C
C
C	GO CHECK OVER-ALLOCATIONS FOR THIS RUN OF $$$DSM. DELETE FILES FROM
C	OFFENDING ACCOUNTS IF AT THE WARNING NUMBER TO TAKE THIS ACTION.
C
	CALL DSMDEL
C
C	CHECK FLAGS BYTE 2 (BIT 0) OF DSMNOT RECORDS.
C	THIS WILL INDICATE WHETHER OR NOT THE ASSOCIATED UIC WAS CHECKED
C	FOR OVER-ALLOCATIONS.  IF BIT 0 IS OFF, THEN WRITE A MESSAGE TO
C	LB0:[1,1]DSM.LOG REPORTING THE UNACCOUNTED UICS.
C
	CALL DSMCK2
C
C
	RETURN
	END
