Significant upgrades to sa(4) and mt(1).

The primary focus of these changes is to modernize FreeBSD's
tape infrastructure so that we can take advantage of some of the
features of modern tape drives and allow support for LTFS.

Significant changes and new features include:

 o sa(4) driver status and parameter information is now exported via an
   XML structure.  This will allow for changes and improvements later
   on that will not break userland applications.  The old MTIOCGET
   status ioctl remains, so applications using the existing interface
   will not break.

 o 'mt status' now reports drive-reported tape position information
   as well as the previously available calculated tape position
   information.  These numbers will be different at times, because
   the drive-reported block numbers are relative to BOP (Beginning
   of Partition), but the block numbers calculated previously via
   sa(4) (and still provided) are relative to the last filemark.
   Both numbers are now provided.  'mt status' now also shows the
   drive INQUIRY information, serial number and any position flags
   (BOP, EOT, etc.) provided with the tape position information.
   'mt status -v' adds information on the maximum possible I/O size,
   and the underlying values used to calculate it.

 o The extra sa(4) /dev entries (/dev/saN.[0-3]) have been removed.

   The extra devices were originally added as place holders for
   density-specific device nodes.  Some OSes (NetBSD, NetApp's OnTap
   and Solaris) have had device nodes that, when you write to them,
   will automatically select a given density for particular tape drives.

   This is a convenient way of switching densities, but it was never
   implemented in FreeBSD.  Only the device nodes were there, and that
   sometimes confused users.

   For modern tape devices, the density is generally not selectable
   (e.g. with LTO) or defaults to the highest availble density when
   the tape is rewritten from BOT (e.g. TS11X0).  So, for most users,
   density selection won't be necessary.  If they do need to select
   the density, it is easy enough to use 'mt density' to change it.

 o Protection information is now supported.  This is either a
   Reed-Solomon CRC or CRC32 that is included at the end of each block
   read and written.  On write, the tape drive verifies the CRC, and
   on read, the tape drive provides a CRC for the userland application
   to verify.

 o New, extensible tape driver parameter get/set interface.

 o Density reporting information.  For drives that support it,
   'mt getdensity' will show detailed information on what formats the
   tape drive supports, and what formats the tape drive supports.

 o Some mt(1) functionality moved into a new mt(3) library so that
   external applications can reuse the code.

 o The new mt(3) library includes helper routines to aid in parsing
   the XML output of the sa(4) driver, and build a tree of driver
   metadata.

 o Support for the MTLOAD (load a tape in the drive) and MTWEOFI
   (write filemark immediate) ioctls needed by IBM's LTFS
   implementation.

 o Improve device departure behavior for the sa(4) driver.  The previous
   implementation led to hangs when the device was open.

 o This has been tested on the following types of drives:
	IBM TS1150
	IBM TS1140
	IBM LTO-6
	IBM LTO-5
	HP LTO-2
	Seagate DDS-4
	Quantum DLT-4000
	Exabyte 8505
	Sony DDS-2

contrib/groff/tmac/doc-syms,
share/mk/bsd.libnames.mk,
lib/Makefile,
	Add libmt.

lib/libmt/Makefile,
lib/libmt/mt.3,
lib/libmt/mtlib.c,
lib/libmt/mtlib.h,
	New mt(3) library that contains functions moved from mt(1) and
	new functions needed to interact with the updated sa(4) driver.

	This includes XML parser helper functions that application writers
	can use when writing code to query tape parameters.

rescue/rescue/Makefile:
	Add -lmt to CRUNCH_LIBS.

src/share/man/man4/mtio.4
	Clarify this man page a bit, and since it contains what is
	essentially the mtio.h header file, add new ioctls and structure
	definitions from mtio.h.

src/share/man/man4/sa.4
	Update BUGS and maintainer section.

sys/cam/scsi/scsi_all.c,
sys/cam/scsi/scsi_all.h:
	Add SCSI SECURITY PROTOCOL IN/OUT CDB definitions and CDB building
	functions.

sys/cam/scsi/scsi_sa.c
sys/cam/scsi/scsi_sa.h
	Many tape driver changes, largely outlined above.

	Increase the sa(4) driver read/write timeout from 4 to 32
	minutes.  This is based on the recommended values for IBM LTO
	5/6 drives.  This may also avoid timeouts for other tape
	hardware that can take a long time to do retries and error
	recovery.  Longer term, a better way to handle this is to ask
	the drive for recommended timeout values using the REPORT
	SUPPORTED OPCODES command.  Modern IBM and Oracle tape drives
	at least support that command, and it would allow for more
	accurate timeout values.

	Add XML status generation.  This is done with a series of
	macros to eliminate as much duplicate code as possible.  The
	new XML-based status values are reported through the new
	MTIOCEXTGET ioctl.

	Add XML driver parameter reporting, using the new MTIOCPARAMGET
	ioctl.

	Add a new driver parameter setting interface, using the new
	MTIOCPARAMSET and MTIOCSETLIST ioctls.

	Add a new MTIOCRBLIM ioctl to get block limits information.

	Add CCB/CDB building routines scsi_locate_16, scsi_locate_10,
	and scsi_read_position_10().

	scsi_locate_10 implements the LOCATE command, as does the
	existing scsi_set_position() command.  It just supports
	additional arguments and features.  If/when we figure out a
	good way to provide backward compatibility for older
	applications using the old function API, we can just revamp
	scsi_set_position().  The same goes for
	scsi_read_position_10() and the existing scsi_read_position()
	function.

	Revamp sasetpos() to take the new mtlocate structure as an
	argument.  It now will use either scsi_locate_10() or
	scsi_locate_16(), depending upon the arguments the user
	supplies.  As before, once we change position we don't have a
	clear idea of what the current logical position of the tape
	drive is.

	For tape drives that support long form position data, we
	read the current position and store that for later reporting
	after changing the position.  This should help applications
	like Bacula speed tape access under FreeBSD once they are
	modified to support the new ioctls.

	Add a new quirk, SA_QUIRK_NO_LONG_POS, that is set for all
	drives that report SCSI-2 or older, as well as drives that
	report an Illegal Request type error for READ POSITION with
	the long format.  So we should automatically detect drives
	that don't support the long form and stop asking for it after
	an initial try.

	Add a partition number to the sa(4) softc.

	Improve device departure handling. The previous implementation
	led to hangs when the device was open.

	If an application had the sa(4) driver open, and attempted to
	close it after it went away, the cam_periph_release() call in
	saclose() would cause the periph to get destroyed because that
	was the last reference to it.  Because destroy_dev() was
	called from the sa(4) driver's cleanup routine (sacleanup()),
	and would block waiting for the close to happen, a deadlock
	would result.

	So instead of calling destroy_dev() from the cleanup routine,
	call destroy_dev_sched_cb() from saoninvalidate() and wait for
	the callback.

	Acquire a reference for devfs in saregister(), and release it
	in the new sadevgonecb() routine when all devfs devices for
	the particular sa(4) driver instance are gone.

	Add a new function, sasetupdev(), to centralize setting
	per-instance devfs device parameters instead of repeating the
	code in saregister().

	Add an open count to the softc, so we know how many
	peripheral driver references are a result of open
       	sessions.

	Add the D_TRACKCLOSE flag to the cdevsw flags so
	that we get a 1:1 mapping of open to close calls
	instead of a N:1 mapping.

	This should be a no-op for everything except the
	control device, since we don't allow more than one
	open on non-control devices.

	However, since we do allow multiple opens on the
	control device, the combination of the open count
	and the D_TRACKCLOSE flag should result in an
	accurate peripheral driver reference count, and an
	accurate open count.

	The accurate open count allows us to release all
	peripheral driver references that are the result
	of open contexts once we get the callback from devfs.

sys/sys/mtio.h:
	Add a number of new mt(4) ioctls and the requisite data
	structures.  None of the existing interfaces been removed
	or changed.

	This includes definitions for the following new ioctls:

	MTIOCRBLIM      /* get block limits */
	MTIOCEXTLOCATE	/* seek to position */
	MTIOCEXTGET     /* get tape status */
	MTIOCPARAMGET	/* get tape params */
	MTIOCPARAMSET	/* set tape params */
	MTIOCSETLIST	/* set N params */

usr.bin/mt/Makefile:
	mt(1) now depends on libmt, libsbuf and libbsdxml.

usr.bin/mt/mt.1:
	Document new mt(1) features and subcommands.

usr.bin/mt/mt.c:
	Implement support for mt(1) subcommands that need to
	use getopt(3) for their arguments.

	Implement a new 'mt status' command to replace the old
	'mt status' command.  The old status command has been
	renamed 'ostatus'.

	The new status function uses the MTIOCEXTGET ioctl, and
	therefore parses the XML data to determine drive status.
	The -x argument to 'mt status' allows the user to dump out
	the raw XML reported by the kernel.

	The new status display is mostly the same as the old status
	display, except that it doesn't print the redundant density
	mode information, and it does print the current partition
	number and position flags.

	Add a new command, 'mt locate', that will supersede the
	old 'mt setspos' and 'mt sethpos' commands.  'mt locate'
	implements all of the functionality of the MTIOCEXTLOCATE
	ioctl, and allows the user to change the logical position
	of the tape drive in a number of ways.  (Partition,
	block number, file number, set mark number, end of data.)
	The immediate bit and the explicit address bits are
	implemented, but not documented in the man page.

	Add a new 'mt weofi' command to use the new MTWEOFI ioctl.
	This allows the user to ask the drive to write a filemark
	without waiting around for the operation to complete.

	Add a new 'mt getdensity' command that gets the XML-based
	tape drive density report from the sa(4) driver and displays
	it.  This uses the SCSI REPORT DENSITY SUPPORT command
	to get comprehensive information from the tape drive about
	what formats it is able to read and write.

	Add a new 'mt protect' command that allows getting and setting
	tape drive protection information.  The protection information
	is a CRC tacked on to the end of every read/write from and to
	the tape drive.

Sponsored by:	Spectra Logic
MFC after:	1 month
This commit is contained in:
Kenneth D. Merry 2015-02-23 21:59:30 +00:00
parent 09ae596bf6
commit 43518607b2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=279219
18 changed files with 6053 additions and 390 deletions

View file

@ -796,6 +796,7 @@
.ds doc-str-Lb-libmd Message Digest (MD4, MD5, etc.) Support Library (libmd, \-lmd)
.ds doc-str-Lb-libmemstat Kernel Memory Allocator Statistics Library (libmemstat, \-lmemstat)
.ds doc-str-Lb-libmenu Curses Menu Library (libmenu, \-lmenu)
.ds doc-str-Lb-libmt Magnetic Tape Library (libmt, \-lmt)
.ds doc-str-Lb-libnetgraph Netgraph User Library (libnetgraph, \-lnetgraph)
.ds doc-str-Lb-libnetpgp Netpgp signing, verification, encryption and decryption (libnetpgp, \-lnetpgp)
.ds doc-str-Lb-libossaudio OSS Audio Emulation Library (libossaudio, \-lossaudio)

View file

@ -70,6 +70,7 @@ SUBDIR= ${SUBDIR_ORDERED} \
libmd \
${_libmilter} \
${_libmp} \
libmt \
${_libnandfs} \
libnetbsd \
${_libnetgraph} \

13
lib/libmt/Makefile Normal file
View file

@ -0,0 +1,13 @@
# $FreeBSD$
LIB= mt
SHLIBDIR?= /lib
SRCS= mtlib.c
INCS= mtlib.h
DPADD= ${LIBSBUF}
LDADD= -lsbuf
MAN= mt.3
.include <bsd.lib.mk>

455
lib/libmt/mt.3 Normal file
View file

