Ignore:
Timestamp:
Jan 31, 2002, 11:12:45 PM (24 years ago)
Author:
umoeller
Message:

Misc speed improvements.

File:
1 edited

Legend:

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

    r133 r135  
    4949#define INCL_DOSMODULEMGR
    5050#define INCL_DOSPROCESS
     51#define INCL_DOSEXCEPTIONS
    5152#define INCL_DOSSESMGR
    5253#define INCL_DOSQUEUES
     
    7475
    7576// static const CHAR  G_acDriveLetters[28] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     77
     78/*
     79 *@@category: Helpers\Control program helpers\Wrappers
     80 */
     81
     82/* ******************************************************************
     83 *
     84 *   Wrappers
     85 *
     86 ********************************************************************/
     87
     88#ifdef DOSH_STANDARDWRAPPERS
     89
     90    /*
     91     *@@ doshSleep:
     92     *
     93     *@@added V0.9.16 (2002-01-26) [umoeller]
     94     */
     95
     96    APIRET doshSleep(ULONG msec)
     97    {
     98        // put the call in brackets so the macro won't apply here
     99        return (DosSleep)(msec);
     100    }
     101
     102    /*
     103     *@@ doshCreateMutexSem:
     104     *
     105     *@@added V0.9.16 (2002-01-26) [umoeller]
     106     */
     107
     108    APIRET doshCreateMutexSem(PSZ pszName,
     109                              PHMTX phmtx,
     110                              ULONG flAttr,
     111                              BOOL32 fState)
     112    {
     113        // put the call in brackets so the macro won't apply here
     114        return (DosCreateMutexSem)(pszName, phmtx, flAttr, fState);
     115    }
     116
     117    /*
     118     *@@ doshRequestMutexSem:
     119     *
     120     *@@added V0.9.16 (2002-01-26) [umoeller]
     121     */
     122
     123    APIRET doshRequestMutexSem(HMTX hmtx, ULONG ulTimeout)
     124    {
     125        return (DosRequestMutexSem)(hmtx, ulTimeout);
     126    }
     127
     128    /*
     129     *@@ doshReleaseMutexSem:
     130     *
     131     *@@added V0.9.16 (2002-01-26) [umoeller]
     132     */
     133
     134    APIRET doshReleaseMutexSem(HMTX hmtx)
     135    {
     136        return (DosReleaseMutexSem)(hmtx);
     137    }
     138
     139    /*
     140     *@@ doshSetExceptionHandler:
     141     *
     142     *@@added V0.9.16 (2002-01-26) [umoeller]
     143     */
     144
     145    APIRET doshSetExceptionHandler(PEXCEPTIONREGISTRATIONRECORD pERegRec)
     146    {
     147        // put the call in brackets so the macro won't apply here
     148        return (DosSetExceptionHandler)(pERegRec);
     149    }
     150
     151    /*
     152     *@@ doshUnsetExceptionHandler:
     153     *
     154     *@@added V0.9.16 (2002-01-26) [umoeller]
     155     */
     156
     157    APIRET doshUnsetExceptionHandler(PEXCEPTIONREGISTRATIONRECORD pERegRec)
     158    {
     159        // put the call in brackets so the macro won't apply here
     160        return (DosUnsetExceptionHandler)(pERegRec);
     161    }
     162
     163#endif
    76164
    77165/*
     
    427515 *      removeable disks.
    428516 *
     517 *      Returns:
     518 *
     519 *      --  NO_ERROR: *pfFixed was set.
     520 *
     521 *      --  ERROR_INVALID_DRIVE: drive letter invalid
     522 *
     523 *      --  ERROR_NOT_SUPPORTED (50): for network drives.
     524 *
    429525 *@@changed V0.9.14 (2001-08-03) [umoeller]: added extra fix for A: and B:
    430526 */
     
    555651
    556652/*
    557  *@@ doshQueryRemoveableType:
     653 *@@ doshQueryDriveType:
    558654 *      tests the specified BIOSPARAMETERBLOCK
    559655 *      for whether it represents a CD-ROM or
     
    562658 *      Returns one of:
    563659 *
    564  *      --  0
     660 *      --  DRVTYPE_HARDDISK (0)
     661 *
     662 *      --  DRVTYPE_PARTITIONABLEREMOVEABLE
    565663 *
    566664 *      --  DRVTYPE_CDROM
    567665 *
    568  *      Call this only if doshIsFixedDisk
    569  *      returned FALSE.
     666 *      --  DRVTYPE_TAPE
     667 *
     668 *      --  DRVTYPE_VDISK
     669 *
     670 *      --  DRVTYPE_FLOPPY
     671 *
     672 *      --  DRVTYPE_UNKNOWN (255)
    570673 *
    571674 *      The BIOSPARAMETERBLOCK must be filled
     
    575678 */
    576679
    577 BYTE doshQueryRemoveableType(PBIOSPARAMETERBLOCK pdp)
     680BYTE doshQueryDriveType(ULONG ulLogicalDrive,
     681                        PBIOSPARAMETERBLOCK pdp,
     682                        BOOL fFixed)
    578683{
    579684    if (pdp)
    580685    {
    581         if (    (pdp->bDeviceType == 7)     // "other"
    582              && (pdp->usBytesPerSector == 2048)
    583              && (pdp->usSectorsPerTrack == (USHORT)-1)
    584            )
    585             return DRVTYPE_CDROM;
    586         else if (pdp->fsDeviceAttr & DEVATTR_PARTITIONALREMOVEABLE) // 0x08
     686        if (pdp->fsDeviceAttr & DEVATTR_PARTITIONALREMOVEABLE) // 0x08
    587687            return DRVTYPE_PARTITIONABLEREMOVEABLE;
    588         else if (pdp->bDeviceType == 6)     // tape
    589             return DRVTYPE_TAPE;
    590     }
    591 
    592     return (0);
     688        else if (fFixed)
     689            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)
     696        {
     697            case DEVTYPE_TAPE: // 6
     698                return DRVTYPE_TAPE;
     699
     700            case DEVTYPE_48TPI:     // 0, 360k  5.25" floppy
     701            case DEVTYPE_96TPI:     // 1, 1.2M  5.25" floppy
     702            case DEVTYPE_35:        // 2, 720k  3.5" floppy
     703            case DEVTYPE_OTHER:     // 7, 1.44  3.5" floppy
     704                                    //    1.84M 3.5" floppy
     705            case DEVTYPE_35_288MB:
     706                if (    (ulLogicalDrive == 1)
     707                     || (ulLogicalDrive == 2)
     708                   )
     709                    return DRVTYPE_FLOPPY;
     710                else
     711                    return DRVTYPE_VDISK;
     712
     713            case DEVTYPE_RWOPTICAL: // 8, what is this?!?
     714                return DRVTYPE_FLOPPY;
     715        }
     716    }
     717
     718    return (DRVTYPE_UNKNOWN);
    593719}
    594720
     
    854980
    855981APIRET doshQueryMedia(ULONG ulLogicalDrive,
    856                       BOOL fCDROM,
     982                      BOOL fCDROM,             // in: is drive CD-ROM?
    857983                      ULONG fl)                // in: DRVFL_* flags
    858984{
     
    9781104
    9791105            if (    (!arc)
    980                  && (DRVTYPE_CDROM == doshQueryRemoveableType(&bpb))
     1106                 && (DRVTYPE_CDROM == doshQueryDriveType(ulLogicalDrive,
     1107                                                         &bpb,
     1108                                                         fFixed))
    9811109               )
    9821110            {
     
    10351163 *
    10361164 *      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
     1165 *      ready" popups, hopefully.
    10471166 *
    10481167 *      fl can be any combination of the following:
     
    10551174 *          default values will be returned.
    10561175 *
     1176 *      --  DRVFL_CHECKEAS: drive should always be
     1177 *          checked for EA support. If this is set,
     1178 *          we will call DosFSCtl for the non-well-known
     1179 *          file systems so we will always have a
     1180 *          value for the DFL_SUPPORTS_EAS flags.
     1181 *          Otherwise that flag might or might not
     1182 *          be set correctly.
     1183 *
     1184 *          The EA support returned by DosFSCtl
     1185 *          might not be correct for remote file
     1186 *          systems since not all of them support
     1187 *          that query.
     1188 *
     1189 *      --  DRVFL_CHECKLONGNAMES: drive should always be
     1190 *          checked for longname support. If this is
     1191 *          set, we will try a DosOpen on the drive
     1192 *          to see if it supports long filenames
     1193 *          (unless it's a "well-known" file-system
     1194 *          and we know it does). In enabled, the
     1195 *          DFL_SUPPORTS_LONGNAMES flag is reliable.
     1196 *
    10571197 *      This should return only one of the following:
    1058  *
    1059  *      --  ERROR_INVALID_DRIVE: drive letter is invalid
    1060  *
    1061  *      --  ERROR_DRIVE_LOCKED
    10621198 *
    10631199 *      --  NO_ERROR: disk info was filled, but not
    10641200 *          necessarily all info was available (e.g.
    10651201 *          if no media was present in CD-ROM drive).
     1202 *          See remarks below.
     1203 *
     1204 *      --  ERROR_INVALID_DRIVE 15): ulLogicalDrive
     1205 *          is not used at all (invalid drive letter)
     1206 *
     1207 *      --  ERROR_BAD_UNIT (20): if drive was renamed for
     1208 *          some reason (according to user reports
     1209 *
     1210 *      --  ERROR_NOT_READY (21): for ZIP disks where
     1211 *          no media is inserted, depending on the
     1212 *          driver apparently... normally ZIP drive
     1213 *          letters should disappear when no media
     1214 *          is present
     1215 *
     1216 *      --  ERROR_DRIVE_LOCKED (108)
     1217 *
     1218 *      So in order to check whether a drive is present
     1219 *      and available, use this function as follows:
     1220 *
     1221 *      1)  Call this function and check whether it
     1222 *          returns NO_ERROR for the given drive.
     1223 *          This will rule out invalid drive letters
     1224 *          and drives that are presently locked.
     1225 *
     1226 *      2)  If so, check whether XDISKINFO.flDevice
     1227 *          has the DFL_MEDIA_PRESENT flag set.
     1228 *          This will rule out removeable drives without
     1229 *          media and unformatted hard disks.
     1230 *
     1231 *      3)  If so, you can test the other fields if
     1232 *          you need more information. For example,
     1233 *          it would not be a good idea to create
     1234 *          a new file if the bType field is
     1235 *          DRVTYPE_CDROM.
     1236 *
     1237 *          If you want to exclude removeable disks,
     1238 *          instead of checking bType, you should
     1239 *          rather check flDevice for the DFL_FIXED
     1240 *          flag, which will be set for ZIP drives also.
     1241 *
     1242 *      Remarks for special drive types:
     1243 *
     1244 *      --  Hard disks always have bType == DRVTYPE_HARDDISK.
     1245 *          For them, we always check the file system.
     1246 *          If this is reported as "UNKNOWN", this means
     1247 *          that the drive is unformatted or formatted
     1248 *          with a file system that OS/2 does not understand
     1249 *          (e.g. NTFS). Only in that case, flDevice
     1250 *          has the DFL_MEDIA_PRESENT bit clear.
     1251 *
     1252 *          DFL_FIXED is always set.
     1253 *
     1254 *      --  Remote (LAN) drives always have bType == DRVTYPE_LAN.
     1255 *          flDevice will always have the DFL_REMOTE and
     1256 *          DFL_MEDIA_PRESENT bits set.
     1257 *
     1258 *      --  ZIP disks will have bType == DRVTYPE_PARTITIONABLEREMOVEABLE.
     1259 *          For them, flDevice will have both the
     1260 *          and DFL_PARTITIONABLEREMOVEABLE and DFL_FIXED
     1261 *          bits set.
     1262 *
     1263 *          ZIP disks are a bit special because they are
     1264 *          dynamically mounted and unmounted when media
     1265 *          is inserted and removed. In other words, if
     1266 *          no media is present, the drive letter becomes
     1267 *          invalid.
     1268 *
     1269 *      --  CD-ROM and DVD drives and CD writers will always
     1270 *          be reported as DRVTYPE_CDROM. The DFL_FIXED bit
     1271 *          will be clear always. For them, always check the
     1272 *          DFL_MEDIA_PRESENT present bit to avoid "Drive not
     1273 *          ready" popups.
     1274 *
     1275 *          As a special goody, we can also determine if the
     1276 *          drive currently has audio media inserted (which
     1277 *          would provoke errors also), by setting the
     1278 *          DFL_AUDIO_CD bit.
    10661279 *
    10671280 *@@added V0.9.16 (2002-01-13) [umoeller]
     
    10761289    HFILE   hf;
    10771290    ULONG   dummy;
    1078     BOOL    fCheck = TRUE;
     1291    BOOL    fCheck = TRUE,
     1292            fCheckFS = FALSE,
     1293            fCheckLongnames = FALSE,
     1294            fCheckEAs = FALSE;
    10791295
    10801296    memset(pdi, 0, sizeof(XDISKINFO));
     
    11001316            pdi->flDevice  = DFL_MEDIA_PRESENT | DFL_SUPPORTS_EAS;
    11011317            strcpy(pdi->szFileSystem, "FAT");
    1102             pdi->bFileSystem = FSYS_FAT;
     1318            pdi->lFileSystem = FSYS_FAT;
    11031319        }
    11041320    }
     
    11121328                              &fFixed);
    11131329
    1114         if (arc == ERROR_INVALID_DRIVE)
    1115             // drive letter doesn't exist at all:
    1116             pdi->fPresent = FALSE;
    1117             // return this APIRET
    1118         else
     1330        switch (arc)
    11191331        {
    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             {
     1332            case ERROR_INVALID_DRIVE:
     1333                // drive letter doesn't exist at all:
     1334                pdi->fPresent = FALSE;
     1335                // return this APIRET
     1336            break;
     1337
     1338            case ERROR_NOT_SUPPORTED:       // 50 for network drives
    11691339                // we get this for remote drives added
    11701340                // via "net use", so set these flags
    11711341                pdi->bType = DRVTYPE_LAN;
    1172                 pdi->bFileSystem = FSYS_REMOTE;
     1342                pdi->lFileSystem = FSYS_REMOTE;
    11731343                pdi->flDevice |= DFL_REMOTE | DFL_MEDIA_PRESENT;
    11741344                // but still check what file-system we
     
    11761346                fCheckFS = TRUE;
    11771347                fCheckLongnames = TRUE;
    1178             }
    1179 
    1180             if (fCheckFS)
     1348                fCheckEAs = TRUE;
     1349            break;
     1350
     1351            case NO_ERROR:
    11811352            {
    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))))
     1353                if (fFixed)
    11871354                {
    1188                     if (!stricmp(pdi->szFileSystem, "FAT"))
     1355                    // fixed drive:
     1356                    pdi->flDevice |= DFL_FIXED | DFL_MEDIA_PRESENT;
     1357
     1358                    fCheckFS = TRUE;
     1359                    fCheckLongnames = TRUE;
     1360                    fCheckEAs = TRUE;
     1361                }
     1362
     1363                if (!(arc = doshQueryDiskParams(ulLogicalDrive,
     1364                                                &pdi->bpb)))
     1365                {
     1366                    BYTE bTemp = doshQueryDriveType(ulLogicalDrive,
     1367                                                    &pdi->bpb,
     1368                                                    fFixed);
     1369                    if (bTemp != DRVTYPE_UNKNOWN)
    11891370                    {
    1190                         pdi->bFileSystem = FSYS_FAT;
    1191                         pdi->flDevice |= DFL_SUPPORTS_EAS;
    1192                         fCheckLongnames = FALSE;
     1371                        // recognized: store it then
     1372                        pdi->bType = bTemp;
     1373
     1374                        if (bTemp == DRVTYPE_PARTITIONABLEREMOVEABLE)
     1375                            pdi->flDevice |=    DFL_FIXED
     1376                                              | DFL_PARTITIONABLEREMOVEABLE;
    11931377                    }
    1194                     else if (    (!stricmp(pdi->szFileSystem, "HPFS"))
    1195                               || (!stricmp(pdi->szFileSystem, "JFS"))
    1196                             )
     1378
     1379                    if (!fFixed)
    11971380                    {
    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;
     1381                        // removeable:
     1382
     1383                        // before checking the drive, try if we have media
     1384                        if (!(arc = doshQueryMedia(ulLogicalDrive,
     1385                                                   (pdi->bType == DRVTYPE_CDROM),
     1386                                                   fl)))
     1387                        {
     1388                            pdi->flDevice |= DFL_MEDIA_PRESENT;
     1389                            fCheckFS = TRUE;
     1390                            fCheckLongnames = TRUE;
     1391                                    // but never EAs
     1392                        }
     1393                        else if (arc == ERROR_AUDIO_CD_ROM)
     1394                        {
     1395                            pdi->flDevice |= DFL_AUDIO_CD;
     1396                            // do not check longnames and file-system
     1397                        }
     1398                        else
     1399                            pdi->arcQueryMedia = arc;
     1400
     1401                        arc = NO_ERROR;
    12161402                    }
    12171403                }
    1218                 // else if this failed, we had an error popup!!
    1219                 // shouldn't happen!!
     1404                else
     1405                    pdi->arcQueryDiskParams = arc;
    12201406            }
    1221 
    1222             if (fCheckLongnames)
     1407            break;
     1408
     1409            default:
     1410                pdi->arcIsFixedDisk = arc;
     1411                // and return this
     1412            break;
     1413
     1414        } // end swich arc = doshIsFixedDisk(ulLogicalDrive, &fFixed);
     1415    }
     1416
     1417    if (fCheckFS)
     1418    {
     1419        // TRUE only for local fixed disks or
     1420        // remote drives or if media was present above
     1421        if (!(arc = doshQueryDiskFSType(ulLogicalDrive,
     1422                                        pdi->szFileSystem,
     1423                                        sizeof(pdi->szFileSystem))))
     1424        {
     1425            if (!stricmp(pdi->szFileSystem, "UNKNOWN"))
    12231426            {
    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;
     1427                // this is returned by the stupid DosQueryFSAttach
     1428                // if the file system is not recognized by OS/2,
     1429                // or if the drive is unformatted
     1430                pdi->lFileSystem = FSYS_UNKNOWN;
     1431                pdi->flDevice &= ~DFL_MEDIA_PRESENT;
     1432                fCheckLongnames = FALSE;
     1433                fCheckEAs = FALSE;
     1434                        // should we return ERROR_NOT_DOS_DISK (26)
     1435                        // in this case?
     1436            }
     1437            else if (!stricmp(pdi->szFileSystem, "FAT"))
     1438            {
     1439                pdi->lFileSystem = FSYS_FAT;
     1440                pdi->flDevice |= DFL_SUPPORTS_EAS;
     1441                fCheckLongnames = FALSE;
     1442                fCheckEAs = FALSE;
     1443            }
     1444            else if (    (!stricmp(pdi->szFileSystem, "HPFS"))
     1445                      || (!stricmp(pdi->szFileSystem, "JFS"))
     1446                    )
     1447            {
     1448                pdi->lFileSystem = FSYS_HPFS_JFS;
     1449                pdi->flDevice |= DFL_SUPPORTS_EAS | DFL_SUPPORTS_LONGNAMES;
     1450                fCheckLongnames = FALSE;
     1451                fCheckEAs = FALSE;
     1452            }
     1453            else if (!stricmp(pdi->szFileSystem, "CDFS"))
     1454                pdi->lFileSystem = FSYS_CDFS;
     1455            else if (    (!stricmp(pdi->szFileSystem, "FAT32"))
     1456                      || (!stricmp(pdi->szFileSystem, "ext2"))
     1457                    )
     1458            {
     1459                pdi->lFileSystem = FSYS_FAT32_EXT2;
     1460                fCheckLongnames = TRUE;
     1461                fCheckEAs = TRUE;
     1462            }
     1463            else if (!stricmp(pdi->szFileSystem, "RAMFS"))
     1464            {
     1465                pdi->lFileSystem = FSYS_RAMFS;
     1466                pdi->flDevice |= DFL_SUPPORTS_EAS | DFL_SUPPORTS_LONGNAMES;
     1467                fCheckLongnames = FALSE;
     1468                fCheckEAs = FALSE;
     1469            }
     1470            else if (!stricmp(pdi->szFileSystem, "TVFS"))
     1471            {
     1472                pdi->lFileSystem = FSYS_TVFS;
     1473                fCheckLongnames = TRUE;
     1474                fCheckEAs = TRUE;
    12501475            }
    12511476        }
     1477        else
     1478            // store negative error code
     1479            pdi->lFileSystem = -(LONG)arc;
     1480    }
     1481
     1482    if (    (!arc)
     1483         && (fCheckLongnames)
     1484         && (fl & DRVFL_CHECKLONGNAMES)
     1485       )
     1486    {
     1487        CHAR szTemp[30] = "?:\\long.name.file";
     1488        szTemp[0]  = ulLogicalDrive + 'A' - 1;
     1489        if (!(arc = DosOpen(szTemp,
     1490                            &hf,
     1491                            &dummy,
     1492                            0,
     1493                            0,
     1494                            FILE_READONLY,
     1495                            OPEN_SHARE_DENYNONE | OPEN_FLAGS_NOINHERIT,
     1496                            0)))
     1497        {
     1498            DosClose(hf);
     1499        }
     1500
     1501        switch (arc)
     1502        {
     1503            case NO_ERROR:
     1504            case ERROR_OPEN_FAILED:
     1505            case ERROR_FILE_NOT_FOUND:      // returned by TVFS
     1506                pdi->flDevice |= DFL_SUPPORTS_LONGNAMES;
     1507            break;
     1508
     1509            // if longnames are not supported,
     1510            // we get ERROR_INVALID_NAME
     1511            default:
     1512                pdi->arcOpenLongnames = arc;
     1513            break;
     1514
     1515            // default:
     1516               //  printf("      drive %d returned %d\n", ulLogicalDrive, arc);
     1517        }
     1518
     1519        arc = NO_ERROR;
     1520    }
     1521
     1522    if (    (!arc)
     1523         && (fCheckEAs)
     1524         && (fl & DRVFL_CHECKEAS)
     1525       )
     1526    {
     1527        EASIZEBUF easb = {0};
     1528        ULONG   cbData = sizeof(easb),
     1529                cbParams = 0;
     1530        CHAR    szDrive[] = "?:\\";
     1531        szDrive[0] = pdi->cDriveLetter;
     1532        if (!(arc = DosFSCtl(&easb,
     1533                             cbData,
     1534                             &cbData,
     1535                             NULL, // params,
     1536                             cbParams,
     1537                             &cbParams,
     1538                             FSCTL_MAX_EASIZE,
     1539                             szDrive,
     1540                             -1,        // HFILE
     1541                             FSCTL_PATHNAME)))
     1542            if (easb.cbMaxEASize != 0)
     1543                        // the other field (cbMaxEAListSize) is 0 always, I think
     1544                pdi->flDevice |= DFL_SUPPORTS_EAS;
    12521545    }
    12531546
     
    21272420 */
    21282421
    2129 APIRET doshLockFile(PXFILE pFile)
     2422/* APIRET doshLockFile(PXFILE pFile)
    21302423{
    21312424    if (!pFile)
     
    21402433
    21412434    return (DosRequestMutexSem(pFile->hmtx, SEM_INDEFINITE_WAIT));
    2142 }
     2435} */
    21432436
    21442437/*
     
    21482441 */
    21492442
    2150 APIRET doshUnlockFile(PXFILE pFile)
     2443/* APIRET doshUnlockFile(PXFILE pFile)
    21512444{
    21522445    if (pFile)
     
    21542447
    21552448    return (ERROR_INVALID_PARAMETER);
    2156 }
     2449} */
    21572450
    21582451/*
     
    21982491                  ULONG fl)         // in: DRFL_* flags
    21992492{
    2200     APIRET arc;
     2493    APIRET arc = NO_ERROR;
    22012494    ULONG cb = *pcb;
    22022495    ULONG ulDummy;
    22032496
    2204     if (!(arc = doshLockFile(pFile)))   // this checks for pFile
     2497    // if (!(arc = doshLockFile(pFile)))   // this checks for pFile
    22052498    {
    22062499        *pcb = 0;
     
    23572650        }
    23582651
    2359         doshUnlockFile(pFile);
     2652        // doshUnlockFile(pFile);
    23602653    }
    23612654
     
    24442737
    24452738            if (!arc)
    2446                 if (!(arc = doshLockFile(pFile)))   // this checks for pFile
     2739                // if (!(arc = doshLockFile(pFile)))   // this checks for pFile
    24472740                {
    24482741                    ULONG cbWritten;
     
    24592752                    }
    24602753
    2461                     doshUnlockFile(pFile);
     2754                    // doshUnlockFile(pFile);
    24622755                }
    24632756
     
    24842777                   PCSZ pbData)     // in: ptr to bytes to write (must be cb bytes)
    24852778{
    2486     APIRET arc;
    2487     if (!(arc = doshLockFile(pFile)))   // this checks for pFile
     2779    APIRET arc = NO_ERROR;
     2780    // if (!(arc = doshLockFile(pFile)))   // this checks for pFile
    24882781    {
    24892782        ULONG cbWritten;
     
    25032796        }
    25042797
    2505         doshUnlockFile(pFile);
     2798        // doshUnlockFile(pFile);
    25062799    }
    25072800
     
    25822875        // request the mutex so that we won't be
    25832876        // taking the file away under someone's butt
    2584         if (!(arc = doshLockFile(pFile)))
     2877        // if (!(arc = doshLockFile(pFile)))
    25852878        {
    2586             HMTX hmtx = pFile->hmtx;
    2587             pFile->hmtx = NULLHANDLE;
     2879            // HMTX hmtx = pFile->hmtx;
     2880            // pFile->hmtx = NULLHANDLE;
    25882881
    25892882            // now that the file is locked,
     
    26012894            }
    26022895
    2603             doshUnlockFile(pFile);
    2604             DosCloseMutexSem(pFile->hmtx);
     2896            // doshUnlockFile(pFile);
     2897            // DosCloseMutexSem(pFile->hmtx);
    26052898        }
    26062899
     
    39614254    ULONG ul;
    39624255
    3963             printf("    type     fs       remot fixed parrm bootd       media audio eas   longn\n");
     4256            printf("Drive checker ("__DATE__")\n");
     4257            printf("    type   fs      remot fixed parrm bootd       media audio eas   longn\n");
    39644258
    39654259    for (ul = 1;
     
    39714265                                      0, // DRVFL_TOUCHFLOPPIES,
    39724266                                      &xdi);
    3973         PCSZ pcsz = "unknown";
    39744267
    39754268        printf(" %c: ", xdi.cDriveLetter, ul);
     
    39804273        {
    39814274            if (arc)
    3982                 printf("error %4d\n", arc);
     4275                printf("error %d (IsFixedDisk: %d, QueryDiskParams %d, QueryMedia %d)\n",
     4276                        arc,
     4277                        xdi.arcIsFixedDisk,
     4278                        xdi.arcQueryDiskParams,
     4279                        xdi.arcQueryMedia);
    39834280            else
    39844281            {
     
    39974294                ULONG ul2;
    39984295
     4296                PCSZ pcsz = NULL;
     4297
    39994298                switch (xdi.bType)
    40004299                {
    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;
     4300                    case DRVTYPE_HARDDISK:  pcsz = "HDISK ";    break;
     4301                    case DRVTYPE_FLOPPY:    pcsz = "FLOPPY"; break;
     4302                    case DRVTYPE_TAPE:      pcsz = "TAPE  "; break;
     4303                    case DRVTYPE_VDISK:     pcsz = "VDISK "; break;
     4304                    case DRVTYPE_CDROM:     pcsz = "CDROM "; break;
     4305                    case DRVTYPE_LAN:       pcsz = "LAN   "; break;
    40074306                    case DRVTYPE_PARTITIONABLEREMOVEABLE:
    4008                                             pcsz = "PARTREMV"; break;
     4307                                            pcsz = "PRTREM"; break;
     4308                    default:
     4309                                            printf("bType=%d, BPB.bDevType=%d",
     4310                                                    xdi.bType,
     4311                                                    xdi.bpb.bDeviceType);
     4312                                            printf("\n           ");
    40094313                }
    40104314
    4011                 printf("%s ", pcsz);
    4012 
    4013                 printf("%8s ", xdi.szFileSystem); // , xdi.bFileSystem);
     4315                if (pcsz)
     4316                    printf("%s ", pcsz);
     4317
     4318                if (xdi.lFileSystem < 0)
     4319                    // negative means error
     4320                    printf("E%3d    ", xdi.lFileSystem); // , xdi.bFileSystem);
     4321                else
     4322                    printf("%7s ", xdi.szFileSystem); // , xdi.bFileSystem);
    40144323
    40154324                for (ul2 = 0;
     
    40204329                        printf("  X   ");
    40214330                    else
    4022                         printf("  -   ");
     4331                        if (    (xdi.arcOpenLongnames)
     4332                             && (aulFlags[ul2] == DFL_SUPPORTS_LONGNAMES)
     4333                           )
     4334                            printf(" E%03d ", xdi.arcOpenLongnames);
     4335                        else
     4336                            printf("  -   ");
    40234337                }
    40244338                printf("\n");
Note: See TracChangeset for help on using the changeset viewer.