Sync with trunk (r48545)
[reactos.git] / dll / win32 / kernel32 / file / tape.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/file/tape.c
6 * PURPOSE: Tape functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
8 * UPDATE HISTORY:
9 * Created 01/11/98
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <k32.h>
15 #define NDEBUG
16 #include <debug.h>
17
18 /* FUNCTIONS ****************************************************************/
19
20 /*
21 * @implemented
22 */
23 DWORD WINAPI
24 CreateTapePartition (HANDLE hDevice,
25 DWORD dwPartitionMethod,
26 DWORD dwCount,
27 DWORD dwSize)
28 {
29 TAPE_CREATE_PARTITION TapeCreatePartition;
30 IO_STATUS_BLOCK IoStatusBlock;
31 DWORD ErrorCode;
32 NTSTATUS Status;
33
34 TapeCreatePartition.Method = dwPartitionMethod;
35 TapeCreatePartition.Count = dwCount;
36 TapeCreatePartition.Size = dwSize;
37
38 Status = NtDeviceIoControlFile (hDevice,
39 NULL,
40 NULL,
41 NULL,
42 &IoStatusBlock,
43 IOCTL_TAPE_CREATE_PARTITION,
44 &TapeCreatePartition,
45 sizeof(TAPE_CREATE_PARTITION),
46 NULL,
47 0);
48 if (!NT_SUCCESS(Status))
49 {
50 ErrorCode = RtlNtStatusToDosError(Status);
51 SetLastError (ErrorCode);
52 return ErrorCode;
53 }
54
55 return ERROR_SUCCESS;
56 }
57
58
59 /*
60 * @implemented
61 */
62 DWORD WINAPI
63 EraseTape (HANDLE hDevice,
64 DWORD dwEraseType,
65 BOOL bImmediate)
66 {
67 TAPE_ERASE TapeErase;
68 IO_STATUS_BLOCK IoStatusBlock;
69 DWORD ErrorCode;
70 NTSTATUS Status;
71
72 TapeErase.Type = dwEraseType;
73 TapeErase.Immediate = (BOOLEAN)bImmediate;
74
75 Status = NtDeviceIoControlFile (hDevice,
76 NULL,
77 NULL,
78 NULL,
79 &IoStatusBlock,
80 IOCTL_TAPE_ERASE,
81 &TapeErase,
82 sizeof(TAPE_ERASE),
83 NULL,
84 0);
85 if (!NT_SUCCESS(Status))
86 {
87 ErrorCode = RtlNtStatusToDosError(Status);
88 SetLastError (ErrorCode);
89 return ErrorCode;
90 }
91
92 return ERROR_SUCCESS;
93 }
94
95
96 /*
97 * @implemented
98 */
99 DWORD WINAPI
100 GetTapeParameters (HANDLE hDevice,
101 DWORD dwOperation,
102 LPDWORD lpdwSize,
103 LPVOID lpTapeInformation)
104 {
105 IO_STATUS_BLOCK IoStatusBlock;
106 DWORD ErrorCode;
107 NTSTATUS Status;
108
109 if (dwOperation == GET_TAPE_MEDIA_INFORMATION)
110 {
111 if (*lpdwSize < sizeof(TAPE_GET_MEDIA_PARAMETERS))
112 {
113 *lpdwSize = sizeof(TAPE_GET_MEDIA_PARAMETERS);
114 return ERROR_MORE_DATA;
115 }
116
117 Status = NtDeviceIoControlFile (hDevice,
118 NULL,
119 NULL,
120 NULL,
121 &IoStatusBlock,
122 IOCTL_TAPE_GET_MEDIA_PARAMS,
123 NULL,
124 0,
125 lpTapeInformation,
126 sizeof(TAPE_GET_MEDIA_PARAMETERS));
127 }
128 else if (dwOperation == GET_TAPE_DRIVE_INFORMATION)
129 {
130 if (*lpdwSize < sizeof(TAPE_GET_DRIVE_PARAMETERS))
131 {
132 *lpdwSize = sizeof(TAPE_GET_DRIVE_PARAMETERS);
133 return ERROR_MORE_DATA;
134 }
135
136 Status = NtDeviceIoControlFile (hDevice,
137 NULL,
138 NULL,
139 NULL,
140 &IoStatusBlock,
141 IOCTL_TAPE_GET_DRIVE_PARAMS,
142 NULL,
143 0,
144 lpTapeInformation,
145 sizeof(TAPE_GET_DRIVE_PARAMETERS));
146 }
147 else
148 {
149 return ERROR_INVALID_FUNCTION;
150 }
151
152 if (!NT_SUCCESS(Status))
153 {
154 ErrorCode = RtlNtStatusToDosError(Status);
155 SetLastError (ErrorCode);
156 return ErrorCode;
157 }
158
159 return ERROR_SUCCESS;
160 }
161
162
163 /*
164 * @implemented
165 */
166 DWORD WINAPI
167 GetTapePosition (HANDLE hDevice,
168 DWORD dwPositionType,
169 LPDWORD lpdwPartition,
170 LPDWORD lpdwOffsetLow,
171 LPDWORD lpdwOffsetHigh)
172 {
173 TAPE_GET_POSITION TapeGetPosition;
174 IO_STATUS_BLOCK IoStatusBlock;
175 DWORD ErrorCode;
176 NTSTATUS Status;
177
178 TapeGetPosition.Type = dwPositionType;
179
180 Status = NtDeviceIoControlFile (hDevice,
181 NULL,
182 NULL,
183 NULL,
184 &IoStatusBlock,
185 IOCTL_TAPE_GET_POSITION,
186 &TapeGetPosition,
187 sizeof(TAPE_GET_POSITION),
188 &TapeGetPosition,
189 sizeof(TAPE_GET_POSITION));
190 if (!NT_SUCCESS(Status))
191 {
192 *lpdwPartition = 0;
193 *lpdwOffsetLow = 0;
194 *lpdwOffsetHigh = 0;
195
196 ErrorCode = RtlNtStatusToDosError(Status);
197 SetLastError (ErrorCode);
198 return ErrorCode;
199 }
200
201 *lpdwPartition = TapeGetPosition.Partition;
202 *lpdwOffsetLow = TapeGetPosition.Offset.u.LowPart;
203 *lpdwOffsetHigh = TapeGetPosition.Offset.u.HighPart;
204
205 return ERROR_SUCCESS;
206 }
207
208
209 /*
210 * @implemented
211 */
212 DWORD WINAPI
213 GetTapeStatus (HANDLE hDevice)
214 {
215 IO_STATUS_BLOCK IoStatusBlock;
216 DWORD ErrorCode;
217 NTSTATUS Status;
218
219 Status = NtDeviceIoControlFile (hDevice,
220 NULL,
221 NULL,
222 NULL,
223 &IoStatusBlock,
224 IOCTL_TAPE_GET_STATUS,
225 NULL,
226 0,
227 NULL,
228 0);
229 if (!NT_SUCCESS(Status))
230 {
231 ErrorCode = RtlNtStatusToDosError(Status);
232 SetLastError (ErrorCode);
233 return ErrorCode;
234 }
235
236 return ERROR_SUCCESS;
237 }
238
239
240 /*
241 * @implemented
242 */
243 DWORD WINAPI
244 PrepareTape (HANDLE hDevice,
245 DWORD dwOperation,
246 BOOL bImmediate)
247 {
248 TAPE_PREPARE TapePrepare;
249 IO_STATUS_BLOCK IoStatusBlock;
250 DWORD ErrorCode;
251 NTSTATUS Status;
252
253 TapePrepare.Operation = dwOperation;
254 TapePrepare.Immediate = (BOOLEAN)bImmediate;
255
256 Status = NtDeviceIoControlFile (hDevice,
257 NULL,
258 NULL,
259 NULL,
260 &IoStatusBlock,
261 IOCTL_TAPE_PREPARE,
262 &TapePrepare,
263 sizeof(TAPE_PREPARE),
264 NULL,
265 0);
266 if (!NT_SUCCESS(Status))
267 {
268 ErrorCode = RtlNtStatusToDosError(Status);
269 SetLastError (ErrorCode);
270 return ErrorCode;
271 }
272
273 return ERROR_SUCCESS;
274 }
275
276
277 /*
278 * @implemented
279 */
280 DWORD WINAPI
281 SetTapeParameters (HANDLE hDevice,
282 DWORD dwOperation,
283 LPVOID lpTapeInformation)
284 {
285 IO_STATUS_BLOCK IoStatusBlock;
286 DWORD ErrorCode;
287 NTSTATUS Status;
288
289 if (dwOperation == SET_TAPE_MEDIA_INFORMATION)
290 {
291 Status = NtDeviceIoControlFile (hDevice,
292 NULL,
293 NULL,
294 NULL,
295 &IoStatusBlock,
296 IOCTL_TAPE_SET_MEDIA_PARAMS,
297 lpTapeInformation,
298 sizeof(TAPE_SET_MEDIA_PARAMETERS),
299 NULL,
300 0);
301 }
302 else if (dwOperation == SET_TAPE_DRIVE_INFORMATION)
303 {
304 Status = NtDeviceIoControlFile (hDevice,
305 NULL,
306 NULL,
307 NULL,
308 &IoStatusBlock,
309 IOCTL_TAPE_SET_DRIVE_PARAMS,
310 lpTapeInformation,
311 sizeof(TAPE_SET_DRIVE_PARAMETERS),
312 NULL,
313 0);
314 }
315 else
316 {
317 return ERROR_INVALID_FUNCTION;
318 }
319
320 if (!NT_SUCCESS(Status))
321 {
322 ErrorCode = RtlNtStatusToDosError(Status);
323 SetLastError (ErrorCode);
324 return ErrorCode;
325 }
326
327 return ERROR_SUCCESS;
328 }
329
330
331 /*
332 * @implemented
333 */
334 DWORD WINAPI
335 SetTapePosition (HANDLE hDevice,
336 DWORD dwPositionMethod,
337 DWORD dwPartition,
338 DWORD dwOffsetLow,
339 DWORD dwOffsetHigh,
340 BOOL bImmediate)
341 {
342 TAPE_SET_POSITION TapeSetPosition;
343 IO_STATUS_BLOCK IoStatusBlock;
344 DWORD ErrorCode;
345 NTSTATUS Status;
346
347 TapeSetPosition.Method = dwPositionMethod;
348 TapeSetPosition.Partition = dwPartition;
349 TapeSetPosition.Offset.u.LowPart = dwOffsetLow;
350 TapeSetPosition.Offset.u.HighPart = dwOffsetHigh;
351 TapeSetPosition.Immediate = (BOOLEAN)bImmediate;
352
353 Status = NtDeviceIoControlFile (hDevice,
354 NULL,
355 NULL,
356 NULL,
357 &IoStatusBlock,
358 IOCTL_TAPE_SET_POSITION,
359 &TapeSetPosition,
360 sizeof(TAPE_SET_POSITION),
361 NULL,
362 0);
363 if (!NT_SUCCESS(Status))
364 {
365 ErrorCode = RtlNtStatusToDosError(Status);
366 SetLastError (ErrorCode);
367 return ErrorCode;
368 }
369
370 return ERROR_SUCCESS;
371 }
372
373
374 /*
375 * @implemented
376 */
377 DWORD WINAPI
378 WriteTapemark (HANDLE hDevice,
379 DWORD dwTapemarkType,
380 DWORD dwTapemarkCount,
381 BOOL bImmediate)
382 {
383 TAPE_WRITE_MARKS TapeWriteMarks;
384 IO_STATUS_BLOCK IoStatusBlock;
385 DWORD ErrorCode;
386 NTSTATUS Status;
387
388 TapeWriteMarks.Type = dwTapemarkType;
389 TapeWriteMarks.Count = dwTapemarkCount;
390 TapeWriteMarks.Immediate = (BOOLEAN)bImmediate;
391
392 Status = NtDeviceIoControlFile (hDevice,
393 NULL,
394 NULL,
395 NULL,
396 &IoStatusBlock,
397 IOCTL_TAPE_WRITE_MARKS,
398 &TapeWriteMarks,
399 sizeof(TAPE_WRITE_MARKS),
400 NULL,
401 0);
402 if (!NT_SUCCESS(Status))
403 {
404 ErrorCode = RtlNtStatusToDosError(Status);
405 SetLastError (ErrorCode);
406 return ErrorCode;
407 }
408
409 return ERROR_SUCCESS;
410 }
411
412 /* EOF */