@ -0,0 +1,455 @@
.\"
.\" Copyright (c) 2013, 2015 Spectra Logic Corporation
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions, and the following disclaimer,
.\" without modification.
.\" 2. Redistributions in binary form must reproduce at minimum a disclaimer
.\" substantially similar to the "NO WARRANTY" disclaimer below
.\" ("Disclaimer") and any redistribution must be conditioned upon
.\" including a substantially similar Disclaimer requirement for further
.\" binary redistribution.
.\"
.\" NO WARRANTY
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
.\" HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGES.
.\"
.\" Authors: Ken Merry (Spectra Logic Corporation)
.\"
.\" $FreeBSD$
.\"
.Dd February 13, 2015
.Dt MT 3
.Os
.Sh NAME
.Nm
.Nm mt_start_element ,
.Nm mt_end_element ,
.Nm mt_char_handler ,
.Nm mt_status_tree_sbuf ,
.Nm mt_status_tree_print ,
.Nm mt_status_entry_free ,
.Nm mt_status_free ,
.Nm mt_entry_sbuf ,
.Nm mt_param_parent_print ,
.Nm mt_param_entry_print ,
.Nm mt_protect_print ,
.Nm mt_param_list ,
.Nm mt_density_name ,
.Nm mt_density_bp ,
.Nm mt_density_num ,
.Nm mt_get_xml_str ,
.Nm mt_get_status
.Nd Magnetic Tape library
.Sh LIBRARY
.Lb libmt
.Sh SYNOPSIS
.In sys/sbuf.h
.In bsdxml.h
.In mtlib.h
.Ft void
.Fo mt_start_element
.Fa "void *user_data"
.Fa "const char *name"
.Fa "const char **attr"
.Fc
.Ft void
.Fo mt_end_element
.Fa "void *user_data"
.Fa "const char *name"
.Fc
.Ft void
.Fo mt_char_handler
.Fa "void *user_data"
.Fa "const XML_Char *str"
.Fa "int len"
.Fc
.Ft void
.Fo mt_status_tree_sbuf
.Fa "struct sbuf *sb"
.Fa "struct mt_status_entry *entry"
.Fa "int indent"
.Fa "void (*sbuf_func)(struct sbuf *sb, struct mt_status_entry *entry, void *arg)"
.Fa "void *arg"
.Fc
.Ft void
.Fo mt_status_tree_print
.Fa "struct mt_status_entry *entry"
.Fa "int indent"
.Fa "void (*print_func)(struct mt_status_entry *entry, void *arg)"
.Fa "void *arg"
.Fc
.Ft "struct mt_status_entry *"
.Fo mt_entry_find
.Fa "struct mt_status_entry *entry"
.Fa "char *name"
.Fc
.Ft "struct mt_status_entry *"
.Fo mt_status_entry_find
.Fa "struct mt_status_data *status_data"
.Fa "char *name"
.Fc
.Ft void
.Fo mt_status_entry_free
.Fa "struct mt_status_entry *entry)"
.Fc
.Ft void
.Fo mt_status_free
.Fa "struct mt_status_data *status_data"
.Fc
.Ft void
.Fo mt_entry_sbuf
.Fa "struct sbuf *sb"
.Fa "struct mt_status_entry *entry"
.Fa "char *fmt"
.Fc
.Ft void
.Fo mt_param_parent_sbuf
.Fa "struct sbuf *sb"
.Fa "struct mt_status_entry *entry"
.Fa "struct mt_print_params *print_params"
.Fc
.Ft void
.Fo mt_param_parent_print
.Fa "struct mt_status_entry *entry"
.Fa "struct mt_print_params *print_params"
.Fc
.Ft void
.Fo mt_param_entry_sbuf
.Fa "struct sbuf *sb"
.Fa "struct mt_status_entry *entry"
.Fa "void *arg"
.Fc
.Ft void
.Fo mt_param_entry_print
.Fa "struct mt_status_entry *entry"
.Fa "void *arg"
.Fc
.Ft int
.Fo mt_protect_print
.Fa "struct mt_status_data *status_data"
.Fa "int verbose"
.Fc
.Ft int
.Fo mt_param_list
.Fa "struct mt_status_data *status_data"
.Fa "char *param_name"
.Fa "int quiet"
.Fc
.Ft "const char *"
.Fo mt_density_name
.Fa "int density_num"
.Fc
.Ft int
.Fo mt_density_bp
.Fa "int density_num"
.Fa "int bpi"
.Fc
.Ft int
.Fo mt_density_num
.Fa "const char *density_name"
.Fc
.Ft int
.Fo mt_get_status
.Fa "char *xml_str"
.Fa "struct mt_status_data *status_data"
.Fc
.Sh DESCRIPTION
The MT library consists of a number of functions designed to aid in
interacting with the
.Xr sa 4
driver.
The
.Xr sa 4
driver returns some status data as XML-formatted strings, and
the primary purpose of this library is to make it easier for the
software developer to parse those strings and extract the status values.
.Pp
The
.Fn mt_start_element ,
.Fn mt_end_element ,
and
.Fn mt_char_handler
functions are designed to work with the
.Xr libbbsdxml 3
library, which is an XML parsing library.
The user data for the XML parser should be set with
.Fn XML_SetUserData
to a zeroed struct
mt_status_data with the entries list initialized.
The element handlers for the XML parser should be set to
.Fn mt_start_element
and
.Fn mt_end_element
with
.Fn XML_SetElementHandler .
The character data handler should be set to
.Fn mt_char_handler
with the
.Fn XML_SetCharacterDataHandler
function.
The error member of the status_data structure will be set to 0 if parsing
is successful, and non-zero if parsing failed.
In the event of a failure, the error_str member will contain an error
message describing the failure.
These functions will build a tree of tape driver status data that can be
searched and printed using the other functions in this library.
.Pp
.Fn mt_status_tree_sbuf
takes the root node of a tree of
.Xr sa 4
driver status information, and displays it in an
.Xr sbuf 9 .
The
.Ar sb
argument is the destination sbuf.
The
.Ar entry
argument is the root of the tree.
The
.Ar indent
argument is the number of characters to indent the output.
Each recursive call to
.Fn mt_status_tree_sbuf
will have the indent level incremented by 2.
The
.Ar sbuf_func
argument is for a user-supplied alternate printing function.
If it is non-NULL, it will be called instead of the default output printing
code.
The
.Ar arg
argument is an argument for the
.Ar sbuf_func
function.
.Pp
The
.Fn mt_status_tree_print
function is the same as the
.Fn mt_status_tree_sbuf
function, except that the tree is printed to standard out instead of to a
sbuf.
.Pp
The
.Fn mt_entry_find
function returns the first entry in the tree starting at
.Ar entry
that matches
.Ar name .
The supplied node name can be a single level name like "foo", or it can
specify mulitple node names that must be matched, for instance "foo.bar.baz".
In the case of a single level name, it will match any node beneath
.Ar entry
that matches
.Ar name .
In the case of a multi-level name like "foo.bar.baz", it will return the
first entry named "baz" whose immediate parent is "bar" and where the
parent of "bar" is named "foo".
.Pp
The
.Fn mt_status_entry_find
is the same as
.Fn mt_entry_find ,
except that it operates on the top level mt_status_data and all
mt_status_entry nodes below it instead of just an mt_status_entry
structure.
.Pp
The
.Fn mt_status_entry_free
function frees the tree of status data underneath
.Ar entry .
.Pp
The
.Fn mt_status_free
function frees the tree of status data underneath
.Ar status_data .
.Pp
The
.Fn mt_entry_sbuf
function prints
.Ar entry
to the supplied sbuf
.Ar sb ,
optionally using the
.Xr printf 3
format
.Ar fmt .
If
.Ar fmt
is NULL, then
.Fn mt_entry_sbuf
will render integer types in base 10 without special formatting and all
other types as they were rendered in the XML.
.Pp
.Fn mt_param_parent_sbuf
prints the parents of the given
.Ar entry
to the supplied sbuf
.Ar sb
subject to the print parameters
.Ar print_params .
The result will be formatted with a period between each level, like
"foo.bar.baz".
.Pp
.Fn mt_param_parent_print
is like
.Fn mt_param_parent_sbuf
except that it prints the results to standard output instead of an sbuf.
.Pp
.Fn mt_param_entry_sbuf
prints the
.Ar entry
to the given sbuf
.Ar sb .
The argument
.Ar arg
is a pointer to struct mt_print_params, which allows the caller to control
the printing output.
This function is intended to be supplied as an argument to
.Fn mt_status_tree_sbuf .
.Pp
.Fn mt_param_entry_print
is like
.Fn mt_param_entry_sbuf
except that it prints to standard output instead of an sbuf.
It is intended to be used as an argument to
.Fn mt_status_tree_print .
.Pp
.Fn mt_protect_print
prints tape drive protection information from the supplied
.Ar status_data
beginning at the node name defined as the root node for protection data.
If the
.Ar verbose
argument is non-zero, protection entry descriptions will be printed.
If it is zero, protection entry descriptions will not be printed.
.Pp
.Fn mt_param_list
prints tape driver parameters information from the supplied
.Ar status_data .
If the
.Ar param_name
is non-NULL, only the named parameter will be printed.
If
.Ar quiet
is non-zero, parameter descriptions will be omitted in the output.
.Pp
.Fn mt_density_name
Returns a text identifier for the supplied numeric
.Ar density_num .
The
.Ar density_num
should currently be a value between 0 and 255 inclusive, since that is the
valid range for
.Tn SCSI
density code values.
See below for notes on the return values.
.Pp
.Fn mt_density_bp
Returns the bits per inch or bits per mm values for a given density entry
specified by the
.Ar density_num .
If the
.Ar bpi
argument is non-zero, the bits per inch value is returned.
Otherwise, the bits per mm value is returned.
.Pp
.Fn mt_density_num
returns a numeric value for a text density description.
It does a case-insensitive comparison of density names in the density table
to the supplied density name.
.Pp
.Fn mt_get_xml_str
gets the current XML status / parameter string from the sa(4) driver
instance referenced by the open file descriptor
.Ar mtfd .
The
.Xr mtio 4
.Xr ioctl 2
to be used is supplied as the
.Ar cmd
argument.
Currently the
.Fn mt_get_xml_str
function will work with the
.Dv MTIOCEXTGET
and
.Dv MTIOCPARAMGET
ioctls.
The supplied
.Ar xml_str
will be filled in with a pointer to the complete XML status string.
Multiple calls to the given
.Xr ioctl 2
are made and more space is malloced until all of the XML string is fetched.
The string returned in the
.Ar xml_str
argument should be freed when it is no longer in use.
.Sh RETURN VALUES
.Fn mt_entry_find
returns the first matching entry, or NULL if it fails to find a match.
.Pp
.Fn mt_status_entry_find
returns the first matching entry, or NULL if it fails to find a match.
.Pp
.Fn mt_protect_print
Returns 0 for success, and non-zero for failure.
.Fn mt_protect_print
can only fail if it cannot find protection information in the supplied
status data.
.Pp
.Fn mt_param_list
Returns 0 for success and non-zero for failure.
.Fn mt_param_list
can only fail if it cannot find parameter information in the supplied
status data.
.Pp
.Fn mt_density_name
returns a text description of a numeric density.
The special density value 0 is decoded as "default".
The special density value 0x7f is decoded as "same".
If the density is not known,
.Fn mt_density_name
will return "UNKNOWN".
.Pp
.Fn mt_density_bp
returns the bits per inch value for the given density (if the
.Ar bpi
field is non-zero), the bits per mm value otherwise, or 0 if the supplied
.Ar density_num
is not in the density table or the table entry does not include bpi / bpmm
values.
.Pp
.Fn mt_density_num
returns a numeric density value between 0 and 255 for the supplied density
name.
It returns 0 if the density name is not recognized.
.Pp
.Fn mt_get_xml_str
returns 0 for success, and -1 for failure.
.Sh SEE ALSO
.Xr mt 1 ,
.Xr mtio 4 ,
.Xr sa 4
.Sh HISTORY
The MT library first appeared in
.Fx 10.1 .
.Sh AUTHORS
.An Ken Merry Aq ken@FreeBSD.org
.Sh BUGS
The library interface is not complete, and may change in the future.
Application authors should not rely on the library interface to be
consistent in the immediate future.

756
lib/libmt/mtlib.c Normal file
View file

