1.\" Copyright (c) 2002
2.\"	Nate Lawson.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the author nor the names of any co-contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY Nate Lawson AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\" $FreeBSD: src/share/examples/scsi_target/scsi_target.8,v 1.2.4.1 2003/02/18 22:07:10 njl Exp $
29.\" $DragonFly: src/share/examples/scsi_target/scsi_target.8,v 1.3 2006/02/17 19:37:09 swildner Exp $
30.\"
31.Dd November 15, 2002
32.Dt SCSI_TARGET 8
33.Os
34.Sh NAME
35.Nm scsi_target
36.Nd usermode SCSI disk emulator
37.Sh SYNOPSIS
38.Nm
39.Op Fl AdST
40.Op Fl b Ar size
41.Op Fl c Ar size
42.Op Fl s Ar size
43.Op Fl W Ar num
44.Ar bus : Ns Ar target : Ns Ar lun
45.Ar filename
46.Sh DESCRIPTION
47The
48.Nm
49utility emulates a SCSI target device using the
50.Xr targ 4
51device driver.
52It supports the basic commands of a direct access device, like
53.Xr da 4 .
54In typical operation, it opens a control device and
55enables target mode for the specified LUN.
56It then communicates with
57the SIM using CCBs exchanged via
58.Xr read 2
59and
60.Xr write 2 .
61READ and WRITE CDBs are satisfied with the specified backing store file.
62.Pp
63For performance, all backing store accesses use
64.Xr aio 4 .
65Thus,
66.Nm
67requires a kernel compiled with
68.Cd "options VFS_AIO" .
69.Pp
70Options:
71.Bl -tag -width indent
72.It Fl A
73Enable 16 addresses if supported by the SIM.
74Default is 8.
75.It Fl S
76Enable synchronous transfers if supported by the SIM.
77Default is disabled.
78.It Fl T
79Enable tagged queuing if supported by the SIM.
80Default is no tagged queuing.
81.It Fl W Cm 8 | 16 | 32
82Enable 16 or 32 bit wide transfers if supported by the SIM.
83Default is 8.
84.It Fl b Ar bufsize
85Set buffer size for transfers.
86Transfers larger than this will be split into multiple transfers.
87.It Fl c Ar sectorsize
88Set sector size for emulated volume.
89Default is 512.
90.It Fl d
91Enable debugging output in
92.Nm
93and its associated control device.
94.It Fl s Ar volsize
95Use a different size for the emulated volume.
96Must be less than or equal to the size of
97.Ar filename .
98.El
99.Pp
100Required arguments:
101.Bl -tag -width indent
102.It Ar bus : Ns Ar target : Ns Ar lun
103Attach to specified bus ID, target ID, and LUN.
104.It Ar filename
105File to use as a backing store.
106.El
107.Pp
108All options default to the minimal functionality of SCSI-1.
109To be safe,
110.Nm
111checks the SIM for the requested capability before enabling target mode.
112.Sh FILES
113.Bl -tag -width ".Pa /usr/share/examples/scsi_target" -compact
114.It Pa /dev/targ*
115Control devices.
116.It Pa /usr/share/examples/scsi_target
117Source directory.
118.El
119.Sh EXAMPLES
120Create a 5 megabyte backing store file.
121.Pp
122.Dl "dd if=/dev/zero of=vol size=1m count=5"
123.Pp
124Enable target mode on bus 0, target ID 1, LUN 0, using
125.Pa vol
126as the backing store for READ6/10 and WRITE6/10 commands.
127Only the first 1000 bytes of
128.Pa vol
129will be used.
130Debugging information will be output.
13116-bit wide transfers will be used if the SIM supports them.
132.Pp
133.Dl "scsi_target -d -v 1000 -W 16 0:1:0 vol"
134.Sh SEE ALSO
135.Xr scsi 4 ,
136.Xr targ 4
137.Sh AUTHORS
138.An -nosplit
139The
140.Nm
141example first appeared in
142.Fx 3.0
143and was written by
144.An Justin T. Gibbs .
145It was rewritten for
146.Fx 5.0
147by
148.An Nate Lawson Aq nate@root.org .
149