diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2008-04-20 05:01:10 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2008-04-20 05:01:10 +0000 |
commit | 225607ea7a970aaee3152bb0b085352d2decc854 (patch) | |
tree | 6a8e389b704701eabea12e02df4ac47e09d2d66f /src | |
parent | f93d250a7c32b60595db211b195e9d167b778e70 (diff) | |
download | sg3_utils-225607ea7a970aaee3152bb0b085352d2decc854.tar.gz |
add --maxlen= argument to sg_luns
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@169 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'src')
-rw-r--r-- | src/sg_luns.c | 109 | ||||
-rw-r--r-- | src/sg_raw.c | 31 | ||||
-rw-r--r-- | src/sg_requests.c | 8 |
3 files changed, 90 insertions, 58 deletions
diff --git a/src/sg_luns.c b/src/sg_luns.c index 9a5b07fb..a2d573a1 100644 --- a/src/sg_luns.c +++ b/src/sg_luns.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2007 Douglas Gilbert. + * Copyright (c) 2004-2008 Douglas Gilbert. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -48,54 +48,63 @@ * This program issues the SCSI command REPORT LUNS to the given SCSI device. */ -static char * version_str = "1.12 20070919"; +static char * version_str = "1.13 20080406"; -#define REPORT_LUNS_BUFF_LEN (1024*64) +#define MAX_RLUNS_BUFF_LEN (1024 * 64) +#define DEF_RLUNS_BUFF_LEN MAX_RLUNS_BUFF_LEN -static unsigned char reportLunsBuff[REPORT_LUNS_BUFF_LEN]; +static unsigned char reportLunsBuff[MAX_RLUNS_BUFF_LEN]; static struct option long_options[] = { - {"decode", 0, 0, 'd'}, - {"help", 0, 0, 'h'}, - {"hex", 0, 0, 'H'}, - {"quiet", 0, 0, 'q'}, - {"raw", 0, 0, 'r'}, - {"select", 1, 0, 's'}, - {"verbose", 0, 0, 'v'}, - {"version", 0, 0, 'V'}, + {"decode", no_argument, 0, 'd'}, + {"help", no_argument, 0, 'h'}, + {"hex", no_argument, 0, 'H'}, + {"maxlen", required_argument, 0, 'm'}, + {"quiet", no_argument, 0, 'q'}, + {"raw", no_argument, 0, 'r'}, + {"select", required_argument, 0, 's'}, + {"verbose", no_argument, 0, 'v'}, + {"version", no_argument, 0, 'V'}, {0, 0, 0, 0}, }; -static void usage() +static void +usage() { fprintf(stderr, "Usage: " - "sg_luns [--decode] [--help] [--hex] [--quiet] [--raw] " - "[--select=SR]\n" - " [--verbose] [--version] DEVICE\n" - " where:\n" - " --decode|-d decode all luns into component parts\n" - " --help|-h print out usage message\n" - " --hex|-H output in hexadecimal\n" - " --quiet|-q output only ASCII hex lun values\n" - " --raw|-r output in binary\n" - " --select=SR|-s SR select report SR (def: 0)\n" - " 0 -> luns apart from 'well " - "known' lus\n" - " 1 -> only 'well known' " - "logical unit numbers\n" - " 2 -> all luns\n" - " --verbose|-v increase verbosity\n" - " --version|-V print version string and exit\n\n" - "Performs a SCSI REPORT LUNS command\n" - ); + "sg_luns [--decode] [--help] [--hex] [--maxlen=LEN] [--quiet] " + "[--raw]\n" + " [--select=SR] [--verbose] [--version] DEVICE\n" + " where:\n" + " --decode|-d decode all luns into component parts\n" + " --help|-h print out usage message\n" + " --hex|-H output in hexadecimal\n" + " --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" + " --raw|-r output in binary\n" + " --select=SR|-s SR select report SR (def: 0)\n" + " 0 -> luns apart from 'well " + "known' lus\n" + " 1 -> only 'well known' " + "logical unit numbers\n" + " 2 -> all luns\n" + " --verbose|-v increase verbosity\n" + " --version|-V print version string and exit\n\n" + "Performs a SCSI REPORT LUNS command\n" + ); } /* Decoded according to SAM-4 rev 4. Note that one draft: BCC rev 0, * defines its own "bridge addressing method" in place of the SAM-3 * "logical addressing method". */ -static void decode_lun(const char * leadin, unsigned char * lunp) +static void +decode_lun(const char * leadin, unsigned char * lunp) { int k, j, x, a_method, bus_id, target, lun, len, e_a_method, next_level; unsigned char not_spec[8] = {0xff, 0xff, 0xff, 0xff, @@ -207,7 +216,8 @@ static void decode_lun(const char * leadin, unsigned char * lunp) } } -static void dStrRaw(const char* str, int len) +static void +dStrRaw(const char* str, int len) { int k; @@ -215,11 +225,13 @@ static void dStrRaw(const char* str, int len) printf("%c", str[k]); } -int main(int argc, char * argv[]) +int +main(int argc, char * argv[]) { int sg_fd, k, m, off, res, c, list_len, luns, trunc; int decode = 0; int do_hex = 0; + int maxlen = 0; int do_quiet = 0; int do_raw = 0; int select_rep = 0; @@ -230,7 +242,7 @@ int main(int argc, char * argv[]) while (1) { int option_index = 0; - c = getopt_long(argc, argv, "dhHqrs:vV", long_options, + c = getopt_long(argc, argv, "dhHm:qrs:vV", long_options, &option_index); if (c == -1) break; @@ -246,6 +258,14 @@ int main(int argc, char * argv[]) case 'H': ++do_hex; break; + case 'm': + maxlen = sg_get_num(optarg); + if ((maxlen < 0) || (maxlen > MAX_RLUNS_BUFF_LEN)) { + fprintf(stderr, "argument to '--maxlen' should be %d or " + "less\n", MAX_RLUNS_BUFF_LEN); + return SG_LIB_SYNTAX_ERROR; + } + break; case 'q': ++do_quiet; break; @@ -290,6 +310,9 @@ int main(int argc, char * argv[]) usage(); return SG_LIB_SYNTAX_ERROR; } + if (0 == maxlen) + maxlen = DEF_RLUNS_BUFF_LEN; + sg_fd = sg_cmds_open_device(device_name, 0 /* rw */, verbose); if (sg_fd < 0) { fprintf(stderr, "open error: %s: %s\n", device_name, @@ -297,11 +320,11 @@ int main(int argc, char * argv[]) return SG_LIB_FILE_ERROR; } - memset(reportLunsBuff, 0x0, sizeof(reportLunsBuff)); + memset(reportLunsBuff, 0x0, maxlen); trunc = 0; - res = sg_ll_report_luns(sg_fd, select_rep, reportLunsBuff, - sizeof(reportLunsBuff), 1, verbose); + res = sg_ll_report_luns(sg_fd, select_rep, reportLunsBuff, maxlen, 1, + verbose); ret = res; if (0 == res) { list_len = (reportLunsBuff[0] << 24) + (reportLunsBuff[1] << 16) + @@ -318,16 +341,16 @@ int main(int argc, char * argv[]) if (0 == do_quiet) printf("Lun list length = %d which imples %d lun entr%s\n", list_len, luns, ((1 == luns) ? "y" : "ies")); - if ((list_len + 8) > (int)sizeof(reportLunsBuff)) { - luns = ((sizeof(reportLunsBuff) - 8) / 8); + if ((list_len + 8) > maxlen) { + luns = ((maxlen - 8) / 8); trunc = 1; fprintf(stderr, " <<too many luns for internal buffer, will " - "show %d luns>>\n", luns); + "show %d lun%s>>\n", luns, ((1 == luns) ? "" : "s")); } if (verbose > 1) { fprintf(stderr, "\nOutput response in hex\n"); dStrHex((const char *)reportLunsBuff, - (trunc ? (int)sizeof(reportLunsBuff) : list_len + 8), 1); + (trunc ? maxlen : list_len + 8), 1); } for (k = 0, off = 8; k < luns; ++k) { if (0 == do_quiet) { diff --git a/src/sg_raw.c b/src/sg_raw.c index a487e06d..f4c2af86 100644 --- a/src/sg_raw.c +++ b/src/sg_raw.c @@ -25,7 +25,7 @@ #include "sg_lib.h" #include "sg_pt.h" -#define SG_RAW_VERSION "0.3.5 (2007-08-20)" +#define SG_RAW_VERSION "0.3.6 (2008-04-17)" #define DEFAULT_TIMEOUT 20 #define MIN_SCSI_CDBSZ 6 @@ -66,7 +66,8 @@ struct opts_t { int do_version; }; -static void version() +static void +version() { fprintf(stderr, "sg_raw " SG_RAW_VERSION "\n" @@ -78,7 +79,8 @@ static void version() "There is NO WARRANTY, to the extent permitted by law.\n"); } -static void usage() +static void +usage() { fprintf(stderr, "Usage: sg_raw [OPTION] DEVICE CDB0 CDB1 ...\n" @@ -87,15 +89,15 @@ static void usage() " -b, --binary Dump data in binary form, even when " "writing to stdout\n" " -h, --help Show this message and exit\n" - " -i, --infile=FILE Read data to send from FILE (default: " + " -i, --infile=IFILE Read data to send from IFILE (default: " "stdin)\n" " -k, --skip=LEN Skip the first LEN bytes when reading " "data to send\n" " -n, --nosense Don't display sense information\n" - " -o, --outfile=FILE Write data to FILE (default: hexdump " + " -o, --outfile=OFILE Write data to OFILE (default: hexdump " "to stdout)\n" - " -r, --request=LEN Request up to LEN bytes of data\n" - " -s, --send=LEN Send LEN bytes of data\n" + " -r, --request=RLEN Request up to RLEN bytes of data\n" + " -s, --send=SLEN Send SLEN bytes of data\n" " -t, --timeout=SEC Timeout in seconds (default: 20)\n" " -v, --verbose Increase verbosity\n" " -V, --version Show version information and exit\n" @@ -107,7 +109,8 @@ static void usage() " sg_raw -r 1k /dev/sg0 12 00 00 00 60 00\n"); } -static int process_cl(struct opts_t *optsp, int argc, char *argv[]) +static int +process_cl(struct opts_t *optsp, int argc, char *argv[]) { while (1) { int c, n; @@ -223,7 +226,8 @@ static int process_cl(struct opts_t *optsp, int argc, char *argv[]) return 0; } -static int skip(int fd, off_t offset) +static int +skip(int fd, off_t offset) { off_t remain; char buffer[512]; @@ -253,7 +257,8 @@ static int skip(int fd, off_t offset) return 0; } -static unsigned char *fetch_dataout(struct opts_t *optsp) +static unsigned char * +fetch_dataout(struct opts_t *optsp) { unsigned char *buf = NULL; int fd, len; @@ -303,7 +308,8 @@ bail: return buf; } -static int write_dataout(const char *filename, unsigned char *buf, int len) +static int +write_dataout(const char *filename, unsigned char *buf, int len) { int ret = SG_LIB_CAT_OTHER; int fd; @@ -331,7 +337,8 @@ bail: return ret; } -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { int ret = 0; int res_cat; diff --git a/src/sg_requests.c b/src/sg_requests.c index 5207d73a..2f72b259 100644 --- a/src/sg_requests.c +++ b/src/sg_requests.c @@ -47,7 +47,7 @@ * This program issues the SCSI command REQUEST SENSE to the given SCSI device. */ -static char * version_str = "1.20 20080404"; +static char * version_str = "1.20 20080406"; #define MAX_REQS_RESP_LEN 255 #define DEF_REQS_RESP_LEN 252 @@ -115,7 +115,8 @@ usage() } -static void dStrRaw(const char* str, int len) +static void +dStrRaw(const char* str, int len) { int k; @@ -123,7 +124,8 @@ static void dStrRaw(const char* str, int len) printf("%c", str[k]); } -int main(int argc, char * argv[]) +int +main(int argc, char * argv[]) { int sg_fd, res, c, resp_len, k, progress; unsigned char requestSenseBuff[MAX_REQS_RESP_LEN + 1]; |