@ -0,0 +1,756 @@
/*-
* Copyright (c) 2013, 2014, 2015 Spectra Logic Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* Authors: Ken Merry (Spectra Logic Corporation)
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/mtio.h>
#include <sys/queue.h>
#include <sys/sbuf.h>
#include <ctype.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <errno.h>
#include <bsdxml.h>
#include <mtlib.h>
/*
* Called at the start of each XML element, and includes the list of
* attributes for the element.
*/
void
mt_start_element(void *user_data, const char *name, const char **attr)
{
int i;
struct mt_status_data *mtinfo;
struct mt_status_entry *entry;
mtinfo = (struct mt_status_data *)user_data;
if (mtinfo->error != 0)
return;
mtinfo->level++;
if ((u_int)mtinfo->level > (sizeof(mtinfo->cur_sb) /
sizeof(mtinfo->cur_sb[0]))) {
mtinfo->error = 1;
snprintf(mtinfo->error_str, sizeof(mtinfo->error_str),
"%s: too many nesting levels, %zd max", __func__,
sizeof(mtinfo->cur_sb) / sizeof(mtinfo->cur_sb[0]));
return;
}
mtinfo->cur_sb[mtinfo->level] = sbuf_new_auto();
if (mtinfo->cur_sb[mtinfo->level] == NULL) {
mtinfo->error = 1;
snprintf(mtinfo->error_str, sizeof(mtinfo->error_str),
"%s: Unable to allocate sbuf", __func__);
return;
}
entry = malloc(sizeof(*entry));
if (entry == NULL) {
mtinfo->error = 1;
snprintf(mtinfo->error_str, sizeof(mtinfo->error_str),
"%s: unable to allocate %zd bytes", __func__,
sizeof(*entry));
return;
}
bzero(entry, sizeof(*entry));
STAILQ_INIT(&entry->nv_list);
STAILQ_INIT(&entry->child_entries);
entry->entry_name = strdup(name);
mtinfo->cur_entry[mtinfo->level] = entry;
if (mtinfo->cur_entry[mtinfo->level - 1] == NULL) {
STAILQ_INSERT_TAIL(&mtinfo->entries, entry, links);
} else {
STAILQ_INSERT_TAIL(
&mtinfo->cur_entry[mtinfo->level - 1]->child_entries,
entry, links);
entry->parent = mtinfo->cur_entry[mtinfo->level - 1];
}
for (i = 0; attr[i] != NULL; i+=2) {
struct mt_status_nv *nv;
int need_nv;
need_nv = 0;
if (strcmp(attr[i], "size") == 0) {
entry->size = strtoull(attr[i+1], NULL, 0);
} else if (strcmp(attr[i], "type") == 0) {
if (strcmp(attr[i+1], "int") == 0) {
entry->var_type = MT_TYPE_INT;
} else if (strcmp(attr[i+1], "uint") == 0) {
entry->var_type = MT_TYPE_UINT;
} else if (strcmp(attr[i+1], "str") == 0) {
entry->var_type = MT_TYPE_STRING;
} else if (strcmp(attr[i+1], "node") == 0) {
entry->var_type = MT_TYPE_NODE;
} else {
need_nv = 1;
}
} else if (strcmp(attr[i], "fmt") == 0) {
entry->fmt = strdup(attr[i+1]);
} else if (strcmp(attr[i], "desc") == 0) {
entry->desc = strdup(attr[i+1]);
} else {
need_nv = 1;
}
if (need_nv != 0) {
nv = malloc(sizeof(*nv));
if (nv == NULL) {
mtinfo->error = 1;
snprintf(mtinfo->error_str,
sizeof(mtinfo->error_str),
"%s: error allocating %zd bytes",
__func__, sizeof(*nv));
}
bzero(nv, sizeof(*nv));
nv->name = strdup(attr[i]);
nv->value = strdup(attr[i+1]);
STAILQ_INSERT_TAIL(&entry->nv_list, nv, links);
}
}
}
/*
* Called on XML element close.
*/
void
mt_end_element(void *user_data, const char *name)
{
struct mt_status_data *mtinfo;
char *str;
mtinfo = (struct mt_status_data *)user_data;
if (mtinfo->error != 0)
return;
if (mtinfo->cur_sb[mtinfo->level] == NULL) {
mtinfo->error = 1;
snprintf(mtinfo->error_str, sizeof(mtinfo->error_str),
"%s: no valid sbuf at level %d (name %s)", __func__,
mtinfo->level, name);
return;
}
sbuf_finish(mtinfo->cur_sb[mtinfo->level]);
str = strdup(sbuf_data(mtinfo->cur_sb[mtinfo->level]));
if (str == NULL) {
mtinfo->error = 1;
snprintf(mtinfo->error_str, sizeof(mtinfo->error_str),
"%s can't allocate %zd bytes for string", __func__,
sbuf_len(mtinfo->cur_sb[mtinfo->level]));
return;
}
if (strlen(str) == 0) {
free(str);
str = NULL;
}
if (str != NULL) {
struct mt_status_entry *entry;
entry = mtinfo->cur_entry[mtinfo->level];
switch(entry->var_type) {
case MT_TYPE_INT:
entry->value_signed = strtoll(str, NULL, 0);
break;
case MT_TYPE_UINT:
entry->value_unsigned = strtoull(str, NULL, 0);
break;
default:
break;
}
}
mtinfo->cur_entry[mtinfo->level]->value = str;
sbuf_delete(mtinfo->cur_sb[mtinfo->level]);
mtinfo->cur_sb[mtinfo->level] = NULL;
mtinfo->cur_entry[mtinfo->level] = NULL;
mtinfo->level--;
}
/*
* Called to handle character strings in the current element.
*/
void
mt_char_handler(void *user_data, const XML_Char *str, int len)
{
struct mt_status_data *mtinfo;
mtinfo = (struct mt_status_data *)user_data;
if (mtinfo->error != 0)
return;
sbuf_bcat(mtinfo->cur_sb[mtinfo->level], str, len);
}
void
mt_status_tree_sbuf(struct sbuf *sb, struct mt_status_entry *entry, int indent,
void (*sbuf_func)(struct sbuf *sb, struct mt_status_entry *entry,
void *arg), void *arg)
{
struct mt_status_nv *nv;
struct mt_status_entry *entry2;
if (sbuf_func != NULL) {
sbuf_func(sb, entry, arg);
} else {
sbuf_printf(sb, "%*sname: %s, value: %s, fmt: %s, size: %zd, "
"type: %d, desc: %s\n", indent, "", entry->entry_name,
entry->value, entry->fmt, entry->size, entry->var_type,
entry->desc);
STAILQ_FOREACH(nv, &entry->nv_list, links) {
sbuf_printf(sb, "%*snv: name: %s, value: %s\n",
indent + 1, "", nv->name, nv->value);
}
}
STAILQ_FOREACH(entry2, &entry->child_entries, links)
mt_status_tree_sbuf(sb, entry2, indent + 2, sbuf_func, arg);
}
void
mt_status_tree_print(struct mt_status_entry *entry, int indent,
void (*print_func)(struct mt_status_entry *entry, void *arg), void *arg)
{
if (print_func != NULL) {
struct mt_status_entry *entry2;
print_func(entry, arg);
STAILQ_FOREACH(entry2, &entry->child_entries, links)
mt_status_tree_print(entry2, indent + 2, print_func,
arg);
} else {
struct sbuf *sb;
sb = sbuf_new_auto();
if (sb == NULL)
return;
mt_status_tree_sbuf(sb, entry, indent, NULL, NULL);
sbuf_finish(sb);
printf("%s", sbuf_data(sb));
sbuf_delete(sb);
}
}
/*
* Given a parameter name in the form "foo" or "foo.bar.baz", traverse the
* tree looking for the parameter (the first case) or series of parameters
* (second case).
*/
struct mt_status_entry *
mt_entry_find(struct mt_status_entry *entry, char *name)
{
struct mt_status_entry *entry2;
char *tmpname = NULL, *tmpname2 = NULL, *tmpstr = NULL;
tmpname = strdup(name);
if (tmpname == NULL)
goto bailout;
/* Save a pointer so we can free this later */
tmpname2 = tmpname;
tmpstr = strsep(&tmpname, ".");
/*
* Is this the entry we're looking for? Or do we have further
* child entries that we need to grab?
*/
if (strcmp(entry->entry_name, tmpstr) == 0) {
if (tmpname == NULL) {
/*
* There are no further child entries to find. We
* have a complete match.
*/
free(tmpname2);
return (entry);
} else {
/*
* There are more child entries that we need to find.
* Fall through to the recursive search off of this
* entry, below. Use tmpname, which will contain
* everything after the first period.
*/
name = tmpname;
}
}
/*
* Recursively look for further entries.
*/
STAILQ_FOREACH(entry2, &entry->child_entries, links) {
struct mt_status_entry *entry3;
entry3 = mt_entry_find(entry2, name);
if (entry3 != NULL) {
free(tmpname2);
return (entry3);
}
}
bailout:
free(tmpname2);
return (NULL);
}
struct mt_status_entry *
mt_status_entry_find(struct mt_status_data *status_data, char *name)
{
struct mt_status_entry *entry, *entry2;
STAILQ_FOREACH(entry, &status_data->entries, links) {
entry2 = mt_entry_find(entry, name);
if (entry2 != NULL)
return (entry2);
}
return (NULL);
}
void
mt_status_entry_free(struct mt_status_entry *entry)
{
struct mt_status_entry *entry2, *entry3;
struct mt_status_nv *nv, *nv2;
STAILQ_FOREACH_SAFE(entry2, &entry->child_entries, links, entry3) {
STAILQ_REMOVE(&entry->child_entries, entry2, mt_status_entry,
links);
mt_status_entry_free(entry2);
}
free(entry->entry_name);
free(entry->value);
free(entry->fmt);
free(entry->desc);
STAILQ_FOREACH_SAFE(nv, &entry->nv_list, links, nv2) {
STAILQ_REMOVE(&entry->nv_list, nv, mt_status_nv, links);
free(nv->name);
free(nv->value);
free(nv);
}
free(entry);
}
void
mt_status_free(struct mt_status_data *status_data)
{
struct mt_status_entry *entry, *entry2;
STAILQ_FOREACH_SAFE(entry, &status_data->entries, links, entry2) {
STAILQ_REMOVE(&status_data->entries, entry, mt_status_entry,
links);
mt_status_entry_free(entry);
}
}
void
mt_entry_sbuf(struct sbuf *sb, struct mt_status_entry *entry, char *fmt)
{
switch(entry->var_type) {
case MT_TYPE_INT:
if (fmt != NULL)
sbuf_printf(sb, fmt, (intmax_t)entry->value_signed);
else
sbuf_printf(sb, "%jd",
(intmax_t)entry->value_signed);
break;
case MT_TYPE_UINT:
if (fmt != NULL)
sbuf_printf(sb, fmt, (uintmax_t)entry->value_unsigned);
else
sbuf_printf(sb, "%ju",
(uintmax_t)entry->value_unsigned);
break;
default:
if (fmt != NULL)
sbuf_printf(sb, fmt, entry->value);
else
sbuf_printf(sb, "%s", entry->value);
break;
}
}
void
mt_param_parent_print(struct mt_status_entry *entry,
struct mt_print_params *print_params)
{
if (entry->parent != NULL)
mt_param_parent_print(entry->parent, print_params);
if (((print_params->flags & MT_PF_INCLUDE_ROOT) == 0)
&& (strcmp(entry->entry_name, print_params->root_name) == 0))
return;
printf("%s.", entry->entry_name);
}
void
mt_param_parent_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
struct mt_print_params *print_params)
{
if (entry->parent != NULL)
mt_param_parent_sbuf(sb, entry->parent, print_params);
if (((print_params->flags & MT_PF_INCLUDE_ROOT) == 0)
&& (strcmp(entry->entry_name, print_params->root_name) == 0))
return;
sbuf_printf(sb, "%s.", entry->entry_name);
}
void
mt_param_entry_sbuf(struct sbuf *sb, struct mt_status_entry *entry, void *arg)
{
struct mt_print_params *print_params;
print_params = (struct mt_print_params *)arg;
/*
* We don't want to print nodes.
*/
if (entry->var_type == MT_TYPE_NODE)
return;
if ((print_params->flags & MT_PF_FULL_PATH)
&& (entry->parent != NULL))
mt_param_parent_sbuf(sb, entry->parent, print_params);
sbuf_printf(sb, "%s: %s", entry->entry_name, entry->value);
if ((print_params->flags & MT_PF_VERBOSE)
&& (entry->desc != NULL)
&& (strlen(entry->desc) > 0))
sbuf_printf(sb, " (%s)", entry->desc);
sbuf_printf(sb, "\n");
}
void
mt_param_entry_print(struct mt_status_entry *entry, void *arg)
{
struct mt_print_params *print_params;
print_params = (struct mt_print_params *)arg;
/*
* We don't want to print nodes.
*/
if (entry->var_type == MT_TYPE_NODE)
return;
if ((print_params->flags & MT_PF_FULL_PATH)
&& (entry->parent != NULL))
mt_param_parent_print(entry->parent, print_params);
printf("%s: %s", entry->entry_name, entry->value);
if ((print_params->flags & MT_PF_VERBOSE)
&& (entry->desc != NULL)
&& (strlen(entry->desc) > 0))
printf(" (%s)", entry->desc);
printf("\n");
}
int
mt_protect_print(struct mt_status_data *status_data, int verbose)
{
struct mt_status_entry *entry;
const char *prot_name = MT_PROTECTION_NAME;
struct mt_print_params print_params;
snprintf(print_params.root_name, sizeof(print_params.root_name),
MT_PARAM_ROOT_NAME);
print_params.flags = MT_PF_FULL_PATH;
if (verbose != 0)
print_params.flags |= MT_PF_VERBOSE;
entry = mt_status_entry_find(status_data, __DECONST(char *,prot_name));
if (entry == NULL)
return (1);
mt_status_tree_print(entry, 0, mt_param_entry_print, &print_params);
return (0);
}
int
mt_param_list(struct mt_status_data *status_data, char *param_name, int quiet)
{
struct mt_status_entry *entry;
struct mt_print_params print_params;
char root_name[20];
snprintf(root_name, sizeof(root_name), "mtparamget");
strlcpy(print_params.root_name, root_name,
sizeof(print_params.root_name));
print_params.flags = MT_PF_FULL_PATH;
if (quiet == 0)
print_params.flags |= MT_PF_VERBOSE;
if (param_name != NULL) {
entry = mt_status_entry_find(status_data, param_name);
if (entry == NULL)
return (1);
mt_param_entry_print(entry, &print_params);
return (0);
} else {
entry = mt_status_entry_find(status_data, root_name);
STAILQ_FOREACH(entry, &status_data->entries, links)
mt_status_tree_print(entry, 0, mt_param_entry_print,
&print_params);
}
return (0);
}
static struct densities {
int dens;
int bpmm;
int bpi;
const char *name;
} dens[] = {
/*
* Taken from T10 Project 997D
* SCSI-3 Stream Device Commands (SSC)
* Revision 11, 4-Nov-97
*
* LTO 1-6 definitions obtained from the eighth edition of the
* IBM TotalStorage LTO Ultrium Tape Drive SCSI Reference
* (July 2007) and the second edition of the IBM System Storage LTO
* Tape Drive SCSI Reference (February 13, 2013).
*
* IBM 3592 definitions obtained from second edition of the IBM
* System Storage Tape Drive 3592 SCSI Reference (May 25, 2012).
*/
/*Num. bpmm bpi Reference */
{ 0x1, 32, 800, "X3.22-1983" },
{ 0x2, 63, 1600, "X3.39-1986" },
{ 0x3, 246, 6250, "X3.54-1986" },
{ 0x5, 315, 8000, "X3.136-1986" },
{ 0x6, 126, 3200, "X3.157-1987" },
{ 0x7, 252, 6400, "X3.116-1986" },
{ 0x8, 315, 8000, "X3.158-1987" },
{ 0x9, 491, 37871, "X3.180" },
{ 0xA, 262, 6667, "X3B5/86-199" },
{ 0xB, 63, 1600, "X3.56-1986" },
{ 0xC, 500, 12690, "HI-TC1" },
{ 0xD, 999, 25380, "HI-TC2" },
{ 0xF, 394, 10000, "QIC-120" },
{ 0x10, 394, 10000, "QIC-150" },
{ 0x11, 630, 16000, "QIC-320" },
{ 0x12, 2034, 51667, "QIC-1350" },
{ 0x13, 2400, 61000, "X3B5/88-185A" },
{ 0x14, 1703, 43245, "X3.202-1991" },
{ 0x15, 1789, 45434, "ECMA TC17" },
{ 0x16, 394, 10000, "X3.193-1990" },
{ 0x17, 1673, 42500, "X3B5/91-174" },
{ 0x18, 1673, 42500, "X3B5/92-50" },
{ 0x19, 2460, 62500, "DLTapeIII" },
{ 0x1A, 3214, 81633, "DLTapeIV(20GB)" },
{ 0x1B, 3383, 85937, "DLTapeIV(35GB)" },
{ 0x1C, 1654, 42000, "QIC-385M" },
{ 0x1D, 1512, 38400, "QIC-410M" },
{ 0x1E, 1385, 36000, "QIC-1000C" },
{ 0x1F, 2666, 67733, "QIC-2100C" },
{ 0x20, 2666, 67733, "QIC-6GB(M)" },
{ 0x21, 2666, 67733, "QIC-20GB(C)" },
{ 0x22, 1600, 40640, "QIC-2GB(C)" },
{ 0x23, 2666, 67733, "QIC-875M" },
{ 0x24, 2400, 61000, "DDS-2" },
{ 0x25, 3816, 97000, "DDS-3" },
{ 0x26, 3816, 97000, "DDS-4" },
{ 0x27, 3056, 77611, "Mammoth" },
{ 0x28, 1491, 37871, "X3.224" },
{ 0x40, 4880, 123952, "LTO-1" },
{ 0x41, 3868, 98250, "DLTapeIV(40GB)" },
{ 0x42, 7398, 187909, "LTO-2" },
{ 0x44, 9638, 244805, "LTO-3" },
{ 0x46, 12725, 323215, "LTO-4" },
{ 0x48, 5236, 133000, "SDLTapeI(110)" },
{ 0x49, 7598, 193000, "SDLTapeI(160)" },
{ 0x4a, 0, 0, "T10000A" },
{ 0x4b, 0, 0, "T10000B" },
{ 0x4c, 0, 0, "T10000C" },
{ 0x4d, 0, 0, "T10000D" },
{ 0x51, 11800, 299720, "3592A1 (unencrypted)" },
{ 0x52, 11800, 299720, "3592A2 (unencrypted)" },
{ 0x53, 13452, 341681, "3592A3 (unencrypted)" },
{ 0x54, 19686, 500024, "3592A4 (unencrypted)" },
{ 0x55, 20670, 525018, "3592A5 (unencrypted)" },
{ 0x58, 15142, 384607, "LTO-5" },
{ 0x5A, 15142, 384607, "LTO-6" },
{ 0x71, 11800, 299720, "3592A1 (encrypted)" },
{ 0x72, 11800, 299720, "3592A2 (encrypted)" },
{ 0x73, 13452, 341681, "3592A3 (encrypted)" },
{ 0x74, 19686, 500024, "3592A4 (encrypted)" },
{ 0x75, 20670, 525018, "3592A5 (encrypted)" },
{ 0x8c, 1789, 45434, "EXB-8500c" },
{ 0x90, 1703, 43245, "EXB-8200c" },
{ 0, 0, 0, NULL }
};
const char *
mt_density_name(int density_num)
{
struct densities *sd;
/* densities 0 and 0x7f are handled as special cases */
if (density_num == 0)
return ("default");
if (density_num == 0x7f)
return ("same");
for (sd = dens; sd->dens != 0; sd++)
if (sd->dens == density_num)
break;
if (sd->dens == 0)
return ("UNKNOWN");
return (sd->name);
}
/*
* Given a specific density number, return either the bits per inch or bits
* per millimeter for the given density.
*/
int
mt_density_bp(int density_num, int bpi)
{
struct densities *sd;
for (sd = dens; sd->dens; sd++)
if (sd->dens == density_num)
break;
if (sd->dens == 0)
return (0);
if (bpi)
return (sd->bpi);
else
return (sd->bpmm);
}
int
mt_density_num(const char *density_name)
{
struct densities *sd;
size_t l = strlen(density_name);
for (sd = dens; sd->dens; sd++)
if (strncasecmp(sd->name, density_name, l) == 0)
break;
return (sd->dens);
}
/*
* Get the current status XML string.
* Returns 0 on success, -1 on failure (with errno set, and *xml_str == NULL).
*/
int
mt_get_xml_str(int mtfd, unsigned long cmd, char **xml_str)
{
size_t alloc_len = 32768;
struct mtextget extget;
int error;
*xml_str = NULL;
for (;;) {
bzero(&extget, sizeof(extget));
*xml_str = malloc(alloc_len);
if (*xml_str == NULL)
return (-1);
extget.status_xml = *xml_str;
extget.alloc_len = alloc_len;
error = ioctl(mtfd, cmd, (caddr_t)&extget);
if (error == 0 && extget.status == MT_EXT_GET_OK)
break;
free(*xml_str);
*xml_str = NULL;
if (error != 0 || extget.status != MT_EXT_GET_NEED_MORE_SPACE)
return (-1);
/* The driver needs more space, so double and try again. */
alloc_len *= 2;
}
return (0);
}
/*
* Populate a struct mt_status_data from the XML string via mt_get_xml_str().
*
* Returns XML_STATUS_OK on success.
* If XML_STATUS_ERROR is returned, errno may be set to indicate the reason.
* The caller must check status_data->error.
*/
int
mt_get_status(char *xml_str, struct mt_status_data *status_data)
{
XML_Parser parser;
int retval;
bzero(status_data, sizeof(*status_data));
STAILQ_INIT(&status_data->entries);
parser = XML_ParserCreate(NULL);
if (parser == NULL) {
errno = ENOMEM;
return (XML_STATUS_ERROR);
}
XML_SetUserData(parser, status_data);
XML_SetElementHandler(parser, mt_start_element, mt_end_element);
XML_SetCharacterDataHandler(parser, mt_char_handler);
retval = XML_Parse(parser, xml_str, strlen(xml_str), 1);
XML_ParserFree(parser);
return (retval);
}

