sendin raw scsi command
Chuck Tuffli
chuck at tuffli.net
Thu Sep 10 14:57:23 UTC 2020
On Thu, Sep 3, 2020 at 6:06 AM Wojciech Puchar <wojtek at puchar.net> wrote:
> i already figured how to list SCSI devices in FreeBSD and find what
> interest me from C language.
>
> After doing so - how can i send raw SCSI command?
>
> That's all i need.
>
> CAM layer userland interface is quite complex.
>
There are two approaches: camcontrol(8) and cam(3)
You can send send arbitrary commands via camcontrol(8)'s cmd. An example of
sending an ATA SMART READ command:
# camcontrol cmd ada0 -a "B0 D0 00 4F C2 00 00 00 00 00 00 00" -i 512 - |
od -tx1
The same can be done with SCSI devices, obviously with a different byte
stream :)
camcontrol(8) uses cam(3) (a.k.a. libcam) under the covers to send commands
to devices via a C library. There are examples in the tree of how to do
this. I've used this approach myself in a small project that collects SMART
data from SCSI, ATA, and NVMe devices (see
https://foss.heptapod.net/bsdutils/smart with most of the CAM related
things in freebsd_dev.c). Hope that helps.
--chuck
More information about the freebsd-hackers
mailing list