Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Peter Norton Programmer's Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

  Function 44H (decimal 68) performs input/output control operations, mostly
  for devices. (See Figure 17-9.) AL selects one of 16 subfunctions,
  numbered 00H through 0FH; some of these subfunctions have sub-subfunctions
  you specify with a "minor code" in CL.

  The main purpose of the IOCTL function is to provide a consistent
  interface between DOS programs and device drivers. In general, you
  shouldn't use IOCTL calls unless you know something about how device
  drivers are structured--a topic we'll cover in Appendix A. A few IOCTL
  calls, however, are useful even if you don't understand the details of
  device-driver operations. We'll point these out as we summarize the
  various IOCTL calls.

  --------------------------------------------------------------------------
  NOTE:
    Not all IOCTL subfunctions are supported in earlier versions of DOS.
    Figure 17-9 indicates the DOS versions in which the various IOCTL
    subfunctions were introduced.
  --------------------------------------------------------------------------

  Subfunction                                                      DOS
  Hex     Dec        Description                                   Version
  --------------------------------------------------------------------------
  00H      0         Get device data.                             2.0
  01H      1         Set device data.                             2.0
  02H      2         Receive control data from character device.  2.0
  03H      3         Send control data to character device.       2.0
  04H      4         Receive control data from block device.      2.0
  05H      5         Send control data to block device.           2.0
  06H      6         Check input status.                          2.0
  07H      7         Check output status.                         2.0
  08H      8         Check if block device is removable.          3.0
  09H      9         Check if block device is remote.             3.1
  0AH     10         Check if handle is remote.                   3.1
  0BH     11         Change sharing retry count.                  3.0
  0CH     12         Generic I/O control for handles.             3.2
  0DH     13         Generic I/O control for block devices.       3.2
  0EH     14         Get logical drive map.                       3.2
  0FH     15         Set logical drive map.                       3.2
  --------------------------------------------------------------------------

  Figure 17-9.  Subfunctions available under interrupt 21H, function 44H
  (IOCTL).

  Subfunctions 00H and 01H. These subfunctions get and set device
  information formatted in DX by a complicated set of bit coding. Bit 7 is
  set to 1 for devices and to 0 for disk files. For devices, bits 0 through
  5 are specified as shown in Figure 17-10. For disk files, bits 0 through
  5 provide the disk-drive number: A value of 0 represents drive A, a value
  of 1 represents drive B, and so on. Both subfunctions should be called
  with a file or device handle in BX. Subfunction 00H can be called for both
  disk files and devices; subfunction 01H can be called only for character
  devices.


                        Bit
  15 14 13 12 11 10  9  8   7  6  5  4  3  2  1  0               Use
  ----------------------------------------------------------------------------------------------
   .  .  .  .  .  .  .  .   .  .  .  .  .  .  .  X               1 = standard input device
   .  .  .  .  .  .  .  .   .  .  .  .  .  .  X  .               1 = standard output device
   .  .  .  .  .  .  .  .   .  .  .  .  .  X  .  .               1 = null device
   .  .  .  .  .  .  X  .   .  .  .  .  X  .  .  .               1 = clock device
   .  .  .  .  .  .  .  .   .  .  .  X  .  .  .  .               (Reserved)
   .  .  .  .  .  .  .  .   .  .  X  .  .  .  .  .               1 = data os "raw" (without
                                                                 control-character checking); 0
                                                                 = data is "cooked" (with
                                                                 control-character checking)
   .  .  .  .  .  .  .  .   .  X  .  .  .  .  .  .               0 = end of file; 1 = not end of
                                                                 file (for input)
   .  .  .  .  .  .  .  .   X  .  .  .  .  .  .  .               1 = device; 0 = disk-drive file
   .  .  .  .  .  .  .  R   .  .  .  .  .  .  .  .               (Reserved)
   .  .  .  .  .  .  R  .   .  .  .  .  .  .  .  .               (Reserved)
   .  .  .  .  .  R  .  .   .  .  .  .  .  .  .  .               (Reserved)
   .  .  .  .  R  .  .  .   .  .  .  .  .  .  .  .               (Reserved)
   .  .  .  R  .  .  .  .   .  .  .  .  .  .  .  .               (Reserved)
   .  .  R  .  .  .  .  .   .  .  .  .  .  .  .  .               (Reserved)
   .  X  .  .  .  .  .  .   .  .  .  .  .  .  .  .               1 = device can process control
                                                                 strings transferred by IOCTL
                                                                 subfunctions 02H through 05H
   R  .  .  .  .  .  .  .   .  .  .  .  .  .  .  .               (Reserved)
  ----------------------------------------------------------------------------------------------


  Figure 17-10.  The bit settings of the device data word DX for subfunction
  00H or 01H of interrupt 21H, function 44H.

  You can modify how DOS processes I/O for the CON device (the keyboard/
  video display combination) by setting "raw" input/output mode for the
  device. Do this by clearing bit 5 of the device data word in DX and
  calling subfunction 01H:

  mov     ax,4400h        ; AH = 44H (interrupt 21H function number)
                          ; AL = 0 (subfunction number)
  mov     bx,0            ; BX = 0 (handle for CON device)
  int     21h             ; get device data into DX
  or      dx,0020h        ; set bit 5 ("raw" mode)
  and     dx,00FFh        ; zero reserved bits 8-15
  mov     ax,4401h        ; set up for subfunction 1
  mov     bx,0            ; BX = CON device handle
  int     21h             ; set device data for CON

  After you execute this sequence of code, DOS no longer recognizes Ctrl-P
  and Ctrl-S characters, nor does it expand tabs on output.

  Subfunctions 02H through 05H. These subfunctions transfer control data
  between your program and a device driver. Subfunctions 02H and 03H get and
  send control data for character-oriented devices; subfunctions 04H and 05H
  get and send control data for block-oriented devices. In all four
  subfunctions you specify the subfunction number in AL, the address of a
  data buffer in DS:DX, and the number of bytes to transfer in CX. For
  subfunctions 02H and 03H, you must specify a handle in BX; for
  subfunctions 04H and 05H, you must specify a drive number in BL (00H =
  default drive, 01H = drive A, and so on).

  The control data you transfer to or from a device driver is not
  necessarily part of the device's input/output data stream: The control
  data is often used to obtain the device status or to control
  hardware-specific features such as printer font characteristics or tape
  drive rewind.

  These subfunctions can be used only if the device can process control
  strings. This capability is indicated by bit 14 in the device data word
  returned by subfunction 00H.

  Subfunctions 06H and 07H. These subfunctions return the current input or
  output status of a device or file. Call them with a handle in BX:
  Subfunction 06H returns the current input status; subfunction 07H returns
  the current output status.

  Both of these subfunctions use the carry flag to indicate a successful
  call. If the carry flag is clear, AL contains the status: AL = 00H means
  the device is not ready for input or output; AL = FFH means the device is
  ready. (For a file, input status AL = 00H means end-of-file; output status
  is always "ready" regardless of the value in AL.) If the carry flag is
  set, AX contains an error code: 01H (invalid function), 05H (access
  denied), 06H (invalid handle), or 0DH (invalid data).

  Subfunction 08H. This subfunction, supported only in DOS versions 3.0 and
  later, indicates whether a block-oriented device has removable media or
  not. (The floppy diskettes in a diskette drive are removable; the fixed
  disk in a fixed-disk drive is not.) Subfunction 08H can be extremely
  useful because it lets a program know if it has to check for a disk change
  or if it can rely on the same disk always being there. Call subfunction
  08H with a drive number in BL (00H = default drive, 01H = drive A, and so
  on). The subfunction clears the carry flag on a successful return and
  leaves AX = 00H if the storage medium is removable or AX = 01H if the
  storage medium is nonremovable. If the carry flag is set, AX contains an
  error code: 01H (invalid function) or 0FH (invalid drive).

  Subfunction 09H. In a network configuration, this subfunction determines
  whether a particular block device is local (attached to the computer
  running the program) or remote (redirected to a network server). You must
  specify a drive number in BL when you call this subfunction.

  Subfunction 09H clears the carry flag to indicate a successful call. In
  this case, bit 12 of the value in DX indicates whether the device is
  remote (bit 12 = 1) or local (bit 12 = 0). If the carry flag is set, AX
  contains an error code: 01H (invalid function) or 0FH (invalid drive).
  Subfunction 09H is available in DOS 3.1 and later.

  Subfunction 0AH (decimal 10). This subfunction is similar to subfunction
  09H but is used with a device handle instead of a drive number. Specify
  the handle in BX when you call this subfunction.

  Like subfunction 09H, subfunction 0AH clears the carry flag and returns a
  value in DX that indicates whether the device is local or remote. Bit 15
  of DX indicates whether the device is remote (bit 15 = 1) or local (bit 15
  = 0). If an error occurs, the function sets the carry flag and returns an
  error code in AX: 01H (invalid function) or 06H (invalid handle).
  Subfunction 09H is available in DOS 3.1 and later.

  Subfunction 0BH (decimal 11). This subfunction, which is supported only in
  DOS versions 3.0 and later, controls the way DOS attempts to resolve
  file-sharing conflicts. Because some programs lock files only briefly,
  file-sharing conflicts can be very transitory. DOS can try more than once
  to gain access to a shared file before reporting a conflict, in the hope
  that the lock condition goes away in the meantime.

  Subfunction 0BH can help you empirically tune a network in which you
  expect transient file-sharing conflicts to occur. Call this subfunction
  with DX containing the number of times you want DOS to retry access to a
  shared file before it gives up and reports an error. CX should specify the
  delay value between retries. DOS creates a delay by executing an empty
  loop 65,536 times; the value in CX indicates the number of times you want
  DOS to execute the empty delay loop. (The DOS defaults are three retries
  and one delay loop between retries.)

  If the subfunction executes successfully, it clears the carry flag. If the
  carry flag is set, AX contains an error code of 01H (invalid function).

  Subfunction 0CH (decimal 12). This subfunction provides miscellaneous
  control functions for character-oriented devices. Each control function is
  designated by a minor code in CL and a major code (also called a category
  code) in CH. The various major and minor codes are listed in Figure 17-11.

  Hex            Dec            Description
  --------------------------------------------------------------------------
  Major Code (specified in CH)
  00H            0              Unknown
  01H            1              Serial port (COM1, COM2, COM3, COM4)
  03H            3              Console (CON)
  05H            5              Printer (LPT1, LPT2, LPT3)

  Minor Code (specified in CL)
  45H            69             Set iteration count.
  4AH            74             Select code page.
  4CH            76             Start code page preparation.
  4DH            77             End code page preparation.
  65H            101            Get iteration count.
  6AH            106            Query selected code page.
  6BH            107            Query prepare list.
  --------------------------------------------------------------------------

  Figure 17-11.  Major and minor codes for IOCTL subfunction 0CH (generic
  I/O control for handles).

  Minor codes 45H and 65H were introduced in DOS version 3.2. They apply
  only to print devices (major code 05H). They deal with the number of times
  DOS attempts to send a character to a printer before it assumes the
  printer is busy. The remaining minor codes were introduced in DOS version
  3.3. They provide detailed support for defining and loading code pages for
  output devices that can use multiple character sets or fonts.

  For details on the use of the services provided in this IOCTL subfunction,
  see the DOS technical reference manual.

  Subfunction 0DH (decimal 13). Subfunction 0DH provides six generic
  services for block-oriented devices. Each service is designated by a major
  code in CH and a minor code in CL. (See Figure 17-12.) In general, these
  services are similar to services provided by the ROM BIOS for diskettes
  and fixed disks, but these IOCTL services provide a consistent interface
  to any block-oriented device with a device driver that supports these
  IOCTL calls.

  Subfunction 0DH is available in DOS 3.2 and later. See the DOS technical
  reference manual for details on subfunction 0DH services.

  Hex            Dec            Description
  --------------------------------------------------------------------------
  Major Code (specified in CH)
  08H            8              Disk drive

  Minor Code (specified in CL)
  40H            64             Set parameters for block device.
  41H            65             Write track on logical drive.
  42H            66             Format and verify track on logical drive.
  60H            96             Get parameters for block device.
  61H            97             Read track on logical drive.
  62H            98             Verify track on logical drive.
  --------------------------------------------------------------------------

  Figure 17-12.  Major and minor codes for IOCTL subfunction 0DH (generic
  I/O control for block devices).

  Subfunctions 0EH and 0FH (decimal 14 and 15). These two subfunctions
  relate logical mapping of drive letter assignments to physical drives. For
  example, in systems with only one diskette drive, DOS maps drive letter B
  to physical drive A.

  Call these subfunctions with a logical drive ID in BL (01H represents
  drive A, 02H represents drive B, and so on). Subfunction 0EH returns a
  logical drive ID that is currently mapped to the drive you specified in
  BL. Subfunction 0FH also updates DOS's internal logical map so that the
  drive ID you specified becomes the new logical drive ID. Both subfunctions
  use AL to return the logical drive ID; if AL = 00H, only one logical drive
  is associated with the drive ID you specified in BL. If an error occurs,
  the carry flag is set and AX contains an error code: 01H (invalid
  function) or 0FH (invalid drive).

  For example, if you execute the following instructions on a system with
  only one diskette drive, DOS associates drive B with the diskette drive:

  mov bl,2                ; BL = logical drive number
  mov ax,440Fh            ; set logical drive map
  int 21h                 ; update the logical drive ID
                          ; (DOS returns AL = 02H)

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson