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

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

pe loader fixes, add system32\drivers dir during installation, add build date + time during kernel32 load

File size: 38.0 KB
Line 
1/* $Id: hmfile.cpp,v 1.22 2000-10-10 17:14:03 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 : TODO: \\.\PHYSICALDRIVEx opens physical drive x
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//testestest!!!!
600 dprintf(("%s", lpRealBuf));
601//testestest!!!!
602
603
604 dprintf(("KERNEL32: HMDeviceFileClass::WriteFile returned %08xh\n",
605 bRC));
606
607 return bRC;
608}
609
610/*****************************************************************************
611 * Name : BOOL WriteFileEx
612 * Purpose : The WriteFileEx function writes data to a file. It is designed
613 * solely for asynchronous operation, unlike WriteFile, which is
614 * designed for both synchronous and asynchronous operation.
615 * WriteFileEx reports its completion status asynchronously,
616 * calling a specified completion routine when writing is completed
617 * and the calling thread is in an alertable wait state.
618 * Parameters: HANDLE hFile handle of file to write
619 * LPVOID lpBuffer address of buffer
620 * DWORD nNumberOfBytesToRead number of bytes to write
621 * LPOVERLAPPED lpOverlapped address of offset
622 * LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine
623 * Variables :
624 * Result : TRUE / FALSE
625 * Remark :
626 * Status : UNTESTED STUB
627 *
628 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
629 *****************************************************************************/
630
631BOOL HMDeviceFileClass::WriteFileEx(PHMHANDLEDATA pHMHandleData,
632 LPVOID lpBuffer,
633 DWORD nNumberOfBytesToWrite,
634 LPOVERLAPPED lpOverlapped,
635 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
636{
637 dprintf(("ERROR: WriteFileEx(%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n",
638 pHMHandleData->hHMHandle,
639 lpBuffer,
640 nNumberOfBytesToWrite,
641 lpOverlapped,
642 lpCompletionRoutine));
643 return FALSE;
644}
645
646/*****************************************************************************
647 * Name : DWORD HMDeviceFileClass::GetFileType
648 * Purpose : determine the handle type
649 * Parameters: PHMHANDLEDATA pHMHandleData
650 * Variables :
651 * Result : API returncode
652 * Remark :
653 * Status :
654 *
655 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
656 *****************************************************************************/
657
658DWORD HMDeviceFileClass::GetFileType(PHMHANDLEDATA pHMHandleData)
659{
660 dprintfl(("KERNEL32: HMDeviceFileClass::GetFileType %s(%08x)\n",
661 lpHMDeviceName,
662 pHMHandleData));
663
664 return FILE_TYPE_DISK;
665}
666
667
668/*****************************************************************************
669 * Name : DWORD HMDeviceFileClass::GetFileInformationByHandle
670 * Purpose : determine the handle type
671 * Parameters: PHMHANDLEDATA pHMHandleData
672 * BY_HANDLE_FILE_INFORMATION* pHFI
673 * Variables :
674 * Result : API returncode
675 * Remark :
676 * Status :
677 *
678 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
679 *****************************************************************************/
680
681DWORD HMDeviceFileClass::GetFileInformationByHandle(PHMHANDLEDATA pHMHandleData,
682 BY_HANDLE_FILE_INFORMATION* pHFI)
683{
684 dprintfl(("KERNEL32: HMDeviceFileClass::GetFileInformationByHandle %s(%08xh,%08xh)\n",
685 lpHMDeviceName,
686 pHMHandleData,
687 pHFI));
688
689 if(OSLibDosGetFileInformationByHandle(pHMHandleData->hHMHandle,
690 pHFI))
691 {
692 return TRUE;
693 }
694 dprintf(("GetFileInformationByHandle failed with error %d", GetLastError()));
695 return FALSE;
696
697}
698
699
700/*****************************************************************************
701 * Name : BOOL HMDeviceFileClass::SetEndOfFile
702 * Purpose : set end of file marker
703 * Parameters: PHMHANDLEDATA pHMHandleData
704 * Variables :
705 * Result : API returncode
706 * Remark :
707 * Status :
708 *
709 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
710 *****************************************************************************/
711
712BOOL HMDeviceFileClass::SetEndOfFile(PHMHANDLEDATA pHMHandleData)
713{
714 dprintfl(("KERNEL32: HMDeviceFileClass::SetEndOfFile %s(%08xh)\n",
715 lpHMDeviceName,
716 pHMHandleData));
717
718 if(OSLibDosSetEndOfFile(pHMHandleData->hHMHandle)) {
719 return TRUE;
720 }
721 dprintf(("SetEndOfFile failed with error %d", GetLastError()));
722 return FALSE;
723}
724
725
726/*****************************************************************************
727 * Name : BOOL HMDeviceFileClass::SetFileTime
728 * Purpose : set file time
729 * Parameters: PHMHANDLEDATA pHMHandleData
730 * PFILETIME pFT1
731 * PFILETIME pFT2
732 * PFILETIME pFT3
733 * Variables :
734 * Result : API returncode
735 * Remark :
736 * Status :
737 *
738 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
739 *****************************************************************************/
740
741BOOL HMDeviceFileClass::SetFileTime(PHMHANDLEDATA pHMHandleData,
742 LPFILETIME pFT1,
743 LPFILETIME pFT2,
744 LPFILETIME pFT3)
745{
746 WORD creationdate = 0, creationtime = 0;
747 WORD lastaccessdate = 0, lastaccesstime = 0;
748 WORD lastwritedate = 0, lastwritetime = 0;
749
750 dprintfl(("KERNEL32: HMDeviceFileClass::SetFileTime %s(%08xh,%08xh,%08xh,%08xh)\n",
751 lpHMDeviceName,
752 pHMHandleData,
753 pFT1,
754 pFT2,
755 pFT3));
756
757 if(pFT1 && pFT1->dwLowDateTime && pFT1->dwHighDateTime) {
758 FileTimeToDosDateTime(pFT1, &creationdate, &creationtime);
759 }
760
761 if(pFT2 && pFT2->dwLowDateTime && pFT2->dwHighDateTime) {
762 FileTimeToDosDateTime(pFT2, &lastaccessdate, &lastaccesstime);
763 }
764
765 if(pFT3 && pFT3->dwLowDateTime && pFT3->dwHighDateTime) {
766 FileTimeToDosDateTime(pFT3, &lastwritedate, &lastwritetime);
767 }
768
769 if(OSLibDosSetFileTime(pHMHandleData->hHMHandle,
770 creationdate, creationtime,
771 lastaccessdate, lastaccesstime,
772 lastwritedate, lastwritetime))
773 {
774 return TRUE;
775 }
776 dprintf(("SetFileTime failed with error %d", GetLastError()));
777 return FALSE;
778}
779
780/*****************************************************************************
781 * Name : BOOL HMDeviceFileClass::GetFileTime
782 * Purpose : get file time
783 * Parameters: PHMHANDLEDATA pHMHandleData
784 * PFILETIME pFT1
785 * PFILETIME pFT2
786 * PFILETIME pFT3
787 * Variables :
788 * Result : API returncode
789 * Remark :
790 * Status :
791 *
792 * Author : SvL
793 *****************************************************************************/
794
795BOOL HMDeviceFileClass::GetFileTime(PHMHANDLEDATA pHMHandleData,
796 LPFILETIME pFT1,
797 LPFILETIME pFT2,
798 LPFILETIME pFT3)
799{
800 WORD creationdate, creationtime;
801 WORD lastaccessdate, lastaccesstime;
802 WORD lastwritedate, lastwritetime;
803 BOOL rc;
804
805 if(!pFT1 && !pFT2 && !pFT3) {//TODO: does NT do this?
806 dprintf(("ERROR: GetFileTime: invalid parameter!"));
807 SetLastError(ERROR_INVALID_PARAMETER);
808 return FALSE;
809 }
810
811 if(OSLibDosGetFileTime(pHMHandleData->hHMHandle,
812 &creationdate, &creationtime,
813 &lastaccessdate, &lastaccesstime,
814 &lastwritedate, &lastwritetime))
815 {
816 if(pFT1) {
817 DosDateTimeToFileTime(creationdate, creationtime, pFT1);
818 }
819 if(pFT2) {
820 DosDateTimeToFileTime(lastaccessdate, lastaccesstime, pFT2);
821 }
822 if(pFT3) {
823 DosDateTimeToFileTime(lastwritedate, lastwritetime, pFT3);
824 }
825 return TRUE;
826 }
827 dprintf(("GetFileTime failed with error %d", GetLastError()));
828 return FALSE;
829}
830
831/*****************************************************************************
832 * Name : DWORD HMDeviceFileClass::GetFileSize
833 * Purpose : set file time
834 * Parameters: PHMHANDLEDATA pHMHandleData
835 * PDWORD pSize
836 * Variables :
837 * Result : API returncode
838 * Remark :
839 * Status :
840 *
841 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
842 *****************************************************************************/
843
844DWORD HMDeviceFileClass::GetFileSize(PHMHANDLEDATA pHMHandleData,
845 PDWORD lpdwFileSizeHigh)
846{
847 dprintfl(("KERNEL32: HMDeviceFileClass::GetFileSize %s(%08xh,%08xh)\n",
848 lpHMDeviceName,
849 pHMHandleData,
850 lpdwFileSizeHigh));
851
852 if(lpdwFileSizeHigh)
853 *lpdwFileSizeHigh = 0;
854
855 return OSLibDosGetFileSize(pHMHandleData->hHMHandle, lpdwFileSizeHigh);
856}
857
858/*****************************************************************************
859 * Name : DWORD HMDeviceFileClass::SetFilePointer
860 * Purpose : set file pointer
861 * Parameters: PHMHANDLEDATA pHMHandleData
862 * LONG lDistanceToMove
863 * PLONG lpDistanceToMoveHigh
864 * DWORD dwMoveMethod
865 * Variables :
866 * Result : API returncode
867 * Remark :
868 * Status :
869 *
870 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
871 *****************************************************************************/
872
873DWORD HMDeviceFileClass::SetFilePointer(PHMHANDLEDATA pHMHandleData,
874 LONG lDistanceToMove,
875 PLONG lpDistanceToMoveHigh,
876 DWORD dwMoveMethod)
877{
878 DWORD ret;
879
880 dprintfl(("KERNEL32: HMDeviceFileClass::SetFilePointer %s(%08xh,%08xh,%08xh,%08xh)\n",
881 lpHMDeviceName,
882 pHMHandleData,
883 lDistanceToMove,
884 lpDistanceToMoveHigh,
885 dwMoveMethod));
886
887 ret = OSLibDosSetFilePointer(pHMHandleData->hHMHandle,
888 lDistanceToMove,
889 (DWORD *)lpDistanceToMoveHigh,
890 dwMoveMethod);
891
892 if(ret == -1) {
893 dprintf(("SetFilePointer failed (error = %d)", GetLastError()));
894 }
895 return ret;
896}
897
898
899/*****************************************************************************
900 * Name : DWORD HMDeviceFileClass::LockFile
901 * Purpose : file locking
902 * Parameters: PHMHANDLEDATA pHMHandleData
903 * DWORD arg2
904 * DWORD arg3
905 * DWORD arg4
906 * DWORD arg5
907 * Variables :
908 * Result : API returncode
909 * Remark :
910 * Status :
911 *
912 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
913 *****************************************************************************/
914
915BOOL HMDeviceFileClass::LockFile(PHMHANDLEDATA pHMHandleData,
916 DWORD dwFileOffsetLow,
917 DWORD dwFileOffsetHigh,
918 DWORD cbLockLow,
919 DWORD cbLockHigh)
920{
921 dprintfl(("KERNEL32: HMDeviceFileClass::LockFile %s(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
922 lpHMDeviceName,
923 pHMHandleData,
924 dwFileOffsetLow,
925 dwFileOffsetHigh,
926 cbLockLow,
927 cbLockHigh));
928
929 return OSLibDosLockFile(pHMHandleData->hHMHandle,
930 LOCKFILE_EXCLUSIVE_LOCK,
931 dwFileOffsetLow,
932 dwFileOffsetHigh,
933 cbLockLow,
934 cbLockHigh,
935 NULL);
936}
937
938/*****************************************************************************
939 * Name : DWORD HMDeviceFileClass::LockFileEx
940 * Purpose : file locking
941 * Parameters: PHMHANDLEDATA pHMHandleData
942 * DWORD dwFlags
943 * DWORD dwReserved
944 * DWORD nNumberOfBytesToLockLow
945 * DWORD nNumberOfBytesToLockHigh
946 * LPOVERLAPPED lpOverlapped
947 * Variables :
948 * Result : API returncode
949 * Remark :
950 * Status :
951 *
952 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
953 *****************************************************************************/
954
955BOOL HMDeviceFileClass::LockFileEx(PHMHANDLEDATA pHMHandleData,
956 DWORD dwFlags,
957 DWORD dwReserved,
958 DWORD nNumberOfBytesToLockLow,
959 DWORD nNumberOfBytesToLockHigh,
960 LPOVERLAPPED lpOverlapped)
961{
962
963 dprintfl(("KERNEL32: HMDeviceFileClass::LockFileEx %s(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh) not completely implemented!",
964 lpHMDeviceName,
965 pHMHandleData,
966 dwFlags,
967 dwReserved,
968 nNumberOfBytesToLockLow,
969 nNumberOfBytesToLockHigh,
970 lpOverlapped));
971
972
973 return(OSLibDosLockFile(pHMHandleData->hHMHandle,
974 dwFlags,
975 lpOverlapped->Offset,
976 lpOverlapped->OffsetHigh,
977 nNumberOfBytesToLockLow,
978 nNumberOfBytesToLockHigh,
979 lpOverlapped));
980}
981
982
983/*****************************************************************************
984 * Name : DWORD HMDeviceFileClass::UnlockFile
985 * Purpose : file locking
986 * Parameters: PHMHANDLEDATA pHMHandleData
987 * DWORD arg2
988 * DWORD arg3
989 * DWORD arg4
990 * DWORD arg5
991 * Variables :
992 * Result : API returncode
993 * Remark :
994 * Status :
995 *
996 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
997 *****************************************************************************/
998
999BOOL HMDeviceFileClass::UnlockFile(PHMHANDLEDATA pHMHandleData,
1000 DWORD dwFileOffsetLow,
1001 DWORD dwFileOffsetHigh,
1002 DWORD cbLockLow,
1003 DWORD cbLockHigh)
1004{
1005 dprintfl(("KERNEL32: HMDeviceFileClass::UnlockFile %s(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
1006 lpHMDeviceName,
1007 pHMHandleData,
1008 dwFileOffsetLow,
1009 dwFileOffsetHigh,
1010 cbLockLow,
1011 cbLockHigh));
1012
1013 return OSLibDosUnlockFile(pHMHandleData->hHMHandle,
1014 dwFileOffsetLow,
1015 dwFileOffsetHigh,
1016 cbLockLow,
1017 cbLockHigh,
1018 NULL);
1019}
1020
1021
1022
1023/*****************************************************************************
1024 * Name : DWORD HMDeviceFileClass::UnlockFileEx
1025 * Purpose : file locking
1026 * Parameters: PHMHANDLEDATA pHMHandleData
1027 * DWORD dwFlags
1028 * DWORD dwReserved
1029 * DWORD nNumberOfBytesToLockLow
1030 * DWORD nNumberOfBytesToLockHigh
1031 * LPOVERLAPPED lpOverlapped
1032 * Variables :
1033 * Result : API returncode
1034 * Remark :
1035 * Status :
1036 *
1037 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1038 *****************************************************************************/
1039
1040BOOL HMDeviceFileClass::UnlockFileEx(PHMHANDLEDATA pHMHandleData,
1041 DWORD dwReserved,
1042 DWORD nNumberOfBytesToLockLow,
1043 DWORD nNumberOfBytesToLockHigh,
1044 LPOVERLAPPED lpOverlapped)
1045{
1046
1047 dprintfl(("KERNEL32: HMDeviceFileClass::UnlockFileEx %s(%08xh,%08xh,%08xh,%08xh,%08xh) not completely implemented!",
1048 lpHMDeviceName,
1049 pHMHandleData,
1050 dwReserved,
1051 nNumberOfBytesToLockLow,
1052 nNumberOfBytesToLockHigh,
1053 lpOverlapped));
1054
1055
1056 return(OSLibDosUnlockFile(pHMHandleData->hHMHandle,
1057 lpOverlapped->Offset,
1058 lpOverlapped->OffsetHigh,
1059 nNumberOfBytesToLockLow,
1060 nNumberOfBytesToLockHigh,
1061 lpOverlapped));
1062}
1063
1064
1065/*****************************************************************************
1066 * Name : DWORD HMDeviceFileClass::FlushFileBuffers
1067 * Purpose : flush the buffers of a file
1068 * Parameters: PHMHANDLEDATA pHMHandleData
1069 * Variables :
1070 * Result : API returncode
1071 * Remark :
1072 * Status :
1073 *
1074 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1075 *****************************************************************************/
1076
1077BOOL HMDeviceFileClass::FlushFileBuffers(PHMHANDLEDATA pHMHandleData)
1078{
1079 dprintfl(("KERNEL32: HMDeviceFileClass:FlushFileBuffers(%08xh)\n",
1080 pHMHandleData->hHMHandle));
1081
1082 return(OSLibDosFlushFileBuffers(pHMHandleData->hHMHandle));
1083}
1084
1085
1086/*****************************************************************************
1087 * Name : DWORD HMDeviceFileClass::GetOverlappedResult
1088 * Purpose : asynchronus I/O
1089 * Parameters: PHMHANDLEDATA pHMHandleData
1090 * LPOVERLAPPED arg2
1091 * LPDWORD arg3
1092 * BOOL arg4
1093 * Variables :
1094 * Result : API returncode
1095 * Remark :
1096 * Status :
1097 *
1098 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1099 *****************************************************************************/
1100
1101BOOL HMDeviceFileClass::GetOverlappedResult(PHMHANDLEDATA pHMHandleData,
1102 LPOVERLAPPED arg2,
1103 LPDWORD arg3,
1104 BOOL arg4)
1105{
1106 dprintfl(("KERNEL32-WARNING: HMDeviceFileClass::GetOverlappedResult(%08xh,%08xh,%08xh,%08xh) STUB!!",
1107 pHMHandleData->hHMHandle,
1108 arg2,
1109 arg3,
1110 arg4));
1111
1112 return FALSE;
1113// return(O32_GetOverlappedResult(pHMHandleData->hHMHandle,
1114// arg2,
1115// arg3,
1116// arg4));
1117}
1118//******************************************************************************
1119//******************************************************************************
1120HMFileInfo::HMFileInfo(LPSTR lpszFileName, PVOID lpSecurityAttributes)
1121{
1122 this->lpszFileName = (LPSTR)malloc(strlen(lpszFileName)+1);
1123 if(!this->lpszFileName) {
1124 DebugInt3();
1125 }
1126 strcpy(this->lpszFileName, lpszFileName);
1127 this->lpSecurityAttributes = lpSecurityAttributes;
1128}
1129//******************************************************************************
1130//******************************************************************************
1131HMFileInfo::~HMFileInfo()
1132{
1133 if(lpszFileName) {
1134 free(lpszFileName);
1135 lpszFileName = NULL;
1136 }
1137}
1138//******************************************************************************
1139//******************************************************************************
Note: See TracBrowser for help on using the repository browser.