read(D2DK) —
NAME
read − read data from a device
SYNOPSIS
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/uio.h>
#include <sys/cred.h>
int prefixread(dev_t dev, uio_t ∗uiop, cred_t ∗crp);
ARGUMENTS
dev Device number.
uiop Pointer to the uio(D4DK) structure that describes where the data is to be stored in user space.
crp Pointer to the user credential structure for the I/O transaction.
DESCRIPTION
The driver read routine is called during the read(2) system call. The read routine is responsible for transferring data from the device to the user data area. The data to be transferred may be of any size or alignment. Only devices which cannot break data transfers into smaller blocks are allowed to refuse a read request on this basis. The pointer to the user credentials, crp, is available so the driver can check to see if the user can read privileged information, if the driver provides access to any. The uio structure provides the information necessary to determine how much data should be transferred. The uiomove(D3DK) function provides a convenient way to copy data using the uio structure.
Block drivers that provide a character interface can use physiock(D3DK) or uiophysio(D3DK) to perform the data transfer with the driver’s strategy(D2DK) routine.
NOTES
This interface is optional. The read routine has user context and can sleep.
RETURN VALUE
The read routine should return 0 for success, or the appropriate error number.
ERROR RETURN CODES
EAGAINTemporary resource allocation failure; try again later. Drivers can return this error when resource allocation fails, for example, kmem_alloc(D3DK) or allocb(D3DK).
EFAULTBad address. Drivers should return this error whenever a call to copyin(D 3DK) or copyout(D3DK) fails.
EINTRInterrupted operation. Drivers can return this error whenever an interruptible operation is interrupted by receipt of an asynchronous signal.
EINVALInvalid argument. Drivers can return this error for operations that have invalid parameters specified.
EIOAn I/O error has occurred. Drivers can return this error when an input or output request has failed.
ENXIONo such device or address. Drivers can return this error when trying to open an invalid minor device, or when trying to perform I/O past the end of a device.
EPERMPermission denied. Drivers can return this error when the current process doesn’t have sufficient privilege for the operation attempted.
SEE ALSO
strategy(D2DK), write(D2DK), drv_priv(D3DK), physiock(D3DK), uiomove(D3DK), ureadc(D3DK), uio(D4DK), uiophysio(D3DK), errnos(D5DK)
DDI/DKI