Specifications

Sample Driver Written in C
B.1 LRDRIVER Example
* irp Pointer to I/O request packet
* pcb Pointer process control block
* ucb Pointer to unit control block
* ccb Pointer to channel control block
*
* Output parameters:
*
* None.
*
* Return value:
*
* status SS$_FDT_COMPL
*
* Environment:
*
* Kernel mode, user process context, IPL 2.
*/
int lr$write (IRP *irp, PCB *pcb, LR_UCB *ucb, CCB *ccb) {
/* Define a structure type for the carraige control information that
* is returned from exe_std$carriage. This information is returned in
* the IRP at the longword that begins with irp->irp$b_carcon.
*/
typedef struct {
uint8 prefix_count; /* Number of prefix chars */
char prefix_char; /* The prefix char, 0 if newline */
uint8 suffix_count; /* Number of suffix chars */
char suffix_char; /* The suffix char, 0 if newline */
} CARCON;
char *qio_bufp; /* Pointer to callers buffer */
int qio_buflen; /* Number of bytes in callers buffer */
SYSBUF_HDR *sys_bufp; /* Pointer to a system buffer packet */
int32 sys_buflen; /* Computed required system packet size */
char *sys_datap; /* Working pointer to next byte in sysbuf */
int pass_all; /* True if this is a "pass all" write */
int status;
/* Get the pointer to the callers buffer and the size of the callers
* buffer from the $QIO P1 and P2 parameters.
*/
qio_bufp = (char *) irp->irp$l_qio_p1;
qio_buflen = irp->irp$l_qio_p2;
/* Assure that the caller has read access to this buffer to do a write
* operation. If not, exe_std$writechk will abort the I/O request and
* return the SS$_FDT_COMPL warning status. If this is the case, we must
* return back to the FDT dispatcher in the $QIO system service. Note we
* continue on even if the user buffer is zero length since there may be
* carriage control to output.
*/
if (qio_buflen != 0) {
status = exe_std$writechk (irp, pcb, &(ucb->ucb$r_ucb),
qio_bufp, qio_buflen);
if ( ! $VMS_STATUS_SUCCESS(status) ) return status;
}
/* Start out assuming that the required system buffer packet size is
* the size of the $QIO buffer plus the size of the buffer packet header.
*/
sys_buflen = qio_buflen + sizeof(SYSBUF_HDR);
/* This is a "pass all" request either if the write physical function
* was specified or if the device is set to "write pass all" mode.
*/
pass_all = irp->irp$v_func == IO$_WRITEPBLK ||
(ucb->ucb$r_ucb.ucb$l_devdepend & LP$M_PASSALL);
B–13