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

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

Fixed bugs in Read/WriteFile; nr of bytes written/read pointer can be NULL

File size: 37.2 KB
Line 
1/* $Id: hmfile.cpp,v 1.12 2000-07-15 17:12:48 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, bytesread;
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 //SvL: It's legal for this pointer to be NULL
424 if(lpNumberOfBytesRead) {
425 lpNumberOfBytesRead = 0;
426 }
427 else lpNumberOfBytesRead = &bytesread;
428
429 if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
430 dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
431 SetLastError(ERROR_INVALID_PARAMETER);
432 return FALSE;
433 }
434 if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
435 dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
436 }
437
438 //SvL: DosRead doesn't like writing to memory addresses returned by
439 // DosAliasMem -> search for original memory mapped pointer and use
440 // that one + commit pages if not already present
441 map = Win32MemMapView::findMapByView((ULONG)lpBuffer, &offset, MEMMAP_ACCESS_WRITE);
442 if(map) {
443 lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset);
444 DWORD nrpages = nNumberOfBytesToRead/4096;
445 if(offset & 0xfff)
446 nrpages++;
447 if(nNumberOfBytesToRead & 0xfff)
448 nrpages++;
449
450 map->commitPage(offset & ~0xfff, TRUE, nrpages);
451 }
452 else lpRealBuf = (LPVOID)lpBuffer;
453
454 if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) {
455 dprintf(("ERROR: Overlapped IO not yet implememented!!"));
456 }
457// else {
458 bRC = OSLibDosRead(pHMHandleData->hHMHandle,
459 (PVOID)lpRealBuf,
460 nNumberOfBytesToRead,
461 lpNumberOfBytesRead);
462// }
463
464 if(bRC == 0) {
465 dprintf(("KERNEL32: HMDeviceFileClass::ReadFile returned %08xh %x\n",
466 bRC, GetLastError()));
467 dprintf(("%x -> %d", lpBuffer, IsBadWritePtr((LPVOID)lpBuffer, nNumberOfBytesToRead)));
468 }
469
470 return bRC;
471}
472
473/*****************************************************************************
474 * Name : BOOL ReadFileEx
475 * Purpose : The ReadFileEx function reads data from a file asynchronously.
476 * It is designed solely for asynchronous operation, unlike the
477 * ReadFile function, which is designed for both synchronous and
478 * asynchronous operation. ReadFileEx lets an application perform
479 * other processing during a file read operation.
480 * The ReadFileEx function reports its completion status asynchronously,
481 * calling a specified completion routine when reading is completed
482 * and the calling thread is in an alertable wait state.
483 * Parameters: HANDLE hFile handle of file to read
484 * LPVOID lpBuffer address of buffer
485 * DWORD nNumberOfBytesToRead number of bytes to read
486 * LPOVERLAPPED lpOverlapped address of offset
487 * LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine
488 * Variables :
489 * Result : TRUE / FALSE
490 * Remark :
491 * Status : UNTESTED STUB
492 *
493 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
494 *****************************************************************************/
495BOOL HMDeviceFileClass::ReadFileEx(PHMHANDLEDATA pHMHandleData,
496 LPVOID lpBuffer,
497 DWORD nNumberOfBytesToRead,
498 LPOVERLAPPED lpOverlapped,
499 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
500{
501 dprintf(("ERROR: ReadFileEx(%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n",
502 pHMHandleData->hHMHandle,
503 lpBuffer,
504 nNumberOfBytesToRead,
505 lpOverlapped,
506 lpCompletionRoutine));
507 return FALSE;
508}
509
510
511/*****************************************************************************
512 * Name : BOOL HMDeviceFileClass::WriteFile
513 * Purpose : write data to handle / device
514 * Parameters: PHMHANDLEDATA pHMHandleData,
515 * LPCVOID lpBuffer,
516 * DWORD nNumberOfBytesToWrite,
517 * LPDWORD lpNumberOfBytesWritten,
518 * LPOVERLAPPED lpOverlapped
519 * Variables :
520 * Result : Boolean
521 * Remark :
522 * Status :
523 *
524 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
525 *****************************************************************************/
526
527BOOL HMDeviceFileClass::WriteFile(PHMHANDLEDATA pHMHandleData,
528 LPCVOID lpBuffer,
529 DWORD nNumberOfBytesToWrite,
530 LPDWORD lpNumberOfBytesWritten,
531 LPOVERLAPPED lpOverlapped)
532{
533 LPVOID lpRealBuf;
534 Win32MemMap *map;
535 DWORD offset, byteswritten;
536 BOOL bRC;
537
538 dprintfl(("KERNEL32: HMDeviceFileClass::WriteFile %s(%08x,%08x,%08x,%08x,%08x) - stub?\n",
539 lpHMDeviceName,
540 pHMHandleData,
541 lpBuffer,
542 nNumberOfBytesToWrite,
543 lpNumberOfBytesWritten,
544 lpOverlapped));
545
546 //SvL: It's legal for this pointer to be NULL
547 if(lpNumberOfBytesWritten) {
548 lpNumberOfBytesWritten = 0;
549 }
550 else lpNumberOfBytesWritten = &byteswritten;
551
552 if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
553 dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
554 SetLastError(ERROR_INVALID_PARAMETER);
555 return FALSE;
556 }
557 if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
558 dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
559 }
560
561 //SvL: DosWrite doesn't like reading from memory addresses returned by
562 // DosAliasMem -> search for original memory mapped pointer and use
563 // that one + commit pages if not already present
564 map = Win32MemMapView::findMapByView((ULONG)lpBuffer, &offset, MEMMAP_ACCESS_READ);
565 if(map) {
566 lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset);
567 DWORD nrpages = nNumberOfBytesToWrite/4096;
568 if(offset & 0xfff)
569 nrpages++;
570 if(nNumberOfBytesToWrite & 0xfff)
571 nrpages++;
572
573 map->commitPage(offset & ~0xfff, TRUE, nrpages);
574 }
575 else lpRealBuf = (LPVOID)lpBuffer;
576
577 if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) {
578 dprintf(("ERROR: Overlapped IO not yet implememented!!"));
579 }
580// else {
581 bRC = OSLibDosWrite(pHMHandleData->hHMHandle,
582 (PVOID)lpRealBuf,
583 nNumberOfBytesToWrite,
584 lpNumberOfBytesWritten);
585// }
586
587 dprintf(("KERNEL32: HMDeviceFileClass::WriteFile returned %08xh\n",
588 bRC));
589
590 return bRC;
591}
592
593/*****************************************************************************
594 * Name : BOOL WriteFileEx
595 * Purpose : The WriteFileEx function writes data to a file. It is designed
596 * solely for asynchronous operation, unlike WriteFile, which is
597 * designed for both synchronous and asynchronous operation.
598 * WriteFileEx reports its completion status asynchronously,
599 * calling a specified completion routine when writing is completed
600 * and the calling thread is in an alertable wait state.
601 * Parameters: HANDLE hFile handle of file to write
602 * LPVOID lpBuffer address of buffer
603 * DWORD nNumberOfBytesToRead number of bytes to write
604 * LPOVERLAPPED lpOverlapped address of offset
605 * LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine
606 * Variables :
607 * Result : TRUE / FALSE
608 * Remark :
609 * Status : UNTESTED STUB
610 *
611 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
612 *****************************************************************************/
613
614BOOL HMDeviceFileClass::WriteFileEx(PHMHANDLEDATA pHMHandleData,
615 LPVOID lpBuffer,
616 DWORD nNumberOfBytesToWrite,
617 LPOVERLAPPED lpOverlapped,
618 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
619{
620 dprintf(("ERROR: WriteFileEx(%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n",
621 pHMHandleData->hHMHandle,
622 lpBuffer,
623 nNumberOfBytesToWrite,
624 lpOverlapped,
625 lpCompletionRoutine));
626 return FALSE;
627}
628
629/*****************************************************************************
630 * Name : DWORD HMDeviceFileClass::GetFileType
631 * Purpose : determine the handle type
632 * Parameters: PHMHANDLEDATA pHMHandleData
633 * Variables :
634 * Result : API returncode
635 * Remark :
636 * Status :
637 *
638 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
639 *****************************************************************************/
640
641DWORD HMDeviceFileClass::GetFileType(PHMHANDLEDATA pHMHandleData)
642{
643 dprintfl(("KERNEL32: HMDeviceFileClass::GetFileType %s(%08x)\n",
644 lpHMDeviceName,
645 pHMHandleData));
646
647 return FILE_TYPE_DISK;
648}
649
650
651/*****************************************************************************
652 * Name : DWORD HMDeviceFileClass::GetFileInformationByHandle
653 * Purpose : determine the handle type
654 * Parameters: PHMHANDLEDATA pHMHandleData
655 * BY_HANDLE_FILE_INFORMATION* pHFI
656 * Variables :
657 * Result : API returncode
658 * Remark :
659 * Status :
660 *
661 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
662 *****************************************************************************/
663
664DWORD HMDeviceFileClass::GetFileInformationByHandle(PHMHANDLEDATA pHMHandleData,
665 BY_HANDLE_FILE_INFORMATION* pHFI)
666{
667 dprintfl(("KERNEL32: HMDeviceFileClass::GetFileInformationByHandle %s(%08xh,%08xh)\n",
668 lpHMDeviceName,
669 pHMHandleData,
670 pHFI));
671
672 if(OSLibDosGetFileInformationByHandle(pHMHandleData->hHMHandle,
673 pHFI))
674 {
675 return TRUE;
676 }
677 dprintf(("GetFileInformationByHandle failed with error %d", GetLastError()));
678 return FALSE;
679
680}
681
682
683/*****************************************************************************
684 * Name : BOOL HMDeviceFileClass::SetEndOfFile
685 * Purpose : set end of file marker
686 * Parameters: PHMHANDLEDATA pHMHandleData
687 * Variables :
688 * Result : API returncode
689 * Remark :
690 * Status :
691 *
692 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
693 *****************************************************************************/
694
695BOOL HMDeviceFileClass::SetEndOfFile(PHMHANDLEDATA pHMHandleData)
696{
697 dprintfl(("KERNEL32: HMDeviceFileClass::SetEndOfFile %s(%08xh)\n",
698 lpHMDeviceName,
699 pHMHandleData));
700
701 if(OSLibDosSetEndOfFile(pHMHandleData->hHMHandle)) {
702 return TRUE;
703 }
704 dprintf(("SetEndOfFile failed with error %d", GetLastError()));
705 return FALSE;
706}
707
708
709/*****************************************************************************
710 * Name : BOOL HMDeviceFileClass::SetFileTime
711 * Purpose : set file time
712 * Parameters: PHMHANDLEDATA pHMHandleData
713 * PFILETIME pFT1
714 * PFILETIME pFT2
715 * PFILETIME pFT3
716 * Variables :
717 * Result : API returncode
718 * Remark :
719 * Status :
720 *
721 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
722 *****************************************************************************/
723
724BOOL HMDeviceFileClass::SetFileTime(PHMHANDLEDATA pHMHandleData,
725 LPFILETIME pFT1,
726 LPFILETIME pFT2,
727 LPFILETIME pFT3)
728{
729 WORD creationdate = 0, creationtime = 0;
730 WORD lastaccessdate = 0, lastaccesstime = 0;
731 WORD lastwritedate = 0, lastwritetime = 0;
732
733 dprintfl(("KERNEL32: HMDeviceFileClass::SetFileTime %s(%08xh,%08xh,%08xh,%08xh)\n",
734 lpHMDeviceName,
735 pHMHandleData,
736 pFT1,
737 pFT2,
738 pFT3));
739
740 if(pFT1 && pFT1->dwLowDateTime && pFT1->dwHighDateTime) {
741 FileTimeToDosDateTime(pFT1, &creationdate, &creationtime);
742 }
743
744 if(pFT2 && pFT2->dwLowDateTime && pFT2->dwHighDateTime) {
745 FileTimeToDosDateTime(pFT2, &lastaccessdate, &lastaccesstime);
746 }
747
748 if(pFT3 && pFT3->dwLowDateTime && pFT3->dwHighDateTime) {
749 FileTimeToDosDateTime(pFT3, &lastwritedate, &lastwritetime);
750 }
751
752 if(OSLibDosSetFileTime(pHMHandleData->hHMHandle,
753 creationdate, creationtime,
754 lastaccessdate, lastaccesstime,
755 lastwritedate, lastwritetime))
756 {
757 return TRUE;
758 }
759 dprintf(("SetFileTime failed with error %d", GetLastError()));
760 return FALSE;
761}
762
763/*****************************************************************************
764 * Name : BOOL HMDeviceFileClass::GetFileTime
765 * Purpose : get file time
766 * Parameters: PHMHANDLEDATA pHMHandleData
767 * PFILETIME pFT1
768 * PFILETIME pFT2
769 * PFILETIME pFT3
770 * Variables :
771 * Result : API returncode
772 * Remark :
773 * Status :
774 *
775 * Author : SvL
776 *****************************************************************************/
777
778BOOL HMDeviceFileClass::GetFileTime(PHMHANDLEDATA pHMHandleData,
779 LPFILETIME pFT1,
780 LPFILETIME pFT2,
781 LPFILETIME pFT3)
782{
783 WORD creationdate, creationtime;
784 WORD lastaccessdate, lastaccesstime;
785 WORD lastwritedate, lastwritetime;
786 BOOL rc;
787
788 if(!pFT1 && !pFT2 && !pFT3) {//TODO: does NT do this?
789 SetLastError(ERROR_INVALID_PARAMETER);
790 return FALSE;
791 }
792
793 if(OSLibDosGetFileTime(pHMHandleData->hHMHandle,
794 &creationdate, &creationtime,
795 &lastaccessdate, &lastaccesstime,
796 &lastwritedate, &lastwritetime))
797 {
798 if(pFT1) {
799 DosDateTimeToFileTime(creationdate, creationtime, pFT1);
800 }
801 if(pFT2) {
802 DosDateTimeToFileTime(lastaccessdate, lastaccesstime, pFT2);
803 }
804 if(pFT3) {
805 DosDateTimeToFileTime(lastwritedate, lastwritetime, pFT3);
806 }
807 return TRUE;
808 }
809 dprintf(("GetFileTime failed with error %d", GetLastError()));
810 return FALSE;
811}
812
813/*****************************************************************************
814 * Name : DWORD HMDeviceFileClass::GetFileSize
815 * Purpose : set file time
816 * Parameters: PHMHANDLEDATA pHMHandleData
817 * PDWORD pSize
818 * Variables :
819 * Result : API returncode
820 * Remark :
821 * Status :
822 *
823 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
824 *****************************************************************************/
825
826DWORD HMDeviceFileClass::GetFileSize(PHMHANDLEDATA pHMHandleData,
827 PDWORD lpdwFileSizeHigh)
828{
829 dprintfl(("KERNEL32: HMDeviceFileClass::GetFileSize %s(%08xh,%08xh)\n",
830 lpHMDeviceName,
831 pHMHandleData,
832 lpdwFileSizeHigh));
833
834 if(lpdwFileSizeHigh)
835 *lpdwFileSizeHigh = 0;
836
837 return OSLibDosGetFileSize(pHMHandleData->hHMHandle, lpdwFileSizeHigh);
838}
839
840/*****************************************************************************
841 * Name : DWORD HMDeviceFileClass::SetFilePointer
842 * Purpose : set file pointer
843 * Parameters: PHMHANDLEDATA pHMHandleData
844 * LONG lDistanceToMove
845 * PLONG lpDistanceToMoveHigh
846 * DWORD dwMoveMethod
847 * Variables :
848 * Result : API returncode
849 * Remark :
850 * Status :
851 *
852 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
853 *****************************************************************************/
854
855DWORD HMDeviceFileClass::SetFilePointer(PHMHANDLEDATA pHMHandleData,
856 LONG lDistanceToMove,
857 PLONG lpDistanceToMoveHigh,
858 DWORD dwMoveMethod)
859{
860 DWORD ret;
861
862 dprintfl(("KERNEL32: HMDeviceFileClass::SetFilePointer %s(%08xh,%08xh,%08xh,%08xh)\n",
863 lpHMDeviceName,
864 pHMHandleData,
865 lDistanceToMove,
866 lpDistanceToMoveHigh,
867 dwMoveMethod));
868
869 ret = OSLibDosSetFilePointer(pHMHandleData->hHMHandle,
870 lDistanceToMove,
871 (DWORD *)lpDistanceToMoveHigh,
872 dwMoveMethod);
873
874 if(ret == -1) {
875 dprintf(("SetFilePointer failed (error = %d)", GetLastError()));
876 }
877 return ret;
878}
879
880
881/*****************************************************************************
882 * Name : DWORD HMDeviceFileClass::LockFile
883 * Purpose : file locking
884 * Parameters: PHMHANDLEDATA pHMHandleData
885 * DWORD arg2
886 * DWORD arg3
887 * DWORD arg4
888 * DWORD arg5
889 * Variables :
890 * Result : API returncode
891 * Remark :
892 * Status :
893 *
894 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
895 *****************************************************************************/
896
897BOOL HMDeviceFileClass::LockFile(PHMHANDLEDATA pHMHandleData,
898 DWORD dwFileOffsetLow,
899 DWORD dwFileOffsetHigh,
900 DWORD cbLockLow,
901 DWORD cbLockHigh)
902{
903 dprintfl(("KERNEL32: HMDeviceFileClass::LockFile %s(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
904 lpHMDeviceName,
905 pHMHandleData,
906 dwFileOffsetLow,
907 dwFileOffsetHigh,
908 cbLockLow,
909 cbLockHigh));
910
911 return OSLibDosLockFile(pHMHandleData->hHMHandle,
912 LOCKFILE_EXCLUSIVE_LOCK,
913 dwFileOffsetLow,
914 dwFileOffsetHigh,
915 cbLockLow,
916 cbLockHigh,
917 NULL);
918}
919
920/*****************************************************************************
921 * Name : DWORD HMDeviceFileClass::LockFileEx
922 * Purpose : file locking
923 * Parameters: PHMHANDLEDATA pHMHandleData
924 * DWORD dwFlags
925 * DWORD dwReserved
926 * DWORD nNumberOfBytesToLockLow
927 * DWORD nNumberOfBytesToLockHigh
928 * LPOVERLAPPED lpOverlapped
929 * Variables :
930 * Result : API returncode
931 * Remark :
932 * Status :
933 *
934 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
935 *****************************************************************************/
936
937BOOL HMDeviceFileClass::LockFileEx(PHMHANDLEDATA pHMHandleData,
938 DWORD dwFlags,
939 DWORD dwReserved,
940 DWORD nNumberOfBytesToLockLow,
941 DWORD nNumberOfBytesToLockHigh,
942 LPOVERLAPPED lpOverlapped)
943{
944
945 dprintfl(("KERNEL32: HMDeviceFileClass::LockFileEx %s(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh) not completely implemented!",
946 lpHMDeviceName,
947 pHMHandleData,
948 dwFlags,
949 dwReserved,
950 nNumberOfBytesToLockLow,
951 nNumberOfBytesToLockHigh,
952 lpOverlapped));
953
954
955 return(OSLibDosLockFile(pHMHandleData->hHMHandle,
956 dwFlags,
957 lpOverlapped->Offset,
958 lpOverlapped->OffsetHigh,
959 nNumberOfBytesToLockLow,
960 nNumberOfBytesToLockHigh,
961 lpOverlapped));
962}
963
964
965/*****************************************************************************
966 * Name : DWORD HMDeviceFileClass::UnlockFile
967 * Purpose : file locking
968 * Parameters: PHMHANDLEDATA pHMHandleData
969 * DWORD arg2
970 * DWORD arg3
971 * DWORD arg4
972 * DWORD arg5
973 * Variables :
974 * Result : API returncode
975 * Remark :
976 * Status :
977 *
978 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
979 *****************************************************************************/
980
981BOOL HMDeviceFileClass::UnlockFile(PHMHANDLEDATA pHMHandleData,
982 DWORD dwFileOffsetLow,
983 DWORD dwFileOffsetHigh,
984 DWORD cbLockLow,
985 DWORD cbLockHigh)
986{
987 dprintfl(("KERNEL32: HMDeviceFileClass::UnlockFile %s(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
988 lpHMDeviceName,
989 pHMHandleData,
990 dwFileOffsetLow,
991 dwFileOffsetHigh,
992 cbLockLow,
993 cbLockHigh));
994
995 return OSLibDosUnlockFile(pHMHandleData->hHMHandle,
996 dwFileOffsetLow,
997 dwFileOffsetHigh,
998 cbLockLow,
999 cbLockHigh,
1000 NULL);
1001}
1002
1003
1004
1005/*****************************************************************************
1006 * Name : DWORD HMDeviceFileClass::UnlockFileEx
1007 * Purpose : file locking
1008 * Parameters: PHMHANDLEDATA pHMHandleData
1009 * DWORD dwFlags
1010 * DWORD dwReserved
1011 * DWORD nNumberOfBytesToLockLow
1012 * DWORD nNumberOfBytesToLockHigh
1013 * LPOVERLAPPED lpOverlapped
1014 * Variables :
1015 * Result : API returncode
1016 * Remark :
1017 * Status :
1018 *
1019 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1020 *****************************************************************************/
1021
1022BOOL HMDeviceFileClass::UnlockFileEx(PHMHANDLEDATA pHMHandleData,
1023 DWORD dwReserved,
1024 DWORD nNumberOfBytesToLockLow,
1025 DWORD nNumberOfBytesToLockHigh,
1026 LPOVERLAPPED lpOverlapped)
1027{
1028
1029 dprintfl(("KERNEL32: HMDeviceFileClass::UnlockFileEx %s(%08xh,%08xh,%08xh,%08xh,%08xh) not completely implemented!",
1030 lpHMDeviceName,
1031 pHMHandleData,
1032 dwReserved,
1033 nNumberOfBytesToLockLow,
1034 nNumberOfBytesToLockHigh,
1035 lpOverlapped));
1036
1037
1038 return(OSLibDosUnlockFile(pHMHandleData->hHMHandle,
1039 lpOverlapped->Offset,
1040 lpOverlapped->OffsetHigh,
1041 nNumberOfBytesToLockLow,
1042 nNumberOfBytesToLockHigh,
1043 lpOverlapped));
1044}
1045
1046
1047/*****************************************************************************
1048 * Name : DWORD HMDeviceFileClass::FlushFileBuffers
1049 * Purpose : flush the buffers of a file
1050 * Parameters: PHMHANDLEDATA pHMHandleData
1051 * Variables :
1052 * Result : API returncode
1053 * Remark :
1054 * Status :
1055 *
1056 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1057 *****************************************************************************/
1058
1059BOOL HMDeviceFileClass::FlushFileBuffers(PHMHANDLEDATA pHMHandleData)
1060{
1061 dprintfl(("KERNEL32: HMDeviceFileClass:FlushFileBuffers(%08xh)\n",
1062 pHMHandleData->hHMHandle));
1063
1064 return(OSLibDosFlushFileBuffers(pHMHandleData->hHMHandle));
1065}
1066
1067
1068/*****************************************************************************
1069 * Name : DWORD HMDeviceFileClass::GetOverlappedResult
1070 * Purpose : asynchronus I/O
1071 * Parameters: PHMHANDLEDATA pHMHandleData
1072 * LPOVERLAPPED arg2
1073 * LPDWORD arg3
1074 * BOOL arg4
1075 * Variables :
1076 * Result : API returncode
1077 * Remark :
1078 * Status :
1079 *
1080 * Author : Patrick Haller [Wed, 1999/06/17 20:44]
1081 *****************************************************************************/
1082
1083BOOL HMDeviceFileClass::GetOverlappedResult(PHMHANDLEDATA pHMHandleData,
1084 LPOVERLAPPED arg2,
1085 LPDWORD arg3,
1086 BOOL arg4)
1087{
1088 dprintfl(("KERNEL32-WARNING: HMDeviceFileClass::GetOverlappedResult(%08xh,%08xh,%08xh,%08xh) STUB!!",
1089 pHMHandleData->hHMHandle,
1090 arg2,
1091 arg3,
1092 arg4));
1093
1094 return FALSE;
1095// return(O32_GetOverlappedResult(pHMHandleData->hHMHandle,
1096// arg2,
1097// arg3,
1098// arg4));
1099}
1100//******************************************************************************
1101//******************************************************************************
1102HMFileInfo::HMFileInfo(LPSTR lpszFileName, PVOID lpSecurityAttributes)
1103{
1104 this->lpszFileName = (LPSTR)malloc(strlen(lpszFileName)+1);
1105 if(!this->lpszFileName) {
1106 DebugInt3();
1107 }
1108 strcpy(this->lpszFileName, lpszFileName);
1109 this->lpSecurityAttributes = lpSecurityAttributes;
1110}
1111//******************************************************************************
1112//******************************************************************************
1113HMFileInfo::~HMFileInfo()
1114{
1115 if(lpszFileName) {
1116 free(lpszFileName);
1117 lpszFileName = NULL;
1118 }
1119}
1120//******************************************************************************
1121//******************************************************************************
Note: See TracBrowser for help on using the repository browser.