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

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

strncpy call changes + language api updates/fixes

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