home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / HANDCNT.ASM < prev    next >
Assembly Source File  |  1991-08-16  |  6KB  |  175 lines

  1. ; File......: HANDCNT.ASM
  2. ; Author....: Bob Clarke
  3. ; CIS ID....: 72621,3563
  4. ; Date......: $Date:   15 Aug 1991 23:06:52  $
  5. ; Revision..: $Revision:   1.2  $
  6. ; Log file..: $Logfile:   E:/nanfor/src/handcnt.asv  $
  7. ; This is an original work by Bob Clarke and is placed in the
  8. ; public domain.
  9. ;
  10. ; Modification history:
  11. ; ---------------------
  12. ;
  13. ; $Log:   E:/nanfor/src/handcnt.asv  $
  14. ;  
  15. ;     Rev 1.2   15 Aug 1991 23:06:52   GLENN
  16. ;  Forest Belt proofread/edited/cleaned up doc
  17. ;  
  18. ;     Rev 1.1   14 Jun 1991 19:54:36   GLENN
  19. ;  Minor edit to file header
  20. ;  
  21. ;     Rev 1.0   07 Jun 1991 21:58:52   GLENN
  22. ;  Initial revision.
  23. ;
  24.  
  25. ; $DOC$
  26. ; $FUNCNAME$
  27. ;    FT_HANDCNT()
  28. ; $CATEGORY$
  29. ;    DOS/BIOS
  30. ; $ONELINER$
  31. ;    Count number of available DOS (not network) file handles
  32. ; $SYNTAX$
  33. ;    FT_HANDCNT() -> nHandles
  34. ; $ARGUMENTS$
  35. ;    None
  36. ; $RETURNS$
  37. ;    numeric, long integer
  38. ; $DESCRIPTION$
  39. ;    FT_HANDCNT() finds the internal DOS Device Control Blocks used for 
  40. ;    storing file information and counts the number of DCB entries.  The
  41. ;    DCB is set up by reading the FILES= line in CONFIG.SYS, and there
  42. ;    is one DCB entry for each file handle.
  43. ;
  44. ;    NOTE: For Novell networks, the number of network file handles is
  45. ;          controlled by SHELL.CFG.  To date, I know where this information
  46. ;          is stored after SHELL.CFG has been read, but have not come up
  47. ;          with a reliable way to retrieve the information.  There is no
  48. ;          public variable associated with the storage location, and the
  49. ;          location can change from version to version of NETx.EXE.
  50. ;          Novell Tech Support's response, though friendly, was "Nope, we 
  51. ;          don't know of a way for you to do it, either.  Good luck."
  52. ; $EXAMPLES$
  53. ;    nHandles := FT_HANDCNT()
  54. ;    ? "This PC has " + LTRIM( STR( nHandles ) ) + " set by CONFIG.SYS."
  55. ; $SEEALSO$
  56. ;
  57. ; $INCLUDE$
  58. ;
  59. ; $END$
  60. ;
  61. ;
  62.  
  63. Public   FT_HANDCNT
  64. Extrn    __RETNL:Far
  65.  
  66. _NanFor  Segment  Word Public 'CODE'
  67.          Assume CS:_Nanfor
  68.  
  69. FT_HANDCNT    Proc Far
  70.  
  71.          push bp
  72.          push es
  73.          push ds
  74.          push si
  75.          push di
  76.          mov  ah,52h                   ;Get Configuration Variable Table
  77.          push es
  78.          push ds
  79.          int  21h
  80.  
  81. ; ES:BX now contains pointer to CVT (Configuration Variable Table)
  82.  
  83.  
  84. ;
  85. ;CVT structure for DOS 3.x:
  86. ;
  87. ;    (The ampersand indicates the address in ES:BX)
  88. ;
  89. ;offset byte        field length        description
  90. ;-----------        ------------        ------------
  91. ;
  92. ;    -08h           double word         current buffer in BUFFERS= chain
  93. ;    -04h           word                offset within current buffer
  94. ;    -02h           word                segment of first memory control block
  95. ;&    00h           double word         pointer to first Drive Parameter Block
  96. ;     04h           double word         Pointer to first DCB (system file table
  97. ;                                       Device Control Block)
  98. ;     08h           double word         pointer to CLOCK$ device driver
  99. ;     0Ch           double word         pointer to CON device driver
  100. ;     10h           word                maximum bytes per sector on any block
  101. ;                                       device
  102. ;     12h           double word         pointer to start of disk buffer chain
  103. ;     16h           double word         pointer to Logical Drive Table
  104. ;     1Ah           double word         pointer to start of DOS's FCB chain
  105. ;     1Eh           word                number of FCBs to keep when swapping
  106. ;     20h           byte                number of block devices
  107. ;     21h           byte                number of logical drives, set by value
  108. ;                                       of LASTDRIVE in CONFIG.SYS (defaults
  109. ;                                       to 5 if not specified)
  110. ;     22h                               Beginning of NUL device driver;
  111. ;                                       first device in the device-driver
  112. ;                                       chain
  113. ;
  114. ; For DOS 4.x, the only change in the CVT was the item at offset 12h.  It is 
  115. ; now a double word pointer to EMS link record that leads to the DOS buffer
  116. ; chain.  All other items and addresses are the same as for DOS 3.x.
  117. ;
  118. ; The number of DCBs in a system is established by the FILES= line in
  119. ; CONFIG.SYS.  The default number is 8 if no FILES= line is found.
  120. ; DCBs are grouped in "links" and each link is preceded by a 3-word header.
  121. ;
  122. ;Structure of device control block header:
  123. ;
  124. ;offset byte        field length        description
  125. ;-----------        ------------        ------------
  126. ;    00h            double word         Far pointer to next link header,
  127. ;                                       or xxxx:FFFFh to indicate that this
  128. ;                                       is final link in chain.
  129. ;    04h            word                number of blocks in this link
  130. ;
  131. ;
  132. ; For more detailed information, see "DOS Programmer's Reference: 2nd Edition"
  133. ; by Que Corporation, pages 807-818.
  134. ;
  135.  
  136.  
  137.          add  bx,4                     ;move to address of first DCB
  138.          mov  si,word ptr es:[bx]      ;get offset of DCB
  139.          mov  ds,word ptr es:[bx+2]    ;get segment of DCB
  140.  
  141. ; DS:SI now contains a pointer to header of first DCB
  142.  
  143.          xor  ax,ax                    ;use as a count holder
  144.          xor  dx,dx                    ;use as a count holder
  145. hand1:   add  ax,word ptr [si+4]       ;adjust running total
  146.          adc  dx,0
  147.          mov  cx,word ptr [si]         ;offset of next link header
  148.          mov  bx,word ptr [si+2]       ;segment of next link header
  149.          mov  si,cx
  150.          mov  ds,bx
  151.          cmp  cx,0ffffh                ;possible end of list?
  152.          jne  hand1                    ;if not, keep looking
  153.          pop  ds
  154.          pop  es
  155.  
  156. ; sum of dcbs from all links is now in DX:AX
  157.  
  158.          pop  di                  ;restore registers before returning value
  159.          pop  si
  160.          pop  ds
  161.          pop  es
  162.          pop  bp
  163.          push dx
  164.          push ax
  165.          call __retnl
  166.          add  sp,4
  167.          ret
  168.  
  169. FT_HANDCNT    Endp
  170. _NanFor       Ends
  171.               End
  172.  
  173. 
  174.