1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/client/file/tape.c
5 * PURPOSE: Tape functions
6 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
7 * UPDATE HISTORY:
8 * Created 01/11/98
9 */
10
11 /* INCLUDES *******************************************************************/
12
13 #include <k32.h>
14 #define NDEBUG
15 #include <debug.h>
16
17 /* PRIVATE FUNCTIONS **********************************************************/
18
19 DWORD
20 WINAPI
BasepDoTapeOperation(IN HANDLE DeviceHandle,IN ULONG Ioctl,IN PVOID Input,IN ULONG InputLength,IN PVOID Output,IN ULONG OutputLength)21 BasepDoTapeOperation(IN HANDLE DeviceHandle,
22 IN ULONG Ioctl,
23 IN PVOID Input,
24 IN ULONG InputLength,
25 IN PVOID Output,
26 IN ULONG OutputLength)
27 {
28 HANDLE TapeEvent;
29 DWORD ErrorCode;
30 NTSTATUS Status;
31 IO_STATUS_BLOCK IoStatusBlock;
32
33 /* Create the wait event */
34 TapeEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
35 if (!TapeEvent) return GetLastError();
36
37 /* Send the IOCTL */
38 Status = NtDeviceIoControlFile(DeviceHandle,
39 TapeEvent,
40 0,
41 0,
42 &IoStatusBlock,
43 Ioctl,
44 Input,
45 InputLength,
46 Output,
47 OutputLength);
48 if (Status == STATUS_PENDING)
49 {
50 /* Wait for its completion */
51 WaitForSingleObject(TapeEvent, INFINITE);
52 Status = IoStatusBlock.Status;
53 }
54
55 /* Get rid of the wait event and check status */
56 CloseHandle(TapeEvent);
57 if (!NT_SUCCESS(Status))
58 {
59 /* Convert to Win32 */
60 BaseSetLastNTError(Status);
61 ErrorCode = GetLastError();
62 }
63 else
64 {
65 /* Set success */
66 ErrorCode = ERROR_SUCCESS;
67 }
68
69 /* Return the Win32 error code */
70 return ErrorCode;
71 }
72
73 /* PUBLIC FUNCTIONS ***********************************************************/
74
75 /*
76 * @implemented
77 */
78 DWORD
79 WINAPI
CreateTapePartition(IN HANDLE hDevice,IN DWORD dwPartitionMethod,IN DWORD dwCount,IN DWORD dwSize)80 CreateTapePartition(IN HANDLE hDevice,
81 IN DWORD dwPartitionMethod,
82 IN DWORD dwCount,
83 IN DWORD dwSize)
84 {
85 TAPE_CREATE_PARTITION TapeCreatePartition;
86
87 TapeCreatePartition.Method = dwPartitionMethod;
88 TapeCreatePartition.Count = dwCount;
89 TapeCreatePartition.Size = dwSize;
90 return BasepDoTapeOperation(hDevice,
91 IOCTL_TAPE_CREATE_PARTITION,
92 &TapeCreatePartition,
93 sizeof(TapeCreatePartition),
94 NULL,
95 0);
96 }
97
98 /*
99 * @implemented
100 */
101 DWORD
102 WINAPI
EraseTape(IN HANDLE hDevice,IN DWORD dwEraseType,IN BOOL bImmediate)103 EraseTape(IN HANDLE hDevice,
104 IN DWORD dwEraseType,
105 IN BOOL bImmediate)
106 {
107 TAPE_ERASE TapeErase;
108
109 TapeErase.Type = dwEraseType;
110 TapeErase.Immediate = (BOOLEAN)bImmediate;
111 return BasepDoTapeOperation(hDevice,
112 IOCTL_TAPE_ERASE,
113 &TapeErase,
114 sizeof(TapeErase),
115 NULL,
116 0);
117 }
118
119 /*
120 * @implemented
121 */
122 DWORD
123 WINAPI
GetTapeParameters(IN HANDLE hDevice,IN DWORD dwOperation,IN LPDWORD lpdwSize,IN LPVOID lpTapeInformation)124 GetTapeParameters(IN HANDLE hDevice,
125 IN DWORD dwOperation,
126 IN LPDWORD lpdwSize,
127 IN LPVOID lpTapeInformation)
128 {
129 if (dwOperation == GET_TAPE_MEDIA_INFORMATION)
130 {
131 if (*lpdwSize < sizeof(TAPE_GET_MEDIA_PARAMETERS))
132 {
133 *lpdwSize = sizeof(TAPE_GET_MEDIA_PARAMETERS);
134 return ERROR_MORE_DATA;
135 }
136
137 return BasepDoTapeOperation(hDevice,
138 IOCTL_TAPE_GET_MEDIA_PARAMS,
139 NULL,
140 0,
141 lpTapeInformation,
142 sizeof(TAPE_GET_MEDIA_PARAMETERS));
143 }
144 else if (dwOperation == GET_TAPE_DRIVE_INFORMATION)
145 {
146 if (*lpdwSize < sizeof(TAPE_GET_DRIVE_PARAMETERS))
147 {
148 *lpdwSize = sizeof(TAPE_GET_DRIVE_PARAMETERS);
149 return ERROR_MORE_DATA;
150 }
151
152 return BasepDoTapeOperation(hDevice,
153 IOCTL_TAPE_GET_DRIVE_PARAMS,
154 NULL,
155 0,
156 lpTapeInformation,
157 sizeof(TAPE_GET_DRIVE_PARAMETERS));
158 }
159
160 return ERROR_INVALID_FUNCTION;
161 }
162
163 /*
164 * @implemented
165 */
166 DWORD
167 WINAPI
GetTapePosition(IN HANDLE hDevice,IN DWORD dwPositionType,IN LPDWORD lpdwPartition,IN LPDWORD lpdwOffsetLow,IN LPDWORD lpdwOffsetHigh)168 GetTapePosition(IN HANDLE hDevice,
169 IN DWORD dwPositionType,
170 IN LPDWORD lpdwPartition,
171 IN LPDWORD lpdwOffsetLow,
172 IN LPDWORD lpdwOffsetHigh)
173 {
174 TAPE_GET_POSITION TapeGetPosition;
175 DWORD Result;
176
177 TapeGetPosition.Type = dwPositionType;
178 Result = BasepDoTapeOperation(hDevice,
179 IOCTL_TAPE_GET_POSITION,
180 &TapeGetPosition,
181 sizeof(TapeGetPosition),
182 &TapeGetPosition,
183 sizeof(TapeGetPosition));
184
185 if (Result)
186 {
187 *lpdwPartition = 0;
188 *lpdwOffsetLow = 0;
189 *lpdwOffsetHigh = 0;
190 }
191 else
192 {
193 *lpdwPartition = TapeGetPosition.Partition;
194 *lpdwOffsetLow = TapeGetPosition.Offset.u.LowPart;
195 *lpdwOffsetHigh = TapeGetPosition.Offset.u.HighPart;
196 }
197
198 return Result;
199 }
200
201 /*
202 * @implemented
203 */
204 DWORD
205 WINAPI
GetTapeStatus(IN HANDLE hDevice)206 GetTapeStatus(IN HANDLE hDevice)
207 {
208 return BasepDoTapeOperation(hDevice,
209 IOCTL_TAPE_GET_STATUS,
210 NULL,
211 0,
212 NULL,
213 0);
214 }
215
216 /*
217 * @implemented
218 */
219 DWORD
220 WINAPI
PrepareTape(IN HANDLE hDevice,IN DWORD dwOperation,IN BOOL bImmediate)221 PrepareTape(IN HANDLE hDevice,
222 IN DWORD dwOperation,
223 IN BOOL bImmediate)
224 {
225 TAPE_PREPARE TapePrepare;
226
227 TapePrepare.Operation = dwOperation;
228 TapePrepare.Immediate = (BOOLEAN)bImmediate;
229 return BasepDoTapeOperation(hDevice,
230 IOCTL_TAPE_PREPARE,
231 &TapePrepare,
232 sizeof(TapePrepare),
233 NULL,
234 0);
235 }
236
237 /*
238 * @implemented
239 */
240 DWORD
241 WINAPI
SetTapeParameters(IN HANDLE hDevice,IN DWORD dwOperation,IN LPVOID lpTapeInformation)242 SetTapeParameters(IN HANDLE hDevice,
243 IN DWORD dwOperation,
244 IN LPVOID lpTapeInformation)
245 {
246 if (dwOperation == SET_TAPE_MEDIA_INFORMATION)
247 {
248 return BasepDoTapeOperation(hDevice,
249 IOCTL_TAPE_SET_MEDIA_PARAMS,
250 lpTapeInformation,
251 sizeof(TAPE_SET_MEDIA_PARAMETERS),
252 NULL,
253 0);
254 }
255 else if (dwOperation == SET_TAPE_DRIVE_INFORMATION)
256 {
257 return BasepDoTapeOperation(hDevice,
258 IOCTL_TAPE_SET_DRIVE_PARAMS,
259 lpTapeInformation,
260 sizeof(TAPE_SET_DRIVE_PARAMETERS),
261 NULL,
262 0);
263 }
264
265 return ERROR_INVALID_FUNCTION;
266 }
267
268 /*
269 * @implemented
270 */
271 DWORD
272 WINAPI
SetTapePosition(IN HANDLE hDevice,IN DWORD dwPositionMethod,IN DWORD dwPartition,IN DWORD dwOffsetLow,IN DWORD dwOffsetHigh,IN BOOL bImmediate)273 SetTapePosition(IN HANDLE hDevice,
274 IN DWORD dwPositionMethod,
275 IN DWORD dwPartition,
276 IN DWORD dwOffsetLow,
277 IN DWORD dwOffsetHigh,
278 IN BOOL bImmediate)
279 {
280 TAPE_SET_POSITION TapeSetPosition;
281
282 TapeSetPosition.Method = dwPositionMethod;
283 TapeSetPosition.Partition = dwPartition;
284 TapeSetPosition.Offset.u.LowPart = dwOffsetLow;
285 TapeSetPosition.Offset.u.HighPart = dwOffsetHigh;
286 TapeSetPosition.Immediate = (BOOLEAN)bImmediate;
287 return BasepDoTapeOperation(hDevice,
288 IOCTL_TAPE_SET_POSITION,
289 &TapeSetPosition,
290 sizeof(TapeSetPosition),
291 NULL,
292 0);
293 }
294
295 /*
296 * @implemented
297 */
298 DWORD
299 WINAPI
WriteTapemark(IN HANDLE hDevice,IN DWORD dwTapemarkType,IN DWORD dwTapemarkCount,IN BOOL bImmediate)300 WriteTapemark(IN HANDLE hDevice,
301 IN DWORD dwTapemarkType,
302 IN DWORD dwTapemarkCount,
303 IN BOOL bImmediate)
304 {
305 TAPE_WRITE_MARKS TapeWriteMarks;
306
307 TapeWriteMarks.Type = dwTapemarkType;
308 TapeWriteMarks.Count = dwTapemarkCount;
309 TapeWriteMarks.Immediate = (BOOLEAN)bImmediate;
310 return BasepDoTapeOperation(hDevice,
311 IOCTL_TAPE_WRITE_MARKS,
312 &TapeWriteMarks,
313 sizeof(TapeWriteMarks),
314 NULL,
315 0);
316 }
317
318 /* EOF */
319