      program UNDEL
c             -----
c List all deleted files on a FILES-11 disk
c
c  ------------------------------------------------------------------------
c
c  Bitmap holds 220 blocks, enough for an RA81 with cluster=1
c
      parameter (maxbitblk=220)
c
      character name*86,file*86,device*10,dir*60,ans*1,result*86
      integer*4 rslen,bitmap(128,maxbitblk),dirty,blocks
      logical*1 done(maxbitblk)
      byte record(512)
c
c  Home block definitions
c
      integer*4 dum3(3),dum,headers,maxfiles
      integer*2 i2dum3(3),cluster,mapvbn,mapsize
      byte struc(2)
c
c  File header definitions
c
      integer*2 check,fid(3),extfid(3),bakfid(3)
      integer*4 filechar,idoff,resoff,acloff
      equivalence (fid(1),record(9)),
     &            (extfid(1),record(15)),
     &            (filechar,record(53)),
     &            (bakfid(1),record(67)),
     &            (check,record(511))
c
c
c  Open INDEXF.SYS and BITMAP.SYS on the afflicted disk
c
      call LIB$GET_FOREIGN(file)
      lendev=INDEX(file,':')
      if(lendev.eq.0) stop 'No device specified, no risks taken'
      device=file(1:lendev)
      print*,'Opening index file and bitmap on ',device
c
      open(1,file=device(1:lendev)//'[000000]INDEXF.SYS',readonly,
     &     form='unformatted',recordtype='fixed',status='old')
      open(2,file=device(1:lendev)//'[000000]BITMAP.SYS',readonly,
     &     form='unformatted',recordtype='fixed',status='old')
c
c  Read in the storage bitmap, skipping over the SCB (block 1)
c
      read(2)
      i=1
    5 read(2,end=6) (bitmap(j,i),j=1,128)
      i=i+1
      go to 5
c
    6 nblocks=i
      print*,nblocks,' blocks read from storage bitmap'
      do i=1,nblocks
         done(i)=.false.
      enddo
c
c  Read the home block (record 2) from INDEXF.SYS
c
      print*,'Reading home block on ',device
      read(1)
      read(1) dum3,struc,cluster,i2dum3,mapvbn,dum,maxfiles,mapsize
      if(struc(2).ne.2) stop 'Disk is not a FILES-11 ODS-2 disk.'
      print*,'Disk is Files-1 ODS-2 version',struc(1)
      print*,'Cluster size is',cluster
      print*,'Maximum number of files is',maxfiles
      print*,'Index file bitmap starts at VBN',mapvbn,
     &       ' and goes on for',mapsize,' blocks'
      headers=mapvbn+mapsize
      print*,'File headers start at VBN',headers
c
c  Skip over the alternate home block, index bitmap etc. and start reading
c  headers for the file
c
      do i=3,headers-1
         read(1,end=150)
      enddo
      ivbn=headers-1
      blocks=0
      dirty=0
      iseek=0
      lastblock=0
      do 100 i=1,maxfiles
         ivbn=ivbn+1
         read(1,end=150) record
c
c  Get the name from the ID offset; the first 20 chars are at the ID offset
c  The remaining 66, if they exist, are later on in the ident area
c
   30    idoff=record(1)
         idoff=idoff*2
         mpoff=record(2)
         mpoff=mpoff*2
         if(idoff.le.0.or.idoff.gt.512) go to 100
         k=1
         name=' '
         do j=1,20
            name(j:j)=CHAR(record(idoff+k))
            k=k+1
            if(idoff+k.gt.mpoff) go to 35
         enddo
         k=55
         do j=21,86
            name(j:j)=CHAR(record(idoff+k))
            k=k+1
            if(idoff+k.gt.mpoff) go to 35
         enddo
   35    lenl=INDEX(name,';')-1
         if(lenl.le.0) lenl=86
         if(check.ne.0.and.fid(1).ne.0) go to 100
         print*,name(1:72)
         if(iseek.eq.0) go to 100
c
100      continue
  150 print*,'EOF on INDEXF.SYS'
  160 close(1)
      close(2)
      call EXIT
         END
c
