diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2013-03-15 03:57:42 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2013-03-15 03:57:42 +0000 |
commit | 2d978766260dc0dfc2b956f15f4e4c9f11b75911 (patch) | |
tree | 2aa416fd8487a27ce216b9c619358b4c65cc002e /src/sg_luns.c | |
parent | e2a8a0b0661fa14d45e9b088329e38eb3f349a7f (diff) | |
download | sg3_utils-2d978766260dc0dfc2b956f15f4e4c9f11b75911.tar.gz |
sg_luns: make --linux Linux only; in --test make trailing B a W (for wrong LUN flip)
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@490 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'src/sg_luns.c')
-rw-r--r-- | src/sg_luns.c | 79 |
1 files changed, 59 insertions, 20 deletions
diff --git a/src/sg_luns.c b/src/sg_luns.c index 02c07034..c87b18d6 100644 --- a/src/sg_luns.c +++ b/src/sg_luns.c @@ -28,7 +28,7 @@ * and decodes the response. */ -static char * version_str = "1.20 20130305"; +static char * version_str = "1.21 20130314"; #define MAX_RLUNS_BUFF_LEN (1024 * 64) #define DEF_RLUNS_BUFF_LEN (1024 * 8) @@ -40,7 +40,9 @@ static struct option long_options[] = { {"decode", no_argument, 0, 'd'}, {"help", no_argument, 0, 'h'}, {"hex", no_argument, 0, 'H'}, +#ifdef SG_LIB_LINUX {"linux", no_argument, 0, 'l'}, +#endif {"maxlen", required_argument, 0, 'm'}, {"quiet", no_argument, 0, 'q'}, {"raw", no_argument, 0, 'r'}, @@ -54,12 +56,22 @@ static struct option long_options[] = { static void usage() { +#ifdef SG_LIB_LINUX fprintf(stderr, "Usage: " "sg_luns [--decode] [--help] [--hex] [--linux] " "[--maxlen=LEN]\n" " [--quiet] [--raw] [--select=SR] " "[--verbose]\n" - " [--version] DEVICE\n" + " [--version] DEVICE\n"); +#else + fprintf(stderr, "Usage: " + "sg_luns [--decode] [--help] [--hex] [--maxlen=LEN] " + "[--quiet]\n" + " [--raw] [--select=SR] [--verbose] " + "[--version]\n" + " DEVICE\n"); +#endif + fprintf(stderr, " or\n" " sg_luns --test=LUNHEX [--hex] [--verbose]\n" " where:\n" @@ -67,15 +79,17 @@ usage() " --help|-h print out usage message\n" " --hex|-H output response in hexadecimal; used " "twice\n" - " shows decoded values in hex\n" + " shows decoded values in hex\n"); +#ifdef SG_LIB_LINUX + fprintf(stderr, " --linux|-l show Linux integer lun after T10 " - "representation\n" + "representation\n"); +#endif + fprintf(stderr, " --maxlen=LEN|-m LEN max response length (allocation " "length in cdb)\n" - " (def: 0 -> %d bytes)\n", - DEF_RLUNS_BUFF_LEN ); - fprintf(stderr, " --quiet|-q output only ASCII hex lun " - "values\n" + " (def: 0 -> %d bytes)\n" + " --quiet|-q output only ASCII hex lun values\n" " --raw|-r output response in binary\n" " --select=SR|-s SR select report SR (def: 0)\n" " 0 -> luns apart from 'well " @@ -90,8 +104,7 @@ usage() " --version|-V print version string and exit\n\n" "Performs a SCSI REPORT LUNS command. When the --test=LUNHEX " "option is\ngiven, decodes LUNHEX rather than sending a " - "REPORT LUNS command.\n" - ); + "REPORT LUNS command.\n", DEF_RLUNS_BUFF_LEN ); } /* Decoded according to SAM-5 rev 10. Note that one draft: BCC rev 0, @@ -262,6 +275,7 @@ decode_lun(const char * leadin, const unsigned char * lunp, int do_hex, } } +#ifdef SG_LIB_LINUX static void linux2t10_lun(uint64_t linux_lun, unsigned char t10_lun[]) { @@ -304,6 +318,7 @@ t10_2linux_lun64bitBR(const unsigned char t10_lun[]) lun = lun | (((t10_lun[i] << 8) | t10_lun[i + 1]) << (i * 8)); return lun; } +#endif /* SG_LIB_LINUX */ static void @@ -321,15 +336,19 @@ main(int argc, char * argv[]) int sg_fd, k, m, off, res, c, list_len, luns, trunc; int decode = 0; int do_hex = 0; +#ifdef SG_LIB_LINUX int do_linux = 0; +#endif int maxlen = 0; int do_quiet = 0; int do_raw = 0; int select_rep = 0; int verbose = 0; +#ifdef SG_LIB_LINUX int test_linux_in = 0; int test_linux_out = 0; int test_linux_out2 = 0; +#endif unsigned int h; const char * test_arg = NULL; const char * device_name = NULL; @@ -340,8 +359,13 @@ main(int argc, char * argv[]) while (1) { int option_index = 0; +#ifdef SG_LIB_LINUX c = getopt_long(argc, argv, "dhHlm:qrs:t:vV", long_options, &option_index); +#else + c = getopt_long(argc, argv, "dhHm:qrs:t:vV", long_options, + &option_index); +#endif if (c == -1) break; @@ -356,9 +380,11 @@ main(int argc, char * argv[]) case 'H': ++do_hex; break; +#ifdef SG_LIB_LINUX case 'l': ++do_linux; break; +#endif case 'm': maxlen = sg_get_num(optarg); if ((maxlen < 0) || (maxlen > MAX_RLUNS_BUFF_LEN)) { @@ -412,6 +438,8 @@ main(int argc, char * argv[]) if (test_arg) { memset(lun_arr, 0, sizeof(lun_arr)); cp = test_arg; + /* check for leading 'L' */ +#ifdef SG_LIB_LINUX if ('L' == toupper(cp[0])) { uint64_t ull; @@ -422,7 +450,17 @@ main(int argc, char * argv[]) } linux2t10_lun(ull, lun_arr); test_linux_in = 1; - } else { + } else +#endif + { + /* Check if trailing 'L' or 'W' */ + m = strlen(cp); /* must be at least 1 char in test_arg */ +#ifdef SG_LIB_LINUX + if ('L' == toupper(cp[m - 1])) + test_linux_out = 1; + else if ('W' == toupper(cp[m - 1])) + test_linux_out2 = 1; +#endif if (('0' == cp[0]) && ('X' == toupper(cp[1]))) cp += 2; if (strchr(cp, ' ') || strchr(cp, '\t')) { @@ -431,20 +469,12 @@ main(int argc, char * argv[]) break; lun_arr[k] = h & 0xff; } - if (strchr(cp, 'L') || strchr(cp, 'l')) - test_linux_out = 1; - else if (strchr(cp, 'B') || strchr(cp, 'b')) - test_linux_out2 = 1; } else { for (k = 0; k < 8; ++k, cp += 2) { if (1 != sscanf(cp, "%2x", &h)) break; lun_arr[k] = h & 0xff; } - if (strchr(cp, 'L') || strchr(cp, 'l')) - test_linux_out = 1; - else if (strchr(cp, 'B') || strchr(cp, 'b')) - test_linux_out2 = 1; } if (0 == k) { fprintf(stderr, "expected a hex number, optionally prefixed " @@ -452,12 +482,18 @@ main(int argc, char * argv[]) return SG_LIB_SYNTAX_ERROR; } } - if (verbose || test_linux_in || test_linux_out2) { +#ifdef SG_LIB_LINUX + if (verbose || test_linux_in || test_linux_out2) +#else + if (verbose) +#endif + { printf("64 bit LUN in T10 preferred (hex) format: "); for (k = 0; k < 8; ++k) printf(" %02x", lun_arr[k]); printf("\n"); } +#ifdef SG_LIB_LINUX if (test_linux_out) { if (do_hex > 1) printf("Linux 'word flipped' integer LUN representation: " @@ -479,6 +515,7 @@ main(int argc, char * argv[]) printf("Linux internal 64 bit LUN representation: %" PRIu64 "\n", t10_2linux_lun64bitBR(lun_arr)); } +#endif printf("Decoded LUN:\n"); decode_lun(" ", lun_arr, do_hex, verbose); return 0; @@ -544,6 +581,7 @@ main(int argc, char * argv[]) } for (m = 0; m < 8; ++m) printf("%02x", reportLunsBuff[off + m]); +#ifdef SG_LIB_LINUX if (do_linux) { uint64_t lin_lun; @@ -553,6 +591,7 @@ main(int argc, char * argv[]) else printf(" [%" PRIu64 "]", lin_lun); } +#endif printf("\n"); if (decode) decode_lun(" ", reportLunsBuff + off, do_hex, |