home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / UNIFLEX / UNIFLEX / UniFLEX_Std.Utils1.tar.Z / UniFLEX_Std.Utils1.tar / utils1 / fcheck < prev    next >
Text File  |  1981-09-01  |  13KB  |  751 lines

  1.  opt nol,pag
  2.  ttl Free block check program
  3.  lib sysdef
  4.  opt lis
  5.  pag
  6.  
  7.  org 0
  8.  
  9. * Free block check program
  10.  
  11. fch sys update update the system
  12.  ldd 0,s get arg count
  13.  cmpd #2 is it ok?
  14.  bne fch8 error?
  15.  ldd 4,s get arg
  16.  std iopn2 set sys call
  17.  sys ind,iopn open the device
  18.  bes fch8 error?
  19.  std dfd save file desc
  20. * check for block type device
  21.  ldd dfd get file desc
  22.  sys seek,0,512,0 seek to sir
  23.  ldd dfd
  24.  sys read,sir,512 read in the sir
  25.  bes fch8
  26.  ldd sir+16 get fdn block count
  27.  std fdcnt save it
  28.  addd #2 set 1st avail block number
  29.  std frbl
  30.  tst sir+18 check if too big for this program (65000 max blocks)
  31.  bne fch8
  32.  ldd sir+19 get volume size
  33.  std vlcnt save it
  34.  ldx #bm point to bit map
  35.  ldd #0
  36. fch4 std 0,x++ zero bit map
  37.  cmpx #bm+BMSZ end of map?
  38.  bne fch4
  39.  jsr frl find free list blocks
  40.  jsr fdn find allocated blocks
  41.  jsr filin fill in rest of map
  42.  jsr lost report lost blocks
  43.  jsr rprt report all data found
  44.  ldd #0
  45.  sys term exit
  46. fch8 swi temp error routine
  47.  
  48. *
  49. * report data collected
  50. *
  51.  
  52. rprt ldx #rm1 header
  53.  jsr pms print it
  54.  ldx #rm2 total files
  55.  ldd bfc add up file counts
  56.  addd cfc
  57.  addd dfc
  58.  addd rfc
  59.  jsr npms
  60.  ldd rfc get regular file count
  61.  ldx #rm3
  62.  jsr npms
  63.  ldd dfc directory file count
  64.  ldx #rm4
  65.  jsr npms
  66.  ldd bfc block device count
  67.  ldx #rm5
  68.  jsr npms
  69.  ldd cfc character device count
  70.  ldx #rm6
  71.  jsr npms
  72.  ldd sindc single ind map blocks
  73.  addd dindc calc total blocks used
  74.  addd tindc
  75.  addd dirbc
  76.  addd rgfbc
  77.  ldx #rm7 print totals
  78.  jsr npms
  79.  ldd rgfbc regular file block count
  80.  ldx #rm8
  81.  jsr npms
  82.  ldd dirbc directory block count
  83.  ldx #rm9
  84.  jsr npms
  85.  ldd sindc single ind map blocks
  86.  ldx #rm10
  87.  jsr npms
  88.  ldd dindc double ind map blocks
  89.  ldx #rm11
  90.  jsr npms
  91.  ldd tindc triple ind map blocks
  92.  ldx #rm12
  93.  jsr npms
  94.  ldd fdcnt fdn block count
  95.  ldx #rm13
  96.  jsr npms
  97.  ldd fbc free block count
  98.  ldx #rm14
  99.  jsr npms
  100.  ldd ufdc used fdn count
  101.  ldx #rm15
  102.  jsr npms
  103.  ldd ffdc free fdn count
  104.  ldx #rm16
  105.  jsr npms
  106.  ldd oorfb out of range blocks
  107.  ldx #rm17
  108.  jsr npms
  109.  ldd dupbc dupd blocks in free
  110.  ldx #rm18
  111.  jsr npms
  112.  ldd oorflb bad file blocks
  113.  ldx #rm21
  114.  jsr npms
  115.  ldd dupfc dupd file blocks
  116.  ldx #rm19
  117.  jsr npms
  118.  ldd mbcnt missing block count
  119.  ldx #rm20
  120.  jmp npms return
  121.  
  122. *
  123. * Output number in D
  124. *
  125.  
  126. ostr ldx #stbf point to buffer
  127.  jsr decst convert number to string
  128.  std iwrt3 save in call
  129.  ldd #stbf set string begin
  130.  std iwrt2
  131.  ldd #1 set file desc
  132.  sys ind,iwrt output number
  133.  rts return
  134.  
  135. *
  136. * print string routines
  137. *
  138.  
  139. npms pshs x save string ptr
  140.  bsr ostr print number
  141.  puls x
  142. pms stx iwrt2 set string in call
  143.  ldd #0 set counter
  144. pms2 tst 0,x+ find string end
  145.  beq pms3
  146.  incb
  147.  bra pms2
  148. pms3 std iwrt3 save count
  149.  ldd #1 set output
  150.  sys ind,iwrt
  151.  rts return
  152.  
  153. *
  154. * Find all blocks in free list
  155. *
  156.  
  157. frl ldd #0 zero counters
  158.  std fbc
  159.  std oorfb
  160.  std dupbc
  161.  ldx #sir+$bd point to incore free list
  162.  ldb 0,x+ get count
  163.  beq frl6 no free?
  164. frl2 bsr gb get blocks from list
  165.  tst 0,x bad block?
  166.  bne frl8
  167.  ldd 1,x get link block
  168.  beq frl6 end of list?
  169.  cmpd vlcnt in range?
  170.  bhi frl8
  171.  cmpd frbl
  172.  blo frl8
  173.  jsr rfb read in block
  174.  ldx #bbuf point to block data
  175.  ldb #100 set block count
  176.  bra frl2
  177. frl6 rts return
  178. frl8 ldx #bdlne print error
  179.  jsr pms
  180.  ldd #0
  181.  sys term exit
  182.  
  183. *
  184. * Get blocks from free list
  185. *
  186.  
  187. gb pshs b save count
  188.  ldb 0,s
  189.  decb find block start location
  190.  lda #3 3 bytes per block
  191.  mul
  192.  leax d,x point to end of list
  193. gb2 tst 0,x out of range?
  194.  beq gb4
  195. gb3 ldd oorfb get counter
  196.  addd #1 bump by one
  197.  std oorfb save new
  198.  bra gb5
  199. gb4 ldd 1,x get block number
  200.  beq gb5
  201.  cmpd vlcnt check if in range
  202.  bhi gb3
  203.  cmpd frbl
  204.  blo gb3
  205.  bsr smap set block in map
  206.  ldd fbc get free count
  207.  addd #1 bump it
  208.  std fbc
  209. gb5 leax -3,x get to next entry
  210.  dec 0,s dec the count
  211.  bne gb2 finished?
  212.  leax 3,x fix pointer
  213.  puls b,pc return
  214.  
  215. *
  216. * read in block in d
  217. *
  218.  
  219. dfsk std isk3 save blocj number
  220.  clr isk2
  221.  lsl isk3+1 mult by 512 char per block
  222.  rol isk3
  223.  rol isk2
  224.  ldd dfd get file desc
  225.  sys ind,isk seek to block
  226.  ldd dfd
  227.  rts
  228. *
  229. rfb bsr dfsk
  230.  sys read,bbuf,512 read block
  231.  lbes drder error?
  232.  rts return
  233.  
  234. *
  235. * Set bit map bit for block in d
  236. *
  237.  
  238. smap pshs x save x
  239.  bsr map find map location
  240.  bita 0,x bit already set?
  241.  bne smap2
  242.  ora 0,x set bit
  243.  sta 0,x
  244.  puls x,pc return
  245. smap2 ldd dupbc get dup count
  246.  addd #1 bump it
  247.  std dupbc
  248.  puls x,pc return
  249.  
  250. *
  251. * Find bit map location
  252. *
  253.  
  254. map ldx #bm point to map
  255.  pshs b save low byte
  256.  lsra divide by 8
  257.  rorb
  258.  lsra
  259.  rorb
  260.  lsra
  261.  rorb
  262.  leax d,x point to entry
  263.  lda #$80 set bit
  264.  puls b get low byte
  265.  andb #$7
  266.  beq map4
  267. map2 lsra adjust bit pos
  268.  decb
  269.  bne map2
  270. map4 rts return
  271.  
  272. *
  273. * filin
  274. *
  275.  
  276. filin ldd #0
  277.  pshs d
  278. filin2 jsr map fill in system blocks
  279.  ora 0,x set bit
  280.  sta 0,x
  281.  ldd 0,s get block count
  282.  addd #1
  283.  std 0,s
  284.  cmpd frbl end of fdn blocks?
  285.  bne filin2
  286.  puls d,pc return
  287.  
  288. *
  289. * Find all file blocks from the fdns
  290. *
  291.  
  292. fdn ldd #0 set counter
  293.  pshs d
  294. fdn2 addd #2 find fdn block number
  295.  jsr dfsk seek to it
  296.  sys read,fdbuf,512 read in fdn block
  297.  lbes drder error?
  298.  ldu #fdbuf point to fdns
  299.  ldb #512/64 set fdn per block count
  300.  pshs b
  301. fdn4 pshs u
  302.  bsr dof process an fdn
  303.  puls u
  304.  leau 64,u move to next fdn
  305.  dec 0,s dec the count
  306.  bne fdn4
  307.  puls b
  308.  ldd 0,s get fdn counter
  309.  addd #1 bump by 1
  310.  std 0,s
  311.  cmpd fdcnt finished?
  312.  blo fdn2
  313.  puls d,pc return
  314.  
  315. *
  316. * Process the data in the fdn pointed at by U.
  317. *
  318.  
  319. dof clr dir clear mode flags
  320.  lda 0,u get modes
  321.  bne dof1 is it active?
  322.  ldd ffdc get free fdn counter
  323.  addd #1 update it
  324.  std ffdc
  325.  rts return
  326. dof1 pshs a save modes
  327.  ldd ufdc get used fdn count
  328.  addd #1 update it
  329.  std ufdc
  330.  puls a
  331.  bita #$2 is it block device?
  332.  beq dof2
  333.  ldd bfc get count
  334.  addd #1 update
  335.  std bfc
  336.  rts return
  337. dof2 bita #$4 is it char device?
  338.  beq dof3
  339.  ldd cfc get count
  340.  addd #1 update it
  341.  std cfc
  342.  rts return
  343. dof3 bita #$8 is it a dir?
  344.  beq dof35
  345.  inc dir set dir flag
  346.  ldd dfc get counter
  347.  addd #1
  348.  std dfc
  349.  bra dof4
  350. dof35 ldd rfc get reg file block counter
  351.  addd #1 update it
  352.  std rfc
  353. dof4 bsr ffb procress blocks
  354.  rts return
  355.  
  356. *
  357. * Find all blocks in the fdn pointed at by U.
  358. *
  359.  
  360. ffb leau 9,u point to map
  361.  ldb #10 process direct map first
  362.  pshs b save counter
  363. ffb2 jsr torfb in range?
  364.  bne ffb3
  365.  ldd 1,u get block number
  366.  beq ffb3 is it null?
  367.  jsr sfmap set bit in map
  368. ffb3 leau 3,u get to next
  369.  dec 0,s end of direct?
  370.  bne ffb2
  371.  puls b
  372.  jsr torfb in range?
  373.  bne ffb4
  374.  ldd 1,u get single ind block
  375.  beq ffb4
  376.  bsr sind process it
  377. ffb4 leau 3,u get double ind block
  378.  jsr torfb in range?
  379.  bne ffb5
  380.  ldd 1,u
  381.  beq ffb5
  382.  jsr dind process it
  383. ffb5 leau 3,u get triple ind block
  384.  jsr torfb in range?
  385.  bne ffb6
  386.  ldd 1,u
  387.  beq ffb6
  388.  jsr tind process it
  389. ffb6 rts return
  390.  
  391. *
  392. * Process single ind block
  393. *
  394.  
  395. sind inc sin set mode
  396.  pshs d save block
  397.  jsr sfmap set map bit
  398.  puls d
  399.  jsr rfb read in block
  400.  ldx #bbuf point to data
  401.  ldb #128 set counter
  402.  pshs b
  403. sind2 jsr torbx in range?
  404.  bne sind4
  405.  ldd 1,x get block number
  406.  beq sind4
  407.  inc rbflg
  408.  jsr sfmap set block in map
  409.  clr rbflg
  410. sind4 leax 3,x get next entry
  411.  dec 0,s dec the count
  412.  bne sind2
  413.  clr sin clear mode
  414.  puls b,pc return
  415.  
  416. *
  417. * Process double ind block
  418. *
  419.  
  420. dind inc din set mode
  421.  pshs d save block
  422.  jsr sfmap set map bit
  423.  puls d
  424.  jsr rdib read in block
  425.  ldx #dbuf point to data
  426.  ldb #128 set counter
  427.  pshs b
  428. dind2 jsr torbx in range?
  429.  bne dind4
  430.  ldd 1,x get block number
  431.  beq dind4
  432.  pshs x
  433.  jsr sind process as single
  434.  puls x
  435. dind4 leax 3,x get next entry
  436.  dec 0,s dec the count
  437.  bne dind2
  438.  clr din clear mode
  439.  puls b,pc return
  440.  
  441. *
  442. * Process triple ind block
  443. *
  444.  
  445. tind inc tin set mode
  446.  pshs d save block
  447.  jsr sfmap set map bit
  448.  puls d
  449.  jsr rtib read in block
  450.  ldx #tbuf point to data
  451.  ldb #128 set counter
  452.  pshs b
  453. tind2 jsr torbx in range?
  454.  bne tind4
  455.  ldd 1,x get block number
  456.  beq tind4
  457.  pshs x
  458.  jsr dind process as double
  459.  puls x
  460. tind4 leax 3,x get next entry
  461.  dec 0,s dec the count
  462.  bne tind2
  463.  clr tin clear mode
  464.  puls b,pc return
  465.  
  466. *
  467. * Set bit map bit for file allocated block
  468. *
  469.  
  470. sfmap pshs d,x
  471.  jsr tbnd in range?
  472.  bne sfmap8
  473.  tst rbflg reg block?
  474.  bne sfmap3
  475.  tst tin find the block type
  476.  beq sfmap1 and bump its counter
  477.  ldd tindc
  478.  addd #1
  479.  std tindc
  480.  bra sfmap5
  481. sfmap1 tst din is it double?
  482.  beq sfmap2
  483.  ldd dindc
  484.  addd #1
  485.  std dindc
  486.  bra sfmap5
  487. sfmap2 tst sin single ind block?
  488.  beq sfmap3
  489.  ldd sindc
  490.  addd #1
  491.  std sindc
  492.  bra sfmap5
  493. sfmap3 tst dir is it dir block?
  494.  beq sfmap4
  495.  ldd dirbc
  496.  addd #1
  497.  std dirbc
  498.  bra sfmap5
  499. sfmap4 ldd rgfbc must be reg file block
  500.  addd #1
  501.  std rgfbc
  502. sfmap5 puls d get block number
  503.  jsr map find in bit map
  504.  bit a 0,x is it already there?
  505.  bne sfmap6
  506.  ora 0,x set bit on
  507.  sta 0,x
  508.  puls x,pc return
  509. sfmap6 ldd dupfc get dup count
  510.  addd #1 bump it
  511.  std dupfc
  512.  puls x,pc return
  513. sfmap8 puls d,x,pc return
  514.  
  515. *
  516. * reads for double & triple indirection
  517. *
  518.  
  519. rdib jsr dfsk do seek
  520.  sys read,dbuf,512
  521.  lbes drder error?
  522.  rts
  523. *
  524. rtib jsr dfsk do seek
  525.  sys read,tbuf,512
  526.  lbes drder error?
  527.  rts return
  528.  
  529. *
  530. * lost
  531. *
  532.  
  533. lost ldd vlcnt get volume block count
  534.  lsra divide by 8
  535.  rorb
  536.  lsra
  537.  rorb
  538.  lsra
  539.  rorb
  540.  pshs d save result
  541.  ldx #bm point to bit map
  542. lost2 lda 0,x+ get a byte
  543.  cmpa #$ff all filled in?
  544.  beq lost5
  545.  ldb #8 set bit count
  546.  bsr cntms count missing blocks
  547. lost5 ldd 0,s get block count
  548.  subd #1
  549.  std 0,s
  550.  bne lost2 finished?
  551.  ldb vlcnt+1 get remainder
  552.  andb #7
  553.  beq lost8
  554.  lda 0,x get reset of bits
  555.  bsr cntms count missing blocks
  556. lost8 puls d,pc return
  557.  
  558. *
  559. * count missing blocks
  560. *
  561.  
  562. cntms rola
  563.  bcs cntms4 missing bit?
  564.  pshs d
  565.  ldd mbcnt get missing count
  566.  addd #1
  567.  std mbcnt
  568.  puls d
  569. cntms4 decb dec the count
  570.  bne cntms
  571.  rts return
  572.  
  573. *
  574. * out of range block tests
  575. *
  576.  
  577. torbx tst 0,x hi byte set
  578.  bne torfb2
  579.  rts return
  580. torfb tst 0,u in range?
  581.  bne torfb2
  582.  rts
  583. torfb2 ldd oorflb get block counter
  584.  addd #1 bump it
  585.  std oorflb
  586.  rts return
  587. *
  588. tbnd cmpd vlcnt past volume end?
  589.  bhi torfb2
  590.  cmpd frbl in fdns?
  591.  blo torfb2
  592.  sez set status ok
  593.  rts return
  594.  
  595. *
  596. * report read error
  597. *
  598.  
  599. drder ldx #drdms
  600.  jsr pms
  601.  ldd #0
  602.  sys term exit
  603.  
  604. *
  605. * decst
  606. *
  607. * Convert the number in D into an ascii string
  608. * representing a decimal number.  The string
  609. * is pointed at by X (X should be set on entry!)
  610. * Also on exit, D has the length of the string.
  611. * The second entry point, 'decstn' will not print
  612. * leading spaces for leading zeroes, but will
  613. * suppress all leading zero info.  All strings
  614. * start with a space.
  615. *
  616.  
  617. decst pshs x save user pointer
  618.  clr 0,-s set suppression flag
  619.  bra decst2
  620. *
  621. decstn pshs x save user pointer
  622.  clr 0,-s
  623.  inc 0,s set for no fielding
  624. decst2 pshs a
  625.  lda #$20 setup leading space
  626.  sta 0,x+ save in buffer
  627.  puls a
  628.  clr 0,-s set up bookkeeping
  629.  clr 0,-s
  630. decst3 ldy #conlst point to constants
  631. decst4 cmpd 0,y compare number to constant
  632.  blo decst5
  633.  subd 0,y do subtraction of constant
  634.  inc 1,s bump digits counter
  635.  bra decst4
  636. decst5 pshs a save number
  637.  tst 2,s zero digit?
  638.  bne decst6
  639.  tst 1,s any numbers output yet?
  640.  bne decst6
  641.  tst 3,s doing suppression?
  642.  bne decst8
  643.  lda #$20 set up space
  644.  bra decst7
  645. decst6 lda 2,s get digit count
  646.  inc 1,s set 'got one' flag
  647.  ora #$30 make ascii
  648. decst7 sta 0,x+ save in buffer
  649. decst8 puls a reset number
  650.  clr 1,s clear out digit
  651.  leay 2,y bump constant ptr
  652.  cmpy #conend end of list?
  653.  bne decst4
  654.  leas 3,s clean up stack
  655.  orb #$30 make last digit
  656.  stb 0,x+ save in buffer
  657.  clr 0,x null terminate string
  658.  tfr x,d
  659.  subd 0,s calculate string length
  660.  puls x,pc return
  661.  
  662. * constants for convert
  663.  
  664. conlst fdb 10000
  665.  fdb 1000
  666.  fdb 100
  667.  fdb 10
  668. conend equ * end of list
  669.  
  670. rm1 fcc $d,'Disk Summary',$d,$d,'Files:',$d,0
  671. rm2 fcc ' total files',$d,0
  672. rm3 fcc ' regular files',$d,0
  673. rm4 fcc ' directories',$d,0
  674. rm5 fcc ' block device files',$d,0
  675. rm6 fcc ' character device files',$d,$d,'Block usage:',$d,0
  676. rm7 fcc ' total blocks used',$d,0
  677. rm8 fcc ' regular blocks',$d,0
  678. rm9 fcc ' directory blocks',$d,0
  679. rm10 fcc ' blocks used for 1st level mapping',$d,0
  680. rm11 fcc ' blocks used for 2nd level mapping',$d,0
  681. rm12 fcc ' blocks used for 3rd level mapping',$d,0
  682. rm13 fcc ' fdn blocks',$d,'     2 system blocks',$d,0
  683. rm14 fcc ' unused blocks',$d,$d,'Fdn usage:',$d,0
  684. rm15 fcc ' busy fdns',$d,0
  685. rm16 fcc ' free fdns',$d,$d,'Error information:',$d,0
  686. rm17 fcc ' out-of-range free blocks',$d,0
  687. rm18 fcc ' duplicate blocks in free list',$d,0
  688. rm19 fcc ' duplicate file blocks',$d,0
  689. rm20 fcc ' missing blocks',$d,$d,0
  690. rm21 fcc ' out-of-range file blocks',$d,0
  691. bdlne fcc 'Bad link in free list - check aborted.',$d,0
  692. drdms fcc 'Disk read error - check aborted.',$d,0
  693.  
  694. BMSZ equ 1024*8-512 bit map size
  695.  
  696. isk fcb seek
  697. isk2 fcb 0
  698. isk3 fdb 0
  699.  fcb 0,0,0
  700.  
  701. iwrt fcb write
  702. iwrt2 fdb 0
  703. iwrt3 fdb 0
  704.  
  705. iopn fcb open
  706. iopn2 fdb 0,0
  707.  
  708. dfd rmb 2 file desc
  709. fdcnt rmb 2 fdn block count
  710. vlcnt rmb 2 volume block count
  711. frbl rmb 2 first free block count
  712. fbc rmb 2 free block count
  713. oorfb rmb 2 out of range count (free list)
  714. dupbc rmb 2 dup block count (free list)
  715. ffdc rmb 2 free fdn count
  716. ufdc rmb 2 used fdn count
  717. dir rmb 1 dir mode flag
  718. tin rmb 1 triple mode
  719. din rmb 1 double mode
  720. sin rmb 1 single mode
  721. rbflg rmb 1 reg block flag
  722. bfc rmb 2 block file count
  723. cfc rmb 2 character file count
  724. dfc rmb 2 dir file count
  725. rfc rmb 2 reg file count
  726. sindc rmb 2 single ind block count
  727. dindc rmb 2 double ind block count
  728. tindc rmb 2 triple ind block count
  729. dirbc rmb 2 dir file block count
  730. rgfbc rmb 2 reg file block count
  731. dupfc rmb 2 dup blocks in files count
  732. mbcnt rmb 2 missing block count
  733. oorflb rmb 2 out of range file blocks
  734.  
  735. stbf rmb 16 string buffer
  736.  
  737. zzzzz equ *
  738.  
  739.  org $800
  740.  
  741. fdbuf rmb 512
  742. dbuf rmb 512
  743. tbuf rmb 512
  744. sir rmb 512
  745.  
  746. bbuf rmb 512
  747.  
  748. bm rmb BMSZ
  749.  
  750.  end fch
  751.