122
lib/libmt/mtlib.h Normal file
View file

@ -0,0 +1,122 @@
/*-
* Copyright (c) 2013, 2014 Spectra Logic Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* Authors: Ken Merry (Spectra Logic Corporation)
*
* $FreeBSD$
*/
#ifndef _MTLIB_H
#define _MTLIB_H
typedef enum {
MT_TYPE_NONE,
MT_TYPE_STRING,
MT_TYPE_INT,
MT_TYPE_UINT,
MT_TYPE_NODE
} mt_variable_type;
struct mt_status_nv {
char *name;
char *value;
STAILQ_ENTRY(mt_status_nv) links;
};
struct mt_status_entry {
char *entry_name;
char *value;
uint64_t value_unsigned;
int64_t value_signed;
char *fmt;
char *desc;
size_t size;
mt_variable_type var_type;
struct mt_status_entry *parent;
STAILQ_HEAD(, mt_status_nv) nv_list;
STAILQ_HEAD(, mt_status_entry) child_entries;
STAILQ_ENTRY(mt_status_entry) links;
};
struct mt_status_data {
int level;
struct sbuf *cur_sb[32];
struct mt_status_entry *cur_entry[32];
int error;
char error_str[128];
STAILQ_HEAD(, mt_status_entry) entries;
};
typedef enum {
MT_PF_NONE = 0x00,
MT_PF_VERBOSE = 0x01,
MT_PF_FULL_PATH = 0x02,
MT_PF_INCLUDE_ROOT = 0x04
} mt_print_flags;
struct mt_print_params {
mt_print_flags flags;
char root_name[64];
};
__BEGIN_DECLS
void mt_start_element(void *user_data, const char *name, const char **attr);
void mt_end_element(void *user_data, const char *name);
void mt_char_handler(void *user_data, const XML_Char *str, int len);
void mt_status_tree_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
int indent, void (*sbuf_func)(struct sbuf *sb,
struct mt_status_entry *entry, void *arg), void *arg);
void mt_status_tree_print(struct mt_status_entry *entry, int indent,
void (*print_func)(struct mt_status_entry *entry,
void *arg), void *arg);
struct mt_status_entry *mt_entry_find(struct mt_status_entry *entry,
char *name);
struct mt_status_entry *mt_status_entry_find(struct mt_status_data *status_data,
char *name);
void mt_status_entry_free(struct mt_status_entry *entry);
void mt_status_free(struct mt_status_data *status_data);
void mt_entry_sbuf(struct sbuf *sb, struct mt_status_entry *entry, char *fmt);
void mt_param_parent_print(struct mt_status_entry *entry,
struct mt_print_params *print_params);
void mt_param_parent_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
struct mt_print_params *print_params);
void mt_param_entry_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
void *arg);
void mt_param_entry_print(struct mt_status_entry *entry, void *arg);
int mt_protect_print(struct mt_status_data *status_data, int verbose);
int mt_param_list(struct mt_status_data *status_data, char *param_name,
int quiet);
const char *mt_density_name(int density_num);
int mt_density_bp(int density_num, int bpi);
int mt_density_num(const char *density_name);
int mt_get_xml_str(int mtfd, unsigned long cmd, char **xml_str);
int mt_get_status(char *xml_str, struct mt_status_data *status_data);
__END_DECLS
#endif /* _MTLIB_H */

View file

@ -131,7 +131,7 @@ CRUNCH_LIBS+= -lgeom -lbsdxml -lkiconv
.if ${MK_OPENSSL} == "no"
CRUNCH_LIBS+= -lmd
.endif
CRUNCH_LIBS+= -lsbuf -lufs -lz
CRUNCH_LIBS+= -lmt -lsbuf -lufs -lz
.if ${MACHINE_CPUARCH} == "i386"
CRUNCH_PROGS_sbin+= bsdlabel sconfig fdisk

View file

