Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Sep 2020 07:57:09 -0700
From:      Chuck Tuffli <chuck@tuffli.net>
To:        Wojciech Puchar <wojtek@puchar.net>
Cc:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   Re: sendin raw scsi command
Message-ID:  <CAM0tzX0B9mfySsJ9aGJwp_d5q=mKFBmxLF2NvNHgd5VuNRia-Q@mail.gmail.com>
In-Reply-To: <alpine.BSF.2.20.2009031502530.72243@puchar.net>
References:  <alpine.BSF.2.20.2009031502530.72243@puchar.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Sep 3, 2020 at 6:06 AM Wojciech Puchar <wojtek@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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAM0tzX0B9mfySsJ9aGJwp_d5q=mKFBmxLF2NvNHgd5VuNRia-Q>