TARG(4)
π TARG(4) β SCSI target emulator driver π
okay bestie, sit down, we're learning about targ from the Kernel Interfaces Manual, and honestly? it's giving main character energy. β¨
πΈ NAME πΈ
targ β the SCSI target emulator driver. yes that's it, that's the whole name, slay. π
π¦ SYNOPSIS π¦
so if you wanna compile this driver into the kernel (no cap, it's a kernel-config situation), you drop this line into your kernel configuration file:
device targ
that's the whole thing. iconic. π
β¨ DESCRIPTION β¨
okay so here's the tea: the targ driver gives usermode programs an interface to emulate SCSI target devices. and if you want a whole example of it doing its thing, there's a sample program that emulates a disk drive β lowkey similar to da(4) β living right here: /usr/share/examples/scsi_target. go look, it's right there. π«Ά
the targ driver hands you the control device /dev/targ. so the flow is:
- you open the device π
- the file descriptor has to be bound to a specific bus/target/LUN and enabled to process CCBs β that's the
TARGIOCENABLEioctl doing the work - then your process uses
write(2)to send CCBs over to the SIM - and
poll(2)orkqueue(2)to check if responses are ready π - pointers to completed CCBs come back to you via
read(2) - and any data transfers the user CCBs asked for? done via zero-copy IO. periodt. π₯
π IOCTLS π
these ioctl(2) calls are all defined in the header file <cam/scsi/scsi_targetio.h>. let's go one by one, bestie:
TARGIOCENABLEβ (struct ioc_enable_lun) β this one enables target mode on the LUN you specify. and you specify it with this structure right here:
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;
};
π¨ important: the selected path (bus), target, and LUN must not already be in use, or you get EADDRINUSE back. no sharing, babe.
and if grp6_len or grp7_len are non-zero, then reception of vendor-specific commands is enabled. cute little bonus. β¨
TARGIOCDISABLEβ disables target mode and aborts all pending CCBs. the CCBs may optionally be read as they complete, if you want. after that you can callTARGIOCENABLEagain to activate a different LUN. multiple disable calls have no effect (it's not gonna get more disabled, bestie). and btw, theclose(2)system call automatically disables target mode if it's enabled β so you don't even have to ask. πTARGIOCDEBUGβ (int) β enables CAM_PERIPH debugging if the argument is non-zero, otherwise it disables it. that's it. flip the switch. ποΈ
π FILES π
<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_targetahc(4)isp(4)scsi(4)- 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. then it got rewritten for FreeBSD 5.0 by Nate Lawson <nate@root.org>. glow-up era fr fr. π
π BUGS π
okay so the fine print, and we keep it real here:
- Currently, only the
ahc(4)andisp(4)drivers fully support target mode. so likeβ¦ keep that in mind. π - The
ahc(4)driver does not support tagged queuing in target mode. not a vibe, but it is the truth.
π and that's the whole page, bestie β this manual came to you from Debian, dated December 13, 2011. literally vintage, and still eating. bye mwah π π¦β¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2002 Nate Lawson. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms