1999-12-10 03:46:20 +00:00
|
|
|
/*
|
|
|
|
* Tape handling functions
|
|
|
|
*
|
|
|
|
* Copyright 1999 Chris Morgan <cmorgan@wpi.edu>
|
|
|
|
* James Abbatiello <abbeyj@wpi.edu>
|
2006-01-27 11:10:03 +00:00
|
|
|
* Copyright 2006 Hans Leidekker
|
1999-12-10 03:46:20 +00:00
|
|
|
*
|
2002-03-09 23:29:33 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-12-10 03:46:20 +00:00
|
|
|
*/
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2003-09-05 23:08:26 +00:00
|
|
|
#include "windef.h"
|
2006-01-27 11:10:03 +00:00
|
|
|
#include "winternl.h"
|
1999-12-10 03:46:20 +00:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
2006-01-27 11:10:03 +00:00
|
|
|
#include "winioctl.h"
|
|
|
|
#include "ddk/ntddtape.h"
|
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(tape);
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
static DWORD set_error_from_status( NTSTATUS status )
|
|
|
|
{
|
|
|
|
DWORD error = RtlNtStatusToDosError( status );
|
|
|
|
|
|
|
|
SetLastError( error );
|
|
|
|
return error;
|
|
|
|
}
|
1999-12-10 03:46:20 +00:00
|
|
|
|
|
|
|
/************************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* BackupRead (KERNEL32.@)
|
2006-01-27 11:10:03 +00:00
|
|
|
*
|
|
|
|
* Backup a file or directory.
|
1999-12-10 03:46:20 +00:00
|
|
|
*/
|
2006-01-27 11:10:03 +00:00
|
|
|
BOOL WINAPI BackupRead( HANDLE file, LPBYTE buffer, DWORD to_read,
|
|
|
|
LPDWORD read, BOOL abort, BOOL security, LPVOID *context )
|
1999-12-10 03:46:20 +00:00
|
|
|
{
|
2022-02-11 07:41:23 +00:00
|
|
|
FIXME( "(%p, %p, %ld, %p, %d, %d, %p)\n", file, buffer,
|
2006-01-27 11:10:03 +00:00
|
|
|
to_read, read, abort, security, context );
|
|
|
|
SetLastError( ERROR_NOT_SUPPORTED );
|
|
|
|
return FALSE;
|
1999-12-10 03:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* BackupSeek (KERNEL32.@)
|
2006-01-27 11:10:03 +00:00
|
|
|
*
|
|
|
|
* Seek forward in a backup stream.
|
1999-12-10 03:46:20 +00:00
|
|
|
*/
|
2006-01-27 11:10:03 +00:00
|
|
|
BOOL WINAPI BackupSeek( HANDLE file, DWORD seek_low, DWORD seek_high,
|
|
|
|
LPDWORD seeked_low, LPDWORD seeked_high, LPVOID *context )
|
1999-12-10 03:46:20 +00:00
|
|
|
{
|
2022-02-11 07:41:23 +00:00
|
|
|
FIXME( "(%p, %ld, %ld, %p, %p, %p)\n", file, seek_low,
|
2006-01-27 11:10:03 +00:00
|
|
|
seek_high, seeked_low, seeked_high, context );
|
|
|
|
SetLastError( ERROR_NOT_SUPPORTED );
|
|
|
|
return FALSE;
|
2002-05-31 23:06:46 +00:00
|
|
|
}
|
1999-12-10 03:46:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* BackupWrite (KERNEL32.@)
|
2006-01-27 11:10:03 +00:00
|
|
|
*
|
|
|
|
* Restore a file or directory.
|
1999-12-10 03:46:20 +00:00
|
|
|
*/
|
2006-01-27 11:10:03 +00:00
|
|
|
BOOL WINAPI BackupWrite( HANDLE file, LPBYTE buffer, DWORD to_write,
|
|
|
|
LPDWORD written, BOOL abort, BOOL security, LPVOID *context )
|
1999-12-10 03:46:20 +00:00
|
|
|
{
|
2022-02-11 07:41:23 +00:00
|
|
|
FIXME( "(%p, %p, %ld, %p, %d, %d, %p)\n", file, buffer,
|
2006-01-27 11:10:03 +00:00
|
|
|
to_write, written, abort, security, context );
|
|
|
|
SetLastError( ERROR_NOT_SUPPORTED );
|
|
|
|
return FALSE;
|
1999-12-10 03:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* CreateTapePartition (KERNEL32.@)
|
2006-01-27 11:10:03 +00:00
|
|
|
*
|
|
|
|
* Format a tape.
|
1999-12-10 03:46:20 +00:00
|
|
|
*/
|
2006-01-27 11:10:03 +00:00
|
|
|
DWORD WINAPI CreateTapePartition( HANDLE device, DWORD method,
|
|
|
|
DWORD count, DWORD size )
|
1999-12-10 03:46:20 +00:00
|
|
|
{
|
2006-01-27 11:10:03 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
TAPE_CREATE_PARTITION part;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
2022-02-11 07:41:23 +00:00
|
|
|
TRACE( "(%p, %ld, %ld, %ld)\n", device, method, count, size );
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
part.Method = method;
|
|
|
|
part.Count = count;
|
|
|
|
part.Size = size;
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
|
|
|
|
IOCTL_TAPE_CREATE_PARTITION, &part, sizeof(TAPE_CREATE_PARTITION), NULL, 0 );
|
|
|
|
|
|
|
|
return set_error_from_status( status );
|
1999-12-10 03:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* EraseTape (KERNEL32.@)
|
2006-01-27 11:10:03 +00:00
|
|
|
*
|
|
|
|
* Erase a tape.
|
1999-12-10 03:46:20 +00:00
|
|
|
*/
|
2006-01-27 11:10:03 +00:00
|
|
|
DWORD WINAPI EraseTape( HANDLE device, DWORD type, BOOL immediate )
|
1999-12-10 03:46:20 +00:00
|
|
|
{
|
2006-01-27 11:10:03 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
TAPE_ERASE erase;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
2022-02-11 07:41:23 +00:00
|
|
|
TRACE( "(%p, %ld, %d)\n", device, type, immediate );
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
erase.Type = type;
|
|
|
|
erase.Immediate = immediate;
|
|
|
|
|
|
|
|
status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
|
|
|
|
IOCTL_TAPE_ERASE, &erase, sizeof(TAPE_ERASE), NULL, 0 );
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
return set_error_from_status( status );
|
1999-12-10 03:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* GetTapeParameters (KERNEL32.@)
|
2006-01-27 11:10:03 +00:00
|
|
|
*
|
|
|
|
* Retrieve information about a tape or tape drive.
|
1999-12-10 03:46:20 +00:00
|
|
|
*/
|
2006-01-27 11:10:03 +00:00
|
|
|
DWORD WINAPI GetTapeParameters( HANDLE device, DWORD operation,
|
|
|
|
LPDWORD size, LPVOID info )
|
1999-12-10 03:46:20 +00:00
|
|
|
{
|
2006-01-27 11:10:03 +00:00
|
|
|
NTSTATUS status = STATUS_INVALID_PARAMETER;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
2022-02-11 07:41:23 +00:00
|
|
|
TRACE( "(%p, %ld, %p, %p)\n", device, operation, size, info );
|
2006-01-27 11:10:03 +00:00
|
|
|
|
|
|
|
switch (operation)
|
|
|
|
{
|
|
|
|
case GET_TAPE_DRIVE_INFORMATION:
|
|
|
|
status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
|
|
|
|
IOCTL_TAPE_GET_DRIVE_PARAMS, NULL, 0, info, *size );
|
|
|
|
break;
|
|
|
|
case GET_TAPE_MEDIA_INFORMATION:
|
|
|
|
status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
|
|
|
|
IOCTL_TAPE_GET_MEDIA_PARAMS, NULL, 0, info, *size );
|
|
|
|
break;
|
|
|
|
default:
|
2022-02-11 07:41:23 +00:00
|
|
|
ERR( "Unhandled operation: 0x%08lx\n", operation );
|
2006-01-27 11:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return set_error_from_status( status );
|
1999-12-10 03:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* GetTapePosition (KERNEL32.@)
|
2006-01-27 11:10:03 +00:00
|
|
|
*
|
|
|
|
* Retrieve the current tape position.
|
1999-12-10 03:46:20 +00:00
|
|
|
*/
|
2006-01-27 11:10:03 +00:00
|
|
|
DWORD WINAPI GetTapePosition( HANDLE device, DWORD type, LPDWORD partition,
|
|
|
|
LPDWORD offset_low, LPDWORD offset_high )
|
2002-05-31 23:06:46 +00:00
|
|
|
{
|
2006-01-27 11:10:03 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
TAPE_GET_POSITION in, out;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
2022-02-11 07:41:23 +00:00
|
|
|
TRACE( "(%p, %ld, %p, %p, %p)\n", device, type, partition, offset_low,
|
2006-01-27 11:10:03 +00:00
|
|
|
offset_high );
|
|
|
|
|
|
|
|
memset( &in, 0, sizeof(TAPE_GET_POSITION) );
|
|
|
|
in.Type = type;
|
|
|
|
|
|
|
|
status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
|
|
|
|
IOCTL_TAPE_GET_POSITION, &in, sizeof(TAPE_GET_POSITION),
|
|
|
|
&out, sizeof(TAPE_GET_POSITION) );
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
return set_error_from_status( status );
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
*partition = out.Partition;
|
|
|
|
*offset_low = out.OffsetLow;
|
|
|
|
*offset_high = out.OffsetHigh;
|
|
|
|
|
|
|
|
return set_error_from_status( status );
|
1999-12-10 03:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* GetTapeStatus (KERNEL32.@)
|
2006-01-27 11:10:03 +00:00
|
|
|
*
|
|
|
|
* Determine if the tape device is ready for operation.
|
1999-12-10 03:46:20 +00:00
|
|
|
*/
|
2006-01-27 11:10:03 +00:00
|
|
|
DWORD WINAPI GetTapeStatus( HANDLE device )
|
1999-12-10 03:46:20 +00:00
|
|
|
{
|
2006-01-27 11:10:03 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
|
|
|
TRACE( "(%p)\n", device );
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
|
|
|
|
IOCTL_TAPE_GET_STATUS, NULL, 0, NULL, 0 );
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
return set_error_from_status( status );
|
1999-12-10 03:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* PrepareTape (KERNEL32.@)
|
2006-01-27 11:10:03 +00:00
|
|
|
*
|
|
|
|
* Prepare a tape for operation.
|
1999-12-10 03:46:20 +00:00
|
|
|
*/
|
2006-01-27 11:10:03 +00:00
|
|
|
DWORD WINAPI PrepareTape( HANDLE device, DWORD operation, BOOL immediate )
|
2002-05-31 23:06:46 +00:00
|
|
|
{
|
2006-01-27 11:10:03 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
TAPE_PREPARE prep;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
2022-02-11 07:41:23 +00:00
|
|
|
TRACE( "(%p, %ld, %d)\n", device, operation, immediate );
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
prep.Operation = operation;
|
|
|
|
prep.Immediate = immediate;
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
|
|
|
|
IOCTL_TAPE_PREPARE, &prep, sizeof(TAPE_PREPARE), NULL, 0 );
|
|
|
|
|
|
|
|
return set_error_from_status( status );
|
1999-12-10 03:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* SetTapeParameters (KERNEL32.@)
|
2006-01-27 11:10:03 +00:00
|
|
|
*
|
|
|
|
* Configure a tape or tape device.
|
1999-12-10 03:46:20 +00:00
|
|
|
*/
|
2006-01-27 11:10:03 +00:00
|
|
|
DWORD WINAPI SetTapeParameters( HANDLE device, DWORD operation, LPVOID info )
|
1999-12-10 03:46:20 +00:00
|
|
|
{
|
2006-01-27 11:10:03 +00:00
|
|
|
NTSTATUS status = STATUS_INVALID_PARAMETER;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
2022-02-11 07:41:23 +00:00
|
|
|
TRACE( "(%p, %ld, %p)\n", device, operation, info );
|
2006-01-27 11:10:03 +00:00
|
|
|
|
|
|
|
switch (operation)
|
|
|
|
{
|
|
|
|
case SET_TAPE_DRIVE_INFORMATION:
|
|
|
|
status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
|
|
|
|
IOCTL_TAPE_SET_DRIVE_PARAMS, info, sizeof(TAPE_SET_DRIVE_PARAMETERS),
|
|
|
|
NULL, 0 );
|
|
|
|
break;
|
|
|
|
case SET_TAPE_MEDIA_INFORMATION:
|
|
|
|
status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
|
|
|
|
IOCTL_TAPE_SET_MEDIA_PARAMS, info, sizeof(TAPE_SET_MEDIA_PARAMETERS),
|
|
|
|
NULL, 0 );
|
|
|
|
break;
|
|
|
|
default:
|
2022-02-11 07:41:23 +00:00
|
|
|
ERR( "Unhandled operation: 0x%08lx\n", operation );
|
2006-01-27 11:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return set_error_from_status( status );
|
1999-12-10 03:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* SetTapePosition (KERNEL32.@)
|
2006-01-27 11:10:03 +00:00
|
|
|
*
|
|
|
|
* Set the tape position on a given device.
|
1999-12-10 03:46:20 +00:00
|
|
|
*/
|
2006-01-27 11:10:03 +00:00
|
|
|
DWORD WINAPI SetTapePosition( HANDLE device, DWORD method, DWORD partition,
|
|
|
|
DWORD offset_low, DWORD offset_high, BOOL immediate )
|
1999-12-10 03:46:20 +00:00
|
|
|
{
|
2006-01-27 11:10:03 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
TAPE_SET_POSITION pos;
|
|
|
|
IO_STATUS_BLOCK io;
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2022-02-11 07:41:23 +00:00
|
|
|
TRACE( "(%p, %ld, %ld, %ld, %ld, %d)\n", device, method, partition,
|
2006-01-27 11:10:03 +00:00
|
|
|
offset_low, offset_high, immediate );
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
pos.Method = method;
|
|
|
|
pos.Partition = partition;
|
|
|
|
pos.Offset.u.LowPart = offset_low;
|
|
|
|
pos.Offset.u.HighPart = offset_high;
|
|
|
|
pos.Immediate = immediate;
|
|
|
|
|
|
|
|
status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
|
|
|
|
IOCTL_TAPE_SET_POSITION, &pos, sizeof(TAPE_SET_POSITION), NULL, 0 );
|
|
|
|
|
|
|
|
return set_error_from_status( status );
|
1999-12-10 03:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
2001-06-13 20:13:18 +00:00
|
|
|
* WriteTapemark (KERNEL32.@)
|
2006-01-27 11:10:03 +00:00
|
|
|
*
|
|
|
|
* Write tapemarks on a tape.
|
1999-12-10 03:46:20 +00:00
|
|
|
*/
|
2006-01-27 11:10:03 +00:00
|
|
|
DWORD WINAPI WriteTapemark( HANDLE device, DWORD type, DWORD count,
|
|
|
|
BOOL immediate )
|
1999-12-10 03:46:20 +00:00
|
|
|
{
|
2006-01-27 11:10:03 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
TAPE_WRITE_MARKS marks;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
2022-02-11 07:41:23 +00:00
|
|
|
TRACE( "(%p, %ld, %ld, %d)\n", device, type, count, immediate );
|
2006-01-27 11:10:03 +00:00
|
|
|
|
|
|
|
marks.Type = type;
|
|
|
|
marks.Count = count;
|
|
|
|
marks.Immediate = immediate;
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
|
|
|
|
IOCTL_TAPE_WRITE_MARKS, &marks, sizeof(TAPE_WRITE_MARKS), NULL, 0 );
|
1999-12-10 03:46:20 +00:00
|
|
|
|
2006-01-27 11:10:03 +00:00
|
|
|
return set_error_from_status( status );
|
1999-12-12 19:40:01 +00:00
|
|
|
}
|