aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2018-05-11 04:36:52 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2018-05-11 04:36:52 +0000
commit71e56cc16387a76971a04fda4ff9306ec704daf9 (patch)
tree2c6e6ee4f1f6efd89a16a865ea5301967c6f34db /src
parent5a4b80a31b1caeb62fdab8d732582d898b3da9e0 (diff)
downloadsg3_utils-71e56cc16387a76971a04fda4ff9306ec704daf9.tar.gz
sg_lib: enhance exit status values and associated strings
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@771 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'src')
-rw-r--r--src/sg_bg_ctl.c31
-rw-r--r--src/sg_compare_and_write.c11
-rw-r--r--src/sg_copy_results.c9
-rw-r--r--src/sg_format.c11
-rw-r--r--src/sg_get_config.c13
-rw-r--r--src/sg_get_lba_status.c11
-rw-r--r--src/sg_ident.c11
-rw-r--r--src/sg_logs.c7
-rw-r--r--src/sg_luns.c9
9 files changed, 82 insertions, 31 deletions
diff --git a/src/sg_bg_ctl.c b/src/sg_bg_ctl.c
index 436a8180..b36ef03e 100644
--- a/src/sg_bg_ctl.c
+++ b/src/sg_bg_ctl.c
@@ -33,7 +33,7 @@
* device. Based on sbc4r10.pdf .
*/
-static const char * version_str = "1.06 20180219";
+static const char * version_str = "1.07 20180509";
#define BACKGROUND_CONTROL_SA 0x15
@@ -137,7 +137,8 @@ sg_ll_background_control(int sg_fd, unsigned int bo_ctl, unsigned int bo_time,
int
main(int argc, char * argv[])
{
- int sg_fd, res, c;
+ int sg_fd = -1;
+ int res, c;
unsigned int ctl = 0;
unsigned int time_tnth = 0;
int verbose = 0;
@@ -203,9 +204,11 @@ main(int argc, char * argv[])
sg_fd = sg_cmds_open_device(device_name, false, verbose);
if (sg_fd < 0) {
- pr2serr("open error: %s: %s\n", device_name,
- safe_strerror(-sg_fd));
- return SG_LIB_FILE_ERROR;
+ if (verbose)
+ pr2serr("open error: %s: %s\n", device_name,
+ safe_strerror(-sg_fd));
+ ret = sg_convert_errno(-sg_fd);
+ goto fini;
}
res = sg_ll_background_control(sg_fd, ctl, time_tnth, true, verbose);
@@ -221,11 +224,19 @@ main(int argc, char * argv[])
}
}
- res = sg_cmds_close_device(sg_fd);
- if (res < 0) {
- pr2serr("close error: %s\n", safe_strerror(-res));
- if (0 == ret)
- return SG_LIB_FILE_ERROR;
+fini:
+ if (0 == verbose) {
+ if (! sg_if_can2stderr("sg_bg_ctl failed: ", ret))
+ pr2serr("Some error occurred, try again with '-v' or '-vv' for "
+ "more information\n");
+ }
+ if (sg_fd >= 0) {
+ res = sg_cmds_close_device(sg_fd);
+ if (res < 0) {
+ pr2serr("close error: %s\n", safe_strerror(-res));
+ if (0 == ret)
+ return sg_convert_errno(-res);
+ }
}
return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
}
diff --git a/src/sg_compare_and_write.c b/src/sg_compare_and_write.c
index e4dbc5ae..24a66b5d 100644
--- a/src/sg_compare_and_write.c
+++ b/src/sg_compare_and_write.c
@@ -54,7 +54,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.22 20180428";
+static const char * version_str = "1.23 20180510";
#define DEF_BLOCK_SIZE 512
#define DEF_NUM_BLOCKS (1)
@@ -72,6 +72,7 @@ static struct option long_options[] = {
{"dpo", no_argument, 0, 'd'},
{"fua", no_argument, 0, 'f'},
{"fua_nv", no_argument, 0, 'F'},
+ {"fua-nv", no_argument, 0, 'F'},
{"group", required_argument, 0, 'g'},
{"grpnum", required_argument, 0, 'g'},
{"help", no_argument, 0, 'h'},
@@ -446,9 +447,8 @@ open_dev(const char * outf, int verbose)
if (sg_fd < 0) {
pr2serr(ME "open error: %s: %s\n", outf,
safe_strerror(-sg_fd));
- return -SG_LIB_FILE_ERROR;
+ return -sg_convert_errno(-sg_fd);
}
-
return sg_fd;
}
@@ -576,5 +576,10 @@ out:
close(wfd);
if (devfd >= 0)
close(devfd);
+ if (0 == op->verbose) {
+ if (! sg_if_can2stderr("sg_compare_and_write failed: ", res))
+ pr2serr("Some error occurred, try again with '-v' "
+ "or '-vv' for more information\n");
+ }
return res;
}
diff --git a/src/sg_copy_results.c b/src/sg_copy_results.c
index 514a33b9..0c64cf61 100644
--- a/src/sg_copy_results.c
+++ b/src/sg_copy_results.c
@@ -38,7 +38,7 @@
and the optional list identifier passed as the list_id argument.
*/
-static const char * version_str = "1.20 20180428";
+static const char * version_str = "1.21 20180510";
#define MAX_XFER_LEN 10000
@@ -461,7 +461,12 @@ finish:
if (res < 0) {
pr2serr(ME "close error: %s\n", safe_strerror(-res));
if (0 == ret)
- return SG_LIB_FILE_ERROR;
+ ret = sg_convert_errno(-res);
+ }
+ if (0 == verbose) {
+ if (! sg_if_can2stderr("sg_copy_results failed: ", ret))
+ pr2serr("Some error occurred, try again with '-v' or '-vv' for "
+ "more information\n");
}
return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
}
diff --git a/src/sg_format.c b/src/sg_format.c
index f3a1f916..563bc307 100644
--- a/src/sg_format.c
+++ b/src/sg_format.c
@@ -37,7 +37,7 @@
#include "sg_pr2serr.h"
#include "sg_pt.h"
-static const char * version_str = "1.45 20180330";
+static const char * version_str = "1.46 20180510";
#define RW_ERROR_RECOVERY_PAGE 1 /* can give alternate with --mode=MP */
@@ -1023,7 +1023,7 @@ main(int argc, char **argv)
op->verbose)) < 0) {
pr2serr("error opening device file: %s: %s\n",
op->device_name, safe_strerror(-fd));
- return SG_LIB_FILE_ERROR;
+ return sg_convert_errno(-fd);
}
if (op->format > 2)
@@ -1346,7 +1346,12 @@ out:
if (res < 0) {
pr2serr("close error: %s\n", safe_strerror(-res));
if (0 == ret)
- return SG_LIB_FILE_ERROR;
+ ret = sg_convert_errno(-res);
+ }
+ if (0 == op->verbose) {
+ if (! sg_if_can2stderr("sg_format failed: ", ret))
+ pr2serr("Some error occurred, try again with '-v' "
+ "or '-vv' for more information\n");
}
return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
}
diff --git a/src/sg_get_config.c b/src/sg_get_config.c
index 9c49fdd7..3c5db7d1 100644
--- a/src/sg_get_config.c
+++ b/src/sg_get_config.c
@@ -31,7 +31,7 @@
*/
-static const char * version_str = "0.47 20180329"; /* mmc6r02 */
+static const char * version_str = "0.48 20180510"; /* mmc6r02 */
#define MX_ALLOC_LEN 8192
#define NAME_BUFF_SZ 64
@@ -1050,7 +1050,7 @@ main(int argc, char * argv[])
< 0) {
pr2serr(ME "error opening file: %s (ro): %s\n", device_name,
safe_strerror(-sg_fd));
- return SG_LIB_FILE_ERROR;
+ return sg_convert_errno(-sg_fd);
}
if (0 == sg_simple_inquiry(sg_fd, &inq_resp, true, verbose)) {
if (! do_raw)
@@ -1073,7 +1073,7 @@ main(int argc, char * argv[])
sg_fd = sg_cmds_open_device(device_name, readonly, verbose);
if (sg_fd < 0) {
pr2serr(ME "open error (rw): %s\n", safe_strerror(-sg_fd));
- return SG_LIB_FILE_ERROR;
+ return sg_convert_errno(-sg_fd);
}
if (do_raw) {
if (sg_set_binary_mode(STDOUT_FILENO) < 0) {
@@ -1109,7 +1109,12 @@ main(int argc, char * argv[])
if (res < 0) {
pr2serr("close error: %s\n", safe_strerror(-res));
if (0 == ret)
- return SG_LIB_FILE_ERROR;
+ ret = sg_convert_errno(-ret);
+ }
+ if (0 == verbose) {
+ if (! sg_if_can2stderr("sg_get_config failed: ", ret))
+ pr2serr("Some error occurred, try again with '-v' or '-vv' for "
+ "more information\n");
}
return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
}
diff --git a/src/sg_get_lba_status.c b/src/sg_get_lba_status.c
index 7db694e4..0c48f886 100644
--- a/src/sg_get_lba_status.c
+++ b/src/sg_get_lba_status.c
@@ -32,7 +32,7 @@
* device.
*/
-static const char * version_str = "1.15 20180425";
+static const char * version_str = "1.16 20180510";
#ifndef UINT32_MAX
#define UINT32_MAX ((uint32_t)-1)
@@ -303,7 +303,7 @@ main(int argc, char * argv[])
sg_fd = sg_cmds_open_device(device_name, o_readonly, verbose);
if (sg_fd < 0) {
pr2serr("open error: %s: %s\n", device_name, safe_strerror(-sg_fd));
- ret = SG_LIB_FILE_ERROR;
+ ret = sg_convert_errno(-sg_fd);
goto free_buff;
}
@@ -476,10 +476,15 @@ the_end:
if (res < 0) {
pr2serr("close error: %s\n", safe_strerror(-res));
if (0 == ret)
- ret = SG_LIB_FILE_ERROR;
+ ret = sg_convert_errno(-res);
}
free_buff:
if (free_glbasBuffp)
free(free_glbasBuffp);
+ if (0 == verbose) {
+ if (! sg_if_can2stderr("sg_get_lba_status failed: ", ret))
+ pr2serr("Some error occurred, try again with '-v' or '-vv' for "
+ "more information\n");
+ }
return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
}
diff --git a/src/sg_ident.c b/src/sg_ident.c
index 5c4830e8..84f924da 100644
--- a/src/sg_ident.c
+++ b/src/sg_ident.c
@@ -31,7 +31,7 @@
* DEVICE IDENTIFIER and SET DEVICE IDENTIFIER prior to spc4r07.
*/
-static const char * version_str = "1.19 20180219";
+static const char * version_str = "1.20 20180510";
#define ME "sg_ident: "
@@ -208,7 +208,7 @@ main(int argc, char * argv[])
sg_fd = sg_cmds_open_device(device_name, false /* rw=false */, verbose);
if (sg_fd < 0) {
pr2serr(ME "open error: %s: %s\n", device_name, safe_strerror(-sg_fd));
- return SG_LIB_FILE_ERROR;
+ return sg_convert_errno(-sg_fd);
}
memset(rdi_buff, 0x0, sizeof(rdi_buff));
@@ -279,7 +279,12 @@ err_out:
if (res < 0) {
pr2serr("close error: %s\n", safe_strerror(-res));
if (0 == ret)
- return SG_LIB_FILE_ERROR;
+ ret = sg_convert_errno(-res);
+ }
+ if (0 == verbose) {
+ if (! sg_if_can2stderr("sg_ident failed: ", ret))
+ pr2serr("Some error occurred, try again with '-v' or '-vv' for "
+ "more information\n");
}
return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
}
diff --git a/src/sg_logs.c b/src/sg_logs.c
index 283a1831..b99b3254 100644
--- a/src/sg_logs.c
+++ b/src/sg_logs.c
@@ -34,7 +34,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.65 20180501"; /* spc5r19 + sbc4r11 */
+static const char * version_str = "1.66 20180510"; /* spc5r19 + sbc4r11 */
#define MX_ALLOC_LEN (0xfffc)
#define SHORT_RESP_LEN 128
@@ -7071,5 +7071,10 @@ err_out:
free(free_rsp_buff);
if (sg_fd >= 0)
sg_cmds_close_device(sg_fd);
+ if (0 == vb) {
+ if (! sg_if_can2stderr("sg_logs failed: ", ret))
+ pr2serr("Some error occurred, try again with '-v' or '-vv' for "
+ "more information\n");
+ }
return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
}
diff --git a/src/sg_luns.c b/src/sg_luns.c
index cacb37c6..d99b3481 100644
--- a/src/sg_luns.c
+++ b/src/sg_luns.c
@@ -31,7 +31,7 @@
* and decodes the response.
*/
-static const char * version_str = "1.39 20180425";
+static const char * version_str = "1.40 20180510";
#define MAX_RLUNS_BUFF_LEN (1024 * 1024)
#define DEF_RLUNS_BUFF_LEN (1024 * 8)
@@ -574,7 +574,7 @@ main(int argc, char * argv[])
sg_fd = sg_cmds_open_device(device_name, o_readonly, verbose);
if (sg_fd < 0) {
pr2serr("open error: %s: %s\n", device_name, safe_strerror(-sg_fd));
- return SG_LIB_FILE_ERROR;
+ return sg_convert_errno(-sg_fd);
}
if (decode_arg && (! lu_cong_arg_given)) {
if (verbose > 1)
@@ -679,5 +679,10 @@ the_end:
if (0 == ret)
return SG_LIB_FILE_ERROR;
}
+ if (0 == verbose) {
+ if (! sg_if_can2stderr("sg_luns failed: ", ret))
+ pr2serr("Some error occurred, try again with '-v' or '-vv' for "
+ "more information\n");
+ }
return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
}