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

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

memory map fixes

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