Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>ioctl() control i/0 device</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 ioctl()                 Control I/0 Device

 #include   <io.h>

 int        ioctl(handle,cmd[,argdx,argcx]);
 int        handle;                      Handle associated with file/drive
 int        cmd;                         Function to be performed
 void       *argdx;
 int        argcx;

    ioctl() connects directly with the MS-DOS system call 0x44 (IOCTL) to
    get or set information related to input/output channels.  ioctl() can
    be used with either devices or files.  For files, however, all calls
    other than the 'cmd' values 0, 6, and 7 in the following list produce
    an EINVAL error.

    The value of 'cmd' specifies the function to be carried out:

               0    Get device information
               1    Set device information (in 'argdx')
               2    Read 'argcx' bytes into the address pointed to
                    by 'argdx'
               3    Write 'argcx' bytes from the address pointed to
                    by 'argdx'
               4    Same as 2, but 'handle' is treated as a drive
                    number (0=default,1=A, etc)
               5    Same as 3, but 'handle' is a drive number
                    (0=default, 1=A, etc)
               6    Get input status
               7    Get output status
               8    Test removability of drive 'handle'; DOS 3.x only
              11    Set sharing conflict retry count; DOS 3.x only


    The arguments 'argdx' and 'argcx' are optional.

       Returns:     For 'cmd' values of 0 or 1, the return value is the
                    device information (DX of the IOCTL call).

                    For 'cmd' values of 2 through 5, the return value is
                    the number of bytes actually transferred.

                    For 'cmd' values of 6 or 7, the return value is the
                    device status.

                    For 'cmd' value of 8, the return value can be: 0, if
                    device is removable or 1 if the device is fixed.

                    For 'cmd' value of 11, the return value is the error
                    code, if the carry flag is set.

                    On error, -1 is returned and 'errno' (defined in
                    <errno.h>) is set to one of the following:

                     EINVAL             Invalid argument
                     EBADF              Bad file number
                     EINVDAT       Invalid data

         Notes:     ioctl() is available on UNIX systems, but not with
                    these parameters or this functionality.  UNIX version
                    7 and System III differ from each other in their use
                    of ioctl().  ioctl() calls are not portable to UNIX
                    and are rarely portable across MS-DOS machines.


   -------------------------------- Example ---------------------------------

    The following statements test the drives A: to D: for removable
    media. NOTE: This example requires MS-DOS 3.0 or later.

           #include <io.h>         /* for ioctl */
           #include <stdio.h>      /* for printf */

           main()
           {
                int drive, status;

                for (drive = 1; drive <= 4; drive++) {
                   status = ioctl(drive,8);
                   printf("Drive %c: is ",'A'+drive-1);
                   if (status == 0xF)
                       printf("not online.\n");
                   else if (status == 0)
                       printf("removable.\n");
                   else
                       printf("not removable.\n");
               }
           }




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