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

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

Fixed bug in OpenFile (don't set structure to 0 for OF_REOPEN mode)

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