home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / DASD / OS2DASD / DMCSUBR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-14  |  20.1 KB  |  689 lines

  1. /*DDK*************************************************************************/
  2. /*                                                                           */
  3. /* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
  4. /*                                                                           */
  5. /*    The following IBM OS/2 WARP source code is provided to you solely for  */
  6. /*    the purpose of assisting you in your development of OS/2 WARP device   */
  7. /*    drivers. You may use this code in accordance with the IBM License      */
  8. /*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
  9. /*    Copyright statement may not be removed.                                */
  10. /*                                                                           */
  11. /*****************************************************************************/
  12. /*static char *SCCSID = "src/dev/dasd/os2dasd/dmcsubr.c, dsdm, ddk_subset, b_bdd.032 93/03/20";*/
  13. #define SCCSID  "src/dev/dasd/os2dasd/dmcsubr.c, dsdm, ddk_subset, b_bdd.032 93/03/20"
  14.  
  15. /**************************************************************************
  16.  *
  17.  * SOURCE FILE NAME = DMCSUBR.C
  18.  *
  19.  * DESCRIPTIVE NAME = OS2DASD.DMD - OS/2 DASD Device Manager
  20.  *
  21.  *
  22.  *
  23.  * VERSION = V2.0
  24.  *
  25.  * DATE
  26.  *
  27.  * DESCRIPTION : Miscellaneous C subroutines/utility fcns.
  28.  *
  29.  *
  30.  *
  31. */
  32. #include "dmh.h"
  33.  
  34. /*------------------------------------------------------------------------
  35. ;
  36. ;** Get_VolCB_Addr - Return a pointer to a VolCB for the specified Drive
  37. ;
  38. ;   USHORT NEAR Get_VolCB_Addr   (USHORT DriveNum, NPVOLCB *pVolCB)
  39. ;
  40. ;   USHORT FAR  f_Get_VolCB_Addr (USHORT DriveNum, NPVOLCB *pVolCB)
  41. ;
  42. ;   ENTRY:    DriveNum         - Drive Number
  43. ;             pVolCB           - returned pointer to VolCB
  44. ;
  45. ;   RETURN:   USHORT           - Result Code (NO_ERROR if VolCB found)
  46. ;
  47. ;   EFFECTS:
  48. ;
  49. ;   NOTES:
  50. ------------------------------------------------------------------------*/
  51. USHORT FAR f_Get_VolCB_Addr (DriveNum, pVolCB)
  52.  
  53. USHORT  DriveNum;
  54. NPVOLCB FAR *pVolCB;
  55. {
  56.    return(Get_VolCB_Addr (DriveNum, (NPVOLCB FAR *) pVolCB));
  57.  
  58. }
  59.  
  60. USHORT Get_VolCB_Addr (DriveNum, pVolCB)
  61.  
  62. USHORT  DriveNum;
  63. NPVOLCB FAR *pVolCB;
  64. {
  65.    USHORT  found = FALSE;
  66.    NPVOLCB pVolCBx;
  67.  
  68.    if ( !(DDFlags & DDF_NO_MEDIA) )
  69.    {
  70.       pVolCBx = VolCB_Head;
  71.  
  72.       while (pVolCBx != NULL && found == FALSE)
  73.       {
  74.          if (pVolCBx->LogDriveNum == DriveNum)
  75.             found = TRUE;
  76.          else
  77.             pVolCBx = pVolCBx->pNextVolCB;
  78.       }
  79.    }
  80.  
  81.    if (found == TRUE)
  82.    {
  83.       *pVolCB = pVolCBx;
  84.       return(NO_ERROR);
  85.    }
  86.    else
  87.       return(ERROR);
  88. }
  89.  
  90. /*---------------------------------------------------------------
  91. ;
  92. ;** ReadSecInScratch_RBA - Read sector into scratch buffer
  93. ;
  94. ;   Reads a sector into the ScratchBuffer.
  95. ;
  96. ;   USHORT ReadSecInScratch_RBA (NPVOLCB pVolCB, ULONG rba, USHORT type)
  97. ;
  98. ;   ENTRY:    pVolCB           - Pointer to VolCB
  99. ;             rba              - RBA of sector to read
  100. ;             type             - Type of request (0= add in hidden sectors,
  101. ;                                                 1= dont add in hidden sectors)
  102. ;
  103. ;   RETURN:   USHORT           - Result Code (NO_ERROR if successful)
  104. ;
  105. ;   EFFECTS:  Reads a sector into global variable ScratchBuffer.
  106. ;
  107. ;   NOTES:
  108. ;
  109. ;   SEGMENT:  StaticCode
  110. ;--------------------------------------------------------------*/
  111. USHORT FAR f_ReadSecInScratch_RBA (pVolCB, rba, type)
  112.  
  113. NPVOLCB  pVolCB;
  114. ULONG    rba;
  115. USHORT   type;
  116. {
  117.    return (ReadSecInScratch_RBA (pVolCB, rba, type));
  118. }
  119.  
  120. USHORT ReadSecInScratch_RBA (pVolCB, rba, type)
  121.  
  122. NPVOLCB  pVolCB;
  123. ULONG    rba;
  124. USHORT   type;
  125. {
  126.    PRP_INTERNAL  pRP;                                                /*@V59914*/
  127.    USHORT rc;
  128.  
  129.    DevHelp_AllocReqPacket (0, (PBYTE FAR *)&pRP); /* Allocate a request packet */
  130.  
  131.    pRP->rph.Cmd = CMDINPUT;
  132.    pRP->rph.Flags = RPF_Internal;       /* Internal read request */
  133.    pRP->rph.Unit = pVolCB->LogDriveNum; /* Copy unit number */
  134.    pRP->XferAddr = ppScratchBuffer;     /* Set xfer addr of ScratchBuffer */
  135.    pRP->NumSectors = 1;                 /* read one sector */
  136.    pRP->rba = rba;                      /* Setup rba */
  137.    pRP->SectorSize = 0;                 /* Setup Sector Size */      /*@V59914*/
  138.  
  139.    pVolCB->Flags |= vf_ForceRdWrt;      /* force next read to succeed */
  140.  
  141.    pRP->rba += pVolCB->PartitionOffset; /* Add in partition offset    */
  142.  
  143.    if (type == 0)
  144.       pRP->rba += pVolCB->MediaBPB.HiddenSectors; /* Add in Hidden sectors */
  145.  
  146.    DiskIO_Wait ((PBYTE)pRP, pVolCB);    /* Issue the read request */
  147.  
  148.    rc = pRP->rph.Status;                /* Get return status */
  149.  
  150.    DevHelp_FreeReqPacket ((PBYTE)pRP);         /* Free the request packet */
  151.  
  152.    if (rc & STERR)                      /* Check for error */
  153.       return(ERROR);
  154.    else
  155.       return(NO_ERROR);
  156. }
  157.  
  158. /*---------------------------------------------------------------
  159. ;
  160. ;** ReadSecInScratch_CHS - Read sector into scratch buffer
  161. ;
  162. ;   Reads a sector into the ScratchBuffer.
  163. ;
  164. ;   USHORT ReadSecInScratch_CHS (NPVOLCB pVolCB, USHORT Cylinder,
  165. ;                                UCHAR Head, UCHAR Sector)
  166. ;
  167. ;   ENTRY:    pVolCB           - pointer to VolCB
  168. ;             Cylinder         - Cylinder
  169. ;             Head             - Head
  170. ;             Sector           - Sector
  171. ;
  172. ;   RETURN:   USHORT           - Result Code (NO_ERROR if successful)
  173. ;
  174. ;   EFFECTS:  Reads a sector into global variable ScratchBuffer.
  175. ;
  176. ;   NOTES:
  177. ;
  178. ;   SEGMENT:  SwapCode
  179. ;--------------------------------------------------------------*/
  180. USHORT FAR f_ReadSecInScratch_CHS (pVolCB, Cylinder, Head, Sector)
  181.  
  182. NPVOLCB  pVolCB;
  183. USHORT   Cylinder;
  184. UCHAR    Head, Sector;
  185.  
  186. {
  187.   return (ReadSecInScratch_CHS (pVolCB, Cylinder, Head, Sector));
  188. }
  189.  
  190. USHORT ReadSecInScratch_CHS (pVolCB, Cylinder, Head, Sector)
  191.  
  192. NPVOLCB  pVolCB;
  193. USHORT   Cylinder;
  194. UCHAR    Head, Sector;
  195.  
  196. {
  197.    return (ReadSecInScratch_RBA (pVolCB,
  198.                                  f_CHS_to_RBA (pVolCB, Cylinder, Head, Sector),
  199.                                  1));
  200. }
  201.  
  202.  
  203.  
  204.  
  205. /*------------------------------------------------------------------------
  206. ;
  207. ;** w_MediaCheck - Worker routine for Media Check
  208. ;
  209. ;   Checks to see if the media in the drive has changed.
  210. ;
  211. ;   USHORT w_MediaCheck   (UCHAR Unit, NPVOLCB pVolCB)
  212. ;
  213. ;   ENTRY:    Unit             - Logical Unit Number
  214. ;             pVolCB           - Pointer to VolCB
  215. ;
  216. ;   RETURN:   USHORT           - Media Change status as follows:
  217. ;                                   -1 = Media has been changed
  218. ;                                    0 = Unsure if media has been changed
  219. ;                                    1 = Media unchanged
  220. ;
  221. ------------------------------------------------------------------------*/
  222. USHORT w_MediaCheck (Unit, pVolCB)
  223.  
  224. UCHAR    Unit;
  225. NPVOLCB  pVolCB;
  226.  
  227. {
  228.    USHORT  ChangeState;
  229.    NPVOLCB pVolCBx;
  230.  
  231.    /* Not changed if fixed disk */
  232.  
  233.    if ( !(pVolCB->pUnitCB->UnitInfo.UnitFlags & UF_REMOVABLE) )
  234.       return (MEDIA_UNCHANGED);
  235.  
  236.    if ( (CheckPseudoChange(Unit, pVolCB) != 0) ||
  237.         (pVolCB->Flags & (vf_ChangedByFormat | vf_Changed)) )
  238.  
  239.       ChangeState = MEDIA_CHANGED;
  240.  
  241.    else
  242.    {
  243.       ChangeState = CheckChangeSignal (Unit, pVolCB);
  244.  
  245.       /* See if changeline support is there for this unit */
  246.  
  247.       if ( !(pVolCB->pUnitCB->UnitInfo.UnitFlags & UF_CHANGELINE) )
  248.       {
  249.          if (ChangeState != MEDIA_UNCHANGED)
  250.             ChangeState = MEDIA_UNSURE_CHANGED;
  251.       }
  252.       else
  253.  
  254.       /* Changeline is supported by the drive and the ChangeLine is not
  255.          active.  This does not mean that it was not triggered!!!!
  256.          It could be the case that it was high, but an access to the second
  257.          floppy drive turned it off (this was a problem reported during
  258.          DOS 3.20). We therefore check to see if this unit was the last
  259.          one accessed if we are on a system with a single floppy drive.
  260.          If it was, then we assume the medium has not changed.
  261.       */
  262.       {
  263.          if ( (ChangeState == MEDIA_UNCHANGED) && (NumRemovableDisks == 1) &&
  264.               (pVolCB->LogDriveNum <= 1) && (XActPDrv != pVolCB->LogDriveNum) )
  265.  
  266.               ChangeState = MEDIA_UNSURE_CHANGED;
  267.       }
  268.    }
  269.       /*
  270.          If the medium may have changed or has changed we note this in the
  271.          VolCB for later use. We *MUST* flag these changes in ALL the
  272.          logical drives that are mapped onto this physical drive.
  273.          We also inform the ROM that the medium may have changed.
  274.          This must be done so that it retries I/O on the medium with
  275.          different data rates, and does not assume a certain rate for
  276.          the particular drive. This is only done for physical drives
  277.          0 and 1 since the ROM only has data areas for these drives.
  278.       */
  279.  
  280.    if (ChangeState == MEDIA_CHANGED)
  281.       pVolCB->Flags &= ~(vf_ChangedByFormat | vf_Changed);
  282.  
  283.  
  284.    if (ChangeState != MEDIA_UNCHANGED)
  285.    {
  286.       for (pVolCBx = VolCB_Head; pVolCBx != NULL; pVolCBx = pVolCBx->pNextVolCB)
  287.       {
  288.          if (pVolCBx->PhysDriveNum == pVolCB->PhysDriveNum)
  289.             pVolCBx->Flags |= vf_UncertainMedia;
  290.       }
  291.    }
  292.  
  293.    return(ChangeState);
  294. }
  295. /*------------------------------------------------------------------------
  296. ;
  297. ;***    CheckPseudoChange - check for floppy pseudo drive change
  298. ;
  299. ;       The DOS/BIOS conspire so that on single-floppy-drive systems there
  300. ;       appear to be two floppy drives, "A" and "B".  The Bios keeps track
  301. ;       of which of these "pseudo drives" is currently active and if it
  302. ;       sees a request to the other drive causes the user to be prompted
  303. ;       to "insert drive ?? disk".
  304. ;
  305. ;       CheckPseudoChange is called when we're doing floppy I/O on a single
  306. ;       drive system.  It takes one of two actions:
  307. ;
  308. ;       1) the request is for the pseudo-drive thats active
  309. ;               - return no change required
  310. ;
  311. ;       2) the request is for the other pseodo-drive:
  312. ;               - Return disk change error to dos and let it map the
  313. ;                 the logical drive.
  314. ;
  315. ;   USHORT CheckPseudoChange (USHORT LogDriveNum, NPVOLCB pVolCB)
  316. ;
  317. ;   ENTRY:    LogDriveNum      - Logical Drive Number
  318. ;             pVolCB           - Pointer to VolCB
  319. ;
  320. ;   RETURN:   USHORT           - Pseudo drive status:
  321. ;                                   -1 = Pseudo drive must be changed
  322. ;                                    0 = Pseudo drive unchanged
  323. ;
  324. ------------------------------------------------------------------------*/
  325. USHORT FAR f_CheckPseudoChange (LogDriveNum, pVolCB)
  326.  
  327. USHORT  LogDriveNum;
  328. NPVOLCB pVolCB;
  329.  
  330. {
  331.    return(CheckPseudoChange (LogDriveNum, pVolCB));
  332. }
  333.  
  334. USHORT CheckPseudoChange (LogDriveNum, pVolCB)
  335.  
  336. USHORT  LogDriveNum;
  337. NPVOLCB pVolCB;
  338.  
  339. {
  340.    USHORT ChangeState;
  341.  
  342.    /* If not one of several logical drives or this unit not  */
  343.    /* mapped onto the physical drive then return unchanged   */
  344.  
  345.    if ( !(pVolCB->Flags & vf_AmMult) || (pVolCB->Flags & vf_OwnPhysical) )
  346.       ChangeState = 0;
  347.  
  348.    else if (NumRemovableDisks != 1)
  349.       ChangeState = -1;
  350.  
  351. /*
  352.  *  If we are trying to switch back to either the A: or the B: drive
  353.  *  and if neither of the drives A: or B: owns the physical device then
  354.  *  the device must be allocated to a EXTDSKDD.SYS device and we
  355.  *  cannot trust the ROMData to tell us which device owns the drive
  356.  *  because neither of the ActPDrv(s) own it!
  357.  */
  358.  
  359.    else if ( (LogDriveNum == 0 || LogDriveNum == 1) &&         /* If A: or B: */
  360.              !(VolCB_Head->Flags & vf_OwnPhysical) &&          /* A: owns ?   */
  361.              !(VolCB_Head->pNextVolCB->Flags & vf_OwnPhysical) )/* B: owns ?   */
  362.  
  363.         ChangeState = -1;
  364.  
  365.  
  366.    else if (XActPDrv == LogDriveNum)
  367.    {
  368.        Update_Owner (pVolCB);
  369.        ChangeState = 0;
  370.    }
  371.    else
  372.        ChangeState = -1;
  373.  
  374.   return (ChangeState);
  375. }
  376. /*------------------------------------------------------------------------
  377. ;
  378. ;** Update_Owner - Update the owner of the logical drive
  379. ;
  380. ;   Update_Owner maps the current drive onto the physical drive by
  381. ;   adjusting the vf_OwnPhysical flag bits in the approporiate VolCBs.
  382. ;   It also adjusts the ROMs data area.
  383. ;
  384. ;   VOID Update_Owner (NPVOLCB pVolCB)
  385. ;
  386. ;   ENTRY:    pVolCB           - Pointer to VolCB
  387. ;
  388. ;   RETURN:
  389. ;
  390. ------------------------------------------------------------------------*/
  391. VOID Update_Owner (pVolCB)
  392.  
  393. NPVOLCB pVolCB;
  394.  
  395. {
  396.    NPVOLCB pVolCBx;
  397.  
  398.    /* Reset vf_OwnPhysical for all VolCBs mapped onto this physical drive */
  399.  
  400.    for (pVolCBx = VolCB_Head; pVolCBx != NULL; pVolCBx = pVolCBx->pNextVolCB)
  401.  
  402.       if (pVolCB->PhysDriveNum == pVolCBx->PhysDriveNum)
  403.          pVolCBx->Flags &= ~vf_OwnPhysical;
  404.  
  405.  
  406.    /* Set ownership for this logical drive */
  407.  
  408.    pVolCB->Flags |= vf_OwnPhysical | vf_Changed;
  409.  
  410.  
  411.   if ( (NumRemovableDisks == 1) && (pVolCB->LogDriveNum <= 1) )
  412.      XActPDrv = pVolCB->LogDriveNum;
  413.  
  414. }
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422. /*------------------------------------------------------------------------
  423. ;
  424. ;** CheckChangeSignal - Check floppy change signal
  425. ;
  426. ;   Checks the floppy change signal.
  427. ;
  428. ;   USHORT CheckChangeSignal (USHORT LogDriveNum, NPVOLCB pVolCB)
  429. ;
  430. ;   ENTRY:    LogDriveNum      - Logical Drive Number
  431. ;             pVolCB           - Pointer to VolCB
  432. ;
  433. ;   RETURN:   USHORT           - Media Change status as follows:
  434. ;                                   -1 = Media has been changed
  435. ;                                    0 = Unsure if media has been changed
  436. ;                                    1 = Media unchanged
  437. ;
  438. ------------------------------------------------------------------------*/
  439. USHORT CheckChangeSignal (LogDriveNum, pVolCB)
  440.  
  441. USHORT   LogDriveNum;
  442. NPVOLCB  pVolCB;
  443.  
  444. {
  445.    USHORT ChangeState;
  446.    PRP_INTERNAL pIRP;
  447.  
  448.    if (DevHelp_AllocReqPacket(0, (PBYTE FAR *) &pIRP) != NO_ERROR)
  449.       return(STDON + STERR + ERROR_I24_GEN_FAILURE);
  450.  
  451.    pIRP->rph.Cmd = CMDInternal;
  452.    pIRP->rph.Unit = LogDriveNum;
  453.    pIRP->rph.Flags = RPF_Internal;
  454.    pIRP->Function = DISKOP_GET_CHANGELINE_STATE;
  455.  
  456.    DiskIO_Wait( (PBYTE)pIRP, pVolCB);
  457.  
  458.    if (pIRP->rph.Status & STERR)
  459.       ChangeState = MEDIA_UNSURE_CHANGED;
  460.    else
  461.    {
  462.       if (pIRP->RetStatus & US_CHANGELINE_ACTIVE)
  463.          ChangeState = MEDIA_CHANGED;
  464.       else
  465.          ChangeState = MEDIA_UNCHANGED;
  466.    }
  467.  
  468.    DevHelp_FreeReqPacket((PBYTE)pIRP);        /* Free internal RP   */
  469.  
  470.    return(ChangeState);
  471.  
  472. }
  473.  
  474. /*------------------------------------------------------------------------
  475. ;
  476. ;** CheckWithinPartition - Check I/O falls within partition limits
  477. ;
  478. ;   Verifies I/O fails within parition limits.
  479. ;
  480. ;   USHORT CheckWithinPartition (NPVOLCB pVolCB, ULONG rba, ULONG NumSectors)
  481. ;
  482. ;   ENTRY:    pVolCB           - Pointer to VolCB
  483. ;             rba              - rba
  484. ;             NumSectors       - Number of sectors to transfer
  485. ;
  486. ;   RETURN:   USHORT           - Packet status word
  487. ;
  488. ------------------------------------------------------------------------*/
  489. USHORT CheckWithinPartition (pVolCB, rba, NumSectors)
  490.  
  491. NPVOLCB pVolCB;
  492. ULONG   rba;
  493. ULONG   NumSectors;
  494.  
  495. {
  496.    ULONG EndSector;
  497.  
  498.    /* Check for a valid partition */
  499.  
  500.    if (pVolCB->Flags & (vf_TooBig | vf_NoDOSPartition))
  501.       return(STDON + STERR + ERROR_I24_SECTOR_NOT_FOUND);
  502.  
  503.    /* Make sure I/O doesnt go beyond end of partition */
  504.  
  505.    if ( (EndSector = f_add32 (rba, NumSectors)) == 0)
  506.       return(STDON + STERR + ERROR_I24_SECTOR_NOT_FOUND);
  507.  
  508.    if (pVolCB->MediaBPB.TotalSectors != 0)
  509.    {
  510.       if (EndSector > pVolCB->MediaBPB.TotalSectors)
  511.           return(STDON + STERR + ERROR_I24_SECTOR_NOT_FOUND);
  512.    }
  513.    else
  514.    {
  515.       if (EndSector > pVolCB->MediaBPB.BigTotalSectors)
  516.           return(STDON + STERR + ERROR_I24_SECTOR_NOT_FOUND);
  517.    }
  518.    return(STDON);
  519. }
  520.  
  521. /*------------------------------------------------------------------------
  522. ;
  523. ;** CHS_to_RBA - Convert Cylinder, Head, Sector to RBA
  524. ;
  525. ;   Converts a Cylinder/Head/Sector address to a double word
  526. ;   Relative Block Address using this formula:
  527. ;
  528. ;   RBA = (((Cylinder * NumHeads) + Head) * SectorsPerTrack) + (Sector - 1)
  529. ;
  530. ;   ULONG  NEAR CHS_to_RBA   (NPVOLCB pVolCB, USHORT Cylinder,
  531. ;                             UCHAR Head, UCHAR Sector)
  532. ;
  533. ;   ULONG  FAR  f_CHS_to_RBA (NPVOLCB pVolCB, USHORT Cylinder,
  534. ;                             UCHAR Head, UCHAR Sector)
  535. ;
  536. ;   ENTRY:    pVolCB           - VolCB entry for the device
  537. ;             Cylinder         - Cylinder
  538. ;             Head             - Head
  539. ;             Sector           - Sector
  540. ;
  541. ;   RETURN:   ULONG            - rba
  542. ;
  543. ;   EFFECTS:
  544. ;
  545. ;   NOTES:
  546. ------------------------------------------------------------------------*/
  547.  
  548. ULONG FAR f_CHS_to_RBA (pVolCB, Cylinder, Head, Sector)
  549.  
  550. NPVOLCB   pVolCB;
  551. USHORT    Cylinder;
  552. UCHAR     Head;
  553. UCHAR     Sector;
  554. {
  555.    return(CHS_to_RBA (pVolCB, Cylinder, Head, Sector));
  556. }
  557.  
  558. ULONG CHS_to_RBA (pVolCB, Cylinder, Head, Sector)
  559.  
  560. NPVOLCB   pVolCB;
  561. USHORT    Cylinder;
  562. UCHAR     Head;
  563. UCHAR     Sector;
  564. {
  565.   ULONG rba;
  566.  
  567.   rba = (((((ULONG) Cylinder * pVolCB->MediaBPB.NumHeads) + Head) *
  568.             pVolCB->MediaBPB.SectorsPerTrack) + Sector - 1);
  569.  
  570.   return (rba);
  571. }
  572.  
  573.  
  574. /*------------------------------------------------------------------------
  575. ;
  576. ;** MapIORBError - Maps an IORB error code to an ERROR_I24 error code.
  577. ;
  578. ;   Maps an IORB error code to an ERROR_I24 error code.
  579. ;
  580. ;   UCHAR  MapIORBError (USHORT IORBErrorCode)
  581. ;
  582. ;   ENTRY:    IORBError        - IORB error code
  583. ;
  584. ;   RETURN:   UCHAR            - ERROR_I24 error code
  585. ;
  586. ------------------------------------------------------------------------*/
  587. typedef struct _ERROR_TABLE_ENTRY
  588. {
  589.    USHORT   IORB_ErrorCode;
  590.    UCHAR    I24_ErrorCode;
  591. } ERROR_TABLE_ENTRY;
  592.  
  593.  
  594. UCHAR MapIORBError(IORB_ErrorCode)
  595.  
  596. USHORT IORB_ErrorCode;
  597.  
  598. {
  599.    static ERROR_TABLE_ENTRY ErrorTable[] =
  600.    {
  601.       {IOERR_UNIT_NOT_READY,        ERROR_I24_NOT_READY},
  602.       {IOERR_RBA_ADDRESSING_ERROR,  ERROR_I24_SECTOR_NOT_FOUND},
  603.       {IOERR_RBA_LIMIT,             ERROR_I24_SECTOR_NOT_FOUND},
  604.       {IOERR_RBA_CRC_ERROR,         ERROR_I24_CRC},
  605.       {IOERR_MEDIA_NOT_FORMATTED,   ERROR_I24_SECTOR_NOT_FOUND},
  606.       {IOERR_MEDIA_NOT_SUPPORTED,   ERROR_I24_SECTOR_NOT_FOUND},
  607.       {IOERR_MEDIA_WRITE_PROTECT,   ERROR_I24_WRITE_PROTECT},
  608.       {IOERR_MEDIA_CHANGED,         ERROR_I24_UNCERTAIN_MEDIA},
  609.       {IOERR_MEDIA_NOT_PRESENT,     ERROR_I24_NOT_READY},
  610.       {-1,-1},
  611.    };
  612.  
  613.    USHORT i;
  614.  
  615.    /* Map the IORB error to the corresponding ERROR_I24 error code */
  616.  
  617.    for (i = 0; ErrorTable[i].IORB_ErrorCode != -1; i++)
  618.      if (ErrorTable[i].IORB_ErrorCode == IORB_ErrorCode)
  619.         return(ErrorTable[i].I24_ErrorCode);
  620.  
  621.    return(ERROR_I24_GEN_FAILURE);
  622. }
  623.  
  624.  
  625. /*------------------------------------------------------------------------
  626. ;
  627. ;** VirtToPhys - Convert a virtual to physical address
  628. ;
  629. ;   Convert a virtual to a physical address.  This routine does
  630. ;   not use DevHlp_VirtToPhys since that devhlp is not callable
  631. ;   at interrupt time.
  632. ;
  633. ;   ULONG  VirtToPhys  (PBYTE VirtAddr)
  634. ;
  635. ;   ENTRY:    VirtAddr         - 16:16 virutal address
  636. ;
  637. ;   RETURN:   ULONG            - 32 bit phys address
  638. ;
  639. ------------------------------------------------------------------------*/
  640. ULONG FAR f_VirtToPhys (VirtAddr)
  641.  
  642. PBYTE VirtAddr;
  643. {
  644.    return(VirtToPhys (VirtAddr));
  645. }
  646.  
  647.  
  648. ULONG VirtToPhys (VirtAddr)
  649.  
  650. PBYTE VirtAddr;
  651.  
  652. {
  653.   USHORT rc;
  654.   SCATGATENTRY ScatGatEntry;
  655.   ULONG VirtLinAddr;
  656.   ULONG ScatLinAddr;
  657.   ULONG PageListCount;
  658.  
  659.   rc = DevHelp_VirtToLin((USHORT) (SELECTOROF(VirtAddr)),
  660.                          (ULONG) (OFFSETOF(VirtAddr)),
  661.                          (PLIN) &VirtLinAddr);
  662.  
  663.   rc = DevHelp_VirtToLin((USHORT) ( ((ULONG)((PVOID) &ScatGatEntry)) >> 16),
  664.                          (ULONG)  ( (USHORT)((PVOID) &ScatGatEntry)),
  665.                          (PLIN) &ScatLinAddr);
  666.  
  667.   rc = DevHelp_LinToPageList(VirtLinAddr, 1, ScatLinAddr,
  668.                                              (PULONG) &PageListCount);
  669.  
  670.   return(ScatGatEntry.ppXferBuf);
  671.  
  672. }
  673.  
  674.  
  675.  
  676.  
  677.  
  678. USHORT PowerOf2 (value)
  679.  
  680. UCHAR  value;
  681. {
  682.    if (value == 0)
  683.       return(0);
  684.    else
  685.       return(1);
  686. }
  687.  
  688.  
  689.