sg_copy_results: fix in service action name strings; xcopy 3PC output and doco

git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@520 6180dd3e-e324-4e3e-922d-17de1ae2f315
diff --git a/ChangeLog b/ChangeLog
index effec7c..4e01c2b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,7 @@
 some description at the top of its ".c" file. All utilities in the main
 directory have their own "man" pages. There is also a sg3_utils man page.
 
-Changelog for sg3_utils-1.37 [20130927] [svn: r519]
+Changelog for sg3_utils-1.37 [20131007] [svn: r520]
   - sg_compare_and_write: fix wrprotect setting
     - add --quiet option to suppress miscompare report
     - merge features from another implementation
@@ -21,6 +21,7 @@
     - add --quiet option
   - sg_xcopy: allow sg and bsg devices
     - fix for bpt going negative
+    - limit each XCOPY(LID1) command to 65535 blocks
     - fix for seek in multi-segment copies
   - sg_sanitize: skip 15 second safety delay with --fail
   - sg_libs: extended copy opcode renamed (spc4r34)
@@ -31,7 +32,7 @@
     - add dStrHexStr(): ascii hex to string
     - add SG_LIB_CAT_MISCOMPARE to categories
     - clean header files
-  - sg_pt_freebsd: sanity check on sense_resid
+  - sg_pt_freebsd: sanity check on sense_resid; fix leaks
   - scripts/rescan-scsi-bus.sh KG's v1.57 + HR patch
     - improve wlun handling, detect updated and resized
       devices, better multipath support
diff --git a/README b/README
index c446861..27aa5df 100644
--- a/README
+++ b/README
@@ -396,4 +396,4 @@
 
 
 Douglas Gilbert
-27th September 2013
+8th October 2013
diff --git a/debian/changelog b/debian/changelog
index 69402db..f93678f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,7 +2,7 @@
 
   * New upstream version
 
- -- Douglas Gilbert <dgilbert@interlog.com>  Fri, 27 Sep 2013 14:00:00 -0400
+ -- Douglas Gilbert <dgilbert@interlog.com>  Tue, 08 Oct 2013 10:00:00 -0400
 
 sg3-utils (1.36-0.1) unstable; urgency=low
 
diff --git a/doc/sg3_utils.8 b/doc/sg3_utils.8
index 95e49f6..ae9b181 100644
--- a/doc/sg3_utils.8
+++ b/doc/sg3_utils.8
@@ -1,4 +1,4 @@
-.TH SG3_UTILS "8" "August 2013" "sg3_utils\-1.37" SG3_UTILS
+.TH SG3_UTILS "8" "October 2013" "sg3_utils\-1.37" SG3_UTILS
 .SH NAME
 sg3_utils \- a package of utilities for sending SCSI commands
 .SH SYNOPSIS
diff --git a/doc/sg_xcopy.8 b/doc/sg_xcopy.8
index be6d69b..883f729 100644
--- a/doc/sg_xcopy.8
+++ b/doc/sg_xcopy.8
@@ -1,4 +1,4 @@
-.TH SG_XCOPY "8" "June 2013" "sg3_utils\-1.37" SG3_UTILS
+.TH SG_XCOPY "8" "October 2013" "sg3_utils\-1.37" SG3_UTILS
 .SH NAME
 sg_xcopy \- copy data to and from files and devices using SCSI EXTENDED
 COPY (XCOPY)
@@ -181,13 +181,6 @@
 block \fISEEK\fR. Note that attempting to 'append' to a device file (e.g.
 a disk) will usually be ignored or may cause an error to be reported.
 .TP
