home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_02 / 2n02053a < prev    next >
Text File  |  1991-01-02  |  8KB  |  253 lines

  1.  
  2.  
  3. COMMENT #
  4. ------------------------------------------------------
  5.         FILE   -  SFHT.ASM
  6.  
  7.   Non model specific method to determine the number
  8.   of file handles available to the entire system.
  9.  
  10.   Written for Microsoft MASM 5.x to interface with
  11.   Microsoft C 5.x.
  12.  
  13.   Module Contents:
  14.         int max_sys_file_handles(void);
  15.         int sys_handles_in_use(void);
  16. ------------------------------------------------------
  17. END OF COMMENT #
  18.  
  19. .model small            ;memory model directive
  20.  
  21. ;           --- EQUATES ---
  22. FOXES           equ     0ffffh
  23.  
  24.  
  25. ;           --- STRUCTURES ---
  26.  
  27. ; DOS List of Lists structure definition
  28. list_of_list struc
  29.    dcb_head_addr       dd  0  ;head DCB list
  30.    sys_file_tbl_addr   dd  0  ;head SFHT list
  31.    clock_addr          dd  0  ;clock device
  32.    console_addr        dd  0  ;console device
  33.    max_sector          dw  0  ;largest sector size
  34.    cache_addr          dd  0  ;head of cache control block
  35.    current_dir_addr    dd  0  ;current directory structure
  36.    sys_fcb_tbl_addr    dd  0  ;head of sys file fcb list
  37.    unknown             dw  0  ;unknown
  38.    num_drives          db  0  ;specified by lastdrive=
  39.    current_drive_cnt   db  0  ;current number of drives
  40. list_of_list ends
  41.  
  42. ; System File Handle Table Header structure definition
  43. sys_file_tbl_hdr struc
  44.    next_sys_file_tbl  dd   0  ;addr of next tbl in chain
  45.    num_hdl_ctl_blks   dw   0  ;number of file handle control
  46.                               ; blks in this data structure
  47. sys_file_tbl_hdr ends
  48.  
  49. ; System File Handle Information Block structure definition
  50. sys_fcb struc
  51.    open_cnt           dw   0  ;zero if not in use
  52.    open_mode          dw   0  ;mode handle was open in
  53.    dir_attr           db   0  ;directory attributes
  54.    flags              dw   0  ;flags
  55.    dbc                dd   0  ;device control block
  56.    cluster1           dw   0  ;initial cluster
  57.    time               dw   0  ;file time
  58.    date               dw   0  ;file date
  59.    fsize              dd   0  ;file size
  60.    fpos               dd   0  ;file pointer location
  61.    rel_cluster        dw   0  ;relative cluster
  62.    cur_cluster        dw   0  ;current cluster
  63.    blk_num            dw   0  ;block number
  64.    dir_index          db   0  ;directory index
  65.    file_name          db 11 dup(0) ;file/device name
  66.    un_known           db  4 dup(0) ;unknown
  67.    owner_machine      dw   0  ;machine id of owner
  68.    owner_psp          dw   0  ;psp of owner process
  69.    status             dw   0  ;status
  70. sys_fcb ends
  71.  
  72.  
  73. SYS_FILE_TBL_HDR_SIZE   equ     size sys_file_tbl_hdr
  74. SYS_FCB_SIZE            equ     size sys_fcb
  75.  
  76.  
  77. ;                   --- CODE ---
  78. .code
  79.  
  80.  
  81. ;------------------------------------------------------
  82. ; int max_sys_file_handles(void);
  83. ;
  84. ;       Sums the number of individual file handle table
  85. ;       entries available to the system.
  86. ; CAUTION:
  87. ;   1.  Utilizes an undocumented function (52h) of
  88. ;       int 21h to obtain the addr of the List of
  89. ;       Lists.
  90. ;   2.  Utilizes undocumented structures of the List of
  91. ;       Lists, the System File Handle Table Header
  92. ;       Record and the System File Handle Information
  93. ;       Block data structures.
  94. ;   The availablity of function 52h and the layout of
  95. ;   the data structures is consistent for all DOS
  96. ;   versions 2.1 and greater - at least as far as they
  97. ;   are used here.
  98.  
  99. ; INPUT:    None
  100. ; OUTPUT:   None
  101. ; RETURNS:  Number of file handles available to the
  102. ;           system in the AX register.
  103. ;           All other registers preserved.
  104. ;------------------------------------------------------
  105.  
  106. public _max_sys_file_handles
  107. _max_sys_file_handles proc
  108. ; --- setup
  109.         push    es
  110.         push    bx
  111.         push    ds
  112.         push    si
  113.  
  114. ; --- undocumented function to retrieve the
  115. ;     address of the list of lists (in es:bx)
  116.         mov     ah,52h
  117.         int     21h
  118.  
  119. ; --- initialize (zero out) the counter
  120.         xor     ax,ax
  121.  
  122. ; --- establish addressability to the first
  123. ;     system file handle table data structure
  124.         lds     si,es:[bx.sys_file_tbl_addr]
  125.  
  126. get_next:
  127. ; --- add the number of individual file handles
  128. ;     the data structure can accommodate
  129.         add     ax,[si.num_hdl_ctl_blks]
  130.  
  131. ; --- load the address of the next system file
  132. ;     handle table data structure in the chain
  133.         lds     si,[si.next_sys_file_tbl]
  134.  
  135. ; --- is the offset to the next 0ffffh, indicating that
  136. ;     the one just processed was the last in the chain
  137.         cmp     si,FOXES
  138.  
  139. ; --- if the last data structure has been processed
  140. ;     return to the caller
  141.         jz      got_last
  142.  
  143. ; --- else process the new system file handle table
  144. ;     data structure
  145.         jmp     get_next
  146.  
  147. ; --- clean up and return
  148. got_last:
  149.         pop     si
  150.         pop     ds
  151.         pop     bx
  152.         pop     es
  153.         ret
  154. _max_sys_file_handles endp
  155.  
  156.  
  157. ;------------------------------------------------------
  158. ; int sys_handles_in_use(void);
  159. ;
  160. ;       Sums the number of DOS internal file handle
  161. ;       information blocks within the System File Handle
  162. ;       Table linked list that are in use.
  163. ; CAUTION:
  164. ;   1.  Utilizes an undocumented function (52h) of
  165. ;       int 21h to obtain the addr of the List of
  166. ;       Lists.
  167. ;   2.  Utilizes undocumented structures of the List of
  168. ;       Lists, the System File Handle Table Header
  169. ;       Record and the System File Handle Information
  170. ;       Block data structures.
  171. ;   The availablity of function 52h and the layout of
  172. ;   the data structures is consistent for all DOS
  173. ;   versions 2.1 and greater - at least as far as they
  174. ;   are used here.
  175.  
  176. ; INPUT:    None
  177. ; OUTPUT:   None
  178. ; RETURNS:  Number of file handles currently in use in
  179. ;           the AX register.
  180. ;           All other registers preserved.
  181. ;------------------------------------------------------
  182.  
  183. public _sys_handles_in_use
  184. _sys_handles_in_use proc
  185. ; --- setup
  186.         push    es
  187.         push    bx
  188.         push    ds
  189.         push    si
  190.  
  191. ; --- undocumented function to retrieve the
  192. ;     address of the list of lists
  193.         mov     ah,52h
  194.         int     21h
  195.  
  196. ; --- initialize (zero out) the counter
  197.         xor     ax,ax
  198.  
  199. ; --- establish addressability to the first
  200. ;     system file handle table data structure
  201.         lds     si,es:[bx.sys_file_tbl_addr]
  202.  
  203. get_next1:
  204. ; --- save the offset addr of the header record
  205.         push    si
  206.  
  207. ; --- load thge number of elements in this node
  208.         mov     cx,[si.num_hdl_ctl_blks]
  209.  
  210. ; --- bump the offset past the header record
  211.         add     si,SYS_FILE_TBL_HDR_SIZE
  212.  
  213. ; --- is this handle control block in use?
  214. nxt_element:
  215.         mov     bx,[si.open_cnt]
  216.         or      bx,bx
  217.         jz      not_in_use
  218.         inc     ax
  219. not_in_use:
  220.  
  221. ; --- move the offset on to the next element
  222.         add     si,SYS_FCB_SIZE
  223.         loop    nxt_element
  224.         pop     si
  225.  
  226. ; --- load the address of the next system file
  227. ;     handle table data structure in the chain
  228.         lds     si,[si.next_sys_file_tbl]
  229.  
  230. ; --- is the offset to the next 0ffffh, indicating that
  231. ;     the one just processed was the last in the chain
  232.         cmp     si,FOXES
  233.  
  234. ; --- if the last data structure has been processed
  235. ;     return to the caller
  236.         jz      got_last1
  237.  
  238. ; --- else process the new system file handle table
  239. ;     data structure
  240.         jmp     get_next1
  241.  
  242. ; --- clean up and return
  243. got_last1:
  244.         pop     si
  245.         pop     ds
  246.         pop     bx
  247.         pop     es
  248.         ret
  249. _sys_handles_in_use endp
  250.  
  251. end
  252.  
  253.