kernel32: Avoid returning the same name when GetTempFileName is called twice in a...
[wine/multimedia.git] / dlls / kernel32 / tape.c
blob5ad8ed3fbb2a485b48a71588393d9e8dc439023a
1 /*
2 * Tape handling functions
4 * Copyright 1999 Chris Morgan <cmorgan@wpi.edu>
5 * James Abbatiello <abbeyj@wpi.edu>
6 * Copyright 2006 Hans Leidekker
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <stdarg.h>
25 #include "ntstatus.h"
26 #define WIN32_NO_STATUS
27 #include "windef.h"
28 #include "winternl.h"
29 #include "winbase.h"
30 #include "winerror.h"
31 #include "winioctl.h"
32 #include "ddk/ntddtape.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(tape);
38 static DWORD set_error_from_status( NTSTATUS status )
40 DWORD error = RtlNtStatusToDosError( status );
42 SetLastError( error );
43 return error;
46 /************************************************************************
47 * BackupRead (KERNEL32.@)
49 * Backup a file or directory.
51 BOOL WINAPI BackupRead( HANDLE file, LPBYTE buffer, DWORD to_read,
52 LPDWORD read, BOOL abort, BOOL security, LPVOID *context )
54 FIXME( "(%p, %p, %d, %p, %d, %d, %p)\n", file, buffer,
55 to_read, read, abort, security, context );
56 SetLastError( ERROR_NOT_SUPPORTED );
57 return FALSE;
61 /************************************************************************
62 * BackupSeek (KERNEL32.@)
64 * Seek forward in a backup stream.
66 BOOL WINAPI BackupSeek( HANDLE file, DWORD seek_low, DWORD seek_high,
67 LPDWORD seeked_low, LPDWORD seeked_high, LPVOID *context )
69 FIXME( "(%p, %d, %d, %p, %p, %p)\n", file, seek_low,
70 seek_high, seeked_low, seeked_high, context );
71 SetLastError( ERROR_NOT_SUPPORTED );
72 return FALSE;
76 /************************************************************************
77 * BackupWrite (KERNEL32.@)
79 * Restore a file or directory.
81 BOOL WINAPI BackupWrite( HANDLE file, LPBYTE buffer, DWORD to_write,
82 LPDWORD written, BOOL abort, BOOL security, LPVOID *context )
84 FIXME( "(%p, %p, %d, %p, %d, %d, %p)\n", file, buffer,
85 to_write, written, abort, security, context );
86 SetLastError( ERROR_NOT_SUPPORTED );
87 return FALSE;
91 /************************************************************************
92 * CreateTapePartition (KERNEL32.@)
94 * Format a tape.
96 DWORD WINAPI CreateTapePartition( HANDLE device, DWORD method,
97 DWORD count, DWORD size )
99 NTSTATUS status;
100 TAPE_CREATE_PARTITION part;
101 IO_STATUS_BLOCK io;
103 TRACE( "(%p, %d, %d, %d)\n", device, method, count, size );
105 part.Method = method;
106 part.Count = count;
107 part.Size = size;
109 status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
110 IOCTL_TAPE_CREATE_PARTITION, &part, sizeof(TAPE_CREATE_PARTITION), NULL, 0 );
112 return set_error_from_status( status );
116 /************************************************************************
117 * EraseTape (KERNEL32.@)
119 * Erase a tape.
121 DWORD WINAPI EraseTape( HANDLE device, DWORD type, BOOL immediate )
123 NTSTATUS status;
124 TAPE_ERASE erase;
125 IO_STATUS_BLOCK io;
127 TRACE( "(%p, %d, %d)\n", device, type, immediate );
129 erase.Type = type;
130 erase.Immediate = immediate;
132 status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
133 IOCTL_TAPE_ERASE, &erase, sizeof(TAPE_ERASE), NULL, 0 );
135 return set_error_from_status( status );
139 /************************************************************************
140 * GetTapeParameters (KERNEL32.@)
142 * Retrieve information about a tape or tape drive.
144 DWORD WINAPI GetTapeParameters( HANDLE device, DWORD operation,
145 LPDWORD size, LPVOID info )
147 NTSTATUS status = STATUS_INVALID_PARAMETER;
148 IO_STATUS_BLOCK io;
150 TRACE( "(%p, %d, %p, %p)\n", device, operation, size, info );
152 switch (operation)
154 case GET_TAPE_DRIVE_INFORMATION:
155 status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
156 IOCTL_TAPE_GET_DRIVE_PARAMS, NULL, 0, info, *size );
157 break;
158 case GET_TAPE_MEDIA_INFORMATION:
159 status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
160 IOCTL_TAPE_GET_MEDIA_PARAMS, NULL, 0, info, *size );
161 break;
162 default:
163 ERR( "Unhandled operation: 0x%08x\n", operation );
166 return set_error_from_status( status );
170 /************************************************************************
171 * GetTapePosition (KERNEL32.@)
173 * Retrieve the current tape position.
175 DWORD WINAPI GetTapePosition( HANDLE device, DWORD type, LPDWORD partition,
176 LPDWORD offset_low, LPDWORD offset_high )
178 NTSTATUS status;
179 TAPE_GET_POSITION in, out;
180 IO_STATUS_BLOCK io;
182 TRACE( "(%p, %d, %p, %p, %p)\n", device, type, partition, offset_low,
183 offset_high );
185 memset( &in, 0, sizeof(TAPE_GET_POSITION) );
186 in.Type = type;
188 status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
189 IOCTL_TAPE_GET_POSITION, &in, sizeof(TAPE_GET_POSITION),
190 &out, sizeof(TAPE_GET_POSITION) );
192 if (status != STATUS_SUCCESS)
193 return set_error_from_status( status );
195 *partition = out.Partition;
196 *offset_low = out.OffsetLow;
197 *offset_high = out.OffsetHigh;
199 return set_error_from_status( status );
203 /************************************************************************
204 * GetTapeStatus (KERNEL32.@)
206 * Determine if the tape device is ready for operation.
208 DWORD WINAPI GetTapeStatus( HANDLE device )
210 NTSTATUS status;
211 IO_STATUS_BLOCK io;
213 TRACE( "(%p)\n", device );
215 status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
216 IOCTL_TAPE_GET_STATUS, NULL, 0, NULL, 0 );
218 return set_error_from_status( status );
222 /************************************************************************
223 * PrepareTape (KERNEL32.@)
225 * Prepare a tape for operation.
227 DWORD WINAPI PrepareTape( HANDLE device, DWORD operation, BOOL immediate )
229 NTSTATUS status;
230 TAPE_PREPARE prep;
231 IO_STATUS_BLOCK io;
233 TRACE( "(%p, %d, %d)\n", device, operation, immediate );
235 prep.Operation = operation;
236 prep.Immediate = immediate;
238 status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
239 IOCTL_TAPE_PREPARE, &prep, sizeof(TAPE_PREPARE), NULL, 0 );
241 return set_error_from_status( status );
245 /************************************************************************
246 * SetTapeParameters (KERNEL32.@)
248 * Configure a tape or tape device.
250 DWORD WINAPI SetTapeParameters( HANDLE device, DWORD operation, LPVOID info )
252 NTSTATUS status = STATUS_INVALID_PARAMETER;
253 IO_STATUS_BLOCK io;
255 TRACE( "(%p, %d, %p)\n", device, operation, info );
257 switch (operation)
259 case SET_TAPE_DRIVE_INFORMATION:
260 status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
261 IOCTL_TAPE_SET_DRIVE_PARAMS, info, sizeof(TAPE_SET_DRIVE_PARAMETERS),
262 NULL, 0 );
263 break;
264 case SET_TAPE_MEDIA_INFORMATION:
265 status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
266 IOCTL_TAPE_SET_MEDIA_PARAMS, info, sizeof(TAPE_SET_MEDIA_PARAMETERS),
267 NULL, 0 );
268 break;
269 default:
270 ERR( "Unhandled operation: 0x%08x\n", operation );
273 return set_error_from_status( status );
277 /************************************************************************
278 * SetTapePosition (KERNEL32.@)
280 * Set the tape position on a given device.
282 DWORD WINAPI SetTapePosition( HANDLE device, DWORD method, DWORD partition,
283 DWORD offset_low, DWORD offset_high, BOOL immediate )
285 NTSTATUS status;
286 TAPE_SET_POSITION pos;
287 IO_STATUS_BLOCK io;
289 TRACE( "(%p, %d, %d, %d, %d, %d)\n", device, method, partition,
290 offset_low, offset_high, immediate );
292 pos.Method = method;
293 pos.Partition = partition;
294 pos.Offset.u.LowPart = offset_low;
295 pos.Offset.u.HighPart = offset_high;
296 pos.Immediate = immediate;
298 status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
299 IOCTL_TAPE_SET_POSITION, &pos, sizeof(TAPE_SET_POSITION), NULL, 0 );
301 return set_error_from_status( status );
305 /************************************************************************
306 * WriteTapemark (KERNEL32.@)
308 * Write tapemarks on a tape.
310 DWORD WINAPI WriteTapemark( HANDLE device, DWORD type, DWORD count,
311 BOOL immediate )
313 NTSTATUS status;
314 TAPE_WRITE_MARKS marks;
315 IO_STATUS_BLOCK io;
317 TRACE( "(%p, %d, %d, %d)\n", device, type, count, immediate );
319 marks.Type = type;
320 marks.Count = count;
321 marks.Immediate = immediate;
323 status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
324 IOCTL_TAPE_WRITE_MARKS, &marks, sizeof(TAPE_WRITE_MARKS), NULL, 0 );
326 return set_error_from_status( status );