home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Examples / USBSampleStorageDriver / StorageClassUTDriver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-12  |  4.8 KB  |  155 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        StorageClassUTDriver.c
  3.  
  4.     Contains:    This file contains the globally exported symbols and 
  5.                 entry points into the Storage Class UT driver.
  6.  
  7.     Version:    1.1
  8.  
  9.     Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved.
  10.  
  11.     File Ownership:
  12.  
  13.         DRI:                Craig Keithley
  14.  
  15.         Other Contact:        xxx put other contact here xxx
  16.  
  17.         Technology:            USB Drivers
  18.  
  19.     Writers:
  20.  
  21.         (CJK)    Craig Keithley
  22.  
  23.     Change History (most recent first):
  24.  
  25.       <USB2>     1/11/99    CJK        update to use sources from 1.1f3 DDK
  26.  
  27. */
  28.  
  29. #include "StorageClassUTDriver.h"
  30. #include "StorageClassUTFunctions.h"
  31. #include "SampleStorageVersion.h"
  32.  
  33. //----------------------------------------------------------------------------------
  34. //    The Driver Description structure -
  35. //     This structure provides the Device Manager with information about our native driver
  36. //----------------------------------------------------------------------------------
  37.  
  38. DriverDescription TheDriverDescription = 
  39. {
  40.     kTheDescriptionSignature,
  41.     kInitialDriverDescriptor,
  42.  
  43.     // DriverType
  44.     "\p.StorageClass_UT_Driver",
  45.     kStorageHexMajorVers, kStorageHexMinorVers, kStorageReleaseStage, kStorageCurrentRelease,
  46.  
  47.     // DriverOSRuntimeInfo
  48.     0
  49.     | (1 * kDriverIsLoadedUponDiscovery)    //    Loader runtime options
  50.     | (1 * kDriverIsOpenedUponLoad)            //    Opened when loaded
  51.     | (0 * kDriverIsUnderExpertControl)        //    No I/O expert to handle loads/opens
  52.     | (0 * kDriverIsConcurrent)                //    Not concurrent yet
  53.     | (0 * kDriverQueuesIOPB),                //    Not internally queued yet
  54.     "\p.StorageClass_UT_Driver",                    //    Str31 driverName (OpenDriver param)
  55.     0, 0, 0, 0, 0, 0, 0, 0,                    //    UInt32 driverDescReserved[8]
  56.  
  57.     // DriverOSService
  58.     1,                                        //    ServiceCount nServices
  59.  
  60.     // DriverServiceInfo
  61.     kServiceCategoryNdrvDriver,                //    OSType serviceCategory
  62.     kNdrvTypeIsGeneric,                        //    OSType serviceType
  63.     kStorageHexMajorVers, kStorageHexMinorVers, kStorageReleaseStage, kStorageCurrentRelease
  64. };
  65.  
  66. //----------------------------------------------------------------------------------
  67. //    The DoDriverIO Function -
  68. //     This function is the only entry to our driver from the Device Manager
  69. //----------------------------------------------------------------------------------
  70.  
  71. OSStatus DoDriverIO(    AddressSpaceID        addressSpaceID,
  72.                         IOCommandID            ioCommandID,
  73.                         IOCommandContents    ioCommandContents,
  74.                         IOCommandCode        ioCommandCode,
  75.                         IOCommandKind        ioCommandKind)
  76. {
  77.     OSStatus    status;
  78.         
  79.     IfDebugging("\pIn my driver");
  80.     /*
  81.         Note: Initialize, Open, KillIO, Close, and Finalize are either synchronous
  82.         or immediate. Read, Write, Control, and Status may be immediate,
  83.         synchronous, or asynchronous.
  84.     */
  85.     switch (ioCommandCode)
  86.     {
  87.         case kInitializeCommand:        /* Always immediate */
  88.             status = DriverInitializeCmd (addressSpaceID, ioCommandContents.initialInfo);
  89.             break;
  90.         case kFinalizeCommand:            /* Always immediate */
  91.             status = DriverFinalizeCmd (ioCommandContents.finalInfo);
  92.             break;
  93.         case kSupersededCommand:        /* Always immediate */
  94.             status = DriverSupersededCmd (ioCommandContents.supersededInfo);
  95.             break;
  96.         case kReplaceCommand:            /* Always immediate, replace an old driver */
  97.             status = DriverReplaceCmd (addressSpaceID, ioCommandContents.replaceInfo);
  98.             break;
  99.         case kOpenCommand:                /* Always immediate */
  100.             status = DriverOpenCmd (addressSpaceID, ioCommandContents.pb);
  101.             break;
  102.         case kCloseCommand:                /* Always immediate */
  103.             status = DriverCloseCmd (ioCommandContents.pb);
  104.             break;
  105.         case kControlCommand:
  106.             status = DriverControlCmd (addressSpaceID, ioCommandID, ioCommandKind, ioCommandContents.pb);
  107.             break;
  108.         case kStatusCommand:
  109.             status = DriverStatusCmd (addressSpaceID, ioCommandID, ioCommandKind, ioCommandContents.pb);
  110.             break;
  111.         case kReadCommand:
  112.             status = DriverReadCmd ( addressSpaceID, ioCommandID, ioCommandKind, ioCommandContents.pb);
  113.             break;
  114.         case kWriteCommand:
  115.             status = DriverWriteCmd ( addressSpaceID, ioCommandID, ioCommandKind, ioCommandContents.pb);
  116.             break;
  117.         case kKillIOCommand:            /* Always immediate */
  118.             status = DriverKillIOCmd (ioCommandContents.pb);
  119.             break;
  120.         default:
  121.             status = paramErr;
  122.             break;
  123.     }
  124.     
  125.     return FinishCommandProcessing(ioCommandID, ioCommandKind, status);
  126. }
  127.     
  128. OSStatus FinishCommandProcessing(IOCommandID ioCommandID,IOCommandKind ioCommandKind,OSStatus incomingStatus)
  129. {
  130.     OSStatus status = incomingStatus;
  131.     
  132.     IfDebugging("\pFinishCommandProcessing");
  133.     
  134.     if ((ioCommandKind & kImmediateIOCommandKind) != 0)
  135.     {
  136.         /* Immediate commands return the operation status and don't call IOCommandIsComplete */
  137.         IfDebugging("\pImmd cmd complete");
  138.     }
  139.     else if (incomingStatus == ioInProgress)
  140.     {
  141.         IfDebugging("\pincomingStatus == ioInProgress");
  142.         /* Perform the action and call IOCommandIsComplete at some later time */
  143.         status = noErr;
  144.     }
  145.     else
  146.     {
  147.         IfDebugging("\pDo Command Is Complete");        
  148.         status = IOCommandIsComplete (ioCommandID, incomingStatus);
  149.     }
  150.  
  151.     IfDebugging("\pExit FinishCommandProcessing");
  152.     return (status);
  153. }
  154.  
  155.