-pad
-sets the SCSI EXTENDED COPY command segment descriptor PAD bit. The
-PAD bit (in conjunction with the CAT bit) controls the handling of
-residual data.(See section
-.B HANDLING OF RESIDUAL DATA
-for details.
-.TP
 excl
 causes the O_EXCL flag to be added to the open of \fIIFILE\fR and/or
 \fIOFILE\fR.
@@ -202,6 +195,16 @@
 .TP
 null
 has no affect, just a placeholder.
+.TP
+pad
+sets the SCSI EXTENDED COPY command segment descriptor PAD bit. The
+PAD bit (in conjunction with the CAT bit) controls the handling of
+residual data.(See section
+.B HANDLING OF RESIDUAL DATA
+for details.
+.TP
+xcopy
+has no affect; for compatibility with ddpt.
 .SH HANDLING OF RESIDUAL DATA
 The \fIpad\fR and \fIcat\fR bits control the handling of residual
 data. As the data can be specified either in terms of source or target
@@ -248,6 +251,12 @@
 dd's output file can be stdout and remain unpolluted. If no options
 are given, then the usage message is output and nothing else happens.
 .PP
+If a device supports xcopy operations then it should set the 3PC
+field (3PC stands for Third Party Copy) in its standard INQUIRY response.
+This utility will attempt a xcopy operation irrespective of the value
+in the 3PC field but if it is zero (cleared) one would expect the
+xcopy operation to fail.
+.PP
 The status of the SCSI EXTENDED COPY command can be queried with
 .B sg_copy_results(sg3_utils)
 .PP
@@ -327,4 +336,4 @@
 .B sdparm(sdparm)
 .PP
 See also
-.B dd(1), sg_copy_results(sg3_utils), ddrescue(GNU), ddpt
+.B dd(1), sg_copy_results(sg3_utils), ddrescue(GNU), ddpt(ddpt)
diff --git a/sg3_utils.spec b/sg3_utils.spec
index c72f984..3f7573f 100644
--- a/sg3_utils.spec
+++ b/sg3_utils.spec
@@ -79,7 +79,7 @@
 %{_libdir}/*.la
 
 %changelog
-* Fri Sep 27 2013 - dgilbert at interlog dot com
+* Tue Oct 08 2013 - dgilbert at interlog dot com
 - track t10 changes
   * sg3_utils-1.37
 
diff --git a/src/sg_copy_results.c b/src/sg_copy_results.c
index 1bb4f25..d73bf5d 100644
--- a/src/sg_copy_results.c
+++ b/src/sg_copy_results.c
@@ -34,7 +34,7 @@
    and the optional list identifier passed as the list_id argument.
 */
 
-static const char * version_str = "1.4 20130730";
+static const char * version_str = "1.5 20131007";
 
 
 #define MAX_XFER_LEN 10000
@@ -177,7 +177,7 @@
                 " output truncated\n");
     }
     printf("Receive copy results (report operating parameters):\n");
-    printf("    Supports no list identifier: %s\n",
+    printf("    Supports no list identifier (SNLID): %s\n",
            rcBuff[4] & 1 ? "yes" : "no");
     n = (rcBuff[8] << 8) | rcBuff[9];
     printf("    Maximum target descriptor count: %u\n", n);
@@ -403,7 +403,7 @@
         return SG_LIB_FILE_ERROR;
     }
 
-    cp = (const char *)&rec_copy_name_arr[sa];
+    cp = rec_copy_name_arr[sa];
     if (verbose)
         fprintf(stderr, ME "issue %s to device %s\n\t\txfer_len= %d (0x%x), "
                 "list_id=%d\n", cp, device_name, xfer_len, xfer_len,
diff --git a/src/sg_xcopy.c b/src/sg_xcopy.c
index 306d7f1..17f0bff 100644
--- a/src/sg_xcopy.c
+++ b/src/sg_xcopy.c
@@ -62,7 +62,7 @@
 #include "sg_cmds_extra.h"
 #include "sg_io_linux.h"
 
-static const char * version_str = "0.38 20130819";
+static const char * version_str = "0.39 20131006";
 
 #define ME "sg_xcopy: "
 
@@ -340,8 +340,9 @@
 
     fp->pdt = sir.peripheral_type;
     if (verbose)
-        pr2serr("    %s: %.8s  %.16s  %.4s  [pdt=%d]\n", fp->fname,
-                sir.vendor, sir.product, sir.revision, fp->pdt);
+        pr2serr("    %s: %.8s  %.16s  %.4s  [pdt=%d, 3pc=%d]\n", fp->fname,
+                sir.vendor, sir.product, sir.revision, fp->pdt,
+                !! (0x8 & sir.byte_5));
 
     return fp->sg_fd;
 }
