aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2009-09-20 13:12:50 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2009-09-20 13:12:50 +0000
commit53add622cd205f4adf3e006545434ad114c0e435 (patch)
tree45cc2ba994ab402182d151bb09650bb12aac3525
parentb799f0fb46d3fe9ad5474e50d44559914d4dd7bb (diff)
downloadsg3_utils-53add622cd205f4adf3e006545434ad114c0e435.tar.gz
more sg_get_lba_status work, major() macro linux problems, include <linux/kdev_t.h>
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@305 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--ChangeLog4
-rw-r--r--README26
-rw-r--r--README.freebsd3
-rw-r--r--README.solaris3
-rw-r--r--README.tru643
-rw-r--r--README.win323
-rw-r--r--configure.ac2
-rw-r--r--debian/changelog2
-rw-r--r--doc/sg_get_lba_status.848
-rw-r--r--lib/sg_cmds_basic.c3
-rw-r--r--lib/sg_pt_linux.c11
-rw-r--r--sg3_utils.spec2
-rw-r--r--src/sg_get_lba_status.c82
-rw-r--r--src/sg_luns.c3
14 files changed, 126 insertions, 69 deletions
diff --git a/ChangeLog b/ChangeLog
index ce3fa644..3da1305c 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.28 [20090920] [svn: r301]
+Changelog for sg3_utils-1.28 [20090920] [svn: r305]
- sg_unmap: new utility for thin provisioning
- add examples/sg_unmap_example.txt
- sg_get_lba_status: new utility for thin provisioning
@@ -30,6 +30,8 @@ Changelog for sg3_utils-1.28 [20090920] [svn: r301]
- sg_cmds_extra: add sg_ll_unmap() and sg_ll_get_lba_status()
- sg_pt_linux: fix check condition but empty sense buffer; occurred
when sg v3 node used and /usr/include/linux/bsg.h visible
+ - major() macro grief, if present include <linux/kdev_t.h> and
+ use MAJOR() instead
- scripts/sas_disk_blink: moved from this package to sdparm
- utils/hxascdmp: in Windows set binary mode on read files
- examples/sg_persist_tst.sh: add PRIN read full status command
diff --git a/README b/README
index 96d733d6..81fb8807 100644
--- a/README
+++ b/README
@@ -198,12 +198,12 @@ Utilities
Here is list in alphabetical order of utilities found in the 'src'
subdirectory of the sg3_utils package:
- sginfo, sgm_dd, sgp_dd, sg_dd, sg_emc_trespass, sg_get_config,
- sg_format, sg_ident, sg_inq, sg_logs, sg_luns, sg_map, sg_map26,
- sg_modes, sg_opcodes, sg_persist, sg_prevent, sg_raw, sg_rbuf, sg_rdac,
- sg_read, sg_readcap, sg_read_block_limits, sg_read_buffer, sg_read_long,
- sg_reassign, sg_request, sg_reset, sg_rmsn, sg_rtpg, sg_safte,
- sg_sat_identify, sg_sat_phy_event, sg_sat_set_features, sg_scan,
- sg_senddiag, sg_ses, sg_start, sg_stpg, sg_sync, sg_test_rwbuff,
+ sg_get_lba_status, sg_format, sg_ident, sg_inq, sg_logs, sg_luns, sg_map,
+ sg_map26, sg_modes, sg_opcodes, sg_persist, sg_prevent, sg_raw, sg_rbuf,
+ sg_rdac, sg_read, sg_readcap, sg_read_block_limits, sg_read_buffer,
+ sg_read_long, sg_reassign, sg_request, sg_reset, sg_rmsn, sg_rtpg,
+ sg_safte, sg_sat_identify, sg_sat_phy_event, sg_sat_set_features,
+ sg_scan, sg_senddiag, sg_ses, sg_start, sg_stpg, sg_sync, sg_test_rwbuff,
sg_turs, sg_unmap, sg_verify, sg_vpd, sg_write_buffer, sg_write_long,
sg_write_same, sg_wr_mode
@@ -334,12 +334,12 @@ interface by defining the SG3_UTILS_OLD_OPTS environment variable
or using '-O' as the first command line option.
The more recent utilities that use "getopt_long" only are:
- - sg_format sg_get_config sg_ident sg_luns sg_map26 sg_persist
- sg_prevent sg_raw sg_read_block_limits sg_read_buffer sg_read_long
- sg_reassign sg_requests sg_rmsn sg_rtpg sg_safte sg_sat_identify
- sg_sat_phy_event sg_sat_set_features sg_scan(w) sg_ses sg_stpg sg_sync
- sg_test_rwbuf sg_unmap sg_verify sg_vpd sg_write_buffer sg_write_long
- sg_write_same sg_wr_mode
+ - sg_format sg_get_config sg_get_lba_status sg_ident sg_luns sg_map26
+ sg_persist sg_prevent sg_raw sg_read_block_limits sg_read_buffer
+ sg_read_long sg_reassign sg_requests sg_rmsn sg_rtpg sg_safte
+ sg_sat_identify sg_sat_phy_event sg_sat_set_features sg_scan(w) sg_ses
+ sg_stpg sg_sync sg_test_rwbuf sg_unmap sg_verify sg_vpd sg_write_buffer
+ sg_write_long sg_write_same sg_wr_mode
Dangerous code
@@ -361,4 +361,4 @@ See http://sg.danny.cz/sg/tools.html
Doug Gilbert
-6th September 2009
+20th September 2009
diff --git a/README.freebsd b/README.freebsd
index c5cbab30..3a178615 100644
--- a/README.freebsd
+++ b/README.freebsd
@@ -15,6 +15,7 @@ Supported Utilities
Here is a list of utilities that have been ported:
sg_format
sg_get_config
+ sg_get_lba_status
sg_ident
sg_inq [dropped ATA IDENTIFY DEVICE capability]
sg_logs
@@ -97,4 +98,4 @@ See the FreeBSD section in the INSTALL file for install directions.
Doug Gilbert
-15th June 2009
+20th September 2009
diff --git a/README.solaris b/README.solaris
index abf2609c..0e1a9925 100644
--- a/README.solaris
+++ b/README.solaris
@@ -10,6 +10,7 @@ Supported Utilities
Here is a list of utilities that have been ported:
sg_format
sg_get_config
+ sg_get_lba_status
sg_ident
sg_inq [dropped ATA IDENTIFY DEVICE capability]
sg_logs
@@ -82,4 +83,4 @@ See the Solaris section in the INSTALL file for install directions.
Doug Gilbert
-15th June 2009
+20th September 2009
diff --git a/README.tru64 b/README.tru64
index a24fc2ed..e531f75b 100644
--- a/README.tru64
+++ b/README.tru64
@@ -10,6 +10,7 @@ Supported Utilities
Here is a list of utilities that have been ported:
sg_format
sg_get_config
+ sg_get_lba_status
sg_ident
sg_inq [dropped ATA IDENTIFY DEVICE capability]
sg_logs
@@ -87,4 +88,4 @@ subdirectory. Currently only the Tru64 port uses it.
Doug Gilbert
-15th June 2009
+20th September 2009
diff --git a/README.win32 b/README.win32
index 943e1f5a..21cef930 100644
--- a/README.win32
+++ b/README.win32
@@ -25,6 +25,7 @@ Supported Utilities
Here is a list of utilities that have been ported:
sg_format
sg_get_config
+ sg_get_lba_status
sg_ident
sg_inq [dropped ATA IDENTIFY DEVICE capability]
sg_logs
@@ -191,4 +192,4 @@ mode" with the setmode() Windows command.
Doug Gilbert
-18th August 2009
+20th September 2009
diff --git a/configure.ac b/configure.ac
index b31717fc..b528b382 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,7 +12,7 @@ AC_PROG_LIBTOOL
# check for headers
AC_HEADER_STDC
-AC_CHECK_HEADERS([linux/types.h linux/bsg.h], [], [],
+AC_CHECK_HEADERS([linux/types.h linux/bsg.h linux/kdev_t.h], [], [],
[[#ifdef HAVE_LINUX_TYPES_H
# include <linux/types.h>
#endif
diff --git a/debian/changelog b/debian/changelog
index 29322326..e51a67fe 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,7 +2,7 @@ sg3-utils (1.28-0.1) unstable; urgency=low
* New upstream version
- -- Doug Gilbert <dgilbert@interlog.com> Sun, 06 Sep 2009 12:00:00 -0400
+ -- Doug Gilbert <dgilbert@interlog.com> Sun, 20 Sep 2009 12:40:00 +0200
sg3-utils (1.27-0.1) unstable; urgency=low
diff --git a/doc/sg_get_lba_status.8 b/doc/sg_get_lba_status.8
index 5969ba5e..cfa19c7b 100644
--- a/doc/sg_get_lba_status.8
+++ b/doc/sg_get_lba_status.8
@@ -1,10 +1,10 @@
.TH SG_GET_LBA_STATUS "8" "September 2009" "sg3_utils\-1.28" SG3_UTILS
.SH NAME
-sg_luns \- send the SCSI GET LBA STATUS command
+sg_get_lba_status \- send the SCSI GET LBA STATUS command
.SH SYNOPSIS
.B sg_get_lba_status
-[\fI\-\-help\fR] [\fI\-\-hex\fR] [\fI\-\-lba=LBA\fR] [\fI\-\-maxlen=LEN\fR]
-[\fI\-\-quiet\fR] [\fI\-\-raw\fR] [\fI\-\-verbose\fR]
+[\fI\-\-brief\fR] [\fI\-\-help\fR] [\fI\-\-hex\fR] [\fI\-\-lba=LBA\fR]
+[\fI\-\-maxlen=LEN\fR] [\fI\-\-raw\fR] [\fI\-\-verbose\fR]
[\fI\-\-version\fR] \fIDEVICE\fR
.SH DESCRIPTION
.\" Add any additional description here
@@ -12,9 +12,28 @@ sg_luns \- send the SCSI GET LBA STATUS command
Send the SCSI GET LBA STATUS command to the \fIDEVICE\fR and outputs the
response. This command was introduced in (draft) SBC-3 revision 20 and
devices that support thin provisioning should support this command.
+.PP
+The default action is to decode the response into one LBA status descriptor
+per line output to stdout. The descriptor LBA is output in hex (prefixed
+by '0x' and the number of blocks is output in decimal followed by the
+provisioning status in decimal. The provisioning status can be in the
+range 0 to 15 of which only 0 (mapped) and 1 (unmapped) are used currently.
+The amount of output can be reduced by the '--brief' option.
.SH OPTIONS
Arguments to long options are mandatory for short options as well.
.TP
+\fB\-b\fR, \fB\-\-brief\fR
+when use once then one LBA status descriptor per line is output to stdout.
+Each line has this
+format: "0x<descriptor_LBA> 0x<blocks> <provisioning_status>". So the
+descriptor LBA and blocks are output in hex and the provisioning status
+in decimal. When used twice (e.g. '-bb' or '--brief --brief') the
+the provisioning status of the given \fILBA\fR (or LBA 0 if the
+\fI\-\-lba\fR option is not given) is output to stdout. A check is made
+that the given \fILBA\fR lies on the range of the first returned LBA
+status descriptor (as it should according to SBC-3 revision 20) and
+warnings are sent to stderr if it doesn't.
+.TP
\fB\-h\fR, \fB\-\-help\fR
output the usage message then exit.
.TP
@@ -22,28 +41,31 @@ output the usage message then exit.
output response to this command in ASCII hex.
.TP
\fB\-l\fR, \fB\-\-lba\fR=\fILBA\fR
-where \fILBA\fR is the starting logical block address (lba) to check the
-status for.
+where \fILBA\fR is the starting Logical Block Address (LBA) to check the
+provisioning status for. Note that the \fIDEVICE\fR chooses how many
+following blocks that it will return provisioning status for.
.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)
-then 24 is used.
-.TP
-\fB\-q\fR, \fB\-\-quiet\fR
-output ASCII hex rendering of each report lun, one per line.
+the cdb's "allocation length" field. If not given then 24 is used. 24 is
+enough space for the response header and one LBA status descriptor.
+\fILEN\fR should be 8 plus a multiple of 16 (i.e. either 24, 40, 56, etc).
.TP
\fB\-r\fR, \fB\-\-raw\fR
output response in binary (to stdout).
.TP
\fB\-v\fR, \fB\-\-verbose\fR
-increase the level of verbosity, (i.e. debug output).
+increase the level of verbosity, (i.e. debug output). Additional output
+caused by this option is sent to stderr.
.TP
\fB\-V\fR, \fB\-\-version\fR
print the version string and then exit.
+.SH NOTES
+For a discussion of thin provisioning see section 4.6.3 of sbcr20.pdf
+at http://www.t10.org (or the corresponding section of a later draft).
.SH EXIT STATUS
-The exit status of sg_luns is 0 when it is successful. Otherwise see
-the sg3_utils(8) man page.
+The exit status of sg_get_lba_status is 0 when it is successful. Otherwise
+see the sg3_utils(8) man page.
.SH AUTHORS
Written by Douglas Gilbert.
.SH "REPORTING BUGS"
diff --git a/lib/sg_cmds_basic.c b/lib/sg_cmds_basic.c
index 09e857ae..eea4f817 100644
--- a/lib/sg_cmds_basic.c
+++ b/lib/sg_cmds_basic.c
@@ -49,7 +49,7 @@
#endif
-static char * version_str = "1.48 20090918";
+static char * version_str = "1.48 20090920";
#define SENSE_BUFF_LEN 32 /* Arbitrary, could be larger */
@@ -195,7 +195,6 @@ sg_cmds_process_resp(struct sg_pt_base * ptvp, const char * leadin, int res,
break;
}
if (verbose || n) {
-fprintf(stderr, "sg_cmds_process_resp: slen=%d\n", slen);
sg_get_sense_str(leadin, sense_b, slen, (verbose > 1),
sizeof(b), b);
fprintf(sg_warnings_strm, "%s", b);
diff --git a/lib/sg_pt_linux.c b/lib/sg_pt_linux.c
index 02365feb..5d94dbc7 100644
--- a/lib/sg_pt_linux.c
+++ b/lib/sg_pt_linux.c
@@ -40,6 +40,7 @@
#include <sys/types.h>
#include <sys/stat.h>
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -480,6 +481,10 @@ get_scsi_pt_os_err_str(const struct sg_pt_base * vp, int max_b_len, char * b)
#include <linux/types.h>
#include <linux/bsg.h>
+#ifdef HAVE_LINUX_KDEV_T_H
+#include <linux/kdev_t.h>
+#endif
+
struct sg_pt_linux_scsi {
struct sg_io_v4 io_hdr; /* use v4 header as it is more general */
@@ -934,9 +939,15 @@ do_scsi_pt(struct sg_pt_base * vp, int fd, int time_secs, int verbose)
"(errno) = %d\n", ptp->os_err);
return -ptp->os_err;
}
+#ifdef HAVE_LINUX_KDEV_T_H
+ if (! S_ISCHR(a_stat.st_mode) ||
+ (bsg_major != (int)MAJOR(a_stat.st_rdev)))
+ return do_scsi_pt_v3(ptp, fd, time_secs, verbose);
+#else
if (! S_ISCHR(a_stat.st_mode) ||
(bsg_major != (int)major(a_stat.st_rdev)))
return do_scsi_pt_v3(ptp, fd, time_secs, verbose);
+#endif
}
if (! ptp->io_hdr.request) {
diff --git a/sg3_utils.spec b/sg3_utils.spec
index 1593c96e..a90e091d 100644
--- a/sg3_utils.spec
+++ b/sg3_utils.spec
@@ -80,7 +80,7 @@ fi
%changelog
* Sun Sep 06 2009 - dgilbert at interlog dot com
-- add sg_unmap, sg_read_block_limits
+- add sg_get_lba_status, sg_unmap, sg_read_block_limits
* sg3_utils-1.28
* Sat Apr 11 2009 - dgilbert at interlog dot com
diff --git a/src/sg_get_lba_status.c b/src/sg_get_lba_status.c
index 9f85f8c5..9c0523c5 100644
--- a/src/sg_get_lba_status.c
+++ b/src/sg_get_lba_status.c
@@ -59,11 +59,11 @@ static unsigned char * glbasBuffp = glbasBuff;
static struct option long_options[] = {
+ {"brief", no_argument, 0, 'b'},
{"help", no_argument, 0, 'h'},
{"hex", no_argument, 0, 'H'},
{"lba", required_argument, 0, 'l'},
{"maxlen", required_argument, 0, 'm'},
- {"quiet", no_argument, 0, 'q'},
{"raw", no_argument, 0, 'r'},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
@@ -74,26 +74,29 @@ static void
usage()
{
fprintf(stderr, "Usage: "
- "sg_get_lba_status [--help] [--hex] [--lba=LBA] [--maxlen=LEN] "
- "[--quiet]\n"
- " [--raw] [--verbose] [--version] DEVICE\n"
+ "sg_get_lba_status [--brief] [--help] [--hex] [--lba=LBA]\n"
+ " [--maxlen=LEN] [--raw] [--verbose] "
+ "[--version]\n"
+ " DEVICE\n"
" where:\n"
- " --help|-h print out usage message\n"
- " --hex|-H output in hexadecimal\n"
+ " --brief|-b a descriptor per line: "
+ "<lba_hex blocks_hex p_status>\n"
+ " use twice ('-bb') for given LBA "
+ "provisioning status\n"
+ " --help|-h print out usage message\n"
+ " --hex|-H output in hexadecimal\n"
" --lba=LBA|-l LBA starting LBA (logical block address) "
"(def: 0)\n"
" --maxlen=LEN|-m LEN max response length (allocation "
"length in cdb)\n"
" (def: 0 -> %d bytes)\n",
DEF_GLBAS_BUFF_LEN );
- fprintf(stderr, " --quiet|-q output 1 if LBA mapped, 0 "
- "if unmapped\n"
- " --raw|-r output in binary\n"
- " --verbose|-v increase verbosity\n"
- " --version|-V print version string and exit\n\n"
+ fprintf(stderr,
+ " --raw|-r output in binary\n"
+ " --verbose|-v increase verbosity\n"
+ " --version|-V print version string and exit\n\n"
"Performs a SCSI GET LBA STATUS command (SBC-3)\n"
);
-
}
static void
@@ -142,13 +145,13 @@ int
main(int argc, char * argv[])
{
int sg_fd, k, j, res, c, rlen, num_descs;
+ int do_brief = 0;
int do_hex = 0;
int64_t ll;
uint64_t lba = 0;
- uint64_t d_lba;
- uint32_t d_blocks;
+ uint64_t d_lba = 0;
+ uint32_t d_blocks = 0;
int maxlen = DEF_GLBAS_BUFF_LEN;
- int do_quiet = 0;
int do_raw = 0;
int verbose = 0;
const char * device_name = NULL;
@@ -158,12 +161,15 @@ main(int argc, char * argv[])
while (1) {
int option_index = 0;
- c = getopt_long(argc, argv, "hHl:m:qrvV", long_options,
+ c = getopt_long(argc, argv, "bhHl:m:rvV", long_options,
&option_index);
if (c == -1)
break;
switch (c) {
+ case 'b':
+ ++do_brief;
+ break;
case 'h':
case '?':
usage();
@@ -187,9 +193,6 @@ main(int argc, char * argv[])
return SG_LIB_SYNTAX_ERROR;
}
break;
- case 'q':
- ++do_quiet;
- break;
case 'r':
++do_raw;
break;
@@ -251,12 +254,18 @@ main(int argc, char * argv[])
verbose);
ret = res;
if (0 == res) {
+ if (maxlen >= 4)
+ rlen = (glbasBuffp[0] << 24) + (glbasBuffp[1] << 16) +
+ (glbasBuffp[2] << 8) + glbasBuffp[3] + 4;
+ else
+ rlen = maxlen;
+ k = (rlen > maxlen) ? maxlen : rlen;
if (do_raw) {
- dStrRaw((const char *)glbasBuffp, maxlen);
+ dStrRaw((const char *)glbasBuffp, k);
goto the_end;
}
if (do_hex) {
- dStrHex((const char *)glbasBuffp, maxlen, 1);
+ dStrHex((const char *)glbasBuffp, k, 1);
goto the_end;
}
if (maxlen < 4) {
@@ -265,8 +274,6 @@ main(int argc, char * argv[])
" less than 4\n");
goto the_end;
}
- rlen = (glbasBuffp[0] << 24) + (glbasBuffp[1] << 16) +
- (glbasBuffp[2] << 8) + glbasBuffp[3] + 4;
if ((verbose > 1) || (verbose && (rlen > maxlen))) {
fprintf(stderr, "response length %d bytes\n", rlen);
if (rlen > maxlen)
@@ -276,7 +283,7 @@ main(int argc, char * argv[])
if (rlen > maxlen)
rlen = maxlen;
- if (do_quiet) {
+ if (do_brief > 1) {
if (rlen < 24) {
fprintf(stderr, "Need maxlen and response length to "
" be at least 24, have %d bytes\n", rlen);
@@ -291,11 +298,12 @@ main(int argc, char * argv[])
goto the_end;
}
if ((lba < d_lba) || (lba >= (d_lba + d_blocks))) {
- fprintf(stderr, "given LBA not range of first descriptor\n"
- "descriptor LBA: 0x");
+ fprintf(stderr, "given LBA not in range of first "
+ "descriptor:\n" " descriptor LBA: 0x");
for (j = 0; j < 8; ++j)
fprintf(stderr, "%02x", glbasBuffp[8 + j]);
- fprintf(stderr, " blocks: 0x%x\n", d_blocks);
+ fprintf(stderr, " blocks: 0x%x p_status: %d\n", d_blocks,
+ res);
ret = SG_LIB_CAT_OTHER;
goto the_end;
}
@@ -316,10 +324,22 @@ main(int argc, char * argv[])
if ((res < 0) || (res > 15))
fprintf(stderr, "descriptor %d: bad LBA status descriptor "
"returned %d\n", k + 1, res);
- printf("descriptor LBA: 0x");
- for (j = 0; j < 8; ++j)
- printf("%02x", ucp[j]);
- printf(" blocks: %d\n", d_blocks);
+ if (do_brief) {
+ printf("0x");
+ for (j = 0; j < 8; ++j)
+ printf("%02x", ucp[j]);
+ printf(" 0x%x %d\n", d_blocks, res);
+ } else {
+ printf("descriptor LBA: 0x");
+ for (j = 0; j < 8; ++j)
+ printf("%02x", ucp[j]);
+ printf(" blocks: %d", d_blocks);
+ if ((0 == res) || (1 == res))
+ printf(" %s\n",
+ ((0x1 & ucp[12]) ? "unmapped" : "mapped"));
+ else
+ printf(" Provisioning status: %d\n", res);
+ }
}
if ((num_descs * 16) + 8 < rlen)
fprintf(stderr, "incomplete trailing LBA status descriptors "
diff --git a/src/sg_luns.c b/src/sg_luns.c
index 0df18a27..838b7faa 100644
--- a/src/sg_luns.c
+++ b/src/sg_luns.c
@@ -48,7 +48,7 @@
* This program issues the SCSI REPORT LUNS command to the given SCSI device.
*/
-static char * version_str = "1.15 20090617";
+static char * version_str = "1.15 20090920";
#define MAX_RLUNS_BUFF_LEN (1024 * 64)
#define DEF_RLUNS_BUFF_LEN (1024 * 8)
@@ -97,7 +97,6 @@ usage()
" --version|-V print version string and exit\n\n"
"Performs a SCSI REPORT LUNS command\n"
);
-
}
/* Decoded according to SAM-4 rev 4. Note that one draft: BCC rev 0,