home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / DASD / OS2DASD / DMSTRAT1.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-14  |  23.0 KB  |  798 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/dmstrat1.c, dsdm, ddk_subset, b_bdd.032 93/11/24";*/
  13. #define SCCSID  "src/dev/dasd/os2dasd/dmstrat1.c, dsdm, ddk_subset, b_bdd.032 93/11/24"
  14.  
  15. /**************************************************************************
  16.  *
  17.  * SOURCE FILE NAME = DMSTRAT1.C
  18.  *
  19.  * DESCRIPTIVE NAME = OS2DASD.DMD - OS/2 DASD Device Manager
  20.  *                    Strategy 1 interface for OS/2 DASD Manager
  21.  *
  22.  *
  23.  * VERSION = V2.0
  24.  *
  25.  * DATE
  26.  *
  27.  * DESCRIPTION   Provides validation and routing of Strategy 1 requests
  28.  *               received from the OS/2 Kernel.
  29.  *
  30.  *
  31. */
  32. #include "dmh.h"
  33. #include "dmfault.h"
  34.  
  35. USHORT (near *Strat1Near[])() =
  36. {                     /*--------------------------------------*/
  37.    CmdErr,            /* 0x00  now an error                   */
  38.    MediaCheck,        /* 0x01  check the media                */
  39.    BuildBPB,          /* 0x02  build BPB                      */
  40.    CmdErr,            /* 0x03  reserved                       */
  41.    ReadWriteV,        /* 0x04  read                           */
  42.    StatusDevReady,    /* 0x05  non-destructive read           */
  43.    StatusComplete,    /* 0x06  input status                   */
  44.    StatusComplete,    /* 0x07  input flush                    */
  45.    ReadWriteV,        /* 0x08  write                          */
  46.    ReadWriteV,        /* 0x09  write with verify              */
  47.    CmdErr,            /* 0x0A  get output status              */
  48.    CmdErr,            /* 0x0B  flush output                   */
  49.    CmdErr,            /* 0x0C  reserved                       */
  50.    StatusComplete,    /* 0x0D  open                           */
  51.    StatusComplete,    /* 0x0E  close                          */
  52.    RemovableMedia,    /* 0x0F  removable media                */
  53.    DriveGenIOCTL,     /* 0x10  generic IOCTL                  */
  54.    ResetMedia,        /* 0x11  reset uncertain media          */
  55.    GetLogDriveMap,    /* 0x12  get Logical Drive Map          */
  56.    SetLogDriveMap,    /* 0x13  set Logical Drive Map          */
  57.    CmdErr,            /* 0x14  de-Install this device         */
  58.    CmdErr,            /* 0x15  reserved                       */
  59.    PartFixedDisks,    /* 0x16  get number of partitions       */
  60.    GetUnitMap,        /* 0x17  get unit map                   */
  61.    ReadWriteV,        /* 0x18  no caching read                */
  62.    ReadWriteV,        /* 0x19  no caching write               */
  63.    ReadWriteV,        /* 0x1A  no caching write/verify        */
  64.    DriveInit,         /* 0x1B  initialize                     */
  65.    CmdErr,            /* 0x1C  reserved for Request List code */
  66.    GetDriverCaps      /* 0x1D  Get Driver Capabilities        */
  67. };                    /*--------------------------------------*/
  68.  
  69. void near DMStrat1()
  70. {
  71.   PRPH          pRPH;
  72.   NPVOLCB       pVolCB;
  73.   USHORT        Cmd, Status;
  74.  
  75.   _asm
  76.   {
  77.      push es
  78.      push bx
  79.      mov word ptr pRPH[0], bx
  80.      mov word ptr pRPH[2], es
  81.   }
  82.  
  83.   pRPH->Status = 0;
  84.   pRPH->Flags = 0;
  85.  
  86.   Cmd = pRPH->Cmd;
  87.  
  88.   /*-----------------------------*/
  89.   /* Filter out invalid requests */
  90.   /*-----------------------------*/
  91.  
  92.   if (DDFlags & DDF_NO_MEDIA)
  93.   {
  94.       Status = STDON + STERR + ERROR_I24_BAD_UNIT;
  95.       goto ExitDiskDD;
  96.   }
  97.  
  98.   if (Cmd > MAX_DISKDD_CMD)
  99.   {
  100.      Status = STDON + STERR + ERROR_I24_BAD_COMMAND;
  101.      goto  ExitDiskDD;
  102.   }
  103.  
  104.   if ( (Get_VolCB_Addr(pRPH->Unit, (NPVOLCB FAR *) &pVolCB) != NO_ERROR) &&
  105.                      (Cmd != CMDGenIOCTL) &&
  106.                      (Cmd != CMDInitBase) &&
  107.                      (Cmd != CMDPartfixeddisks) )
  108.   {
  109.       Status = STDON + STERR + ERROR_I24_BAD_UNIT;
  110.       goto ExitDiskDD;
  111.   }
  112.  
  113.   if ( (Cmd != CMDInitBase) && IsTraceOn() )
  114.         Trace(TRACE_STRAT1 | TRACE_ENTRY, (PBYTE) pRPH, pVolCB);
  115.  
  116.   /*---------------------*/
  117.   /* Call Worker Routine */
  118.   /*---------------------*/
  119.  
  120.   Status = (*Strat1Near[Cmd])(pRPH, pVolCB);
  121.  
  122.   /*--------------------------------------------------------------------*/
  123.   /* Finish up by setting the Status word in the Request Packet Header  */
  124.   /*--------------------------------------------------------------------*/
  125.  
  126. ExitDiskDD:  ;
  127.  
  128.   DISABLE;
  129.  
  130.   pRPH->Status = Status;             /* Save status in Request Packet */
  131.  
  132.   ENABLE;
  133.  
  134.   if ( (TraceFlags != 0) && (pRPH->Status & STDON) && (Cmd != CMDInitBase) )
  135.      Trace(TRACE_STRAT1 | TRACE_EXIT, (PBYTE) pRPH, pVolCB);
  136.  
  137.  
  138.   _asm
  139.   {
  140.      pop bx
  141.      pop es
  142.   }
  143. DMStrat1_Exit:
  144.   _asm
  145.   {
  146.      LEAVE
  147.      retf
  148.   }
  149.  
  150. }
  151.  
  152. /*------------------------------------------------------------------------
  153. ;
  154. ;** MediaCheck - Check the Media    (Command = 0x01)
  155. ;
  156. ;   Checks to see if the media in the drive has changed.
  157. ;
  158. ;   USHORT MediaCheck   (PRP_MEDIACHECK pRP, NPVOLCB pVolCB)
  159. ;
  160. ;   ENTRY:    pRP              - Request Packet
  161. ;             pVolCB           - Pointer to VolCB
  162. ;
  163. ;   RETURN:   USHORT           - Packet Status word
  164. ;
  165. ;   EFFECTS:  The Return Code in the Request Packet is set to one
  166. ;             of the following:
  167. ;
  168. ;                 -1 = Media has been changed
  169. ;                  0 = Unsure if media has been changed
  170. ;                  1 = Media unchanged
  171. ;
  172. ------------------------------------------------------------------------*/
  173. USHORT NEAR MediaCheck(pRP, pVolCB)
  174.  
  175. PRP_MEDIACHECK    pRP;
  176. NPVOLCB           pVolCB;
  177. {
  178.  
  179.    if (pVolCB->Flags & vf_UncertainMedia)
  180.       pRP->rc = -1;
  181.    else
  182.       pRP->rc = w_MediaCheck (pRP->rph.Unit, pVolCB);
  183.  
  184.    return (pRP->rph.Status | STDON);
  185. }
  186.  
  187. /*------------------------------------------------------------------------
  188. ;
  189. ;** BuildBPB - Build the BPB      (Command = 0x02)
  190. ;
  191. ;   Builds the BPB.  This is requested when the media has changed
  192. ;   of when the media type is uncertain.
  193. ;
  194. ;   USHORT BuildBPB   (PRP_BUILDBPB pRP, NPVOLCB pVolCB)
  195. ;
  196. ;   ENTRY:    pRP              - Request Packet
  197. ;             pVolCB           - Pointer to VolCB
  198. ;
  199. ;   RETURN:   USHORT           - Packet status word
  200. ;
  201. ;   EFFECTS:
  202. ;
  203. ------------------------------------------------------------------------*/
  204. USHORT near BuildBPB(pRP, pVolCB)
  205. PRP_BUILDBPB   pRP;
  206. NPVOLCB        pVolCB;
  207. {
  208.    USHORT rc;
  209.  
  210.    if ((rc = BPBFromBoot (pVolCB, (PDOSBOOTREC) pRP->XferAddr)) != NO_ERROR)
  211.       rc = BPBFromScratch (pVolCB);
  212.  
  213.    if (rc == NO_ERROR)
  214.    {
  215.  
  216.       pRP->MediaDescr = pVolCB->MediaBPB.MediaType;
  217.       pRP->bpb = (PVOID) &(pVolCB->MediaBPB);
  218.  
  219.       /* If removable media and sectors <= 2.88 M        */
  220.       /* then issue SET_LOGICAL_GEOMETRY call to ADD.    */
  221.  
  222.       if ( (pVolCB->pUnitCB->UnitInfo.UnitFlags & UF_REMOVABLE) &&
  223.            (pVolCB->MediaBPB.TotalSectors <= 5760) &&
  224.            (pVolCB->MediaBPB.TotalSectors != 0) &&
  225.            ( !(pVolCB->Flags & vf_ReturnFakeBPB) ) )
  226.       {
  227.         if (pVolCB->MediaBPB.TotalSectors <= 720)
  228.             pVolCB->NumLogCylinders = 40;
  229.         else
  230.             pVolCB->NumLogCylinders = 80;
  231.  
  232.         rc = SetLogicalGeometry (pVolCB);
  233.       }
  234.       rc |= STDON;
  235.    }
  236.    else
  237.       rc |= (STDON | STERR);
  238.  
  239.    return (rc);
  240. }
  241. /*------------------------------------------------------------------------
  242. ;
  243. ;** SetLogicalGeometry - Set Logical Geometry
  244. ;
  245. ;   Sets the logical geometry for the specified media BPB.
  246. ;
  247. ;   USHORT SetLogicalGeometry  (NPVOLCB pVolCB)
  248. ;
  249. ;   ENTRY:    pVolCB           - Pointer to VolCB
  250. ;
  251. ;   RETURN:   USHORT           - Packet status word
  252. ;
  253. ;   EFFECTS:
  254. ;
  255. ------------------------------------------------------------------------*/
  256. USHORT FAR f_SetLogicalGeometry (pVolCB)
  257.  
  258. NPVOLCB pVolCB;
  259. {
  260.    return(SetLogicalGeometry(pVolCB));
  261. }
  262.  
  263.  
  264. USHORT SetLogicalGeometry (pVolCB)
  265.  
  266. NPVOLCB pVolCB;
  267. {
  268.      PRP_INTERNAL pIRP;
  269.      USHORT rc;
  270.  
  271.      if (DevHelp_AllocReqPacket(0, (PBYTE FAR *) &pIRP) != NO_ERROR)
  272.          return(STDON + STERR + ERROR_I24_GEN_FAILURE);
  273.  
  274.      pIRP->rph.Unit = pVolCB->LogDriveNum;
  275.      pIRP->rph.Flags = RPF_Internal;
  276.      pIRP->rph.Cmd = CMDInternal;
  277.      pIRP->Function = DISKOP_GET_MEDIA_GEOMETRY;
  278.      pIRP->NumSectors = (USHORT) pVolCB;
  279.      rc = DiskIO_Wait ( (PBYTE)pIRP, pVolCB );
  280.  
  281.  
  282.      if ( !(rc & STERR) &&
  283.         (pIRP->NumSectors != pVolCB->MediaBPB.TotalSectors) )
  284.      {
  285.         pIRP->Function = DISKOP_SET_LOGICAL_GEOMETRY;
  286.         pIRP->NumSectors = (USHORT) pVolCB;
  287.         rc = DiskIO_Wait ( (PBYTE)pIRP, pVolCB );
  288.      }
  289.  
  290.      DevHelp_FreeReqPacket( (PBYTE)pIRP );
  291.  
  292.      return(rc);
  293. }
  294.  
  295.  
  296. /*------------------------------------------------------------------------
  297. ;
  298. ;** ReadWriteV - Read, Write and Write with Verify  (Commands 0x04, 0x08, 0x09)
  299. ;
  300. ;   These are the basic strategy-1 I/O routines for the driver.
  301. ;   The request is queued and sent to the adapter driver for
  302. ;   processing.
  303. ;
  304. ;   USHORT ReadWriteV   (PRP_RWV pRP, NPVOLCB pVolCB)
  305. ;
  306. ;   ENTRY:    pRP              - Request Packet
  307. ;             pVolCB           - Pointer to VolCB
  308. ;
  309. ;   RETURN:   USHORT           - Packet Status word
  310. ;
  311. ;   EFFECTS:
  312. ;
  313. ------------------------------------------------------------------------*/
  314. USHORT ReadWriteV (pRP, pVolCB)
  315.  
  316. PRP_RWV   pRP;
  317. NPVOLCB   pVolCB;
  318. {
  319.    USHORT Uncertain;
  320.    ULONG  EndSector;
  321.  
  322.    USHORT rc = NO_ERROR;
  323.  
  324.    if (pRP->NumSectors == 0)
  325.       return (STDON);
  326.  
  327.    /* Check for a valid partition */
  328.  
  329.    if ((rc=CheckWithinPartition(pVolCB,pRP->rba,(ULONG)pRP->NumSectors)) & STERR)
  330.       return(rc);
  331.  
  332.    /*--------------------------------------------------------------*/
  333.    /*  If it's for a psuedo-drive which is not currently mapped to */
  334.    /*  it's associated unit, then a disk swap is needed.           */
  335.    /*--------------------------------------------------------------*/
  336.  
  337.    if  (pVolCB->pUnitCB->UnitInfo.UnitFlags & UF_REMOVABLE)
  338.    {
  339.       if (CheckPseudoChange(pRP->rph.Unit, pVolCB) == -1)
  340.       {
  341.          pRP->NumSectors = 0;
  342.          return(STDON + STERR + ERROR_I24_DISK_CHANGE);
  343.       }
  344.  
  345.       if ( (!(pVolCB->Flags & vf_ForceRdWrt)) &&
  346.              (pVolCB->Flags & vf_UncertainMedia))
  347.       {
  348.          pRP->NumSectors = 0;
  349.          return(STDON + STERR + ERROR_I24_UNCERTAIN_MEDIA);
  350.       }
  351.    }
  352.    /*  Add in the partition offset and the hidden sectors and do the I/O */
  353.  
  354.    pRP->rba = pRP->rba + pVolCB->PartitionOffset+pVolCB->MediaBPB.HiddenSectors;
  355.    pRP->sfn = 512;                      /* Use sfn field for sector size */
  356.    pVolCB->Flags &= ~vf_ForceRdWrt;
  357.  
  358.  
  359.    rc =  DiskIO ((PBYTE)pRP, pVolCB);
  360.  
  361.    return(rc);
  362.  
  363. }
  364. /*------------------------------------------------------------------------
  365. ;
  366. ;** RemovableMedia - Check for Removable Media    (Command = 0x0F)
  367. ;
  368. ;   USHORT RemovableMedia (PRPH pRPH, NPVOLCB pVolCB)
  369. ;
  370. ;   ENTRY:    pRPH             - Request Packet Header
  371. ;             pVolCB           - Pointer to VolCB
  372. ;
  373. ;   RETURN:   USHORT           - Packet Status word
  374. ;
  375. ;   EFFECTS:  The busy bit of the status word is set as follows:
  376. ;
  377. ;                  1 = Media is non-removable
  378. ;                  0 = Media is removable
  379. ;
  380. ------------------------------------------------------------------------*/
  381.  
  382. USHORT RemovableMedia(pRPH, pVolCB)
  383. PRPH    pRPH;
  384. NPVOLCB pVolCB;
  385. {
  386.    if (pVolCB->pUnitCB->UnitInfo.UnitFlags & UF_REMOVABLE)
  387.       return (STDON);
  388.    else
  389.       return (STDON + STBUI);
  390.  
  391. }
  392.  
  393. /*------------------------------------------------------------------------
  394. ;
  395. ;** ResetMedia - Reset Uncertain Media  (Command = 0x11)
  396. ;
  397. ;   USHORT ResetMedia (PRPH pRPH, NPVOLCB pVolCB)
  398. ;
  399. ;   ENTRY:    pRPH             - Request Packet Header
  400. ;             pVolCB           - Pointer to VolCB
  401. ;
  402. ;   RETURN:   USHORT           - Packet Status word
  403. ;
  404. ;   EFFECTS:
  405. ;
  406. ------------------------------------------------------------------------*/
  407.  
  408. USHORT ResetMedia (pRPH, pVolCB)
  409.  
  410. PRPH    pRPH;
  411. NPVOLCB pVolCB;
  412. {
  413.   if ( !(pVolCB->Flags & vf_ReturnFakeBPB) )
  414.      pVolCB->MediaBPB = pVolCB->RecBPB;
  415.  
  416.   pVolCB->Flags &= ~(vf_UncertainMedia | vf_ChangedByFormat | vf_Changed);
  417.  
  418.   pVolCB->Flags |= vf_ForceRdWrt;
  419.  
  420.   return (STDON);
  421.  
  422. }
  423. /*------------------------------------------------------------------------
  424. ;
  425. ;** GetLogDriveMap - Get Logical Drive Mapping  (Command = 0x12)
  426. ;
  427. ;   Returns which logical drive is currently mapped onto a particular
  428. ;   physical drive.  A zero is returned if only one logical drive is
  429. ;   mapped to the physical drive.
  430. ;
  431. ;   USHORT GetLogDriveMap (PRPH pRPH, NPVOLCB pVolCBIn)
  432. ;
  433. ;   ENTRY:    pRPH             - Request Packet Header
  434. ;             pVolCBIn         - Pointer to VolCB
  435. ;
  436. ;   RETURN:   USHORT           - Packet Status word
  437. ;
  438. ;   EFFECTS: The logical drive is returned in the unit field
  439. ;            of the request packet header.  The logical drive
  440. ;            is actually LogDriveNum + 1, which represents the
  441. ;            drive letter, i.e. C: = 3.  A zero is returned
  442. ;            if only one logical drive is mapped to the physical drive.
  443. ;
  444. ------------------------------------------------------------------------*/
  445.  
  446. USHORT GetLogDriveMap (pRPH, pVolCB)
  447.  
  448. PRPH    pRPH;
  449. NPVOLCB pVolCB;
  450. {
  451.    NPVOLCB pVolCBx;
  452.  
  453.    for (pVolCBx = VolCB_Head; pVolCBx != NULL; pVolCBx = pVolCBx->pNextVolCB)
  454.    {
  455.       if ( (pVolCBx->pUnitCB->PhysDriveNum == pVolCB->pUnitCB->PhysDriveNum) &&
  456.            (pVolCBx->Flags & vf_OwnPhysical) )
  457.          break;
  458.    }
  459.  
  460.    if (pVolCBx == NULL)
  461.       return (STDON + STERR + ERROR_I24_BAD_UNIT);  /* Unit not found */
  462.  
  463.    if (pVolCBx->Flags & vf_AmMult)
  464.       pRPH->Unit = pVolCBx->LogDriveNum + 1;  /* ret drive letter value */
  465.    else
  466.       pRPH->Unit = 0;                        /* ret 0 if one drive mapped */
  467.  
  468.    return (STDON);
  469.  
  470. }
  471. /*------------------------------------------------------------------------
  472. ;
  473. ;** SetLogDriveMap - Set Logical Drive Mapping  (Command = 0x13)
  474. ;
  475. ;   Maps the specified logical drive onto the physical drive.
  476. ;
  477. ;   USHORT SetLogDriveMap (PRPH pRPH, NPVOLCB pVolCB)
  478. ;
  479. ;   ENTRY:    pRPH             - Request Packet Header
  480. ;             pVolCB           - Pointer to VolCB
  481. ;
  482. ;   RETURN:   USHORT           - Packet Status word
  483. ;
  484. ;   EFFECTS: The logical drive is returned in the unit field
  485. ;            of the request packet header.  The logical drive
  486. ;            is actually LogDriveNum + 1, which represents the
  487. ;            drive letter, i.e. C: = 3.  A zero is returned
  488. ;            if only one logical drive is mapped to the physical drive.
  489. ;
  490. ------------------------------------------------------------------------*/
  491.  
  492. USHORT SetLogDriveMap (pRPH, pVolCB)
  493.  
  494. PRPH    pRPH;
  495. NPVOLCB pVolCB;
  496. {
  497.    Update_Owner (pVolCB);                    /* Update vf_OwnPhysical */
  498.  
  499.    if (pVolCB->Flags & vf_AmMult)
  500.       pRPH->Unit = pVolCB->LogDriveNum + 1;   /* If mapped, ret drive letter */
  501.    else
  502.       pRPH->Unit = 0;                         /* else ret 0 */
  503.  
  504.    return (STDON);
  505. }
  506.  
  507.  
  508. /*------------------------------------------------------------------------
  509. ;
  510. ;** PartFixedDisks - Get number of fixed disks  (Command = 0x16)
  511. ;
  512. ;   Returns the number of fixed disks supported by the driver.
  513. ;
  514. ;   USHORT PartFixedDisks (PRP_PARTFIXEDDISKS pRP, NPVOLCB pVolCB)
  515. ;
  516. ;   ENTRY:    pRP              - Request Packet
  517. ;             pVolCB           - Pointer to VolCB
  518. ;
  519. ;   RETURN:   USHORT           - Packet Status word
  520. ;
  521. ;   EFFECTS:
  522. ;
  523. ------------------------------------------------------------------------*/
  524.  
  525. USHORT PartFixedDisks (pRP, pVolCB)
  526.  
  527. PRP_PARTFIXEDDISKS  pRP;
  528. NPVOLCB             pVolCB;
  529. {
  530.    pRP->NumFixedDisks = (UCHAR) NumFixedDisks;
  531.  
  532.    return (STDON);
  533. }
  534.  
  535. /*------------------------------------------------------------------------
  536. ;
  537. ;** GetUnitMap - Get logical units mapped to a physical unit (Command = 0x17)
  538. ;
  539. ;   Looks at all the VolCB entries and builds a double
  540. ;   word bit map that indicates what logical drives exist
  541. ;   on the given physical drive.  The low order bit of the
  542. ;   map corresponds to logical unit 0 (A:).  Bits are set for
  543. ;   those units that exist on the given physical drive.
  544. ;
  545. ;   USHORT GetUnitMap (PRP_GETUNITMAP pRP, NPVOLCB pVolCB)
  546. ;
  547. ;   ENTRY:    pRP              - Request Packet
  548. ;             pVolCB           - Pointer to VolCB
  549. ;
  550. ;   RETURN:   USHORT           - Packet Status word
  551. ;
  552. ;   EFFECTS:
  553. ;
  554. ------------------------------------------------------------------------*/
  555.  
  556. USHORT GetUnitMap (pRP, pVOLCB)
  557.  
  558. PRP_GETUNITMAP  pRP;
  559. NPVOLCB         pVOLCB;
  560. {
  561.    NPVOLCB pVolCBx;
  562.    UCHAR   PhysUnit;
  563.    ULONG   Mask = 1;
  564.    ULONG   UnitMap = 0;
  565.  
  566.    if (NumFixedDisks == 0 || pRP->rph.Unit >= NumFixedDisks)
  567.       return (STDON + STERR + ERROR_I24_BAD_UNIT);
  568.  
  569.    PhysUnit = pRP->rph.Unit | 0x80;         /* Make disk 0x80 based */
  570.  
  571.    for (pVolCBx=VolCB_Head; pVolCBx->LogDriveNum != 0x80;
  572.                                                  pVolCBx=pVolCBx->pNextVolCB)
  573.    {
  574.       /* Unit on specified drive ? */
  575.  
  576.       if (pVolCBx->pUnitCB->PhysDriveNum == PhysUnit)
  577.         UnitMap |= Mask;
  578.  
  579.       Mask <<= 1;                      /* Adjust mask for next unit */
  580.    }
  581.  
  582.    pRP->UnitMap = UnitMap;             /* Return unit mask */
  583.  
  584.    return (STDON);
  585. }
  586.  
  587.  
  588. /*------------------------------------------------------------------------
  589. ;
  590. ;** GetDriverCapabilites - Get Device Driver Capabilities  (Command = 0x1D)
  591. ;
  592. ;   Returns informations describing the functional characteristics
  593. ;   of the device driver.  The control blocks returned are the
  594. ;   Driver Capabilites Structure and the Volume Characteristics
  595. ;   structure.  This command must be supported to support the
  596. ;   Strategy-2, extended device driver interface.
  597. ;
  598. ;   USHORT GetUnitMap (PRP_GETDRIVERCAPS pRP, NPVOLCB pVolCB)
  599. ;
  600. ;   ENTRY:    pRP              - Request Packet
  601. ;             pVolCB           - Pointer to VolCB
  602. ;
  603. ;   RETURN:   USHORT           - Packet Status word
  604. ;
  605. ;   EFFECTS:
  606. ;
  607. ------------------------------------------------------------------------*/
  608.  
  609. USHORT GetDriverCaps (pRP, pVolCB)
  610.  
  611. PRP_GETDRIVERCAPS  pRP;
  612. NPVOLCB            pVolCB;
  613. {
  614.    pRP->pDCS = (PVOID) &DriverCapabilities;
  615.    pRP->pVCS = (PVOID) pVolCB->pVolChar;
  616.    return (STDON);
  617. }
  618.  
  619. /*-----------------------------------------------*/
  620. /* Near Entry Point to swappable IOCTL routine.  */
  621. /*-----------------------------------------------*/
  622.  
  623. USHORT DriveGenIOCTL(pRP, pVolCB)
  624.  
  625. PRP_GENIOCTL pRP;
  626. NPVOLCB      pVolCB;
  627. {
  628.   USHORT rc;
  629.  
  630.   rc = f_DriveGenIOCTL (pRP, pVolCB);
  631.  
  632.   rc |= STDON;
  633.  
  634.   return(rc);
  635.  
  636. }
  637.  
  638.  
  639. /*-----------------------------------------------------------*/
  640. /*   Packet Status return functions:                         */
  641. /*                                                           */
  642. /*   CmdErr, StatusError, StatusDevReady, StatusComplete     */
  643. /*-----------------------------------------------------------*/
  644.  
  645. USHORT near CmdErr (pRPH, pVolCB)
  646. PRPH    pRPH;
  647. NPVOLCB pVolCB;
  648. {
  649.    return (STERR + STDON + ERROR_I24_BAD_COMMAND);
  650. }
  651.  
  652.  
  653. USHORT StatusDevReady(pRPH, pVolCB)
  654. PRPH    pRPH;
  655. NPVOLCB pVolCB;
  656. {
  657.   return (STDON + STBUI);
  658. }
  659.  
  660. USHORT StatusComplete(pRPH, pVolCB)
  661. PRPH    pRPH;
  662. NPVOLCB pVolCB;
  663. {
  664.   return (STDON);
  665. }
  666.  
  667.  
  668. USHORT StatusError( pRPH, ErrorCode )
  669.  
  670. PRPH    pRPH;
  671. USHORT  ErrorCode;
  672. {
  673.   return (STDON + STERR);
  674. }
  675.  
  676.  
  677. /*------------------------------------------------------------------------
  678. ;
  679. ;** DiskIO - Common disk access routine
  680. ;
  681. ;   DiskIO is the common routine for all operations that need to
  682. ;   be performed on a device.
  683. ;
  684. ;   USHORT DiskIO (PBYTE pRP, NPVOLCB pVolCB)
  685. ;
  686. ;   ENTRY:    pRP              - Request Packet
  687. ;             pVolCB           - Pointer to VolCB
  688. ;
  689. ;   RETURN:   USHORT           - Packet Status word
  690. ;
  691. ;   EFFECTS:
  692. ;
  693. ------------------------------------------------------------------------*/
  694. USHORT DiskIO (pRP, pVolCB)
  695.  
  696. PBYTE    pRP;
  697. NPVOLCB  pVolCB;
  698.  
  699. {
  700.    NPUNITCB pUnitCB1 = 0;
  701.    NPUNITCB pUnitCB2 = 0;
  702.  
  703.   /* -------------------------------------------------------------
  704.    ; Check to see if the request is for zero sectors, and if     ;
  705.    ; so simply return.  We must do this as the LAST check to     ;
  706.    ; make sure that various status flags are properly set (if    ;
  707.    ; we had a floppy change error, and the retry was for         ;
  708.    ; zero bytes in length, we would not release the floppy       ;
  709.    ; change semaphore).                                          ;
  710.    --------------------------------------------------------------*/
  711.  
  712.  
  713.    ((PRPFT)pRP)->ftdb.FT_Flags = 0;
  714.  
  715.    if ( (DDFlags & DDF_FT_ENABLED)  &&
  716.         (f_FT_CheckFTSupport(pVolCB->pUnitCB, (PBYTE) pRP) == YES) )
  717.    {
  718.          f_FT_PutPriorityQueue(pVolCB->pUnitCB, pRP,
  719.                      (NPUNITCB FAR *) &pUnitCB1, (NPUNITCB FAR *) &pUnitCB2);
  720.  
  721.          if (pUnitCB1 != 0)
  722.             SubmitRequestsToADD(pUnitCB1);
  723.  
  724.          if (pUnitCB2 != 0)
  725.             SubmitRequestsToADD(pUnitCB2);
  726.    }
  727.    else
  728.    {
  729.       PutPriorityQueue_RP (pVolCB->pUnitCB, pRP);
  730.  
  731.       SubmitRequestsToADD (pVolCB->pUnitCB);
  732.    }
  733.    DISABLE;
  734.  
  735.    if ( !( ((PRPH)pRP)->Status & STDON) )
  736.       ((PRPH)pRP)->Status = STBUI;
  737.  
  738.    return(((PRPH)pRP)->Status);
  739.  
  740. }
  741.  
  742. /*------------------------------------------------------------------------
  743. ;
  744. ;** DiskIO_Wait - Perform disk I/O, blocking until done
  745. ;
  746. ;   Calls DiskIO, and blocks this thread until the operation
  747. ;   is complete, i.e. the STDON bit is set in the request packet.
  748. ;
  749. ;   USHORT DiskIO_Wait (PBYTE pRPH, NPVOLCB pVolCB)
  750. ;
  751. ;   ENTRY:    pRP              - Request Packet
  752. ;             pVolCB           - Pointer to VolCB
  753. ;
  754. ;   RETURN:   USHORT           - Packet Status word
  755. ;
  756. ;   EFFECTS:
  757. ;
  758. ------------------------------------------------------------------------*/
  759. USHORT FAR f_DiskIO_Wait (pRP, pVolCB)
  760.  
  761. PBYTE pRP;
  762. NPVOLCB pVolCB;
  763. {
  764.  
  765.    return(DiskIO_Wait(pRP, pVolCB));
  766. }
  767.  
  768.  
  769. USHORT DiskIO_Wait (pRP, pVolCB)
  770.  
  771. PBYTE pRP;
  772. NPVOLCB pVolCB;
  773.  
  774. {
  775.    ((PRPH)pRP)->Status = 0;
  776.  
  777.    /* Block until I/O done.  Infinite timeout, Non interruptable. */
  778.  
  779.    if ( ( ((PRPH)pRP)->Cmd == CMDInternal ) &&
  780.         ( ((PRP_INTERNAL)pRP)->Function == DISKOP_RESUME ) )
  781.  
  782.       SubmitImmedRequestToADD(pVolCB->pUnitCB, pRP);
  783.    else
  784.       DiskIO (pRP, pVolCB);
  785.  
  786.  
  787.    DISABLE;
  788.    while ( !( ((PRPH)pRP)->Status & STDON ) )
  789.    {
  790.       DevHelp_ProcBlock ((ULONG)pRP, -1L, 1);
  791.       DISABLE;                          /* Block does an enable  */
  792.    }
  793.    ENABLE;
  794.  
  795.    return ( ((PRPH)pRP)->Status);   /* return packet status  */
  796. }
  797.  
  798.