1.\" $OpenBSD: scsi.8,v 1.35 2015/02/28 21:51:57 bentley Exp $ 2.\" $FreeBSD: scsi.8,v 1.5 1995/05/05 20:41:58 dufault Exp $ 3.\" 4.\" Written By Julian ELischer 5.\" Copyright julian Elischer 1993. 6.\" Permission is granted to use or redistribute this file in any way as long 7.\" as this notice remains. Julian Elischer does not guarantee that this file 8.\" is totally correct for any given task and users of this file must 9.\" accept responsibility for any damage that occurs from the application of 10.\" this file. 11.\" 12.\" (julian@tfs.com julian@dialix.oz.au) 13.\" User SCSI hooks added by Peter Dufault: 14.\" 15.\" Copyright (c) 1994 HD Associates 16.\" (contact: dufault@hda.com) 17.\" All rights reserved. 18.\" 19.\" Redistribution and use in source and binary forms, with or without 20.\" modification, are permitted provided that the following conditions 21.\" are met: 22.\" 1. Redistributions of source code must retain the above copyright 23.\" notice, this list of conditions and the following disclaimer. 24.\" 2. Redistributions in binary form must reproduce the above copyright 25.\" notice, this list of conditions and the following disclaimer in the 26.\" documentation and/or other materials provided with the distribution. 27.\" 3. The name of HD Associates 28.\" may not be used to endorse or promote products derived from this software 29.\" without specific prior written permission. 30.\" 31.\" THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES ``AS IS'' AND 32.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34.\" ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES BE LIABLE 35.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41.\" SUCH DAMAGE. 42.\" 43.Dd $Mdocdate: February 28 2015 $ 44.Dt SCSI 8 45.Os 46.Sh NAME 47.Nm scsi 48.Nd program to assist with SCSI devices 49.Sh SYNOPSIS 50.Nm scsi 51.Fl f Ar device 52.Fl d Ar debug_level 53.Nm scsi 54.Fl f Ar device 55.Fl m Ar page 56.Op Fl e 57.Op Fl P Ar pc 58.Nm scsi 59.Fl f Ar device 60.Op Fl v 61.Op Fl s Ar seconds 62.Fl c Ar cmd_fmt 63.Op Ar arg ... 64.Fl o Ar count out_fmt 65.Op Ar arg ... 66.Fl i Ar count in_fmt 67.Op Ar arg ... 68.Sh DESCRIPTION 69The 70.Nm 71program is used to send commands to a SCSI device. 72It is also a sample usage of the user-level SCSI commands. 73.Ar out_fmt 74can be 75.Ql - 76to read output data from stdin; 77.Ar in_fmt 78can be 79.Ql - 80to write input data to stdout. 81.Pp 82The options are as follows: 83.Bl -tag -width Ds 84.It Xo 85.Fl c Ar cmd_fmt Op Ar arg ... 86.Xc 87Send a user-level SCSI command to a device. 88The command format is described below and the command is sent using the 89.Dv SCIOCCOMMAND 90.Xr ioctl 2 , 91so the device being accessed must permit this ioctl. 92See 93.Xr scsi 4 94for full details of which minor devices permit the ioctl. 95.It Fl d Ar debug_level 96Sets the SCSI kernel debug level. 97The kernel must have been compiled with the 98.Ic SCSIDEBUG 99option. 100See 101.Pa /sys/scsi/scsi_debug.h 102to figure out what to set the kernel debug level to. 103.It Fl e 104Permits edit of the fields. 105It will use the editor specified by the 106.Ev EDITOR 107environment variable. 108To store changes permanently, edit page control 3 using the 109.Fl P 110flag. 111.It Fl f Ar device 112Specifies the 113.Ar device 114that should be opened, e.g., 115.Pa /dev/rsd0c . 116.It Xo 117.Fl i Ar count in_fmt Op Ar arg ... 118.Xc 119Indicates that this is an input command (i.e., data will be read from 120the device into the system) with 121.Ar count 122bytes of data read in. 123The information is extracted according to 124.Ar in_fmt 125and is displayed on standard output. 126.Ar in_fmt 127can be specified as a hyphen 128.Pq Ql - 129to indicate that 130.Ar count 131bytes of data input should be written to standard output. 132.It Fl m Ar page 133Read a device mode page. 134The file 135.Pa /usr/share/misc/scsi_modes 136is read to discover how to interpret the mode data. 137The environment variable 138.Ev SCSI_MODES 139can specify a different file to use. 140.It Xo 141.Fl o Ar count out_fmt Op Ar arg ... 142.Xc 143Indicates that this is an output command (i.e., data will be sent from 144the system to the device) with 145.Ar count 146bytes of data. 147The data is built up 148using the provided arguments to fill in any integer variables. 149.Ar out_fmt 150can be specified as a hyphen 151.Pq Ql - 152to indicate that 153.Ar count 154bytes of data should be read from standard input. 155.It Fl P Ar pc 156Specify a page control field. 157The page control fields are 158.Bd -literal -offset indent 1590 Current Values 1601 Changeable Values 1612 Default Values 1623 Saved Values 163.Ed 164.It Fl s Ar seconds 165Sets the command timeout to 166.Ar seconds . 167The default is two seconds. 168.It Fl v 169Turns on more verbose information. 170.El 171.Ss SCSI commands 172The command arguments to the 173.Fl cio 174options specify the command data buffer used to both send and receive 175information to and from the 176.Xr scsi 4 177subsystem. 178Their format is: 179.Pp 180.Dl Fl c Ar command Op Ar argument ... 181.Pp 182The commands are composed of a list of field specifiers. 183The specifiers denote the field name, the field value, and the length of 184the field. 185Examples are given below. 186.Pp 187Whitespace and text following a 188.Sq # 189character in the command string are ignored. 190.Pp 191The first part of a field specifier is the field name and is surrounded 192by curly braces 193.Pq Sq {} . 194This part is optional and may be left out. 195.Pp 196The second part is the value of the field. 197The value may be given directly or may arrange that the next argument to 198the 199.Nm 200command be used as the value of the field. 201Direct hexadecimal 202.Pq Li 0\-FF 203or decimal 204.Pq 0\-255 205values may be specified. 206The special value 207.Ic v 208can be used to arrange that the next integer argument be taken from the 209.Ar argument 210list. 211For retrieving output (with 212.Fl i ) , 213this part of the field cannot be used. 214.Pp 215The third part specifies the length of the field. 216This is optional and defaults to one byte if not specified. 217The length may be specified in bits by prefixing it with 218.Ic b 219or 220.Ic t , 221or in bytes by prefixing it with 222.Ic i . 223Additionally, character arrays can be specified by prefixing with 224.Ic c 225or, with zeroed trailing spaces, with 226.Ic z . 227Bits are packed together tightly and begin with the high bit. 228New bytes are started when a byte fills or an 229.Ic i 230field is next. 231.Ic i 232fields indicate a 1\-4 byte integral value that must already be given in 233SCSI byte order (most significant byte first). 234Otherwise, the field value specified will be swapped into SCSI byte order. 235.Pp 236Retrieving data (with 237.Fl i ) 238follows similarly but without field values. 239Besides field specifiers, the command can also include control operations, 240which currently includes seeking operations used to ignore returned data. 241Seek operations are composed of the 242.Ic s 243character followed by the absolute position to skip to. 244If the position is prefixed with a 245.Ic + , 246the position is interpreted relative to the current position. 247.\" The position can also be read from the 248.\" .Ar arg 249.\" list if 250.\" .Ic v 251.\" is specified as the seek value. 252.Pp 253Entire fields can be suppressed from being returned with the 254.Ic * 255modifier prepended to the field width. 256.Pp 257Here are some examples: 258.Bl -tag -width 17n 259.It Ic s8 z8 z16 z4 260Seek to position 8 and specify three fields of lengths 8 bytes, 16 261bytes, and 4 bytes. 262.It Ic 1A 2 263Specify a one-byte field with the hexadecimal value 264.Li 0x1A 265followed by another one-byte field with the decimal value 2. 266.It Ic v:i1 267Specify a one-byte field whose value will be determined from the 268next argument in the 269.Ar argument 270list. 271.It Ic 0:7 272Specify a 7-bit field with a value of zero. 273.It Ic *b3 b5 274Specify a three-bit field that will be suppressed from being returned 275and a five-bit field that will be returned. 276.El 277.Sh ENVIRONMENT 278.Bl -tag -width SU_DEBUG_TRUNCATE 279.It Ev SU_DEBUG_OUTPUT 280This 281variable can be set to a file to send debugging 282output to that file. 283.It Dv SU_DEBUG_LEVEL 284This 285variable can be set to a non-zero integer to increase 286the level of debugging. 287Currently this is an on or off thing; it should 288perhaps use the ioctl to set the debug level in the kernel and then set 289it back to zero at program exit. 290.It Ev SU_DEBUG_TRUNCATE 291This 292variable can be set to an integer to limit the 293amount of data phase output sent to the debugging file. 294.It Ev EDITOR 295This 296variable determines the editor to use for the mode editor. 297.El 298.Sh FILES 299.Bl -tag -width /usr/share/misc/scsi_modes 300.It Pa /usr/share/misc/scsi_modes 301.El 302.Sh EXIT STATUS 303.Ex -std scsi 304.Sh EXAMPLES 305To verify that the device type for the disk 306.Pa /dev/rsd0c 307is 0 308(direct access device): 309.Bd -literal -offset indent 310# scsi -f /dev/rsd0c -c "12 0 0 0 64 0" -i 0x64 "*b3 b5" 3110 312.Ed 313.Pp 314To do an inquiry to 315.Pa /dev/rsd2c : 316.Bd -literal -offset indent 317# scsi -f /dev/rsd2c -c "12 0 0 0 64 0" -i 0x64 "s8 z8 z16 z4" 318FUJITSU M2654S-512 010P 319.Ed 320.Pp 321To spin down 322.Pa /dev/rsd2c : 323.Bd -literal -offset indent 324# scsi -f /dev/rsd2c -c "1b 0 0 0 0 0" 325.Ed 326.Pp 327To edit mode page 1 on 328.Pa /dev/rsd2c 329and store it permanently on the 330drive (set AWRE and ARRE to 1 to enable bad block remapping): 331.Pp 332.Dl # scsi -f /dev/rsd2c -m 1 -e -P 3 333.Sh SEE ALSO 334.Xr ioctl 2 , 335.Xr scsi 4 336.Sh HISTORY 337The 338.Nm 339command appeared in 386BSD 0.1.2.4/FreeBSD to support the new reprobe 340and user SCSI commands. 341.Sh BUGS 342.Ic scsi\ -f /dev/rsd0c -c \(dq4 0 0 0 0 0\(dq 343permits anyone who can write to 344.Pa /dev/rsd0c 345to format the disk drive. 346