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/Fileio.cpp

    r100 r111  
    1 /* $Id: Fileio.cpp,v 1.5 1999-06-10 20:47:58 phaller Exp $ */
     1/* $Id: Fileio.cpp,v 1.6 1999-06-17 18:21:42 phaller Exp $ */
    22
    33/*
     
    3131{
    3232  HANDLE rc;
    33   HANDLE hFile;
    34 
    35   if(lpszName == NULL)
    36     return(NULL);
    37 
    38   dprintf(("KERNEL32: CreateFile %s\n", lpszName));
    39 
    40   if(strncmp(lpszName,
    41              "\\\\.\\",
    42              4) == 0)
    43   {
    44     return(OS2CreateFile((char *)&lpszName[4],
    45                          fdwAccess,
    46                          fdwShareMode));
    47   }
    4833
    4934  dprintf(("KERNEL32: CreateFileA(%s,%08xh,%08xh,%08xh,%08xh,%08xh,%08xh)\n",
     
    5641           hTemplateFile));
    5742
    58   rc = O32_CreateFile(lpszName,
    59                   fdwAccess,
    60                   fdwShareMode,
    61                   lpsa,
    62                   fdwCreate,
    63                   fdwAttrsAndFlags,
    64                   hTemplateFile);
    65 
    66   /* @@@PH 1998/02/12 Handle Manager support */
    67   if (rc == -1)
    6843    rc = HMCreateFile(lpszName,
    6944                      fdwAccess,
     
    7449                      hTemplateFile);
    7550
    76   /* @@@PH experimental Handlemanager support */
    77   if (HMHandleAllocate(&hFile,
    78                        rc) == NO_ERROR)
    79     rc = hFile;
    80 
    81   dprintf(("KERNEL32:  CreateFile returned %08xh\n",
    82            rc));
    83 
    8451  return(rc);
    8552}
     
    151118//******************************************************************************
    152119//******************************************************************************
    153 DWORD WIN32API GetFileType(HANDLE file)
    154 {
    155   DWORD rc;
    156   HFILE hFile;
    157 
    158   /* @@@PH 1998/02/12 Handle Manager support */
    159   if (IS_HM_HANDLE(file))
    160     return (HMGetFileType(file));
    161 
    162   /* @@@PH experimental Handlemanager support */
    163   if (HMHandleTranslateToOS2(file,
    164                        &hFile) == NO_ERROR)
    165     file = hFile;
    166 
    167   dprintf(("KERNEL32:  GetFileType %08xh\n",
    168            file));
    169 
    170   rc = O32_GetFileType(file);
    171   if(rc == 0)
    172   {
    173     //bugfix
    174     rc = 1;
    175   }
    176 
    177   dprintf(("KERNEL32:  GetFileType returned %08xh\n",
    178            rc));
    179 
    180   return(rc);
     120DWORD WIN32API GetFileType(HANDLE hFile)
     121{
     122  dprintf(("KERNEL32: GetFileType(%08xh)\n",
     123           hFile));
     124
     125  return(HMGetFileType(hFile));
    181126}
    182127//******************************************************************************
     
    185130                                          BY_HANDLE_FILE_INFORMATION *arg2)
    186131{
    187   DWORD rc;
    188   HFILE hFile;
    189 
    190    /* @@@PH experimental Handlemanager support */
    191   if (HMHandleTranslateToOS2(arg1,
    192                        &hFile) == NO_ERROR)
    193     arg1 = hFile;
    194 
    195 
    196   rc = O32_GetFileInformationByHandle(arg1,
    197                                       arg2);
    198 
    199   dprintf(("KERNEL32:  GetFileInformationByHandle (%08xh) returned %08xh\n",
     132  dprintf(("KERNEL32: GetFIleInformationByHandle(%08xh,%0xh)\n",
    200133           arg1,
    201            rc));
    202 
    203   /* @@@PH irrelevant
    204   if(rc == 0)
    205   {
    206     //might be converted _lopen handle, so go get it
    207     //      arg1 = ConvertHandle(arg1);
    208     rc = O32_GetFileInformationByHandle(arg1, arg2);
    209     dprintf(("KERNEL32:  GetFileInformationByHandle (%X) returned %d\n", arg1, rc));
    210   }
    211   */
    212 
    213   return(rc);
     134           arg2));
     135
     136  return(HMGetFileInformationByHandle(arg1,arg2));
    214137}
    215138//******************************************************************************
     
    217140BOOL WIN32API SetEndOfFile( HANDLE arg1)
    218141{
    219   HFILE hFile;
    220 
    221   /* @@@PH experimental Handlemanager support */
    222   if (HMHandleTranslateToOS2(arg1,
    223                        &hFile) == NO_ERROR)
    224     arg1 = hFile;
    225 
    226142  dprintf(("KERNEL32: SetEndOfFile(%08xh)\n",
    227143           arg1));
    228144
    229   return O32_SetEndOfFile(arg1);
     145  return HMSetEndOfFile(arg1);
    230146}
    231147//******************************************************************************
     
    236152                          const FILETIME *arg4)
    237153{
    238   HFILE hFile;
    239 
    240   /* @@@PH experimental Handlemanager support */
    241   if (HMHandleTranslateToOS2(arg1,
    242                        &hFile) == NO_ERROR)
    243     arg1 = hFile;
    244 
    245154  dprintf(("KERNEL32: SetFileTime(%08xh,%08xh,%08xh,%08xh)\n",
    246155           arg1,
     
    249158           arg4));
    250159
    251   return O32_SetFileTime(arg1,
    252                          arg2,
    253                          arg3,
    254                          arg4);
     160  return HMSetFileTime(arg1,
     161                       arg2,
     162                       arg3,
     163                       arg4);
    255164}
    256165//******************************************************************************
     
    288197DWORD WIN32API GetFileSize( HANDLE arg1, PDWORD  arg2)
    289198{
    290   HFILE hFile;
    291 
    292   /* @@@PH experimental Handlemanager support */
    293   if (HMHandleTranslateToOS2(arg1,
    294                        &hFile) == NO_ERROR)
    295     arg1 = hFile;
    296 
    297199  dprintf(("KERNEL32: GetFileSize (%08xh, %08xh)\n",
    298200           arg1,
    299201           arg2));
    300202
    301   return O32_GetFileSize(arg1,
    302                          arg2);
     203  return HMGetFileSize(arg1,
     204                       arg2);
    303205}
    304206//******************************************************************************
     
    377279{
    378280  BOOL rc;
    379   HFILE hFile;
    380 
    381   /* @@@PH 1998/02/12 Handle Manager support */
    382   if (IS_HM_HANDLE(arg1))
    383     return (HMReadFile(arg1, arg2, arg3, arg4, arg5));
    384 
    385   /* @@@PH 1999/06/09 Handle Manager support */
    386 
    387   /* @@@PH experimental Handlemanager support */
    388   if (HMHandleTranslateToOS2(arg1,
    389                        &hFile) == NO_ERROR)
    390     arg1 = hFile;
    391 
    392   rc = O32_ReadFile(arg1,
    393                     arg2,
    394                     arg3,
    395                     arg4,
    396                     arg5);
     281
     282  rc = HMReadFile(arg1,
     283                  arg2,
     284                  arg3,
     285                  arg4,
     286                  arg5);
    397287
    398288  dprintf(("KERNEL32:  ReadFile %X %d bytes returned %d\n",
     
    410300                              DWORD  dwMoveMethod)
    411301{
    412   HANDLE hFile2;
    413 
    414 //  dprintf(("KERNEL32:  SetFilePointer\n"));
    415 
    416   /* @@@PH experimental Handlemanager support */
    417   if (HMHandleTranslateToOS2(hFile,
    418                        &hFile2) == NO_ERROR)
    419     hFile = hFile2;
    420 
    421   return(O32_SetFilePointer(hFile,
    422                             lDistanceToMove,
    423                             lpDistanceToMoveHigh,
    424                             dwMoveMethod));
     302  dprintf(("KERNEL32: SetFilePointer(%08xh,%08xh,%08xh,%08xh)\n",
     303           hFile,
     304           lDistanceToMove,
     305           lpDistanceToMoveHigh,
     306           dwMoveMethod));
     307
     308  return(HMSetFilePointer(hFile,
     309                         lDistanceToMove,
     310                         lpDistanceToMoveHigh,
     311                         dwMoveMethod));
    425312}
    426313//******************************************************************************
    427314//******************************************************************************
    428315BOOL WIN32API WriteFile(HANDLE  hFile,
    429                            LPCVOID buffer,
    430                            DWORD   nrbytes,
    431                            LPDWORD nrbyteswritten,
    432                            LPOVERLAPPED lpOverlapped)
    433 {
    434   BOOL   rc;
    435   HANDLE hFile2;
    436 
    437   //@@@PH translate handle
    438   //KSO Aug 31 1998: when writing 0 bytes to a file win32 sets eof here.
    439   if (nrbytes == 0 && !IS_HM_HANDLE(hFile))
    440   {
    441     *nrbyteswritten = 0;
    442     return O32_SetEndOfFile(hFile);
    443   }
    444 
    445   /* @@@PH 1998/02/12 Handle Manager support */
    446   if (IS_HM_HANDLE(hFile))
    447     return (HMWriteFile(hFile,
    448                         buffer,
    449                         nrbytes,
    450                         nrbyteswritten,
    451                         lpOverlapped));
    452 
    453   /* @@@PH experimental Handlemanager support */
    454   if (HMHandleTranslateToOS2(hFile,
    455                        &hFile2) == NO_ERROR)
    456     hFile = hFile2;
    457 
    458 
    459   rc = O32_WriteFile(hFile, buffer, nrbytes, nrbyteswritten, (LPOVERLAPPED)lpOverlapped);
    460   if(rc == 0 && GetLastError() == 436) { //ERROR_VIO_INVALID_HANDLE (OS/2)
    461 ////    dprintf(("KERNEL32:  WriteFile %s\n", buffer));
    462         return(TRUE);
    463   }
    464   dprintf(("KERNEL32:  WriteFile handle = %X, %d bytes, returned %d (%X)\n", hFile, nrbytes, rc, GetLastError()));
    465   return(rc);
     316                        LPCVOID buffer,
     317                        DWORD   nrbytes,
     318                        LPDWORD nrbyteswritten,
     319                        LPOVERLAPPED lpOverlapped)
     320{
     321  dprintf(("KERNEL32: WriteFile(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
     322           hFile,
     323           buffer,
     324           nrbytes,
     325           nrbyteswritten,
     326           lpOverlapped));
     327
     328  return (HMWriteFile(hFile,
     329                      buffer,
     330                      nrbytes,
     331                      nrbyteswritten,
     332                      lpOverlapped));
    466333}
    467334//******************************************************************************
     
    586453                       DWORD  arg5)
    587454{
    588   HFILE hFile;
    589 
    590   /* @@@PH experimental Handlemanager support */
    591   if (HMHandleTranslateToOS2(arg1,
    592                        &hFile) == NO_ERROR)
    593     arg1 = hFile;
    594 
    595455  dprintf(("KERNEL32: LockFile (%08xh,%08xh,%08xh,%08xh,%08xh)\n",
    596456           arg1,
     
    600460           arg5));
    601461
    602   return O32_LockFile(arg1,
    603                       arg2,
    604                       arg3,
    605                       arg4,
    606                       arg5);
     462  return HMLockFile(arg1,
     463                    arg2,
     464                    arg3,
     465                    arg4,
     466                    arg5);
    607467}
    608468
     
    630490                         DWORD        nNumberOfBytesToLockLow,
    631491                         DWORD        nNumberOfBytesToLockHigh,
    632                          LPOVERLAPPED LPOVERLAPPED)
    633 {
    634   HFILE hFile2;
    635 
    636   /* @@@PH experimental Handlemanager support */
    637   if (HMHandleTranslateToOS2(hFile,
    638                        &hFile2) == NO_ERROR)
    639     hFile = hFile2;
    640 
     492                         LPOVERLAPPED lpOverlapped)
     493{
    641494  dprintf(("Kernel32: LockFileEx(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh)\n",
    642495           hFile,
     
    645498           nNumberOfBytesToLockLow,
    646499           nNumberOfBytesToLockHigh,
    647            LPOVERLAPPED));
    648 
    649   return(O32_LockFile(hFile,
    650                   LPOVERLAPPED->Offset,
    651                   LPOVERLAPPED->OffsetHigh,
    652                   nNumberOfBytesToLockLow,
    653                   nNumberOfBytesToLockHigh));
     500           lpOverlapped));
     501
     502  return(HMLockFile(hFile,
     503                    lpOverlapped->Offset,
     504                    lpOverlapped->OffsetHigh,
     505                    nNumberOfBytesToLockLow,
     506                    nNumberOfBytesToLockHigh));
    654507}
    655508
     
    715568{
    716569  HFILE hFile;
    717   ULONG ulWindowsHandle;                        /* translated windows handle */
    718570
    719571  dprintf(("KERNEL32: OpenFile(%s, %08xh, %08xh)\n",
     
    722574           arg3));
    723575
    724   hFile = O32_OpenFile(arg1,                                      /* call open32 */
    725                    arg2,
    726                    arg3);
    727 
    728   /* @@@PH 1999/06/09 HandleManager support temporarily disabled */
    729   if (hFile != 0)                                /* check if handle is valid */
    730   {
    731     if (HMHandleAllocate(&ulWindowsHandle,    /* allocate translation handle */
    732                          hFile) == NO_ERROR)
    733       return (ulWindowsHandle);
    734   }
     576  hFile = HMOpenFile(arg1,                                      /* call open32 */
     577                     arg2,
     578                     arg3);
    735579
    736580  return (hFile);
     
    744588                         DWORD  arg5)
    745589{
    746   HFILE hFile2;
    747 
    748   /* @@@PH experimental Handlemanager support */
    749   if (HMHandleTranslateToOS2(arg1,
    750                        &hFile2) == NO_ERROR)
    751     arg1 = hFile2;
    752 
    753590  dprintf(("KERNEL32: UnlockFile(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
    754591           arg1,
     
    758595           arg5));
    759596
    760   return O32_UnlockFile(arg1,
    761                         arg2,
    762                         arg3,
    763                         arg4,
    764                         arg5);
     597  return HMUnlockFile(arg1,
     598                      arg2,
     599                      arg3,
     600                      arg4,
     601                      arg5);
    765602}
    766603
     
    786623                           DWORD        nNumberOfBytesToLockLow,
    787624                           DWORD        nNumberOfBytesToLockHigh,
    788                            LPOVERLAPPED LPOVERLAPPED)
    789 {
    790   HFILE hFile2;
    791 
    792   /* @@@PH experimental Handlemanager support */
    793   if (HMHandleTranslateToOS2(hFile,
    794                        &hFile2) == NO_ERROR)
    795     hFile = hFile2;
    796 
     625                           LPOVERLAPPED lpOverlapped)
     626{
    797627  dprintf(("Kernel32: UnlockFileEx(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh)\n",
    798628           hFile,
     
    800630           nNumberOfBytesToLockLow,
    801631           nNumberOfBytesToLockHigh,
    802            LPOVERLAPPED));
    803 
    804   return(O32_UnlockFile(hFile,
    805                    LPOVERLAPPED->Offset,
    806                    LPOVERLAPPED->OffsetHigh,
    807                    nNumberOfBytesToLockLow,
    808                    nNumberOfBytesToLockHigh));
     632           lpOverlapped));
     633
     634  return(HMUnlockFile(hFile,
     635                      lpOverlapped->Offset,
     636                      lpOverlapped->OffsetHigh,
     637                      nNumberOfBytesToLockLow,
     638                      nNumberOfBytesToLockHigh));
    809639}
    810640//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.