Specifications
Developing a Device Drive
r
10-1
7
The Ioctl Routine 10
Specification
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/file.h>
#include <sys/cred.h>
#include <sys/ddi.h>
int xxioctl (dev, cmd, arg, mode, crp, rvalp)
dev_t dev;
int cmd;
void * arg;
int mode;
cred_t *crp;
int *rvalp;
Return Values
• 0 if the device ioctl is successful
• A nonzero value if the ioctl fails. The number is returned to the user in
errno; it should be an error number as defined in <sys/errno.h>.
Thedevicedriver’sioctl(D2) entry point routine is called when a user makes an
ioctl(2) system call to perform specialized operations on the associated device.
This entry point is optional. It is valid only for character device drivers.
The dev argument specifies the device major and minor number.
The cmd argument is an integer value that specifies the type of operation to be performed.
This integer value comprises several fields; these fields encode such information as the
following: the command, the direction of a data transfer, and the size of the transfer
buffer. Command types are defined in the device driver. It is recommended that you
always define them by using the ioctl macros that are defined in the file
<sys/ioccom.h>. These macros are described in Chapter 9, “Ioctl Macros” on page
9-12.
The arg argument passes parameters between the user and the driver. The interpretation of
the argument is dependent on the command and the driver. For example, the argument can
be an integer, or it can be the address of a user structure containing driver or hardware
settings. In the latter case, the driver can use the copyin(D3) and copyout(D3)
routines to transfer data between the user space and the kernel space.
The mode argument contains the file modes set when the device was opened. The driver
can use this to determine if the device was opened for reading (FREAD), writing
(FWRITE), and so on. See open(D2) for a description of the values.
The crp argument is a pointer to the user credential structure.
The rvalp argument is a pointer to the return value for the calling process. The driver can
elect to set the value if the ioctl(D2) succeeds.