sg utils sg_io -i 0x24 -y "12 00:00:00 24 00"
Patrick M:
Hi!
Quoted 11 lines
http://marc.theaimsgroup.com/?l=linux-scsi&m=106762441112762
List: linux-scsi Subject: Re: [PATCH/RFT] mode sense madness always use page 8 From: Patrick Mansfield <patmans () us ! ibm ! com> Date: 2003-10-31 18:16:46...
Quoted 4 lines
sudo ./plscsi
/dev/sg1-v -i x1C -x "5A 00 08:00:00:00 00 00:1C 00"
sudo ./plscsi/dev/sg1-v -i 4 -x "5A 00 3F:00:00:00 00 00:04 00"
sudo ./plscsi/dev/sg1-v -i 4 -x "5A 00 00:00:00:00 00 00:04 00"
sudo ./plscsi/dev/sg1-v -i xFF -x "5A 00 3F:00:00:00 00 00:FF 00"
Quoted 7 lines
Nice ...
Quoted 2 lines
Also personally I find the source for that
plscsi app impenetrably awful to read.Maybe you can rewrite it in c and get it into
sg_utils.
I notice the equivalent C is smaller than any one edition of my plain text inline cdrom.ko CDC_MMC_WR patches. So now this email ends with a copy of what I have working so far.
$ mkdir gccscsi $ cd gccscsi $ wget ... ... $ patch -p1 <... patching file inq.c patching file spinq.c patching file Makefile patching file gccscsi.h patching file lscsi.c $ $ make gcc -Wall -o spinq spinq.c lscsi.c $ $ sudo ./spinq /dev/cdrom LITE-ON COMBO LTC-48161HKH0K $ $ sudo ./spinq /dev/scd0 IOMEGA DVDRW4216INP-A 1.A0 $ $ gcc -c -Wall inq.c $ # no worries
I'm trying to get to where we can easily write the many fun variations on the concise inq.c rather than the verbose spinq.c that reads like an SG_IO example from the web ... except without losing the freedom to misalign stuff.
Mostly I'm now stuck wrestling with how to ask concisely to misalign the struct sg_io_hdr_t, the cdb, the data, and/or the sense. I've coded a few schemes that work, none yet concise. I want to be able to say things like try the sg_io_hdr_t at N * x1000 - 1, then the cdb at + x200, then the sense at + x206, then the data at + x21F. We could solve this differently for scripts like inq.c and spinq.c that we interpret entirely by gcc: for those to arrange mis/alignment we could declare a __packed struct. But when interpreting a command line we don't have that luxury unless we resort to printing the command line into a .c file and then calling gcc.
I'm also not delighted to expose all the members of the struct sp in the header, but as yet that's how I export its sizeof for the caller to allocate.
Pat LaVarre
inq.c +13 -0
@@ -0,0 +1,13 @@ +#include "gccscsi.h" +int main (int argc,char * argv[]) +{ + --argc; ++argv; +while (0 < argc--) { +char const * dev = *argv++; +ALSO (dev); + } +I (0x24 );Y ("12 00:00:00 24 00" ); +DATA [8 +0x10 +8 +4 ] ='\0' ; +printf ("%s\n" , &DATA [8 ]); +return 0 ; +}
spinq.c +35 -0
@@ -0,0 +1,35 @@ +#include "gccscsi.h" +int main (int argc,char * argv[]) +{ +int i =-1 ; + +struct sp * sp = (struct sp *)calloc (1 ,sizeof *sp); +int max =0x24 ; +char * data = (char *)calloc (1 , max); + +assert (sp !=NULL ); +assert (data !=NULL ); +assert ((char *) sp < data); + + --argc; ++argv; +assert (0 < argc); + +if (sp_open (sp, argv[0 ]) <0 ) { +sp_perror ("sp_open" ); + }else { +sp_cdb (sp,"\x12\x00\x00\x00\x24\x00" ,6 ); + i =sp_read (sp, &data[0 ], max); +if (i !=0 ) { +if (i ==SP_THRU ) { +sp_perror ("sp_read" ); + }else { +fprintf (stderr,"sp_read: x%X\n" , i); + } + }else { + data[8 +0x10 +8 +4 ] ='\0' ; +printf ("%s\n" , &data[8 ]); + } + } + +return i; +}
Makefile +5 -0
@@ -0,0 +1,5 @@ +spinq: gccscsi.h spinq.c lscsi.c + gcc -Wall -o spinq spinq.c lscsi.c + +inq: gccscsi.h inq.c gccscsi.c lscsi.c + gcc -Wall -o inq inq.c gccscsi.c lscsi.c
gccscsi.h +187 -0
187 lines not on this page · raw message
lscsi.c +316 -0
316 lines not on this page · raw message
Quoted 3 lines
plscsi is starting to look remarkably like FreeBSD's camcontrol utility. Perhaps we should be looking at implementing camcontrol in Linux.
Fun web trail, thanks:
http://www.google.com/search?q=man+camcontrol
Unix Man Page For 8 camcontrol
http://www.svbug.com/cgi-bin/man.cgi?comd=8+camcontrol
I've seen a legion of pr*prietary tools that do this same work. My most recent survey appears at:
http://members.aol.com/ppaatt/#storage
Pat LaVarre
P.S. Please yell at me offline if I chose wrong to give you this email in pieces.
Quoted 2 lines
Perhaps we should be looking at
implementing camcontrol in Linux.
Implementing, yes. Copying, no. I have a series of arguments, this email presents only the First:
Quoted 2 lines
Unix Man Page For 8 camcontrol
http://www.svbug.com/cgi-bin/man.cgi?comd=8+camcontrol
I vote (: vehemently :) against merging into sg utils the camcontrol etc. practice of ...
... obscuring the plain hex by substituting English at this level. For example, in place of:
camcontrol tur da0
camcontrol eject -n cd -u 1 -v
camcontrol inquiry -D
I vote for:
sg_io -y "00 00:00:00 00 00"sg_io -y "1B 01:00:00 02 00"sg_io -i 0x24 -y "12 00:00:00 24 00"
Already we have sg_scan sg_inq sg_turs for less precise communication.
I vote for the hex because I can see what it means. With those camcontrol examples, I have to guess whether they sometimes or always mean the hex I intend.
I'm not opposed to offering text & gui as well. I just want text & gui made available separately. Some of my ideas for a gui full of natural language text cribbed from the t10 fiction appear as screen shots near the end of the web trail:
Pat LaVarre et alia
http://members.aol.com/ppaatt/
Directly manipulating storage devices
http://members.aol.com/ppaatt/#storage
2.1. Arbitrary transparent pass thru of SCSI.
2.1.1. Via Java GUI
screen shots
http://members.aol.com/plforth/console/scsi/
http://members.aol.com/plforth/console/scsi/javaspt3c.png
(and others)
Although few people can easily give SCSI pass thru privilege to a Java applet, I surprised myself by discovering that an unsigned unprivileged Java applet here remains useful. In practice I found I left the voluminous text & GUI on the web, then where I was actually working I fetched the command line app and copy-pasted the command line args I wanted from the applet.
Pat LaVarre
Quoted 8 lines
Quoted 2 lines
Perhaps we should be looking at
implementing camcontrol in Linux.Implementing, yes. Copying, no.
I have a series of arguments, ...Quoted 2 lines
Unix Man Page For 8 camcontrol
http://www.svbug.com/cgi-bin/man.cgi?comd=8+camcontrol
I think arg parsing is an issue.
I see the camcontrol man page includes such off-putting apologetic fragments as:
"The sense information from the test unit ready command would not get printed out, since the first getopt(3) call in camcontrol bails out when it sees the second argument to -c (0x00), above.
"If the CDB specified causes data to be transfered to or from the SCSI device in question, you MUST specify either
... -i len fmt ... -o len fmt [args] ..."
I particular want the common things to remain concise.
I choke over the idea of having to specify fmt in addition to len of -i or -o.
Part of why I find plscsi/ unreadable, even though I wrote plscsi/ myself, is that in plscsi/ I resorted to rewriting getopts to fix this kind of thing.
Since then I think I have by now found my way to a (more?) fully getopt-compatible parsing of args. That gccscsi.h I posted #define's A thru Z macros that correspond to proposed sg_io args -a thru -z.
1) That -d is unused appears as, e.g.:
#undef D
2) That some options exist only for the command line appears as, e.g.:
#undef P /* gcs --please */
The -p or --please option is an interlock. You have to add it to pass thru such things as non-standard CDB lengths, the op x04 Format that smashes disks, and the -y "12 00:00:00 00" Inquiry for Zero that crashes many version of Linux 2.4.
3) Seeing that the args are single can be difficult, e.g.:
#define L(S, NS) gcs_late(gcs(), (S), (NS))
I figure at the command line we parse $s.fraction and convert to the standard posix int pair (seconds, nanoseconds).
4) Seeing that the args are omitted or single can be easy, e.g.:
#define Q() gcs_quiet(gcs())
#define S(S) gcs_sense_in(gcs(), (S), 4, 0)
Pat LaVarre
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Perhaps we should be looking at
implementing camcontrol in Linux.Implementing, yes. Copying, no.
I have a series of arguments, ...
Or maybe not so very many. Mostly, I find camcontrol disappointingly large.
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Unix Man Page For 8 camcontrol
http://www.svbug.com/cgi-bin/man.cgi?comd=8+camcontrolI think arg parsing is an issue.
I see the camcontrol man page includes such off-putting ...
Personally I think even my own plscsi/ is too large. I'm hoping gccscsi by contrast is small enough to demo kernel trouble (and proposed plug 'n play patches).
For example, offline recently I thought I saw someone report that a cdb-unexpectedly-short doesn't pass thru 2.6.0 to usb mass. Seeing plscsi say that doesn't tell us the kernel has an issue there: we have to ask, and we cannot easily answer, does plscsi have an issue there.
I care most here about transparency: easily establishing more confidence that I know what I asked the kernel than if I had written an ad hoc test program
I figure I can achieve transparency by remembering reuse proves my general test program free of the simple errors I might make in an ad hoc test program, but I have to keep my general test program small enough to let me easily read over, step thru, maybe even copy-paste-edit out, just the lines of code that I need.
Pat LaVarre
On Thu, Nov 06, 2003 at 05:38:36PM -0700, Pat LaVarre wrote:
Do you have a tar ball or such of all the code? Or is this still very much a work in progress?
I don't see all the functions in the patch, for example, gcs_in.
I was going to say put the functions in a library, but maybe you already are headed that way. Then create a libsgio or such, and users like sg_utils, scsi_id, cdrecord, scsidev, etc. could link with sgio.
And lose the macros I, Y, etc, just use the function name, or at least have more meaningful macro names.
The command line plscsi could support both long and short names (-i or --gcs-in).
-- Patrick Mansfield
Patrick M:
Quoted 1 line
Hi! Immediate attention! Wow. Thank you.
Quoted 2 lines
Do you have a tar ball or such of all the code?
Or is this still very much a work in progress?
Yes release early release often.
Quoted 1 line
I don't see all the functions in the patch, for example,
gcs_in.
That patch just gives you enough to compile & link & run the verbose, spinq.c, and to compile without linking the alternative, concise, inq.c. I don't mean to be coy, I'm just trying not to overwhelm the list, I've thought about this problem in isolation for nearly a decade without before now finding anyone else on Earth who cared.
Quoted 3 lines
I was going to say put the functions in a library, but maybe you already are headed that way. Then create a libsgio or such, and users like
sg_utils,scsi_id, cdrecord, scsidev, etc. could link with sgio.
Aye. Yes I did try this already. Most recent demo might be the lscsi.so of the gccscsi tar ball on the web. There I called the .so library from gforth, which more directly offers dynamic link than static link, again I built both Linux & Win XP/2K.
Quoted 2 lines
And lose the macros I, Y, etc, just use the function name, or at least have more meaningful macro names.
I'm trying to distinguish two kinds of test code.
In spinq.c we see the meaningful subroutine names we like already - yes?
I'm not sure you agree we want to write any other kind of code?
In inq.c we see cryptic macro names. Those cryptic names correspond directly to the -a thru -z options of a "nice" tool like plscsi or camcontrol or my now proposed sg_io.
For example, if our command line is -i x24 -y "12 00:00:00 24 00" then our C code is { I(0x24); Y("12 00:00:00 24 00"); }. When you learn the one cryptic syntax, you learn the other cryptic syntax, modulo some transliteration.
I'm thinking if we like a cryptic command line, then so too we like cryptic C code. We write inq.c, not just spinq.c, depending on our audience.
I'm in two minds over the name sg_io. I'm guessing that's the name that the sg utils audience will want, but I'm confident that name won't mean anything on the other operating systems and having to find how to type _ will annoy people.
I figure for those other folk we will offer a gcs command line, and let people ignore the fact that a gcs command line and an sg_io command line accomplish the same thing with the same syntax.
Or maybe we'd rather say gcs always. But if the cost of getting gcs into sg utils is to say sg_io for Linux only, then I figure we pay that cost.
Quoted 2 lines
The command line plscsi could support both long and short names (-i or --gcs-in).
Ouch, sorry, yes I left that part of the patch out, I find I have to sneaker net it here, please stay tuned.
Pat LaVarre
Quoted 5 lines
Quoted 2 lines
The command line plscsi could support both long and short names (-i or --gcs-in).
Ouch, sorry, yes I left that part of the patch out, I find I have to sneaker net it here, please stay tuned.
As follows. --yes, --in, --out, etc., very much like plscsi --help says. Perhaps the key fragment is the zero or one arg per option usage and default values description:
"-b --beyond $length // else 0\n"
"-c --compare\n"
"-e --each\n"
"-f --from $fn // else stdin\n"
"-h --help\n"
"-i --in $length // else 0.4096.0 = 0 aligned at 4 KiB\n"
"-l --late $seconds // else 100800.000 = 28 hours\n"
"-n --no $hex\n"
"-o --out $length // else 0.4096.0 = 0 aligned at 4 KiB\n"
"-p --please // else audit cdb length, etc.\n"
"-q --quiet\n"
"-r --repeat $count // else 1\n" "-s --sense $length // else 18.4.0 = x12 aligned at 4 bytes\n" "-t --to $fn // else stdout\n"
"-v --verbose\n"
"-w --with $hex // else -w \"AE\"\n"
"-y --yes $hex // else -i x24 -y \"12 00:00:00 24 00\"\n"
"\n" ...
"gsc $dev -v -i 0x24 -y \"12 00:00:00 24 00\" // Inquiry\n" "gsc $dev -v -i 8 -y \"25 00 00:00:00:00 00 00:00 00\" // Read Max LBA\n" "gsc $dev -v -y \"00 00:00:00 00 00\" // Test Unit Ready\n" "gsc $dev -v -y \"1B 00:00:00 00 00\" // Stop Unit\n"
"gsc $dev -v -y \"1B 00:00:00 01 00\" // Start Unit\n"
"gsc $dev -v -y \"1B 00:00:00 02 00\" // Stop Then Eject\n"
Again I say I'm not happy with the treatment of misalignment.
Diff'ed against this version, striving to keep the gccscsi.c small, I find maybe now I'm learning towards a deeply arcane multi-arg option such as:
--align 0x1000 -1 0x234 0x345 0x456
By that I mean, with respect to what kind of interesting alignment boundary (x1000), say where to position the sg_io_hdr_t (-1), the cdb (0x234), the sense (x345), and the data (x456).
Quoted 3 lines
Quoted 1 line
Do you have a tar ball ...
Yes release early release often.
Tar ball to list is forbidden, no? So I launched this thread with a normal small patch, but then in this post I have included a version of the command line parser as plain text inline.
Pat LaVarre
--- gsc.c
/* gsc.c
*
* Interpret a command line in terms of "gccscsi.h". */
/* Link with local C libraries. */
#include "gccscsi.h"
#include "version.h"
/* Step thru implicit and command line args. */
static char const * const * args;
/* Remember some command line args. */
static int interpret_dash = 1;
static int interpret_compare = 0;
static int interpret_please = 0;
static int interpret_repeat = 1;
static int interpret_yes = -1;
static char const * interpret_from = NULL;
static char const * interpret_to = NULL;
/* Summarise command line syntax. */
#define USAGE \
"gsc $dev... -e -yiowp -acfnlrst -bhqv $args... // $comment..."
/* Complain of command line syntax. */
static void confused_exit(void)
{
fprintf(stderr, "Usage: %s\nMore details at: gss --help\n", USAGE);
exit(-__LINE__);
}/* Convert to CDB length from CDB[0]. */
static int to_cdb_length(int op, int guess)
{
switch (op & 0xE0) { /* &xE0 = "group" */
case 0x00: return 6; /* x00 .. x1F */
case 0x20: return 10;/* x20 .. x3F */
case 0x40: return 10; /* x40 .. x5F */
case 0x60: break; /* x60 .. x7F reserved */
case 0x80: break; /* x80 .. x9F reserved */
case 0xA0: return 12; /* xA0 .. xBF */
case 0xC0: break; /* xC0 .. xDF vendor-specific */
case 0xE0: break; /* xE0 .. xFF vendor-specific */
}
return guess;
}/* Complain of SCSI pass thru known to crash operating systems. */
static void displeased_exit(char const * st)
{
fprintf(stderr, "Say --please to pass thru %s\n", st);
exit(-__LINE__);
}/* Exit without risking a crash. */
static void audit_gss(struct gss * gss)
{
char const * cdb = gss_get_cdb(gss);
int op = (cdb[0] & 0xFF);
int enough = to_cdb_length(op, -1);
if (gss_get_cdb_enough(gss) != enough) {
displeased_exit("non-standard CDB length");
}
if (cdb[0] == 0x04) {
displeased_exit("op x04 Format");
}
if ((cdb[0] == 0x12) && (gss_get_chars_length(gss) == 0)) {
displeased_exit("op x12 Inquiry for zero");
}
if ((cdb[0] == 0x1A) && (gss_get_chars_length(gss) < 8)) {
displeased_exit("op x1A Mode Sense 6 for less than 8");
}
}/* Open a file to read from. */
static FILE * open_from(char const * fn)
{
if (*fn == '\0') {
return stdin; /* FIXME: might be opened "rt" */
} else {
FILE * fi = fopen(fn, "rb");
if (fi != NULL) {
return fi;
}
perror("gss:from:fopen");
exit(-__LINE__);
}
}/* Fill with copies of the beginning. */
static void fill(char * chars, int index, int length)
{
char const * home = chars;
int step = index;
for (;;) {
chars += step; length -= step;
step = ((length < index) ? length : index);
if (step <= 0) break;
memmove(chars, home, step);
index += step;
}
}/* Read once to fill with copies, else fill with '\0' nul. */
static void read_to_fill(FILE * fi)
{
int length = gss_get_chars_length(gss_first);
if (0 < length) {
char * chars = gss_get_chars(gss_first);
int io = fread(chars, 1, length, fi);
if ((0 <= io) && (io <= length)) {
chars[0] = '\0';
if (io == 0) ++io;
fill(chars, io, length);
} else {
if (ferror(fi)) {
perror("gss:from:fread");
} else {
fprintf(stderr, "gss:from:feof\n");
}
exit(-__LINE__);
}
}
}/* Copy the data before passing the data out. */
char const * new_copy(struct gss * gss)
{
int length = gss_get_chars_length(gss);
if (0 < length) {
char * chars = gss_get_chars(gss);
char * new_chars = calloc(1, length);
if (new_chars != NULL) {
memcpy(new_chars, chars, length);
return new_chars;
}
perror("gss:compare:calloc");
exit(-__LINE__);
}
return NULL;
}/* Compare the data passed out to the data passed in. */
static int compare_copy(struct gss * gss, int rc, char const * was)
{
int enough = gss_get_chars_enough(gss);
if (0 < enough) {
char * chars = gss_get_chars(gss);
if (memcmp(was, chars, enough) != 0) {
if (0 < rc) rc = SP_RESIDUE;
rc |= SP_PASS_THRU;
rc |= SP_COMPARE;
}
}
return rc;
}/* Open a file to write to. */
static FILE * open_to(char const * fn)
{
if (*fn == '\0') {
return stdout; /* FIXME: might be opened "wt" */
} else {
FILE * fi = fopen(fn, "wb");
if (fi != NULL) {
return fi;
}
perror("gss:to:fopen");
exit(-__LINE__);
}
}/* Write once. */
static void write_to(FILE * fi)
{
int length = gss_get_chars_length(gss_first);
if (0 < length) {
char * chars = gss_get_chars(gss_first);
int io = fwrite(chars, 1, length, fi);
if (io != length) {
perror("gss:to:fwrite");
exit(-__LINE__);
}
}
}/* Interpret --yes or --no. */
static void run(char const * hex)
{
struct gss * gss = gss_first;
int please = interpret_please;
int compare = interpret_compare;
int repeat = interpret_repeat;
int yes = interpret_yes;
char const * from_fn = interpret_from;
char const * to_fn = interpret_to;
FILE * from_fi = NULL;
FILE * to_fi = NULL;
char const * was = NULL;
int tolerable = 0;
int rc = 0;
/* Audit. */
if (!please) {
audit_gss(gss);
}
if (to_fn != NULL) {
to_fi = open_to(to_fn);
}
/* Start up. */
if (from_fn != NULL) {
from_fi = open_from(from_fn);
}
if (from_fi != NULL) {
read_to_fill(from_fi);
}
if (compare) {
was = new_copy(gss);
}
/* Speak, maybe repeatedly. */
while (0 < repeat--) {
rc = gss_hex_try(gss, hex);
if (compare) {
rc = compare_copy(gss, rc, was);
}
if (tolerable == 0) {
tolerable = ((0 < rc) ? rc : -1);
}
if ((0 < rc) && (rc == tolerable)) {
rc = 0;
}
if (yes != (rc == 0)) {
break;
}
}
/* Shut down. */
if (to_fi != NULL) {
write_to(to_fi);
}
exit(rc);
}static char const * arg_read(void)
{
if (*args == NULL) {
confused_exit();
}
return *args++;
}static int to_int(char const * st)
{
st = st;
return 0;
}static void helpful_exit(void)
{
char const * st = /* one line per option, sorted by name */
"-b --beyond $length // else 0\n"
"-c --compare\n"
"-e --each\n"
"-f --from $fn // else stdin\n"
"-h --help\n"
"-i --in $length // else 0.4096.0 = 0 aligned at 4 KiB\n"
"-l --late $seconds // else 100800.000 = 28 hours\n"
"-n --no $hex\n"
"-o --out $length // else 0.4096.0 = 0 aligned at 4 KiB\n"
"-p --please // else audit cdb length, etc.\n"
"-q --quiet\n"
"-r --repeat $count // else 1\n" "-s --sense $length // else 18.4.0 = x12 aligned at 4 bytes\n" "-t --to $fn // else stdout\n"
"-v --verbose\n"
"-w --with $hex // else -w \"AE\"\n"
"-y --yes $hex // else -i x24 -y \"12 00:00:00 24 00\"\n"
"\n" /*" 1234567 1234567 1234567 1234567 1234567 1234567 1234567 tab stops */ "gsc $dev -v -i 0x24 -y \"12 00:00:00 24 00\" // Inquiry\n"
"gsc $dev -v -i 8 -y \"25 00 00:00:00:00 00 00:00 00\" // Read Max LBA\n" "gsc $dev -v -y \"00 00:00:00 00 00\" // Test Unit Ready\n"
"gsc $dev -v -y \"1B 00:00:00 00 00\" // Stop Unit\n"
"gsc $dev -v -y \"1B 00:00:00 01 00\" // Start Unit\n"
"gsc $dev -v -y \"1B 00:00:00 02 00\" // Stop Then Eject\n" "...\n"
;
printf("Usage: %s\n\n%s\n\n%s\n", USAGE, st, VERSION);
exit(0);
}static char const * abbreviate(char const * st)
{
if (strcmp(st, "--align")) return "-a";
if (strcmp(st, "--beyond")) return "-b";
if (strcmp(st, "--compare")) return "-c";
if (strcmp(st, "--each")) return "-e";
if (strcmp(st, "--from")) return "-f";
if (strcmp(st, "--help")) return "-h";
if (strcmp(st, "--in")) return "-i";
if (strcmp(st, "--late")) return "-l";
if (strcmp(st, "--no")) return "-n";
if (strcmp(st, "--out")) return "-o";
if (strcmp(st, "--please")) return "-p";
if (strcmp(st, "--quiet")) return "-q";
if (strcmp(st, "--repeat")) return "-r";
if (strcmp(st, "--sense")) return "-s";
if (strcmp(st, "--to")) return "-t";
if (strcmp(st, "--verbose")) return "-v";
if (strcmp(st, "--with")) return "-w";
if (strcmp(st, "--yes")) return "-y";
return st;
}static void step(char const * st)
{
if (strcmp(st, "--")) {
interpret_dash = 0;
} else if (strcmp(st, "-a")) { /* align $page $offset */
int l = to_int(arg_read());
int o = to_int(arg_read());
gss_align(gss_first, l, o);
} else if (strcmp(st, "-b")) { /* beyond $length */
int b = to_int(arg_read());
gss_verbose_limit(gss_first, b);
} else if (strcmp(st, "-c")) { /* compare */
interpret_compare = 1;
} else if (strcmp(st, "-e")) { /* each */
gss_each(NULL);
} else if (strcmp(st, "-f")) { /* from $fn */
interpret_from = arg_read();
} else if (strcmp(st, "-h")) { /* help */
helpful_exit();
} else if (strcmp(st, "-i")) { /* in $length */
int i = to_int(arg_read());
gss_in_limit(gss_first, i);
} else if (strcmp(st, "-l")) { /* late $s $ns */
int s = to_int(arg_read());
int ns = to_int(arg_read());
gss_define_late(gss_first, s, ns);
} else if (strcmp(st, "-n")) { /* no $hex */
interpret_yes = 0;
run(arg_read());
} else if (strcmp(st, "-o")) { /* out $length */
int o = to_int(arg_read());
gss_out_limit(gss_first, o);
} else if (strcmp(st, "-p")) { /* please */
interpret_please = 1;
} else if (strcmp(st, "-q")) { /* quiet */
int b = 0;
gss_verbose_limit(gss_first, b);
} else if (strcmp(st, "-r")) { /* repeat $count */
interpret_repeat = to_int(arg_read());
} else if (strcmp(st, "-s")) { /* sense $length $page $offset */
int s = to_int(arg_read());
int l = to_int(arg_read());
int o = to_int(arg_read());
gss_sense_stress(gss_first, s, l, o);
} else if (strcmp(st, "-t")) { /* to $fn */
interpret_to = arg_read();
} else if (strcmp(st, "-v")) { /* verbose */
int b = 1;
gss_verbose_limit(gss_first, b);
} else if (strcmp(st, "-w")) { /* with $hex */
gss_hex_with(gss_first, arg_read());
} else if (strcmp(st, "-y")) { /* yes $hex */
interpret_yes = 1;
run(arg_read());
} else {
char const * name = arg_read();
if ((name[0] == '-') && interpret_dash) {
confused_exit();
}
gss_also(gss_first, name);
}
}static void interpret(char const * const * argv)
{
args = argv;
while (*args != NULL) {
step(abbreviate(arg_read()));
}
}int main(int argc, char const * const * argv)
{
char const * const preface[] = {
"--align", "4096", "0",
"--beyond", "0",
"--in", "0",
"--late", "100800", "0", /* 100800 = 28 * 60 * 60 */
"--out", "0",
"--quiet",
"--repeat", "1",
"--sense", "12", "16", "0",
"--with", "AE",
NULL
};
char const * const inquiry[] = {
"--in", "x24", "--yes", "12 00:00:00 24 00",
NULL
};
interpret(preface);
interpret(argv);
if (interpret_yes < 0) {
interpret(inquiry);
}
return 0;
}/* end of file */
Offline kindly I was asked about "documentation".
We have man camcontrol.
Also we have slightly obsolete documentation in place in man page style as section "3. Syntax" of:
http://members.aol.com/plscsi/
Also we have the PLScsi Tutorial, which I now see coincidentally gives some of the same examples as man camcontrol:
http://members.aol.com/plscsi/tutorial/
Also from that plscsi/ web site we have such alternatives as:
MTX for SCSI ... Device Control [Linux]
http://mtx.badtux.net/
scu = a SCSI Command Utility [Linux/ Win]
http://www.bit-net.com/~rmiller/scu.html
scsitool [Dos]
http://www.nu2.nu/scsitool/
cizer [Apple Mac OS before X]
...
Pat LaVarre
The SG_IO analogue in BSD may be:
http://www.google.com/search?q=man+SCIOCCOMMAND
The corresponding struct appears in such sources as:
Same as ever, again there we see CDB for length, data for expected length returning actual length, sense for expected length returning actual length.
Pat LaVarre
Quoted 11 lines · Pat LaVarre
The
SG_IOanalogue in BSD may be:http://www.google.com/search?q=man+SCIOCCOMMAND
The corresponding struct appears in such sources as:
Same as ever, again there we see CDB for length, data for expected length returning actual length, sense for expected length returning actual length.
Pat,
I don't think the above references are correct. FreeBSD has been using SCSI's Common Access Method (CAM) for some time. Your can find one document at www.t10.org (drafts section under the SCSI-2 heading). More appropriate is the withdrawn CAM-3 draft standard (see www.t10.org/ftp/t10/drafts/cam3/cam3r03.pdf ). That is where you will find the structure sg_io_hdr was modelled on (struct ccb_scsiio3).
Another way to find SCSI pass-through mechanisms is to look at Joerg Schilling's libscg. A simpler way may be to look at smartmontools ( smartmontools.sourceforge.net ) and compare os_linux.c , os_freebsd.c and os_solaris.c
Doug Gilbert
Quoted 3 lines
again there we see CDB for length, data for expected length returning actual length, sense for expected length returning actual length.
ftp://members.aol.com/plscsi/linux/plscsi.tar.gz
says g++ rather than gcc in that Makefile for the sake of that minority of folk who have gcc/g++ configured so that gcc fails to link after compiling .cpp.
http://members.aol.com/plscsi/linux/plscsi.tar.gz
fetches the same, but via http rather than via ftp.
Neither, whoops, yet give us the following popular patch that often makes such commands work as:
plscsi /dev/hdc
plscsi /dev/hdd
plscsi /dev/scd0
Pat LaVarre
sgio.cpp +1 -0
@@ -116,6 +116,7 @@ sgio->theErrFile = stderr; sgio->theOpenMode = O_RDWR; /* O_RDONLY often works */ + sgio->theOpenMode = O_RDONLY|O_NONBLOCK; sgio->theFileDescriptor = -1; sgio->theSgVersionNum = 0; /* 0 = unknown */