A typical driver code framework for responding to DoDriverIO is shown in Listing 8-2.
Listing 8-2 Driver handler for DoDriverIO
OSErr
DoDriverIO(AddressSpaceID spaceID,
IOCommandID theID,
IOCommandContents theContents,
IOCommandCode theCode,
IOCommandKind theKind)
{
OSErr result;
switch(theCode)
{
case kInitializeCommand:
case kReplaceCommand:
result = DoInitializeCmd
(theContents.initialInfo->refNum,
&theContents.initialInfo->deviceEntry);
break;
case kFinalizeCommand:
case kSupersededCommand:
result = DoFinalizeCmd
(theContents.finalInfo->refNum,
&theContents.finalInfo->deviceEntry);
break;
case kOpenCommand:
result = DoOpenCmd (theContents.pb);
break;
case kCloseCommand:
result = DoCloseCmd (theContents.pb);
break;
case kKillIOCommand:
result = DoKillIOCmd (theContents.pb);
break;
case kReadCommand:
result = DoReadCmd (theContents.pb);
break;
case kWriteCommand:
result = DoWriteCmd (theContents.pb);
break;
case kControlCommand:
result = DoControlCmd (theContents.pb);
break;
case kStatusCommand:
result = DoStatusCmd (theContents.pb);
break;
default:
result = paramErr;
break;
}
/* if an immediate command make sure result = a valid result */
if ((ioCommandKind & kImmediateIOCommandKind) != 0) {
return (result); /* immediate commands return the */
/* operation status */
}
else if (status == kIOBusyStatus) {
/*
* An asynchronous operation is in progress. The driver
* handler promises to call IOCommandIsComplete when the
* operation concludes.
*/
return (noErr);
}
else {
/*
* Normal command that completed synchronously. Complete
* the operation and return.
*/
return (IOCommandIsComplete(ioCommandID, status));
}