aboutsummaryrefslogtreecommitdiff
path: root/src/sg_sanitize.c
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2012-02-23 05:17:49 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2012-02-23 05:17:49 +0000
commitc410806c13d2baab90641ef6816866cd6e6bfeff (patch)
tree2f16adddbbfae85dfe4eafd2ce804574a32bae27 /src/sg_sanitize.c
parent5a7d1a76846e903ba66d96c2649ff8c700d0d35a (diff)
downloadsg3_utils-c410806c13d2baab90641ef6816866cd6e6bfeff.tar.gz
sg_inq --export, sg_sanitize --ause --fail --test=, partial spc4r34+sbc3r30 sync
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@441 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'src/sg_sanitize.c')
-rw-r--r--src/sg_sanitize.c55
1 files changed, 42 insertions, 13 deletions
diff --git a/src/sg_sanitize.c b/src/sg_sanitize.c
index 4abf23cc..9b5cd381 100644
--- a/src/sg_sanitize.c
+++ b/src/sg_sanitize.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011 Douglas Gilbert.
+ * Copyright (c) 2011-2012 Douglas Gilbert.
* All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the BSD_LICENSE file.
@@ -26,7 +26,7 @@
#include "sg_cmds_basic.h"
#include "sg_cmds_extra.h"
-static char * version_str = "0.90 20110622";
+static char * version_str = "0.91 20120222";
/* Not all environments support the Unix sleep() */
#if defined(MSC_VER) || defined(__MINGW32__)
@@ -56,16 +56,19 @@ static char * version_str = "0.90 20110622";
static struct option long_options[] = {
+ {"ause", no_argument, 0, 'A'},
{"block", no_argument, 0, 'B'},
{"count", required_argument, 0, 'c'},
{"crypto", no_argument, 0, 'C'},
{"early", no_argument, 0, 'e'},
+ {"fail", no_argument, 0, 'F'},
{"help", no_argument, 0, 'h'},
{"invert", no_argument, 0, 'I'},
{"ipl", required_argument, 0, 'i'},
{"overwrite", no_argument, 0, 'O'},
{"pattern", required_argument, 0, 'p'},
{"quick", no_argument, 0, 'Q'},
+ {"test", required_argument, 0, 'T'},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
{"wait", no_argument, 0, 'w'},
@@ -73,13 +76,16 @@ static struct option long_options[] = {
};
struct opts_t {
+ int ause;
int block;
int count;
int crypto;
int early;
+ int fail;
int invert;
int ipl; /* initialization pattern length */
int overwrite;
+ int test;
int quick;
int verbose;
int wait;
@@ -92,13 +98,14 @@ static void
usage()
{
fprintf(stderr, "Usage: "
- "sg_sanitize [--block] [--count=OC] [--crypto] [--early] "
- "[--help]\n"
+ "sg_sanitize [--ause] [--block] [--count=OC] [--crypto] [--early] "
+ "[--fail] [--help]\n"
" [--invert] [--ipl=LEN] [--overwrite] "
"[--pattern=PF]\n"
- " [--quick] [--verbose] [--version] [--wait] "
+ " [--quick] [--test=TE] [--verbose] [--version] [--wait] "
"DEVICE\n"
" where:\n"
+ " --ause|-A set AUSE bit in cdb\n"
" --block|-B do BLOCK ERASE sanitize\n"
" --count=OC|-c OC OC is overwrite count field (from 1 "
"(def) to 31)\n"
@@ -107,6 +114,7 @@ usage()
"in cdb)\n"
" user can monitor progress with REQUEST "
"SENSE\n"
+ " --fail|-F do EXIT FAILURE MODE sanitize\n"
" --help|-h print out usage message\n"
" --invert|-I set INVERT bit in OVERWRITE parameter "
"list\n"
@@ -119,6 +127,9 @@ usage()
" --quick|-Q start sanitize without pause for user\n"
" intervention (i.e. no time to "
"reconsider)\n"
+ " --test=TE|-T TE TE is placed in TEST field of "
+ "OVERWRITE\n"
+ " parameter list (def: 0)\n"
" --verbose|-v increase verbosity\n"
" --version|-V print version string then exit\n"
" --wait|-w wait for command to finish (could "
@@ -154,10 +165,14 @@ do_sanitize(int sg_fd, const struct opts_t * op, const void * param_lstp,
sanCmdBlk[1] = 2;
else if (op->crypto)
sanCmdBlk[1] = 3;
+ else if (op->fail)
+ sanCmdBlk[1] = 0x1f;
else
return SG_LIB_SYNTAX_ERROR;
if (immed)
sanCmdBlk[1] |= 0x80;
+ if (op->ause)
+ sanCmdBlk[1] |= 0x20;
sanCmdBlk[7] = ((param_lst_len >> 8) & 0xff);
sanCmdBlk[8] = (param_lst_len & 0xff);
@@ -244,12 +259,15 @@ main(int argc, char * argv[])
while (1) {
int option_index = 0;
- c = getopt_long(argc, argv, "Bc:Cehi:IOp:QvVw", long_options,
+ c = getopt_long(argc, argv, "ABc:CeFhi:IOp:QT:vVw", long_options,
&option_index);
if (c == -1)
break;
switch (c) {
+ case 'A':
+ ++opts.ause;
+ break;
case 'B':
++opts.block;
break;
@@ -267,6 +285,9 @@ main(int argc, char * argv[])
case 'e':
++opts.early;
break;
+ case 'F':
+ ++opts.fail;
+ break;
case 'h':
case '?':
usage();
@@ -291,6 +312,13 @@ main(int argc, char * argv[])
case 'Q':
++opts.quick;
break;
+ case 'T':
+ opts.test = sg_get_num(optarg);
+ if ((opts.test < 0) || (opts.test > 3)) {
+ fprintf(stderr, "bad argument to '--test', expect 0 to 3\n");
+ return SG_LIB_SYNTAX_ERROR;
+ }
+ break;
case 'v':
++opts.verbose;
break;
@@ -325,10 +353,10 @@ main(int argc, char * argv[])
return SG_LIB_SYNTAX_ERROR;
}
vb = opts.verbose;
- n = !!opts.block + !!opts.crypto + !!opts.overwrite;
+ n = !!opts.block + !!opts.crypto + !!opts.fail + !!opts.overwrite;
if (1 != n) {
- fprintf(stderr, "one and only one of '--block', '--crypto' or "
- "'--overwrite' please\n");
+ fprintf(stderr, "one and only one of '--block', '--crypto', "
+ "'--fail' or '--overwrite' please\n");
return SG_LIB_SYNTAX_ERROR;
}
if (opts.overwrite) {
@@ -341,9 +369,8 @@ main(int argc, char * argv[])
if (! got_stdin) {
memset(&a_stat, 0, sizeof(a_stat));
if (stat(opts.pattern_fn, &a_stat) < 0) {
- if (vb)
- fprintf(stderr, "unable to stat(%s): %s\n",
- opts.pattern_fn, safe_strerror(errno));
+ fprintf(stderr, "pattern file: unable to stat(%s): %s\n",
+ opts.pattern_fn, safe_strerror(errno));
return SG_LIB_FILE_ERROR;
}
if (opts.ipl <= 0) {
@@ -424,7 +451,9 @@ main(int argc, char * argv[])
if (! got_stdin)
close(infd);
- wBuff[0] = opts.count;
+ wBuff[0] = opts.count & 0x1f;;
+ if (opts.test)
+ wBuff[0] |= ((opts.test & 0x3) << 5);
if (opts.invert)
wBuff[0] |= 0x80;
wBuff[2] = ((opts.ipl >> 8) & 0xff);