Changeset 716 for trunk/src


Ignore:
Timestamp:
Apr 30, 2010, 12:17:16 AM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: Do DosOpen() with OPEN_FLAGS_FAIL_ON_ERROR on drive letters instead of DosQueryFSAttach() to check if a removable drive is actually accessible or not. This eliminates the hardware error popups in Qt file dialogs even with AUTOFAIL=NO/absent in config.sys.

Location:
trunk/src/corelib/io
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/corelib/io/qfsfileengine_iterator_os2.cpp

    r683 r716  
    133133            // delays and noise for drives with no media inserted
    134134            BYTE drv[3] = { path.at(0).cell(), ':', '\0' };
    135             BYTE buf[sizeof(FSQBUFFER2) + (3 * CCHMAXPATH)] = {0};
    136             ULONG bufSize = sizeof(buf);
    137             PFSQBUFFER2 pfsq = (PFSQBUFFER2) buf;
    138             arc = DosQueryFSAttach(drv, 0, FSAIL_QUERYNAME, pfsq, &bufSize);
     135            HFILE hdrv;
     136            ULONG action;
     137            arc = DosOpen(drv, &hdrv, &action, 0, FILE_NORMAL, FILE_OPEN,
     138                          OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE |
     139                          OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR, NULL);
     140            if (arc == NO_ERROR) {
     141                // sometimes, 0 is returned for drive A: with no media in it
     142                // but SYS0045 pops up when doing stat(). The trick is to
     143                // read from the handle to detect this case.
     144                char buf;
     145                arc = DosRead(hdrv, &buf, sizeof(buf), &action);
     146                if (arc != ERROR_SECTOR_NOT_FOUND)
     147                    arc = NO_ERROR;
     148                DosClose(hdrv);
     149            }
    139150        }
    140         if (arc != NO_ERROR) {
     151        if (arc == ERROR_NOT_READY || arc == ERROR_DISK_CHANGE ||
     152            arc == ERROR_SECTOR_NOT_FOUND || arc == ERROR_INVALID_DRIVE) {
    141153            that->platform->dir = 0;
    142154            that->platform->done = true;
  • trunk/src/corelib/io/qfsfileengine_os2.cpp

    r690 r716  
    617617                // media inserted will cause an unnecessary delay and noise.
    618618                BYTE drv[3] = { filePath.at(0).cell(), ':', '\0' };
    619                 BYTE buf[sizeof(FSQBUFFER2) + (3 * CCHMAXPATH)] = {0};
    620                 ULONG bufSize = sizeof(buf);
    621                 PFSQBUFFER2 pfsq = (PFSQBUFFER2) buf;
    622                 APIRET arc = DosQueryFSAttach(drv, 0, FSAIL_QUERYNAME, pfsq,
    623                                               &bufSize);
    624                 if (arc != NO_ERROR) {
     619                HFILE hdrv;
     620                ULONG action;
     621                APIRET arc = DosOpen(drv, &hdrv, &action, 0, FILE_NORMAL, FILE_OPEN,
     622                                     OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE |
     623                                     OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR, NULL);
     624                if (arc == NO_ERROR) {
     625                    // sometimes, 0 is returned for drive A: with no media in it
     626                    // but SYS0045 pops up when doing stat(). The trick is to
     627                    // read from the handle to detect this case.
     628                    char buf;
     629                    arc = DosRead(hdrv, &buf, sizeof(buf), &action);
     630                    if (arc != ERROR_SECTOR_NOT_FOUND)
     631                        arc = NO_ERROR;
     632                    DosClose(hdrv);
     633                }
     634                if (arc == ERROR_NOT_READY || arc == ERROR_DISK_CHANGE ||
     635                    arc == ERROR_SECTOR_NOT_FOUND) {
     636                    // it must be a removable drive with no media in it
     637                    could_stat = false;
     638                } else if (arc == ERROR_INVALID_DRIVE) {
     639                    // just an invalid drive letter
    625640                    could_stat = false;
    626641                } else {
Note: See TracChangeset for help on using the changeset viewer.