Convert most of the file APIs to Unicode.
[wine] / msdos / int13.c
1 /*
2  * BIOS interrupt 13h handler
3  *
4  * Copyright 1997 Andreas Mohr
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <stdlib.h>
24 #include <sys/types.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
28
29 #include "winbase.h"
30 #include "winioctl.h"
31 #include "miscemu.h"
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(int);
35
36 static void DIOCRegs_2_CONTEXT( DIOC_REGISTERS *pIn, CONTEXT86 *pCxt )
37 {
38     memset( pCxt, 0, sizeof(*pCxt) );
39     /* Note: segment registers == 0 means that CTX_SEG_OFF_TO_LIN
40              will interpret 32-bit register contents as linear pointers */
41
42     pCxt->ContextFlags=CONTEXT86_INTEGER|CONTEXT86_CONTROL;
43     pCxt->Eax = pIn->reg_EAX;
44     pCxt->Ebx = pIn->reg_EBX;
45     pCxt->Ecx = pIn->reg_ECX;
46     pCxt->Edx = pIn->reg_EDX;
47     pCxt->Esi = pIn->reg_ESI;
48     pCxt->Edi = pIn->reg_EDI;
49
50     /* FIXME: Only partial CONTEXT86_CONTROL */
51     pCxt->EFlags = pIn->reg_Flags;
52 }
53
54 static void CONTEXT_2_DIOCRegs( CONTEXT86 *pCxt, DIOC_REGISTERS *pOut )
55 {
56     memset( pOut, 0, sizeof(DIOC_REGISTERS) );
57
58     pOut->reg_EAX = pCxt->Eax;
59     pOut->reg_EBX = pCxt->Ebx;
60     pOut->reg_ECX = pCxt->Ecx;
61     pOut->reg_EDX = pCxt->Edx;
62     pOut->reg_ESI = pCxt->Esi;
63     pOut->reg_EDI = pCxt->Edi;
64
65     /* FIXME: Only partial CONTEXT86_CONTROL */
66     pOut->reg_Flags = pCxt->EFlags;
67 }
68
69 /**********************************************************************
70  *          INT_Int13Handler (WPROCS.119)
71  *
72  * Handler for int 13h (disk I/O).
73  */
74 void WINAPI INT_Int13Handler( CONTEXT86 *context )
75 {
76     HANDLE hVWin32;
77     DIOC_REGISTERS regs;
78     DWORD dwRet;
79
80     hVWin32 = CreateFileA("\\\\.\\VWIN32", GENERIC_READ|GENERIC_WRITE,
81                0, NULL, OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, 0);
82
83     if(hVWin32!=INVALID_HANDLE_VALUE)
84     {
85         CONTEXT_2_DIOCRegs( context, &regs);
86
87         if(!DeviceIoControl(hVWin32, VWIN32_DIOC_DOS_INT13,
88                 &regs, sizeof regs, &regs, sizeof regs, &dwRet, NULL))
89             DIOCRegs_2_CONTEXT(&regs, context);
90         else
91             SET_CFLAG(context);
92
93         CloseHandle(hVWin32);
94     }
95     else
96     {
97         ERR("Failed to open device VWIN32\n");
98         SET_CFLAG(context);
99     }
100 }