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

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

added dprintf to duplicatehandle

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