aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2013-03-15 03:57:42 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2013-03-15 03:57:42 +0000
commit2d978766260dc0dfc2b956f15f4e4c9f11b75911 (patch)
tree2aa416fd8487a27ce216b9c619358b4c65cc002e
parente2a8a0b0661fa14d45e9b088329e38eb3f349a7f (diff)
downloadsg3_utils-2d978766260dc0dfc2b956f15f4e4c9f11b75911.tar.gz
sg_luns: make --linux Linux only; in --test make trailing B a W (for wrong LUN flip)
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@490 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--ChangeLog2
-rw-r--r--doc/sg3_utils.816
-rw-r--r--doc/sg_luns.826
-rw-r--r--doc/sg_prevent.82
-rw-r--r--doc/sg_scan.8.win324
-rw-r--r--src/sg_luns.c79
6 files changed, 92 insertions, 37 deletions
diff --git a/ChangeLog b/ChangeLog
index 55fdcb84..267926c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,7 @@ Each utility has its own version number, date of last change and
some description at the top of its ".c" file. All utilities in the main
directory have their own "man" pages. There is also a sg3_utils man page.
-Changelog for sg3_utils-1.36 [20130313] [svn: r489]
+Changelog for sg3_utils-1.36 [20130314] [svn: r490]
- sg_vpd: Protocol-specific port information VPD page for
SAS SSP, persistent connection (spl3r2)
- sg_xcopy: handle more descriptor types; handle zero
diff --git a/doc/sg3_utils.8 b/doc/sg3_utils.8
index 2b82f9bf..2ccc40bf 100644
--- a/doc/sg3_utils.8
+++ b/doc/sg3_utils.8
@@ -1,4 +1,4 @@
-.TH SG3_UTILS "8" "December 2012" "sg3_utils\-1.35" SG3_UTILS
+.TH SG3_UTILS "8" "March 2013" "sg3_utils\-1.36" SG3_UTILS
.SH NAME
sg3_utils \- a package of utilities for sending SCSI commands
.SH SYNOPSIS
@@ -108,10 +108,10 @@ order as devices are discovered (and sometimes rediscovered).
Some storage devices have a SCSI lower level device name which starts
with a SCSI (pseudo) adapter name of the form "SCSI<n>:". To this is added
sub\-addressing in the form of a "bus" number, a "target" identifier and
-a "lun" (logical unit number). The "bus" number is also known as a "PathId".
+a LUN (Logical Unit Number). The "bus" number is also known as a "PathId".
These are assembled to form a device name of the
form: "SCSI<n>:<bus>,<target>,<lun>". The trailing ",<lun>" may be omitted
-in which case a lun of zero is assumed. This lower level device name cannot
+in which case a LUN of zero is assumed. This lower level device name cannot
often be used directly since Windows blocks attempts to use it if a class
driver has "claimed" the device. There are SCSI device types (e.g.
Automation/Drive interface type) for which there is no class driver. At
@@ -126,8 +126,8 @@ utilities in this package.
A single device (e.g. a disk) can have many device names. For
example: "PD0" can also be "C:", "D:" and "SCSI0:0,1,0". The two volume names
reflect that the disk has two partitions on it. Disk partitions that are
-not recognised by Windows are not usually given a volume name. However
-Vista does show a volume name for a disk which has no partitions recognised
+not recognized by Windows are not usually given a volume name. However
+Vista does show a volume name for a disk which has no partitions recognized
by it and when selected invites the user to format it (which may be rather
unfriendly to other OSes).
.PP
@@ -272,7 +272,7 @@ If an option takes a numeric argument then that argument is assumed to
be decimal unless otherwise indicated (e.g. with a leading "0x", a
trailing "h" or as noted in the usage message).
.PP
-Some options are used uniformally in most of the utilities in this
+Some options are used uniformly in most of the utilities in this
package. Those options are listed below. Note that there are some
exceptions.
.TP
@@ -387,7 +387,7 @@ the 'utils' subdirectory.
.SH WEB SITE
There is a web page discussing this package at
http://sg.danny.cz/sg/sg3_utils.html . The device naming used by this
-package on various operating system is discussed in the page:
+package on various operating systems is discussed at:
http://sg.danny.cz/sg/device_name.html .
.SH AUTHORS
Written by Douglas Gilbert. Some utilities have been contributed, see the
@@ -395,7 +395,7 @@ CREDITS file and individual source files (in the 'src' directory).
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 1999\-2012 Douglas Gilbert
+Copyright \(co 1999\-2013 Douglas Gilbert
.br
Some utilities are distributed under a GPL version 2 license while
others, usually more recent ones, are under a FreeBSD license. The files
diff --git a/doc/sg_luns.8 b/doc/sg_luns.8
index aa38d472..f79ceac2 100644
--- a/doc/sg_luns.8
+++ b/doc/sg_luns.8
@@ -1,11 +1,11 @@
-.TH SG_LUNS "8" "February 2013" "sg3_utils\-1.36" SG3_UTILS
+.TH SG_LUNS "8" "March 2013" "sg3_utils\-1.36" SG3_UTILS
.SH NAME
sg_luns \- send SCSI REPORT LUNS command or decode LUN
.SH SYNOPSIS
.B sg_luns
-[\fI\-\-decode\fR] [\fI\-\-help\fR] [\fI\-\-hex\fR] [\fI\-\-maxlen=LEN\fR]
-[\fI\-\-quiet\fR] [\fI\-\-raw\fR] [\fI\-\-select=SR\fR]
-[\fI\-\-verbose\fR] [\fI\-\-version\fR] \fIDEVICE\fR
+[\fI\-\-decode\fR] [\fI\-\-help\fR] [\fI\-\-hex\fR] [\fI\-\-linux\fR]
+[\fI\-\-maxlen=LEN\fR] [\fI\-\-quiet\fR] [\fI\-\-raw\fR]
+[\fI\-\-select=SR\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR] \fIDEVICE\fR
.PP
.B sg_luns
\fI\-\-test=LUNHEX\fR [\fI\-\-hex\fR] [\fI\-\-verbose\fR]
@@ -38,6 +38,13 @@ in ASCII hex then exit. When given twice it causes the decode option to
output values in hex rather than decimal. When this option is used with
\fI\-\-test=LUNHEX\fR then decoded component fields are output in hex.
.TP
+\fB\-l\fR, \fB\-\-linux\fR
+this option is only available in Linux. After the T10 representation of
+each 64 bit LUN (in 16 hexadecimal digits), if this option is given then
+to the right, in square brackets, is the Linux LUN integer in decimal.
+If the \fI\-\-hex\fR option is given twice (e.g. \-HH) as well then the
+Linux LUN integer is output in hexadecimal.
+.TP
\fB\-m\fR, \fB\-\-maxlen\fR=\fILEN\fR
where \fILEN\fR is the (maximum) response length in bytes. It is placed in
the cdb's "allocation length" field. If not given (or \fILEN\fR is zero)
@@ -181,6 +188,15 @@ I_T Nexus):
.br
REPORT LUNS well known logical unit
.PP
+The following example uses the \fI\-\-linux\fR option and is not available
+in other operating systems.
+.PP
+ # sg_luns \-q \-s 2 \-l /dev/sg1
+.br
+ 0001000000000000 [1]
+.br
+ c101000000000000 [49409]
+.PP
Now we use the \fI\-\-test=\fR option to decode LUNS input on the command
line (rather than send a REPORT LUNS command and act on the response):
.PP
@@ -220,7 +236,7 @@ Linux LUN 49409 translates to in the T10 world:
And the mapping between T10 and Linux LUN representations can be done the
other way:
.PP
- # sg_luns -t c101L
+ # sg_luns \-t c101L
.br
Linux 'word flipped' integer LUN representation: 49409
.br
diff --git a/doc/sg_prevent.8 b/doc/sg_prevent.8
index df1268c4..3548ffba 100644
--- a/doc/sg_prevent.8
+++ b/doc/sg_prevent.8
@@ -35,7 +35,7 @@ persistent removal. "Persistent" in this context means that the
initiator (port) that successfully uses code 3 blocks other initiators (ports)
from allowing removal. A "persistent prevent" state can be cleared by the
owner allowing persistent removal (code 2) or a power cycle (or anything that
-resets the device (lun)) or some special commands (e.g. various service
+resets the device (LU)) or some special commands (e.g. various service
actions of Persistent Reserve Out, see SPC\-3).
.TP
\fB\-v\fR, \fB\-\-verbose\fR
diff --git a/doc/sg_scan.8.win32 b/doc/sg_scan.8.win32
index 89bd4ab9..d68e85aa 100644
--- a/doc/sg_scan.8.win32
+++ b/doc/sg_scan.8.win32
@@ -28,10 +28,10 @@ sometimes rediscovered).
Some storage devices have a SCSI lower level device name which starts
with a SCSI (pseudo) adapter name of the form "SCSI<n>:". To this is added
sub\-addressing in the form of a "bus" number, a "target" identifier and
-a "lun" (logical unit number). The "bus" number is also known as a "PathId".
+a LUN (Logical Unit Number). The "bus" number is also known as a "PathId".
These components are combined by the utility to make a device name of the
form: "SCSI<n>:<bus>,<target>,<lun>". This utility allows the
-trailing ",<lun>" to be omitted in which case a lun of zero is assumed. This
+trailing ",<lun>" to be omitted in which case a LUN of zero is assumed. This
lower level device name cannot often be used directly since Windows blocks
attempts to use it if a class driver has "claimed" the device. There are
SCSI device types (e.g. Automation/Drive interface type) for which there is
diff --git a/src/sg_luns.c b/src/sg_luns.c
index 02c07034..c87b18d6 100644
--- a/src/sg_luns.c
+++ b/src/sg_luns.c
@@ -28,7 +28,7 @@
* and decodes the response.
*/
-static char * version_str = "1.20 20130305";
+static char * version_str = "1.21 20130314";
#define MAX_RLUNS_BUFF_LEN (1024 * 64)
#define DEF_RLUNS_BUFF_LEN (1024 * 8)
@@ -40,7 +40,9 @@ static struct option long_options[] = {
{"decode", no_argument, 0, 'd'},
{"help", no_argument, 0, 'h'},
{"hex", no_argument, 0, 'H'},
+#ifdef SG_LIB_LINUX
{"linux", no_argument, 0, 'l'},
+#endif
{"maxlen", required_argument, 0, 'm'},
{"quiet", no_argument, 0, 'q'},
{"raw", no_argument, 0, 'r'},
@@ -54,12 +56,22 @@ static struct option long_options[] = {
static void
usage()
{
+#ifdef SG_LIB_LINUX
fprintf(stderr, "Usage: "
"sg_luns [--decode] [--help] [--hex] [--linux] "
"[--maxlen=LEN]\n"
" [--quiet] [--raw] [--select=SR] "
"[--verbose]\n"
- " [--version] DEVICE\n"
+ " [--version] DEVICE\n");
+#else
+ fprintf(stderr, "Usage: "
+ "sg_luns [--decode] [--help] [--hex] [--maxlen=LEN] "
+ "[--quiet]\n"
+ " [--raw] [--select=SR] [--verbose] "
+ "[--version]\n"
+ " DEVICE\n");
+#endif
+ fprintf(stderr,
" or\n"
" sg_luns --test=LUNHEX [--hex] [--verbose]\n"
" where:\n"
@@ -67,15 +79,17 @@ usage()
" --help|-h print out usage message\n"
" --hex|-H output response in hexadecimal; used "
"twice\n"
- " shows decoded values in hex\n"
+ " shows decoded values in hex\n");
+#ifdef SG_LIB_LINUX
+ fprintf(stderr,
" --linux|-l show Linux integer lun after T10 "
- "representation\n"
+ "representation\n");
+#endif
+ fprintf(stderr,
" --maxlen=LEN|-m LEN max response length (allocation "
"length in cdb)\n"
- " (def: 0 -> %d bytes)\n",
- DEF_RLUNS_BUFF_LEN );
- fprintf(stderr, " --quiet|-q output only ASCII hex lun "
- "values\n"
+ " (def: 0 -> %d bytes)\n"
+ " --quiet|-q output only ASCII hex lun values\n"
" --raw|-r output response in binary\n"
" --select=SR|-s SR select report SR (def: 0)\n"
" 0 -> luns apart from 'well "
@@ -90,8 +104,7 @@ usage()
" --version|-V print version string and exit\n\n"
"Performs a SCSI REPORT LUNS command. When the --test=LUNHEX "
"option is\ngiven, decodes LUNHEX rather than sending a "
- "REPORT LUNS command.\n"
- );
+ "REPORT LUNS command.\n", DEF_RLUNS_BUFF_LEN );
}
/* Decoded according to SAM-5 rev 10. Note that one draft: BCC rev 0,
@@ -262,6 +275,7 @@ decode_lun(const char * leadin, const unsigned char * lunp, int do_hex,
}
}
+#ifdef SG_LIB_LINUX
static void
linux2t10_lun(uint64_t linux_lun, unsigned char t10_lun[])
{
@@ -304,6 +318,7 @@ t10_2linux_lun64bitBR(const unsigned char t10_lun[])
lun = lun | (((t10_lun[i] << 8) | t10_lun[i + 1]) << (i * 8));
return lun;
}
+#endif /* SG_LIB_LINUX */
static void
@@ -321,15 +336,19 @@ main(int argc, char * argv[])
int sg_fd, k, m, off, res, c, list_len, luns, trunc;
int decode = 0;
int do_hex = 0;
+#ifdef SG_LIB_LINUX
int do_linux = 0;
+#endif
int maxlen = 0;
int do_quiet = 0;
int do_raw = 0;
int select_rep = 0;
int verbose = 0;
+#ifdef SG_LIB_LINUX
int test_linux_in = 0;
int test_linux_out = 0;
int test_linux_out2 = 0;
+#endif
unsigned int h;
const char * test_arg = NULL;
const char * device_name = NULL;
@@ -340,8 +359,13 @@ main(int argc, char * argv[])
while (1) {
int option_index = 0;
+#ifdef SG_LIB_LINUX
c = getopt_long(argc, argv, "dhHlm:qrs:t:vV", long_options,
&option_index);
+#else
+ c = getopt_long(argc, argv, "dhHm:qrs:t:vV", long_options,
+ &option_index);
+#endif
if (c == -1)
break;
@@ -356,9 +380,11 @@ main(int argc, char * argv[])
case 'H':
++do_hex;
break;
+#ifdef SG_LIB_LINUX
case 'l':
++do_linux;
break;
+#endif
case 'm':
maxlen = sg_get_num(optarg);
if ((maxlen < 0) || (maxlen > MAX_RLUNS_BUFF_LEN)) {
@@ -412,6 +438,8 @@ main(int argc, char * argv[])
if (test_arg) {
memset(lun_arr, 0, sizeof(lun_arr));
cp = test_arg;
+ /* check for leading 'L' */
+#ifdef SG_LIB_LINUX
if ('L' == toupper(cp[0])) {
uint64_t ull;
@@ -422,7 +450,17 @@ main(int argc, char * argv[])
}
linux2t10_lun(ull, lun_arr);
test_linux_in = 1;
- } else {
+ } else
+#endif
+ {
+ /* Check if trailing 'L' or 'W' */
+ m = strlen(cp); /* must be at least 1 char in test_arg */
+#ifdef SG_LIB_LINUX
+ if ('L' == toupper(cp[m - 1]))
+ test_linux_out = 1;
+ else if ('W' == toupper(cp[m - 1]))
+ test_linux_out2 = 1;
+#endif
if (('0' == cp[0]) && ('X' == toupper(cp[1])))
cp += 2;
if (strchr(cp, ' ') || strchr(cp, '\t')) {
@@ -431,20 +469,12 @@ main(int argc, char * argv[])
break;
lun_arr[k] = h & 0xff;
}
- if (strchr(cp, 'L') || strchr(cp, 'l'))
- test_linux_out = 1;
- else if (strchr(cp, 'B') || strchr(cp, 'b'))
- test_linux_out2 = 1;
} else {
for (k = 0; k < 8; ++k, cp += 2) {
if (1 != sscanf(cp, "%2x", &h))
break;
lun_arr[k] = h & 0xff;
}
- if (strchr(cp, 'L') || strchr(cp, 'l'))
- test_linux_out = 1;
- else if (strchr(cp, 'B') || strchr(cp, 'b'))
- test_linux_out2 = 1;
}
if (0 == k) {
fprintf(stderr, "expected a hex number, optionally prefixed "
@@ -452,12 +482,18 @@ main(int argc, char * argv[])
return SG_LIB_SYNTAX_ERROR;
}
}
- if (verbose || test_linux_in || test_linux_out2) {
+#ifdef SG_LIB_LINUX
+ if (verbose || test_linux_in || test_linux_out2)
+#else
+ if (verbose)
+#endif
+ {
printf("64 bit LUN in T10 preferred (hex) format: ");
for (k = 0; k < 8; ++k)
printf(" %02x", lun_arr[k]);
printf("\n");
}
+#ifdef SG_LIB_LINUX
if (test_linux_out) {
if (do_hex > 1)
printf("Linux 'word flipped' integer LUN representation: "
@@ -479,6 +515,7 @@ main(int argc, char * argv[])
printf("Linux internal 64 bit LUN representation: %"
PRIu64 "\n", t10_2linux_lun64bitBR(lun_arr));
}
+#endif
printf("Decoded LUN:\n");
decode_lun(" ", lun_arr, do_hex, verbose);
return 0;
@@ -544,6 +581,7 @@ main(int argc, char * argv[])
}
for (m = 0; m < 8; ++m)
printf("%02x", reportLunsBuff[off + m]);
+#ifdef SG_LIB_LINUX
if (do_linux) {
uint64_t lin_lun;
@@ -553,6 +591,7 @@ main(int argc, char * argv[])
else
printf(" [%" PRIu64 "]", lin_lun);
}
+#endif
printf("\n");
if (decode)
decode_lun(" ", reportLunsBuff + off, do_hex,