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

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

Rewrote file io apis

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