Ignore:
Timestamp:
Nov 22, 2001, 5:03:23 PM (24 years ago)
Author:
sandervl
Message:

floppy change fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/hmdisk.cpp

    r7272 r7430  
    1 /* $Id: hmdisk.cpp,v 1.27 2001-10-30 00:46:17 sandervl Exp $ */
     1/* $Id: hmdisk.cpp,v 1.28 2001-11-22 16:03:23 sandervl Exp $ */
    22
    33/*
     
    3737    ULONG     driveLetter;
    3838    ULONG     driveType;
     39    ULONG     dwVolumelabel;
    3940    CHAR      signature[8];
    4041    DWORD     dwAccess;
     
    137138        DRIVE_INFO *drvInfo = (DRIVE_INFO *)malloc(sizeof(DRIVE_INFO));
    138139        if(drvInfo == NULL) {
     140             DebugInt3();
    139141             if(pHMHandleData->hHMHandle) OSLibDosClose(pHMHandleData->hHMHandle);
    140142             return ERROR_OUTOFMEMORY;
     
    180182        }
    181183
     184        if(hFile) {
     185            OSLibDosQueryVolumeSerialAndName(1 + drvInfo->driveLetter - 'A', &drvInfo->dwVolumelabel, NULL, 0);
     186        }
     187
    182188        return (NO_ERROR);
    183189    }
     
    217223             return 0;
    218224        }
    219         else return hFile;
     225        OSLibDosQueryVolumeSerialAndName(1 + drvInfo->driveLetter - 'A', &drvInfo->dwVolumelabel, NULL, 0);
     226        return hFile;
    220227    }
    221228    return 0;
     
    566573        }
    567574
    568         char   temp;
    569         ULONG  bytesread, oldmode;
     575        ULONG  volumelabel;
    570576        APIRET rc;
    571577
     
    580586
    581587        //Applications can use this IOCTL to check if the floppy has been changed
    582         //OSLibDosGetDiskGeometry won't fail when that happens so we read one
    583         //byte from the disk and return ERROR_MEDIA_CHANGED if it fails with
    584         //ERROR_WRONG_DISK
    585         oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
    586         rc = OSLibDosRead(pHMHandleData->hHMHandle, (PVOID)&temp,
    587                           1, &bytesread);
    588         SetErrorMode(oldmode);
    589         if(rc == FALSE) {
    590             dprintf(("IOCTL_DISK_GET_DRIVE_GEOMETRY: DosRead failed with rc %d", GetLastError()));
    591             if(GetLastError() == ERROR_WRONG_DISK) {
    592                 SetLastError(ERROR_MEDIA_CHANGED);
    593                 return FALSE;
    594             }
    595         }
    596         else OSLibDosSetFilePtr(pHMHandleData->hHMHandle, -1, OSLIB_SETPTR_FILE_CURRENT);
     588        //OSLibDosGetDiskGeometry won't fail when that happens so we read the
     589        //volume label from the disk and return ERROR_MEDIA_CHANGED if the volume
     590        //label has changed
     591        //TODO: Find better way to determine if floppy was removed or switched
     592        rc = OSLibDosQueryVolumeSerialAndName(1 + drvInfo->driveLetter - 'A', &volumelabel, NULL, 0);
     593        if(rc) {
     594            dprintf(("IOCTL_DISK_GET_DRIVE_GEOMETRY: OSLibDosQueryVolumeSerialAndName failed with rc %d", GetLastError()));
     595            if(pHMHandleData->hHMHandle) OSLibDosClose(pHMHandleData->hHMHandle);
     596            pHMHandleData->hHMHandle = 0;
     597            SetLastError(ERROR_MEDIA_CHANGED);
     598            return FALSE;
     599        }
     600        if(volumelabel != drvInfo->dwVolumelabel) {
     601            dprintf(("IOCTL_DISK_GET_DRIVE_GEOMETRY: volume changed %x -> %x", drvInfo->dwVolumelabel, volumelabel));
     602            SetLastError(ERROR_MEDIA_CHANGED);
     603            return FALSE;
     604        }
    597605
    598606        if(OSLibDosGetDiskGeometry(pHMHandleData->hHMHandle, drvInfo->driveLetter, pGeom) == FALSE) {
     
    12151223  }
    12161224
     1225  //If we didn't get an OS/2 handle for the disk before, get one now
    12171226  if(!pHMHandleData->hHMHandle) {
    12181227      DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
     
    13121321  return ret;
    13131322}
     1323/*****************************************************************************
     1324 * Name      : BOOL ReadFileEx
     1325 * Purpose   : The ReadFileEx function reads data from a file asynchronously.
     1326 *             It is designed solely for asynchronous operation, unlike the
     1327 *             ReadFile function, which is designed for both synchronous and
     1328 *             asynchronous operation. ReadFileEx lets an application perform
     1329 *             other processing during a file read operation.
     1330 *             The ReadFileEx function reports its completion status asynchronously,
     1331 *             calling a specified completion routine when reading is completed
     1332 *             and the calling thread is in an alertable wait state.
     1333 * Parameters: HANDLE       hFile                handle of file to read
     1334 *             LPVOID       lpBuffer             address of buffer
     1335 *             DWORD        nNumberOfBytesToRead number of bytes to read
     1336 *             LPOVERLAPPED lpOverlapped         address of offset
     1337 *             LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine
     1338 * Variables :
     1339 * Result    : TRUE / FALSE
     1340 * Remark    :
     1341 * Status    : UNTESTED STUB
     1342 *
     1343 * Author    : Patrick Haller [Mon, 1998/06/15 08:00]
     1344 *****************************************************************************/
     1345BOOL HMDeviceDiskClass::ReadFileEx(PHMHANDLEDATA pHMHandleData,
     1346                           LPVOID       lpBuffer,
     1347                           DWORD        nNumberOfBytesToRead,
     1348                           LPOVERLAPPED lpOverlapped,
     1349                           LPOVERLAPPED_COMPLETION_ROUTINE  lpCompletionRoutine)
     1350{
     1351  dprintf(("ERROR: ReadFileEx(%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n",
     1352           pHMHandleData->hHMHandle,
     1353           lpBuffer,
     1354           nNumberOfBytesToRead,
     1355           lpOverlapped,
     1356           lpCompletionRoutine));
     1357  return FALSE;
     1358}
     1359
     1360
     1361/*****************************************************************************
     1362 * Name      : BOOL HMDeviceDiskClass::WriteFile
     1363 * Purpose   : write data to handle / device
     1364 * Parameters: PHMHANDLEDATA pHMHandleData,
     1365 *             LPCVOID       lpBuffer,
     1366 *             DWORD         nNumberOfBytesToWrite,
     1367 *             LPDWORD       lpNumberOfBytesWritten,
     1368 *             LPOVERLAPPED  lpOverlapped
     1369 * Variables :
     1370 * Result    : Boolean
     1371 * Remark    :
     1372 * Status    :
     1373 *
     1374 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
     1375 *****************************************************************************/
     1376
     1377BOOL HMDeviceDiskClass::WriteFile(PHMHANDLEDATA pHMHandleData,
     1378                                    LPCVOID       lpBuffer,
     1379                                    DWORD         nNumberOfBytesToWrite,
     1380                                    LPDWORD       lpNumberOfBytesWritten,
     1381                                    LPOVERLAPPED  lpOverlapped)
     1382{
     1383  LPVOID       lpRealBuf;
     1384  Win32MemMap *map;
     1385  DWORD        offset, byteswritten;
     1386  BOOL         bRC;
     1387
     1388  dprintf2(("KERNEL32: HMDeviceDiskClass::WriteFile %s(%08x,%08x,%08x,%08x,%08x) - stub?\n",
     1389           lpHMDeviceName,
     1390           pHMHandleData,
     1391           lpBuffer,
     1392           nNumberOfBytesToWrite,
     1393           lpNumberOfBytesWritten,
     1394           lpOverlapped));
     1395
     1396  DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
     1397  if(drvInfo == NULL) {
     1398      dprintf(("ERROR: DeviceIoControl: drvInfo == NULL!!!"));
     1399      DebugInt3();
     1400      SetLastError(ERROR_INVALID_HANDLE);
     1401      return FALSE;
     1402  }
     1403
     1404  //SvL: It's legal for this pointer to be NULL
     1405  if(lpNumberOfBytesWritten)
     1406    *lpNumberOfBytesWritten = 0;
     1407  else
     1408    lpNumberOfBytesWritten = &byteswritten;
     1409
     1410  if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
     1411    dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
     1412    SetLastError(ERROR_INVALID_PARAMETER);
     1413    return FALSE;
     1414  }
     1415  if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
     1416    dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
     1417  }
     1418
     1419  //If we didn't get an OS/2 handle for the disk before, get one now
     1420  if(!pHMHandleData->hHMHandle) {
     1421      DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
     1422      pHMHandleData->hHMHandle = OpenDisk(drvInfo);
     1423      if(!pHMHandleData->hHMHandle) {
     1424          dprintf(("No disk inserted; aborting"));
     1425          SetLastError(ERROR_NOT_READY);
     1426          return -1;
     1427      }
     1428  }
     1429  //NOTE: For now only allow an application to write to drive A
     1430  //      Might want to extend this to all removable media, but it's
     1431  //      too dangerous to allow win32 apps to write to the harddisk directly
     1432  if(drvInfo->driveLetter != 'A') {
     1433      SetLastError(ERROR_ACCESS_DENIED);
     1434      return -1;
     1435  }
     1436
     1437
     1438  //SvL: DosWrite doesn't like reading from memory addresses returned by
     1439  //     DosAliasMem -> search for original memory mapped pointer and use
     1440  //     that one + commit pages if not already present
     1441  map = Win32MemMapView::findMapByView((ULONG)lpBuffer, &offset, MEMMAP_ACCESS_READ);
     1442  if(map) {
     1443    lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset);
     1444    DWORD nrpages = nNumberOfBytesToWrite/4096;
     1445    if(offset & 0xfff)
     1446        nrpages++;
     1447    if(nNumberOfBytesToWrite & 0xfff)
     1448        nrpages++;
     1449
     1450    map->commitPage(offset & ~0xfff, TRUE, nrpages);
     1451  }
     1452  else  lpRealBuf = (LPVOID)lpBuffer;
     1453
     1454  if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) {
     1455    dprintf(("ERROR: Overlapped IO not yet implememented!!"));
     1456  }
     1457//  else {
     1458    bRC = OSLibDosWrite(pHMHandleData->hHMHandle,
     1459                            (PVOID)lpRealBuf,
     1460                            nNumberOfBytesToWrite,
     1461                            lpNumberOfBytesWritten);
     1462//  }
     1463
     1464  dprintf2(("KERNEL32: HMDeviceDiskClass::WriteFile returned %08xh\n",
     1465           bRC));
     1466
     1467  return bRC;
     1468}
     1469
     1470/*****************************************************************************
     1471 * Name      : BOOL WriteFileEx
     1472 * Purpose   : The WriteFileEx function writes data to a file. It is designed
     1473 *             solely for asynchronous operation, unlike WriteFile, which is
     1474 *             designed for both synchronous and asynchronous operation.
     1475 *             WriteFileEx reports its completion status asynchronously,
     1476 *             calling a specified completion routine when writing is completed
     1477 *             and the calling thread is in an alertable wait state.
     1478 * Parameters: HANDLE       hFile                handle of file to write
     1479 *             LPVOID       lpBuffer             address of buffer
     1480 *             DWORD        nNumberOfBytesToRead number of bytes to write
     1481 *             LPOVERLAPPED lpOverlapped         address of offset
     1482 *             LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine
     1483 * Variables :
     1484 * Result    : TRUE / FALSE
     1485 * Remark    :
     1486 * Status    : UNTESTED STUB
     1487 *
     1488 * Author    : Patrick Haller [Mon, 1998/06/15 08:00]
     1489 *****************************************************************************/
     1490
     1491BOOL HMDeviceDiskClass::WriteFileEx(PHMHANDLEDATA pHMHandleData,
     1492                           LPVOID       lpBuffer,
     1493                           DWORD        nNumberOfBytesToWrite,
     1494                           LPOVERLAPPED lpOverlapped,
     1495                           LPOVERLAPPED_COMPLETION_ROUTINE  lpCompletionRoutine)
     1496{
     1497  dprintf(("ERROR: WriteFileEx(%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n",
     1498           pHMHandleData->hHMHandle,
     1499           lpBuffer,
     1500           nNumberOfBytesToWrite,
     1501           lpOverlapped,
     1502           lpCompletionRoutine));
     1503  return FALSE;
     1504}
     1505
     1506/*****************************************************************************
     1507 * Name      : DWORD HMDeviceDiskClass::GetFileType
     1508 * Purpose   : determine the handle type
     1509 * Parameters: PHMHANDLEDATA pHMHandleData
     1510 * Variables :
     1511 * Result    : API returncode
     1512 * Remark    :
     1513 * Status    :
     1514 *
     1515 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
     1516 *****************************************************************************/
     1517
     1518DWORD HMDeviceDiskClass::GetFileType(PHMHANDLEDATA pHMHandleData)
     1519{
     1520  dprintf2(("KERNEL32: HMDeviceDiskClass::GetFileType %s(%08x)\n",
     1521             lpHMDeviceName,
     1522             pHMHandleData));
     1523
     1524  return FILE_TYPE_DISK;
     1525}
    13141526//******************************************************************************
    13151527//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.