@@ -514,13 +515,13 @@
             "    dc          segment descriptor DC bit (default: 0)\n"
             "    ibs         input block size (if given must be same as "
             "'bs=')\n"
-            "    id_usage    sets list id usage field to hold (0), "
+            "    id_usage    sets list_id_usage field to hold (0), "
             "discard (2) or\n"
             "                disable (3)\n"
             "    if          file or device to read from (def: stdin)\n"
             "    iflag       comma separated list from: [cat,dc,excl,"
             "flock,null]\n"
-            "    list_id     sets list identifier field to ID (default: 1)\n"
+            "    list_id     sets list_id field to ID (default: 1 or 0)\n"
             "    obs         output block size (if given must be same as "
             "'bs=')\n"
             "    of          file or device to write to (def: stdout), "
@@ -664,7 +665,7 @@
 static int
 scsi_operating_parameter(struct xcopy_fp_t *xfp, int is_target)
 {
-    int res, ftype;
+    int res, ftype, snlid;
     unsigned char rcBuff[256];
     unsigned int rcBuffLen = 256, len, n, td_list = 0;
     unsigned long num, max_target_num, max_segment_num, max_segment_len;
@@ -696,6 +697,7 @@
         pr2serr("\nOutput response in hex:\n");
         dStrHexErr((const char *)rcBuff, len, 1);
     }
+    snlid = rcBuff[4] & 0x1;
     max_target_num = rcBuff[8] << 8 | rcBuff[9];
     max_segment_num = rcBuff[10] << 8 | rcBuff[11];
     max_desc_len = rcBuff[12] << 24 | rcBuff[13] << 16 | rcBuff[14] << 8 |
@@ -707,6 +709,7 @@
                       rcBuff[23];
     if (verbose) {
         pr2serr(" >> Receive copy results (report operating parameters):\n");
+        pr2serr("    Support No List IDentifier (SNLID): %d\n", snlid);
         pr2serr("    Maximum target descriptor count: %lu\n", max_target_num);
         pr2serr("    Maximum segment descriptor count: %lu\n",
                 max_segment_num);
@@ -723,8 +726,8 @@
             list_id_usage = 0;
     }
     if (verbose) {
-        pr2serr("    Held data limit: %lu (usage: %d)\n", held_data_limit,
-                list_id_usage);
+        pr2serr("    Held data limit: %lu (list_id_usage: %d)\n",
+                held_data_limit, list_id_usage);
         num = rcBuff[28] << 24 | rcBuff[29] << 16 | rcBuff[30] << 8 |
               rcBuff[31];
         pr2serr("    Maximum stream device transfer size: %lu\n", num);
@@ -1307,14 +1310,16 @@
             *np++ = '\0';
         if (0 == strcmp(cp, "append"))
             fp->append = 1;
-        else if (0 == strcmp(cp, "pad"))
-            fp->pad = 1;
         else if (0 == strcmp(cp, "excl"))
             fp->excl = 1;
-        else if (0 == strcmp(cp, "null"))
-            ;
         else if (0 == strcmp(cp, "flock"))
             ++fp->flock;
+        else if (0 == strcmp(cp, "null"))
+            ;
+        else if (0 == strcmp(cp, "pad"))
+            fp->pad = 1;
+        else if (0 == strcmp(cp, "xcopy"))
+            ;   /* ignore, for ddpt compatibility */
         else {
             pr2serr("unrecognised flag: %s\n", cp);
             return 1;
@@ -1608,6 +1613,8 @@
             verbose += 2;
         else if (0 == strcmp(key, "-v"))
             verbose += 1;
+        else if (0 == strncmp(key, "--xcopy", 6))
+            ;   /* ignore; for compatibility with ddpt */
         else {
             pr2serr("Unrecognized option '%s'\n", key);
             pr2serr("For more information use '--help'\n");