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

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

RegQueryValueW, OpenFile and LoadLibrary fixes

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