home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / USBSampleStorageDriver / UnitTableDriver / UnitTablePCExchangeSupport.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-25  |  6.9 KB  |  231 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        UnitTablePCExchangeSupport.c
  3.  
  4.     Contains:    All functionality needed especially for PC Exchange/FSM support.
  5.  
  6.     Version:    1.0
  7.  
  8.     Copyright:    © 1999 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. #include "UnitTablePCExchangeSupport.h"
  12. #include "UnitTableDriveQSupport.h"
  13.  
  14. // The parameters userData and callBack are currently unused because all requests will complete 
  15. // immediately.  If at a later point a request is added that needs to call the DAM, an internal
  16. // paramter block will need to be created, and these values saved.
  17. OSStatus PCExchangeControlCallSupport(     UInt32                                    userData,
  18.                                         CntrlParamPtr                            cntrlPBPtr,
  19.                                         ControlStatusCompletionProcPtr            callBack )
  20. {
  21. #pragma unused ( userData, callBack )
  22.  
  23.     OSStatus        err            = noErr;
  24.     SInt16            driveNum;
  25.  
  26.     driveNum = cntrlPBPtr->ioVRefNum;
  27.     
  28.     // Parse the control codes…
  29.     switch( cntrlPBPtr->csCode ) 
  30.     {
  31.         case kRegisterPartition:            // Register New Partition
  32.         {
  33.             // PCX will call this function when it wants to redefine a partition.  It will
  34.             // pass in the drive queue element pointer of the partition to redefine, the
  35.             // new starting physical block offset, and the new block length.
  36.             if( AreThereMountedDrives() == false )
  37.             {
  38.                 err = nsDrvErr;            // no Media is inserted, return an error
  39.             }
  40.             else
  41.             {
  42.                 DrvQElPtr        theDrvQEl;                                // drive queue element pointer
  43.                 UInt32            *altParams;                                // local pointer to alternate control parameters
  44.                 
  45.                 altParams = (UInt32 *) (&cntrlPBPtr->csParam[0]);        // alternate parameters
  46.                 theDrvQEl = (DrvQElPtr) altParams[THE_DRIVE];
  47.                 if ( theDrvQEl != nil )                                    // if valid queue element pointer
  48.                 {
  49.                     DriveQRecPtr    vol = nil;                            // pointer to our volume record structure
  50.                     
  51.                     vol = FindDriveQRecForDriveNum( theDrvQEl->dQDrive );
  52.                     if ( vol )                                            // and valid volume reference
  53.                     {
  54.                         vol->partoffset = altParams[THE_PHYS_START];    // new partition offset
  55.                         vol->curoffset = vol->partoffset;                // current offset changes also
  56.                         vol->partblks = altParams[THE_PHYS_SIZE];        // new partition size
  57.                         
  58.                         UpdateQ(theDrvQEl->dQDrive, vol->partblks);        // Update drive queue capacity
  59.                         vol->diskInsertPosted = true;                    // PCX will handle the Disk Insert event
  60.                         err = noErr;                                    // clear error
  61.                     }
  62.                     else
  63.                     {
  64.                         err = nsDrvErr;                                    // no Media is inserted, return an error
  65.                     }
  66.                 }
  67.                 else
  68.                 {
  69.                     err = nsDrvErr;                                        // invalid DriveQEl was passed in
  70.                 }
  71.             }
  72.         }
  73.         break;
  74.  
  75.         case kGetADrive:                    // Get A Drive (Create New Partition)
  76.         {    
  77.             // PCX calls this function to add a new partition.  The new partition's DrvQElPtr is
  78.             // returned. NOTE: If the driver handles multiple drives note that PCX does not pass
  79.             // in the physical drive number on which to create the new partition.  However, the
  80.             // DrvQElPtr stored at the pointer passed in is for another partition on the drive.
  81.             if( AreThereMountedDrives() == false )
  82.             {
  83.                 err = nsDrvErr;            // no Media is inserted, return an error
  84.             }
  85.             else
  86.             {
  87.                 // PC Exchange does not pass in a drive number, because the purpose of this
  88.                 // control call is to allow PC Exchange to create new drives for a disk
  89.                 // that has multiple DOS partitions
  90.                 UInt32            *altParams;                                // local pointer to alternate control parameters
  91.                 
  92.                 altParams = (UInt32 *) (&cntrlPBPtr->csParam[0]);        // alternate parameters
  93.                 if (altParams[THE_VAR_QUEL] == nil)                        // verify a valid queue element handle
  94.                 {
  95.                     err = paramErr;
  96.                 }
  97.                 else
  98.                 {
  99.                     // create a new volume record and DrvQEl associated with the physical drive.
  100.                     // The new volume starts at offset 0 and has no capacity yet. By default, the
  101.                     // partition will not have a partition map entry on the media.
  102.                     DriveQRecPtr    vol = nil;        // pointer to our volume record structure
  103.                         
  104.                     vol = CreateNewDriveQRecForPartition( NextPartitionID(), 0, 0 );
  105.                     if ( vol ) 
  106.                     {
  107.                         // Return the DrvQElPtr at the location passed in…
  108.                         *((DrvQElPtr*)altParams[THE_VAR_QUEL]) = (DrvQElPtr) &vol->driveStatus.qLink;
  109.                         err = noErr;
  110.                     }
  111.                     else
  112.                     {
  113.                         err = controlErr;
  114.                     }
  115.                 }
  116.             }
  117.         }
  118.         break;
  119.         
  120.         case kProhibitMounting:
  121.         {
  122.             // This PC Exchange control call is currently not supported,
  123.             // need to verify that this is still used.
  124.             err = controlErr;
  125.         }
  126.         break;
  127.  
  128.         default:
  129.         {
  130.             err = controlErr;
  131.         }
  132.         break;
  133.     }
  134.     
  135.     return err;
  136. }
  137.  
  138. // The parameters userData and callBack are currently unused because all requests will complete 
  139. // immediately.  If at a later point a request is added that needs to call the DAM, an internal
  140. // paramter block will need to be created, and these values saved.
  141. OSStatus PCExchangeStatusCallSupport(     UInt32                                    userData,
  142.                                         CntrlParamPtr                            cntrlPBPtr,
  143.                                         ControlStatusCompletionProcPtr            callBack )
  144. {
  145. #pragma unused ( userData, callBack )
  146.     OSStatus        err    = noErr;
  147.     SInt16            driveNum;
  148.  
  149.     driveNum = cntrlPBPtr->ioVRefNum;
  150.     
  151.     // Parse the status codes…
  152.     switch(cntrlPBPtr->csCode) 
  153.     {
  154.         case kGetPartitionStatus:
  155.         {
  156.             // I have never seen this called, who uses it?
  157.             UInt32                *altParams;                        // alternate csParams as long words
  158.             partInfoRecPtr         thePartInfo;
  159.             
  160.             altParams = (UInt32 *) &cntrlPBPtr->csParam[0];            // alternate parameters
  161.             thePartInfo = (partInfoRecPtr) altParams[kDeviceToQuery];
  162.             if( thePartInfo != nil )
  163.             {
  164.                 DriveQRecPtr        vol = nil;
  165.                 
  166.                 vol = FindDriveQRecForPartitionNum( thePartInfo->partitionNumber );
  167.                 if ( vol != nil )
  168.                 {
  169.                     altParams[kDeviceResponse] = vol->driveNum;
  170.                     err = noErr;
  171.                 }
  172.                 else
  173.                 {
  174.                     err = nsDrvErr;        // no Media is inserted, or this is not our drive, return an error
  175.                 }
  176.             }
  177.             else
  178.             {
  179.                 err = nsDrvErr;            // no Media is inserted, or this is not our drive, return an error
  180.             }
  181.         }
  182.         break;
  183.         
  184.         case kGetPartInfo:
  185.         {
  186.             // PCX will call this function to get info on the specified partition. 
  187.             // Return the physical drive reference, the starting block offset, and 
  188.             // the partition ID (any relative non-zero reference).
  189.             if( AreThereMountedDrives() == false )
  190.             {
  191.                 err = nsDrvErr;            // no Media is inserted, return an error
  192.             }
  193.             else
  194.             {
  195.                 DriveQRecPtr        vol = nil;
  196.                 
  197.                 vol = FindDriveQRecForDriveNum( driveNum );
  198.                 if( vol != nil )
  199.                 {
  200.                     UInt32                *altParams;                // alternate csParams as long words
  201.                     partInfoRecPtr         thePartInfo;
  202.                     
  203.                     altParams = (UInt32 *) &cntrlPBPtr->csParam[0];            // alternate parameters
  204.                     thePartInfo = (partInfoRecPtr) altParams[kPartInfoResponse];
  205.                     
  206.                     // SCSIID is not defined for non-SCSI devices.  Return zero
  207.                     *((UInt32 *)&thePartInfo->SCSIID) = 0;
  208.             
  209.                     thePartInfo->physPartitionLoc = vol->partoffset;
  210.                     thePartInfo->partitionNumber = vol->partitionNo;
  211.                     err = noErr;
  212.                 }
  213.                 else
  214.                 {
  215.                     err = nsDrvErr;            // no Media is inserted, or this is not our drive, return an error
  216.                 }
  217.             }
  218.         }
  219.         break;
  220.     
  221.         default:
  222.         {
  223.             err = statusErr;
  224.         }
  225.         break;
  226.     }
  227.     
  228.     return err;
  229. }
  230.  
  231.