[PATCH sg3_utils] sg_xcopy: Improve the code for building a CSCD descriptor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Since the maximum length of the designator field in an identification CSCD
descriptor is 20 bytes, accept designators with a length of up to 20 bytes.

Since the upper four bits of byte 4 in a CSCD descriptor are reserved, use
mask 0x0f instead of 0x1f for that byte.

Since the upper two bits of byte 5 in a CSCD descriptor are reserved, use
mask 0x3f for that byte.

Compile-tested only.

Cc: Eitan Cohen <eitancohen456@xxxxxxxxx>
Cc: Hannes Reinecke <hare@xxxxxxxx>
Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
---
 src/sg_xcopy.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/sg_xcopy.c b/src/sg_xcopy.c
index e691a73ef4c9..dff565a2eab8 100644
--- a/src/sg_xcopy.c
+++ b/src/sg_xcopy.c
@@ -1075,27 +1075,27 @@ desc_from_vpd_id(int sg_fd, uint8_t *desc, int desc_len,
         if (verbose > 2)
             pr2serr("    Desc %d: assoc %u desig %u len %d\n", off, assoc,
                     desig, i_len);
-        /* Descriptor must be less than 16 bytes */
-        if (i_len > 16)
+        /* Designator length must be <= 20. */
+        if (i_len > 20)
             continue;
-        if (desig == 3) {
+        if (desig == /*NAA=*/3) {
             best = bp;
             best_len = i_len;
             break;
         }
-        if (desig == 2) {
+        if (desig == /*EUI64=*/2) {
             if (!best || f_desig < 2) {
                 best = bp;
                 best_len = i_len;
                 f_desig = 2;
             }
-        } else if (desig == 1) {
+        } else if (desig == /*T10*/1) {
             if (!best || f_desig == 0) {
                 best = bp;
                 best_len = i_len;
                 f_desig = desig;
             }
-        } else if (desig == 0) {
+        } else if (desig == /*vend.spec.=*/0) {
             if (!best) {
                 best = bp;
                 best_len = i_len;
@@ -1108,9 +1108,10 @@ desc_from_vpd_id(int sg_fd, uint8_t *desc, int desc_len,
             decode_designation_descriptor(best, best_len);
         if (best_len + 4 < desc_len) {
             memset(desc, 0, 32);
-            desc[0] = 0xe4;
+            desc[0] = 0xe4; /* Identification Descriptor */
             memcpy(desc + 4, best, best_len + 4);
-            desc[4] &= 0x1f;
+            desc[4] &= 0x0f; /* code set */
+	    desc[5] &= 0x3f; /* association and designator type */
             if (pad)
                 desc[28] = 0x4;
             sg_put_unaligned_be24((uint32_t)block_size, desc + 29);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux