source: trunk/src/kernel32/hmnul.cpp@ 7476

Last change on this file since 7476 was 7476, checked in by phaller, 24 years ago

added NUL device

File size: 10.5 KB
Line 
1/* $Id: hmnul.cpp,v 1.1 2001-11-29 00:20:48 phaller Exp $ */
2
3/*
4 * Project Odin Software License can be found in LICENSE.TXT
5 *
6 * Win32 NUL device access class
7 *
8 * 2001 Patrick Haller <patrick.haller@innotek.de>
9 *
10 */
11
12
13
14#include <os2win.h>
15#include <string.h>
16#include <handlemanager.h>
17#include "handlenames.h"
18#include <heapstring.h>
19#include <winioctl.h>
20#include "hmdevice.h"
21#include "hmnul.h"
22#include "oslibdos.h"
23
24#define DBG_LOCALLOG DBG_hmnul
25#include "dbglocal.h"
26
27
28HMDeviceNulClass::HMDeviceNulClass(LPCSTR lpDeviceName) : HMDeviceHandler(lpDeviceName)
29{
30 dprintf(("HMDeviceNulClass::HMDevParPortClass(%s)\n",
31 lpDeviceName));
32
33 HMDeviceRegister("NUL", this);
34
35 // add symbolic links to the "real name" of the device
36 HandleNamesAddSymbolicLink("NUL:", "NUL");
37 HandleNamesAddSymbolicLink("\\\\.\\NUL", "NUL");
38}
39
40/*****************************************************************************
41 * Name : HMDeviceNulClass::FindDevice
42 * Purpose : Checks if lpDeviceName belongs to this device class
43 * Parameters: LPCSTR lpClassDevName
44 * LPCSTR lpDeviceName
45 * int namelength
46 * Variables :
47 * Result : checks if name is COMx or COMx: (x=1..8)
48 * Remark :
49 * Status :
50 *
51 * Author : SvL
52 *****************************************************************************/
53BOOL HMDeviceNulClass::FindDevice(LPCSTR lpClassDevName, LPCSTR lpDeviceName, int namelength)
54{
55 // == "NUL"
56 if(lstrcmpiA(lpDeviceName, lpClassDevName) != 0)
57 return FALSE;
58
59 return TRUE;
60}
61
62DWORD HMDeviceNulClass::CreateFile(HANDLE hHandle,
63 LPCSTR lpFileName,
64 PHMHANDLEDATA pHMHandleData,
65 PVOID lpSecurityAttributes,
66 PHMHANDLEDATA pHMHandleDataTemplate)
67{
68 dprintf(("HMDeviceNulClass::CreateFile(%s,%08xh,%08xh,%08xh)\n",
69 lpFileName,
70 pHMHandleData,
71 lpSecurityAttributes,
72 pHMHandleDataTemplate));
73
74 // we don't actually open a handle to OS/2's NUL device,
75 // we just swallow any I/O
76 pHMHandleData->hHMHandle = 0xdeadface;
77 SetLastError(ERROR_SUCCESS);
78 return NO_ERROR;
79}
80
81
82 /* this is a handler method for calls to CloseHandle() */
83BOOL HMDeviceNulClass::CloseHandle(PHMHANDLEDATA pHMHandleData)
84{
85 dprintf(("HMDeviceNulClass: close request(%08xh)\n",
86 pHMHandleData));
87
88 return TRUE;
89}
90
91
92/*****************************************************************************
93 * Name : BOOL HMDeviceNulClass::WriteFile
94 * Purpose : write data to handle / device
95 * Parameters: PHMHANDLEDATA pHMHandleData,
96 * LPCVOID lpBuffer,
97 * DWORD nNumberOfBytesToWrite,
98 * LPDWORD lpNumberOfBytesWritten,
99 * LPOVERLAPPED lpOverlapped
100 * Variables :
101 * Result : Boolean
102 * Remark :
103 * Status :
104 *
105 * Author : Patrick Haller [2001/11/29]
106 *****************************************************************************/
107
108BOOL HMDeviceNulClass::WriteFile(PHMHANDLEDATA pHMHandleData,
109 LPCVOID lpBuffer,
110 DWORD nNumberOfBytesToWrite,
111 LPDWORD lpNumberOfBytesWritten,
112 LPOVERLAPPED lpOverlapped)
113{
114 dprintf(("KERNEL32:HMDeviceNulClass::WriteFile %s(%08x,%08x,%08x,%08x,%08x)",
115 lpHMDeviceName,
116 pHMHandleData->hHMHandle,
117 lpBuffer,
118 nNumberOfBytesToWrite,
119 lpNumberOfBytesWritten,
120 lpOverlapped));
121
122 BOOL ret;
123 ULONG ulBytesWritten;
124
125 if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
126 dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
127 SetLastError(ERROR_INVALID_PARAMETER);
128 return FALSE;
129 }
130 if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
131 dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
132 }
133
134 // this is real NUL I/O
135 ret = NO_ERROR;
136 ulBytesWritten = nNumberOfBytesToWrite;
137
138 if(lpNumberOfBytesWritten) {
139 *lpNumberOfBytesWritten = (ret) ? ulBytesWritten : 0;
140 }
141 if(ret == FALSE) {
142 dprintf(("ERROR: WriteFile failed with rc %d", GetLastError()));
143 }
144
145 return ret;
146}
147
148/*****************************************************************************
149 * Name : BOOL WriteFileEx
150 * Purpose : The WriteFileEx function writes data to a file. It is designed
151 * solely for asynchronous operation, unlike WriteFile, which is
152 * designed for both synchronous and asynchronous operation.
153 * WriteFileEx reports its completion status asynchronously,
154 * calling a specified completion routine when writing is completed
155 * and the calling thread is in an alertable wait state.
156 * Parameters: HANDLE hFile handle of file to write
157 * LPVOID lpBuffer address of buffer
158 * DWORD nNumberOfBytesToRead number of bytes to write
159 * LPOVERLAPPED lpOverlapped address of offset
160 * LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine
161 * Variables :
162 * Result : TRUE / FALSE
163 * Remark :
164 * Status : UNTESTED STUB
165 *
166 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
167 *****************************************************************************/
168
169BOOL HMDeviceNulClass::WriteFileEx(PHMHANDLEDATA pHMHandleData,
170 LPVOID lpBuffer,
171 DWORD nNumberOfBytesToWrite,
172 LPOVERLAPPED lpOverlapped,
173 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
174{
175 dprintf(("ERROR: WriteFileEx %s (%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n",
176 lpHMDeviceName,
177 pHMHandleData->hHMHandle,
178 lpBuffer,
179 nNumberOfBytesToWrite,
180 lpOverlapped,
181 lpCompletionRoutine));
182
183 SetLastError(ERROR_INVALID_FUNCTION);
184 return FALSE;
185}
186
187/*****************************************************************************
188 * Name : BOOL HMDeviceNulClass::ReadFile
189 * Purpose : read data from handle / device
190 * Parameters: PHMHANDLEDATA pHMHandleData,
191 * LPCVOID lpBuffer,
192 * DWORD nNumberOfBytesToRead,
193 * LPDWORD lpNumberOfBytesRead,
194 * LPOVERLAPPED lpOverlapped
195 * Variables :
196 * Result : Boolean
197 * Remark :
198 * Status :
199 *
200 * Author : SvL
201 *****************************************************************************/
202
203BOOL HMDeviceNulClass::ReadFile(PHMHANDLEDATA pHMHandleData,
204 LPCVOID lpBuffer,
205 DWORD nNumberOfBytesToRead,
206 LPDWORD lpNumberOfBytesRead,
207 LPOVERLAPPED lpOverlapped)
208{
209 dprintf(("KERNEL32:HMDeviceNulClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x)",
210 lpHMDeviceName,
211 pHMHandleData->hHMHandle,
212 lpBuffer,
213 nNumberOfBytesToRead,
214 lpNumberOfBytesRead,
215 lpOverlapped));
216
217 BOOL ret;
218 ULONG ulBytesRead;
219
220 if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
221 dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
222 SetLastError(ERROR_INVALID_PARAMETER);
223 return FALSE;
224 }
225 if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
226 dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
227 }
228
229 // this is real NUL I/O
230 ret = NO_ERROR;
231 ulBytesRead = nNumberOfBytesToRead;
232
233 if(lpNumberOfBytesRead) {
234 *lpNumberOfBytesRead = (ret) ? ulBytesRead : 0;
235 }
236 if(ret == FALSE) {
237 dprintf(("ERROR: ReadFile failed with rc %d", GetLastError()));
238 }
239 return ret;
240}
241
242/*****************************************************************************
243 * Name : BOOL ReadFileEx
244 * Purpose : The ReadFileEx function reads data from a file asynchronously.
245 * It is designed solely for asynchronous operation, unlike the
246 * ReadFile function, which is designed for both synchronous and
247 * asynchronous operation. ReadFileEx lets an application perform
248 * other processing during a file read operation.
249 * The ReadFileEx function reports its completion status asynchronously,
250 * calling a specified completion routine when reading is completed
251 * and the calling thread is in an alertable wait state.
252 * Parameters: HANDLE hFile handle of file to read
253 * LPVOID lpBuffer address of buffer
254 * DWORD nNumberOfBytesToRead number of bytes to read
255 * LPOVERLAPPED lpOverlapped address of offset
256 * LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine
257 * Variables :
258 * Result : TRUE / FALSE
259 * Remark :
260 * Status : UNTESTED STUB
261 *
262 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
263 *****************************************************************************/
264BOOL HMDeviceNulClass::ReadFileEx(PHMHANDLEDATA pHMHandleData,
265 LPVOID lpBuffer,
266 DWORD nNumberOfBytesToRead,
267 LPOVERLAPPED lpOverlapped,
268 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
269{
270 dprintf(("ERROR: ReadFileEx %s (%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n",
271 lpHMDeviceName,
272 pHMHandleData->hHMHandle,
273 lpBuffer,
274 nNumberOfBytesToRead,
275 lpOverlapped,
276 lpCompletionRoutine));
277
278 SetLastError(ERROR_INVALID_FUNCTION);
279 return FALSE;
280}
281
282
283BOOL HMDeviceNulClass::DeviceIoControl(PHMHANDLEDATA pHMHandleData,
284 DWORD dwIoControlCode,
285 LPVOID lpInBuffer,
286 DWORD nInBufferSize,
287 LPVOID lpOutBuffer,
288 DWORD nOutBufferSize,
289 LPDWORD lpBytesReturned,
290 LPOVERLAPPED lpOverlapped)
291{
292 dprintf(("HMDeviceNulClass::DeviceIoControl: unimplemented dwIoControlCode=%08lx\n", dwIoControlCode));
293 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
294 return FALSE;
295}
Note: See TracBrowser for help on using the repository browser.