C*	DSMTB - COMPILE TOTAL BLOCK STATS PER FILE/OWNER
C
	SUBROUTINE DSMTB (NDEV)
C
C	SCAN THROUGH THE INDEX FILE COMPILING TOTAL BLOCKS
C	USE/ALLOCATED ON A FILE OWNER BASIS.
C
	INCLUDE 'DSMCM.COM/NOLIST'
C
	DIMENSION IBLOCK(2,16)
	DIMENSION IHDRS(256,16)
C
C	ISTAT(1)	= UIC
C	ISTAT(2)	= FLAGS WORD
C			  BYTE 1 CONTAINS # OF FILE-ID MISMATCHES
C			  BYTE 2 CONTAINS FLAG BITS -
C				BIT 0 - UIC CHECKED FOR USEAGE LIMITS
C	ISTAT(3-4)	= BLOCKS USED
C	ISTAT(5-6)	= BLOCKS ALLOCATED
C	ISTAT(7)	= NUMBER OF FILES IN DIRECTORY
C
	ILNDX	= 1		! LUN FOR INDEXF.SYS
	NBIND	= 8		! NO. OF BLOCKS IN BITMAP FOR INDEXF.SYS
	NWSEC	= 256		! NO. WORDS PER SECTOR (BLOCK)
	KBS	= 3		! VIRTUAL START BLOCK NO. FOR BITMAP
	KBHDR	= KBS+NBIND	! VIRTUAL START BLOCK FOR FILE HEADERS
	NBREAD	= 16		! NO. OF HEADERS TO READ PER I/O
	NWUICR	= 2*NBREAD	! NO. OF WORDS IN UIC/SEQ NO. MAP FILE TO READ
	IFLNOF = KBHDR		! OFFSET FOR FILE NO. CALCULATION
C
C	LOOP ON MAP SCRATCH FILE CREATED IN DSMUIC
C
	NRMAP = 1
	CALL X1LRN (FIDMAP, IEFMAP)
D	TYPE *,'IEFMAP',
D	TYPE *,'IEFMAP=',IEFMAP
 100	CONTINUE
	NBREAD = MIN0 (NBREAD,IEFMAP-NRMAP+1)
	IF (NRMAP .GT. IEFMAP) GO TO 900
	CALL X1DR (FIDMAP, NRMAP, NWUICR, IBLOCK)
C
	DO 110 I=1, NBREAD
	IF (IBLOCK(1,I) .NE. -1) GO TO 200
 110	CONTINUE
	GO TO 300
C
C	READ 16 HEADERS AND GET STATS
C
 200	CONTINUE
	IFLN = KBHDR - IFLNOF
	CALL RVB (ILNDX, IHDRS, NBREAD, KBHDR, NERR)
D	TYPE *,'NERR=',NERR,' NBREAD=',NBREAD
	IF (NERR.NE.1) GO TO 490
C
C	CHECK EACH GROUP OF 16 HEADERS, COMPARE WORD IN MAP FILE
C
	DO 250 J=1, NBREAD
	IF (IBLOCK(1,J) .EQ. -1) GO TO 250
C
C	LOOK UP UIC IN ISTAT AND ADD STATS
C
	NUIC = IBLOCK(1,J)
D	ITEMP = NRMAP-17+J
D	TYPE 1000,NUIC, IHDRS(5,J),ITEMP
D1000	FORMAT (' ',O6,2X,O6,2X,O6)
	NER = 0
	CALL DSMBS (1, NFO, IPOS, NER)
	IF (NER .NE. 0) GO TO 250
	CALL DSMAD (IHDRS(1,J), IFLN+J,IBLOCK(2,J),
	1	ISTAT(2,IPOS),ISTAT(3,IPOS),ISTAT(5,IPOS),ISTAT(7,IPOS))
 250	CONTINUE
	GO TO 350		! KBHDR ALREADY UPDATED FROM RVB
C
 300	KBHDR = KBHDR + NBREAD
 350	CONTINUE
	GO TO 100
C
 490	CONTINUE
	TYPE *,'ERROR ON IHDRS', KBHDR
 900	CONTINUE
C
C	CLOSE FILES
C
	CALL X1EF (FIDMAP)
	CALL DBKCF (ILNDX)
C
	RETURN
	END
