---
name: "targ"
section: "4freebsd"
platform: "linux"
package: "freebsd-manpages"
version: "12.2-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/targ/4freebsd"
---

# targ(4freebsd)

SCSI target emulator driver

## NAME

**targ** – SCSI target emulator driver

## SYNOPSIS

To compile this driver into the kernel, place the following line in your kernel configuration file:

**device targ**

## DESCRIPTION

The **targ** driver provides an interface for usermode programs to emulate SCSI target devices. A sample program that emulates a disk drive (similar to [da(4)](/da/4.md)) can be found in */usr/share/examples/scsi\_target*.

The **targ** driver supplies the control device */dev/targ*. After opening the device, the file descriptor must be bound to a specific bus/target/LUN and enabled to process CCBs using the TARGIOCENABLE ioctl. The process then uses [write(2)](/write/2.md) to send CCBs to the SIM and [poll(2)](/poll/2.md) or [kqueue(2)](/kqueue/2.md) to see if responses are ready. Pointers to completed CCBs are returned via [read(2)](/read/2.md). Any data transfers requested by the user CCBs are done via zero-copy IO.

## IOCTLS

The following [ioctl(2)](/ioctl/2.md) calls are defined in the header file ⟨cam/scsi/scsi\_targetio.h⟩.

- TARGIOCENABLE

  (*struct ioc\_enable\_lun*) Enable target mode on the LUN specified by the following structure:

  ```
  struct ioc_enable_lun {
  	path_id_t	path_id;
  	target_id_t	target_id;
  	lun_id_t	lun_id;
  	int		grp6_len;
  	int		grp7_len;
  };
  ```

  The selected path (bus), target, and LUN must not already be in use or EADDRINUSE is returned. If *grp6\_len* or *grp7\_len* are non-zero, reception of vendor-specific commands is enabled.

- TARGIOCDISABLE

  Disable target mode and abort all pending CCBs. The CCBs may optionally be read as they complete. TARGIOCENABLE can then be called to activate a different LUN. Multiple disable calls have no effect. The [close(2)](/close/2.md) system call automatically disables target mode if enabled.

- TARGIOCDEBUG

  (*int*) Enables CAM\_PERIPH debugging if the argument is non-zero, otherwise disables it.

## FILES

- In cam/scsi/scsi\_targetio.h

  describes the usermode interface.

- */sys/cam/scsi/scsi\_target.c*

  is the driver source file.

- */dev/targ*

  is the control device.

## SEE ALSO

*/usr/share/examples/scsi\_target*, [ahc(4)](/ahc/4.md), [isp(4)](/isp/4.md), [scsi(4)](/scsi/4.md) *FreeBSD Target Information*, http://www.root.org/~nate/freebsd/.

## AUTHORS

The **targ** driver first appeared in FreeBSD 3.0 and was written by Justin T. Gibbs. It was rewritten for FreeBSD 5.0 by Nate Lawson ⟨*nate@root.org*⟩.

## BUGS

Currently, only the [ahc(4)](/ahc/4.md) and [isp(4)](/isp/4.md) drivers fully support target mode.

The [ahc(4)](/ahc/4.md) driver does not support tagged queuing in target mode.
