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

Last change on this file since 3714 was 3714, checked in by phaller, 25 years ago

some fixes

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