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 / fdncheck < prev    next >
Text File  |  1982-07-13  |  11KB  |  643 lines

  1.  opt nol,pag
  2.  ttl Directory check program
  3.  info UniFLEX fdncheck
  4.  info Version 1.4, Released July 6, 1982
  5.  info Copyright, (C) 1981, by
  6.  info Technical Systems Consultants, Inc.
  7.  info All rights reserved.
  8.  lib sysdef
  9.  opt lis
  10.  pag
  11.  
  12. ** 3/1/82 GDT - Changed all Output to use Standard Output
  13. STDOUT equ 1 Standard Output Channel
  14.  
  15. * Directory check program
  16.  
  17. BSIZ equ $4000
  18.  
  19. * structure definitions
  20.  
  21.  org 0
  22.  
  23. busy rmb 1 busy status
  24. pos rmb 1 position
  25. size rmb 2 size
  26. map rmb 10*3
  27.  
  28.  
  29.  org 0
  30.  
  31. dch ldd 0,s get arg count
  32.  cmpd #2
  33.  bne dch8 error?
  34.  sys update
  35.  ldd 4,s get device name
  36.  std iopn2 set sys call
  37.  sys ind,iopn open it
  38.  bes dch8 *** should be different ***
  39.  std dfd save file dessc
  40. * check block device status here
  41.  leax -4096,s set stack size
  42.  sys stack
  43.  ldd dfd get file desc
  44.  sys seek,0,512,0 seek to sir
  45.  ldd dfd
  46.  sys read,fbuf,512 read in sir
  47.  lbes err5 error?
  48.  ldd fbuf+16 get fdn block count
  49.  std fdcnt save it
  50.  jsr zbuf zero buffer
  51.  jsr chdup check for dupes in core list
  52.  jsr flist find all fdns
  53.  clrb set zero
  54.  lda #15 set count
  55. dch4 pshs b
  56.  deca
  57.  bne dch4
  58.  lda #'/ set root file name
  59.  sta 0,s save on stack
  60.  sts nptr save name ptr
  61.  ldd #1 set root fdn number
  62.  jsr rddir read dir tree
  63.  leas 15,s clean up stack
  64.  jsr chkf check fdn status
  65.  ldd #0
  66.  sys term exit
  67. dch8 ldd #STDOUT
  68.  sys write,sym,22
  69.  ldd #$ff
  70.  sys term
  71. sym fcc 'Command syntax error.',$d
  72.  
  73. *
  74. * zero fdn buffer
  75. *
  76.  
  77. zbuf ldd #0 set zero
  78.  ldx #buf point to buffer
  79. zbuf2 std 0,x++ zero buffer
  80.  cmpx #buf+BSIZ finished?
  81.  bne zbuf2
  82.  rts return
  83.  
  84. *
  85. * fill fdn buffer with fdn info
  86. *
  87.  
  88. flist ldd #buf point to buffer start
  89.  std nxtfdn
  90.  ldd dfd get file desc
  91.  sys seek,0,1024,0 seek to fdn start
  92. flist2 ldd dfd get file desc
  93.  sys read,fbuf,512 read in a block
  94.  lbes err1 error?
  95.  ldx #fbuf
  96.  ldu nxtfdn
  97.  ldb #8 set fdn per block count
  98. flist4 lda 0,x get modes
  99.  sta 0,u+
  100.  lda 2,x get link count
  101.  sta 0,u+
  102.  leax 64,x get to next fdn
  103.  decb dec the counter
  104.  bne flist4
  105.  stu nxtfdn mark table end
  106.  ldd fdcnt get fdn block count
  107.  subd #1 dec it
  108.  std fdcnt
  109.  bne flist2
  110.  rts return
  111.  
  112. *
  113. * rddir
  114. *
  115. * Read dirs recursively
  116. *
  117.  
  118. rddir std fdnsav save fdn
  119.  jsr stfnd set fdn found bit
  120.  ldd #0 set name term ptr
  121.  pshs d
  122.  ldx nptr get name pointer
  123.  pshs x save it
  124.  ldy #name point to buffer
  125.  bra xfn3
  126. xfn2 lda #'/ set sep char
  127.  sta 0,y+
  128. xfn3 lda 0,x+ transfer name
  129.  sta 0,y+
  130.  bne xfn3
  131.  leay -1,y
  132.  ldx 0,s get name ptr
  133.  ldx -4,x get next in line
  134.  stx 0,s save new ptr
  135.  bne xfn2
  136.  leas 2,s
  137.  ldd fdnsav get fdn number
  138.  jsr xopen open file
  139.  pshs d save file desc
  140.  leas -512,s make buffer on stack
  141. rddir1 ldx #0 zero out buffer
  142.  clrb
  143.  leau 0,s
  144. rddir2 stx 0,u++
  145.  decb
  146.  bne rddir2
  147.  sts ird2 set read sys call
  148.  ldd 512,s get file desc
  149.  jsr xread read in block
  150.  cmpd #0 end of dir?
  151.  lbeq rddir8
  152.  ldb #512/16 set entry counter
  153.  pshs b
  154.  leau 1,s point to block just read
  155. rddir3 ldd 0,u get fdn number
  156.  beq rddir6 empty entry?
  157.  ldx #buf point to fdn list
  158.  subd #1 finf fdn entry
  159.  lslb
  160.  rola
  161.  leax d,x point to entry
  162.  lda 0,x check if allocated
  163.  ora #$40
  164.  sta 0,x set linked to bit
  165.  tst 1,x link count zero?
  166.  bne rddir4
  167.  bita #$3f is it allocated?
  168.  beq rddi52
  169.  pshs x
  170.  jsr zler report error
  171.  puls x
  172.  bra rddir5
  173. rddir4 lda 1,x get link count
  174.  cmpa #127 is it max?
  175.  beq rddir5
  176.  dec 1,x dec the link count
  177. rddir5 lda 0,x check modes
  178.  bita #$3f
  179.  bne rddi55
  180. rddi52 pshs x
  181.  jsr ffer free fdn error
  182.  puls x
  183.  bra rddir6
  184. rddi55 tsta
  185.  bmi rddir6
  186.  bita #$8 is it dir?
  187.  beq rddir6
  188.  pshs u save u
  189.  ldb #0 set up dir name
  190.  pshs b
  191.  ldd 14,u transfer name to stack
  192.  pshs d
  193.  ldd 12,u
  194.  pshs d
  195.  ldd 10,u
  196.  pshs d
  197.  ldd 8,u
  198.  pshs d
  199.  ldd 6,u
  200.  pshs d
  201.  ldd 4,u
  202.  pshs d
  203.  ldd 2,u
  204.  pshs d
  205.  sts 532,s save name ptr
  206.  ldd 0,u
  207.  jsr rddir read this dir
  208.  leas 15,s clean stack
  209.  puls u
  210. rddir6 leau 16,u move to next entry
  211.  dec 0,s dec the count
  212.  bne rddir3 repeat?
  213.  puls b
  214.  lbra rddir1
  215. rddir8 leas 512,s clean stack
  216.  puls d get file desc
  217.  jsr xclose close the file
  218.  puls d,pc return
  219.  
  220. *
  221. * set fdn found bit
  222. *
  223.  
  224. stfnd ldx #buf point to fdn list
  225.  subd #1
  226.  lslb
  227.  rola
  228.  leax d,x point to entry
  229.  lda 0,x get mode
  230.  ora #$80 set bit
  231.  sta 0,x
  232.  rts return
  233.  
  234. *
  235. * Report zero link error
  236. *
  237.  
  238. zler ldd #STDOUT set file desc
  239.  sys write,zzm,13
  240.  bra generr
  241.  
  242. *
  243. * Report no link error
  244. *
  245.  
  246. ffer ldd #STDOUT
  247.  sys write,ffm,12
  248.  
  249. *
  250. * general error
  251. *
  252.  
  253. generr ldd #STDOUT set file desc
  254.  sys write,gnm1,6
  255.  leax 2,u point to file name
  256.  stx iwrt2
  257.  ldd #0 find name length
  258. gener2 tst 0,x+
  259.  beq gener4
  260.  incb
  261.  bra gener2
  262. gener4 std iwrt3 save count
  263.  ldd #STDOUT set file desc
  264.  sys ind,iwrt output name
  265.  ldd #STDOUT set file desc
  266.  sys write,gnm2,1
  267.  ldd 0,u get fdn number
  268. gener6 pshs d
  269.  ldd #STDOUT set file desc
  270.  sys write,gnm3,6
  271.  puls d get fdn
  272. prtdec ldx #sbuf point to string buffer
  273.  stx iwrt2
  274.  jsr decstn
  275.  leax d,x
  276.  addd #2 set length
  277.  std iwrt3
  278.  ldd #'.<<8|$d
  279.  std 0,x set in string
  280.  ldd #STDOUT set file desc
  281.  sys ind,iwrt output fdn number
  282.  rts return
  283.  
  284. *
  285. * Report fdn check error
  286. *
  287.  
  288. cherr pshs d save fdn
  289.  ldd #STDOUT
  290.  sys write,chm1,15
  291.  puls d
  292.  bra gener6
  293. cherr2 pshs d save fdn
  294.  ldd #STDOUT
  295.  sys write,chm2,16
  296.  puls d
  297.  bra gener6
  298.  
  299. *
  300. * Check fdns
  301. *
  302.  
  303. chkf ldd #1 set fdn counter
  304.  pshs d
  305.  ldu #buf point to list
  306. chkf2 lda 0,u get status
  307.  beq chkf5
  308.  bita #$40 referenced?
  309.  beq chkf4
  310.  lda 1,u link 0?
  311.  beq chkf5
  312.  cmpa #127 is it max?
  313.  beq chkf5
  314.  ldd 0,s get fdn number
  315.  jsr cherr report error
  316.  bra chkf5
  317. chkf4 ldd 0,s get fdn
  318.  jsr cherr2 report error
  319. chkf5 ldd 0,s get fdn
  320.  addd #1 bump by 1
  321.  std 0,s
  322.  leau 2,u next entry
  323.  cmpu nxtfdn end of table?
  324.  bne chkf2
  325.  puls d,pc return
  326.  
  327. *
  328. * error routines
  329. *
  330.  
  331. err1 pshs d
  332.  ldd #STDOUT set file desc
  333.  sys write,E1,21
  334.  puls d
  335.  swi
  336.  sys term
  337. *
  338. err3 pshs d
  339.  ldd #STDOUT set file desc
  340.  sys write,E3,22
  341.  puls d
  342.  swi
  343.  sys term
  344. *
  345. err4 pshs d
  346.  ldd #STDOUT
  347.  sys write,E4,22
  348.  puls d
  349.  swi
  350.  sys term
  351. *
  352. err5 pshs d
  353.  ldd #STDOUT
  354.  sys write,E5,24
  355.  puls d
  356.  swi
  357.  sys term
  358. *
  359. ferr ldd #STDOUT set file desc
  360.  sys write,ferm,FRSZ
  361.  ldd #$ff
  362.  sys term exit
  363.  
  364. dbig ldd #STDOUT set file desc
  365.  sys write,dirbig,DIRBIG "Directory too large"
  366.  bra ferr
  367.  
  368. *
  369. * xread
  370. *
  371. * Fake system read routine.  Reads dirs
  372. *
  373.  
  374. xread lda #34 set file table entry size
  375.  mul b has file desc
  376.  ldx #filtab point to file table
  377.  leax d,x point to entry
  378.  ldd size,x get file size
  379.  beq xread6 eof?
  380.  pshs d save size
  381.  subd #512 dec by read amount
  382.  std size,x save new size
  383.  bpl xread2 ok?
  384.  ldd #0 set size to 0
  385.  std size,x
  386. xread2 lda pos,x get file position (block offset)
  387.  inc pos,x bump pos
  388.  ldb #3 set map entry size
  389.  mul
  390.  leax map,x point to map
  391.  leax d,x point to block entry
  392.  lda 0,x transfer block to seek
  393.  sta isk+1
  394.  clr isk3
  395.  ldd 1,x get rest of it
  396.  std isk2
  397.  lsl isk2+1 shift left 1 (512 mult)
  398.  rol isk2
  399.  rol isk+1
  400.  ldd dfd get file desc
  401.  sys ind,isk seek to block
  402.  ldd dfd get file desc
  403.  sys ind,ird read in block
  404.  lbes err4 error?
  405.  ldx ird2 get buffer location
  406.  puls d get size
  407.  cmpd #512 enough there?
  408.  bhs xread5
  409.  leax d,x zero rest of buffer
  410.  pshs d save count
  411.  ldd #512 find count
  412.  subd 0,s++
  413. xread4 clr 0,x+ zero buffer
  414.  subd #1
  415.  bne xread4
  416. xread5 ldd #512 set read count
  417. xread6 rts return
  418.  
  419. *
  420. * close file simulation
  421. *
  422.  
  423. xclose lda #34 find entry
  424.  mul
  425.  ldx #filtab in file table
  426.  leax d,x
  427.  clr 0,x clear status
  428.  rts return
  429.  
  430. *
  431. * open simulation
  432. *
  433.  
  434. xopen clr isk3 set up seek to fdn
  435.  clr isk+1
  436.  subd #1 calc its position
  437.  lsra
  438.  rorb
  439.  ror isk3
  440.  lsra
  441.  rorb
  442.  ror isk3
  443.  addd #2<<1 add in start block for fdns
  444.  std isk2
  445.  ldd dfd get file desc
  446.  sys ind,isk seek to block
  447.  ldd dfd get file desc
  448.  sys read,fdntmp,64 read in fdn
  449.  lbes err3 error?
  450.  ldx #filtab point to file table
  451.  ldd #0 find a slot for this guy
  452. xopen3 tst 0,x busy?
  453.  beq xopen4
  454.  addd #1 bump file desc
  455.  leax 34,x next entry
  456.  cmpx #filend end of table?
  457.  bne xopen3
  458.  lbra ferr error!
  459. xopen4 pshs d save file desc
  460.  inc 0,x set busy
  461.  pshs u save u
  462.  ldu #fdntmp+5 point to fdn
  463.  ldd 0,u++ get size
  464.  lbne dbig too big?
  465.  ldd 0,u++
  466.  cmpd #5120 too big?
  467.  lbhi dbig
  468.  std size,x save size
  469.  clr pos,x set begin pos
  470.  ldb #10 set map count
  471.  pshs b
  472.  leax map,x point to map
  473. xopen5 lda 0,u+ transfer map
  474.  sta 0,x+
  475.  ldd 0,u++
  476.  std 0,x++
  477.  dec 0,s dec count
  478.  bne xopen5
  479.  puls b,u reset regs
  480.  puls d,pc return
  481.  
  482. *
  483. *  chdup - check for duplicate fdn's in core list
  484. *
  485.  
  486. chdup ldx #fbuf+$58 (x)=ptr to fdn count
  487.  lda 0,x+ get count
  488.  pshs a save it
  489.  
  490. chdup1 lda 0,s+ restore count
  491.  beq chdup4 if exam of all fdn's complete
  492.  deca decrement fdn count
  493.  pshs a save new count
  494.  ldy 0,x++ get an fdn
  495.  pshs x save ptr into fdn list
  496.  clrb clear count of dupes
  497.  
  498. chdup2 tsta check count
  499.  beq chdup3 if done looking for dupes
  500.  cmpy 0,x++ duplicate fdn ?
  501.  bne chdp25 no dupe found
  502.  incb dump count to dupes found
  503. chdp25 deca decrement count
  504.  bra chdup2 continue search for dupes
  505.  
  506. chdup3 tstb dupes found ?
  507.  bne chdup6 if dupes found, report it
  508. chdp35 puls x restore ptr into fdn list
  509.  bra chdup1 check next fdn entry
  510.  
  511. chdup4 rts
  512.  
  513. ** report dupes found.
  514. chdup6 ldd #STDOUT set file desc
  515.  sys write,dupe,DUPSZ "Duplicate fdn found"
  516.  tfr y,d (d)=fdn #
  517.  jsr prtdec print it
  518.  bra chdp35 look at next fdn
  519.  
  520.  
  521. *
  522. * decst
  523. *
  524. * Convert the number in D into an ascii string
  525. * representing a decimal number.  The string
  526. * is pointed at by X (X should be set on entry!)
  527. * Also on exit, D has the length of the string.
  528. * The second entry point, 'decstn' will not print
  529. * leading spaces for leading zeroes, but will
  530. * suppress all leading zero info.  All strings
  531. * start with a space.
  532. *
  533.  
  534. decst pshs x save user pointer
  535.  clr 0,-s set suppression flag
  536.  bra decst2
  537. *
  538. decstn pshs x save user pointer
  539.  clr 0,-s
  540.  inc 0,s set for no fielding
  541. decst2 pshs a
  542.  lda #$20 setup leading space
  543.  sta 0,x+ save in buffer
  544.  puls a
  545.  clr 0,-s set up bookkeeping
  546.  clr 0,-s
  547. decst3 ldy #conlst point to constants
  548. decst4 cmpd 0,y compare number to constant
  549.  blo decst5
  550.  subd 0,y do subtraction of constant
  551.  inc 1,s bump digits counter
  552.  bra decst4
  553. decst5 pshs a save number
  554.  tst 2,s zero digit?
  555.  bne decst6
  556.  tst 1,s any numbers output yet?
  557.  bne decst6
  558.  tst 3,s doing suppression?
  559.  bne decst8
  560.  lda #$20 set up space
  561.  bra decst7
  562. decst6 lda 2,s get digit count
  563.  inc 1,s set 'got one' flag
  564.  ora #$30 make ascii
  565. decst7 sta 0,x+ save in buffer
  566. decst8 puls a reset number
  567.  clr 1,s clear out digit
  568.  leay 2,y bump constant ptr
  569.  cmpy #conend end of list?
  570.  bne decst4
  571.  leas 3,s clean up stack
  572.  orb #$30 make last digit
  573.  stb 0,x+ save in buffer
  574.  clr 0,x null terminate string
  575.  tfr x,d
  576.  subd 0,s calculate string length
  577.  puls x,pc return
  578.  
  579.  pag
  580.  
  581. * constants for convert
  582.  
  583. conlst fdb 10000
  584.  fdb 1000
  585.  fdb 100
  586.  fdb 10
  587. conend equ * end of list
  588.  
  589. * data
  590.  
  591. E1 fcc "Can't read fdn list.",$d
  592. E3 fcc "Can't open directory.",$d
  593. E4 fcc "Can't read directory.",$d
  594. E5 fcc "Can't read system info.",$d
  595. zzm fcc "Too few links"
  596. ffm fcc "Inactive fdn"
  597. gnm1 fcc ' for "'
  598. gnm2 fcc '"'
  599. gnm3 fcc ' - fdn'
  600. chm1 fcc 'Link count high'
  601. chm2 fcc 'Never referenced'
  602. ferm fcc 'Fatal error - fdncheck aborted!',$d
  603. FRSZ equ *-ferm
  604. dirbig fcc 'Encountered directory too large',$d
  605. DIRBIG equ *-dirbig
  606. dupe fcc 'Duplicate entry found "in core" list - fdn #'
  607. DUPSZ equ *-dupe
  608. dfd fdb 0 file desc
  609. nxtfdn fdb 0 next fdn
  610. fdcnt fdb 0 fdn block count
  611. nptr fdb 0 name pointer
  612.  
  613. iopn fcb open
  614. iopn2 fdb 0,0
  615.  
  616. ird fcb read
  617. ird2 fdb 0,512
  618.  
  619. iwrt fcb write
  620. iwrt2 fdb 0
  621. iwrt3 fdb 0
  622.  
  623. isk fcb seek,0
  624. isk2 fdb 0
  625. isk3 fcb 0,0,0
  626.  
  627. fdnsave rmb 2 temp for fdn
  628. name rmb 128 name buffer
  629. fdntmp rmb 64 fdn buffer
  630. filtab rmb 10*34 file table
  631. filend equ *
  632.  
  633. sbuf rmb 16 buffer
  634.  
  635.  org $e00
  636.  
  637. fbuf rmb 512
  638.  
  639. buf rmb BSIZ
  640.  
  641.  
  642.  end dch
  643.