2006-01-26 13:23:08 +01:00
|
|
|
/*
|
|
|
|
* TAPE support
|
|
|
|
*
|
|
|
|
* Copyright 2006 Hans Leidekker
|
|
|
|
*
|
|
|
|
* 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 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-01-26 13:23:08 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_MTIO_H
|
|
|
|
#include <sys/mtio.h>
|
|
|
|
#endif
|
|
|
|
|
2006-01-31 13:02:10 +01:00
|
|
|
#if !defined(MTCOMPRESSION) && defined(MTCOMP)
|
|
|
|
#define MTCOMPRESSION MTCOMP
|
|
|
|
#endif
|
2006-02-09 12:08:32 +01:00
|
|
|
#if !defined(MTSETBLK) && defined(MTSETBSIZ)
|
|
|
|
#define MTSETBLK MTSETBSIZ
|
|
|
|
#endif
|
2006-06-20 20:20:45 +02:00
|
|
|
#if !defined(MTSETBLK) && defined(MTSRSZ)
|
|
|
|
#define MTSETBLK MTSRSZ
|
|
|
|
#endif
|
|
|
|
#ifndef MT_ST_BLKSIZE_MASK
|
|
|
|
#define MT_ST_BLKSIZE_MASK 0xffffff
|
|
|
|
#endif
|
2006-01-31 13:02:10 +01:00
|
|
|
|
2006-11-05 22:53:54 +01:00
|
|
|
/* Darwin 7.9.0 has MTSETBSIZ instead of MTSETBLK */
|
|
|
|
#if !defined(MTSETBLK) && defined(MTSETBSIZ)
|
|
|
|
#define MTSETBLK MTSETBSIZ
|
|
|
|
#endif
|
|
|
|
|
2006-01-26 13:23:08 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2015-03-14 03:38:17 +01:00
|
|
|
#define NONAMELESSUNION
|
2006-01-26 13:23:08 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "winioctl.h"
|
|
|
|
#include "ddk/ntddtape.h"
|
|
|
|
#include "ntdll_misc.h"
|
|
|
|
#include "wine/server.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(tape);
|
|
|
|
|
|
|
|
static const char *io2str( DWORD io )
|
|
|
|
{
|
|
|
|
switch (io)
|
|
|
|
{
|
2009-03-24 20:54:00 +01:00
|
|
|
#define X(x) case (x): return #x
|
2006-01-26 13:23:08 +01:00
|
|
|
X(IOCTL_TAPE_CHECK_VERIFY);
|
|
|
|
X(IOCTL_TAPE_CREATE_PARTITION);
|
|
|
|
X(IOCTL_TAPE_ERASE);
|
|
|
|
X(IOCTL_TAPE_FIND_NEW_DEVICES);
|
|
|
|
X(IOCTL_TAPE_GET_DRIVE_PARAMS);
|
|
|
|
X(IOCTL_TAPE_GET_MEDIA_PARAMS);
|
|
|
|
X(IOCTL_TAPE_GET_POSITION);
|
|
|
|
X(IOCTL_TAPE_GET_STATUS);
|
|
|
|
X(IOCTL_TAPE_PREPARE);
|
|
|
|
X(IOCTL_TAPE_SET_DRIVE_PARAMS);
|
|
|
|
X(IOCTL_TAPE_SET_MEDIA_PARAMS);
|
|
|
|
X(IOCTL_TAPE_SET_POSITION);
|
|
|
|
X(IOCTL_TAPE_WRITE_MARKS);
|
|
|
|
#undef X
|
2006-10-16 13:49:06 +02:00
|
|
|
default: { static char tmp[32]; sprintf(tmp, "IOCTL_TAPE_%d\n", io); return tmp; }
|
2006-01-26 13:23:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* TAPE_GetStatus
|
|
|
|
*/
|
2015-06-29 19:56:23 +02:00
|
|
|
#ifdef HAVE_SYS_MTIO_H
|
2010-04-26 14:18:46 +02:00
|
|
|
static inline NTSTATUS TAPE_GetStatus( int error )
|
2006-01-26 13:23:08 +01:00
|
|
|
{
|
|
|
|
if (!error) return STATUS_SUCCESS;
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
2015-06-29 19:56:23 +02:00
|
|
|
#endif
|
2006-01-26 13:23:08 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* TAPE_CreatePartition
|
|
|
|
*/
|
2007-06-25 22:11:38 +02:00
|
|
|
static NTSTATUS TAPE_CreatePartition( int fd, const TAPE_CREATE_PARTITION *data )
|
2006-01-26 13:23:08 +01:00
|
|
|
{
|
|
|
|
#ifdef HAVE_SYS_MTIO_H
|
|
|
|
struct mtop cmd;
|
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "fd: %d method: 0x%08x count: 0x%08x size: 0x%08x\n",
|
2006-01-26 13:23:08 +01:00
|
|
|
fd, data->Method, data->Count, data->Size );
|
|
|
|
|
|
|
|
if (data->Count > 1)
|
|
|
|
{
|
|
|
|
WARN( "Creating more than 1 partition is not supported\n" );
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (data->Method)
|
|
|
|
{
|
2006-01-31 13:02:10 +01:00
|
|
|
#ifdef MTMKPART
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_FIXED_PARTITIONS:
|
|
|
|
case TAPE_SELECT_PARTITIONS:
|
|
|
|
cmd.mt_op = MTMKPART;
|
|
|
|
cmd.mt_count = 0;
|
|
|
|
break;
|
|
|
|
case TAPE_INITIATOR_PARTITIONS:
|
|
|
|
cmd.mt_op = MTMKPART;
|
|
|
|
cmd.mt_count = data->Size;
|
|
|
|
break;
|
2006-01-31 13:02:10 +01:00
|
|
|
#endif
|
2006-01-26 13:23:08 +01:00
|
|
|
default:
|
2006-10-16 13:49:06 +02:00
|
|
|
ERR( "Unhandled method: 0x%08x\n", data->Method );
|
2006-01-26 13:23:08 +01:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TAPE_GetStatus( ioctl( fd, MTIOCTOP, &cmd ) );
|
|
|
|
#else
|
|
|
|
FIXME( "Not implemented.\n" );
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* TAPE_Erase
|
|
|
|
*/
|
2007-06-25 22:11:38 +02:00
|
|
|
static NTSTATUS TAPE_Erase( int fd, const TAPE_ERASE *data )
|
2006-01-26 13:23:08 +01:00
|
|
|
{
|
|
|
|
#ifdef HAVE_SYS_MTIO_H
|
|
|
|
struct mtop cmd;
|
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "fd: %d type: 0x%08x immediate: 0x%02x\n",
|
2006-01-26 13:23:08 +01:00
|
|
|
fd, data->Type, data->Immediate );
|
|
|
|
|
|
|
|
switch (data->Type)
|
|
|
|
{
|
|
|
|
case TAPE_ERASE_LONG:
|
|
|
|
cmd.mt_op = MTERASE;
|
|
|
|
cmd.mt_count = 1;
|
|
|
|
break;
|
|
|
|
case TAPE_ERASE_SHORT:
|
|
|
|
cmd.mt_op = MTERASE;
|
|
|
|
cmd.mt_count = 0;
|
|
|
|
break;
|
|
|
|
default:
|
2006-10-16 13:49:06 +02:00
|
|
|
ERR( "Unhandled type: 0x%08x\n", data->Type );
|
2006-01-26 13:23:08 +01:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TAPE_GetStatus( ioctl( fd, MTIOCTOP, &cmd ) );
|
|
|
|
#else
|
|
|
|
FIXME( "Not implemented.\n" );
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* TAPE_GetDriveParams
|
|
|
|
*/
|
|
|
|
static NTSTATUS TAPE_GetDriveParams( int fd, TAPE_GET_DRIVE_PARAMETERS *data )
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SYS_MTIO_H
|
|
|
|
struct mtget get;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE( "fd: %d\n", fd );
|
|
|
|
|
|
|
|
memset( data, 0, sizeof(TAPE_GET_DRIVE_PARAMETERS) );
|
|
|
|
|
|
|
|
status = TAPE_GetStatus( ioctl( fd, MTIOCGET, &get ) );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
data->ECC = FALSE;
|
|
|
|
data->Compression = FALSE;
|
|
|
|
data->DataPadding = FALSE;
|
|
|
|
data->ReportSetmarks = FALSE;
|
2006-02-05 13:51:03 +01:00
|
|
|
#ifdef HAVE_STRUCT_MTGET_MT_BLKSIZ
|
|
|
|
data->DefaultBlockSize = get.mt_blksiz;
|
|
|
|
#else
|
2006-01-26 13:23:08 +01:00
|
|
|
data->DefaultBlockSize = get.mt_dsreg & MT_ST_BLKSIZE_MASK;
|
2006-02-05 13:51:03 +01:00
|
|
|
#endif
|
2006-01-26 13:23:08 +01:00
|
|
|
data->MaximumBlockSize = data->DefaultBlockSize;
|
|
|
|
data->MinimumBlockSize = data->DefaultBlockSize;
|
|
|
|
data->MaximumPartitionCount = 1;
|
|
|
|
|
|
|
|
return status;
|
|
|
|
#else
|
|
|
|
FIXME( "Not implemented.\n" );
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* TAPE_GetMediaParams
|
|
|
|
*/
|
|
|
|
static NTSTATUS TAPE_GetMediaParams( int fd, TAPE_GET_MEDIA_PARAMETERS *data )
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SYS_MTIO_H
|
|
|
|
struct mtget get;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE( "fd: %d\n", fd );
|
|
|
|
|
|
|
|
memset( data, 0, sizeof(TAPE_GET_MEDIA_PARAMETERS) );
|
|
|
|
|
|
|
|
status = TAPE_GetStatus( ioctl( fd, MTIOCGET, &get ) );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
2012-10-30 11:43:05 +01:00
|
|
|
data->Capacity.QuadPart = 1024 * 1024 * 1024;
|
|
|
|
data->Remaining.QuadPart = 1024 * 1024 * 1024;
|
2006-02-05 13:51:03 +01:00
|
|
|
#ifdef HAVE_STRUCT_MTGET_MT_BLKSIZ
|
|
|
|
data->BlockSize = get.mt_blksiz;
|
|
|
|
#else
|
2006-01-26 13:23:08 +01:00
|
|
|
data->BlockSize = get.mt_dsreg & MT_ST_BLKSIZE_MASK;
|
2006-02-05 13:51:03 +01:00
|
|
|
#endif
|
2006-01-26 13:23:08 +01:00
|
|
|
data->PartitionCount = 1;
|
2006-02-07 21:18:19 +01:00
|
|
|
#ifdef HAVE_STRUCT_MTGET_MT_GSTAT
|
2006-11-18 11:09:36 +01:00
|
|
|
data->WriteProtected = (GMT_WR_PROT(get.mt_gstat) != 0);
|
2006-02-05 13:51:03 +01:00
|
|
|
#else
|
|
|
|
data->WriteProtected = 0;
|
|
|
|
#endif
|
2006-01-26 13:23:08 +01:00
|
|
|
|
|
|
|
return status;
|
|
|
|
#else
|
|
|
|
FIXME( "Not implemented.\n" );
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* TAPE_GetPosition
|
|
|
|
*/
|
|
|
|
static NTSTATUS TAPE_GetPosition( int fd, ULONG type, TAPE_GET_POSITION *data )
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SYS_MTIO_H
|
|
|
|
struct mtget get;
|
2006-02-06 20:59:44 +01:00
|
|
|
#ifndef HAVE_STRUCT_MTGET_MT_BLKNO
|
2006-01-26 13:23:08 +01:00
|
|
|
struct mtpos pos;
|
2006-02-06 20:59:44 +01:00
|
|
|
#endif
|
2006-01-26 13:23:08 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "fd: %d type: 0x%08x\n", fd, type );
|
2006-01-26 13:23:08 +01:00
|
|
|
|
|
|
|
memset( data, 0, sizeof(TAPE_GET_POSITION) );
|
|
|
|
|
|
|
|
status = TAPE_GetStatus( ioctl( fd, MTIOCGET, &get ) );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
2006-02-06 20:59:44 +01:00
|
|
|
#ifndef HAVE_STRUCT_MTGET_MT_BLKNO
|
2006-01-26 13:23:08 +01:00
|
|
|
status = TAPE_GetStatus( ioctl( fd, MTIOCPOS, &pos ) );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
return status;
|
2006-02-06 20:59:44 +01:00
|
|
|
#endif
|
2006-01-26 13:23:08 +01:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case TAPE_ABSOLUTE_BLOCK:
|
|
|
|
data->Type = type;
|
|
|
|
data->Partition = get.mt_resid;
|
2006-02-06 20:59:44 +01:00
|
|
|
#ifdef HAVE_STRUCT_MTGET_MT_BLKNO
|
|
|
|
data->OffsetLow = get.mt_blkno;
|
|
|
|
#else
|
2006-01-26 13:23:08 +01:00
|
|
|
data->OffsetLow = pos.mt_blkno;
|
2006-02-06 20:59:44 +01:00
|
|
|
#endif
|
2006-01-31 13:02:10 +01:00
|
|
|
break;
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_LOGICAL_BLOCK:
|
|
|
|
case TAPE_PSEUDO_LOGICAL_BLOCK:
|
|
|
|
WARN( "Positioning type not supported\n" );
|
|
|
|
break;
|
|
|
|
default:
|
2006-10-16 13:49:06 +02:00
|
|
|
ERR( "Unhandled type: 0x%08x\n", type );
|
2006-01-26 13:23:08 +01:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
#else
|
|
|
|
FIXME( "Not implemented.\n" );
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* TAPE_Prepare
|
|
|
|
*/
|
2007-06-25 22:11:38 +02:00
|
|
|
static NTSTATUS TAPE_Prepare( int fd, const TAPE_PREPARE *data )
|
2006-01-26 13:23:08 +01:00
|
|
|
{
|
|
|
|
#ifdef HAVE_SYS_MTIO_H
|
|
|
|
struct mtop cmd;
|
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "fd: %d type: 0x%08x immediate: 0x%02x\n",
|
2006-01-26 13:23:08 +01:00
|
|
|
fd, data->Operation, data->Immediate );
|
|
|
|
|
|
|
|
switch (data->Operation)
|
|
|
|
{
|
2006-01-31 13:02:10 +01:00
|
|
|
#ifdef MTLOAD
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_LOAD:
|
|
|
|
cmd.mt_op = MTLOAD;
|
|
|
|
break;
|
2006-01-31 13:02:10 +01:00
|
|
|
#endif
|
|
|
|
#ifdef MTUNLOAD
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_UNLOAD:
|
|
|
|
cmd.mt_op = MTUNLOAD;
|
|
|
|
break;
|
2006-01-31 13:02:10 +01:00
|
|
|
#endif
|
|
|
|
#ifdef MTRETEN
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_TENSION:
|
|
|
|
cmd.mt_op = MTRETEN;
|
|
|
|
break;
|
2006-01-31 13:02:10 +01:00
|
|
|
#endif
|
|
|
|
#ifdef MTLOCK
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_LOCK:
|
|
|
|
cmd.mt_op = MTLOCK;
|
|
|
|
break;
|
2006-01-31 13:02:10 +01:00
|
|
|
#endif
|
|
|
|
#ifdef MTUNLOCK
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_UNLOCK:
|
|
|
|
cmd.mt_op = MTUNLOCK;
|
|
|
|
break;
|
2006-01-31 13:02:10 +01:00
|
|
|
#endif
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_FORMAT:
|
|
|
|
/* Native ignores this if the drive doesn't support it */
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
default:
|
2006-10-16 13:49:06 +02:00
|
|
|
ERR( "Unhandled operation: 0x%08x\n", data->Operation );
|
2006-01-26 13:23:08 +01:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TAPE_GetStatus( ioctl( fd, MTIOCTOP, &cmd ) );
|
|
|
|
#else
|
|
|
|
FIXME( "Not implemented.\n" );
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* TAPE_SetDriveParams
|
|
|
|
*/
|
2007-06-25 22:11:38 +02:00
|
|
|
static NTSTATUS TAPE_SetDriveParams( int fd, const TAPE_SET_DRIVE_PARAMETERS *data )
|
2006-01-26 13:23:08 +01:00
|
|
|
{
|
2006-02-11 20:26:33 +01:00
|
|
|
#if defined(HAVE_SYS_MTIO_H) && defined(MTCOMPRESSION)
|
2006-01-26 13:23:08 +01:00
|
|
|
struct mtop cmd;
|
|
|
|
|
|
|
|
TRACE( "fd: %d ECC: 0x%02x, compression: 0x%02x padding: 0x%02x\n",
|
|
|
|
fd, data->ECC, data->Compression, data->DataPadding );
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "setmarks: 0x%02x zonesize: 0x%08x\n",
|
2006-01-26 13:23:08 +01:00
|
|
|
data->ReportSetmarks, data->EOTWarningZoneSize );
|
|
|
|
|
|
|
|
if (data->ECC || data->DataPadding || data->ReportSetmarks ||
|
|
|
|
data->EOTWarningZoneSize ) WARN( "Setting not supported\n" );
|
|
|
|
|
|
|
|
cmd.mt_op = MTCOMPRESSION;
|
|
|
|
cmd.mt_count = data->Compression;
|
|
|
|
|
|
|
|
return TAPE_GetStatus( ioctl( fd, MTIOCTOP, &cmd ) );
|
|
|
|
#else
|
|
|
|
FIXME( "Not implemented.\n" );
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* TAPE_SetMediaParams
|
|
|
|
*/
|
2007-06-25 22:11:38 +02:00
|
|
|
static NTSTATUS TAPE_SetMediaParams( int fd, const TAPE_SET_MEDIA_PARAMETERS *data )
|
2006-01-26 13:23:08 +01:00
|
|
|
{
|
|
|
|
#ifdef HAVE_SYS_MTIO_H
|
|
|
|
struct mtop cmd;
|
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "fd: %d blocksize: 0x%08x\n", fd, data->BlockSize );
|
2006-01-26 13:23:08 +01:00
|
|
|
|
|
|
|
cmd.mt_op = MTSETBLK;
|
|
|
|
cmd.mt_count = data->BlockSize;
|
|
|
|
|
|
|
|
return TAPE_GetStatus( ioctl( fd, MTIOCTOP, &cmd ) );
|
|
|
|
#else
|
|
|
|
FIXME( "Not implemented.\n" );
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* TAPE_SetPosition
|
|
|
|
*/
|
2007-06-25 22:11:38 +02:00
|
|
|
static NTSTATUS TAPE_SetPosition( int fd, const TAPE_SET_POSITION *data )
|
2006-01-26 13:23:08 +01:00
|
|
|
{
|
|
|
|
#ifdef HAVE_SYS_MTIO_H
|
|
|
|
struct mtop cmd;
|
|
|
|
|
2017-08-25 10:24:48 +02:00
|
|
|
TRACE( "fd: %d method: 0x%08x partition: 0x%08x offset: 0x%s immediate: 0x%02x\n",
|
|
|
|
fd, data->Method, data->Partition, wine_dbgstr_longlong(data->Offset.QuadPart),
|
|
|
|
data->Immediate );
|
2006-01-26 13:23:08 +01:00
|
|
|
|
2007-11-02 10:34:11 +01:00
|
|
|
if (sizeof(cmd.mt_count) < sizeof(data->Offset.QuadPart) &&
|
|
|
|
(int)data->Offset.QuadPart != data->Offset.QuadPart)
|
|
|
|
{
|
|
|
|
ERR("Offset too large or too small\n");
|
2006-01-26 13:23:08 +01:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2007-11-02 10:34:11 +01:00
|
|
|
}
|
2006-01-26 13:23:08 +01:00
|
|
|
|
|
|
|
switch (data->Method)
|
|
|
|
{
|
|
|
|
case TAPE_REWIND:
|
|
|
|
cmd.mt_op = MTREW;
|
|
|
|
break;
|
2006-01-31 13:02:10 +01:00
|
|
|
#ifdef MTSEEK
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_ABSOLUTE_BLOCK:
|
|
|
|
cmd.mt_op = MTSEEK;
|
2007-11-02 10:34:11 +01:00
|
|
|
cmd.mt_count = data->Offset.QuadPart;
|
2006-01-26 13:23:08 +01:00
|
|
|
break;
|
2006-01-31 13:02:10 +01:00
|
|
|
#endif
|
|
|
|
#ifdef MTEOM
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_SPACE_END_OF_DATA:
|
|
|
|
cmd.mt_op = MTEOM;
|
|
|
|
break;
|
2006-01-31 13:02:10 +01:00
|
|
|
#endif
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_SPACE_FILEMARKS:
|
2007-11-02 10:34:11 +01:00
|
|
|
if (data->Offset.QuadPart >= 0) {
|
2006-01-26 13:23:08 +01:00
|
|
|
cmd.mt_op = MTFSF;
|
2007-11-02 10:34:11 +01:00
|
|
|
cmd.mt_count = data->Offset.QuadPart;
|
2006-01-26 13:23:08 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
cmd.mt_op = MTBSF;
|
2007-11-02 10:34:11 +01:00
|
|
|
cmd.mt_count = -data->Offset.QuadPart;
|
2006-01-26 13:23:08 +01:00
|
|
|
}
|
2006-01-31 13:02:10 +01:00
|
|
|
break;
|
2006-02-11 20:26:33 +01:00
|
|
|
#if defined(MTFSS) && defined(MTBSS)
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_SPACE_SETMARKS:
|
2007-11-02 10:34:11 +01:00
|
|
|
if (data->Offset.QuadPart >= 0) {
|
2006-01-26 13:23:08 +01:00
|
|
|
cmd.mt_op = MTFSS;
|
2007-11-02 10:34:11 +01:00
|
|
|
cmd.mt_count = data->Offset.QuadPart;
|
2006-01-26 13:23:08 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
cmd.mt_op = MTBSS;
|
2007-11-02 10:34:11 +01:00
|
|
|
cmd.mt_count = -data->Offset.QuadPart;
|
2006-01-26 13:23:08 +01:00
|
|
|
}
|
2006-01-31 13:02:10 +01:00
|
|
|
break;
|
2006-02-11 20:26:33 +01:00
|
|
|
#endif
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_LOGICAL_BLOCK:
|
|
|
|
case TAPE_PSEUDO_LOGICAL_BLOCK:
|
|
|
|
case TAPE_SPACE_RELATIVE_BLOCKS:
|
|
|
|
case TAPE_SPACE_SEQUENTIAL_FMKS:
|
|
|
|
case TAPE_SPACE_SEQUENTIAL_SMKS:
|
|
|
|
WARN( "Positioning method not supported\n" );
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
default:
|
2006-10-16 13:49:06 +02:00
|
|
|
ERR( "Unhandled method: 0x%08x\n", data->Method );
|
2006-01-26 13:23:08 +01:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TAPE_GetStatus( ioctl( fd, MTIOCTOP, &cmd ) );
|
|
|
|
#else
|
|
|
|
FIXME( "Not implemented.\n" );
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* TAPE_WriteMarks
|
|
|
|
*/
|
2007-06-25 22:11:38 +02:00
|
|
|
static NTSTATUS TAPE_WriteMarks( int fd, const TAPE_WRITE_MARKS *data )
|
2006-01-26 13:23:08 +01:00
|
|
|
{
|
|
|
|
#ifdef HAVE_SYS_MTIO_H
|
|
|
|
struct mtop cmd;
|
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "fd: %d type: 0x%08x count: 0x%08x immediate: 0x%02x\n",
|
2006-01-26 13:23:08 +01:00
|
|
|
fd, data->Type, data->Count, data->Immediate );
|
|
|
|
|
|
|
|
switch (data->Type)
|
|
|
|
{
|
2006-01-31 13:02:10 +01:00
|
|
|
#ifdef MTWSM
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_SETMARKS:
|
|
|
|
cmd.mt_op = MTWSM;
|
|
|
|
cmd.mt_count = data->Count;
|
|
|
|
break;
|
2006-01-31 13:02:10 +01:00
|
|
|
#endif
|
2006-01-26 13:23:08 +01:00
|
|
|
case TAPE_FILEMARKS:
|
|
|
|
case TAPE_SHORT_FILEMARKS:
|
|
|
|
case TAPE_LONG_FILEMARKS:
|
|
|
|
cmd.mt_op = MTWEOF;
|
|
|
|
cmd.mt_count = data->Count;
|
|
|
|
break;
|
|
|
|
default:
|
2006-10-16 13:49:06 +02:00
|
|
|
ERR( "Unhandled type: 0x%08x\n", data->Type );
|
2006-01-26 13:23:08 +01:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TAPE_GetStatus( ioctl( fd, MTIOCTOP, &cmd ) );
|
|
|
|
#else
|
|
|
|
FIXME( "Not implemented.\n" );
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* TAPE_DeviceIoControl
|
|
|
|
*
|
|
|
|
* SEE ALSO
|
|
|
|
* NtDeviceIoControl.
|
|
|
|
*/
|
|
|
|
NTSTATUS TAPE_DeviceIoControl( HANDLE device, HANDLE event,
|
|
|
|
PIO_APC_ROUTINE apc, PVOID apc_user, PIO_STATUS_BLOCK io_status,
|
|
|
|
ULONG io_control, LPVOID in_buffer, DWORD in_size,
|
|
|
|
LPVOID out_buffer, DWORD out_size )
|
|
|
|
{
|
|
|
|
DWORD sz = 0;
|
|
|
|
NTSTATUS status = STATUS_INVALID_PARAMETER;
|
2006-11-03 11:38:44 +01:00
|
|
|
int fd, needs_close;
|
2006-01-26 13:23:08 +01:00
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "%p %s %p %d %p %d %p\n", device, io2str(io_control),
|
2006-01-26 13:23:08 +01:00
|
|
|
in_buffer, in_size, out_buffer, out_size, io_status );
|
|
|
|
|
|
|
|
io_status->Information = 0;
|
|
|
|
|
2006-11-20 14:15:06 +01:00
|
|
|
if ((status = server_get_unix_fd( device, 0, &fd, &needs_close, NULL, NULL )))
|
2006-01-26 13:23:08 +01:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
switch (io_control)
|
|
|
|
{
|
|
|
|
case IOCTL_TAPE_CREATE_PARTITION:
|
2009-03-17 00:12:11 +01:00
|
|
|
status = TAPE_CreatePartition( fd, in_buffer );
|
2006-01-26 13:23:08 +01:00
|
|
|
break;
|
|
|
|
case IOCTL_TAPE_ERASE:
|
2009-03-17 00:12:11 +01:00
|
|
|
status = TAPE_Erase( fd, in_buffer );
|
2006-01-26 13:23:08 +01:00
|
|
|
break;
|
|
|
|
case IOCTL_TAPE_GET_DRIVE_PARAMS:
|
2009-03-17 00:12:11 +01:00
|
|
|
status = TAPE_GetDriveParams( fd, out_buffer );
|
2006-01-26 13:23:08 +01:00
|
|
|
break;
|
|
|
|
case IOCTL_TAPE_GET_MEDIA_PARAMS:
|
2009-03-17 00:12:11 +01:00
|
|
|
status = TAPE_GetMediaParams( fd, out_buffer );
|
2006-01-26 13:23:08 +01:00
|
|
|
break;
|
2006-01-30 14:55:47 +01:00
|
|
|
case IOCTL_TAPE_GET_POSITION:
|
2006-01-26 13:23:08 +01:00
|
|
|
status = TAPE_GetPosition( fd, ((TAPE_GET_POSITION *)in_buffer)->Type,
|
2009-03-17 00:12:11 +01:00
|
|
|
out_buffer );
|
2006-01-26 13:23:08 +01:00
|
|
|
break;
|
|
|
|
case IOCTL_TAPE_GET_STATUS:
|
|
|
|
status = FILE_GetNtStatus();
|
|
|
|
break;
|
|
|
|
case IOCTL_TAPE_PREPARE:
|
2009-03-17 00:12:11 +01:00
|
|
|
status = TAPE_Prepare( fd, in_buffer );
|
2006-01-26 13:23:08 +01:00
|
|
|
break;
|
|
|
|
case IOCTL_TAPE_SET_DRIVE_PARAMS:
|
2009-03-17 00:12:11 +01:00
|
|
|
status = TAPE_SetDriveParams( fd, in_buffer );
|
2006-01-26 13:23:08 +01:00
|
|
|
break;
|
|
|
|
case IOCTL_TAPE_SET_MEDIA_PARAMS:
|
2009-03-17 00:12:11 +01:00
|
|
|
status = TAPE_SetMediaParams( fd, in_buffer );
|
2006-01-26 13:23:08 +01:00
|
|
|
break;
|
2006-01-30 14:55:47 +01:00
|
|
|
case IOCTL_TAPE_SET_POSITION:
|
2009-03-17 00:12:11 +01:00
|
|
|
status = TAPE_SetPosition( fd, in_buffer );
|
2006-01-26 13:23:08 +01:00
|
|
|
break;
|
|
|
|
case IOCTL_TAPE_WRITE_MARKS:
|
2009-03-17 00:12:11 +01:00
|
|
|
status = TAPE_WriteMarks( fd, in_buffer );
|
2006-01-26 13:23:08 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IOCTL_TAPE_CHECK_VERIFY:
|
|
|
|
case IOCTL_TAPE_FIND_NEW_DEVICES:
|
|
|
|
break;
|
|
|
|
default:
|
2006-10-16 13:49:06 +02:00
|
|
|
FIXME( "Unsupported IOCTL %x (type=%x access=%x func=%x meth=%x)\n",
|
2006-01-26 13:23:08 +01:00
|
|
|
io_control, io_control >> 16, (io_control >> 14) & 3,
|
|
|
|
(io_control >> 2) & 0xfff, io_control & 3 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-11-03 11:38:44 +01:00
|
|
|
if (needs_close) close( fd );
|
2006-01-26 13:23:08 +01:00
|
|
|
|
|
|
|
error:
|
|
|
|
io_status->u.Status = status;
|
|
|
|
io_status->Information = sz;
|
|
|
|
if (event) NtSetEvent( event, NULL );
|
|
|
|
return status;
|
|
|
|
}
|