diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2014-01-28 16:27:16 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2014-01-28 16:27:16 +0000 |
commit | 7a21fa031cd5f471ffbfbf1e2c8b2a27a6149657 (patch) | |
tree | de95ab2764b89f8bd4314a0f5e228fdb630821ce | |
parent | 4ac0d027631c7d48114d36257fde211c32d20137 (diff) | |
download | sg3_utils-7a21fa031cd5f471ffbfbf1e2c8b2a27a6149657.tar.gz |
sg_unmap cleanup; manpages: add rescan-scsi-bus.sh.8 and other cleanups
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@548 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r-- | CREDITS | 7 | ||||
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | doc/Makefile.am | 1 | ||||
-rw-r--r-- | doc/Makefile.in | 1 | ||||
-rw-r--r-- | doc/rescan-scsi-bus.sh.8 | 90 | ||||
-rw-r--r-- | doc/sg3_utils.8 | 3 | ||||
-rw-r--r-- | doc/sg_format.8 | 8 | ||||
-rw-r--r-- | doc/sg_get_lba_status.8 | 14 | ||||
-rw-r--r-- | doc/sg_ses.8 | 6 | ||||
-rw-r--r-- | doc/sg_stpg.8 | 6 | ||||
-rw-r--r-- | doc/sginfo.8 | 4 | ||||
-rw-r--r-- | src/sg_reassign.c | 4 | ||||
-rw-r--r-- | src/sg_unmap.c | 130 |
13 files changed, 199 insertions, 78 deletions
@@ -15,8 +15,11 @@ Christophe Varoqui <christophe dot varoqui at free dot fr> original sg_rtpg Clayton Weaver <cgweav at email dot com> contributed safe_strerror(). +Dan Horak <dhorak at redhat dot com> website support for this package and + others. Lot of fixes, recently man pages [20140128] + Dave Johnson <ddj at ccv dot brown dot edu> improved disk defect list - handling [20051218] + handling [20051218] Dave Williams <dave at opensourcesolutions dot co dot uk> help with sgp_dd especially and "> 0x7fffffff" with sg*_dd [20060303] @@ -127,4 +130,4 @@ Trent Piepho <xyzzy at speakeasy dot org> print out some "sense key specific" Douglas Gilbert -28th August 2013 +28th January 2014 @@ -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.38 [20140123] [svn: r547] +Changelog for sg3_utils-1.38 [20140128] [svn: r548] - sg_ses: add --dev-slot-num= and --sas-addr= - fix --data=- problem with large buffers - new --data=@FN to read hex data from file FN @@ -30,6 +30,7 @@ Changelog for sg3_utils-1.38 [20140123] [svn: r547] - sg_cmds_extra: fix sa bug in sg_ll_3party_copy_out() - scripts/rescan-scsi-bus.sh: check if FC driver exports issue_lip before using it + - man page added (Linux only) - examples: add sg_tst_excl3 for testing O_EXCL - improve sg_tst_excl and sg_tst_excl2 - add sg_tst_context for testing file handle contexts diff --git a/doc/Makefile.am b/doc/Makefile.am index f33a66dd..734ecf4b 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -8,6 +8,7 @@ if OS_LINUX # sg_scan is shared by Linux and Win32 man_MANS = \ + rescan-scsi-bus.sh.8 \ sg3_utils.8 sg_decode_sense.8 scsi_logging_level.8 \ scsi_mandat.8 scsi_readcap.8 scsi_ready.8 scsi_satl.8 \ scsi_start.8 scsi_stop.8 scsi_temperature.8 \ diff --git a/doc/Makefile.in b/doc/Makefile.in index b774a817..cb88a3e5 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -278,6 +278,7 @@ top_srcdir = @top_srcdir@ # # sg_scan is shared by Linux and Win32 @OS_LINUX_TRUE@man_MANS = \ +@OS_LINUX_TRUE@ rescan-scsi-bus.sh.8 \ @OS_LINUX_TRUE@ sg3_utils.8 sg_decode_sense.8 scsi_logging_level.8 \ @OS_LINUX_TRUE@ scsi_mandat.8 scsi_readcap.8 scsi_ready.8 scsi_satl.8 \ @OS_LINUX_TRUE@ scsi_start.8 scsi_stop.8 scsi_temperature.8 \ diff --git a/doc/rescan-scsi-bus.sh.8 b/doc/rescan-scsi-bus.sh.8 new file mode 100644 index 00000000..8e700923 --- /dev/null +++ b/doc/rescan-scsi-bus.sh.8 @@ -0,0 +1,90 @@ +.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.41.2. +.TH RESCAN-SCSI-BUS.SH "1" "leden 2014" "rescan-scsi-bus.sh 1.57" "User Commands" +.SH NAME +rescan-scsi-bus.sh \- script for adding and removing SCSI devices without rebooting +.SH SYNOPSIS +.B rescan-scsi-bus.sh +[\fIoptions\fR] [\fIhost \fR[\fIhost \fR...]] +.SH OPTIONS +.TP +\fB\-a\fR, \fB\-\-alltargets\fR +scan all targets, not just currently existing [default: disabled] +.TP +\fB\-d\fR +enable debug [default: 0] +.TP +\fB\-l\fR +activates scanning for LUNs 0\-\-7 [default: 0] +.TP +\fB\-L\fR NUM +activates scanning for LUNs 0\-\-NUM [default: 0] +.TP +\fB\-w\fR, \fB\-\-wide\fR +scan for target device IDs 0\-\-15 [default: 0\-\-7] +.TP +\fB\-c\fR +enables scanning of channels 0 1 [default: 0 / all detected ones] +.TP +\fB\-r\fR, \fB\-\-remove\fR +enables removing of devices [default: disabled] +.TP +\fB\-f\fR, \fB\-\-flush\fR +flush failed multipath devices [default: disabled] +.TP +\fB\-i\fR, \fB\-\-issue\-lip\fR +issue a FibreChannel LIP reset [default: disabled] +.TP +\fB\-u\fR, \fB\-\-update\fR +look for existing disks that have been remapped +.TP +\fB\-s\fR, \fB\-\-resize\fR +look for resized disks and reload associated multipath devices, if applicable +.TP +\fB\-\-forcerescan\fR +rescan existing devices +.TP +\fB\-\-forceremove\fR +remove and readd every device (DANGEROUS) +.TP +\fB\-\-nooptscan\fR +don't stop looking for LUNs is 0 is not found +.TP +\fB\-\-color\fR +use coloured prefixes OLD/NEW/DEL +.TP +\fB\-\-hosts\fR=\fILIST\fR +scan only host(s) in \fILIST\fR +.TP +\fB\-\-channels\fR=\fILIST\fR +scan only channel(s) in \fILIST\fR +.TP +\fB\-\-ids\fR=\fILIST\fR +scan only target ID(s) in \fILIST\fR +.TP +\fB\-\-luns\fR=\fILIST\fR +scan only lun(s) in \fILIST\fR +.TP +\fB\-\-sync\fR, \fB\-\-nosync\fR +issue a sync / no sync [default: sync if remove] +.TP +\fB\-\-attachpq3\fR +tell kernel to attach sg to LUN 0 that reports PQ=3 +.TP +\fB\-\-reportlun2\fR +tell kernel to try REPORT_LUN even on SCSI2 devices +.TP +\fB\-\-largelun\fR +tell kernel to support LUNs > 7 even on SCSI2 devs +.TP +\fB\-\-sparselun\fR +tell kernel to support sparse LUN numbering +.IP +Host numbers may thus be specified either directly on cmd line (deprecated) or +or with the \fB\-\-hosts\fR=\fILIST\fR parameter (recommended). +.PP +\fILIST\fR: A[\-B][,C[\-D]]... is a comma separated list of single values and ranges +(No spaces allowed.) +.SH SEE ALSO +\fBrescan-scsi-bus.sh\fR Homepage: \fBhttp://www.garloff.de/kurt/linux/#rescan-scsi\fR +.PP +\fBsg3_utils\fR Homepage: \fBhttp://sg.danny.cz/sg\fR diff --git a/doc/sg3_utils.8 b/doc/sg3_utils.8 index 586090ed..b0aeb09c 100644 --- a/doc/sg3_utils.8 +++ b/doc/sg3_utils.8 @@ -146,8 +146,7 @@ drives and "cd" for SCSI CD/DVD/BD drives. Each SCSI device has a corresponding pass\-through device name of the form /dev/pass<num> where <num> is an integer starting at zero. The "camcontrol devlist" command may be useful for finding out which SCSI device names are -available and the correspondence between between class and pass\-through -names. +available and the correspondence between class and pass\-through names. .SH SOLARIS DEVICE NAMING SCSI device names below the /dev directory have a form like: c5t4d3s2 where the number following "c" is the controller (HBA) number, the number diff --git a/doc/sg_format.8 b/doc/sg_format.8 index 4cf4e821..a77f5507 100644 --- a/doc/sg_format.8 +++ b/doc/sg_format.8 @@ -1,4 +1,4 @@ -.TH SG_FORMAT "8" "June 2013" "sg3_utils\-1.37" SG3_UTILS +.TH SG_FORMAT "8" "January 2014" "sg3_utils\-1.38" SG3_UTILS .SH NAME sg_format \- format or resize a SCSI disk (perhaps change its block size) .SH SYNOPSIS @@ -155,7 +155,7 @@ parameters (e.g. when '\-\-pie=PIE' is greater than zero). \fB\-P\fR, \fB\-\-pfu\fR=\fIPFU\fR sets the "Protection Field Usage" field in the parameter block associated with a FORMAT UNIT command to \fIPFU\fR. The default value is 0, the only -other defined value currently is 1. See the PROTECTION TYPES section below +other defined value currently is 1. See the PROTECTION TYPES section below for more information. .TP \fB\-q\fR, \fB\-\-pie\fR=\fIPIE\fR @@ -265,7 +265,7 @@ protection type of a disk can be found in the "P_TYPE" and "PROT_EN" fields in the response of a READ CAPACITY (16) command (e.g. with the 'sg_readcap \-\-long' utility). .PP -Given that a device supports a particular protection type, a user can then +Given that a device supports a particular protection type, a user can then choose to format that disk with that protection type by setting the "FMTPINFO" and "Protection Field Usage" fields in the FORMAT UNIT command. Those fields correspond to the \fI\-\-fmtpinfo=FPI\fR and the @@ -448,7 +448,7 @@ Written by Grant Grundler, James Bottomley and Douglas Gilbert. .SH "REPORTING BUGS" Report bugs to <dgilbert at interlog dot com>. .SH COPYRIGHT -Copyright \(co 2005\-2013 Grant Grundler, James Bottomley and Douglas Gilbert +Copyright \(co 2005\-2014 Grant Grundler, James Bottomley and Douglas Gilbert .br This software is distributed under the GPL version 2. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/doc/sg_get_lba_status.8 b/doc/sg_get_lba_status.8 index ab8269c3..9c062f47 100644 --- a/doc/sg_get_lba_status.8 +++ b/doc/sg_get_lba_status.8 @@ -1,4 +1,4 @@ -.TH SG_GET_LBA_STATUS "8" "November 2012" "sg3_utils\-1.35" SG3_UTILS +.TH SG_GET_LBA_STATUS "8" "January 2014" "sg3_utils\-1.38" SG3_UTILS .SH NAME sg_get_lba_status \- send SCSI GET LBA STATUS command .SH SYNOPSIS @@ -27,11 +27,11 @@ Arguments to long options are mandatory for short options as well. 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 +descriptor's starting LBA and number of blocks are output in hex and the +provisioning status in decimal. When used twice (e.g. '\-bb' or '\-\-brief +\-\-brief') then 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 in 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 @@ -76,7 +76,7 @@ Written by Douglas Gilbert. .SH "REPORTING BUGS" Report bugs to <dgilbert at interlog dot com>. .SH COPYRIGHT -Copyright \(co 2009\-2012 Douglas Gilbert +Copyright \(co 2009\-2014 Douglas Gilbert .br This software is distributed under a FreeBSD license. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/doc/sg_ses.8 b/doc/sg_ses.8 index 8bdd2790..2fa47686 100644 --- a/doc/sg_ses.8 +++ b/doc/sg_ses.8 @@ -269,9 +269,9 @@ given. .PP One of two command lines variants can be used to specify indexes: \fI\-\-index=TIA,II\fR where \fITIA\fR is either an type header index (TI) -or an Element type abbreviation (A) (e.g. "ps" or "ps1"). \fIII\fR is -is either an individual index or "\-1" to specify the overall element. The -second variant is \fI\-\-index=IIA\fR where \fIIIA\fR is either an individual +or an Element type abbreviation (A) (e.g. "ps" or "ps1"). \fIII\fR is either +an individual index or "\-1" to specify the overall element. The second +variant is \fI\-\-index=IIA\fR where \fIIIA\fR is either an individual index (II) or an Element type abbreviation (A). When \fIIIA\fR is an individual index then the option is equivalent to \fI\-\-index=0,II\fR. When \fIIIA\fR is an Element type abbreviation then the option is equivalent to diff --git a/doc/sg_stpg.8 b/doc/sg_stpg.8 index f93f0296..187054a5 100644 --- a/doc/sg_stpg.8 +++ b/doc/sg_stpg.8 @@ -1,4 +1,4 @@ -.TH SG_STPG "8" "November 2012" "sg3_utils\-1.35" SG3_UTILS +.TH SG_STPG "8" "January 2014" "sg3_utils\-1.38" SG3_UTILS .SH NAME sg_stpg \- send SCSI SET TARGET PORT GROUPS command .SH SYNOPSIS @@ -104,7 +104,7 @@ identifier (i.e. acts on one or more target ports). When \fI\-\-tp=\fR is given then the same number of elements should be given to the \fI\-\-state=\fR option. If more than one list element is given to \fI\-\-tp=\fR and an equal number of elements is _not_ given -to the the \fI\-\-state=\fR option, then if only one state is specified +to the \fI\-\-state=\fR option, then if only one state is specified then it is repeated. .SH EXIT STATUS The exit status of sg_stpg is 0 when it is successful. Otherwise see @@ -114,7 +114,7 @@ Written by Douglas Gilbert. .SH "REPORTING BUGS" Report bugs to <dgilbert at interlog dot com>. .SH COPYRIGHT -Copyright \(co 2007\-2012 Hannes Reinecke, Christophe Varoqui and Douglas Gilbert +Copyright \(co 2007\-2014 Hannes Reinecke, Christophe Varoqui and Douglas Gilbert .br This software is distributed under a FreeBSD license. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/doc/sginfo.8 b/doc/sginfo.8 index 8d570b10..77448a0a 100644 --- a/doc/sginfo.8 +++ b/doc/sginfo.8 @@ -1,4 +1,4 @@ -.TH SGINFO "8" "May 2013" "sg3_utils\-1.36" SG3_UTILS +.TH SGINFO "8" "January 2014" "sg3_utils\-1.38" SG3_UTILS .SH NAME sginfo \- access mode page information for a SCSI (or ATAPI) device .SH SYNOPSIS @@ -287,7 +287,7 @@ hex (mode page index in the first column and the corresponding byte value in the second column) use "\-u 0xa". Mode pages (subpage code == 0) start at index position 2 while subpages start at index position 4. If the "\-Xu ..." option is used then a list a hex values each value -prefixed by "@" is output. Mode (sub)page values can then be modified with +prefixed by "@" is output. Mode (sub)page values can then be modified with the "\-RXu ..." option. .PP .SH RESTRICTIONS diff --git a/src/sg_reassign.c b/src/sg_reassign.c index d2d40292..de3fe9e2 100644 --- a/src/sg_reassign.c +++ b/src/sg_reassign.c @@ -32,7 +32,7 @@ * vendor specific data is written. */ -static const char * version_str = "1.14 20140108"; +static const char * version_str = "1.15 20140126"; #define DEF_DEFECT_LIST_FORMAT 4 /* bytes from index */ @@ -95,7 +95,7 @@ usage() /* Trying to decode multipliers as sg_get_llnum() [in sg_libs] does would * only confuse things here, so use this local trimmed version */ -int64_t +static int64_t get_llnum(const char * buf) { int res, len; diff --git a/src/sg_unmap.c b/src/sg_unmap.c index 314ca7a5..aaafc2b0 100644 --- a/src/sg_unmap.c +++ b/src/sg_unmap.c @@ -9,6 +9,7 @@ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> +#include <stdarg.h> #include <string.h> #include <ctype.h> #include <getopt.h> @@ -29,7 +30,7 @@ * logical blocks. */ -static const char * version_str = "1.04 20140110"; +static const char * version_str = "1.05 20140126"; #define DEF_TIMEOUT_SECS 60 @@ -49,10 +50,30 @@ static struct option long_options[] = { {0, 0, 0, 0}, }; + +#ifdef __GNUC__ +static int pr2serr(const char * fmt, ...) + __attribute__ ((format (printf, 1, 2))); +#else +static int pr2serr(const char * fmt, ...); +#endif + +static int +pr2serr(const char * fmt, ...) +{ + va_list args; + int n; + + va_start(args, fmt); + n = vfprintf(stderr, fmt, args); + va_end(args); + return n; +} + static void usage() { - fprintf(stderr, "Usage: " + pr2serr("Usage: " "sg_unmap [--anchor] [--grpnum=GN] [--help] [--in=FILE]\n" " [--lba=LBA,LBA...] [--num=NUM,NUM...] " "[--timeout=TO]\n" @@ -85,7 +106,7 @@ usage() /* Trying to decode multipliers as sg_get_llnum() [in sg_libs] does would * only confuse things here, so use this local trimmed version */ -int64_t +static int64_t get_llnum(const char * buf) { int res, len; @@ -133,12 +154,12 @@ build_lba_arr(const char * inp, uint64_t * lba_arr, if (0 == in_len) *lba_arr_len = 0; if ('-' == inp[0]) { /* read from stdin */ - fprintf(stderr, "'--lba' cannot be read from stdin\n"); + pr2serr("'--lba' cannot be read from stdin\n"); return 1; } else { /* list of numbers (default decimal) on command line */ k = strspn(inp, "0123456789aAbBcCdDeEfFhHxX, "); if (in_len != k) { - fprintf(stderr, "build_lba_arr: error at pos %d\n", k + 1); + pr2serr("build_lba_arr: error at pos %d\n", k + 1); return 1; } for (k = 0; k < max_arr_len; ++k) { @@ -155,14 +176,14 @@ build_lba_arr(const char * inp, uint64_t * lba_arr, cp = c2p; lcp = cp + 1; } else { - fprintf(stderr, "build_lba_arr: error at pos %d\n", + pr2serr("build_lba_arr: error at pos %d\n", (int)(lcp - inp + 1)); return 1; } } *lba_arr_len = k + 1; if (k == max_arr_len) { - fprintf(stderr, "build_lba_arr: array length exceeded\n"); + pr2serr("build_lba_arr: array length exceeded\n"); return 1; } } @@ -191,18 +212,23 @@ build_num_arr(const char * inp, uint32_t * num_arr, if (0 == in_len) *num_arr_len = 0; if ('-' == inp[0]) { /* read from stdin */ - fprintf(stderr, "'--len' cannot be read from stdin\n"); + pr2serr("'--len' cannot be read from stdin\n"); return 1; } else { /* list of numbers (default decimal) on command line */ k = strspn(inp, "0123456789aAbBcCdDeEfFhHxX, "); if (in_len != k) { - fprintf(stderr, "build_num_arr: error at pos %d\n", k + 1); + pr2serr("build_num_arr: error at pos %d\n", k + 1); return 1; } for (k = 0; k < max_arr_len; ++k) { ll = get_llnum(lcp); if (-1 != ll) { - num_arr[k] = (uint32_t)ll; // could truncate + if (ll > UINT32_MAX) { + pr2serr("build_num_arr: number exceeds 32 bits at pos " + "%d\n", (int)(lcp - inp + 1)); + return 1; + } + num_arr[k] = (uint32_t)ll; cp = (char *)strchr(lcp, ','); c2p = (char *)strchr(lcp, ' '); if (NULL == cp) @@ -213,14 +239,14 @@ build_num_arr(const char * inp, uint32_t * num_arr, cp = c2p; lcp = cp + 1; } else { - fprintf(stderr, "build_num_arr: error at pos %d\n", + pr2serr("build_num_arr: error at pos %d\n", (int)(lcp - inp + 1)); return 1; } } *num_arr_len = k + 1; if (k == max_arr_len) { - fprintf(stderr, "build_num_arr: array length exceeded\n"); + pr2serr("build_num_arr: array length exceeded\n"); return 1; } } @@ -249,8 +275,7 @@ build_joint_arr(const char * file_name, uint64_t * lba_arr, uint32_t * num_arr, else { fp = fopen(file_name, "r"); if (NULL == fp) { - fprintf(stderr, "build_joint_arr: unable to open %s\n", - file_name); + pr2serr("build_joint_arr: unable to open %s\n", file_name); return 1; } } @@ -278,8 +303,8 @@ build_joint_arr(const char * file_name, uint64_t * lba_arr, uint32_t * num_arr, continue; k = strspn(lcp, "0123456789aAbBcCdDeEfFhHxX ,\t"); if ((k < in_len) && ('#' != lcp[k])) { - fprintf(stderr, "build_joint_arr: syntax error at " - "line %d, pos %d\n", j + 1, m + k + 1); + pr2serr("build_joint_arr: syntax error at line %d, pos %d\n", + j + 1, m + k + 1); return 1; } for (k = 0; k < 1024; ++k) { @@ -288,13 +313,18 @@ build_joint_arr(const char * file_name, uint64_t * lba_arr, uint32_t * num_arr, ind = ((off + k) >> 1); bit0 = 0x1 & (off + k); if (ind >= max_arr_len) { - fprintf(stderr, "build_joint_arr: array length " - "exceeded\n"); + pr2serr("build_joint_arr: array length exceeded\n"); return 1; } - if (bit0) - num_arr[ind] = (uint32_t)ll; - else + if (bit0) { + if (ll > UINT32_MAX) { + pr2serr("build_joint_arr: number exceeds 32 bits in " + "line %d, at pos %d\n", j + 1, + (int)(lcp - line + 1)); + return 1; + } + num_arr[ind] = (uint32_t)ll; + } else lba_arr[ind] = (uint64_t)ll; lcp = strpbrk(lcp, " ,\t"); if (NULL == lcp) @@ -307,17 +337,16 @@ build_joint_arr(const char * file_name, uint64_t * lba_arr, uint32_t * num_arr, --k; break; } - fprintf(stderr, "build_joint_arr: error in " - "line %d, at pos %d\n", j + 1, - (int)(lcp - line + 1)); + pr2serr("build_joint_arr: error on line %d, at pos %d\n", + j + 1, (int)(lcp - line + 1)); return 1; } } off += (k + 1); } if (0x1 & off) { - fprintf(stderr, "build_joint_arr: expect LBA,NUM pairs but decoded " - "odd number\n from %s\n", have_stdin ? "stdin" : file_name); + pr2serr("build_joint_arr: expect LBA,NUM pairs but decoded odd " + "number\n from %s\n", have_stdin ? "stdin" : file_name); return 1; } *arr_len = off >> 1; @@ -362,7 +391,7 @@ main(int argc, char * argv[]) if ((1 == num) && ((res < 0) || (res > 31))) grpnum = res; else { - fprintf(stderr, "value for '--grpnum=' must be 0 to 31\n"); + pr2serr("value for '--grpnum=' must be 0 to 31\n"); return SG_LIB_SYNTAX_ERROR; } break; @@ -382,7 +411,7 @@ main(int argc, char * argv[]) case 't': timeout = sg_get_num(optarg); if (timeout < 0) { - fprintf(stderr, "bad argument to '--timeout'\n"); + pr2serr("bad argument to '--timeout'\n"); return SG_LIB_SYNTAX_ERROR; } else if (0 == timeout) timeout = DEF_TIMEOUT_SECS; @@ -391,10 +420,10 @@ main(int argc, char * argv[]) ++verbose; break; case 'V': - fprintf(stderr, "version: %s\n", version_str); + pr2serr("version: %s\n", version_str); return 0; default: - fprintf(stderr, "unrecognised option code 0x%x ??\n", c); + pr2serr("unrecognised option code 0x%x ??\n", c); usage(); return SG_LIB_SYNTAX_ERROR; } @@ -406,30 +435,28 @@ main(int argc, char * argv[]) } if (optind < argc) { for (; optind < argc; ++optind) - fprintf(stderr, "Unexpected extra argument: %s\n", - argv[optind]); + pr2serr("Unexpected extra argument: %s\n", argv[optind]); usage(); return SG_LIB_SYNTAX_ERROR; } } if (NULL == device_name) { - fprintf(stderr, "missing device name!\n"); + pr2serr("missing device name!\n"); usage(); return SG_LIB_SYNTAX_ERROR; } if (in_op && (lba_op || num_op)) { - fprintf(stderr, "expect '--in=' by itself, or both '--lba=' and " - "'--num='\n"); + pr2serr("expect '--in=' by itself, or both '--lba=' and '--num='\n"); usage(); return SG_LIB_SYNTAX_ERROR; } else if (in_op || (lba_op && num_op)) ; else { if (lba_op) - fprintf(stderr, "since '--lba=' is given, also need '--num='\n"); + pr2serr("since '--lba=' is given, also need '--num='\n"); else - fprintf(stderr, "expect either both '--lba=' and '--num=', or " + pr2serr("expect either both '--lba=' and '--num=', or " "'--in=' by itself\n"); usage(); return SG_LIB_SYNTAX_ERROR; @@ -441,16 +468,16 @@ main(int argc, char * argv[]) if (lba_op && num_op) { if (0 != build_lba_arr(lba_op, addr_arr, &addr_arr_len, MAX_NUM_ADDR)) { - fprintf(stderr, "bad argument to '--lba'\n"); + pr2serr("bad argument to '--lba'\n"); return SG_LIB_SYNTAX_ERROR; } if (0 != build_num_arr(num_op, num_arr, &num_arr_len, MAX_NUM_ADDR)) { - fprintf(stderr, "bad argument to '--num'\n"); + pr2serr("bad argument to '--num'\n"); return SG_LIB_SYNTAX_ERROR; } if ((addr_arr_len != num_arr_len) || (num_arr_len <= 0)) { - fprintf(stderr, "need same number of arguments to '--lba=' " + pr2serr("need same number of arguments to '--lba=' " "and '--num=' options\n"); return SG_LIB_SYNTAX_ERROR; } @@ -458,12 +485,12 @@ main(int argc, char * argv[]) if (in_op) { if (0 != build_joint_arr(in_op, addr_arr, num_arr, &addr_arr_len, MAX_NUM_ADDR)) { - fprintf(stderr, "bad argument to '--in'\n"); + pr2serr("bad argument to '--in'\n"); return SG_LIB_SYNTAX_ERROR; } if (addr_arr_len <= 0) { - fprintf(stderr, "no addresses found in '--in=' argument, file: " - "%s\n", in_op); + pr2serr("no addresses found in '--in=' argument, file: %s\n", + in_op); return SG_LIB_SYNTAX_ERROR; } } @@ -496,8 +523,7 @@ main(int argc, char * argv[]) sg_fd = sg_cmds_open_device(device_name, 0 /* rw */, verbose); if (sg_fd < 0) { - fprintf(stderr, "open error: %s: %s\n", device_name, - safe_strerror(-sg_fd)); + pr2serr("open error: %s: %s\n", device_name, safe_strerror(-sg_fd)); return SG_LIB_FILE_ERROR; } @@ -505,29 +531,29 @@ main(int argc, char * argv[]) 1, verbose); ret = res; if (SG_LIB_CAT_NOT_READY == res) { - fprintf(stderr, "UNMAP failed, device not ready\n"); + pr2serr("UNMAP failed, device not ready\n"); goto err_out; } else if (SG_LIB_CAT_UNIT_ATTENTION == res) { - fprintf(stderr, "UNMAP, unit attention\n"); + pr2serr("UNMAP, unit attention\n"); goto err_out; } else if (SG_LIB_CAT_ABORTED_COMMAND == res) { - fprintf(stderr, "UNMAP, aborted command\n"); + pr2serr("UNMAP, aborted command\n"); goto err_out; } else if (SG_LIB_CAT_INVALID_OP == res) { - fprintf(stderr, "UNMAP not supported\n"); + pr2serr("UNMAP not supported\n"); goto err_out; } else if (SG_LIB_CAT_ILLEGAL_REQ == res) { - fprintf(stderr, "bad field in UNMAP cdb\n"); + pr2serr("bad field in UNMAP cdb\n"); goto err_out; } else if (0 != res) { - fprintf(stderr, "UNMAP failed (use '-v' to get more information)\n"); + pr2serr("UNMAP failed (use '-v' to get more information)\n"); goto err_out; } err_out: res = sg_cmds_close_device(sg_fd); if (res < 0) { - fprintf(stderr, "close error: %s\n", safe_strerror(-res)); + pr2serr("close error: %s\n", safe_strerror(-res)); if (0 == ret) return SG_LIB_FILE_ERROR; } |