home *** CD-ROM | disk | FTP | other *** search
- /*
- File: UnitTableDoDriverIO
-
- Contains: This file contains the sole entry point into the driver
- from the system, and the sole return command completion point.
-
- Version: 1.0
-
- Copyright: © 1998-1999 by Apple Computer, Inc., all rights reserved.
-
- */
-
-
- #include "UnitTableDoDriverIO.h"
- #include "UnitTableFunctions.h"
-
- //----------------------------------------------------------------------------------
- // The DoDriverIO Function -
- // This function is the only entry to our driver from the Device Manager
- //----------------------------------------------------------------------------------
-
- OSStatus DoDriverIO( AddressSpaceID addressSpaceID,
- IOCommandID ioCommandID,
- IOCommandContents ioCommandContents,
- IOCommandCode ioCommandCode,
- IOCommandKind ioCommandKind)
- {
- #pragma unused ( addressSpaceID )
- OSStatus status;
-
- // All mangement of the Address space should be handled here. Currently the
- // MacOS only supports one address space so nothing needs to be done.
-
- /*
- Note: Initialize, Open, KillIO, Close, and Finalize are either synchronous
- or immediate. Read, Write, Control, and Status may be immediate,
- synchronous, or asynchronous.
- */
- switch (ioCommandCode)
- {
- case kInitializeCommand: /* Always immediate */
- status = DriverInitializeCmd ( ioCommandContents.initialInfo->refNum, &ioCommandContents.initialInfo->deviceEntry );
- break;
-
- case kFinalizeCommand: /* Always immediate */
- status = DriverFinalizeCmd ( ioCommandContents.finalInfo->refNum, &ioCommandContents.finalInfo->deviceEntry );
- break;
-
- case kSupersededCommand: /* Always immediate */
- status = DriverSupersededCmd ( ioCommandContents.supersededInfo->refNum, &ioCommandContents.supersededInfo->deviceEntry );
- break;
-
- case kReplaceCommand: /* Always immediate, replace an old driver */
- status = DriverReplaceCmd ( ioCommandContents.replaceInfo->refNum, &ioCommandContents.replaceInfo->deviceEntry );
- break;
-
- case kOpenCommand: /* Always immediate */
- status = DriverOpenCmd ( ioCommandContents.pb);
- break;
-
- case kCloseCommand: /* Always immediate */
- status = DriverCloseCmd ( ioCommandContents.pb );
- break;
-
- case kControlCommand:
- status = DriverControlCmd ( ioCommandID, ioCommandContents.pb );
- break;
-
- case kStatusCommand:
- status = DriverStatusCmd ( ioCommandID, ioCommandContents.pb );
- break;
-
- case kReadCommand:
- status = DriverReadCmd ( ioCommandID, ioCommandContents.pb );
- break;
-
- case kWriteCommand:
- status = DriverWriteCmd ( ioCommandID, ioCommandContents.pb );
- break;
-
- case kKillIOCommand: /* Always immediate */
- status = DriverKillIOCmd ( ioCommandContents.pb );
- break;
-
- default:
- status = paramErr;
- break;
- }
-
- if ((ioCommandKind & kImmediateIOCommandKind) != 0)
- {
- // We have an immediate command, return the status.
- return status;
- }
- else
- {
- // The command may not yet have finished, FinishCommandProcessing
- // will handle appropriately
- return FinishCommandProcessing(ioCommandID, status);
- }
- }
-
- OSStatus FinishCommandProcessing(IOCommandID ioCommandID, OSStatus incomingStatus)
- {
- OSStatus status;
- IOCommandContents ioCommandContents;
- IOCommandCode ioCommandCode;
- IOCommandKind ioCommandKind;
-
- status = GetIOCommandInfo( ioCommandID, &ioCommandContents, &ioCommandCode, &ioCommandKind);
- if ( status != noErr )
- {
- return status;
- }
-
- status = incomingStatus;
-
- if ((ioCommandKind & kImmediateIOCommandKind) != 0)
- {
- /* Immediate commands return the operation status and don't call IOCommandIsComplete */
- IfDebugging("\pImmd cmd complete");
- }
- else if (incomingStatus == ioInProgress)
- {
- IfDebugging("\pincomingStatus == ioInProgress");
- /* Perform the action and call IOCommandIsComplete at some later time */
- status = noErr;
- }
- else
- {
- IfDebugging("\pDo Command Is Complete");
- status = IOCommandIsComplete (ioCommandID, incomingStatus);
- }
-
- IfDebugging("\pExit FinishCommandProcessing");
- return (status);
- }
-
-