Ignore:
Timestamp:
Sep 2, 2002, 4:00:04 PM (23 years ago)
Author:
umoeller
Message:

Misc changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/dosh.c

    r217 r220  
    685685    {
    686686        if (pdp->fsDeviceAttr & DEVATTR_PARTITIONALREMOVEABLE) // 0x08
    687             return DRVTYPE_PARTITIONABLEREMOVEABLE;
    688         else if (fFixed)
     687            return DRVTYPE_PRT;
     688
     689        if (fFixed)
    689690            return DRVTYPE_HARDDISK;
    690         else if (    (pdp->bDeviceType == 7)     // "other"
    691                   && (pdp->usBytesPerSector == 2048)
    692                   && (pdp->usSectorsPerTrack == (USHORT)-1)
    693                 )
    694                  return DRVTYPE_CDROM;
    695         else switch (pdp->bDeviceType)
     691
     692        if (    (pdp->bDeviceType == 7)     // "other"
     693             && (pdp->usBytesPerSector == 2048)
     694             && (pdp->usSectorsPerTrack == (USHORT)-1)
     695           )
     696            return DRVTYPE_CDROM;
     697
     698        switch (pdp->bDeviceType)
    696699        {
    697700            case DEVTYPE_TAPE: // 6
     
    708711                   )
    709712                    return DRVTYPE_FLOPPY;
    710                 else
    711                     return DRVTYPE_VDISK;
     713
     714                return DRVTYPE_VDISK;
    712715
    713716            case DEVTYPE_RWOPTICAL: // 8, what is this?!?
     
    716719    }
    717720
    718     return (DRVTYPE_UNKNOWN);
     721    return DRVTYPE_UNKNOWN;
     722}
     723
     724/*
     725 *@@ doshQueryCDDrives:
     726 *      returns the no. of CD-ROM drives on the system
     727 *      as well as the drive letter of the first
     728 *      CD-ROM drive.
     729 *
     730 *@@added V0.9.21 (2002-08-31) [umoeller]
     731 */
     732
     733APIRET doshQueryCDDrives(PBYTE pcCDs,           // out: CD-ROM drives count
     734                         PCHAR pcFirstCD)       // out: drive letter of first CD
     735{
     736    APIRET  arc;
     737    HFILE   hfCDROM;
     738    ULONG   ulAction;
     739
     740    if (!(arc = DosOpen("\\DEV\\CD-ROM2$",
     741                        &hfCDROM,
     742                        &ulAction,
     743                        0,
     744                        FILE_NORMAL,
     745                        OPEN_ACTION_OPEN_IF_EXISTS,
     746                        OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY,
     747                        NULL)))
     748    {
     749        struct
     750        {
     751            USHORT cCDs;
     752            USHORT usFirstCD;       // 0 == A:, 1 == B:, ...
     753        } cdinfo;
     754
     755        ULONG cb = sizeof(cdinfo);
     756
     757        if (!(arc = DosDevIOCtl(hfCDROM,
     758                                0x82,
     759                                0x60,
     760                                NULL,
     761                                0,
     762                                NULL,
     763                                &cdinfo,
     764                                cb,
     765                                &cb)))
     766        {
     767            *pcCDs = cdinfo.cCDs;
     768            *pcFirstCD = cdinfo.usFirstCD + 'A';
     769        }
     770
     771        DosClose(hfCDROM);
     772    }
     773
     774    return arc;
     775}
     776
     777/*
     778 *@@ doshOpenDrive:
     779 *      opens the given logical drive using
     780 *      DosOpen with OPEN_FLAGS_DASD. Use
     781 *      the file handle returned from here
     782 *      for doshHasAudioCD and doshQueryCDStatus.
     783 *
     784 *      If NO_ERROR is returned, use DosClose
     785 *      to close the device again.
     786 *
     787 *@@added V0.9.21 (2002-08-31) [umoeller]
     788 */
     789
     790APIRET doshOpenDrive(ULONG ulLogicalDrive,
     791                     HFILE *phf)            // out: open drive's file handle
     792{
     793    ULONG   dummy;
     794
     795    CHAR    szDrive[] = "C:";
     796    szDrive[0] = 'A' + ulLogicalDrive - 1;
     797
     798    return DosOpen(szDrive,   // "C:", "D:", ...
     799                   phf,
     800                   &dummy,
     801                   0,
     802                   FILE_NORMAL,
     803                   // OPEN_ACTION_FAIL_IF_NEW
     804                          OPEN_ACTION_OPEN_IF_EXISTS,
     805                   OPEN_FLAGS_DASD
     806                          | OPEN_FLAGS_FAIL_ON_ERROR
     807                                // ^^^ if this flag is not set, we get the white
     808                                // hard-error box
     809                          | OPEN_FLAGS_NOINHERIT     // V0.9.6 (2000-11-25) [pr]
     810               //            | OPEN_ACCESS_READONLY  // V0.9.13 (2001-06-14) [umoeller]
     811                          | OPEN_SHARE_DENYNONE,
     812                   NULL);
    719813}
    720814
     
    729823 *
    730824 *@@added V0.9.14 (2001-08-01) [umoeller]
    731  */
    732 
    733 APIRET doshHasAudioCD(ULONG ulLogicalDrive,
    734                       HFILE hfDrive,            // in: DASD open
     825 *@@changed V0.9.21 (2002-08-31) [umoeller]: removed ulLogicalDrive which was not needed
     826 */
     827
     828APIRET doshHasAudioCD(HFILE hfDrive,            // in: DASD open
    735829                      BOOL fMixedModeCD,
    736830                      PBOOL pfAudio)
     
    758852        else
    759853        {
     854            #pragma pack(1)         // V0.9.21 (2002-08-31) [umoeller]
     855
    760856            struct {
    761857                UCHAR   ucFirstTrack,
     
    763859                ULONG   ulLeadOut;
    764860            } cdat;
     861
     862            struct {
     863                ULONG   ulTrackAddress;
     864                BYTE    bFlags;
     865            } trackdata;
     866
     867            #pragma pack()
    765868
    766869            // get track count
     
    780883                      { 'C', 'D', '0', '1', (UCHAR)i };
    781884
    782                     struct {
    783                         ULONG   ulTrackAddress;
    784                         BYTE    bFlags;
    785                     } trackdata;
    786 
    787885                    if (!(arc = doshDevIOCtl(hfDrive,
    788886                                             IOCTL_CDROMAUDIO,
     
    828926        // _Pmpf(("   CDROMDISK_GETDRIVER returned %d", arc));
    829927        arc = NO_ERROR;
     928    }
     929
     930    return arc;
     931}
     932
     933/*
     934 *@@ doshQueryCDStatus:
     935 *      returns the status bits of a CD-ROM drive.
     936 *      This calls the CDROMDISK_DEVICESTATUS
     937 *      ioctl.
     938 *
     939 *      If NO_ERROR is returned, *pflStatus has
     940 *      received the following flags:
     941 *
     942 *      --  CDFL_DOOROPEN (bit 0)
     943 *
     944 *      --  CDFL_DOORLOCKED (bit 1)
     945 *
     946 *      and many more (see dosh.h).
     947 *
     948 *      Actually I wrote this function to have a way to
     949 *      find out whether the drive door is already open.
     950 *      But thanks to IBM's thoughtful design, this ioctl
     951 *      is 99% useless for that purpose since it requires
     952 *      a DASD disk handle to be passed in, which cannot
     953 *      be obtained if there's no media in the drive.
     954 *
     955 *      In other words, it is absolutely impossible to
     956 *      ever get the CDFL_DOOROPEN flag, because if the
     957 *      door is open, DosOpen already fails on the drive.
     958 *      As a consequence, it is seems to be impossible
     959 *      to find out if the door is open with OS/2.
     960 *
     961 *@@added V0.9.21 (2002-08-31) [umoeller]
     962 */
     963
     964APIRET doshQueryCDStatus(HFILE hfDrive,            // in: DASD open
     965                         PULONG pflStatus)         // out: CD-ROM status bits
     966{
     967    APIRET  arc;
     968
     969    CHAR    cds1[4] = { 'C', 'D', '0', '1' };
     970    ULONG   fl;
     971
     972    *pflStatus = 0;
     973
     974    if (!(arc = doshDevIOCtl(hfDrive,
     975                             IOCTL_CDROMDISK,
     976                             CDROMDISK_DEVICESTATUS,
     977                             &cds1, sizeof(cds1),
     978                             &fl, sizeof(fl))))
     979    {
     980        *pflStatus = fl;
    830981    }
    831982
     
    9651116    }
    9661117
    967     return (cBootDrive);
     1118    return cBootDrive;
    9681119}
    9691120
     
    9761127 *      Use doshIsFixedDisk to find out.
    9771128 *
     1129 *      Returns:
     1130 *
     1131 *      --  NO_ERROR: media is present.
     1132 *
     1133 *      --  ERROR_AUDIO_CD_ROM (10000): audio CD-ROM is present.
     1134 *
     1135 *      --  ERROR_NOT_READY (21) or other: drive has no media.
     1136 *
    9781137 *@@added V0.9.16 (2002-01-13) [umoeller]
    9791138 */
    9801139
    981 APIRET doshQueryMedia(ULONG ulLogicalDrive,
     1140APIRET doshQueryMedia(ULONG ulLogicalDrive,    // in: 1 for A:, 2 for B:, 3 for C:, ...
    9821141                      BOOL fCDROM,             // in: is drive CD-ROM?
    9831142                      ULONG fl)                // in: DRVFL_* flags
     
    9851144    APIRET  arc;
    9861145
    987     HFILE   hf = NULLHANDLE;
    988     ULONG   dummy;
    989 
    990     CHAR    szDrive[3] = "C:";
    991     szDrive[0] = 'A' + ulLogicalDrive - 1;
    992 
    993     arc = DosOpen(szDrive,   // "C:", "D:", ...
    994                   &hf,
    995                   &dummy,
    996                   0,
    997                   FILE_NORMAL,
    998                   OPEN_ACTION_FAIL_IF_NEW
    999                          | OPEN_ACTION_OPEN_IF_EXISTS,
    1000                   OPEN_FLAGS_DASD
    1001                          | OPEN_FLAGS_FAIL_ON_ERROR
    1002                          | OPEN_FLAGS_NOINHERIT     // V0.9.6 (2000-11-25) [pr]
    1003               //            | OPEN_ACCESS_READONLY  // V0.9.13 (2001-06-14) [umoeller]
    1004                          | OPEN_SHARE_DENYNONE,
    1005                   NULL);
     1146    HFILE   hf;
     1147
     1148    // exported this code to doshOpenDrive V0.9.21 (2002-08-31) [umoeller]
     1149    arc = doshOpenDrive(ulLogicalDrive,
     1150                        &hf);
    10061151
    10071152    // this still returns NO_ERROR for audio CDs in a
     
    10171162    {
    10181163        BOOL fAudio;
    1019         if (    (!(arc = doshHasAudioCD(ulLogicalDrive,
    1020                                         hf,
     1164        if (    (!(arc = doshHasAudioCD(hf,
    10211165                                        ((fl & DRVFL_MIXEDMODECD) != 0),
    10221166                                        &fAudio)))
     
    11791323 *          file systems so we will always have a
    11801324 *          value for the DFL_SUPPORTS_EAS flags.
    1181  *          Otherwise that flag might or might not
    1182  *          be set correctly.
    1183  *
    11841325 *          The EA support returned by DosFSCtl
    11851326 *          might not be correct for remote file
     
    11871328 *          that query.
    11881329 *
    1189  *      --  DRVFL_CHECKLONGNAMES: drive should always be
    1190  *          checked for longname support. If this is
     1330 *          If not set, we set DFL_SUPPORTS_EAS only
     1331 *          for file systems such as HPFS and JFS
     1332 *          that are known to support EAs.
     1333 *
     1334 *      --  DRVFL_CHECKLONGNAMES: drive should be
     1335 *          tested for longname support. If this is
    11911336 *          set, we will try a DosOpen("\\long.name.file")
    11921337 *          on the drive to see if it supports long
     
    13761521                        pdi->bType = bTemp;
    13771522
    1378                         if (bTemp == DRVTYPE_PARTITIONABLEREMOVEABLE)
     1523                        if (bTemp == DRVTYPE_PRT)
    13791524                            pdi->flDevice |=    DFL_FIXED
    13801525                                              | DFL_PARTITIONABLEREMOVEABLE;
Note: See TracChangeset for help on using the changeset viewer.