home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / util / diskfile / deskchec.sit / FCensus.asm < prev   
Encoding:
Assembly Source File  |  1987-01-29  |  2.7 KB  |  111 lines

  1.  
  2. ;    FCensus: HFS/MSF file census routine from Feb '86 MacTutor
  3. ;    Provides info on each file on a volume, whether MFS or HFS.
  4.  
  5. ;    Proc FCensus(vRefNum:integer; DirID:longint; Inspector:ProcPtr);
  6.  
  7. ;    vRefNum: volume reference number (or drive number) of volume
  8.  
  9. ;    dirID: ID of directory to start.  Root dir = 2.
  10.  
  11. ;    Inspector: user-supplied function
  12. ;        MyInspector(ParamBlock:ParmBlkPtr; dirID:longint):boolean
  13. ;        ParamBlock is a GetFileInfo block
  14. ;        dirID is the ID of the file's directory
  15. ;        If returned value = True, search ends.
  16. ;        If returned value = False, search continues.
  17.  
  18.     Include    Traps.D
  19.     Include    SysEquX.D
  20.     Include    FSEqu.D
  21.     Include    SysErr.D
  22.         
  23.         .MACRO _TFSCORE
  24.         IF '%1' <> ''
  25.         LEA    %1,A0
  26.         ENDIF
  27.         IF '%3' = ''
  28.         DC.W   $A200+%2
  29.         ENDIF
  30.         IF '%3' = 'REGS'
  31.         DC.W   $A300+%2
  32.         ENDIF
  33.         IF '%3' = 'ASYNC'
  34.         DC.W   $A600+%2
  35.         ENDIF
  36.         IF '%3' = 'SYS'
  37.         DC.W   $A600+%2
  38.         ENDIF
  39.         IF '%3' = 'IMMED'
  40.         DC.W   $A200+%2
  41.         ENDIF
  42.         .ENDM
  43.  
  44.  
  45.         .MACRO _GetCatInfo 
  46.         MOVEQ        #9,D0
  47.         _TFSCore    %1,96,%2
  48.         .ENDM
  49.  
  50.  
  51. ;    A6 offsets
  52. OldA6        set    0
  53. ReturnAddr    set    OldA6+4
  54. Inspec        set    ReturnAddr+4
  55. DirID        set    Inspec+4
  56. vRefNum        set    DirID+4
  57. ArgsSz        set    vRefNum+2-Inspec
  58. ;
  59. ParmBlk        set    OldA6-ioHVQElSize    ; local parm block
  60. NameStr        set    ParmBlk-256        ; Str255 buffer
  61. Index        set    NameStr-2        ; directory index
  62.  
  63.     XRef    FCensus
  64.  
  65. FCensus
  66.     Link    a6,#Index
  67.     clr.l    -(sp)            ; sentinel for end of DirID list
  68. NextDir
  69.     clr    Index(a6)        ; init index = 0
  70. NextFile
  71.     lea    ParmBlk(a6),a0        ; a0 = parm block pointer
  72.     clr.l    ioCompletion(a0)
  73.     clr.l    ioFileName(a0)
  74.     move    vRefNum(a6),ioVRefNum(a0)    ; set volume
  75.     move.l    dirID(a6),ioDirID(a0)    ; set directory ID
  76.     lea    NameStr(a6),a1        ; a1 = name string buffer pointer
  77.     move.l    a1,ioFileName(a0)    ; set file name pointer
  78.     addq    #1,Index(a6)        ; advance index
  79.     move    Index(a6),ioFDirIndex(a0)    ; set index
  80.     tst    FSFCBLen        ; HFS running?
  81.     bmi.s    @0            ; branch if not
  82.     _GetCatInfo
  83.     bra.s    @1
  84. @0    _GetFileInfo            ; MFS, get partial story
  85. @1    beq.s    NodeKind        ; no error, check things out
  86.     cmp    #fnfErr,d0        ; end of directory?
  87.     bne.s    FCExit            ; no, unexpected problem
  88.     move.l    (sp)+,dirID(a6)        ; pop next directory off stack
  89.     bne.s    NextDir            ; branch if there is one
  90.     bra.s    FCExit            ; branch if there isn't one
  91. NodeKind
  92.     btst    #ioDirFlg,ioFlAttrib(a0)    ; directory?
  93.     beq.s    CallInspec        ; a file, call Inspector
  94.     move.l    ioDirID(a0),-(sp)    ; directory, push on stack
  95.     bra.s    NextFile        ; look for next file
  96. CallInspec
  97.     clr    -(sp)            ; for returned value
  98.     pea    ParmBlk(a6)        ; param block for inspector
  99.     move.l    dirID(a6),-(sp)        ; pass dirID
  100.     move.l    Inspec(a6),a0        ; address of user function
  101.     jsr    (a0)            ; call inspector
  102.     tst.b    (sp)+            ; time to quit?
  103.     beq.s    NextFile        ; no, keep going
  104. FCExit
  105.     unlk    a6
  106.     move.l    (sp)+,a0        ; a0 = return address
  107.     lea    ArgsSz(sp),sp        ; pop arguments
  108.     jmp    (a0)            ; return
  109.     dc.b    'FCensus'
  110.     .align    2
  111.