source: trunk/src/kernel32/hmfile.cpp@ 4230

Last change on this file since 4230 was 4230, checked in by sandervl, 25 years ago

memory map fixes + extra reg keys for init

File size: 37.8 KB
Line 
1/* $Id: hmfile.cpp,v 1.20 2000-09-10 21:54:06 sandervl Exp $ */
2
3/*
4 * File IO win32 apis
5 *
6 * Copyright 1999-2000 Sander van Leeuwen
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12
13/*****************************************************************************
14 * Remark *
15 *****************************************************************************
16 */
17
18//#define DEBUG_LOCAL
19
20#ifdef DEBUG_LOCAL
21# define dprintfl(a) dprintf(a)
22#else
23inline void ignore_dprintf(...){}
24# define dprintfl(a) ignore_dprintf(a)
25#endif
26
27/*****************************************************************************
28 * Includes *
29 *****************************************************************************/
30
31#include <os2win.h>
32#include <string.h>
33#include "HandleManager.h"
34#include "HMFile.h"
35#include "mmap.h"
36#include "oslibdos.h"
37
38#define DBG_LOCALLOG DBG_hmfile
39#include "dbglocal.h"
40
41/*****************************************************************************
42 * Name : DWORD HMDeviceFileClass::CreateFile
43 * Purpose : this is called from the handle manager if a CreateFile() is
44 * performed on a handle
45 * Parameters: LPCSTR lpFileName name of the file / device
46 * PHMHANDLEDATA pHMHandleData data of the NEW handle
47 * PVOID lpSecurityAttributes ignored
48 * PHMHANDLEDATA pHMHandleDataTemplate data of the template handle
49 * Variables :
50 * Result :
51 * Remark :
52 * Status : NO_ERROR - API succeeded
53 * other - what is to be set in SetLastError
54 *
55 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
56 *****************************************************************************/
57
58DWORD HMDeviceFileClass::CreateFile (LPCSTR lpFileName,
59 PHMHANDLEDATA pHMHandleData,
60 PVOID lpSecurityAttributes,
61 PHMHANDLEDATA pHMHandleDataTemplate)
62{
63 HFILE hFile;
64 HFILE hTemplate;
65
66 dprintfl(("KERNEL32: HMDeviceFileClass::CreateFile %s(%s,%08x,%08x,%08x)\n",
67 lpHMDeviceName,
68 lpFileName,
69 pHMHandleData,
70 lpSecurityAttributes,
71 pHMHandleDataTemplate));
72
73 if(strncmp(lpFileName, // "support" for local unc names
74 "\\\\.\\",
75 4) == 0)
76 {
77 // check the named pipes
78 if (strnicmp("\\\\.\\PIPE",lpFileName,8)==0)
79 lpFileName+=3;
80 else
81 lpFileName+=4;
82 }
83
84
85 // create from template
86 if (pHMHandleDataTemplate != NULL)
87 hTemplate = pHMHandleDataTemplate->hHMHandle;
88 else
89 hTemplate = 0;
90
91 //TODO: FILE_SHARE_DELETE
92 hFile = OSLibDosCreateFile((LPSTR)lpFileName,
93 pHMHandleData->dwAccess,
94 pHMHandleData->dwShare,
95 (LPSECURITY_ATTRIBUTES)lpSecurityAttributes,
96 pHMHandleData->dwCreation,
97 pHMHandleData->dwFlags,
98 hTemplate);
99
100 if (hFile != INVALID_HANDLE_ERROR)
101 {
102 pHMHandleData->dwUserData = (DWORD) new HMFileInfo((LPSTR)lpFileName, lpSecurityAttributes);
103 pHMHandleData->hHMHandle = hFile;
104 return (NO_ERROR);
105 }
106 else {
107 dprintf(("CreateFile failed; error %d", GetLastError()));
108 return(GetLastError());
109 }
110}
111
112/*****************************************************************************
113 * Name : DWORD HMDeviceFileClass::OpenFile
114 * Purpose : this is called from the handle manager if a OpenFile() is
115 * performed on a handle
116 * Parameters: LPCSTR lpFileName name of the file / device
117 * PHMHANDLEDATA pHMHandleData data of the NEW handle
118 * PVOID lpSecurityAttributes ignored
119 * PHMHANDLEDATA pHMHandleDataTemplate data of the template handle
120 * Variables :
121 * Result :
122 * Remark : TODO: Check if this implementation is complete and 100% correct
123 * Status : NO_ERROR - API succeeded
124 * other - what is to be set in SetLastError
125 *
126 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
127 *****************************************************************************/
128
129DWORD HMDeviceFileClass::OpenFile (LPCSTR lpszFileName,
130 PHMHANDLEDATA pHMHandleData,
131 OFSTRUCT *pOFStruct,
132 UINT fuMode)
133{
134 HFILE hFile;
135 FILETIME filetime;
136 WORD filedatetime[2];
137 char filepath[260];
138 LPSTR lpFileName = (LPSTR)lpszFileName;
139
140 SetLastError(ERROR_SUCCESS);
141
142 dprintf(("KERNEL32: HMDeviceFileClass::OpenFile %s(%s,%08x,%08x,%08x)",
143 lpHMDeviceName,
144 lpFileName,
145 pHMHandleData,
146 pOFStruct,
147 fuMode));
148
149 //Re-open using name in OFSTRUCT
150 if(fuMode & OF_REOPEN)
151 lpFileName = (LPSTR)pOFStruct->szPathName;
152 else memset(pOFStruct, 0, sizeof(OFSTRUCT));
153
154 if(strcmp(lpFileName, // "support" for local unc names
155 "\\\\.\\") == 0)
156 {
157 lpFileName+=4;
158 }
159 else
160 if(!strchr(lpFileName, ':') && !strchr(lpFileName, '\\'))
161 {
162 //filename only; search for file in following order
163 //1: dir from which the app loaded
164 //2: current dir
165 //3: windows system dir
166 //4: windows dir
167 //5: dirs in path path environment variable
168 //SearchPath does exactly that
169 LPSTR filenameinpath;
170
171 if(SearchPathA(NULL, lpFileName, NULL, sizeof(filepath), filepath, &filenameinpath) == 0
172 && !(fuMode & OF_CREATE) )
173 {
174 pOFStruct->nErrCode = ERROR_FILE_NOT_FOUND;
175 SetLastError(ERROR_FILE_NOT_FOUND);
176 return HFILE_ERROR;
177 }
178 lpFileName = filepath;
179 }
180 // filling OFSTRUCT
181 pOFStruct->cBytes = sizeof(OFSTRUCT);
182 pOFStruct->nErrCode = 0;
183 strncpy((char *)pOFStruct->szPathName, lpFileName, OFS_MAXPATHNAME);
184 pOFStruct->szPathName[OFS_MAXPATHNAME-1] = 0;
185
186 hFile = OSLibDosOpenFile((LPSTR)lpFileName, fuMode);
187
188 if(hFile != INVALID_HANDLE_ERROR)
189 {
190 //Needed for GetFileTime
191 pHMHandleData->hHMHandle = hFile;
192 GetFileTime(pHMHandleData,
193 NULL,
194 NULL,
195 &filetime );
196
197 FileTimeToDosDateTime(&filetime,
198 &filedatetime[0],
199 &filedatetime[1] );
200 memcpy(pOFStruct->reserved, filedatetime, sizeof(pOFStruct->reserved));
201
202 if(fuMode & OF_DELETE)
203 {
204 OSLibDosClose(hFile);
205 OSLibDosDelete((LPSTR)lpFileName);
206 }
207 else
208 if(fuMode & OF_EXIST)
209 {
210 OSLibDosClose(hFile);
211 hFile = HFILE_ERROR;
212 }
213 if(fuMode & OF_PARSE)
214 {
215 CHAR drive[4];
216
217 drive[0] = pOFStruct->szPathName[0];
218 drive[1] = pOFStruct->szPathName[1];
219 drive[2] = pOFStruct->szPathName[2];
220 drive[3] = 0;
221
222 pOFStruct->fFixedDisk = (GetDriveTypeA(drive) != DRIVE_REMOVABLE);
223
224 OSLibDosClose(hFile);
225 hFile = HFILE_ERROR;
226 }
227
228 if((fuMode & OF_VERIFY))
229 {
230 if(memcmp(pOFStruct->reserved, filedatetime, sizeof(pOFStruct->reserved)))
231 {
232 OSLibDosClose(hFile);
233 SetLastError(ERROR_FILE_NOT_FOUND);
234 }
235 hFile = HFILE_ERROR;
236 }
237
238 pOFStruct->nErrCode = GetLastError();
239 pHMHandleData->hHMHandle = hFile;
240
241 if(hFile != HFILE_ERROR) {
242 pHMHandleData->dwUserData = (DWORD) new HMFileInfo((LPSTR)lpFileName, NULL);
243 }
244 return (NO_ERROR);
245 }
246 else {
247 DWORD rc = GetLastError();
248
249 if(fuMode & OF_EXIST)
250 {
251 if(rc == ERROR_OPEN_FAILED) {
252 SetLastError(ERROR_FILE_NOT_FOUND);
253 }
254 }
255 //todo: OF_PROMPT handling (pop up message box)
256 }
257 // error branch
258 pOFStruct->nErrCode = GetLastError();
259 dprintf(("KERNEL32: HMDeviceFileClass::OpenFile Error %08xh\n",
260 pOFStruct->nErrCode));
261
262 // return != NO_ERROR => error code
263 return(hFile);
264}
265
266/*****************************************************************************
267 * Name : HMDeviceFileClass::DuplicateHandle
268 * Purpose :
269 * Parameters:
270 * various parameters as required
271 * Variables :
272 * Result :
273 * Remark : DUPLICATE_CLOSE_SOURCE flag handled in HMDuplicateHandle
274 *
275 * Status : partially implemented
276 *
277 * Author : SvL
278 *****************************************************************************/
279BOOL HMDeviceFileClass::DuplicateHandle(PHMHANDLEDATA pHMHandleData,
280 HANDLE srcprocess,
281 PHMHANDLEDATA pHMSrcHandle,
282 HANDLE destprocess,
283 PHANDLE desthandle,
284 DWORD fdwAccess,
285 BOOL fInherit,
286 DWORD fdwOptions,
287 DWORD fdwOdinOptions)
288{
289 HMFileInfo *srcfileinfo = (HMFileInfo *)pHMSrcHandle->dwUserData;
290 DWORD rc;
291
292 dprintf(("KERNEL32:HMDeviceFileClass::DuplicateHandle (%08x,%08x,%08x,%08x,%08x)",
293 pHMHandleData,
294 srcprocess,
295 pHMSrcHandle->hHMHandle,
296 destprocess,
297 desthandle));
298
299 //TODO: Inheritance of file handles won't work!
300
301 if(destprocess != srcprocess)
302 {
303 //TODO:!!!!
304 dprintf(("ERROR: DuplicateHandle; different processes not yet supported!!"));
305 return FALSE;
306 }
307
308 if(srcfileinfo)
309 {
310 //SvL: Special duplicatehandle option used by memory mapped class to duplicate
311 // file handle
312 // Can't use DosDupHandle or else there can be a sharing violation
313 // when an app tries to access the same file again
314 if(fdwOdinOptions)
315 {
316 HMHANDLEDATA duphdata;
317
318 memcpy(&duphdata, pHMHandleData, sizeof(duphdata));
319 duphdata.dwCreation = OPEN_EXISTING;
320
321 if(CreateFile(srcfileinfo->lpszFileName, &duphdata,
322 srcfileinfo->lpSecurityAttributes, NULL) == NO_ERROR)
323 {
324 memcpy(pHMHandleData, &duphdata, sizeof(duphdata));
325 SetLastError(ERROR_SUCCESS);
326 return TRUE;
327 }
328 dprintf(("ERROR: DuplicateHandle; CreateFile %s failed -> trying DosDupHandle instead!",
329 srcfileinfo->lpszFileName));
330 //SvL: IE5 setup opens file with DENYREADWRITE, so CreateFile can't
331 // be used for duplicating the handle; try DosDupHandle instead
332 }
333
334 if(!(fdwOptions & DUPLICATE_SAME_ACCESS) && fdwAccess != pHMSrcHandle->dwAccess) {
335 dprintf(("WARNING: DuplicateHandle; app wants different access permission; Not supported!! (%x, %x)", fdwAccess, pHMSrcHandle->dwAccess));
336 }
337
338 rc = OSLibDosDupHandle(pHMSrcHandle->hHMHandle,
339 desthandle);
340 if (rc)
341 {
342 dprintf(("ERROR: DulicateHandle: OSLibDosDupHandle(%s) failed = %u\n",
343 rc,
344 srcfileinfo->lpszFileName));
345 SetLastError(rc);
346 return FALSE; // ERROR
347 }
348 else {
349 SetLastError(ERROR_SUCCESS);
350 pHMHandleData->hHMHandle = *desthandle;
351 return TRUE; // OK
352 }
353 }
354 else
355 {
356 dprintf(("ERROR: DuplicateHandle; invalid parameter!!"));
357 SetLastError(ERROR_INVALID_PARAMETER);
358 return FALSE;
359 }
360}
361
362/*****************************************************************************
363 * Name : DWORD HMDeviceFileClass::CloseHandle
364 * Purpose : close the handle
365 * Parameters: PHMHANDLEDATA pHMHandleData
366 * Variables :
367 * Result : API returncode
368 * Remark :
369 * Status :
370 *
371 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
372 *****************************************************************************/
373
374DWORD HMDeviceFileClass::CloseHandle(PHMHANDLEDATA pHMHandleData)
375{
376 HMFileInfo *fileInfo = (HMFileInfo *)pHMHandleData->dwUserData;
377 BOOL bRC;
378
379 dprintfl(("KERNEL32: HMDeviceFileClass::CloseHandle(%08x)\n",
380 pHMHandleData->hHMHandle));
381
382 bRC = OSLibDosClose(pHMHandleData->hHMHandle);
383
384 if(pHMHandleData->dwFlags & FILE_FLAG_DELETE_ON_CLOSE) {
385 //TODO: should only do this after all handles have been closed
386 if(fileInfo) {
387 DeleteFileA(fileInfo->lpszFileName);
388 }
389 }
390 if(fileInfo) {
391 delete fileInfo;
392 }
393 dprintf(("KERNEL32: HMDeviceFileClass::CloseHandle returned %08xh\n",
394 bRC));
395
396 return (DWORD)bRC;
397}
398
399
400/*****************************************************************************
401 * Name : BOOL HMDeviceFileClass::ReadFile
402 * Purpose : read data from handle / device
403 * Parameters: PHMHANDLEDATA pHMHandleData,
404 * LPCVOID lpBuffer,
405 * DWORD nNumberOfBytesToRead,
406 * LPDWORD lpNumberOfBytesRead,
407 * LPOVERLAPPED lpOverlapped
408 * Variables :
409 * Result : Boolean
410 * Remark :
411 * Status :
412 *
413 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
414 *****************************************************************************/
415
416BOOL HMDeviceFileClass::ReadFile(PHMHANDLEDATA pHMHandleData,
417 LPCVOID lpBuffer,
418 DWORD nNumberOfBytesToRead,
419 LPDWORD lpNumberOfBytesRead,
420 LPOVERLAPPED lpOverlapped)
421{
422 LPVOID lpRealBuf;
423 Win32MemMap *map;
424 DWORD offset, bytesread;
425 BOOL bRC;
426
427 dprintfl(("KERNEL32: HMDeviceFileClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x) - stub?\n",
428 lpHMDeviceName,
429 pHMHandleData,
430 lpBuffer,
431 nNumberOfBytesToRead,
432 lpNumberOfBytesRead,
433 lpOverlapped));
434
435 //SvL: It's legal for this pointer to be NULL
436 if(lpNumberOfBytesRead)
437 *lpNumberOfBytesRead = 0;
438 else
439 lpNumberOfBytesRead = &bytesread;
440
441 if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
442 dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
443 SetLastError(ERROR_INVALID_PARAMETER);
444 return FALSE;
445 }
446 if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
447 dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
448 }
449
450 //SvL: DosRead doesn't like writing to memory addresses returned by
451 // DosAliasMem -> search for original memory mapped pointer and use
452 // that one + commit pages if not already present
453 map = Win32MemMapView::findMapByView((ULONG)lpBuffer, &offset, MEMMAP_ACCESS_WRITE);
454 if(map) {
455 lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset);
456 DWORD nrpages = nNumberOfBytesToRead/4096;
457 if(offset & 0xfff)
458 nrpages++;
459 if(nNumberOfBytesToRead & 0xfff)
460 nrpages++;
461
462 map->commitPage(offset & ~0xfff, TRUE, nrpages);
463 }
464 else lpRealBuf = (LPVOID)lpBuffer;
465
466 if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) {
467 dprintf(("ERROR: Overlapped IO not yet implememented!!"));
468 }
469// else {
470 bRC = OSLibDosRead(pHMHandleData->hHMHandle,
471 (PVOID)lpRealBuf,
472 nNumberOfBytesToRead,
473 lpNumberOfBytesRead);
474// }
475
476 if(bRC == 0) {
477 dprintf(("KERNEL32: HMDeviceFileClass::ReadFile returned %08xh %x\n",
478 bRC, GetLastError()));
479 dprintf(("%x -> %d", lpBuffer, IsBadWritePtr((LPVOID)lpBuffer, nNumberOfBytesToRead)));
480 }
481
482 return bRC;
483}
484
485/*****************************************************************************
486 * Name : BOOL ReadFileEx
487 * Purpose : The ReadFileEx function reads data from a file asynchronously.
488 * It is designed solely for asynchronous operation, unlike the
489 * ReadFile function, which is designed for both synchronous and
490 * asynchronous operation. ReadFileEx lets an application perform
491 * other processing during a file read operation.
492 * The ReadFileEx function reports its completion status asynchronously,
493 * calling a specified completion routine when reading is completed
494 * and the calling thread is in an alertable wait state.
495 * Parameters: HANDLE hFile handle of file to read
496 * LPVOID lpBuffer address of buffer
497 * DWORD nNumberOfBytesToRead number of bytes to read
498 * LPOVERLAPPED lpOverlapped address of offset
499 * LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine
500 * Variables :
501 * Result : TRUE / FALSE
502 * Remark :
503 * Status : UNTESTED STUB
504 *
505 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
506 *****************************************************************************/
507BOOL HMDeviceFileClass::ReadFileEx(PHMHANDLEDATA pHMHandleData,
508 LPVOID lpBuffer,
509 DWORD nNumberOfBytesToRead,
510 LPOVERLAPPED lpOverlapped,
511 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
512{
513 dprintf(("ERROR: ReadFileEx(%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n",
514 pHMHandleData->hHMHandle,
515 lpBuffer,
516 nNumberOfBytesToRead,
517 lpOverlapped,
518 lpCompletionRoutine));
519 return FALSE;
520}
521
522
523/*****************************************************************************
524 * Name : BOOL HMDeviceFileClass::WriteFile
525 * Purpose : write data to handle / device
526 * Parameters: PHMHANDLEDATA pHMHandleData,
527 * LPCVOID lpBuffer,
528 * DWORD nNumberOfBytesToWrite,
529 * LPDWORD lpNumberOfBytesWritten,
530 * LPOVERLAPPED lpOverlapped
531 * Variables :
532 * Result : Boolean
533 * Remark :
534 * Status :
535 *
536 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
537 *****************************************************************************/
538
539BOOL HMDeviceFileClass::WriteFile(PHMHANDLEDATA pHMHandleData,
540 LPCVOID lpBuffer,
541 DWORD nNumberOfBytesToWrite,
542 LPDWORD lpNumberOfBytesWritten,
543 LPOVERLAPPED lpOverlapped)
544{
545 LPVOID lpRealBuf;
546 Win32MemMap *map;
547 DWORD offset, byteswritten;
548 BOOL bRC;
549
550 dprintfl(("KERNEL32: HMDeviceFileClass::WriteFile %s(%08x,%08x,%08x,%08x,%08x) - stub?\n",
551 lpHMDeviceName,
552 pHMHandleData,
553 lpBuffer,
554 nNumberOfBytesToWrite,
555 lpNumberOfBytesWritten,
556 lpOverlapped));
557
558 //SvL: It's legal for this pointer to be NULL
559 if(lpNumberOfBytesWritten)
560 *lpNumberOfBytesWritten = 0;
561 else
562 lpNumberOfBytesWritten = &byteswritten;
563
564 if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
565 dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
566 SetLastError(ERROR_INVALID_PARAMETER);
567 return FALSE;
568 }
569 if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
570 dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
571 }
572
573 //SvL: DosWrite doesn't like reading from memory addresses returned by
574 // DosAliasMem -> search for original memory mapped pointer and use
575 // that one + commit pages if not already present
576 map = Win32MemMapView::findMapByView((ULONG)lpBuffer, &offset, MEMMAP_ACCESS_READ);
577 if(map) {
578 lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset);
579 DWORD nrpages = nNumberOfBytesToWrite/4096;
580 if(offset & 0xfff)
581 nrpages++;
582 if(nNumberOfBytesToWrite & 0xfff)
583 nrpages++;
584
585 map->commitPage(offset & ~0xfff, TRUE, nrpages);
586 }
587 else lpRealBuf = (LPVOID)lpBuffer;
588
589 if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) {
590 dprintf(("ERROR: Overlapped IO not yet implememented!!"));
591 }
592// else {
593 bRC = OSLibDosWrite(pHMHandleData->hHMHandle,
594 (PVOID)lpRealBuf,
595 nNumberOfBytesToWrite,
596 lpNumberOfBytesWritten);
597// }
598
599 dprintf(("KERNEL32: HMDeviceFileClass::WriteFile returned %08xh\n",
600 bRC));
601
602 return bRC;
603}
604
605/*****************************************************************************
606 * Name : BOOL WriteFileEx
607 * Purpose : The WriteFileEx function writes data to a file. It is designed
608 * solely for asynchronous operation, unlike WriteFile, which is
609 * designed for both synchronous and asynchronous operation.
610 * WriteFileEx reports its completion status asynchronously,
611 * calling a specified completion routine when writing is completed
612 * and the calling thread is in an alertable wait state.
613 * Parameters: HANDLE hFile handle of file to write
614 * LPVOID lpBuffer address of buffer
615 * DWORD nNumberOfBytesToRead number of bytes to write
616 * LPOVERLAPPED lpOverlapped address of offset
617 * LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine
618 * Variables :
619 * Result : TRUE / FALSE
620 * Remark :
621 * Status : UNTESTED STUB
622 *
623 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
624 *****************************************************************************/
625
626BOOL HMDeviceFileClass::WriteFileEx(PHMHANDLEDATA pHMHandleData,
627 LPVOID lpBuffer,
628 DWORD nNumberOfBytesToWrite,
629 LPOVERLAPPED lpOverlapped,
630 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
631{
632 dprintf(("ERROR: WriteFileEx(%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n",
633 pHMHandleData->hHMHandle,
634 lpBuffer,
635 nNumberOfBytesToWrite,
636 lpOverlapped,
637 lpCompletionRoutine));
638 return FALSE;
639}
640
641/*****************************************************************************
642 * Name : DWORD HMDeviceFileClass::GetFileType
643 * Purpose : determine the handle type
644 * Parameters: PHMHANDLEDATA pHMHandleData
645 * Variables :
646 * Result : API returncode
647 * Remark :
648 * Status :
649 *
650 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
651 *****************************************************************************/
652
653DWORD HMDeviceFileClass::GetFileType(PHMHANDLEDATA pHMHandleData)
654{
655 dprintfl(("KERNEL32: HMDeviceFileClass::GetFileType %s(%08x)\n",
656 lpHMDeviceName,
657 pHMHandleData));
658
659 return FILE_TYPE_DISK;
660}
661
662
663/*****************************************************************************
664 * Name : DWORD HMDeviceFileClass::GetFileInformationByHandle
665 * Purpose : determine the handle type
666 * Parameters: PHMHANDLEDATA pHMHandleData
667 * BY_HANDLE_FILE_INFORMATION* pHFI
668 * Variables :
669 * Result : API returncode
670 * Remark :
671 * Status :
672 *
673 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
674 *****************************************************************************/
675
676DWORD HMDeviceFileClass::GetFileInformationByHandle(PHMHANDLEDATA pHMHandleData,
677 BY_HANDLE_FILE_INFORMATION* pHFI)
678{
679 dprintfl(("KERNEL32: HMDeviceFileClass::GetFileInformationByHandle %s(%08xh,%08xh)\n",
680 lpHMDeviceName,
681 pHMHandleData,
682 pHFI));
683
684 if(OSLibDosGetFileInformationByHandle(pHMHandleData->hHMHandle,
685 pHFI))
686 {
687 return TRUE;
688 }
689 dprintf(("GetFileInformationByHandle failed with error %d", GetLastError()));
690 return FALSE;
691
692}
693
694
695/*****************************************************************************
696 * Name : BOOL HMDeviceFileClass::SetEndOfFile
697 * Purpose : set end of file marker
698 * Parameters: PHMHANDLEDATA pHMHandleData
699 * Variables :
700 * Result : API returncode
701 * Remark :
702 * Status :
703 *
704 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
705 *****************************************************************************/
706
707BOOL HMDeviceFileClass::SetEndOfFile(PHMHANDLEDATA pHMHandleData)
708{
709 dprintfl(("KERNEL32: HMDeviceFileClass::SetEndOfFile %s(%08xh)\n",
710 lpHMDeviceName,
711 pHMHandleData));
712
713 if(OSLibDosSetEndOfFile(pHMHandleData->hHMHandle)) {
714 return TRUE;
715 }
716 dprintf(("SetEndOfFile failed with error %d", GetLastError()));
717 return FALSE;
718}
719
720
721/*****************************************************************************
722 * Name : BOOL HMDeviceFileClass::SetFileTime
723 * Purpose : set file time
724 * Parameters: PHMHANDLEDATA pHMHandleData
725 * PFILETIME pFT1
726 * PFILETIME pFT2
727 * PFILETIME pFT3
728 * Variables :
729 * Result : API returncode
730 * Remark :
731 * Status :
732 *
733 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
734 *****************************************************************************/
735
736BOOL HMDeviceFileClass::SetFileTime(PHMHANDLEDATA pHMHandleData,
737 LPFILETIME pFT1,
738 LPFILETIME pFT2,
739 LPFILETIME pFT3)
740{
741 WORD creationdate = 0, creationtime = 0;
742 WORD lastaccessdate = 0, lastaccesstime = 0;
743 WORD lastwritedate = 0, lastwritetime = 0;
744
745 dprintfl(("KERNEL32: HMDeviceFileClass::SetFileTime %s(%08xh,%08xh,%08xh,%08xh)\n",
746 lpHMDeviceName,
747 pHMHandleData,
748 pFT1,
749 pFT2,
750 pFT3));
751
752 if(pFT1 && pFT1->dwLowDateTime && pFT1->dwHighDateTime) {
753 FileTimeToDosDateTime(pFT1, &creationdate, &creationtime);
754 }
755
756 if(pFT2 && pFT2->dwLowDateTime && pFT2->dwHighDateTime) {
757 FileTimeToDosDateTime(pFT2, &lastaccessdate, &lastaccesstime);
758 }
759
760 if(pFT3 && pFT3->dwLowDateTime && pFT3->dwHighDateTime) {
761 FileTimeToDosDateTime(pFT3, &lastwritedate, &lastwritetime);
762 }
763
764 if(OSLibDosSetFileTime(pHMHandleData->hHMHandle,
765 creationdate, creationtime,
766 lastaccessdate, lastaccesstime,
767 lastwritedate, lastwritetime))
768 {
769 return TRUE;
770 }
771 dprintf(("SetFileTime failed with error %d", GetLastError()));
772 return FALSE;
773}
774
775/*****************************************************************************
776 * Name : BOOL HMDeviceFileClass::GetFileTime
777 * Purpose : get file time
778 * Parameters: PHMHANDLEDATA pHMHandleData
779 * PFILETIME pFT1
780 * PFILETIME pFT2
781 * PFILETIME pFT3
782 * Variables :
783 * Result : API returncode
784 * Remark :
785 * Status :
786 *
787 * Author : SvL
788 *****************************************************************************/
789
790BOOL HMDeviceFileClass::GetFileTime(PHMHANDLEDATA pHMHandleData,
791 LPFILETIME pFT1,
792 LPFILETIME pFT2,
793 LPFILETIME pFT3)
794{
795 WORD creationdate, creationtime;
796 WORD lastaccessdate, lastaccesstime;
797 WORD lastwritedate, lastwritetime;
798 BOOL rc;
799
800 if(!pFT1 && !pFT2 && !pFT3) {//TODO: does NT do this?
801 dprintf(("ERROR: GetFileTime: invalid parameter!"));
802 SetLastError(ERROR_INVALID_PARAMETER);
803 return FALSE;
804 }
805
806 if(OSLibDosGetFileTime(pHMHandleData->hHMHandle,
807 &creationdate, &creationtime,
808 &lastaccessdate, &lastaccesstime,
809 &lastwritedate, &lastwritetime))
810 {
811 if(pFT1) {
812 DosDateTimeToFileTime(creationdate, creationtime, pFT1);
813 }
814 if(pFT2) {
815 DosDateTimeToFileTime(lastaccessdate, lastaccesstime, pFT2);
816 }
817 if(pFT3) {
818 DosDateTimeToFileTime(lastwritedate, lastwritetime, pFT3);
819 }
820 return TRUE;
821 }
822 dprintf(("GetFileTime failed with error %d", GetLastError()));
823 return FALSE;
824}
825
826/*****************************************************************************
827 * Name : DWORD HMDeviceFileClass::GetFileSize
828 * Purpose : set file time
829 * Parameters: PHMHANDLEDATA pHMHandleData
830 * PDWORD pSize
831 * Variables :
832 * Result : API returncode
833 * Remark :
834 * Status :
835 *
836 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
837 *****************************************************************************/
838
839DWORD HMDeviceFileClass::GetFileSize(PHMHANDLEDATA pHMHandleData,
840 PDWORD lpdwFileSizeHigh)
841{
842 dprintfl(("KERNEL32: HMDeviceFileClass::GetFileSize %s(%08xh,%08xh)\n",
843 lpHMDeviceName,
844 pHMHandleData,
845 lpdwFileSizeHigh));
846
847 if(lpdwFileSizeHigh)
848 *lpdwFileSizeHigh = 0;
849
850 return OSLibDosGetFileSize(pHMHandleData->hHMHandle, lpdwFileSizeHigh);
851}
852
853/*****************************************************************************
854 * Name : DWORD HMDeviceFileClass::SetFilePointer
855 * Purpose : set file pointer
856 * Parameters: PHMHANDLEDATA pHMHandleData
857 * LONG lDistanceToMove
858 * PLONG lpDistanceToMoveHigh
859 * DWORD dwMoveMethod
860 * Variables :
861 * Result : API returncode
862 * Remark :
863 * Status :
864 *
865 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
866 *****************************************************************************/
867
868DWORD HMDeviceFileClass::SetFilePointer(PHMHANDLEDATA pHMHandleData,
869 LONG lDistanceToMove,
870 PLONG lpDistanceToMoveHigh,
871 DWORD dwMoveMethod)
872{
873 DWORD ret;
874
875 dprintfl(("KERNEL32: HMDeviceFileClass::SetFilePointer %s(%08xh,%08xh,%08xh,%08xh)\n",
876 lpHMDeviceName,
877 pHMHandleData,
878 lDistanceToMove,
879 lpDistanceToMoveHigh,
880 dwMoveMethod));
881
882 ret = OSLibDosSetFilePointer(pHMHandleData->hHMHandle,
883 lDistanceToMove,
884 (DWORD *)lpDistanceToMoveHigh,
885 dwMoveMethod);
886
887 if(ret == -1) {
888 dprintf(("SetFilePointer failed (error = %d)", GetLastError()));
889 }
890 return ret;
891}
892
893
894/*****************************************************************************
895 * Name : DWORD HMDeviceFileClass::LockFile
896 * Purpose : file locking
897 * Parameters: PHMHANDLEDATA pHMHandleData
898 * DWORD arg2
899 * DWORD arg3
900 * DWORD arg4
901 * DWORD arg5
902 * Variables :
903 * Result : API returncode
904 * Remark :
905 * Status :
906 *
907 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
908 *****************************************************************************/
909
910BOOL HMDeviceFileClass::LockFile(PHMHANDLEDATA pHMHandleData,
911 DWORD dwFileOffsetLow,
912 DWORD dwFileOffsetHigh,
913 DWORD cbLockLow,
914 DWORD cbLockHigh)
915{
916 dprintfl(("KERNEL32: HMDeviceFileClass::LockFile %s(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
917 lpHMDeviceName,
918 pHMHandleData,
919 dwFileOffsetLow,
920 dwFileOffsetHigh,
921 cbLockLow,
922 cbLockHigh));
923
924 return OSLibDosLockFile(pHMHandleData->hHMHandle,
925 LOCKFILE_EXCLUSIVE_LOCK,
926 dwFileOffsetLow,
927 dwFileOffsetHigh,
928 cbLockLow,
929 cbLockHigh,
930 NULL);
931}
932
933/*****************************************************************************
934 * Name : DWORD HMDeviceFileClass::LockFileEx
935 * Purpose : file locking
936 * Parameters: PHMHANDLEDATA pHMHandleData
937 * DWORD dwFlags
938 * DWORD dwReserved
939 * DWORD nNumberOfBytesToLockLow
940 * DWORD nNumberOfBytesToLockHigh
941 * LPOVERLAPPED lpOverlapped
942 * Variables :
943 * Result : API returncode
944 * Remark :
945 * Status :
946 *
947 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
948 *****************************************************************************/
949
950BOOL HMDeviceFileClass::LockFileEx(PHMHANDLEDATA pHMHandleData,
951 DWORD dwFlags,
952 DWORD dwReserved,
953 DWORD nNumberOfBytesToLockLow,
954 DWORD nNumberOfBytesToLockHigh,
955 LPOVERLAPPED lpOverlapped)
956{
957
958 dprintfl(("KERNEL32: HMDeviceFileClass::LockFileEx %s(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh) not completely implemented!",
959 lpHMDeviceName,
960 pHMHandleData,
961 dwFlags,
962 dwReserved,
963 nNumberOfBytesToLockLow,
964 nNumberOfBytesToLockHigh,
965 lpOverlapped));
966
967
968 return(OSLibDosLockFile(pHMHandleData->hHMHandle,
969 dwFlags,
970 lpOverlapped->Offset,
971 lpOverlapped->OffsetHigh,
972 nNumberOfBytesToLockLow,
973 nNumberOfBytesToLockHigh,
974 lpOverlapped));
975}
976
977
978/*****************************************************************************
979 * Name : DWORD HMDeviceFileClass::UnlockFile
980 * Purpose : file locking
981 * Parameters: PHMHANDLEDATA pHMHandleData
982 * DWORD arg2
983 * DWORD arg3
984 * DWORD arg4
985 * DWORD arg5
986 * Variables :
987 * Result : API returncode
988 * Remark :
989 * Status :
990 *
991 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
992 *****************************************************************************/
993
994BOOL HMDeviceFileClass::UnlockFile(PHMHANDLEDATA pHMHandleData,
995 DWORD dwFileOffsetLow,
996 DWORD dwFileOffsetHigh,
997 DWORD cbLockLow,
998 DWORD cbLockHigh)
999{
1000 dprintfl(("KERNEL32: HMDeviceFileClass::UnlockFile %s(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
1001 lpHMDeviceName,
1002 pHMHandleData,
1003 dwFileOffsetLow,
1004 dwFileOffsetHigh,
1005 cbLockLow,
1006 cbLockHigh));
1007
1008 return OSLibDosUnlockFile(pHMHandleData->hHMHandle,
1009 dwFileOffsetLow,
1010 dwFileOffsetHigh,
1011 cbLockLow,
1012 cbLockHigh,
1013 NULL);
1014}
1015
1016
1017
1018/*****************************************************************************
1019 * Name : DWORD HMDeviceFileClass::UnlockFileEx
1020 * Purpose : file locking
1021 * Parameters: PHMHANDLEDATA pHMHandleData
1022 * DWORD dwFlags
1023 * DWORD dwReserved
1024 * DWORD nNumberOfBytesToLockLow
1025 * DWORD nNumberOfBytesToLockHigh
1026 * LPOVERLAPPED lpOverlapped
1027 * Variables :
1028 * Result : API returncode
1029 * Remark :
1030 * Status :
1031 *
1032 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1033 *****************************************************************************/
1034
1035BOOL HMDeviceFileClass::UnlockFileEx(PHMHANDLEDATA pHMHandleData,
1036 DWORD dwReserved,
1037 DWORD nNumberOfBytesToLockLow,
1038 DWORD nNumberOfBytesToLockHigh,
1039 LPOVERLAPPED lpOverlapped)
1040{
1041
1042 dprintfl(("KERNEL32: HMDeviceFileClass::UnlockFileEx %s(%08xh,%08xh,%08xh,%08xh,%08xh) not completely implemented!",
1043 lpHMDeviceName,
1044 pHMHandleData,
1045 dwReserved,
1046 nNumberOfBytesToLockLow,
1047 nNumberOfBytesToLockHigh,
1048 lpOverlapped));
1049
1050
1051 return(OSLibDosUnlockFile(pHMHandleData->hHMHandle,
1052 lpOverlapped->Offset,
1053 lpOverlapped->OffsetHigh,
1054 nNumberOfBytesToLockLow,
1055 nNumberOfBytesToLockHigh,
1056 lpOverlapped));
1057}
1058
1059
1060/*****************************************************************************
1061 * Name : DWORD HMDeviceFileClass::FlushFileBuffers
1062 * Purpose : flush the buffers of a file
1063 * Parameters: PHMHANDLEDATA pHMHandleData
1064 * Variables :
1065 * Result : API returncode
1066 * Remark :
1067 * Status :
1068 *
1069 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1070 *****************************************************************************/
1071
1072BOOL HMDeviceFileClass::FlushFileBuffers(PHMHANDLEDATA pHMHandleData)
1073{
1074 dprintfl(("KERNEL32: HMDeviceFileClass:FlushFileBuffers(%08xh)\n",
1075 pHMHandleData->hHMHandle));
1076
1077 return(OSLibDosFlushFileBuffers(pHMHandleData->hHMHandle));
1078}
1079
1080
1081/*****************************************************************************
1082 * Name : DWORD HMDeviceFileClass::GetOverlappedResult
1083 * Purpose : asynchronus I/O
1084 * Parameters: PHMHANDLEDATA pHMHandleData
1085 * LPOVERLAPPED arg2
1086 * LPDWORD arg3
1087 * BOOL arg4
1088 * Variables :
1089 * Result : API returncode
1090 * Remark :
1091 * Status :
1092 *
1093 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1094 *****************************************************************************/
1095
1096BOOL HMDeviceFileClass::GetOverlappedResult(PHMHANDLEDATA pHMHandleData,
1097 LPOVERLAPPED arg2,
1098 LPDWORD arg3,
1099 BOOL arg4)
1100{
1101 dprintfl(("KERNEL32-WARNING: HMDeviceFileClass::GetOverlappedResult(%08xh,%08xh,%08xh,%08xh) STUB!!",
1102 pHMHandleData->hHMHandle,
1103 arg2,
1104 arg3,
1105 arg4));
1106
1107 return FALSE;
1108// return(O32_GetOverlappedResult(pHMHandleData->hHMHandle,
1109// arg2,
1110// arg3,
1111// arg4));
1112}
1113//******************************************************************************
1114//******************************************************************************
1115HMFileInfo::HMFileInfo(LPSTR lpszFileName, PVOID lpSecurityAttributes)
1116{
1117 this->lpszFileName = (LPSTR)malloc(strlen(lpszFileName)+1);
1118 if(!this->lpszFileName) {
1119 DebugInt3();
1120 }
1121 strcpy(this->lpszFileName, lpszFileName);
1122 this->lpSecurityAttributes = lpSecurityAttributes;
1123}
1124//******************************************************************************
1125//******************************************************************************
1126HMFileInfo::~HMFileInfo()
1127{
1128 if(lpszFileName) {
1129 free(lpszFileName);
1130 lpszFileName = NULL;
1131 }
1132}
1133//******************************************************************************
1134//******************************************************************************
Note: See TracBrowser for help on using the repository browser.