aboutsummaryrefslogtreecommitdiff
path: root/sg_ident.c
diff options
context:
space:
mode:
Diffstat (limited to 'sg_ident.c')
-rw-r--r--sg_ident.c72
1 files changed, 42 insertions, 30 deletions
diff --git a/sg_ident.c b/sg_ident.c
index c5eb2a51..2de032a4 100644
--- a/sg_ident.c
+++ b/sg_ident.c
@@ -44,7 +44,7 @@
* SET DEVICE IDENTIFIER and/or INQUIRY (VPD=0x83 [device identifier]).
*/
-static char * version_str = "1.01 20060106";
+static char * version_str = "1.02 20060623";
#define ME "sg_ident: "
@@ -94,7 +94,7 @@ int main(int argc, char * argv[])
int do_set = 0;
int verbose = 0;
char device_name[512];
- int ret = 1;
+ int ret = 0;
memset(device_name, 0, sizeof device_name);
while (1) {
@@ -131,7 +131,7 @@ int main(int argc, char * argv[])
default:
fprintf(stderr, "unrecognised switch code 0x%x ??\n", c);
usage();
- return 1;
+ return SG_LIB_SYNTAX_ERROR;
}
}
if (optind < argc) {
@@ -145,36 +145,36 @@ int main(int argc, char * argv[])
fprintf(stderr, "Unexpected extra argument: %s\n",
argv[optind]);
usage();
- return 1;
+ return SG_LIB_SYNTAX_ERROR;
}
}
if (0 == device_name[0]) {
fprintf(stderr, "missing device name!\n");
usage();
- return 1;
+ return SG_LIB_SYNTAX_ERROR;
}
if (do_set && do_clear) {
fprintf(stderr, "only one of '--clear' and '--set' can be given\n");
usage();
- return 1;
+ return SG_LIB_SYNTAX_ERROR;
}
if (ascii && raw) {
fprintf(stderr, "only one of '--ascii' and '--raw' can be given\n");
usage();
- return 1;
+ return SG_LIB_SYNTAX_ERROR;
}
if ((do_set || do_clear) && (raw || ascii)) {
fprintf(stderr, "'--set' cannot be used with either '--ascii' or "
"'--raw'\n");
usage();
- return 1;
+ return SG_LIB_SYNTAX_ERROR;
}
sg_fd = sg_cmds_open_device(device_name, 0 /* rw */, verbose);
if (sg_fd < 0) {
fprintf(stderr, ME "open error: %s: %s\n", device_name,
safe_strerror(-sg_fd));
- return 1;
+ return SG_LIB_FILE_ERROR;
}
memset(rdi_buff, 0x0, sizeof(rdi_buff));
@@ -194,12 +194,16 @@ int main(int argc, char * argv[])
res = sg_ll_set_dev_id(sg_fd, rdi_buff, di_len, 1, verbose);
} else /* do_clear */
res = sg_ll_set_dev_id(sg_fd, rdi_buff, 0, 1, verbose);
- if (0 == res)
- ret = 0;
- else {
- if (SG_LIB_CAT_INVALID_OP == res)
+ if (res) {
+ ret = res;
+ if (SG_LIB_CAT_NOT_READY == res)
+ fprintf(stderr, "Set Device Identifier command, device "
+ "not ready\n");
+ else if (SG_LIB_CAT_INVALID_OP == res)
fprintf(stderr, "Set Device Identifier command not "
"supported\n");
+ else if (SG_LIB_CAT_UNIT_ATTENTION == res)
+ fprintf(stderr, "Set Device Identifier, unit attention\n");
else if (SG_LIB_CAT_ILLEGAL_REQ == res)
fprintf(stderr, "bad field in Set Device Identifier "
"cdb\n");
@@ -243,20 +247,27 @@ int main(int argc, char * argv[])
dStrHex((const char *)ucp + 4, di_len, 0);
}
}
- ret = 0;
- }
- }
- if (0 != res) {
- if (SG_LIB_CAT_INVALID_OP == res)
- fprintf(stderr, "Report Device Identifier command not "
- "supported\n");
- else if (SG_LIB_CAT_ILLEGAL_REQ == res)
- fprintf(stderr, "bad field in Report Device Identifier "
- "cdb\n");
- else {
- fprintf(stderr, "Report Device Identifier command failed\n");
- if (0 == verbose)
- fprintf(stderr, " try '-v' for more information\n");
+ } else {
+ ret = res;
+ if (SG_LIB_CAT_NOT_READY == res)
+ fprintf(stderr, "Report Device Identifier command, "
+ "device not ready\n");
+ else if (SG_LIB_CAT_UNIT_ATTENTION == res)
+ fprintf(stderr, "Report Device Identifier, unit "
+ "attention\n");
+ else if (SG_LIB_CAT_INVALID_OP == res)
+ fprintf(stderr, "Report Device Identifier command not "
+ "supported\n");
+ else if (SG_LIB_CAT_ILLEGAL_REQ == res)
+ fprintf(stderr, "bad field in Report Device Identifier "
+ "cdb\n");
+ else {
+ fprintf(stderr, "Report Device Identifier command "
+ "failed\n");
+ if (0 == verbose)
+ fprintf(stderr, " try '-v' for more "
+ "information\n");
+ }
}
}
}
@@ -264,8 +275,9 @@ int main(int argc, char * argv[])
err_out:
res = sg_cmds_close_device(sg_fd);
if (res < 0) {
- fprintf(stderr, ME "close error: %s\n", safe_strerror(-res));
- return 1;
+ fprintf(stderr, "close error: %s\n", safe_strerror(-res));
+ if (0 == ret)
+ return SG_LIB_FILE_ERROR;
}
- return ret;
+ return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
}