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

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

DuplicateHandle fix

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