home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / IOCTL.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-05-30  |  10.7 KB  |  588 lines

  1.         page    58,132
  2. ;
  3. ; ioctl.asm
  4. ; contains:     GetIOCTLDevInfo()    getiodevi()
  5. ;        
  6. ;
  7.         include model.h
  8.         include prologue.h
  9.         include equ.h
  10.  
  11.         name    ioctl
  12.  
  13.         ifndef    AZTEC
  14.          ReferVar    _gferror,<cWord>
  15.         endif
  16.  
  17.         dseg    DIoCtrl
  18.         ifdef    AZTEC
  19.          ReferVar    _gferror,<cWord>
  20.         endif
  21.         endds
  22.  
  23.         pseg    ioctl
  24.  
  25.              ifdef    DSNOTHING
  26.          assume    ds:nothing
  27.         endif
  28.  
  29.  
  30. DOSCALL        equ    021h        ; interrupt to DOS
  31. IOCTL        equ    044h        ; generic IOCTL for AH
  32.  
  33. ;==>--    int getiodev( handle )
  34. ;
  35. ;
  36. ;;    ARGUMENTS:
  37. ;      int handle;        - device or file handle from DOS
  38. ;
  39. ;;    DESCRIPTION:
  40. ;      Obtains IOCTL information from a device or file via handle.
  41. ;    
  42. ;
  43. ;;    SIDE EFFECTS:
  44. ;      None.
  45. ;
  46. ;;    RETURNS:
  47. ;      16-bit device word from DOS
  48. ;
  49. ;;    AUTHOR:
  50. ;      DK  05-Feb-1989  12:18:47
  51. ;      Copyright (C)1990 Greenleaf Software Inc. All Rights Reserved.
  52. ;
  53. ;
  54. ;;    MODIFICATIONS:
  55. ;
  56. ;
  57. ;;;
  58.     cproc    getiodev
  59.     mov    bx,parm1_        ; get incoming handle
  60.     xor    al,al
  61.     mov    ah,IOCTL
  62.     int    DOSCALL
  63.     mov    ax,dx            ; return value
  64.     cproce
  65.  
  66.  
  67. ;==>--    unsigned SetIOCTLDevInfo( int handle, unsigned char info )
  68. ;         setiodev()
  69. ;
  70. ;;    ARGUMENTS:
  71. ;      int handle;        - device or file handle from DOS
  72. ;      unsigned char info;    - device information
  73. ;
  74. ;        Can contain any of the following bits or combination thereof:
  75. ;        
  76. ;        DEVISCIN
  77. ;        DEVISCOT
  78. ;        DEVISNUL
  79. ;        DEVISCLK
  80. ;        DEVBINARY
  81. ;        DEVEOF
  82. ;        DEVISDEV
  83. ;
  84. ;
  85. ;;    DESCRIPTION:
  86. ;      Sets bits in the device driver.
  87. ;
  88. ;;    SIDE EFFECTS:
  89. ;
  90. ;
  91. ;;    RETURNS:
  92. ;      16-bit device word from DOS
  93. ;
  94. ;;    AUTHOR:
  95. ;      DK  05-Feb-1989  12:25:37
  96. ;      Copyright (C)1990 Greenleaf Software Inc. All Rights Reserved.
  97. ;
  98. ;
  99. ;;    MODIFICATIONS:
  100. ;
  101. ;
  102. ;;;
  103.     cproc    setiodev
  104.     mov    bx,parm1_        ; get incoming handle
  105.     mov    dx,parm2_        ; get incoming control word to DL
  106.     xor    dh,dh            ; clear DH
  107.     mov    al,01h            ; command
  108.     mov    ah,IOCTL
  109.     int    DOSCALL
  110.     mov    ax,dx            ; return value
  111.     cproce
  112.  
  113.  
  114. ;==>--    unsigned ReadIOCTLCharDev( handle,bfr,n)
  115. ;         readiocd                   
  116. ;
  117. ;;    ARGUMENTS:
  118. ;      int handle;        - device or file handle from DOS
  119. ;      char *bfr;        - pointer to data buffer
  120. ;      unsigned n;        - Number of bytes to read
  121. ;
  122. ;;    DESCRIPTION:
  123. ;      Reads n characters from a character-oriented device handle.
  124. ;
  125. ;
  126. ;
  127. ;;    SIDE EFFECTS:
  128. ;
  129. ;
  130. ;;    RETURNS:
  131. ;     Number of bytes read, or (if Cy flag set) 0 with error code in
  132. ;     _gferror
  133. ;
  134. ;;    AUTHOR:
  135. ;      DK  05-Feb-1989  12:34:47
  136. ;      Copyright (C)1989-90 Greenleaf Software Inc. All Rights Reserved.
  137. ;
  138. ;
  139. ;;    MODIFICATIONS:
  140. ;
  141. ;
  142. ;;;
  143.     cproc    readiocd
  144.     mov    AH,IOCTL
  145.     mov    al,02h            ; function to read
  146.     mov    bx,parm1_
  147.     if    _LDATA
  148.      push    ds
  149.      lds    dx,parm2_        ; pointer to buffer
  150.      mov    cx,parm4_
  151.     else
  152.      mov    dx,parm2_
  153.      mov    cx,parm3_
  154.     endif
  155.     int    DOSCALL
  156.     jnc    rdiocdxit        ; if no error, # bytes is in AX
  157.     ifdef    DSNOTHING
  158.      mov    bx,seg _gferror
  159.      mov    ds,bx
  160.     endif
  161.     mov    _gferror,ax        ; error, so store error code
  162.     xor    ax,ax            ;  and indicate it to user
  163. rdiocdxit:
  164.     if    _LDATA
  165.      pop    ds
  166.     endif
  167.     cproce
  168.  
  169.  
  170. ;==>--    unsigned WriteIOCTLCharDev( handle,bfr,n)
  171. ;         writiocd                   
  172. ;
  173. ;;    ARGUMENTS:
  174. ;      int handle;        - device or file handle from DOS
  175. ;      char *bfr;        - pointer to data buffer
  176. ;      unsigned n;        - Number of bytes to write
  177. ;
  178. ;;    DESCRIPTION:
  179. ;      Writes n characters from buffer to
  180. ;     a character-oriented device handle.
  181. ;
  182. ;;    SIDE EFFECTS:
  183. ;
  184. ;
  185. ;;    RETURNS:
  186. ;     Number of bytes written, or (if Cy flag set) 0 with error code in
  187. ;     _gferror
  188. ;
  189. ;;    AUTHOR:
  190. ;      DK  05-Feb-1989  12:34:47
  191. ;      Copyright (C)1989-90 Greenleaf Software Inc. All Rights Reserved.
  192. ;
  193. ;
  194. ;;    MODIFICATIONS:
  195. ;
  196. ;
  197. ;;;
  198.     cproc    writiocd
  199.     mov    AH,IOCTL
  200.     mov    al,03h            ; function to write
  201.     mov    bx,parm1_
  202.     if    _LDATA
  203.      push    ds
  204.      lds    dx,parm2_        ; pointer to buffer
  205.      mov    cx,parm4_
  206.     else
  207.      mov    dx,parm2_
  208.      mov    cx,parm3_
  209.     endif
  210.     int    DOSCALL
  211.     jnc    writiocdxit        ; if no error, # bytes is in AX
  212.     ifdef    DSNOTHING
  213.      mov    bx,seg _gferror
  214.      mov    ds,bx
  215.     endif
  216.     mov    _gferror,ax        ; error, so store error code
  217.     xor    ax,ax            ;  and indicate it to user
  218. writiocdxit:
  219.     if    _LDATA
  220.      pop    ds
  221.     endif
  222.     cproce
  223.     
  224.  
  225.  
  226. ;==>--    unsigned SendIOCTLString( handle, buf, n )
  227. ;    sendiost
  228. ;
  229. ;;    ARGUMENTS:
  230. ;      int drive;        - drive number 0=default, 1=A, etc.
  231. ;      char *bfr;        - pointer to data buffer
  232. ;      unsigned n;        - Number of bytes to write
  233. ;
  234. ;;    DESCRIPTION:
  235. ;      Writes n character control string from buffer to
  236. ;     a block-oriented device.
  237. ;
  238. ;;    SIDE EFFECTS:
  239. ;
  240. ;
  241. ;;    RETURNS:
  242. ;     Number of bytes written, or (if Cy flag set) 0 with error code in
  243. ;     _gferror
  244. ;
  245. ;;    AUTHOR:
  246. ;      DK  05-Feb-1989  12:34:47
  247. ;      Copyright (C)1990 Greenleaf Software Inc. All Rights Reserved.
  248. ;
  249. ;
  250. ;;    MODIFICATIONS:
  251. ;
  252. ;
  253. ;;;
  254.     cproc    sendiost
  255.     mov    AH,IOCTL
  256.     mov    al,05h            ; function to write
  257.     mov    bx,parm1_
  258.     if    _LDATA
  259.      push    ds
  260.      lds    dx,parm2_        ; pointer to buffer
  261.      mov    cx,parm4_
  262.     else
  263.      mov    dx,parm2_
  264.      mov    cx,parm3_
  265.     endif
  266.     int    DOSCALL
  267.     jnc    sendiostxit        ; if no error, # bytes is in AX
  268.     ifdef    DSNOTHING
  269.      mov    bx,seg _gferror
  270.      mov    ds,bx
  271.     endif
  272.     mov    _gferror,ax        ; error, so store error code
  273.     xor    ax,ax            ;  and indicate it to user
  274. sendiostxit:
  275.     if    _LDATA
  276.      pop    ds
  277.     endif
  278.     cproce
  279.  
  280.     
  281. ;==>--    unsigned ReadIOCTLString( handle, buf, n )
  282. ;    readiost
  283. ;
  284. ;;    ARGUMENTS:
  285. ;      int drive;        - drive number 0=default, 1=A, etc.
  286. ;      char *bfr;        - pointer to data buffer
  287. ;      unsigned n;        - Number of bytes to write
  288. ;
  289. ;;    DESCRIPTION:
  290. ;      Reads n character control string from
  291. ;     a block-oriented device to buffer.
  292. ;
  293. ;;    SIDE EFFECTS:
  294. ;
  295. ;
  296. ;;    RETURNS:
  297. ;     Number of bytes read, or (if Cy flag set) 0 with error code in
  298. ;     _gferror
  299. ;
  300. ;;    AUTHOR:
  301. ;      DK  05-Feb-1989  12:34:47
  302. ;      Copyright (C)1989-90 Greenleaf Software Inc. All Rights Reserved.
  303. ;
  304. ;
  305. ;;    MODIFICATIONS:
  306. ;
  307. ;
  308. ;;;
  309.     cproc    readiost
  310.     mov    AH,IOCTL
  311.     mov    al,04h            ; function to read
  312.     mov    bx,parm1_
  313.     if    _LDATA
  314.      push    ds
  315.      lds    dx,parm2_        ; pointer to buffer
  316.      mov    cx,parm4_
  317.     else
  318.      mov    dx,parm2_
  319.      mov    cx,parm3_
  320.     endif
  321.     int    DOSCALL
  322.     jnc    readiostxit        ; if no error, # bytes is in AX
  323.     ifdef    DSNOTHING
  324.      mov    bx,seg _gferror
  325.      mov    ds,bx
  326.     endif
  327.     mov    _gferror,ax        ; error, so store error code
  328.     xor    ax,ax            ;  and indicate it to user
  329. readiostxit:
  330.     if    _LDATA
  331.      pop    ds
  332.     endif
  333.     cproce
  334.     
  335.  
  336.  
  337. ;==>--    int ChkIOCTLInputRdy( handle )
  338. ;    chkinrdy
  339. ;
  340. ;
  341. ;;    ARGUMENTS:
  342. ;      int handle;        - device handle
  343. ;
  344. ;;    DESCRIPTION:
  345. ;      Checks to see if the handle is ready for input.
  346. ;
  347. ;
  348. ;
  349. ;;    SIDE EFFECTS:
  350. ;
  351. ;
  352. ;;    RETURNS:
  353. ;      0 if OK, ready for input, else -1.  For file, this means after EOF.
  354. ;
  355. ;
  356. ;;    AUTHOR:
  357. ;      DK 05-Feb-1989  12:59:56
  358. ;      Copyright (C)1989-90 Greenleaf Software Inc. All Rights Reserved.
  359. ;
  360. ;
  361. ;;    MODIFICATIONS:
  362. ;
  363. ;
  364. ;;;
  365.     cproc    chkinrdy
  366.     mov    bx,parm1_
  367.     mov    AH,IOCTL
  368.     mov    al,06h            ; function to check input status
  369.     int    DOSCALL
  370.     xor    ah,ah
  371.     cmp    al,0
  372.     jz    chkinrdyxit
  373.     mov    ax,-1            ; not ready so return -1
  374. chkinrdyxit:
  375.     cproce
  376.  
  377.  
  378.  
  379.  
  380. ;==>--    int ChkIOCTLOutputRdy( handle )
  381. ;    chkoprdy
  382. ;
  383. ;
  384. ;;    ARGUMENTS:
  385. ;      int handle;        - device handle
  386. ;
  387. ;;    DESCRIPTION:
  388. ;      Checks to see if the handle is ready for output
  389. ;
  390. ;
  391. ;
  392. ;;    SIDE EFFECTS:
  393. ;
  394. ;
  395. ;;    RETURNS:
  396. ;      0 if OK, ready for output, else -1.  For file, this means after EOF.
  397. ;
  398. ;
  399. ;;    AUTHOR:
  400. ;      DK 05-Feb-1989  12:59:56
  401. ;      Copyright (C)1989-90 Greenleaf Software Inc. All Rights Reserved.
  402. ;
  403. ;
  404. ;;    MODIFICATIONS:
  405. ;
  406. ;
  407. ;;;
  408.     cproc    chkoprdy
  409.     mov    bx,parm1_
  410.     mov    AH,IOCTL
  411.     mov    al,07h            ; function to check output status
  412.     int    DOSCALL
  413.     xor    ah,ah
  414.     cmp    al,0
  415.     jz    chkoprdyxit
  416.     mov    ax,-1            ; not ready so return -1
  417. chkoprdyxit:
  418.     cproce
  419.  
  420.  
  421. ;==>--    int IsIOCTLDevRemovable( drv )
  422. ;    isremov
  423. ;
  424. ;;    ARGUMENTS:
  425. ;      int drv;        - Drive 0=default, 1=A, etc.
  426. ;
  427. ;;    DESCRIPTION:
  428. ;      Checks if device supports removable media
  429. ;
  430. ;;    SIDE EFFECTS:
  431. ;
  432. ;
  433. ;;    RETURNS:
  434. ;      0 if removable, 1 if fixed, 0x000f if invalid drive specified.
  435. ;
  436. ;;    AUTHOR:
  437. ;      DK 05-Feb-1989  13:18:04
  438. ;      Copyright (C)1989-90 Greenleaf Software Inc. All Rights Reserved.
  439. ;
  440. ;
  441. ;;    MODIFICATIONS:
  442. ;
  443. ;
  444. ;;;
  445.     cproc isremov
  446.     mov    bx,parm1_
  447.     mov    ah,IOCTL
  448.     mov    al,08h            ; function to determine if removeable
  449.     int    DOSCALL            ; return is ready-made in AX
  450.     cproce
  451.  
  452.  
  453.  
  454. ;==>--    int IsIOCTLNetwork( drv )
  455. ;    isnetwk
  456. ;
  457. ;
  458. ;;    ARGUMENTS:
  459. ;      int drv;        - Drive 0=default, 1=A, etc.
  460. ;
  461. ;;    DESCRIPTION:
  462. ;      Checks if logical drive is local or remote (associated with a
  463. ;    network directory).
  464. ;
  465. ;;    SIDE EFFECTS:
  466. ;
  467. ;
  468. ;;    RETURNS:
  469. ;      0 if local, nonzero if network associated.
  470. ;
  471. ;;    AUTHOR:
  472. ;        05-Feb-1989  13:23:54
  473. ;      Copyright (C)1989-90 Greenleaf Software Inc. All Rights Reserved.
  474. ;
  475. ;
  476. ;;    MODIFICATIONS:
  477. ;
  478. ;
  479. ;;;
  480.     cproc    isnetwk
  481.     mov    bx,parm1_
  482.     mov    ah,IOCTL
  483.     mov    al,09h            ; function to check network vs. local
  484.     int    DOSCALL
  485.     and    dx,01000h        ; mask off all but bit 12
  486.     mov    ax,dx            ; return in AX
  487.     cproce
  488.  
  489.  
  490.  
  491. ;==>--    int IsIOCTLRemote( handle )
  492. ;    isremote
  493. ;
  494. ;;    ARGUMENTS:
  495. ;      int handle;        - Device (file) handle
  496. ;
  497. ;;    DESCRIPTION:
  498. ;      Checks if device handle is for a local device or a remote device
  499. ;    accross the network.
  500. ;
  501. ;;    SIDE EFFECTS:
  502. ;
  503. ;
  504. ;;    RETURNS:
  505. ;      0 if local, nonzero if remote.
  506. ;
  507. ;;    AUTHOR:
  508. ;        05-Feb-1989  13:28:49
  509. ;      Copyright (C)1989-90 Greenleaf Software Inc. All Rights Reserved.
  510. ;
  511. ;
  512. ;;    MODIFICATIONS:
  513. ;
  514. ;
  515. ;;;
  516.     cproc    isremote
  517.     mov    bx,parm1_
  518.     mov    ah,IOCTL
  519.     mov    al,0ah            ; function to check network vs. local
  520.     int    DOSCALL
  521.     and    dx,08000h        ; mask off all but bit 12
  522.     mov    ax,dx            ; return in AX
  523.     cproce
  524.  
  525.  
  526.  
  527. ;==>--    int IOCTLShareControl( loop, n )
  528. ;    ioctlshr
  529. ;
  530. ;
  531. ;;    ARGUMENTS:
  532. ;      unsigned loop;    - number of times to execute a delay loop
  533. ;      unsigned n;        - number of retries
  534. ;
  535. ;;    DESCRIPTION:
  536. ;      All sharing and lock conflicts are automatically retried a number
  537. ;    of times before they are returned as a DOS error or critical error.
  538. ;
  539. ;      This function selects the number of retries and the delay between
  540. ;    retries.  The delay loop consists of the following sequence:
  541. ;
  542. ;        XOR    CX,CX
  543. ;        LOOP    $        ; spin 64 times
  544. ;
  545. ;    The default that DOS will use is delay=1 and retries-3 if you never
  546. ;    call this function.  Increasing these values can reduce the amount
  547. ;    of threshing due to having to check DOS error codes when applications
  548. ;    use a lot of conflicts about file locks or sharing of files.
  549. ;
  550. ;;    SIDE EFFECTS:
  551. ;
  552. ;
  553. ;;    RETURNS:
  554. ;      0 if successful, else a DOS error code (if Cy flag set) (will also
  555. ;    be in _gferror)
  556. ;
  557. ;;    AUTHOR:
  558. ;      DK  05-Feb-1989  13:33:12
  559. ;      Copyright (C)1989-90 Greenleaf Software Inc. All Rights Reserved.
  560. ;
  561. ;
  562. ;;    MODIFICATIONS:
  563. ;
  564. ;
  565. ;;;
  566.     cproc    ioctlshr
  567.     mov    cx,parm1_        ; loop count
  568.     mov    dx,parm2_        ; retries
  569.     mov    ah,IOCTL
  570.     mov    al,0bh            ; function to set retries/loop
  571.     int    DOSCALL
  572.     jc    ioctlshrxit        ; hop if AX contains error code
  573.     xor    ax,ax            ;  no error, assure clear AX
  574. ioctlshrxit:
  575.     ifdef    DSNOTHING
  576.      mov    bx,seg _gferror
  577.      push    ds
  578.      mov    ds,bx
  579.     endif
  580.      mov    _gferror,ax
  581.     ifdef    DSNOTHING
  582.      pop    ds
  583.     endif
  584.     cproce
  585.  
  586.     endps
  587.     end
  588.