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

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

PD: added handlemanager support for named & unnamed pipes

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