Changeset 133


Ignore:
Timestamp:
Jan 26, 2002, 4:59:23 PM (24 years ago)
Author:
umoeller
Message:

program plus other fixes

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/helpers/dosh.h

    r132 r133  
    7878
    7979    #ifdef INCL_DOSDEVIOCTL
    80 
    81         // flags for DRIVEPARMS.usDeviceAttrs (see DSK_GETDEVICEPARAMS in CPREF):
    82         #define DEVATTR_REMOVEABLE  0x0001      // drive is removeable
    83         #define DEVATTR_CHANGELINE  0x0002      // media has been removed since last I/O operation
    84         #define DEVATTR_GREATER16MB 0x0004      // physical device driver supports physical addresses > 16 MB
    8580
    8681        // #pragma pack(1)
     
    167162                                   PBIOSPARAMETERBLOCK pdp);
    168163
    169         BOOL XWPENTRY doshIsCDROM(PBIOSPARAMETERBLOCK pdp);
     164        BYTE doshQueryRemoveableType(PBIOSPARAMETERBLOCK pdp);
     165
     166        APIRET XWPENTRY doshHasAudioCD(ULONG ulLogicalDrive,
     167                                       HFILE hfDrive,
     168                                       BOOL fMixedModeCD,
     169                                       PBOOL pfAudio);
    170170
    171171    #endif
    172 
    173     APIRET XWPENTRY doshHasAudioCD(ULONG ulLogicalDrive,
    174                                    HFILE hfDrive,
    175                                    BOOL fMixedModeCD,
    176                                    PBOOL pfAudio);
    177172
    178173    VOID XWPENTRY doshEnumDrives(PSZ pszBuffer,
     
    186181    CHAR doshQueryBootDrive(VOID);
    187182
    188     #define ERROR_AUDIO_CD_ROM      10000
    189 
    190     #define ASSERTFL_MIXEDMODECD    0x0001
     183    #define ERROR_AUDIO_CD_ROM          10000
     184
     185    #define DRVFL_MIXEDMODECD        0x0001
     186    #define DRVFL_TOUCHFLOPPIES      0x0002
    191187
    192188    APIRET doshAssertDrive(ULONG ulLogicalDrive,
    193189                           ULONG fl);
     190
     191    #ifdef INCL_DOSDEVIOCTL
     192
     193        /*
     194         *@@ XDISKINFO:
     195         *
     196         *@@added V0.9.16 (2002-01-13) [umoeller]
     197         */
     198
     199        typedef struct _XDISKINFO
     200        {
     201            CHAR        cDriveLetter;           // drive letter
     202            CHAR        cLogicalDrive;          // logical drive no.
     203
     204            BOOL        fPresent;               // if FALSE, drive does not exist
     205
     206            // the following are only valid if fPresent == TRUE
     207
     208            BIOSPARAMETERBLOCK bpb;
     209                            // 0x00 USHORT usBytesPerSector;
     210                            // 0x02 BYTE   bSectorsPerCluster;
     211                            // 0x03 USHORT usReservedSectors;
     212                            // 0x05 BYTE   cFATs;
     213                            // 0x06 USHORT cRootEntries;
     214                            // 0x08 USHORT cSectors;
     215                            // 0x0a BYTE   bMedia;
     216                            // 0x0b USHORT usSectorsPerFAT;
     217                            // 0x0d USHORT usSectorsPerTrack;
     218                            // 0x0f USHORT cHeads;
     219                            // 0x11 ULONG  cHiddenSectors;
     220                            // 0x15 ULONG  cLargeSectors;
     221                            // 0x19 BYTE   abReserved[6];
     222                            // 0x1a USHORT cCylinders;
     223                            // 0x1c BYTE   bDeviceType;
     224                                    // DEVTYPE_48TPI                      0x0000
     225                                    // DEVTYPE_96TPI                      0x0001
     226                                    // DEVTYPE_35                         0x0002
     227                                    // DEVTYPE_8SD                        0x0003
     228                                    // DEVTYPE_8DD                        0x0004
     229                                    // DEVTYPE_FIXED                      0x0005
     230                                    // DEVTYPE_TAPE                       0x0006
     231                                    // DEVTYPE_UNKNOWN                    0x0007
     232                            // 0x1d USHORT fsDeviceAttr;
     233                                #define DEVATTR_REMOVEABLE              0x0001
     234                                            // drive is removeable
     235                                #define DEVATTR_CHANGELINE              0x0002
     236                                            // device can determine whether media has
     237                                            // been removed since last I/O operation
     238                                #define DEVATTR_GREATER16MB             0x0004
     239                                            // physical device driver supports physical
     240                                            // addresses > 16 MB
     241                                #define DEVATTR_PARTITIONALREMOVEABLE   0x0008
     242
     243            BYTE        bType;
     244                // do not change these codes, XWorkplace relies
     245                // on them too to parse WPDisk data
     246                #define DRVTYPE_HARDDISK        0
     247                #define DRVTYPE_FLOPPY          1
     248                #define DRVTYPE_TAPE            2
     249                #define DRVTYPE_VDISK           3
     250                #define DRVTYPE_CDROM           4
     251                #define DRVTYPE_LAN             5
     252                #define DRVTYPE_PARTITIONABLEREMOVEABLE 6
     253                #define DRVTYPE_UNKNOWN       255
     254
     255            ULONG       flDevice;
     256                // any combination of the following:
     257                #define DFL_REMOTE                      0x0001
     258                            // drive is remote (not local)
     259                #define DFL_FIXED                       0x0002
     260                            // drive is fixed; otherwise it is removeable!
     261                #define DFL_PARTITIONABLEREMOVEABLE     0x0004
     262                            // in that case, DFL_FIXED is set also
     263                #define DFL_BOOTDRIVE                   0x0008
     264                            // drive was booted from
     265
     266                // media flags:
     267
     268                #define DFL_MEDIA_PRESENT               0x1000
     269                            // media is present in drive; always
     270                            // true for fixed and remove drives and
     271                            // drives A: and B:
     272                #define DFL_AUDIO_CD                    0x2000
     273                            // set for CD-ROMs only, if an audio CD
     274                            // is currently inserted; in that case,
     275                            // DFL_MEDIA_PRESENT is _not_ set
     276                #define DFL_SUPPORTS_EAS                0x4000
     277                            // drive supports extended attributes
     278                #define DFL_SUPPORTS_LONGNAMES          0x8000
     279                            // drive supports long names; this does not
     280                            // necessarily mean that we support all IFS
     281                            // characters also
     282
     283            // the following are only valid if DFL_MEDIA_PRESENT is set;
     284            // they are always set for drives A: and B:
     285
     286            CHAR        szFileSystem[30];
     287                            // e.g. "FAT" or "HPFS" or "JFS" or "CDFS"
     288
     289            BYTE        bFileSystem;
     290                // do not change these codes, XWorkplace relies
     291                // on them too to parse WPDisk data
     292                #define FSYS_FAT             1
     293                #define FSYS_HPFS_JFS        2
     294                #define FSYS_CDFS            3
     295                #define FSYS_FAT32           8      // not used by WPS!
     296                #define FSYS_RAMFS           9      // not used by WPS!
     297                #define FSYS_REMOTE         10
     298
     299        } XDISKINFO, *PXDISKINFO;
     300
     301        APIRET doshGetDriveInfo(ULONG ulLogicalDrive,
     302                                ULONG fl,
     303                                PXDISKINFO pdi);
     304
     305    #endif
    194306
    195307    APIRET doshSetLogicalMap(ULONG ulLogicalDrive);
  • trunk/src/helpers/apps.c

    r131 r133  
    4949#include "helpers\dosh.h"
    5050#include "helpers\prfh.h"
     51#include "helpers\standards.h"          // some standard macros
    5152#include "helpers\stringh.h"
    5253#include "helpers\winh.h"
     
    636637
    637638/*
    638  *@@ appDescribeAppType:
    639  *      returns a "PROG_*" string for the given
    640  *      program type. Useful for WPProgram setup
    641  *      strings and such.
    642  *
    643  *@@added V0.9.16 (2001-10-06)
    644  */
    645 
    646 PCSZ appDescribeAppType(PROGCATEGORY progc)        // in: from PROGDETAILS.progc
     639 *@@ PROGTYPESTRING:
     640 *
     641 *@@added V0.9.16 (2002-01-13) [umoeller]
     642 */
     643
     644typedef struct _PROGTYPESTRING
    647645{
    648     switch (progc)
    649     {
    650         case PROG_DEFAULT: return "PROG_DEFAULT";
    651         case PROG_FULLSCREEN: return "PROG_FULLSCREEN";
    652         case PROG_WINDOWABLEVIO: return "PROG_WINDOWABLEVIO";
    653         case PROG_PM: return "PROG_PM";
    654         case PROG_GROUP: return "PROG_GROUP";
    655         case PROG_VDM: return "PROG_VDM";
    656             // same as case PROG_REAL: return "PROG_REAL";
    657         case PROG_WINDOWEDVDM: return "PROG_WINDOWEDVDM";
    658         case PROG_DLL: return "PROG_DLL";
    659         case PROG_PDD: return "PROG_PDD";
    660         case PROG_VDD: return "PROG_VDD";
    661         case PROG_WINDOW_REAL: return "PROG_WINDOW_REAL";
    662         case PROG_30_STD: return "PROG_30_STD";
    663             // same as case PROG_WINDOW_PROT: return "PROG_WINDOW_PROT";
    664         case PROG_WINDOW_AUTO: return "PROG_WINDOW_AUTO";
    665         case PROG_30_STDSEAMLESSVDM: return "PROG_30_STDSEAMLESSVDM";
    666             // same as case PROG_SEAMLESSVDM: return "PROG_SEAMLESSVDM";
    667         case PROG_30_STDSEAMLESSCOMMON: return "PROG_30_STDSEAMLESSCOMMON";
    668             // same as case PROG_SEAMLESSCOMMON: return "PROG_SEAMLESSCOMMON";
    669         case PROG_31_STDSEAMLESSVDM: return "PROG_31_STDSEAMLESSVDM";
    670         case PROG_31_STDSEAMLESSCOMMON: return "PROG_31_STDSEAMLESSCOMMON";
    671         case PROG_31_ENHSEAMLESSVDM: return "PROG_31_ENHSEAMLESSVDM";
    672         case PROG_31_ENHSEAMLESSCOMMON: return "PROG_31_ENHSEAMLESSCOMMON";
    673         case PROG_31_ENH: return "PROG_31_ENH";
    674         case PROG_31_STD: return "PROG_31_STD";
     646    PROGCATEGORY    progc;
     647    PCSZ            pcsz;
     648} PROGTYPESTRING, *PPROGTYPESTRING;
     649
     650PROGTYPESTRING G_aProgTypes[] =
     651    {
     652        PROG_DEFAULT, "PROG_DEFAULT",
     653        PROG_FULLSCREEN, "PROG_FULLSCREEN",
     654        PROG_WINDOWABLEVIO, "PROG_WINDOWABLEVIO",
     655        PROG_PM, "PROG_PM",
     656        PROG_GROUP, "PROG_GROUP",
     657        PROG_VDM, "PROG_VDM",
     658            // same as PROG_REAL, "PROG_REAL",
     659        PROG_WINDOWEDVDM, "PROG_WINDOWEDVDM",
     660        PROG_DLL, "PROG_DLL",
     661        PROG_PDD, "PROG_PDD",
     662        PROG_VDD, "PROG_VDD",
     663        PROG_WINDOW_REAL, "PROG_WINDOW_REAL",
     664        PROG_30_STD, "PROG_30_STD",
     665            // same as PROG_WINDOW_PROT, "PROG_WINDOW_PROT",
     666        PROG_WINDOW_AUTO, "PROG_WINDOW_AUTO",
     667        PROG_30_STDSEAMLESSVDM, "PROG_30_STDSEAMLESSVDM",
     668            // same as PROG_SEAMLESSVDM, "PROG_SEAMLESSVDM",
     669        PROG_30_STDSEAMLESSCOMMON, "PROG_30_STDSEAMLESSCOMMON",
     670            // same as PROG_SEAMLESSCOMMON, "PROG_SEAMLESSCOMMON",
     671        PROG_31_STDSEAMLESSVDM, "PROG_31_STDSEAMLESSVDM",
     672        PROG_31_STDSEAMLESSCOMMON, "PROG_31_STDSEAMLESSCOMMON",
     673        PROG_31_ENHSEAMLESSVDM, "PROG_31_ENHSEAMLESSVDM",
     674        PROG_31_ENHSEAMLESSCOMMON, "PROG_31_ENHSEAMLESSCOMMON",
     675        PROG_31_ENH, "PROG_31_ENH",
     676        PROG_31_STD, "PROG_31_STD",
    675677
    676678// Warp 4 toolkit defines, whatever these were designed for...
     
    685687#endif
    686688
    687         case PROG_DOS_GAME: return "PROG_DOS_GAME";
    688         case PROG_WIN_GAME: return "PROG_WIN_GAME";
    689         case PROG_DOS_MODE: return "PROG_DOS_MODE";
     689        PROG_DOS_GAME, "PROG_DOS_GAME",
     690        PROG_WIN_GAME, "PROG_WIN_GAME",
     691        PROG_DOS_MODE, "PROG_DOS_MODE",
    690692
    691693        // added this V0.9.16 (2001-12-08) [umoeller]
    692         case PROG_WIN32: return "PROG_WIN32";
     694        PROG_WIN32, "PROG_WIN32"
     695    };
     696
     697/*
     698 *@@ appDescribeAppType:
     699 *      returns a "PROG_*" string for the given
     700 *      program type. Useful for WPProgram setup
     701 *      strings and such.
     702 *
     703 *@@added V0.9.16 (2001-10-06)
     704 */
     705
     706PCSZ appDescribeAppType(PROGCATEGORY progc)        // in: from PROGDETAILS.progc
     707{
     708    ULONG ul;
     709    for (ul = 0;
     710         ul < ARRAYITEMCOUNT(G_aProgTypes);
     711         ul++)
     712    {
     713        if (G_aProgTypes[ul].progc == progc)
     714            return (G_aProgTypes[ul].pcsz);
    693715    }
    694716
  • trunk/src/helpers/dosh.c

    r132 r133  
    291291
    292292/*
    293  *@@ Allocate:
     293 *@@ doshMalloc:
    294294 *      wrapper around malloc() which automatically
    295295 *      sets ERROR_NOT_ENOUGH_MEMORY.
     
    457457        UCHAR ucNonRemoveable;
    458458
    459         parms.drive = (UCHAR)(ulLogicalDrive-1);
    460         arc = doshDevIOCtl((HFILE)-1,
    461                            IOCTL_DISK,                  // 0x08
    462                            DSK_BLOCKREMOVABLE,          // 0x20
    463                            &parms, sizeof(parms),
    464                            &ucNonRemoveable, sizeof(ucNonRemoveable));
    465 
    466         if (arc == NO_ERROR)
     459        parms.drive = (UCHAR)(ulLogicalDrive - 1);
     460        if (!(arc = doshDevIOCtl((HFILE)-1,
     461                                 IOCTL_DISK,                  // 0x08
     462                                 DSK_BLOCKREMOVABLE,          // 0x20
     463                                 &parms, sizeof(parms),
     464                                 &ucNonRemoveable, sizeof(ucNonRemoveable))))
    467465            *pfFixed = (BOOL)ucNonRemoveable;
    468466    }
     
    504502 *
    505503 *      This returns the DOS error code of DosDevIOCtl.
     504 *      This will be:
     505 *
     506 *      --  NO_ERROR for all local disks;
     507 *
     508 *      --  ERROR_NOT_SUPPORTED (50) for network drives.
    506509 *
    507510 *@@added V0.9.0 [umoeller]
     
    552555
    553556/*
    554  *@@ doshIsCDROM:
     557 *@@ doshQueryRemoveableType:
    555558 *      tests the specified BIOSPARAMETERBLOCK
    556  *      for whether it represents a CD-ROM drive.
     559 *      for whether it represents a CD-ROM or
     560 *      some other removeable drive type.
     561 *
     562 *      Returns one of:
     563 *
     564 *      --  0
     565 *
     566 *      --  DRVTYPE_CDROM
     567 *
     568 *      Call this only if doshIsFixedDisk
     569 *      returned FALSE.
    557570 *
    558571 *      The BIOSPARAMETERBLOCK must be filled
    559572 *      first using doshQueryDiskParams.
    560573 *
    561  *@@added V0.9.13 (2001-06-14) [umoeller]
    562  */
    563 
    564 BOOL doshIsCDROM(PBIOSPARAMETERBLOCK pdp)
    565 {
    566     return (    (pdp)
    567              && (pdp->bDeviceType == 7)     // "other"
     574 *@@added V0.9.16 (2002-01-13) [umoeller]
     575 */
     576
     577BYTE doshQueryRemoveableType(PBIOSPARAMETERBLOCK pdp)
     578{
     579    if (pdp)
     580    {
     581        if (    (pdp->bDeviceType == 7)     // "other"
    568582             && (pdp->usBytesPerSector == 2048)
    569583             && (pdp->usSectorsPerTrack == (USHORT)-1)
    570            );
     584           )
     585            return DRVTYPE_CDROM;
     586        else if (pdp->fsDeviceAttr & DEVATTR_PARTITIONALREMOVEABLE) // 0x08
     587            return DRVTYPE_PARTITIONABLEREMOVEABLE;
     588        else if (pdp->bDeviceType == 6)     // tape
     589            return DRVTYPE_TAPE;
     590    }
     591
     592    return (0);
    571593}
    572594
     
    578600 *      Better call this only if you're sure that
    579601 *      ulLogicalDrive is a CD-ROM drive. Use
    580  *      doshIsCDROM to check.
     602 *      doshQueryRemoveableType to check.
    581603 *
    582604 *@@added V0.9.14 (2001-08-01) [umoeller]
     
    798820 *      single (capital) character, which is useful for
    799821 *      constructing file names using sprintf and such.
     822 *
     823 *@@changed V0.9.16 (2002-01-13) [umoeller]: optimized
    800824 */
    801825
    802826CHAR doshQueryBootDrive(VOID)
    803827{
    804     ULONG ulBootDrive;
    805     DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
    806                     &ulBootDrive,
    807                     sizeof(ulBootDrive));
    808     return (ulBootDrive + 'A' - 1);
     828    // this can never change, so query this only once
     829    // V0.9.16 (2002-01-13) [umoeller]
     830    static CHAR     cBootDrive = '\0';
     831
     832    if (!cBootDrive)
     833    {
     834        ULONG ulBootDrive;
     835        DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
     836                        &ulBootDrive,
     837                        sizeof(ulBootDrive));
     838        cBootDrive = (CHAR)ulBootDrive + 'A' - 1;
     839    }
     840
     841    return (cBootDrive);
     842}
     843
     844/*
     845 *@@ doshQueryMedia:
     846 *      determines whether the given drive currently
     847 *      has media inserted.
     848 *
     849 *      Call this only for non-fixed (removable) disks.
     850 *      Use doshIsFixedDisk to find out.
     851 *
     852 *@@added V0.9.16 (2002-01-13) [umoeller]
     853 */
     854
     855APIRET doshQueryMedia(ULONG ulLogicalDrive,
     856                      BOOL fCDROM,
     857                      ULONG fl)                // in: DRVFL_* flags
     858{
     859    APIRET  arc;
     860
     861    HFILE   hf = NULLHANDLE;
     862    ULONG   dummy;
     863
     864    CHAR    szDrive[3] = "C:";
     865    szDrive[0] = 'A' + ulLogicalDrive - 1;
     866
     867    arc = DosOpen(szDrive,   // "C:", "D:", ...
     868                  &hf,
     869                  &dummy,
     870                  0,
     871                  FILE_NORMAL,
     872                  OPEN_ACTION_FAIL_IF_NEW
     873                         | OPEN_ACTION_OPEN_IF_EXISTS,
     874                  OPEN_FLAGS_DASD
     875                         | OPEN_FLAGS_FAIL_ON_ERROR
     876                         | OPEN_FLAGS_NOINHERIT     // V0.9.6 (2000-11-25) [pr]
     877              //            | OPEN_ACCESS_READONLY  // V0.9.13 (2001-06-14) [umoeller]
     878                         | OPEN_SHARE_DENYNONE,
     879                  NULL);
     880
     881    // this still returns NO_ERROR for audio CDs in a
     882    // CD-ROM drive...
     883    // however, the WPS then attempts to read in the
     884    // root directory for audio CDs, which produces
     885    // a "sector not found" error box...
     886
     887    if (    (!arc)
     888         && (hf)
     889         && (fCDROM)
     890       )
     891    {
     892        BOOL fAudio;
     893        if (    (!(arc = doshHasAudioCD(ulLogicalDrive,
     894                                        hf,
     895                                        ((fl & DRVFL_MIXEDMODECD) != 0),
     896                                        &fAudio)))
     897             && (fAudio)
     898           )
     899            arc = ERROR_AUDIO_CD_ROM;       // special private error code (10000)
     900    }
     901
     902    if (hf)
     903        DosClose(hf);
     904
     905    return (arc);
    809906}
    810907
     
    818915 *      and can be any combination of:
    819916 *
    820  *      --  ASSERTFL_MIXEDMODECD: whether to allow
     917 *      --  DRVFL_MIXEDMODECD: whether to allow
    821918 *          mixed-mode CD-ROMs. See error codes below.
    822919 *
     
    835932 *                  media inserted.
    836933 *
    837  *                  If ASSERTFL_MIXEDMODECD was specified, ERROR_AUDIO_CD_ROM
     934 *                  If DRVFL_MIXEDMODECD was specified, ERROR_AUDIO_CD_ROM
    838935 *                  is returned _only_ if _no_ data tracks are
    839936 *                  present on a CD-ROM. Since OS/2 is not very
     
    841938 *                  be desireable.
    842939 *
    843  *                  If ASSERTFL_MIXEDMODECD was not set, ERROR_AUDIO_CD_ROM
     940 *                  If DRVFL_MIXEDMODECD was not set, ERROR_AUDIO_CD_ROM
    844941 *                  will be returned already if _one_ audio track is present.
    845942 *
     
    855952
    856953APIRET doshAssertDrive(ULONG ulLogicalDrive,    // in: 1 for A:, 2 for B:, 3 for C:, ...
    857                        ULONG fl)                // in: ASSERTFL_* flags
     954                       ULONG fl)                // in: DRVFL_* flags
    858955{
    859956    APIRET  arc = NO_ERROR;
     
    881978
    882979            if (    (!arc)
    883                  && (doshIsCDROM(&bpb))
     980                 && (DRVTYPE_CDROM == doshQueryRemoveableType(&bpb))
    884981               )
    885982            {
     
    890987
    891988    if (!arc)
    892     {
    893         HFILE hfDrive = NULLHANDLE;
    894 
    895         ULONG   ulTemp = 0;
    896         CHAR    szDrive[3] = "C:";
    897         szDrive[0] = 'A' + ulLogicalDrive - 1;
    898 
    899         arc = DosOpen(szDrive,   // "C:", "D:", ...
    900                       &hfDrive,
    901                       &ulTemp,
    902                       0,
    903                       FILE_NORMAL,
    904                       OPEN_ACTION_FAIL_IF_NEW
    905                              | OPEN_ACTION_OPEN_IF_EXISTS,
    906                       OPEN_FLAGS_DASD
    907                              | OPEN_FLAGS_FAIL_ON_ERROR
    908                              | OPEN_FLAGS_NOINHERIT     // V0.9.6 (2000-11-25) [pr]
    909                   //            | OPEN_ACCESS_READONLY  // V0.9.13 (2001-06-14) [umoeller]
    910                              | OPEN_SHARE_DENYNONE,
    911                       NULL);
    912 
    913         // _Pmpf(("   DosOpen(OPEN_FLAGS_DASD) returned %d", arc));
    914 
    915         // this still returns NO_ERROR for audio CDs in a
    916         // CD-ROM drive...
    917         // however, the WPS then attempts to read in the
    918         // root directory for audio CDs, which produces
    919         // a "sector not found" error box...
    920 
    921         if (    (!arc)
    922              && (hfDrive)
    923              && (fCDROM)
    924            )
    925         {
    926             BOOL fAudio;
    927             if (    (!(arc = doshHasAudioCD(ulLogicalDrive,
    928                                             hfDrive,
    929                                             ((fl & ASSERTFL_MIXEDMODECD) != 0),
    930                                             &fAudio)))
    931                  && (fAudio)
    932                )
    933                 arc = ERROR_AUDIO_CD_ROM;       // special private error code (10000)
    934         }
    935 
    936         if (hfDrive)
    937             DosClose(hfDrive);
    938     }
     989        arc = doshQueryMedia(ulLogicalDrive,
     990                             fCDROM,
     991                             fl);
    939992
    940993    switch (arc)
     
    9721025        break;
    9731026    }
     1027
     1028    return (arc);
     1029}
     1030
     1031/*
     1032 *@@ doshGetDriveInfo:
     1033 *      fills the given XDISKINFO buffer with
     1034 *      information about the given logical drive.
     1035 *
     1036 *      This function will not provoke "Drive not
     1037 *      ready" popups, hopefully. Tested with the
     1038 *      following drive types:
     1039 *
     1040 *      --  all kinds of local partitions (FAT,
     1041 *          FAT32, HPFS, JFS)
     1042 *
     1043 *      --  remote NetBIOS drives added via "net use"
     1044 *
     1045 *      --  CD-ROM drives; one DVD drive and one
     1046 *          CD writer, even if no media is present
     1047 *
     1048 *      fl can be any combination of the following:
     1049 *
     1050 *      --  DRVFL_MIXEDMODECD: see doshAssertDrive.
     1051 *
     1052 *      --  DRVFL_TOUCHFLOPPIES: drive A: and B: should
     1053 *          be touched for media checks (click, click);
     1054 *          otherwise they will be left alone and
     1055 *          default values will be returned.
     1056 *
     1057 *      This should return only one of the following:
     1058 *
     1059 *      --  ERROR_INVALID_DRIVE: drive letter is invalid
     1060 *
     1061 *      --  ERROR_DRIVE_LOCKED
     1062 *
     1063 *      --  NO_ERROR: disk info was filled, but not
     1064 *          necessarily all info was available (e.g.
     1065 *          if no media was present in CD-ROM drive).
     1066 *
     1067 *@@added V0.9.16 (2002-01-13) [umoeller]
     1068 */
     1069
     1070APIRET doshGetDriveInfo(ULONG ulLogicalDrive,
     1071                        ULONG fl,               // in: DRVFL_* flags
     1072                        PXDISKINFO pdi)
     1073{
     1074    APIRET  arc = NO_ERROR;
     1075
     1076    HFILE   hf;
     1077    ULONG   dummy;
     1078    BOOL    fCheck = TRUE;
     1079
     1080    memset(pdi, 0, sizeof(XDISKINFO));
     1081
     1082    pdi->cDriveLetter = 'A' + ulLogicalDrive - 1;
     1083    pdi->cLogicalDrive = ulLogicalDrive;
     1084
     1085    pdi->bType = DRVTYPE_UNKNOWN;
     1086    pdi->fPresent = TRUE;       // for now
     1087
     1088    if (    (ulLogicalDrive == 1)
     1089         || (ulLogicalDrive == 2)
     1090       )
     1091    {
     1092        // drive A: and B: are special cases,
     1093        // we don't even want to touch them (click, click)
     1094        pdi->bType = DRVTYPE_FLOPPY;
     1095
     1096        if (0 == (fl & DRVFL_TOUCHFLOPPIES))
     1097        {
     1098            fCheck = FALSE;
     1099            // these support EAs too
     1100            pdi->flDevice  = DFL_MEDIA_PRESENT | DFL_SUPPORTS_EAS;
     1101            strcpy(pdi->szFileSystem, "FAT");
     1102            pdi->bFileSystem = FSYS_FAT;
     1103        }
     1104    }
     1105
     1106    if (fCheck)
     1107    {
     1108        // any other drive:
     1109        // check if it's removeable first
     1110        BOOL    fFixed = FALSE;
     1111        arc = doshIsFixedDisk(ulLogicalDrive,
     1112                              &fFixed);
     1113
     1114        if (arc == ERROR_INVALID_DRIVE)
     1115            // drive letter doesn't exist at all:
     1116            pdi->fPresent = FALSE;
     1117            // return this APIRET
     1118        else
     1119        {
     1120            BOOL fCheckFS = FALSE;
     1121            BOOL fCheckLongnames = FALSE;
     1122
     1123            if (fFixed)
     1124                // fixed drive:
     1125                pdi->flDevice |= DFL_FIXED | DFL_MEDIA_PRESENT;
     1126
     1127            if (!(arc = doshQueryDiskParams(ulLogicalDrive,
     1128                                            &pdi->bpb)))
     1129            {
     1130                if (!fFixed)
     1131                {
     1132                    // removeable:
     1133                    BYTE bTemp;
     1134                    if (bTemp = doshQueryRemoveableType(&pdi->bpb))
     1135                    {
     1136                        // DRVTYPE_TAPE or DRVTYPE_CDROM
     1137                        pdi->bType = bTemp;
     1138
     1139                        if (bTemp == DRVTYPE_PARTITIONABLEREMOVEABLE)
     1140                            pdi->flDevice |=    DFL_FIXED
     1141                                              | DFL_PARTITIONABLEREMOVEABLE;
     1142                    }
     1143
     1144                    // before checking the drive, try if we have media
     1145                    if (!(arc = doshQueryMedia(ulLogicalDrive,
     1146                                               (pdi->bType == DRVTYPE_CDROM),
     1147                                               fl)))
     1148                    {
     1149                        pdi->flDevice |= DFL_MEDIA_PRESENT;
     1150                        fCheckFS = TRUE;
     1151                        fCheckLongnames = TRUE;
     1152                    }
     1153                    else if (arc == ERROR_AUDIO_CD_ROM)
     1154                    {
     1155                        pdi->flDevice |= DFL_AUDIO_CD;
     1156                        // do not check longnames and file-system
     1157                    }
     1158
     1159                    arc = NO_ERROR;
     1160                }
     1161                else
     1162                {
     1163                    pdi->bType = DRVTYPE_HARDDISK;
     1164                    fCheckFS = TRUE;
     1165                }
     1166            }
     1167            else if (arc == ERROR_NOT_SUPPORTED)       // 50
     1168            {
     1169                // we get this for remote drives added
     1170                // via "net use", so set these flags
     1171                pdi->bType = DRVTYPE_LAN;
     1172                pdi->bFileSystem = FSYS_REMOTE;
     1173                pdi->flDevice |= DFL_REMOTE | DFL_MEDIA_PRESENT;
     1174                // but still check what file-system we
     1175                // have and whether longnames are supported
     1176                fCheckFS = TRUE;
     1177                fCheckLongnames = TRUE;
     1178            }
     1179
     1180            if (fCheckFS)
     1181            {
     1182                // TRUE only for local fixed disks or
     1183                // remote drives or if media was present above
     1184                if (!(arc = doshQueryDiskFSType(ulLogicalDrive,
     1185                                                pdi->szFileSystem,
     1186                                                sizeof(pdi->szFileSystem))))
     1187                {
     1188                    if (!stricmp(pdi->szFileSystem, "FAT"))
     1189                    {
     1190                        pdi->bFileSystem = FSYS_FAT;
     1191                        pdi->flDevice |= DFL_SUPPORTS_EAS;
     1192                        fCheckLongnames = FALSE;
     1193                    }
     1194                    else if (    (!stricmp(pdi->szFileSystem, "HPFS"))
     1195                              || (!stricmp(pdi->szFileSystem, "JFS"))
     1196                            )
     1197                    {
     1198                        pdi->bFileSystem = FSYS_HPFS_JFS;
     1199                        pdi->flDevice |= DFL_SUPPORTS_EAS | DFL_SUPPORTS_LONGNAMES;
     1200                        fCheckLongnames = FALSE;
     1201                    }
     1202                    else if (!stricmp(pdi->szFileSystem, "CDFS"))
     1203                        pdi->bFileSystem = FSYS_CDFS;
     1204                    else if (!stricmp(pdi->szFileSystem, "FAT32"))
     1205                    {
     1206                        pdi->bFileSystem = FSYS_FAT32;
     1207                        pdi->flDevice |= DFL_SUPPORTS_LONGNAMES;
     1208                                // @@todo check EA support
     1209                        fCheckLongnames = FALSE;
     1210                    }
     1211                    else if (!stricmp(pdi->szFileSystem, "RAMFS"))
     1212                    {
     1213                        pdi->bFileSystem = FSYS_RAMFS;
     1214                        pdi->flDevice |= DFL_SUPPORTS_EAS | DFL_SUPPORTS_LONGNAMES;
     1215                        fCheckLongnames = FALSE;
     1216                    }
     1217                }
     1218                // else if this failed, we had an error popup!!
     1219                // shouldn't happen!!
     1220            }
     1221
     1222            if (fCheckLongnames)
     1223            {
     1224                CHAR szTemp[30] = "?:\\long.name.file";
     1225                szTemp[0]  = ulLogicalDrive + 'A' - 1;
     1226                if (!(arc = DosOpen(szTemp,
     1227                                    &hf,
     1228                                    &dummy,
     1229                                    0,
     1230                                    0,
     1231                                    FILE_READONLY,
     1232                                    OPEN_SHARE_DENYNONE | OPEN_FLAGS_NOINHERIT,
     1233                                    0)))
     1234                {
     1235                    DosClose(hf);
     1236                }
     1237
     1238                switch (arc)
     1239                {
     1240                    case NO_ERROR:
     1241                    case ERROR_OPEN_FAILED:
     1242                        pdi->flDevice |= DFL_SUPPORTS_LONGNAMES;
     1243
     1244                    // otherwise we get ERROR_INVALID_NAME
     1245                    // default:
     1246                       //  printf("      drive %d returned %d\n", ulLogicalDrive, arc);
     1247                }
     1248
     1249                arc = NO_ERROR;
     1250            }
     1251        }
     1252    }
     1253
     1254    if (doshQueryBootDrive() == pdi->cDriveLetter)
     1255        pdi->flDevice |= DFL_BOOTDRIVE;
    9741256
    9751257    return (arc);
     
    25222804 *      Example: Assuming TEMP is set to C:\TEMP,
    25232805 +
    2524  +          dosCreateTempFileName(szBuffer,
    2525  +                                NULL,             // use $(TEMP)
    2526  +                                "pre",            // prefix
    2527  +                                "tmp")            // extension
     2806 +          doshCreateTempFileName(szBuffer,
     2807 +                                 NULL,             // use $(TEMP)
     2808 +                                 "pre",            // prefix
     2809 +                                 "tmp")            // extension
    25282810 +
    25292811 *      would produce something like "C:\TEMP\pre07FG2.tmp".
     
    36673949}
    36683950
    3669 
     3951/* ******************************************************************
     3952 *
     3953 *   Testcase
     3954 *
     3955 ********************************************************************/
     3956
     3957#ifdef BUILD_MAIN
     3958
     3959int main (int argc, char *argv[])
     3960{
     3961    ULONG ul;
     3962
     3963            printf("    type     fs       remot fixed parrm bootd       media audio eas   longn\n");
     3964
     3965    for (ul = 1;
     3966         ul <= 26;
     3967         ul++)
     3968    {
     3969        XDISKINFO xdi;
     3970        APIRET arc = doshGetDriveInfo(ul,
     3971                                      0, // DRVFL_TOUCHFLOPPIES,
     3972                                      &xdi);
     3973        PCSZ pcsz = "unknown";
     3974
     3975        printf(" %c: ", xdi.cDriveLetter, ul);
     3976
     3977        if (!xdi.fPresent)
     3978            printf("not present\n");
     3979        else
     3980        {
     3981            if (arc)
     3982                printf("error %4d\n", arc);
     3983            else
     3984            {
     3985                ULONG   aulFlags[] =
     3986                    {
     3987                        DFL_REMOTE,
     3988                        DFL_FIXED,
     3989                        DFL_PARTITIONABLEREMOVEABLE,
     3990                        DFL_BOOTDRIVE,
     3991                        0,
     3992                        DFL_MEDIA_PRESENT,
     3993                        DFL_AUDIO_CD,
     3994                        DFL_SUPPORTS_EAS,
     3995                        DFL_SUPPORTS_LONGNAMES
     3996                    };
     3997                ULONG ul2;
     3998
     3999                switch (xdi.bType)
     4000                {
     4001                    case DRVTYPE_HARDDISK:  pcsz = "HARDDISK";    break;
     4002                    case DRVTYPE_FLOPPY:    pcsz = "FLOPPY  "; break;
     4003                    case DRVTYPE_TAPE:      pcsz = "TAPE    "; break;
     4004                    case DRVTYPE_VDISK:     pcsz = "VDISK   "; break;
     4005                    case DRVTYPE_CDROM:     pcsz = "CDROM   "; break;
     4006                    case DRVTYPE_LAN:       pcsz = "LAN     "; break;
     4007                    case DRVTYPE_PARTITIONABLEREMOVEABLE:
     4008                                            pcsz = "PARTREMV"; break;
     4009                }
     4010
     4011                printf("%s ", pcsz);
     4012
     4013                printf("%8s ", xdi.szFileSystem); // , xdi.bFileSystem);
     4014
     4015                for (ul2 = 0;
     4016                     ul2 < ARRAYITEMCOUNT(aulFlags);
     4017                     ul2++)
     4018                {
     4019                    if (xdi.flDevice & aulFlags[ul2])
     4020                        printf("  X   ");
     4021                    else
     4022                        printf("  -   ");
     4023                }
     4024                printf("\n");
     4025            }
     4026        }
     4027    }
     4028}
     4029
     4030#endif
  • trunk/src/helpers/memdebug.c

    r132 r133  
    756756        if (psz = strhCreateDump(pb, ulSize, ulIndent))
    757757        {
    758             // _Pmpf(("\n%s", psz));
     758            _Pmpf(("\n%s", psz));
    759759            free(psz);
    760760        }
  • trunk/src/helpers/xprf.c

    r91 r133  
    160160                     const char *pcszApp)
    161161{
    162     PXINIAPPDATA pReturn = NULL;
    163162    PLISTNODE pAppNode = lstQueryFirstNode(&pXIni->llApps);
    164163    while (pAppNode)
    165164    {
    166165        PXINIAPPDATA pAppDataThis = (PXINIAPPDATA)pAppNode->pItemData;
    167         if (strcmp(pAppDataThis->pszAppName, pcszApp) == 0)
    168         {
    169             pReturn = pAppDataThis;
    170             break;
    171         }
     166        if (!strcmp(pAppDataThis->pszAppName, pcszApp))
     167            return (pAppDataThis);
    172168
    173169        pAppNode = pAppNode->pNext;
    174170    }
    175171
    176     return (pReturn);
     172    return (NULL);
    177173}
    178174
     
    190186                       const char *pcszApp)
    191187{
    192     PXINIAPPDATA pAppData = (PXINIAPPDATA)malloc(sizeof(XINIAPPDATA));
    193     if (pAppData)
     188    PXINIAPPDATA pAppData;
     189    if (pAppData = (PXINIAPPDATA)malloc(sizeof(XINIAPPDATA)))
    194190    {
    195191        pAppData->pszAppName = strdup(pcszApp);
     
    217213                     const char *pcszKey)
    218214{
    219     PXINIKEYDATA pReturn = NULL;
    220215    PLISTNODE pKeyNode = lstQueryFirstNode(&pAppData->llKeys);
    221216    while (pKeyNode)
    222217    {
    223218        PXINIKEYDATA pKeyDataThis = (PXINIKEYDATA)pKeyNode->pItemData;
    224         if (strcmp(pKeyDataThis->pszKeyName, pcszKey) == 0)
    225         {
    226             pReturn = pKeyDataThis;
    227             break;
    228         }
     219        if (!strcmp(pKeyDataThis->pszKeyName, pcszKey))
     220            return (pKeyDataThis);
    229221
    230222        pKeyNode = pKeyNode->pNext;
    231223    }
    232224
    233     return (pReturn);
     225    return (NULL);
    234226}
    235227
     
    249241                       ULONG cbData)            // in: sizeof (*pbData)
    250242{
    251     PXINIKEYDATA pKeyData = (PXINIKEYDATA)malloc(sizeof(XINIKEYDATA));
    252     if (pKeyData)
     243    PXINIKEYDATA pKeyData;
     244    if (pKeyData = (PXINIKEYDATA)malloc(sizeof(XINIKEYDATA)))
    253245    {
    254246        pKeyData->pszKeyName = strdup(pcszKey);
    255247
    256         pKeyData->pbData = (PBYTE)malloc(cbData);
    257         if (pKeyData->pbData)
     248        if (pKeyData->pbData = (PBYTE)malloc(cbData))
    258249        {
    259250            memcpy(pKeyData->pbData, pbData, cbData);
     
    377368            == NO_ERROR)
    378369    {
    379         PBYTE   pbFileData = (PBYTE)malloc(fs3.cbFile);
    380         if (pbFileData)
     370        PBYTE  pbFileData;
     371        if (pbFileData = (PBYTE)malloc(fs3.cbFile))
    381372        {
    382373            ULONG ulSet = 0;
     
    508499
    509500    // allocate buffer for total size
    510     pbData2Write = (PBYTE)malloc(ulTotalFileSize);
    511     if (pbData2Write)
     501    if (pbData2Write = (PBYTE)malloc(ulTotalFileSize))
    512502    {
    513503        APIRET arc = NO_ERROR;
     
    640630
    641631        // write out everything
    642         arc = DosProtectSetFilePtr(pXIni->hFile,
    643                                    0,
    644                                    FILE_BEGIN,
    645                                    &ulSet,
    646                                    pXIni->hLock);
    647         if (arc == NO_ERROR)
     632        if (!(arc = DosProtectSetFilePtr(pXIni->hFile,
     633                                         0,
     634                                         FILE_BEGIN,
     635                                         &ulSet,
     636                                         pXIni->hLock)))
    648637        {
    649638            ULONG cbWritten = 0;
    650             arc = DosProtectWrite(pXIni->hFile,
    651                                   pbData2Write,
    652                                   ulTotalFileSize,
    653                                   &cbWritten,
    654                                   pXIni->hLock);
    655             if (arc == NO_ERROR)
    656             {
    657                 arc = DosProtectSetFileSize(pXIni->hFile,
    658                                             ulTotalFileSize,
    659                                             pXIni->hLock);
    660                 if (arc == NO_ERROR)
    661                     brc = TRUE;
    662             }
     639            if (    (!(arc = DosProtectWrite(pXIni->hFile,
     640                                             pbData2Write,
     641                                             ulTotalFileSize,
     642                                             &cbWritten,
     643                                             pXIni->hLock)))
     644                 && (!(arc = DosProtectSetFileSize(pXIni->hFile,
     645                                                   ulTotalFileSize,
     646                                                   pXIni->hLock)))
     647               )
     648                brc = TRUE;
    663649        }
    664650
Note: See TracChangeset for help on using the changeset viewer.