Ignore:
Timestamp:
Jun 17, 1999, 8:22:43 PM (26 years ago)
Author:
phaller
Message:

Fix: major restructuring of Open32 handle management, HandleManager

File:
1 edited

Legend:

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

    r17 r111  
    1 /* $Id: HandleManager.cpp,v 1.2 1999-05-31 22:08:08 phaller Exp $ */
     1/* $Id: HandleManager.cpp,v 1.3 1999-06-17 18:21:35 phaller Exp $ */
    22
    33/*
     
    5050
    5151#include "HandleManager.H"
    52 
    53 #include <string.h>
     52#include "HMDevice.h"
     53#include "HMOpen32.h"
    5454
    5555
     
    127127                                         /* this MUST !!! be false initially */
    128128
     129  HMDeviceHandler *pHMOpen32;             /* default handle manager instance */
     130
    129131
    130132  ULONG         ulHandleLast;                   /* index of last used handle */
     
    165167  PHMDEVICE pHMDevice;                     /* iterator over the device table */
    166168
    167   for (pHMDevice = TabWin32Devices;    /* loop over all devices in the table */
    168        pHMDevice != NULL;
    169        pHMDevice = pHMDevice->pNext)
    170   {
    171     if (stricmp(pHMDevice->pszDeviceName,         /* case-insensitive search */
    172                 pszDeviceName) == 0)
    173       return (pHMDevice->pDeviceHandler);      /* OK, we've found our device */
    174   }
    175 
    176   return ((HMDeviceHandler *) NULL);               /* haven't found anything */
     169  if (pszDeviceName != NULL)
     170    for (pHMDevice = TabWin32Devices;  /* loop over all devices in the table */
     171         pHMDevice != NULL;
     172         pHMDevice = pHMDevice->pNext)
     173    {
     174      if (stricmp(pHMDevice->pszDeviceName,       /* case-insensitive search */
     175                  pszDeviceName) == 0)
     176        return (pHMDevice->pDeviceHandler);    /* OK, we've found our device */
     177    }
     178
     179  return (HMGlobals.pHMOpen32);    /* haven't found anything, return default */
    177180}
    178181
     
    199202  {
    200203                                                      /* free handle found ? */
    201     if (0 == TabWin32Handles[iLoop].hmHandleData.hHandle)
     204    if (0 == TabWin32Handles[iLoop].hmHandleData.hHMHandle)
    202205      return (iLoop);                    /* OK, then return it to the caller */
    203206  }
     
    234237
    235238                                                   /* Oops, invalid handle ! */
    236   if (TabWin32Handles[ulIndex].hmHandleData.hHandle != hHandle)
     239  if (TabWin32Handles[ulIndex].hmHandleData.hHMHandle != hHandle)
    237240    return (-1);                               /* nope, ERROR_INVALID_HANDLE */
    238241
     
    301304  if (HMGlobals.fIsInitialized != TRUE)
    302305  {
     306    HMGlobals.fIsInitialized = TRUE;                             /* OK, done */
     307
    303308    dprintf(("KERNEL32:HandleManager:HMInitialize() storing handles.\n"));
    304309
     
    312317    HMSetStdHandle(STD_ERROR_HANDLE,  GetStdHandle(STD_ERROR_HANDLE));
    313318
    314     HMGlobals.fIsInitialized = TRUE;                             /* OK, done */
     319                        /* create handle manager instance for Open32 handles */
     320    HMGlobals.pHMOpen32 = new HMDeviceOpen32Class("\\\\.\\");
    315321  }
    316322  return (NO_ERROR);
     
    336342  return (NO_ERROR);
    337343}
     344
     345
     346/*****************************************************************************/
     347/* handle translation buffer management                                      */
     348/*                                                                           */
     349/* Since some Win32 applications rely (!) on 16-bit handles, we've got to do */
     350/* 32-bit to 16-bit and vs vsa translation here.                             */
     351/* Filehandle-based functions should be routed via the handlemanager instead */
     352/* of going to Open32 directly.                                              */
     353/*****************************************************************************/
     354
     355
     356/*****************************************************************************
     357 * Name      : DWORD HMHandleAllocate
     358 * Purpose   : allocate a handle in the translation table
     359 * Parameters: PULONG pHandle16 - to return the allocated handle
     360 *             ULONG  hHandle32 - the associated OS/2 handle
     361 * Variables :
     362 * Result    : API returncode
     363 * Remark    : no parameter checking is done, phHandle may not be invalid
     364 *             hHandle32 shouldn't be 0
     365 * Status    :
     366 *
     367 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
     368 *****************************************************************************/
     369
     370DWORD  HMHandleAllocate (PULONG phHandle16,
     371                                 ULONG  hHandle32)
     372{
     373  register ULONG ulHandle;
     374
     375#ifdef DEBUG_LOCAL
     376  dprintf(("KERNEL32: HMHandleAllocate (%08xh,%08xh)\n",
     377           phHandle16,
     378           hHandle32));
     379#endif
     380
     381  ulHandle = HMGlobals.ulHandleLast;                      /* get free handle */
     382
     383  do
     384  {
     385                                                  /* check if handle is free */
     386    if (HMGlobals.TabTranslationHandles[ulHandle].hHandle32 == 0)
     387    {
     388      *phHandle16 = ulHandle;
     389      HMGlobals.TabTranslationHandles[ulHandle].hHandle32 = hHandle32;
     390      HMGlobals.ulHandleLast = ulHandle;          /* to shorten search times */
     391
     392      return (NO_ERROR);                                               /* OK */
     393    }
     394
     395    ulHandle++;                                        /* skip to next entry */
     396
     397    if (ulHandle >= MAX_TRANSLATION_HANDLES)               /* check boundary */
     398      ulHandle = 0;
     399  }
     400  while (ulHandle != HMGlobals.ulHandleLast);
     401
     402  return (ERROR_TOO_MANY_OPEN_FILES);                      /* OK, we're done */
     403}
     404
     405
     406/*****************************************************************************
     407 * Name      : DWORD HMHandleFree
     408 * Purpose   : free a handle from the translation table
     409 * Parameters: ULONG hHandle16 - the handle to be freed
     410 * Variables :
     411 * Result    : API returncode
     412 * Remark    : no parameter checking is done, hHandle16 MAY NEVER exceed
     413 *             the MAX_TRANSLATION_HANDLES boundary
     414 * Status    :
     415 *
     416 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
     417 *****************************************************************************/
     418
     419DWORD  HMHandleFree (ULONG hHandle16)
     420{
     421  ULONG rc;                                                /* API returncode */
     422
     423#ifdef DEBUG_LOCAL
     424  dprintf(("KERNEL32: HMHandleFree (%08xh)\n",
     425           hHandle16));
     426#endif
     427
     428  rc = HMHandleValidate(hHandle16);                         /* verify handle */
     429  if (rc != NO_ERROR)                                        /* check errors */
     430    return (rc);                                    /* raise error condition */
     431
     432  HMGlobals.TabTranslationHandles[hHandle16].hHandle32 = 0;      /* OK, done */
     433
     434  return (NO_ERROR);
     435}
     436
     437
     438/*****************************************************************************
     439 * Name      : DWORD HMHandleValidate
     440 * Purpose   : validate a handle through the translation table
     441 * Parameters: ULONG hHandle16 - the handle to be verified
     442 * Variables :
     443 * Result    : API returncode
     444 * Remark    :
     445 * Status    :
     446 *
     447 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
     448 *****************************************************************************/
     449
     450DWORD  HMHandleValidate (ULONG hHandle16)
     451{
     452#ifdef DEBUG_LOCAL
     453  dprintf(("KERNEL32: HMHandleValidate (%08xh)\n",
     454           hHandle16));
     455#endif
     456
     457  if (hHandle16 >= MAX_TRANSLATION_HANDLES)                /* check boundary */
     458    return (ERROR_INVALID_HANDLE);                  /* raise error condition */
     459
     460  if (HMGlobals.TabTranslationHandles[hHandle16].hHandle32 == 0)  /* valid ? */
     461    return (ERROR_INVALID_HANDLE);                  /* raise error condition */
     462
     463  return (NO_ERROR);
     464}
     465
     466
     467/*****************************************************************************
     468 * Name      : DWORD HMHandleTranslateToWin
     469 * Purpose   : translate a 32-bit OS/2 handle to the associated windows handle
     470 * Parameters: ULONG  hHandle32  - the OS/2 handle
     471 *             PULONG phHandle16 - the associated windows handle
     472 * Variables :
     473 * Result    : API returncode
     474 * Remark    :
     475 * Status    :
     476 *
     477 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
     478 *****************************************************************************/
     479
     480DWORD  HMHandleTranslateToWin (ULONG  hHandle32,
     481                                       PULONG phHandle16)
     482{
     483           ULONG rc;                                       /* API returncode */
     484  register ULONG ulIndex;                    /* index counter over the table */
     485
     486#ifdef DEBUG_LOCAL
     487  dprintf(("KERNEL32: HMHandleTranslateToWin (%08xh, %08xh)\n",
     488           hHandle32,
     489           phHandle16));
     490#endif
     491
     492  for (ulIndex = 0;
     493       ulIndex < MAX_TRANSLATION_HANDLES;
     494       ulIndex++)
     495  {
     496                                                      /* look for the handle */
     497    if (HMGlobals.TabTranslationHandles[ulIndex].hHandle32 == hHandle32)
     498    {
     499      *phHandle16 = ulIndex;                               /* deliver result */
     500      return (NO_ERROR);                                               /* OK */
     501    }
     502  }
     503
     504  return (ERROR_INVALID_HANDLE);                    /* raise error condition */
     505}
     506
     507
     508/*****************************************************************************
     509 * Name      : DWORD HMHandleTranslateToOS2
     510 * Purpose   : translate a 16-bit Win32 handle to the associated OS/2 handle
     511 * Parameters: ULONG  hHandle16  - the windows handle
     512 *             PULONG phHandle32 - the associated OS/2 handle
     513 * Variables :
     514 * Result    : API returncode
     515 * Remark    :
     516 * Status    :
     517 *
     518 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
     519 *****************************************************************************/
     520
     521DWORD  HMHandleTranslateToOS2 (ULONG  hHandle16,
     522                                       PULONG phHandle32)
     523{
     524#ifdef DEBUG_LOCAL
     525  dprintf(("KERNEL32: HMHandleTranslateToOS2 (%08xh, %08xh)\n",
     526           hHandle16,
     527           phHandle32));
     528#endif
     529
     530  if (HMHandleValidate(hHandle16) == NO_ERROR)              /* verify handle */
     531  {
     532    *phHandle32 = HMGlobals.TabTranslationHandles[hHandle16].hHandle32;
     533    return (NO_ERROR);
     534  }
     535
     536  return (ERROR_INVALID_HANDLE);                    /* raise error condition */
     537}
     538
     539
     540/*****************************************************************************
     541 * Name      : DWORD HMHandleTranslateToOS2i
     542 * Purpose   : translate a 16-bit Win32 handle to the associated OS/2 handle
     543 * Parameters: ULONG  hHandle16  - the windows handle
     544 * Variables :
     545 * Result    : OS/2 handle
     546 * Remark    : no checkinf
     547 * Status    :
     548 *
     549 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
     550 *****************************************************************************/
     551
     552DWORD  HMHandleTranslateToOS2i (ULONG  hHandle16)
     553{
     554#ifdef DEBUG_LOCAL
     555  dprintf(("KERNEL32: HMHandleTranslateToOS2i (%08xh)\n",
     556           hHandle16));
     557#endif
     558
     559  return(HMGlobals.TabTranslationHandles[hHandle16].hHandle32);
     560}
     561
    338562
    339563
     
    411635 *****************************************************************************/
    412636
    413 HANDLE HMCreateFile(LPCSTR lpFileName,
    414                              DWORD  dwDesiredAccess,
    415                              DWORD  dwShareMode,
    416                              PVOID lpSecurityAttributes,
    417                              DWORD  dwCreationDisposition,
    418                              DWORD  dwFlagsAndAttributes,
    419                              HANDLE hTemplateFile)
     637HFILE HMCreateFile(LPCSTR lpFileName,
     638                   DWORD  dwDesiredAccess,
     639                   DWORD  dwShareMode,
     640                   LPSECURITY_ATTRIBUTES lpSecurityAttributes,
     641                   DWORD  dwCreationDisposition,
     642                   DWORD  dwFlagsAndAttributes,
     643                   HANDLE hTemplateFile)
    420644{
    421645  int             iIndex;                     /* index into the handle table */
     
    485709          /* write appropriate entry into the handle table if open succeeded */
    486710  hResult = (ULONG)iIndexNew | HM_HANDLE_ID;
    487   HMHandleTemp.hHandle                      = hResult;
     711  HMHandleTemp.hHMHandle                      = hResult;
    488712  TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;
    489713
     
    506730  if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
    507731  {
    508     TabWin32Handles[iIndexNew].hmHandleData.hHandle = INVALID_HANDLE_VALUE;
     732    TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    509733    SetLastError(rc);          /* Hehe, OS/2 and NT are pretty compatible :) */
    510734    return (INVALID_HANDLE_VALUE);                           /* signal error */
     
    530754
    531755/*****************************************************************************
     756 * Name      : HANDLE  HMOpenFile
     757 * Purpose   : Wrapper for the OpenFile() API
     758 * Parameters:
     759 * Variables :
     760 * Result    :
     761 * Remark    : Fix parameters passed to the HMDeviceManager::OpenFile
     762 *             Supply access mode and share mode validation routines
     763 * Status    :
     764 *
     765 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
     766 *****************************************************************************/
     767
     768
     769/***********************************************************************
     770 *              FILE_ConvertOFMode
     771 *
     772 * Convert OF_* mode into flags for CreateFile.
     773 */
     774static void FILE_ConvertOFMode( INT mode, DWORD *access, DWORD *sharing )
     775{
     776    switch(mode & 0x03)
     777    {
     778      case OF_READ:      *access = GENERIC_READ; break;
     779      case OF_WRITE:     *access = GENERIC_WRITE; break;
     780      case OF_READWRITE: *access = GENERIC_READ | GENERIC_WRITE; break;
     781      default:           *access = 0; break;
     782    }
     783    switch(mode & 0x70)
     784    {
     785      case OF_SHARE_EXCLUSIVE:  *sharing = 0; break;
     786      case OF_SHARE_DENY_WRITE: *sharing = FILE_SHARE_READ; break;
     787      case OF_SHARE_DENY_READ:  *sharing = FILE_SHARE_WRITE; break;
     788       case OF_SHARE_DENY_NONE:
     789      case OF_SHARE_COMPAT:
     790      default:                  *sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; break;
     791    }
     792}
     793
     794HANDLE HMOpenFile(LPCSTR    lpFileName,
     795                  OFSTRUCT* pOFStruct,
     796                  UINT      fuMode)
     797{
     798  int             iIndex;                     /* index into the handle table */
     799  int             iIndexNew;                  /* index into the handle table */
     800  HMDeviceHandler *pDeviceHandler;         /* device handler for this handle */
     801  HANDLE          hResult;
     802  PHMHANDLEDATA   pHMHandleData;
     803  DWORD           rc;                                     /* API return code */
     804
     805
     806  pDeviceHandler = _HMDeviceFind((PSZ)lpFileName);            /* find device */
     807  if (NULL == pDeviceHandler)                  /* this name is unknown to us */
     808  {
     809    SetLastError(ERROR_FILE_NOT_FOUND);
     810    return (INVALID_HANDLE_VALUE);                           /* signal error */
     811  }
     812  else
     813    pHMHandleData  = NULL;
     814
     815
     816  iIndexNew = _HMHandleGetFree();                         /* get free handle */
     817  if (-1 == iIndexNew)                            /* oops, no free handles ! */
     818  {
     819    SetLastError(ERROR_NOT_ENOUGH_MEMORY);      /* use this as error message */
     820    return (INVALID_HANDLE_VALUE);                           /* signal error */
     821  }
     822
     823
     824                           /* initialize the complete HMHANDLEDATA structure */
     825  pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;
     826  pHMHandleData->dwType     = FILE_TYPE_UNKNOWN;      /* unknown handle type */
     827
     828  FILE_ConvertOFMode(fuMode,                                 /* map OF_flags */
     829                     &pHMHandleData->dwAccess,
     830                     &pHMHandleData->dwShare);
     831
     832  pHMHandleData->dwCreation = 0;
     833  pHMHandleData->dwFlags    = 0;
     834  pHMHandleData->lpHandlerData = NULL;
     835
     836
     837      /* we've got to mark the handle as occupied here, since another device */
     838                   /* could be created within the device handler -> deadlock */
     839
     840          /* write appropriate entry into the handle table if open succeeded */
     841  hResult = (ULONG)iIndexNew | HM_HANDLE_ID;
     842  TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = hResult;
     843  TabWin32Handles[iIndexNew].pDeviceHandler       = pDeviceHandler;
     844
     845  rc = pDeviceHandler->OpenFile  (lpFileName,     /* call the device handler */
     846                                  &TabWin32Handles[iIndexNew].hmHandleData,
     847                                  pOFStruct,
     848                                  fuMode);
     849
     850#ifdef DEBUG_LOCAL
     851    dprintf(("KERNEL32/HandleManager:CheckPoint3: %s lpHandlerData=%08xh\n",
     852             lpFileName,
     853             HMHandleTemp.lpHandlerData));
     854#endif
     855
     856  if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
     857  {
     858    TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     859    SetLastError(rc);          /* Hehe, OS/2 and NT are pretty compatible :) */
     860    return (INVALID_HANDLE_VALUE);                           /* signal error */
     861  }
     862
     863#ifdef DEBUG_LOCAL
     864  dprintf(("KERNEL32/HandleManager: OpenFile(%s)=%08xh\n",
     865           lpFileName,
     866           hResult));
     867#endif
     868
     869  return hResult;                                     /* return valid handle */
     870}
     871
     872
     873
     874/*****************************************************************************
    532875 * Name      : HANDLE  HMCloseFile
    533876 * Purpose   : Wrapper for the CloseHandle() API
     
    541884 *****************************************************************************/
    542885
    543 BOOL  HMCloseHandle(HANDLE hObject)
     886BOOL HMCloseHandle(HANDLE hObject)
    544887{
    545888  int       iIndex;                           /* index into the handle table */
     
    559902
    560903  if (fResult == TRUE)                   /* remove handle if close succeeded */
    561     pHMHandle->hmHandleData.hHandle = 0;              /* mark handle as free */
     904    pHMHandle->hmHandleData.hHMHandle = 0;            /* mark handle as free */
    562905
    563906  return (fResult);                                   /* deliver return code */
     
    576919 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    577920 *****************************************************************************/
    578 
    579 BOOL  HMReadFile(HANDLE       hFile,
    580                          LPCVOID      lpBuffer,
    581                          DWORD        nNumberOfBytesToRead,
    582                          LPDWORD      lpNumberOfBytesRead,
    583                          LPOVERLAPPED lpOverlapped)
     921BOOL HMReadFile(HANDLE       hFile,
     922                LPVOID       lpBuffer,
     923                DWORD        nNumberOfBytesToRead,
     924                LPDWORD      lpNumberOfBytesRead,
     925                LPOVERLAPPED lpOverlapped)
    584926{
    585927  int       iIndex;                           /* index into the handle table */
     
    618960 *****************************************************************************/
    619961
    620 BOOL  HMWriteFile(HANDLE       hFile,
    621                           LPCVOID      lpBuffer,
    622                           DWORD        nNumberOfBytesToWrite,
    623                           LPDWORD      lpNumberOfBytesWritten,
    624                           LPOVERLAPPED lpOverlapped)
     962BOOL HMWriteFile(HANDLE       hFile,
     963                        LPCVOID      lpBuffer,
     964                        DWORD        nNumberOfBytesToWrite,
     965                        LPDWORD      lpNumberOfBytesWritten,
     966                        LPOVERLAPPED lpOverlapped)
    625967{
    626968  int       iIndex;                           /* index into the handle table */
     
    6591001 *****************************************************************************/
    6601002
    661 DWORD  HMGetFileType(HANDLE hFile)
     1003DWORD HMGetFileType(HANDLE hFile)
    6621004{
    6631005  int       iIndex;                           /* index into the handle table */
     
    6701012  {
    6711013    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
    672     return (FILE_TYPE_UNKNOWN);                            /* signal failure */
     1014    return (INVALID_HANDLE_ERROR);                         /* signal failure */
    6731015  }
    6741016
     
    6941036 *****************************************************************************/
    6951037DWORD   HMDeviceRequest (HANDLE hFile,
    696                                  ULONG  ulRequestCode,
    697                                  ULONG  arg1,
    698                                  ULONG  arg2,
    699                                  ULONG  arg3,
    700                                  ULONG  arg4)
     1038                         ULONG  ulRequestCode,
     1039                         ULONG  arg1,
     1040                         ULONG  arg2,
     1041                         ULONG  arg3,
     1042                         ULONG  arg4)
    7011043{
    7021044  int       iIndex;                           /* index into the handle table */
     
    7091051  {
    7101052    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
    711     return (FILE_TYPE_UNKNOWN);                            /* signal failure */
     1053    return (INVALID_HANDLE_ERROR);                         /* signal failure */
    7121054  }
    7131055
     
    7251067
    7261068/*****************************************************************************
    727  * Name      : HMDeviceHandler::HMDeviceHandler
    728  * Purpose   : default constructor for a device handler object
    729  * Parameters: LPCSTR lpDeviceName
    730  * Variables :
    731  * Result    :
    732  * Remark    : this is only to identify the device for debugging purposes
    733  * Status    :
    734  *
    735  * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    736  *****************************************************************************/
    737 
    738 HMDeviceHandler::HMDeviceHandler(LPCSTR lpDeviceName)
    739 {
    740                                       /* only a reference on the device name */
    741   HMDeviceHandler::lpHMDeviceName = lpDeviceName;
    742 }
    743 
    744 
    745 /*****************************************************************************
    746  * Name      : HMDeviceHandler::_DeviceReuqest
    747  * Purpose   : entry method for special request functions
    748  * Parameters: ULONG ulRequestCode
    749  *             various parameters as required
    750  * Variables :
    751  * Result    :
    752  * Remark    : the standard behaviour is to return an error code for non-
    753  *             existant request codes
    754  * Status    :
    755  *
    756  * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    757  *****************************************************************************/
    758 DWORD  HMDeviceHandler::_DeviceRequest (PHMHANDLEDATA pHMHandleData,
    759                                         ULONG         ulRequestCode,
    760                                         ULONG         arg1,
    761                                         ULONG         arg2,
    762                                         ULONG         arg3,
    763                                         ULONG         arg4)
    764 {
    765   dprintf(("KERNEL32:HandleManager::_DeviceRequest %s(%08x,%08x) - stub?\n",
    766            lpHMDeviceName,
    767            pHMHandleData,
    768            ulRequestCode));
    769 
    770   return(ERROR_INVALID_FUNCTION);
    771 }
    772 
    773 
    774 /*****************************************************************************
    775  * Name      : DWORD HMDeviceHandler::CreateFile
    776  * Purpose   : this is called from the handle manager if a CreateFile() is
    777  *             performed on a handle
    778  * Parameters: LPCSTR        lpFileName            name of the file / device
    779  *             PHMHANDLEDATA pHMHandleData         data of the NEW handle
    780  *             PVOID         lpSecurityAttributes  ignored
    781  *             PHMHANDLEDATA pHMHandleDataTemplate data of the template handle
    782  * Variables :
    783  * Result    :
    784  * Remark    :
    785  * Status    : NO_ERROR - API succeeded
    786  *             other    - what is to be set in SetLastError
    787  *
    788  * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    789  *****************************************************************************/
    790 
    791 DWORD HMDeviceHandler::CreateFile (LPCSTR        lpFileName,
    792                                    PHMHANDLEDATA pHMHandleData,
    793                                    PVOID         lpSecurityAttributes,
    794                                    PHMHANDLEDATA pHMHandleDataTemplate)
    795 {
    796   dprintf(("KERNEL32:HandleManager::CreateFile %s(%s,%08x,%08x,%08x) - stub?\n",
    797            lpHMDeviceName,
    798            lpFileName,
    799            pHMHandleData,
    800            lpSecurityAttributes,
    801            pHMHandleDataTemplate));
    802 
    803   return(ERROR_INVALID_FUNCTION);
    804 }
    805 
    806 
    807 /*****************************************************************************
    808  * Name      : DWORD HMDeviceHandler::CloseHandle
    809  * Purpose   : close the handle
    810  * Parameters: PHMHANDLEDATA pHMHandleData
    811  * Variables :
    812  * Result    : API returncode
    813  * Remark    :
    814  * Status    :
    815  *
    816  * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    817  *****************************************************************************/
    818 
    819 DWORD HMDeviceHandler::CloseHandle(PHMHANDLEDATA pHMHandleData)
    820 {
    821   dprintf(("KERNEL32:HandleManager::CloseHandle %s(%08x) - stub?\n",
    822            lpHMDeviceName,
    823            pHMHandleData));
    824 
    825   return(ERROR_INVALID_FUNCTION);
    826 }
    827 
    828 
    829 /*****************************************************************************
    830  * Name      : DWORD HMDeviceHandler::ReadFile
    831  * Purpose   : read data from handle / device
    832  * Parameters: PHMHANDLEDATA pHMHandleData,
    833  *             LPCVOID       lpBuffer,
    834  *             DWORD         nNumberOfBytesToRead,
    835  *             LPDWORD       lpNumberOfBytesRead,
    836  *             LPOVERLAPPED  lpOverlapped
    837  * Variables :
    838  * Result    : API returncode
    839  * Remark    :
    840  * Status    :
    841  *
    842  * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    843  *****************************************************************************/
    844 
    845 DWORD HMDeviceHandler::ReadFile(PHMHANDLEDATA pHMHandleData,
    846                                 LPCVOID       lpBuffer,
    847                                 DWORD         nNumberOfBytesToRead,
    848                                 LPDWORD       lpNumberOfBytesRead,
    849                                 LPOVERLAPPED  lpOverlapped)
    850 {
    851   dprintf(("KERNEL32:HandleManager::ReadFile %s(%08x,%08x,%08x,%08x,%08x) - stub?\n",
    852            lpHMDeviceName,
    853            pHMHandleData,
    854            lpBuffer,
    855            nNumberOfBytesToRead,
    856            lpNumberOfBytesRead,
    857            lpOverlapped));
    858 
    859   return(ERROR_INVALID_FUNCTION);
    860 }
    861 
    862 
    863 /*****************************************************************************
    864  * Name      : DWORD HMDeviceHandler::WriteFile
    865  * Purpose   : write data to handle / device
    866  * Parameters: PHMHANDLEDATA pHMHandleData,
    867  *             LPCVOID       lpBuffer,
    868  *             DWORD         nNumberOfBytesToWrite,
    869  *             LPDWORD       lpNumberOfBytesWritten,
    870  *             LPOVERLAPPED  lpOverlapped
    871  * Variables :
    872  * Result    : API returncode
    873  * Remark    :
    874  * Status    :
    875  *
    876  * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    877  *****************************************************************************/
    878 
    879 DWORD HMDeviceHandler::WriteFile(PHMHANDLEDATA pHMHandleData,
    880                                  LPCVOID       lpBuffer,
    881                                  DWORD         nNumberOfBytesToWrite,
    882                                  LPDWORD       lpNumberOfBytesWritten,
    883                                  LPOVERLAPPED  lpOverlapped)
    884 {
    885   dprintf(("KERNEL32:HandleManager::WriteFile %s(%08x,%08x,%08x,%08x,%08x) - stub?\n",
    886            lpHMDeviceName,
    887            pHMHandleData,
    888            lpBuffer,
    889            nNumberOfBytesToWrite,
    890            lpNumberOfBytesWritten,
    891            lpOverlapped));
    892 
    893   return(ERROR_INVALID_FUNCTION);
    894 }
    895 
    896 
    897 /*****************************************************************************
    898  * Name      : DWORD HMDeviceHandler::GetFileType
    899  * Purpose   : determine the handle type
    900  * Parameters: PHMHANDLEDATA pHMHandleData
    901  * Variables :
    902  * Result    : API returncode
    903  * Remark    :
    904  * Status    :
    905  *
    906  * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    907  *****************************************************************************/
    908 
    909 DWORD HMDeviceHandler::GetFileType(PHMHANDLEDATA pHMHandleData)
    910 {
    911   dprintf(("KERNEL32:HandleManager::GetFileType %s(%08x)\n",
    912            lpHMDeviceName,
    913            pHMHandleData));
    914 
    915   return pHMHandleData->dwType;
    916 }
    917 
    918 
    919 
    920 /*****************************************************************************/
    921 /* handle translation buffer management                                      */
    922 /*                                                                           */
    923 /* Since some Win32 applications rely (!) on 16-bit handles, we've got to do */
    924 /* 32-bit to 16-bit and vs vsa translation here.                             */
    925 /* Filehandle-based functions should be routed via the handlemanager instead */
    926 /* of going to Open32 directly.                                              */
    927 /*****************************************************************************/
    928 
    929 
    930 /*****************************************************************************
    931  * Name      : DWORD HMHandleAllocate
    932  * Purpose   : allocate a handle in the translation table
    933  * Parameters: PULONG pHandle16 - to return the allocated handle
    934  *             ULONG  hHandle32 - the associated OS/2 handle
    935  * Variables :
    936  * Result    : API returncode
    937  * Remark    : no parameter checking is done, phHandle may not be invalid
    938  *             hHandle32 shouldn't be 0
    939  * Status    :
    940  *
    941  * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    942  *****************************************************************************/
    943 
    944 DWORD  HMHandleAllocate (PULONG phHandle16,
    945                                  ULONG  hHandle32)
    946 {
    947   register ULONG ulHandle;
    948 
    949 #ifdef DEBUG_LOCAL
    950   dprintf(("KERNEL32::HMHandleAllocate (%08xh,%08xh)\n",
    951            phHandle16,
    952            hHandle32));
    953 #endif
    954 
    955   ulHandle = HMGlobals.ulHandleLast;                      /* get free handle */
    956 
    957   do
    958   {
    959                                                   /* check if handle is free */
    960     if (HMGlobals.TabTranslationHandles[ulHandle].hHandle32 == 0)
    961     {
    962       *phHandle16 = ulHandle;
    963       HMGlobals.TabTranslationHandles[ulHandle].hHandle32 = hHandle32;
    964       HMGlobals.ulHandleLast = ulHandle;          /* to shorten search times */
    965 
    966       return (NO_ERROR);                                               /* OK */
    967     }
    968 
    969     ulHandle++;                                        /* skip to next entry */
    970 
    971     if (ulHandle >= MAX_TRANSLATION_HANDLES)               /* check boundary */
    972       ulHandle = 0;
    973   }
    974   while (ulHandle != HMGlobals.ulHandleLast);
    975 
    976   return (ERROR_TOO_MANY_OPEN_FILES);                      /* OK, we're done */
    977 }
    978 
    979 
    980 /*****************************************************************************
    981  * Name      : DWORD HMHandleFree
    982  * Purpose   : free a handle from the translation table
    983  * Parameters: ULONG hHandle16 - the handle to be freed
    984  * Variables :
    985  * Result    : API returncode
    986  * Remark    : no parameter checking is done, hHandle16 MAY NEVER exceed
    987  *             the MAX_TRANSLATION_HANDLES boundary
    988  * Status    :
    989  *
    990  * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    991  *****************************************************************************/
    992 
    993 DWORD  HMHandleFree (ULONG hHandle16)
    994 {
    995   ULONG rc;                                                /* API returncode */
    996 
    997 #ifdef DEBUG_LOCAL
    998   dprintf(("KERNEL32::HMHandleFree (%08xh)\n",
    999            hHandle16));
    1000 #endif
    1001 
    1002   rc = HMHandleValidate(hHandle16);                         /* verify handle */
    1003   if (rc != NO_ERROR)                                        /* check errors */
    1004     return (rc);                                    /* raise error condition */
    1005 
    1006   HMGlobals.TabTranslationHandles[hHandle16].hHandle32 = 0;      /* OK, done */
    1007 
    1008   return (NO_ERROR);
    1009 }
    1010 
    1011 
    1012 /*****************************************************************************
    1013  * Name      : DWORD HMHandleValidate
    1014  * Purpose   : validate a handle through the translation table
    1015  * Parameters: ULONG hHandle16 - the handle to be verified
    1016  * Variables :
    1017  * Result    : API returncode
    1018  * Remark    :
    1019  * Status    :
    1020  *
    1021  * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    1022  *****************************************************************************/
    1023 
    1024 DWORD  HMHandleValidate (ULONG hHandle16)
    1025 {
    1026 #ifdef DEBUG_LOCAL
    1027   dprintf(("KERNEL32::HMHandleValidate (%08xh)\n",
    1028            hHandle16));
    1029 #endif
    1030 
    1031   if (hHandle16 >= MAX_TRANSLATION_HANDLES)                /* check boundary */
    1032     return (ERROR_INVALID_HANDLE);                  /* raise error condition */
    1033 
    1034   if (HMGlobals.TabTranslationHandles[hHandle16].hHandle32 == 0)  /* valid ? */
    1035     return (ERROR_INVALID_HANDLE);                  /* raise error condition */
    1036 
    1037   return (NO_ERROR);
    1038 }
    1039 
    1040 
    1041 /*****************************************************************************
    1042  * Name      : DWORD HMHandleTranslateToWin
    1043  * Purpose   : translate a 32-bit OS/2 handle to the associated windows handle
    1044  * Parameters: ULONG  hHandle32  - the OS/2 handle
    1045  *             PULONG phHandle16 - the associated windows handle
    1046  * Variables :
    1047  * Result    : API returncode
    1048  * Remark    :
    1049  * Status    :
    1050  *
    1051  * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    1052  *****************************************************************************/
    1053 
    1054 DWORD  HMHandleTranslateToWin (ULONG  hHandle32,
    1055                                        PULONG phHandle16)
    1056 {
    1057            ULONG rc;                                       /* API returncode */
    1058   register ULONG ulIndex;                    /* index counter over the table */
    1059 
    1060 #ifdef DEBUG_LOCAL
    1061   dprintf(("KERNEL32::HMHandleTranslateToWin (%08xh, %08xh)\n",
    1062            hHandle32,
    1063            phHandle16));
    1064 #endif
    1065 
    1066   for (ulIndex = 0;
    1067        ulIndex < MAX_TRANSLATION_HANDLES;
    1068        ulIndex++)
    1069   {
    1070                                                       /* look for the handle */
    1071     if (HMGlobals.TabTranslationHandles[ulIndex].hHandle32 == hHandle32)
    1072     {
    1073       *phHandle16 = ulIndex;                               /* deliver result */
    1074       return (NO_ERROR);                                               /* OK */
    1075     }
    1076   }
    1077 
    1078   return (ERROR_INVALID_HANDLE);                    /* raise error condition */
    1079 }
    1080 
    1081 
    1082 /*****************************************************************************
    1083  * Name      : DWORD HMHandleTranslateToOS2
    1084  * Purpose   : translate a 16-bit Win32 handle to the associated OS/2 handle
    1085  * Parameters: ULONG  hHandle16  - the windows handle
    1086  *             PULONG phHandle32 - the associated OS/2 handle
    1087  * Variables :
    1088  * Result    : API returncode
    1089  * Remark    :
    1090  * Status    :
    1091  *
    1092  * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    1093  *****************************************************************************/
    1094 
    1095 DWORD  HMHandleTranslateToOS2 (ULONG  hHandle16,
    1096                                        PULONG phHandle32)
    1097 {
    1098 #ifdef DEBUG_LOCAL
    1099   dprintf(("KERNEL32::HMHandleTranslateToOS2 (%08xh, %08xh)\n",
    1100            hHandle16,
    1101            phHandle32));
    1102 #endif
    1103 
    1104   if (HMHandleValidate(hHandle16) == NO_ERROR)              /* verify handle */
    1105   {
    1106     *phHandle32 = HMGlobals.TabTranslationHandles[hHandle16].hHandle32;
    1107     return (NO_ERROR);
    1108   }
    1109 
    1110   return (ERROR_INVALID_HANDLE);                    /* raise error condition */
    1111 }
    1112 
    1113 
    1114 /*****************************************************************************
    1115  * Name      : DWORD HMHandleTranslateToOS2i
    1116  * Purpose   : translate a 16-bit Win32 handle to the associated OS/2 handle
    1117  * Parameters: ULONG  hHandle16  - the windows handle
    1118  * Variables :
    1119  * Result    : OS/2 handle
    1120  * Remark    : no checkinf
    1121  * Status    :
    1122  *
    1123  * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    1124  *****************************************************************************/
    1125 
    1126 DWORD  HMHandleTranslateToOS2i (ULONG  hHandle16)
    1127 {
    1128 #ifdef DEBUG_LOCAL
    1129   dprintf(("KERNEL32::HMHandleTranslateToOS2i (%08xh)\n",
    1130            hHandle16));
    1131 #endif
    1132 
    1133   return(HMGlobals.TabTranslationHandles[hHandle16].hHandle32);
    1134 }
     1069 * Name      : HMDeviceHandler::GetFileInformationByHandle
     1070 * Purpose   : router function for GetFileInformationByHandle
     1071 * Parameters:
     1072 * Variables :
     1073 * Result    :
     1074 * Remark    :
     1075 * Status    :
     1076 *
     1077 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
     1078 *****************************************************************************/
     1079DWORD HMGetFileInformationByHandle (HANDLE                     hFile,
     1080                                    BY_HANDLE_FILE_INFORMATION *pHFI)
     1081{
     1082  int       iIndex;                           /* index into the handle table */
     1083  DWORD     dwResult;                /* result from the device handler's API */
     1084  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     1085
     1086                                                          /* validate handle */
     1087  iIndex = _HMHandleQuery(hFile);                           /* get the index */
     1088  if (-1 == iIndex)                                               /* error ? */
     1089  {
     1090    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
     1091    return (INVALID_HANDLE_ERROR);                         /* signal failure */
     1092  }
     1093
     1094  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1095  dwResult = pHMHandle->pDeviceHandler->GetFileInformationByHandle(&pHMHandle->hmHandleData,
     1096                                                       pHFI);
     1097
     1098  return (dwResult);                                  /* deliver return code */
     1099}
     1100
     1101
     1102
     1103/*****************************************************************************
     1104 * Name      : HMDeviceHandler::SetEndOfFile
     1105 * Purpose   : router function for SetEndOfFile
     1106 * Parameters:
     1107 * Variables :
     1108 * Result    :
     1109 * Remark    :
     1110 * Status    :
     1111 *
     1112 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
     1113 *****************************************************************************/
     1114BOOL HMSetEndOfFile (HANDLE hFile)
     1115{
     1116  int       iIndex;                           /* index into the handle table */
     1117  BOOL      bResult;                 /* result from the device handler's API */
     1118  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     1119
     1120                                                          /* validate handle */
     1121  iIndex = _HMHandleQuery(hFile);                           /* get the index */
     1122  if (-1 == iIndex)                                               /* error ? */
     1123  {
     1124    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
     1125    return (INVALID_HANDLE_ERROR);                         /* signal failure */
     1126  }
     1127
     1128  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1129  bResult = pHMHandle->pDeviceHandler->SetEndOfFile(&pHMHandle->hmHandleData);
     1130
     1131  return (bResult);                                   /* deliver return code */
     1132}
     1133
     1134
     1135/*****************************************************************************
     1136 * Name      : HMDeviceHandler::SetFileTime
     1137 * Purpose   : router function for SetFileTime
     1138 * Parameters:
     1139 * Variables :
     1140 * Result    :
     1141 * Remark    :
     1142 * Status    :
     1143 *
     1144 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
     1145 *****************************************************************************/
     1146BOOL HMSetFileTime (HANDLE         hFile,
     1147                    const FILETIME *pFT1,
     1148                    const FILETIME *pFT2,
     1149                    const FILETIME *pFT3)
     1150{
     1151  int       iIndex;                           /* index into the handle table */
     1152  BOOL      bResult;                 /* result from the device handler's API */
     1153  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     1154
     1155                                                          /* validate handle */
     1156  iIndex = _HMHandleQuery(hFile);                           /* get the index */
     1157  if (-1 == iIndex)                                               /* error ? */
     1158  {
     1159    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
     1160    return (INVALID_HANDLE_ERROR);                         /* signal failure */
     1161  }
     1162
     1163  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1164  bResult = pHMHandle->pDeviceHandler->SetFileTime(&pHMHandle->hmHandleData,
     1165                                                   (LPFILETIME)pFT1,
     1166                                                   (LPFILETIME)pFT2,
     1167                                                   (LPFILETIME)pFT3);
     1168
     1169  return (bResult);                                   /* deliver return code */
     1170}
     1171
     1172
     1173/*****************************************************************************
     1174 * Name      : HMDeviceHandler::GetFileSize
     1175 * Purpose   : router function for GetFileSize
     1176 * Parameters:
     1177 * Variables :
     1178 * Result    :
     1179 * Remark    :
     1180 * Status    :
     1181 *
     1182 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
     1183 *****************************************************************************/
     1184DWORD HMGetFileSize (HANDLE hFile,
     1185                     PDWORD pSize)
     1186{
     1187  int       iIndex;                           /* index into the handle table */
     1188  DWORD     dwResult;                /* result from the device handler's API */
     1189  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     1190
     1191                                                          /* validate handle */
     1192  iIndex = _HMHandleQuery(hFile);                           /* get the index */
     1193  if (-1 == iIndex)                                               /* error ? */
     1194  {
     1195    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
     1196    return (INVALID_HANDLE_ERROR);                         /* signal failure */
     1197  }
     1198
     1199  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1200  dwResult = pHMHandle->pDeviceHandler->GetFileSize(&pHMHandle->hmHandleData,
     1201                                                    pSize);
     1202
     1203  return (dwResult);                                  /* deliver return code */
     1204}
     1205
     1206
     1207/*****************************************************************************
     1208 * Name      : HMDeviceHandler::SetFilePointer
     1209 * Purpose   : router function for SetFilePointer
     1210 * Parameters:
     1211 * Variables :
     1212 * Result    :
     1213 * Remark    :
     1214 * Status    :
     1215 *
     1216 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
     1217 *****************************************************************************/
     1218DWORD HMSetFilePointer (HANDLE hFile,
     1219                        LONG   lDistanceToMove,
     1220                        PLONG  lpDistanceToMoveHigh,
     1221                        DWORD  dwMoveMethod)
     1222{
     1223  int       iIndex;                           /* index into the handle table */
     1224  DWORD     dwResult;                /* result from the device handler's API */
     1225  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     1226
     1227                                                          /* validate handle */
     1228  iIndex = _HMHandleQuery(hFile);                           /* get the index */
     1229  if (-1 == iIndex)                                               /* error ? */
     1230  {
     1231    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
     1232    return (INVALID_HANDLE_ERROR);                         /* signal failure */
     1233  }
     1234
     1235  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1236  dwResult = pHMHandle->pDeviceHandler->SetFilePointer(&pHMHandle->hmHandleData,
     1237                                                       lDistanceToMove,
     1238                                                       lpDistanceToMoveHigh,
     1239                                                       dwMoveMethod);
     1240
     1241  return (dwResult);                                  /* deliver return code */
     1242}
     1243
     1244
     1245/*****************************************************************************
     1246 * Name      : HMDeviceHandler::LockFile
     1247 * Purpose   : router function for LockFile
     1248 * Parameters:
     1249 * Variables :
     1250 * Result    :
     1251 * Remark    :
     1252 * Status    :
     1253 *
     1254 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
     1255 *****************************************************************************/
     1256BOOL HMLockFile (HFILE         hFile,
     1257                 DWORD         arg2,
     1258                 DWORD         arg3,
     1259                 DWORD         arg4,
     1260                 DWORD         arg5)
     1261{
     1262  int       iIndex;                           /* index into the handle table */
     1263  DWORD     dwResult;                /* result from the device handler's API */
     1264  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     1265
     1266                                                          /* validate handle */
     1267  iIndex = _HMHandleQuery(hFile);                           /* get the index */
     1268  if (-1 == iIndex)                                               /* error ? */
     1269  {
     1270    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
     1271    return (INVALID_HANDLE_ERROR);                         /* signal failure */
     1272  }
     1273
     1274  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1275  dwResult = pHMHandle->pDeviceHandler->LockFile(&pHMHandle->hmHandleData,
     1276                                                 arg2,
     1277                                                 arg3,
     1278                                                 arg4,
     1279                                                 arg5);
     1280
     1281  return (dwResult);                                  /* deliver return code */
     1282}
     1283
     1284
     1285/*****************************************************************************
     1286 * Name      : HMDeviceHandler::LockFileEx
     1287 * Purpose   : router function for LockFileEx
     1288 * Parameters:
     1289 * Variables :
     1290 * Result    :
     1291 * Remark    :
     1292 * Status    :
     1293 *
     1294 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
     1295 *****************************************************************************/
     1296DWORD HMLockFileEx(HANDLE        hFile,
     1297                   DWORD         dwFlags,
     1298                   DWORD         dwReserved,
     1299                   DWORD         nNumberOfBytesToLockLow,
     1300                   DWORD         nNumberOfBytesToLockHigh,
     1301                   LPOVERLAPPED  lpOverlapped)
     1302{
     1303  int       iIndex;                           /* index into the handle table */
     1304  DWORD     dwResult;                /* result from the device handler's API */
     1305  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     1306
     1307                                                          /* validate handle */
     1308  iIndex = _HMHandleQuery(hFile);                           /* get the index */
     1309  if (-1 == iIndex)                                               /* error ? */
     1310  {
     1311    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
     1312    return (INVALID_HANDLE_ERROR);                         /* signal failure */
     1313  }
     1314
     1315  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1316  dwResult = pHMHandle->pDeviceHandler->LockFileEx(&pHMHandle->hmHandleData,
     1317                                                   dwFlags,
     1318                                                   dwReserved,
     1319                                                   nNumberOfBytesToLockLow,
     1320                                                   nNumberOfBytesToLockHigh,
     1321                                                   lpOverlapped);
     1322
     1323  return (dwResult);                                  /* deliver return code */
     1324}
     1325
     1326
     1327
     1328/*****************************************************************************
     1329 * Name      : HMDeviceHandler::UnlockFile
     1330 * Purpose   : router function for UnlockFile
     1331 * Parameters:
     1332 * Variables :
     1333 * Result    :
     1334 * Remark    :
     1335 * Status    :
     1336 *
     1337 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
     1338 *****************************************************************************/
     1339BOOL HMUnlockFile (HFILE         hFile,
     1340                   DWORD         arg2,
     1341                   DWORD         arg3,
     1342                   DWORD         arg4,
     1343                   DWORD         arg5)
     1344{
     1345  int       iIndex;                           /* index into the handle table */
     1346  DWORD     dwResult;                /* result from the device handler's API */
     1347  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     1348
     1349                                                          /* validate handle */
     1350  iIndex = _HMHandleQuery(hFile);                           /* get the index */
     1351  if (-1 == iIndex)                                               /* error ? */
     1352  {
     1353    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
     1354    return (INVALID_HANDLE_ERROR);                         /* signal failure */
     1355  }
     1356
     1357  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1358  dwResult = pHMHandle->pDeviceHandler->UnlockFile(&pHMHandle->hmHandleData,
     1359                                                   arg2,
     1360                                                   arg3,
     1361                                                   arg4,
     1362                                                   arg5);
     1363
     1364  return (dwResult);                                  /* deliver return code */
     1365}
     1366
     1367/*****************************************************************************
     1368 * Name      : HMDeviceHandler::UnlockFileEx
     1369 * Purpose   : router function for UnlockFileEx
     1370 * Parameters:
     1371 * Variables :
     1372 * Result    :
     1373 * Remark    :
     1374 * Status    :
     1375 *
     1376 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
     1377 *****************************************************************************/
     1378BOOL HMUnlockFileEx(HANDLE        hFile,
     1379                    DWORD         dwFlags,
     1380                    DWORD         dwReserved,
     1381                    DWORD         nNumberOfBytesToLockLow,
     1382                    DWORD         nNumberOfBytesToLockHigh,
     1383                    LPOVERLAPPED  lpOverlapped)
     1384{
     1385  int       iIndex;                           /* index into the handle table */
     1386  DWORD     dwResult;                /* result from the device handler's API */
     1387  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
     1388
     1389                                                          /* validate handle */
     1390  iIndex = _HMHandleQuery(hFile);                           /* get the index */
     1391  if (-1 == iIndex)                                               /* error ? */
     1392  {
     1393    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
     1394    return (INVALID_HANDLE_ERROR);                         /* signal failure */
     1395  }
     1396
     1397  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1398  dwResult = pHMHandle->pDeviceHandler->UnlockFileEx(&pHMHandle->hmHandleData,
     1399                                                     dwFlags,
     1400                                                     dwReserved,
     1401                                                     nNumberOfBytesToLockLow,
     1402                                                     nNumberOfBytesToLockHigh,
     1403                                                     lpOverlapped);
     1404
     1405  return (dwResult);                                  /* deliver return code */
     1406}
     1407
Note: See TracChangeset for help on using the changeset viewer.