@ -31,7 +31,7 @@
.\" @(#)mtio.4 8.1 (Berkeley) 6/5/93
.\" $FreeBSD$
.\"
.Dd November 11, 2011
.Dd February 12, 2015
.Dt MTIO 4
.Os
.Sh NAME
@ -40,10 +40,10 @@
.Sh DESCRIPTION
The special files
named
.Pa /dev/[n]sa*
.Pa /dev/[en]sa*
refer to SCSI tape drives,
which may be attached to the system.
.Pa /dev/[n]sa*.ctl
.Pa /dev/sa*.ctl
are control devices that can be used to issue ioctls to the SCSI
tape driver to set parameters that are required to last beyond the
unmounting of a tape.
@ -53,16 +53,19 @@ when the last requested read, write or seek has finished, or the end of the tape
has been reached.
The letter
.Ql n
is usually prepended to
is prepended to
the name of the no-rewind devices.
The letter
.Ql e
is prepended to the name of the eject devices.
.Pp
Tapes can be written with either fixed length records or variable length
records.
See
.Xr sa 4
for more information.
Two end-of-file markers mark the end of a tape, and
one end-of-file marker marks the end of a tape file.
Two filemarks mark the end of a tape, and
one filemark marks the end of a tape file.
If the tape is not to be rewound it is positioned with the
head in between the two tape marks, where the next write
will over write the second end-of-file marker.
@ -128,6 +131,8 @@ struct mtop {
#define MTWSS 16 /* write setmark(s) */
#define MTFSS 17 /* forward space setmark */
#define MTBSS 18 /* backward space setmark */
#define MTLOAD 19 /* load tape in drive */
#define MTWEOFI 20 /* write an end-of-file record without waiting*/
#define MT_COMP_ENABLE 0xffffffff
#define MT_COMP_DISABLED 0xfffffffe
@ -224,6 +229,112 @@ union mterrstat {
char _reserved_padding[256];
};
struct mtrblim {
uint32_t granularity;
uint32_t min_block_length;
uint32_t max_block_length;
};
typedef enum {
MT_LOCATE_DEST_OBJECT = 0x00,
MT_LOCATE_DEST_FILE = 0x01,
MT_LOCATE_DEST_SET = 0x02,
MT_LOCATE_DEST_EOD = 0x03
} mt_locate_dest_type;
typedef enum {
MT_LOCATE_BAM_IMPLICIT = 0x00,
MT_LOCATE_BAM_EXPLICIT = 0x01
} mt_locate_bam;
typedef enum {
MT_LOCATE_FLAG_IMMED = 0x01,
MT_LOCATE_FLAG_CHANGE_PART = 0x02
} mt_locate_flags;
struct mtlocate {
mt_locate_flags flags;
mt_locate_dest_type dest_type;
mt_locate_bam block_address_mode;
int64_t partition;
uint64_t logical_id;
uint8_t reserved[64];
};
typedef enum {
MT_EXT_GET_NONE,
MT_EXT_GET_OK,
MT_EXT_GET_NEED_MORE_SPACE,
MT_EXT_GET_ERROR
} mt_ext_get_status;
struct mtextget {
uint32_t alloc_len;
char *status_xml;
uint32_t fill_len;
mt_ext_get_status status;
char error_str[128];
uint8_t reserved[64];
};
#define MT_EXT_GET_ROOT_NAME "mtextget"
#define MT_DENSITY_ROOT_NAME "mtdensity"
#define MT_MEDIA_DENSITY_NAME "media_density"
#define MT_DENSITY_REPORT_NAME "density_report"
#define MT_MEDIUM_TYPE_REPORT_NAME "medium_type_report"
#define MT_MEDIA_REPORT_NAME "media_report"
#define MT_DENSITY_ENTRY_NAME "density_entry"
#define MT_DENS_WRITE_OK 0x80
#define MT_DENS_DUP 0x40
#define MT_DENS_DEFLT 0x20
#define MT_PARAM_FIXED_STR_LEN 32
union mt_param_value {
int64_t value_signed;
uint64_t value_unsigned;
char *value_var_str;
char value_fixed_str[MT_PARAM_FIXED_STR_LEN];
uint8_t reserved[64];
};
typedef enum {
MT_PARAM_SET_NONE,
MT_PARAM_SET_SIGNED,
MT_PARAM_SET_UNSIGNED,
MT_PARAM_SET_VAR_STR,
MT_PARAM_SET_FIXED_STR
} mt_param_set_type;
typedef enum {
MT_PARAM_STATUS_NONE,
MT_PARAM_STATUS_OK,
MT_PARAM_STATUS_ERROR
} mt_param_set_status;
#define MT_PARAM_VALUE_NAME_LEN 64
struct mtparamset {
char value_name[MT_PARAM_VALUE_NAME_LEN];
mt_param_set_type value_type;
int value_len;
union mt_param_value value;
mt_param_set_status status;
char error_str[128];
};
#define MT_PARAM_ROOT_NAME "mtparamget"
#define MT_PROTECTION_NAME "protection"
/*
* Set a list of parameters.
*/
struct mtsetlist {
int num_params;
int param_len;
struct mtparamset *params;
};
/*
* Constants for mt_type byte. These are the same
* for controllers compatible with the types listed.
@ -273,6 +384,12 @@ union mterrstat {
#define MTIOCSETEOTMODEL _IOW('m', 8, uint32_t)
/* Get current EOT model */
#define MTIOCGETEOTMODEL _IOR('m', 8, uint32_t)
#define MTIOCRBLIM _IOR('m', 9, struct mtrblim) /* get block limits */
#define MTIOCEXTLOCATE _IOW('m', 10, struct mtlocate) /* seek to position */
#define MTIOCEXTGET _IOWR('m', 11, struct mtextget) /* get tape status */
#define MTIOCPARAMGET _IOWR('m', 12, struct mtextget) /* get tape params */
#define MTIOCPARAMSET _IOWR('m', 13, struct mtparamset) /* set tape params */
#define MTIOCSETLIST _IOWR('m', 14, struct mtsetlist) /* set N params */
#ifndef _KERNEL
#define DEFTAPE "/dev/nsa0"
@ -281,13 +398,12 @@ union mterrstat {
#endif /* !_SYS_MTIO_H_ */
.Ed
.Sh FILES
.Bl -tag -width /dev/[n]sa* -compact
.It Pa /dev/[n]sa*
.Bl -tag -width /dev/[en]sa* -compact
.It Pa /dev/[en]sa*
.El
.Sh SEE ALSO
.Xr mt 1 ,
.Xr tar 1 ,
.Xr ast 4 ,
.Xr sa 4
.Sh HISTORY
The
@ -296,8 +412,3 @@ manual appeared in
.Bx 4.2 .
An i386 version first appeared in
.Fx 2.2 .
.Sh BUGS
The status should be returned in a device independent format.
.Pp
The special file naming should be redone in a more consistent and
understandable manner.

View file

@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd August 23, 2013
.Dd February 12, 2015
.Dt SA 4
.Os
.Sh NAME
@ -285,10 +285,10 @@ device driver written and ported from
by
.An Julian Elischer .
.Pp
The current owner of record is
.An Matthew Jacob
who has suffered too many
years of breaking tape drivers.
The owner of record for many years was
.An Matthew Jacob .
The current maintainer is
.An Kenneth Merry
.Sh BUGS
This driver lacks many of the hacks required to deal with older devices.
Many older
@ -305,7 +305,5 @@ for your device in order to read tapes written under
.Fx
2.X.
.Pp
Fine grained density and compression mode support that is bound to specific
device names needs to be added.
.Pp
Support for fast indexing by use of partitions is missing.
Partitions are only supported for status information and location.
It would be nice to add support for creating and editing tape partitions.

View file

@ -85,6 +85,7 @@ LIBMEMSTAT?= ${DESTDIR}${LIBDIR}/libmemstat.a
LIBMENU?= ${DESTDIR}${LIBDIR}/libmenu.a
LIBMILTER?= ${DESTDIR}${LIBDIR}/libmilter.a
LIBMP?= ${DESTDIR}${LIBDIR}/libmp.a
LIBMT?= ${DESTDIR}${LIBDIR}/libmt.a
LIBNCURSES?= ${DESTDIR}${LIBDIR}/libncurses.a
LIBNCURSESW?= ${DESTDIR}${LIBDIR}/libncursesw.a
LIBNETGRAPH?= ${DESTDIR}${LIBDIR}/libnetgraph.a

View file

@ -7442,6 +7442,71 @@ scsi_persistent_reserve_out(struct ccb_scsiio *csio, uint32_t retries,
scsi_cmd->opcode = PERSISTENT_RES_OUT;
scsi_cmd->action = service_action;
scsi_cmd->scope_type = scope | res_type;
cam_fill_csio(csio,
retries,
cbfcnp,
/*flags*/CAM_DIR_OUT,
tag_action,
/*data_ptr*/data_ptr,
/*dxfer_len*/dxfer_len,
sense_len,
sizeof(*scsi_cmd),
timeout);
}
void
scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries,
void (*cbfcnp)(struct cam_periph *, union ccb *),
uint8_t tag_action, uint32_t security_protocol,
uint32_t security_protocol_specific, int byte4,
uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
int timeout)
{
struct scsi_security_protocol_in *scsi_cmd;
scsi_cmd = (struct scsi_security_protocol_in *)&csio->cdb_io.cdb_bytes;
bzero(scsi_cmd, sizeof(*scsi_cmd));
scsi_cmd->opcode = SECURITY_PROTOCOL_IN;
scsi_cmd->security_protocol = security_protocol;
scsi_ulto2b(security_protocol_specific,
scsi_cmd->security_protocol_specific);
scsi_cmd->byte4 = byte4;
scsi_ulto4b(dxfer_len, scsi_cmd->length);
cam_fill_csio(csio,
retries,
cbfcnp,
/*flags*/CAM_DIR_IN,
tag_action,
data_ptr,
dxfer_len,
sense_len,
sizeof(*scsi_cmd),
timeout);
}
void
scsi_security_protocol_out(struct ccb_scsiio *csio, uint32_t retries,
void (*cbfcnp)(struct cam_periph *, union ccb *),
uint8_t tag_action, uint32_t security_protocol,
uint32_t security_protocol_specific, int byte4,
uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
int timeout)
{
struct scsi_security_protocol_out *scsi_cmd;
scsi_cmd = (struct scsi_security_protocol_out *)&csio->cdb_io.cdb_bytes;
bzero(scsi_cmd, sizeof(*scsi_cmd));
scsi_cmd->opcode = SECURITY_PROTOCOL_OUT;
scsi_cmd->security_protocol = security_protocol;
scsi_ulto2b(security_protocol_specific,
scsi_cmd->security_protocol_specific);
scsi_cmd->byte4 = byte4;
scsi_ulto4b(dxfer_len, scsi_cmd->length);
cam_fill_csio(csio,

View file

@ -1758,6 +1758,7 @@ struct ata_pass_16 {
#define SERVICE_ACTION_IN 0x9E
#define REPORT_LUNS 0xA0
#define ATA_PASS_12 0xA1
#define SECURITY_PROTOCOL_IN 0xA2
#define MAINTENANCE_IN 0xA3
#define MAINTENANCE_OUT 0xA4
#define MOVE_MEDIUM 0xA5
@ -1765,6 +1766,7 @@ struct ata_pass_16 {
#define WRITE_12 0xAA
#define WRITE_VERIFY_12 0xAE
#define VERIFY_12 0xAF
#define SECURITY_PROTOCOL_OUT 0xB5
#define READ_ELEMENT_STATUS 0xB8
#define READ_CD 0xBE
@ -2702,6 +2704,41 @@ struct scsi_target_group_data_extended {
struct scsi_target_port_group_descriptor groups[];
};
struct scsi_security_protocol_in
{
uint8_t opcode;
uint8_t security_protocol;
#define SPI_PROT_INFORMATION 0x00
#define SPI_PROT_CBCS 0x07
#define SPI_PROT_TAPE_DATA_ENC 0x20
#define SPI_PROT_DATA_ENC_CONFIG 0x21
#define SPI_PROT_SA_CREATE_CAP 0x40
#define SPI_PROT_IKEV2_SCSI 0x41
#define SPI_PROT_JEDEC_UFS 0xEC
#define SPI_PROT_SDCARD_TFSSS 0xED
#define SPI_PROT_AUTH_HOST_TRANSIENT 0xEE
#define SPI_PROT_ATA_DEVICE_PASSWORD 0xEF
uint8_t security_protocol_specific[2];
uint8_t byte4;
#define SPI_INC_512 0x80
uint8_t reserved1;
uint8_t length[4];
uint8_t reserved2;
uint8_t control;
};
struct scsi_security_protocol_out
{
uint8_t opcode;
uint8_t security_protocol;
uint8_t security_protocol_specific[2];
uint8_t byte4;
#define SPO_INC_512 0x80
uint8_t reserved1;
uint8_t length[4];
uint8_t reserved2;
uint8_t control;
};
typedef enum {
SSD_TYPE_NONE,
@ -3623,6 +3660,20 @@ void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
u_int8_t tag_action, int start, int load_eject,
int immediate, u_int8_t sense_len, u_int32_t timeout);
void scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries,
void (*cbfcnp)(struct cam_periph *, union ccb *),
uint8_t tag_action, uint32_t security_protocol,
uint32_t security_protocol_specific, int byte4,
uint8_t *data_ptr, uint32_t dxfer_len,
int sense_len, int timeout);
void scsi_security_protocol_out(struct ccb_scsiio *csio, uint32_t retries,
void (*cbfcnp)(struct cam_periph *,union ccb *),
uint8_t tag_action, uint32_t security_protocol,
uint32_t security_protocol_specific, int byte4,
uint8_t *data_ptr, uint32_t dxfer_len,
int sense_len, int timeout);
void scsi_persistent_reserve_in(struct ccb_scsiio *csio, uint32_t retries,
void (*cbfcnp)(struct cam_periph *,union ccb *),
uint8_t tag_action, int service_action,

File diff suppressed because it is too large Load diff

View file

@ -3,6 +3,7 @@
* SCSI Sequential Access Peripheral driver for CAM.
*
* Copyright (c) 1999, 2000 Matthew Jacob
* Copyright (c) 2013, 2014, 2015 Spectra Logic Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -141,6 +142,53 @@ struct scsi_erase
u_int8_t control;
};
/*
* Set tape capacity.
*/
struct scsi_set_capacity
{
u_int8_t opcode;
u_int8_t byte1;
#define SA_SSC_IMMED 0x01
u_int8_t reserved;
u_int8_t cap_proportion[2];
u_int8_t control;
};
/*
* Format tape media. The CDB opcode is the same as the disk-specific
* FORMAT UNIT command, but the fields are different inside the CDB. Thus
* the reason for a separate definition here.
*/
struct scsi_format_medium
{
u_int8_t opcode;
u_int8_t byte1;
#define SFM_IMMED 0x01
#define SFM_VERIFY 0x02
u_int8_t byte2;
#define SFM_FORMAT_DEFAULT 0x00
#define SFM_FORMAT_PARTITION 0x01
#define SFM_FORMAT_DEF_PART 0x02
#define SFM_FORMAT_MASK 0x0f
u_int8_t length[2];
u_int8_t control;
};
struct scsi_allow_overwrite
{
u_int8_t opcode;
u_int8_t reserved1;
u_int8_t allow_overwrite;
#define SAO_ALLOW_OVERWRITE_DISABLED 0x00
#define SAO_ALLOW_OVERWRITE_CUR_POS 0x01
#define SAO_ALLOW_OVERWRITE_FORMAT 0x02
u_int8_t partition;
u_int8_t logical_id[8];
u_int8_t reserved2[3];
u_int8_t control;
};
/*
* Dev specific mode page masks.
*/
@ -180,11 +228,18 @@ struct scsi_dev_conf_page {
#define SA_BIS 0x40 /* block identifiers supported */
#define SA_RSMK 0x20 /* report setmarks */
#define SA_AVC 0x10 /* automatic velocity control */
#define SA_SOCF_MASK 0xc0 /* stop on consecutive formats */
#define SA_RBO 0x20 /* recover buffer order */
#define SA_REW 0x10 /* report early warning */
#define SA_SOCF_MASK 0x0c /* stop on consecutive formats */
#define SA_RBO 0x02 /* recover buffer order */
#define SA_REW 0x01 /* report early warning */
u_int8_t gap_size;
u_int8_t byte10;
/* from SCSI-3: SSC-4 Working draft (2/14) 8.3.3 */
#define SA_EOD_DEF_MASK 0xe0 /* EOD defined */
#define SA_EEG 0x10 /* Enable EOD Generation */
#define SA_SEW 0x08 /* Synchronize at Early Warning */
#define SA_SOFT_WP 0x04 /* Software Write Protect */
#define SA_BAML 0x02 /* Block Address Mode Lock */
#define SA_BAM 0x01 /* Block Address Mode */
u_int8_t ew_bufsize[3];
u_int8_t sel_comp_alg;
#define SA_COMP_NONE 0x00
@ -221,10 +276,78 @@ typedef union {
struct scsi_data_compression_page dcomp;
} sa_comp_t;
/*
* Control Data Protection subpage. This is as defined in SSC3r03.
*/
struct scsi_control_data_prot_subpage {
uint8_t page_code;
#define SA_CTRL_DP_PAGE_CODE 0x0a
uint8_t subpage_code;
#define SA_CTRL_DP_SUBPAGE_CODE 0xf0
uint8_t length[2];
uint8_t prot_method;
#define SA_CTRL_DP_NO_LBP 0x00
#define SA_CTRL_DP_REED_SOLOMON 0x01
#define SA_CTRL_DP_METHOD_MAX 0xff
uint8_t pi_length;
#define SA_CTRL_DP_PI_LENGTH_MASK 0x3f
#define SA_CTRL_DP_RS_LENGTH 4
uint8_t prot_bits;
#define SA_CTRL_DP_LBP_W 0x80
#define SA_CTRL_DP_LBP_R 0x40
#define SA_CTRL_DP_RBDP 0x20
uint8_t reserved[];
};
/*
* This is the Read/Write Control mode page used on IBM Enterprise Tape
* Drives. They are known as 3592, TS, or Jaguar drives. The SCSI inquiry
* data will show a Product ID "03592XXX", where XXX is 'J1A', 'E05' (TS1120),
* 'E06' (TS1130), 'E07' (TS1140) or 'E08' (TS1150).
*
* This page definition is current as of the 3592 SCSI Reference v6,
* released on December 16th, 2014.
*/
struct scsi_tape_ibm_rw_control {
uint8_t page_code;
#define SA_IBM_RW_CTRL_PAGE_CODE 0x25
uint8_t page_length;
uint8_t ignore_seq_checks;
#define SA_IBM_RW_CTRL_LOC_IGNORE_SEQ 0x04
#define SA_IBM_RW_CTRL_SPC_BLK_IGNORE_SEQ 0x02
#define SA_IBM_RW_CTRL_SPC_FM_IGNORE_SEQ 0x01
uint8_t ignore_data_checks;
#define SA_IBM_RW_CTRL_LOC_IGNORE_DATA 0x04
#define SA_IBM_RW_CTRL_SPC_BLK_IGNORE_DATA 0x02
#define SA_IBM_RW_CTRL_SPC_FM_IGNORE_DATA 0x01
uint8_t reserved1;
uint8_t leop_method;
#define SA_IBM_RW_CTRL_LEOP_DEFAULT 0x00
#define SA_IBM_RW_CTRL_LEOP_MAX_CAP 0x01
#define SA_IBM_RW_CTRL_LEOP_CONST_CAP 0x02
uint8_t leop_ew[2];
uint8_t byte8;
#define SA_IBM_RW_CTRL_DISABLE_FASTSYNC 0x80
#define SA_IBM_RW_CTRL_DISABLE_SKIPSYNC 0x40
#define SA_IBM_RW_CTRL_DISABLE_CROSS_EOD 0x08
#define SA_IBM_RW_CTRL_DISABLE_CROSS_PERM_ERR 0x04
#define SA_IBM_RW_CTRL_REPORT_SEG_EW 0x02
#define SA_IBM_RW_CTRL_REPORT_HOUSEKEEPING_ERR 0x01
uint8_t default_write_dens_bop_0;
uint8_t pending_write_dens_bop_0;
uint8_t reserved2[21];
};
struct scsi_tape_read_position {
u_int8_t opcode; /* READ_POSITION */
u_int8_t byte1; /* set LSB to read hardware block pos */
u_int8_t reserved[8];
#define SA_RPOS_SHORT_FORM 0x00
#define SA_RPOS_SHORT_VENDOR 0x01
#define SA_RPOS_LONG_FORM 0x06
#define SA_RPOS_EXTENDED_FORM 0x08
u_int8_t reserved[5];
u_int8_t length[2];
u_int8_t control;
};
struct scsi_tape_position_data { /* Short Form */
@ -235,6 +358,7 @@ struct scsi_tape_position_data { /* Short Form */
#define SA_RPOS_BYCU 0x10 /* Byte Count Unknown (SCSI3) */
#define SA_RPOS_BPU 0x04 /* Block Position Unknown */
#define SA_RPOS_PERR 0x02 /* Position Error (SCSI3) */
#define SA_RPOS_BPEW 0x01 /* Beyond Programmable Early Warning */
#define SA_RPOS_UNCERTAIN SA_RPOS_BPU
u_int8_t partition;
u_int8_t reserved[2];
@ -245,6 +369,38 @@ struct scsi_tape_position_data { /* Short Form */
u_int8_t nbufbyte[4];
};
struct scsi_tape_position_long_data {
u_int8_t flags;
#define SA_RPOS_LONG_BOP 0x80 /* Beginning of Partition */
#define SA_RPOS_LONG_EOP 0x40 /* End of Partition */
#define SA_RPOS_LONG_MPU 0x08 /* Mark Position Unknown */
#define SA_RPOS_LONG_LONU 0x04 /* Logical Object Number Unknown */
#define SA_RPOS_LONG_BPEW 0x01 /* Beyond Programmable Early Warning */
u_int8_t reserved[3];
u_int8_t partition[4];
u_int8_t logical_object_num[8];
u_int8_t logical_file_num[8];
u_int8_t set_id[8];
};
struct scsi_tape_position_ext_data {
u_int8_t flags;
#define SA_RPOS_EXT_BOP 0x80 /* Beginning of Partition */
#define SA_RPOS_EXT_EOP 0x40 /* End of Partition */
#define SA_RPOS_EXT_LOCU 0x20 /* Logical Object Count Unknown */
#define SA_RPOS_EXT_BYCU 0x10 /* Byte Count Unknown */
#define SA_RPOS_EXT_LOLU 0x04 /* Logical Object Location Unknown */
#define SA_RPOS_EXT_PERR 0x02 /* Position Error */
#define SA_RPOS_EXT_BPEW 0x01 /* Beyond Programmable Early Warning */
u_int8_t partition;
u_int8_t length[2];
u_int8_t reserved;
u_int8_t num_objects[3];
u_int8_t first_object[8];
u_int8_t last_object[8];
u_int8_t bytes_in_buffer[8];
};
struct scsi_tape_locate {
u_int8_t opcode;
u_int8_t byte1;
@ -253,18 +409,521 @@ struct scsi_tape_locate {
#define SA_SPOS_BT 0x04
u_int8_t reserved1;
u_int8_t blkaddr[4];
#define SA_SPOS_MAX_BLK 0xffffffff
u_int8_t reserved2;
u_int8_t partition;
u_int8_t control;
};
struct scsi_locate_16 {
u_int8_t opcode;
u_int8_t byte1;
#define SA_LC_IMMEDIATE 0x01
#define SA_LC_CP 0x02
#define SA_LC_DEST_TYPE_MASK 0x38
#define SA_LC_DEST_TYPE_SHIFT 3
#define SA_LC_DEST_OBJECT 0x00
#define SA_LC_DEST_FILE 0x01
#define SA_LC_DEST_SET 0x02
#define SA_LC_DEST_EOD 0x03
u_int8_t byte2;
#define SA_LC_BAM_IMPLICIT 0x00
#define SA_LC_BAM_EXPLICIT 0x01
u_int8_t partition;
u_int8_t logical_id[8];
u_int8_t reserved[3];
u_int8_t control;
};
struct scsi_report_density_support {
u_int8_t opcode;
u_int8_t byte1;
#define SRDS_MEDIA 0x01
#define SRDS_MEDIUM_TYPE 0x02
u_int8_t reserved[5];
u_int8_t length[2];
#define SRDS_MAX_LENGTH 0xffff
u_int8_t control;
};
struct scsi_density_hdr {
u_int8_t length[2];
u_int8_t reserved[2];
u_int8_t descriptor[];
};
struct scsi_density_data {
u_int8_t primary_density_code;
u_int8_t secondary_density_code;
u_int8_t byte2;
#define SDD_DLV 0x01
#define SDD_DEFLT 0x20
#define SDD_DUP 0x40
#define SDD_WRTOK 0x80
u_int8_t length[2];
#define SDD_DEFAULT_LENGTH 52
u_int8_t bits_per_mm[3];
u_int8_t media_width[2];
u_int8_t tracks[2];
u_int8_t capacity[4];
u_int8_t assigning_org[8];
u_int8_t density_name[8];
u_int8_t description[20];
};
struct scsi_medium_type_data {
u_int8_t medium_type;
u_int8_t reserved1;
u_int8_t length[2];
#define SMTD_DEFAULT_LENGTH 52
u_int8_t num_density_codes;
u_int8_t primary_density_codes[8];
u_int8_t media_width[2];
u_int8_t medium_length[2];
u_int8_t reserved2[2];
u_int8_t assigning_org[8];
u_int8_t medium_type_name[8];
u_int8_t description[20];
};
/*
* Security Protocol Specific values for the Tape Data Encryption protocol
* (0x20) used with SECURITY PROTOCOL IN. See below for values used with
* SECURITY PROTOCOL OUT. Current as of SSC4r03.
*/
#define TDE_IN_SUPPORT_PAGE 0x0000
#define TDE_OUT_SUPPORT_PAGE 0x0001
#define TDE_DATA_ENC_CAP_PAGE 0x0010
#define TDE_SUPPORTED_KEY_FORMATS_PAGE 0x0011
#define TDE_DATA_ENC_MAN_CAP_PAGE 0x0012
#define TDE_DATA_ENC_STATUS_PAGE 0x0020
#define TDE_NEXT_BLOCK_ENC_STATUS_PAGE 0x0021
#define TDE_GET_ENC_MAN_ATTR_PAGE 0x0022
#define TDE_RANDOM_NUM_PAGE 0x0030
#define TDE_KEY_WRAP_PK_PAGE 0x0031
/*
* Tape Data Encryption protocol pages used with SECURITY PROTOCOL IN and
* SECURITY PROTOCOL OUT.
*/
/*
* Tape Data Encryption In Support page (0x0000).
*/
struct tde_in_support_page {
uint8_t page_code[2];
uint8_t page_length[2];
uint8_t page_codes[];
};
/*
* Tape Data Encryption Out Support page (0x0001).
*/
struct tde_out_support_page {
uint8_t page_code[2];
uint8_t page_length[2];
uint8_t page_codes[];
};
/*
* Logical block encryption algorithm descriptor. This is reported in the
* Data Encryption Capabilities page.
*/
struct tde_block_enc_alg_desc {
uint8_t alg_index;
uint8_t reserved1;
uint8_t desc_length[2];
uint8_t byte4;
#define TDE_BEA_AVFMV 0x80
#define TDE_BEA_SDK_C 0x40
#define TDE_BEA_MAC_C 0x20
#define TDE_BEA_DELB_C 0x10
#define TDE_BEA_DECRYPT_C_MASK 0x0c
#define TDE_BEA_DECRYPT_C_EXT 0x0c
#define TDE_BEA_DECRYPT_C_HARD 0x08
#define TDE_BEA_DECRYPT_C_SOFT 0x04
#define TDE_BEA_DECRYPT_C_NO_CAP 0x00
#define TDE_BEA_ENCRYPT_C_MASK 0x03
#define TDE_BEA_ENCRYPT_C_EXT 0x03
#define TDE_BEA_ENCRYPT_C_HARD 0x02
#define TDE_BEA_ENCRYPT_C_SOFT 0x01
#define TDE_BEA_ENCRYPT_C_NO_CAP 0x00
uint8_t byte5;
#define TDE_BEA_AVFCLP_MASK 0xc0
#define TDE_BEA_AVFCLP_VALID 0x80
#define TDE_BEA_AVFCLP_NOT_VALID 0x40
#define TDE_BEA_AVFCLP_NOT_APP 0x00
#define TDE_BEA_NONCE_C_MASK 0x30
#define TDE_BEA_NONCE_C_SUPPORTED 0x30
#define TDE_BEA_NONCE_C_PROVIDED 0x20
#define TDE_BEA_NONCE_C_GENERATED 0x10
#define TDE_BEA_NONCE_C_NOT_REQUIRED 0x00
#define TDE_BEA_KADF_C 0x08
#define TDE_BEA_VCELB_C 0x04
#define TDE_BEA_UKADF 0x02
#define TDE_BEA_AKADF 0x01
uint8_t max_unauth_key_bytes[2];
uint8_t max_auth_key_bytes[2];
uint8_t lbe_key_size[2];
uint8_t byte12;
#define TDE_BEA_DKAD_C_MASK 0xc0
#define TDE_BEA_DKAD_C_CAPABLE 0xc0
#define TDE_BEA_DKAD_C_NOT_ALLOWED 0x80
#define TDE_BEA_DKAD_C_REQUIRED 0x40
#define TDE_BEA_EEMC_C_MASK 0x30
#define TDE_BEA_EEMC_C_ALLOWED 0x20
#define TDE_BEA_EEMC_C_NOT_ALLOWED 0x10
#define TDE_BEA_EEMC_C_NOT_SPECIFIED 0x00
/*
* Raw Decryption Mode Control Capabilities (RDMC_C) field. The
* descriptions are too complex to represent as a simple name.
*/
#define TDE_BEA_RDMC_C_MASK 0x0e
#define TDE_BEA_RDMC_C_MODE_7 0x0e
#define TDE_BEA_RDMC_C_MODE_6 0x0c
#define TDE_BEA_RDMC_C_MODE_5 0x0a
#define TDE_BEA_RDMC_C_MODE_4 0x08
#define TDE_BEA_RDMC_C_MODE_1 0x02
#define TDE_BEA_EAREM 0x01
uint8_t byte13;
#define TDE_BEA_MAX_EEDKS_MASK 0x0f
uint8_t msdk_count[2];
uint8_t max_eedk_size[2];
uint8_t reserved2[2];
uint8_t security_algo_code[4];
};
/*
* Data Encryption Capabilities page (0x0010).
*/
struct tde_data_enc_cap_page {
uint8_t page_code[2];
uint8_t page_length;
uint8_t byte4;
#define DATA_ENC_CAP_EXTDECC_MASK 0x0c
#define DATA_ENC_CAP_EXTDECC_NOT_REPORTED 0x00
#define DATA_ENC_CAP_EXTDECC_NOT_CAPABLE 0x04
#define DATA_ENC_CAP_EXTDECC_CAPABLE 0x08
#define DATA_ENC_CAP_CFG_P_MASK 0x03
#define DATA_ENC_CAP_CFG_P_NOT_REPORTED 0x00
#define DATA_ENC_CAP_CFG_P_ALLOWED 0x01
#define DATA_ENC_CAP_CFG_P_NOT_ALLOWED 0x02
uint8_t reserved[15];
struct tde_block_enc_alg_desc alg_descs[];
};
/*
* Tape Data Encryption Supported Key Formats page (0x0011).
*/
struct tde_supported_key_formats_page {
uint8_t page_code[2];
uint8_t page_length[2];
uint8_t key_formats_list[];
};
/*
* Tape Data Encryption Management Capabilities page (0x0012).
*/
struct tde_data_enc_man_cap_page {
uint8_t page_code[2];
uint8_t page_length[2];
uint8_t byte4;
#define TDE_DEMC_LOCK_C 0x01
uint8_t byte5;
#define TDE_DEMC_CKOD_C 0x04
#define TDE_DEMC_CKORP_C 0x02
#define TDE_DEMC_CKORL_C 0x01
uint8_t reserved1;
uint8_t byte7;
#define TDE_DEMC_AITN_C 0x04
#define TDE_DEMC_LOCAL_C 0x02
#define TDE_DEMC_PUBLIC_C 0x01
uint8_t reserved2[8];
};
/*
* Tape Data Encryption Status Page (0x0020).
*/
struct tde_data_enc_status_page {
uint8_t page_code[2];
uint8_t page_length[2];
uint8_t scope;
#define TDE_DES_IT_NEXUS_SCOPE_MASK 0xe0
#define TDE_DES_LBE_SCOPE_MASK 0x07
uint8_t encryption_mode;
uint8_t decryption_mode;
uint8_t algo_index;
uint8_t key_instance_counter[4];
uint8_t byte12;
#define TDE_DES_PARAM_CTRL_MASK 0x70
#define TDE_DES_PARAM_CTRL_MGMT 0x40
#define TDE_DES_PARAM_CTRL_CHANGER 0x30
#define TDE_DES_PARAM_CTRL_DRIVE 0x20
#define TDE_DES_PARAM_CTRL_EXT 0x10
#define TDE_DES_PARAM_CTRL_NOT_REPORTED 0x00
#define TDE_DES_VCELB 0x08
#define TDE_DES_CEEMS_MASK 0x06
#define TDE_DES_RDMD 0x01
uint8_t enc_params_kad_format;
uint8_t asdk_count[2];
uint8_t reserved[8];
uint8_t key_assoc_data_desc[];
};
/*
* Tape Data Encryption Next Block Encryption Status page (0x0021).
*/
struct tde_next_block_enc_status_page {
uint8_t page_code[2];
uint8_t page_length[2];
uint8_t logical_obj_number[8];
uint8_t status;
#define TDE_NBES_COMP_STATUS_MASK 0xf0
#define TDE_NBES_COMP_INCAPABLE 0x00
#define TDE_NBES_COMP_NOT_YET 0x10
#define TDE_NBES_COMP_NOT_A_BLOCK 0x20
#define TDE_NBES_COMP_NOT_COMPRESSED 0x30
#define TDE_NBES_COMP_COMPRESSED 0x40
#define TDE_NBES_ENC_STATUS_MASK 0x0f
#define TDE_NBES_ENC_INCAPABLE 0x00
#define TDE_NBES_ENC_NOT_YET 0x01
#define TDE_NBES_ENC_NOT_A_BLOCK 0x02
#define TDE_NBES_ENC_NOT_ENCRYPTED 0x03
#define TDE_NBES_ENC_ALG_NOT_SUPPORTED 0x04
#define TDE_NBES_ENC_SUPPORTED_ALG 0x05
#define TDE_NBES_ENC_NO_KEY 0x06
uint8_t algo_index;
uint8_t byte14;
#define TDE_NBES_EMES 0x02
#define TDE_NBES_RDMDS 0x01
uint8_t next_block_kad_format;
uint8_t key_assoc_data_desc[];
};
/*
* Tape Data Encryption Get Encryption Management Attributes page (0x0022).
*/
struct tde_get_enc_man_attr_page {
uint8_t page_code[2];
uint8_t reserved[3];
uint8_t byte5;
#define TDE_GEMA_CAOD 0x01
uint8_t page_length[2];
uint8_t enc_mgmt_attr_desc[];
};
/*
* Tape Data Encryption Random Number page (0x0030).
*/
struct tde_random_num_page {
uint8_t page_code[2];
uint8_t page_length[2];
uint8_t random_number[32];
};
/*
* Tape Data Encryption Device Server Key Wrapping Public Key page (0x0031).
*/
struct tde_key_wrap_pk_page {
uint8_t page_code[2];
uint8_t page_length[2];
uint8_t public_key_type[4];
uint8_t public_key_format[4];
uint8_t public_key_length[2];
uint8_t public_key[];
};
/*
* Security Protocol Specific values for the Tape Data Encryption protocol
* (0x20) used with SECURITY PROTOCOL OUT. See above for values used with
* SECURITY PROTOCOL IN. Current as of SSCr03.
*/
#define TDE_SET_DATA_ENC_PAGE 0x0010
#define TDE_SA_ENCAP_PAGE 0x0011
#define TDE_SET_ENC_MGMT_ATTR_PAGE 0x0022
/*
* Tape Data Encryption Set Data Encryption page (0x0010).
*/
struct tde_set_data_enc_page {
uint8_t page_code[2];
uint8_t page_length[2];
uint8_t byte4;
#define TDE_SDE_SCOPE_MASK 0xe0
#define TDE_SDE_SCOPE_ALL_IT_NEXUS 0x80
#define TDE_SDE_SCOPE_LOCAL 0x40
#define TDE_SDE_SCOPE_PUBLIC 0x00
#define TDE_SDE_LOCK 0x01
uint8_t byte5;
#define TDE_SDE_CEEM_MASK 0xc0
#define TDE_SDE_CEEM_ENCRYPT 0xc0
#define TDE_SDE_CEEM_EXTERNAL 0x80
#define TDE_SDE_CEEM_NO_CHECK 0x40
#define TDE_SDE_RDMC_MASK 0x30
#define TDE_SDE_RDMC_DISABLED 0x30
#define TDE_SDE_RDMC_ENABLED 0x20
#define TDE_SDE_RDMC_DEFAULT 0x00
#define TDE_SDE_SDK 0x08
#define TDE_SDE_CKOD 0x04
#define TDE_SDE_CKORP 0x02
#define TDE_SDE_CKORL 0x01
uint8_t encryption_mode;
#define TDE_SDE_ENC_MODE_DISABLE 0x00
#define TDE_SDE_ENC_MODE_EXTERNAL 0x01
#define TDE_SDE_ENC_MODE_ENCRYPT 0x02
uint8_t decryption_mode;
#define TDE_SDE_DEC_MODE_DISABLE 0x00
#define TDE_SDE_DEC_MODE_RAW 0x01
#define TDE_SDE_DEC_MODE_DECRYPT 0x02
#define TDE_SDE_DEC_MODE_MIXED 0x03
uint8_t algo_index;
uint8_t lbe_key_format;
#define TDE_SDE_KEY_PLAINTEXT 0x00
#define TDE_SDE_KEY_VENDOR_SPEC 0x01
#define TDE_SDE_KEY_PUBLIC_WRAP 0x02
#define TDE_SDE_KEY_ESP_SCSI 0x03
uint8_t kad_format;
#define TDE_SDE_KAD_ASCII 0x02
#define TDE_SDE_KAD_BINARY 0x01
#define TDE_SDE_KAD_UNSPECIFIED 0x00
uint8_t reserved[7];
uint8_t lbe_key_length[2];
uint8_t lbe_key[];
};
/*
* Used for the Vendor Specific key format (0x01).
*/
struct tde_key_format_vendor {
uint8_t t10_vendor_id[8];
uint8_t vendor_key[];
};
/*
* Used for the public key wrapped format (0x02).
*/
struct tde_key_format_public_wrap {
uint8_t parameter_set[2];
#define TDE_PARAM_SET_RSA2048 0x0000
#define TDE_PARAM_SET_ECC521 0x0010
uint8_t label_length[2];
uint8_t label[];
};
/*
* Tape Data Encryption SA Encapsulation page (0x0011).
*/
struct tde_sa_encap_page {
uint8_t page_code[2];
uint8_t data_desc[];
};
/*
* Tape Data Encryption Set Encryption Management Attributes page (0x0022).
*/
struct tde_set_enc_mgmt_attr_page {
uint8_t page_code[2];
uint8_t reserved[3];
uint8_t byte5;
#define TDE_SEMA_CAOD 0x01
uint8_t page_length[2];
uint8_t attr_desc[];
};
/*
* Tape Data Encryption descriptor format.
* SSC4r03 Section 8.5.4.2.1 Table 197
*/
struct tde_data_enc_desc {
uint8_t key_desc_type;
#define TDE_KEY_DESC_WK_KAD 0x04
#define TDE_KEY_DESC_M_KAD 0x03
#define TDE_KEY_DESC_NONCE_VALUE 0x02
#define TDE_KEY_DESC_A_KAD 0x01
#define TDE_KEY_DESC_U_KAD 0x00
uint8_t byte2;
#define TDE_KEY_DESC_AUTH_MASK 0x07
#define TDE_KEY_DESC_AUTH_FAILED 0x04
#define TDE_KEY_DESC_AUTH_SUCCESS 0x03
#define TDE_KEY_DESC_AUTH_NO_ATTEMPT 0x02
#define TDE_KEY_DESC_AUTH_U_KAD 0x01
uint8_t key_desc_length[2];
uint8_t key_desc[];
};
/*
* Wrapped Key descriptor format.
* SSC4r03 Section 8.5.4.3.1 Table 200
*/
struct tde_wrapped_key_desc {
uint8_t wrapped_key_type;
#define TDE_WRAP_KEY_DESC_LENGTH 0x04
#define TDE_WRAP_KEY_DESC_IDENT 0x03
#define TDE_WRAP_KEY_DESC_INFO 0x02
#define TDE_WRAP_KEY_DESC_ENTITY_ID 0x01
#define TDE_WRAP_KEY_DESC_DEVICE_ID 0x00
uint8_t reserved;
uint8_t wrapped_desc_length[2];
uint8_t wrapped_desc[];
};
/*
* Encryption management attributes descriptor format.
* SSC4r03 Section 8.5.4.4.1 Table 202
*/
struct tde_enc_mgmt_attr_desc {
uint8_t enc_mgmt_attr_type[2];
#define TDE_EMAD_DESIRED_KEY_MGR_OP 0x0000
#define TDE_EMAD_LOG_BLOCK_ENC_KEY_CRIT 0x0001
#define TDE_EMAD_LOG_BLOCK_ENC_KEY_WRAP 0x0002
uint8_t reserved;
uint8_t byte2;
#define TDE_EMAD_CRIT 0x80
uint8_t attr_length[2];
uint8_t attributes[];
#define TDE_EMAD_DESIRED_KEY_CREATE 0x0001
#define TDE_EMAD_DESIRED_KEY_RESOLVE 0x0002
};
/*
* Logical block encryption key selection criteria descriptor format.
* SSC4r03 Section 8.5.4.4.3.1 Table 206
*/
struct tde_lb_enc_key_sel_desc {
uint8_t lbe_key_sel_crit_type[2];
/*
* The CRIT bit is the top bit of the first byte of the type.
*/
#define TDE_LBE_KEY_SEL_CRIT 0x80
#define TDE_LBE_KEY_SEL_ALGO 0x0001
#define TDE_LBE_KEY_SEL_ID 0x0002
uint8_t lbe_key_sel_crit_length[2];
uint8_t lbe_key_sel_crit[];
};
/*
* Logical block encryption key wrapping attribute descriptor format.
* SSC4r03 Section 8.5.4.4.4.1 Table 209
*/
struct tde_lb_enc_key_wrap_desc {
uint8_t lbe_key_wrap_type[2];
/*
* The CRIT bit is the top bit of the first byte of the type.
*/
#define TDE_LBE_KEY_WRAP_CRIT 0x80
#define TDE_LBE_KEY_WRAP_KEKS 0x0001
uint8_t lbe_key_wrap_length[2];
uint8_t lbe_key_wrap_attr[];
};
/*
* Opcodes
*/
#define REWIND 0x01
#define FORMAT_MEDIUM 0x04
#define READ_BLOCK_LIMITS 0x05
#define SA_READ 0x08
#define SA_WRITE 0x0A
#define SET_CAPACITY 0x0B
#define WRITE_FILEMARKS 0x10
#define SPACE 0x11
#define RESERVE_UNIT 0x16
@ -273,6 +932,9 @@ struct scsi_tape_locate {
#define LOAD_UNLOAD 0x1B
#define LOCATE 0x2B
#define READ_POSITION 0x34
#define REPORT_DENSITY_SUPPORT 0x44
#define ALLOW_OVERWRITE 0x82
#define LOCATE_16 0x92
/*
* Tape specific density codes- only enough of them here to recognize
@ -352,11 +1014,55 @@ void scsi_read_position(struct ccb_scsiio *csio, u_int32_t retries,
u_int8_t tag_action, int hardsoft,
struct scsi_tape_position_data *sbp,
u_int8_t sense_len, u_int32_t timeout);
void scsi_read_position_10(struct ccb_scsiio *csio, u_int32_t retries,
void (*cbfcnp)(struct cam_periph *, union ccb *),
u_int8_t tag_action, int service_action,
u_int8_t *data_ptr, u_int32_t length,
u_int32_t sense_len, u_int32_t timeout);
void scsi_set_position(struct ccb_scsiio *csio, u_int32_t retries,
void (*cbfcnp)(struct cam_periph *, union ccb *),
u_int8_t tag_action, int hardsoft, u_int32_t blkno,
u_int8_t sense_len, u_int32_t timeout);
void scsi_locate_10(struct ccb_scsiio *csio, u_int32_t retries,
void (*cbfcnp)(struct cam_periph *, union ccb *),
u_int8_t tag_action, int immed, int cp, int hard,
int64_t partition, u_int32_t block_address,
int sense_len, u_int32_t timeout);
void scsi_locate_16(struct ccb_scsiio *csio, u_int32_t retries,
void (*cbfcnp)(struct cam_periph *, union ccb *),
u_int8_t tag_action, int immed, int cp,
u_int8_t dest_type, int bam, int64_t partition,
u_int64_t logical_id, int sense_len,
u_int32_t timeout);
void scsi_report_density_support(struct ccb_scsiio *csio, u_int32_t retries,
void (*cbfcnp)(struct cam_periph *,
union ccb *),
u_int8_t tag_action, int media,
int medium_type, u_int8_t *data_ptr,
u_int32_t length, u_int32_t sense_len,
u_int32_t timeout);
void scsi_set_capacity(struct ccb_scsiio *csio, u_int32_t retries,
void (*cbfcnp)(struct cam_periph *, union ccb *),
u_int8_t tag_action, int byte1, u_int32_t proportion,
u_int32_t sense_len, u_int32_t timeout);
void scsi_format_medium(struct ccb_scsiio *csio, u_int32_t retries,
void (*cbfcnp)(struct cam_periph *, union ccb *),
u_int8_t tag_action, int byte1, int byte2,
u_int8_t *data_ptr, u_int32_t length,
u_int32_t sense_len, u_int32_t timeout);
void scsi_allow_overwrite(struct ccb_scsiio *csio, u_int32_t retries,
void (*cbfcnp)(struct cam_periph *, union ccb *),
u_int8_t tag_action, int allow_overwrite,
int partition, u_int64_t logical_id,
u_int32_t sense_len, u_int32_t timeout);
__END_DECLS
#endif /* _SCSI_SCSI_SA_H */

View file

@ -80,6 +80,8 @@ struct mtop {
#define MTWSS 16 /* write setmark(s) */
#define MTFSS 17 /* forward space setmark */
#define MTBSS 18 /* backward space setmark */
#define MTLOAD 19 /* load tape in drive */
#define MTWEOFI 20 /* write an end-of-file record without waiting*/
#define MT_COMP_ENABLE 0xffffffff
#define MT_COMP_DISABLED 0xfffffffe
@ -176,6 +178,112 @@ union mterrstat {
char _reserved_padding[256];
};
struct mtrblim {
uint32_t granularity;
uint32_t min_block_length;
uint32_t max_block_length;
};
typedef enum {
MT_LOCATE_DEST_OBJECT = 0x00,
MT_LOCATE_DEST_FILE = 0x01,
MT_LOCATE_DEST_SET = 0x02,
MT_LOCATE_DEST_EOD = 0x03
} mt_locate_dest_type;
typedef enum {
MT_LOCATE_BAM_IMPLICIT = 0x00,
MT_LOCATE_BAM_EXPLICIT = 0x01
} mt_locate_bam;
typedef enum {
MT_LOCATE_FLAG_IMMED = 0x01,
MT_LOCATE_FLAG_CHANGE_PART = 0x02
} mt_locate_flags;
struct mtlocate {
mt_locate_flags flags;
mt_locate_dest_type dest_type;
mt_locate_bam block_address_mode;
int64_t partition;
uint64_t logical_id;
uint8_t reserved[64];
};
typedef enum {
MT_EXT_GET_NONE,
MT_EXT_GET_OK,
MT_EXT_GET_NEED_MORE_SPACE,
MT_EXT_GET_ERROR
} mt_ext_get_status;
struct mtextget {
uint32_t alloc_len;
char *status_xml;
uint32_t fill_len;
mt_ext_get_status status;
char error_str[128];
uint8_t reserved[64];
};
#define MT_EXT_GET_ROOT_NAME "mtextget"
#define MT_DENSITY_ROOT_NAME "mtdensity"
#define MT_MEDIA_DENSITY_NAME "media_density"
#define MT_DENSITY_REPORT_NAME "density_report"
#define MT_MEDIUM_TYPE_REPORT_NAME "medium_type_report"
#define MT_MEDIA_REPORT_NAME "media_report"
#define MT_DENSITY_ENTRY_NAME "density_entry"
#define MT_DENS_WRITE_OK 0x80
#define MT_DENS_DUP 0x40
#define MT_DENS_DEFLT 0x20
#define MT_PARAM_FIXED_STR_LEN 32
union mt_param_value {
int64_t value_signed;
uint64_t value_unsigned;
char *value_var_str;
char value_fixed_str[MT_PARAM_FIXED_STR_LEN];
uint8_t reserved[64];
};
typedef enum {
MT_PARAM_SET_NONE,
MT_PARAM_SET_SIGNED,
MT_PARAM_SET_UNSIGNED,
MT_PARAM_SET_VAR_STR,
MT_PARAM_SET_FIXED_STR
} mt_param_set_type;
typedef enum {
MT_PARAM_STATUS_NONE,
MT_PARAM_STATUS_OK,
MT_PARAM_STATUS_ERROR
} mt_param_set_status;
#define MT_PARAM_VALUE_NAME_LEN 64
struct mtparamset {
char value_name[MT_PARAM_VALUE_NAME_LEN];
mt_param_set_type value_type;
int value_len;
union mt_param_value value;
mt_param_set_status status;
char error_str[128];
};
#define MT_PARAM_ROOT_NAME "mtparamget"
#define MT_PROTECTION_NAME "protection"
/*
* Set a list of parameters.
*/
struct mtsetlist {
int num_params;
int param_len;
struct mtparamset *params;
};
/*
* Constants for mt_type byte. These are the same
* for controllers compatible with the types listed.
@ -218,6 +326,7 @@ union mterrstat {
#define MTIOCSLOCATE _IOW('m', 5, u_int32_t) /* seek to logical blk addr */
#define MTIOCHLOCATE _IOW('m', 6, u_int32_t) /* seek to hardware blk addr */
#define MTIOCERRSTAT _IOR('m', 7, union mterrstat) /* get tape errors */
/*
* Set EOT model- argument is number of filemarks to end a tape with.
* Note that not all possible values will be accepted.
@ -226,6 +335,13 @@ union mterrstat {
/* Get current EOT model */
#define MTIOCGETEOTMODEL _IOR('m', 8, u_int32_t)
#define MTIOCRBLIM _IOR('m', 9, struct mtrblim) /* get block limits */
#define MTIOCEXTLOCATE _IOW('m', 10, struct mtlocate) /* seek to position */
#define MTIOCEXTGET _IOWR('m', 11, struct mtextget) /* get tape status */
#define MTIOCPARAMGET _IOWR('m', 12, struct mtextget) /* get tape params */
#define MTIOCPARAMSET _IOWR('m', 13, struct mtparamset) /* set tape params */
#define MTIOCSETLIST _IOWR('m', 14, struct mtsetlist) /* set N params */
#ifndef _KERNEL
#define DEFTAPE "/dev/nsa0"
#endif

View file

@ -2,5 +2,7 @@
# $FreeBSD$
PROG= mt
DPADD= ${LIBMT} ${LIBSBUF} ${LIBBSDXML}
LDADD= -lmt -lsbuf -lbsdxml
.include <bsd.prog.mk>

View file

@ -29,7 +29,7 @@
.\" @(#)mt.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
.Dd January 20, 2008
.Dd February 12, 2014
.Dt MT 1
.Os
.Sh NAME
@ -71,6 +71,12 @@ which defaults to 1.
Write
.Ar count
end-of-file (EOF) marks at the current position.
This returns when the file mark has been written to the media.
.It Cm weofi
Write
.Ar count
end-of-file (EOF) marks at the current position.
This returns as soon as the command has been validated by the tape drive.
.It Cm smk
Write
.Ar count
@ -129,6 +135,8 @@ Rewind the tape.
.It Cm offline , rewoffl
Rewind the tape and place the drive off line.
Some drives are never off line.
.It Cm load
Load the tape into the drive.
.It Cm retension
Re-tension the tape.
This winds the tape from the current position to the end
@ -136,7 +144,7 @@ and then to the beginning.
This sometimes improves subsequent reading and writing,
particularly for streaming drives.
Some drives do not support this.
.It Cm status
.It Cm ostatus
Output status information about the drive.
For SCSI magnetic tape devices,
the current operating modes of density, blocksize, and whether compression
@ -149,6 +157,9 @@ Note
that this information is not definitive (only BOT, End of Recorded Media, and
hardware or SCSI logical block position (if the drive supports such) are
considered definitive tape positions).
.Pp
Also note that this is the old status command, and will be eliminated in
favor of the new status command (see below) in a future release.
.It Cm errstat
Output (and clear) error status information about this device.
For every normal
@ -165,9 +176,12 @@ many filemarks will be written at close if a tape was being written.
.It Cm eod , eom
Wind the tape to the end of the recorded data,
typically after an EOF mark where another file may be written.
.It Cm rblim
Report the block limits of the tape drive, including the minimum and
maximum block size, and the block granularity if any.
.El
.Pp
The following commands require an
The following commands may require an
.Ar argument .
.Bl -tag -width ".Cm seteotmodel"
.It Cm sethpos
@ -199,6 +213,180 @@ You may only choose a value of
.Ar 1
or
.Ar 2 .
.It Cm status
Output status information about the drive.
For SCSI magnetic tape devices,
the current operating modes of density, blocksize, and whether compression
is enabled is reported.
The current state of the driver (what it thinks that
it is doing with the device) is reported.
.Pp
If the driver knows the relative
position from BOT (in terms of filemarks and records), it outputs that.
If the tape drive supports the long form report of the
.Tn SCSI
READ POSITION command, the Reported File Number and Reported Record Number
will be numbers other than -1, and there may be Flags reported as well.
.Pp
The BOP flag means that the logical position of the drive is at the
beginning of the partition.
.Pp
The EOP flag means that the logical position of the drive is between Early
Warning and End of Partition.
.Pp
The BPEW flag means that the logical position of the drive is in a
Programmable Early Warning Zone or on the EOP side of Early Warning.
.Pp
Note that the Reported Record Number is the tape block or object number
relative to the beginning of the partition.
The Calculated Record Number is the tape block or object number relative
to the previous file mark.
.Pp
Note
that the Calculated File and Record Numbers are not definitive.
The Reported File and Record Numbers are definitive, if they are numbers
other than -1.
.Bl -tag -width 6n
.It Fl v
Print additional status information, such as the maximum supported I/O
size.
.It Fl x
Print all available status data to stdout in XML format.
.El
.It Cm getdensity
Report density support information for the tape drive and any media that is
loaded.
Most drives will report at least basic density information similar to that
reported by
.Nm status
command.
Newer tape drives that conform to the T-10 SSC and newer tape
specifications may report more detailed information about the types of
tapes they support and the tape currently in the drive.
.Bl -tag -width 6n
.It Fl x
Print all available density data to stdout in XML format.
Because density information is currently included in the general status XML
report used for
.Nm
status command, this will be the same XML output via
.Do
.Nm
status
.Fl x
.Dc
.El
.It Cm param
Display or set parameters.
One of
.Fl l ,
.Fl s ,
or
.Fl x
must be specified to indicate which operation to perform.
.Bl -tag -width 8n
.It Fl l
List parameters, values and descriptions.
By default all parameters will be displayed.
To display a specific parameter, specify the parameter with
.Fl p .
.It Fl p Ar name
Specify the parameter name to list (with
.Fl l )
or set (with
.Fl s ) .
.It Fl q
Enable quiet mode for parameter listing.
This will suppress printing of parameter descriptions.
.It Fl s Ar value
Specify the parameter value to set.
The general type of this argument (integer, unsigned integer, string) is
determined by the type of the variable indicated by the
.Xr sa 4
driver.
More detailed argument checking is done by the
.Xr sa 4
driver.
.It Fl x
Print out all parameter information in XML format.
.El
.It Cm protect
Display or set drive protection parameters.
This is used to control checking and reporting a per-block checksum for
tape drives that support it.
Some drives may only support some parameters.
.Bl -tag -width 8n
.It Fl b Ar 0|1
Set the Recover Buffered Data Protected bit.
If set, this indicates that checksums are transferred with the logical
blocks transferred by the RECOVERED BUFFERED DATA
.Tn SCSI
command.
.It Fl d
Disable all protection information settings.
.It Fl e
Enable all protection information settings.
The default protection method used is Reed-Solomon CRC (protection method
1), as specified in ECMA-319.
The default protection information length used with Reed-Solomon CRC is
4 bytes.
To enable all settings except one more more settings, specify the
.Fl e
argument and then explicitly disable settings that you do not wish to
enable.
For example, specifying
.Fl e
.Fl w Ar 0
will enable all settings except for LBP_W.
.It Fl l
List available protection parmeters and their current settings.
.It Fl L Ar len
Set the length of the protection information in bytes.
For Reed-Solomon CRC, the protection information length should be 4 bytes.
.It Fl m Ar num
Specify the numeric value for the protection method.
The numeric value for Reed-Solomon CRC is 1.
.It Fl r Ar 0|1
Set the LBP_R parameter.
When set, this indicates that each block read from the tape drive will
have a checksum at the end.
.It Fl v
Enable verbose mode for parameter listing.
This will include descriptions of each parameter.
.It Fl w Ar 0|1
Set the LBP_W parameter.
When set, this indicates that each block written to the tape drive will have
a checksum at the end.
The drive will verify the checksum before writing the block to tape.
.El
.It Cm locate
Set the tape drive's logical position.
One of
.Fl b ,
.Fl e ,
.Fl f ,
or
.Fl s
must be specified to indicate the type of position.
If the partition number is specified, the drive will first relocate to the
given partition (if it exists) and then to the position indicated within
that partition.
If the partition number is not specified, the drive will relocate to the
given position within the current partition.
.Bl -tag -width 14n
.It Fl b Ar block_addr
Relocate to the given tape block or logical object identifier.
Note that the block number is the Reported Record Number that is relative
to the beginning of the partition (or beginning of tape).
.It Fl e
Relocate to the end of data.
.It Fl f Ar fileno
Relocate to the given file number.
.It Fl p Ar partition
Specify the partition to change to.
.It Fl s Ar setmark
Relocate to the given set mark.
.El
.It Cm comp
Set the drive's compression mode.
The non-numeric values of
@ -234,6 +422,13 @@ If this is not the case (see the
display to see which compression algorithm is currently in use), the user
can manually specify one of the supported compression keywords (above), or
supply a numeric compression value from the drive's specifications.
.Pp
Note that for some older tape drives (for example the Exabyte 8200 and 8500
series drives) it is necessary to switch to a different density to tell the
drive to record data in its compressed format.
If the user attempts to turn compression on while the uncompressed density
is selected, the drive will return an error.
This is generally not an issue for modern tape drives.
.It Cm density
Set the density for the drive.
For the density codes, see below.
@ -249,13 +444,14 @@ exactly, an informational message is output about what the given
string has been taken for.
.El
.Pp
The following density table was taken from the
The initial version of the density table below was taken from the
.Sq Historical sequential access density codes
table (A-1) in Revision 11 of the SCSI-3 Stream Device Commands (SSC)
working draft, dated November 11, 1997.
Subsequent additions have come from a number of sources.
.Pp
The density codes are:
.Bd -literal -offset 3n
.Bd -literal -offset 2n
0x0 default for device
0xE reserved for ECMA
@ -278,8 +474,8 @@ Value Width Tracks Density Code Type Reference Note
0x11 6.3 (0.25) 26 630 (16,000) GCR C QIC-320 1,6
0x12 6.3 (0.25) 30 2,034 (51,667) RLL C QIC-1350 1,6
0x13 3.81 (0.15) 1 2,400 (61,000) DDS CS X3B5/88-185A 5
0x14 8.0 (0.315) 1 1,703 (43,245) RLL CS X3.202-1991 5
0x15 8.0 (0.315) 1 1,789 (45,434) RLL CS ECMA TC17 5
0x14 8.0 (0.315) 1 1,703 (43,245) RLL CS X3.202-1991 5,11
0x15 8.0 (0.315) 1 1,789 (45,434) RLL CS ECMA TC17 5,12
0x16 12.7 (0.5) 48 394 (10,000) MFM C X3.193-1990 1
0x17 12.7 (0.5) 48 1,673 (42,500) MFM C X3B5/91-174 1
0x18 12.7 (0.5) 112 1,673 (42,500) MFM C X3B5/92-50 1
@ -302,11 +498,33 @@ Value Width Tracks Density Code Type Reference Note
0x29 12.7 (0.5)
0x2A
0x2B 12.7 (0.5) 3 ? ? ? C X3.267 5
0x40 12.7 (0.5) 384 4,800 (123,952) C LTO-1
0x41 12.7 (0.5) 208 3,868 (98,250) RLL C DLTapeIV(40) 6,7
0x42 12.7 (0.5) 512 7,398 (187,909) C LTO-2
0x44 12.7 (0.5) 704 9,638 (244,805) C LTO-3
0x46 12.7 (0.5) 896 12,725 (323,215) C LTO-4
0x48 12.7 (0.5) 448 5,236 (133,000) PRML C SDLTapeI(110) 6,8
0x49 12.7 (0.5) 448 7,598 (193,000) PRML C SDLTapeI(160) 6,8
0x4A 12.7 (0.5) 768 ? C T10000A 10
0x4B 12.7 (0.5) 1152 ? C T10000B 10
0x4C 12.7 (0.5) 3584 ? C T10000C 10
0x4D 12.7 (0.5) 4608 ? C T10000D 10
0x51 12.7 (0.5) 512 11,800 (299,720) C 3592A1 (unencrypted)
0x52 12.7 (0.5) 896 11,800 (299,720) C 3592A2 (unencrypted)
0x53 12.7 (0.5) 1152 13,452 (341,681) C 3592A3 (unencrypted)
0x54 12.7 (0.5) 2560 19,686 (500,024) C 3592A4 (unencrypted)
0x55 12.7 (0.5) 5120 20,670 (525,018) C 3592A5 (unencrypted)
0x58 12.7 (0.5) 1280 15,142 (384,607) C LTO-5
0x5A 12.7 (0.5) 2176 15,142 (384,607) C LTO-6
0x71 12.7 (0.5) 512 11,800 (299,720) C 3592A1 (encrypted)
0x72 12.7 (0.5) 896 11,800 (299,720) C 3592A2 (encrypted)
0x73 12.7 (0.5) 1152 13,452 (341,681) C 3592A3 (encrypted)
0x74 12.7 (0.5) 2560 19,686 (500,024) C 3592A4 (encrypted)
0x75 12.7 (0.5) 5120 20,670 (525,018) C 3592A5 (encrypted)
0x8c 8.0 (0.315) 1 1,789 (45,434) RLL CS EXB-8500c 5,9
0x90 8.0 (0.315) 1 1,703 (43,245) RLL CS EXB-8200c 5,9
.Ed
.Bd -literal -offset 3n
.Bd -literal -offset 2n
Code Description Type Description
---- -------------------------------------- ---- -----------
NRZI Non return to zero, change on ones R Reel-to-reel
@ -318,18 +536,26 @@ DDS DAT data storage
RLL Run length limited
PRML Partial Response Maximum Likelihood
.Ed
.Bd -literal -offset 3n
.Bd -literal -offset 2n
NOTES
1. Serial recorded.
2. Parallel recorded.
3. Old format known as QIC-11.
5. Helical scan.
6. This is not an American National Standard. The reference is based on
an industry standard definition of the media format.
7. DLT recording: serially recorded track pairs (DLTapeIII and
DLTapeIV(20)), or track quads (DLTapeIV(35) and DLTapeIV(40)).
8. Super DLT (SDLT) recording: 56 serially recorded logical tracks with
8 physical tracks each.
1. Serial recorded.
2. Parallel recorded.
3. Old format known as QIC-11.
5. Helical scan.
6. This is not an American National Standard. The reference is based
on an industry standard definition of the media format.
7. DLT recording: serially recorded track pairs (DLTapeIII and
DLTapeIV(20)), or track quads (DLTapeIV(35) and DLTapeIV(40)).
8. Super DLT (SDLT) recording: 56 serially recorded logical tracks
with 8 physical tracks each.
9. Vendor-specific Exabyte density code for compressed format.
10. bpi/bpmm values for the Oracle/StorageTek T10000 tape drives are
not listed in the manual. Someone with access to a drive can
supply the necessary values by running 'mt getdensity'.
11. This is Exabyte 8200 uncompressed format. The compressed format
density code is 0x90.
12. This is Exabyte 8500 uncompressed format. The compressed format
density code is 0x8c.
.Ed
.Sh ENVIRONMENT
.Bl -tag -width ".Ev TAPE"
@ -343,8 +569,6 @@ option.
.El
.Sh FILES
.Bl -tag -width ".Pa /dev/*sa[0-9]*" -compact
.It Pa /dev/*wt*
QIC-02/QIC-36 magnetic tape interface
.It Pa /dev/*sa[0-9]*
SCSI magnetic tape interface
.El
@ -357,7 +581,6 @@ Some undocumented commands support old software.
.Sh SEE ALSO
.Xr dd 1 ,
.Xr ioctl 2 ,
.Xr ast 4 ,
.Xr mtio 4 ,
.Xr sa 4 ,
.Xr environ 7

File diff suppressed because it is too large Load diff