Ignore:
Timestamp:
Jun 1, 2000, 1:28:48 PM (25 years ago)
Author:
sandervl
Message:

Rewrote file io apis

File:
1 edited

Legend:

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

    r3588 r3642  
    1 /* $Id: HandleManager.cpp,v 1.39 2000-05-22 19:07:52 sandervl Exp $ */
     1/* $Id: HandleManager.cpp,v 1.40 2000-06-01 11:28:42 sandervl Exp $ */
    22
    33/*
     
    5252#include "HMOpen32.h"
    5353#include "HMEvent.h"
     54#include "HMFile.h"
    5455#include "HMMutex.h"
    5556#include "HMSemaphore.h"
     
    125126  HMDeviceHandler        *pHMOpen32;      /* default handle manager instance */
    126127  HMDeviceHandler        *pHMEvent;        /* static instances of subsystems */
     128  HMDeviceHandler        *pHMFile;
    127129  HMDeviceHandler        *pHMMutex;
    128130  HMDeviceHandler        *pHMSemaphore;
     
    354356    HMGlobals.pHMOpen32     = new HMDeviceOpen32Class("\\\\.\\");
    355357    HMGlobals.pHMEvent      = new HMDeviceEventClass("\\\\EVENT\\");
     358    HMGlobals.pHMFile       = new HMDeviceFileClass("\\\\FILE\\");
    356359    HMGlobals.pHMMutex      = new HMDeviceMutexClass("\\\\MUTEX\\");
    357360    HMGlobals.pHMSemaphore  = new HMDeviceSemaphoreClass("\\\\SEM\\");
     
    383386  delete HMGlobals.pHMOpen32;
    384387  delete HMGlobals.pHMEvent;
     388  delete HMGlobals.pHMFile;
    385389  delete HMGlobals.pHMMutex;
    386390  delete HMGlobals.pHMSemaphore;
     
    706710  HMDeviceHandler *pDeviceHandler;         /* device handler for this handle */
    707711  PHMHANDLEDATA   pHMHandleData;
    708   DWORD           rc;                                     /* API return code */
     712  BOOL            rc;                                     /* API return code */
    709713
    710714  if(HMHandleValidate(srchandle) != NO_ERROR)
     
    758762    HMCloseHandle(srchandle);
    759763
    760   if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
     764  if(rc == FALSE)     /* oops, creation failed within the device handler */
    761765  {
    762766    TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    763     SetLastError(rc);          /* Hehe, OS/2 and NT are pretty compatible :) */
    764767    return FALSE;                           /* signal error */
    765768  }
     
    827830    else
    828831      pHMHandleData  = NULL;
     832
     833    if(pDeviceHandler == HMGlobals.pHMOpen32) {
     834        pDeviceHandler = HMGlobals.pHMFile;
     835    }
    829836  }
    830837
     
    962969    pHMHandleData  = NULL;
    963970
     971  if(pDeviceHandler == HMGlobals.pHMOpen32) {
     972    pDeviceHandler = HMGlobals.pHMFile;
     973  }
    964974
    965975  iIndexNew = _HMHandleGetFree();                         /* get free handle */
     
    10031013#endif
    10041014
    1005   if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
    1006   {
    1007     TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    1008     SetLastError(rc);          /* Hehe, OS/2 and NT are pretty compatible :) */
    1009     return (INVALID_HANDLE_VALUE);                           /* signal error */
    1010   }
    1011   else
    1012     SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
     1015  if(rc != NO_ERROR)     /* oops, creation failed within the device handler */
     1016  {
     1017        TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     1018        SetLastError(rc);          /* Hehe, OS/2 and NT are pretty compatible :) */
     1019        return (INVALID_HANDLE_VALUE);                           /* signal error */
     1020  }
     1021  else {
     1022        if(fuMode & (OF_DELETE|OF_EXIST)) {
     1023                //file handle already closed
     1024                TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     1025                return TRUE; //TODO: correct?
     1026        }
     1027        if(fuMode & OF_PARSE) {
     1028                TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     1029                return 0;
     1030        }
     1031        if(fuMode & OF_VERIFY) {
     1032                TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     1033                return 1; //TODO: correct?
     1034        }
     1035  }
    10131036
    10141037#ifdef DEBUG_LOCAL
     
    11191142  return (fResult);                                   /* deliver return code */
    11201143}
    1121 
     1144/*****************************************************************************
     1145 * Name      : HANDLE  HMReadFileEx
     1146 * Purpose   : Wrapper for the ReadFileEx() API
     1147 * Parameters:
     1148 * Variables :
     1149 * Result    :
     1150 * Remark    :
     1151 * Status    :
     1152 *
     1153 * Author    : SvL
     1154 *****************************************************************************/
     1155BOOL HMReadFileEx(HANDLE                     hFile,
     1156                  LPVOID                     lpBuffer,
     1157                  DWORD                      nNumberOfBytesToRead,
     1158                  LPOVERLAPPED               lpOverlapped,
     1159                  LPOVERLAPPED_COMPLETION_ROUTINE  lpCompletionRoutine)
     1160{
     1161  int       iIndex;                           /* index into the handle table */
     1162  BOOL      fResult;       /* result from the device handler's CloseHandle() */
     1163  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     1164
     1165                                                          /* validate handle */
     1166  iIndex = _HMHandleQuery(hFile);                           /* get the index */
     1167  if (-1 == iIndex)                                               /* error ? */
     1168  {
     1169    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
     1170    return (FALSE);                                        /* signal failure */
     1171  }
     1172
     1173  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1174  fResult = pHMHandle->pDeviceHandler->ReadFileEx(&pHMHandle->hmHandleData,
     1175                                                  lpBuffer,
     1176                                                  nNumberOfBytesToRead,
     1177                                                  lpOverlapped,
     1178                                                  lpCompletionRoutine);
     1179
     1180  return (fResult);                                   /* deliver return code */
     1181}
    11221182
    11231183/*****************************************************************************
     
    11341194
    11351195BOOL HMWriteFile(HANDLE       hFile,
    1136                         LPCVOID      lpBuffer,
    1137                         DWORD        nNumberOfBytesToWrite,
    1138                         LPDWORD      lpNumberOfBytesWritten,
    1139                         LPOVERLAPPED lpOverlapped)
     1196                 LPCVOID      lpBuffer,
     1197                 DWORD        nNumberOfBytesToWrite,
     1198                 LPDWORD      lpNumberOfBytesWritten,
     1199                 LPOVERLAPPED lpOverlapped)
    11401200{
    11411201  int       iIndex;                           /* index into the handle table */
     
    11571217                                                 lpNumberOfBytesWritten,
    11581218                                                 lpOverlapped);
     1219
     1220  return (fResult);                                   /* deliver return code */
     1221}
     1222
     1223/*****************************************************************************
     1224 * Name      : HANDLE  HMWriteFileEx
     1225 * Purpose   : Wrapper for the WriteFileEx() API
     1226 * Parameters:
     1227 * Variables :
     1228 * Result    :
     1229 * Remark    :
     1230 * Status    :
     1231 *
     1232 * Author    : SvL
     1233 *****************************************************************************/
     1234BOOL HMWriteFileEx(HANDLE                     hFile,
     1235                   LPVOID                     lpBuffer,
     1236                   DWORD                      nNumberOfBytesToWrite,
     1237                   LPOVERLAPPED               lpOverlapped,
     1238                   LPOVERLAPPED_COMPLETION_ROUTINE  lpCompletionRoutine)
     1239{
     1240  int       iIndex;                           /* index into the handle table */
     1241  BOOL      fResult;       /* result from the device handler's CloseHandle() */
     1242  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     1243
     1244                                                          /* validate handle */
     1245  iIndex = _HMHandleQuery(hFile);                           /* get the index */
     1246  if (-1 == iIndex)                                               /* error ? */
     1247  {
     1248    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
     1249    return (FALSE);                                        /* signal failure */
     1250  }
     1251
     1252  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1253  fResult = pHMHandle->pDeviceHandler->WriteFileEx(&pHMHandle->hmHandleData,
     1254                                                   lpBuffer,
     1255                                                   nNumberOfBytesToWrite,
     1256                                                   lpOverlapped,
     1257                                                   lpCompletionRoutine);
    11591258
    11601259  return (fResult);                                   /* deliver return code */
     
    15981697
    15991698BOOL HMUnlockFileEx(HANDLE        hFile,
    1600                     DWORD         dwFlags,
    16011699                    DWORD         dwReserved,
    16021700                    DWORD         nNumberOfBytesToLockLow,
     
    16181716  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
    16191717  dwResult = pHMHandle->pDeviceHandler->UnlockFileEx(&pHMHandle->hmHandleData,
    1620                                                      dwFlags,
    16211718                                                     dwReserved,
    16221719                                                     nNumberOfBytesToLockLow,
Note: See TracChangeset for help on using the changeset viewer.