Diff for /embedaddon/istgt/src/istgt_lu_dvd.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2012/02/21 16:42:02 version 1.1.1.2, 2012/10/09 09:13:23
Line 1 Line 1
 /*  /*
 * Copyright (C) 2008-2011 Daisuke Aoyama <aoyama@peach.ne.jp>. * Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
  * All rights reserved.   * All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
Line 57 Line 57
 #include "istgt_proto.h"  #include "istgt_proto.h"
 #include "istgt_scsi.h"  #include "istgt_scsi.h"
   
   #if !defined(__GNUC__)
   #undef __attribute__
   #define __attribute__(x)
   #endif
   
 //#define ISTGT_TRACE_DVD  //#define ISTGT_TRACE_DVD
   
 #define DEFAULT_DVD_BLOCKLEN 2048  #define DEFAULT_DVD_BLOCKLEN 2048
Line 103  typedef struct istgt_lu_dvd_t { Line 108  typedef struct istgt_lu_dvd_t {
         volatile int sense;          volatile int sense;
 } ISTGT_LU_DVD;  } ISTGT_LU_DVD;
   
#define BUILD_SENSE(SK,ASC,ASCQ)                                                                                \#define BUILD_SENSE(SK,ASC,ASCQ)                                        \
        do {                                                                                                                            \        do {                                                            \
                *sense_len =                                                                                                    \                *sense_len =                                            \
                        istgt_lu_dvd_build_sense_data(spec, sense_data,                         \                        istgt_lu_dvd_build_sense_data(spec, sense_data, \
                                                                                   ISTGT_SCSI_SENSE_ ## SK,             \                            ISTGT_SCSI_SENSE_ ## SK,                    \
                                                                                   (ASC), (ASCQ));                              \                            (ASC), (ASCQ));                             \
         } while (0)          } while (0)
   
 static int istgt_lu_dvd_build_sense_data(ISTGT_LU_DVD *spec, uint8_t *data, int sk, int asc, int ascq);  static int istgt_lu_dvd_build_sense_data(ISTGT_LU_DVD *spec, uint8_t *data, int sk, int asc, int ascq);
Line 178  istgt_lu_dvd_write(ISTGT_LU_DVD *spec, const void *buf Line 183  istgt_lu_dvd_write(ISTGT_LU_DVD *spec, const void *buf
 }  }
   
 static int64_t  static int64_t
istgt_lu_dvd_sync(ISTGT_LU_DVD *spec, uint64_t offset, uint64_t nbytes)istgt_lu_dvd_sync(ISTGT_LU_DVD *spec, uint64_t offset __attribute__((__unused__)), uint64_t nbytes __attribute__((__unused__)))
 {  {
         int64_t rc;          int64_t rc;
   
Line 287  istgt_lu_dvd_load_media(ISTGT_LU_DVD *spec) Line 292  istgt_lu_dvd_load_media(ISTGT_LU_DVD *spec)
                 }                  }
                 rc = istgt_lu_dvd_open(spec, flags, 0666);                  rc = istgt_lu_dvd_open(spec, flags, 0666);
                 if (rc < 0) {                  if (rc < 0) {
                        ISTGT_ERRLOG("LU%d: LUN%d: open error\n", lu->num, spec->lun);                        ISTGT_ERRLOG("LU%d: LUN%d: open error(errno=%d)\n",
                             lu->num, spec->lun, errno);
                         return -1;                          return -1;
                 }                  }
                 if (lu->lun[spec->lun].u.removable.size < ISTGT_LU_MEDIA_SIZE_MIN) {                  if (lu->lun[spec->lun].u.removable.size < ISTGT_LU_MEDIA_SIZE_MIN) {
Line 449  istgt_lu_dvd_allocate(ISTGT_LU_DVD *spec) Line 455  istgt_lu_dvd_allocate(ISTGT_LU_DVD *spec)
                 return -1;                  return -1;
         }          }
         rc = istgt_lu_dvd_write(spec, data, nbytes);          rc = istgt_lu_dvd_write(spec, data, nbytes);
        if (rc == -1 || rc != nbytes) {        if (rc == -1 || (uint64_t) rc != nbytes) {
                 ISTGT_ERRLOG("lu_dvd_write() failed\n");                  ISTGT_ERRLOG("lu_dvd_write() failed\n");
                 xfree(data);                  xfree(data);
                 return -1;                  return -1;
Line 460  istgt_lu_dvd_allocate(ISTGT_LU_DVD *spec) Line 466  istgt_lu_dvd_allocate(ISTGT_LU_DVD *spec)
 }  }
   
 int  int
istgt_lu_dvd_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu)istgt_lu_dvd_init(ISTGT_Ptr istgt __attribute__((__unused__)), ISTGT_LU_Ptr lu)
 {  {
         ISTGT_LU_DVD *spec;          ISTGT_LU_DVD *spec;
         uint64_t gb_size;          uint64_t gb_size;
Line 481  istgt_lu_dvd_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu) Line 487  istgt_lu_dvd_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu)
         for (i = 0; i < lu->maxlun; i++) {          for (i = 0; i < lu->maxlun; i++) {
                 if (lu->lun[i].type == ISTGT_LU_LUN_TYPE_NONE) {                  if (lu->lun[i].type == ISTGT_LU_LUN_TYPE_NONE) {
                         ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "LU%d: LUN%d none\n",                          ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "LU%d: LUN%d none\n",
                                                   lu->num, i);                            lu->num, i);
                         lu->lun[i].spec = NULL;                          lu->lun[i].spec = NULL;
                         continue;                          continue;
                 }                  }
Line 490  istgt_lu_dvd_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu) Line 496  istgt_lu_dvd_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu)
                         return -1;                          return -1;
                 }                  }
                 ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "LU%d: LUN%d removable\n",                  ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "LU%d: LUN%d removable\n",
                                           lu->num, i);                    lu->num, i);
   
                 spec = xmalloc(sizeof *spec);                  spec = xmalloc(sizeof *spec);
                 memset(spec, 0, sizeof *spec);                  memset(spec, 0, sizeof *spec);
Line 527  istgt_lu_dvd_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu) Line 533  istgt_lu_dvd_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu)
                         spec->mwait = 0;                          spec->mwait = 0;
   
                         if (spec->lu->readonly                          if (spec->lu->readonly
                                || (spec->mflags & ISTGT_LU_FLAG_MEDIA_READONLY)) {                            || (spec->mflags & ISTGT_LU_FLAG_MEDIA_READONLY)) {
                                 ro = 1;                                  ro = 1;
                         } else {                          } else {
                                 ro = 0;                                  ro = 0;
                         }                          }
   
                         printf("LU%d: LUN%d file=%s, size=%"PRIu64", flag=%s\n",                          printf("LU%d: LUN%d file=%s, size=%"PRIu64", flag=%s\n",
                                   lu->num, i, spec->file, spec->size, ro ? "ro" : "rw");                            lu->num, i, spec->file, spec->size, ro ? "ro" : "rw");
                         printf("LU%d: LUN%d %"PRIu64" blocks, %"PRIu64" bytes/block\n",                          printf("LU%d: LUN%d %"PRIu64" blocks, %"PRIu64" bytes/block\n",
                                   lu->num, i, spec->blockcnt, spec->blocklen);                            lu->num, i, spec->blockcnt, spec->blocklen);
   
                         gb_size = spec->size / ISTGT_LU_1GB;                          gb_size = spec->size / ISTGT_LU_1GB;
                         mb_size = (spec->size % ISTGT_LU_1GB) / ISTGT_LU_1MB;                          mb_size = (spec->size % ISTGT_LU_1GB) / ISTGT_LU_1MB;
                         if (gb_size > 0) {                          if (gb_size > 0) {
                                 mb_digit = (int) (((mb_size * 100) / 1024) / 10);                                  mb_digit = (int) (((mb_size * 100) / 1024) / 10);
                                 printf("LU%d: LUN%d %"PRIu64".%dGB %sstorage for %s\n",                                  printf("LU%d: LUN%d %"PRIu64".%dGB %sstorage for %s\n",
                                           lu->num, i, gb_size, mb_digit,                                    lu->num, i, gb_size, mb_digit,
                                           lu->readonly ? "readonly " : "", lu->name);                                    lu->readonly ? "readonly " : "", lu->name);
                         } else {                          } else {
                                 printf("LU%d: LUN%d %"PRIu64"MB %sstorage for %s\n",                                  printf("LU%d: LUN%d %"PRIu64"MB %sstorage for %s\n",
                                           lu->num, i, mb_size,                                    lu->num, i, mb_size,
                                           lu->readonly ? "readonly " : "", lu->name);                                    lu->readonly ? "readonly " : "", lu->name);
                         }                          }
                 } else {                  } else {
                         /* initial state */                          /* initial state */
Line 557  istgt_lu_dvd_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu) Line 563  istgt_lu_dvd_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu)
                         spec->mwait = 0;                          spec->mwait = 0;
   
                         printf("LU%d: LUN%d empty slot\n",                          printf("LU%d: LUN%d empty slot\n",
                                   lu->num, i);                            lu->num, i);
                 }                  }
   
                 lu->lun[i].spec = spec;                  lu->lun[i].spec = spec;
Line 567  istgt_lu_dvd_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu) Line 573  istgt_lu_dvd_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu)
 }  }
   
 int  int
istgt_lu_dvd_shutdown(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu)istgt_lu_dvd_shutdown(ISTGT_Ptr istgt __attribute__((__unused__)), ISTGT_LU_Ptr lu)
 {  {
         ISTGT_LU_DVD *spec;          ISTGT_LU_DVD *spec;
         int rc;          int rc;
Line 580  istgt_lu_dvd_shutdown(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu Line 586  istgt_lu_dvd_shutdown(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu
         for (i = 0; i < lu->maxlun; i++) {          for (i = 0; i < lu->maxlun; i++) {
                 if (lu->lun[i].type == ISTGT_LU_LUN_TYPE_NONE) {                  if (lu->lun[i].type == ISTGT_LU_LUN_TYPE_NONE) {
                         ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "LU%d: LUN%d none\n",                          ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "LU%d: LUN%d none\n",
                                                   lu->num, i);                            lu->num, i);
                         continue;                          continue;
                 }                  }
                 if (lu->lun[i].type != ISTGT_LU_LUN_TYPE_REMOVABLE) {                  if (lu->lun[i].type != ISTGT_LU_LUN_TYPE_REMOVABLE) {
Line 610  istgt_lu_dvd_shutdown(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu Line 616  istgt_lu_dvd_shutdown(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu
 }  }
   
 static int  static int
istgt_lu_dvd_scsi_report_luns(ISTGT_LU_Ptr lu, CONN_Ptr conn, uint8_t *cdb, int sel, uint8_t *data, int alloc_len)istgt_lu_dvd_scsi_report_luns(ISTGT_LU_Ptr lu, CONN_Ptr conn __attribute__((__unused__)), uint8_t *cdb __attribute__((__unused__)), int sel, uint8_t *data, int alloc_len)
 {  {
         uint64_t fmt_lun, lun, method;          uint64_t fmt_lun, lun, method;
         int hlen = 0, len = 0;          int hlen = 0, len = 0;
Line 640  istgt_lu_dvd_scsi_report_luns(ISTGT_LU_Ptr lu, CONN_Pt Line 646  istgt_lu_dvd_scsi_report_luns(ISTGT_LU_Ptr lu, CONN_Pt
                 if (lu->lun[i].type == ISTGT_LU_LUN_TYPE_NONE) {                  if (lu->lun[i].type == ISTGT_LU_LUN_TYPE_NONE) {
 #if 0  #if 0
                         ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "LU%d: LUN%d none\n",                          ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "LU%d: LUN%d none\n",
                                                   lu->num, i);                            lu->num, i);
 #endif  #endif
                         continue;                          continue;
                 }                  }
Line 653  istgt_lu_dvd_scsi_report_luns(ISTGT_LU_Ptr lu, CONN_Pt Line 659  istgt_lu_dvd_scsi_report_luns(ISTGT_LU_Ptr lu, CONN_Pt
                         method = 0x00U;                          method = 0x00U;
                         fmt_lun = (method & 0x03U) << 62;                          fmt_lun = (method & 0x03U) << 62;
                         fmt_lun |= (lun & 0x00ffU) << 48;                          fmt_lun |= (lun & 0x00ffU) << 48;
                } else if (lu->maxlun <= 0x4000U) {                } else if (lu->maxlun <= 0x4000) {
                         /* below 16384 */                          /* below 16384 */
                         method = 0x01U;                          method = 0x01U;
                         fmt_lun = (method & 0x03U) << 62;                          fmt_lun = (method & 0x03U) << 62;
Line 809  istgt_lu_dvd_scsi_inquiry(ISTGT_LU_DVD *spec, CONN_Ptr Line 815  istgt_lu_dvd_scsi_inquiry(ISTGT_LU_DVD *spec, CONN_Ptr
                         istgt_strcpy_pad(&cp[12], 16, spec->lu->inq_product, ' ');                          istgt_strcpy_pad(&cp[12], 16, spec->lu->inq_product, ' ');
                         /* PRODUCT SERIAL NUMBER */                          /* PRODUCT SERIAL NUMBER */
                         istgt_strcpy_pad(&cp[28], MAX_LU_SERIAL_STRING,                          istgt_strcpy_pad(&cp[28], MAX_LU_SERIAL_STRING,
                                                         spec->lu->inq_serial, ' ');                            spec->lu->inq_serial, ' ');
                         plen += 16 + MAX_LU_SERIAL_STRING;                          plen += 16 + MAX_LU_SERIAL_STRING;
   
                         cp[3] = plen;                          cp[3] = plen;
Line 833  istgt_lu_dvd_scsi_inquiry(ISTGT_LU_DVD *spec, CONN_Ptr Line 839  istgt_lu_dvd_scsi_inquiry(ISTGT_LU_DVD *spec, CONN_Ptr
   
                         /* IDENTIFIER */                          /* IDENTIFIER */
                         plen = snprintf((char *) &cp[4], MAX_TARGET_NAME,                          plen = snprintf((char *) &cp[4], MAX_TARGET_NAME,
                                                        "%s",                            "%s", spec->lu->name);
                                                        spec->lu->name); 
                         cp[3] = plen;                          cp[3] = plen;
                         len += 4 + plen;                          len += 4 + plen;
   
Line 856  istgt_lu_dvd_scsi_inquiry(ISTGT_LU_DVD *spec, CONN_Ptr Line 861  istgt_lu_dvd_scsi_inquiry(ISTGT_LU_DVD *spec, CONN_Ptr
   
                         /* IDENTIFIER */                          /* IDENTIFIER */
                         plen = snprintf((char *) &cp[4], MAX_TARGET_NAME,                          plen = snprintf((char *) &cp[4], MAX_TARGET_NAME,
                                                        "%s"",t,0x""%4.4x",                            "%s"",t,0x""%4.4x", spec->lu->name, conn->portal.tag);
                                                        spec->lu->name, 
                                                        conn->portal.tag); 
                         cp[3] = plen;                          cp[3] = plen;
                         len += 4 + plen;                          len += 4 + plen;
   
Line 929  istgt_lu_dvd_scsi_inquiry(ISTGT_LU_DVD *spec, CONN_Ptr Line 932  istgt_lu_dvd_scsi_inquiry(ISTGT_LU_DVD *spec, CONN_Ptr
                         BDSET8W(&cp[1], 1, 7, 1); /* PIV */                          BDSET8W(&cp[1], 1, 7, 1); /* PIV */
                         BDADD8W(&cp[1], SPC_VPD_ASSOCIATION_TARGET_PORT, 5, 2);                          BDADD8W(&cp[1], SPC_VPD_ASSOCIATION_TARGET_PORT, 5, 2);
                         BDADD8W(&cp[1], SPC_VPD_IDENTIFIER_TYPE_LOGICAL_UNIT_GROUP,                          BDADD8W(&cp[1], SPC_VPD_IDENTIFIER_TYPE_LOGICAL_UNIT_GROUP,
                                        3, 4);                            3, 4);
                         /* Reserved */                          /* Reserved */
                         cp[2] = 0;                          cp[2] = 0;
                         /* IDENTIFIER LENGTH */                          /* IDENTIFIER LENGTH */
Line 1104  istgt_lu_dvd_scsi_inquiry(ISTGT_LU_DVD *spec, CONN_Ptr Line 1107  istgt_lu_dvd_scsi_inquiry(ISTGT_LU_DVD *spec, CONN_Ptr
   
                                 /* IDENTIFIER */                                  /* IDENTIFIER */
                                 plen = snprintf((char *) &cp2[4], MAX_TARGET_NAME,                                  plen = snprintf((char *) &cp2[4], MAX_TARGET_NAME,
                                                                "%s"",t,0x""%4.4x",                                    "%s"",t,0x""%4.4x", spec->lu->name, pg_tag);
                                                                spec->lu->name, 
                                                                pg_tag); 
                                 cp2[3] = plen;                                  cp2[3] = plen;
                                 plen2 += 4 + plen;                                  plen2 += 4 + plen;
   
Line 1189  istgt_lu_dvd_scsi_inquiry(ISTGT_LU_DVD *spec, CONN_Ptr Line 1190  istgt_lu_dvd_scsi_inquiry(ISTGT_LU_DVD *spec, CONN_Ptr
         return hlen + len;          return hlen + len;
 }  }
   
#define MODE_SENSE_PAGE_INIT(B,L,P,SP)                          \#define MODE_SENSE_PAGE_INIT(B,L,P,SP)                                  \
        do {                                                                                    \        do {                                                            \
                memset((B), 0, (L));                                            \                memset((B), 0, (L));                                    \
                if ((SP) != 0x00) {                                                     \                if ((SP) != 0x00) {                                     \
                        (B)[0] = (P) | 0x40; /* PAGE + SPF=1 */ \                        (B)[0] = (P) | 0x40; /* PAGE + SPF=1 */         \
                        (B)[1] = (SP);                                                  \                        (B)[1] = (SP);                                  \
                        DSET16(&(B)[2], (L) - 4);                               \                        DSET16(&(B)[2], (L) - 4);                       \
                } else {                                                                        \                } else {                                                \
                        (B)[0] = (P);                                                   \                        (B)[0] = (P);                                   \
                        (B)[1] = (L) - 2;                                               \                        (B)[1] = (L) - 2;                               \
                }                                                                                       \                }                                                       \
         } while (0)          } while (0)
   
 static int  static int
Line 1221  istgt_lu_dvd_scsi_mode_sense_page(ISTGT_LU_DVD *spec,  Line 1222  istgt_lu_dvd_scsi_mode_sense_page(ISTGT_LU_DVD *spec, 
                 /* Changeable values */                  /* Changeable values */
                 if (page != 0x08) {                  if (page != 0x08) {
                         /* not supported */                          /* not supported */
                        return 0;                        return -1;
                 }                  }
         } else if (pc == 0x02) {          } else if (pc == 0x02) {
                 /* Default values */                  /* Default values */
Line 1415  istgt_lu_dvd_scsi_mode_sense6(ISTGT_LU_DVD *spec, CONN Line 1416  istgt_lu_dvd_scsi_mode_sense6(ISTGT_LU_DVD *spec, CONN
   
         data[0] = 0;                    /* Mode Data Length */          data[0] = 0;                    /* Mode Data Length */
         if (spec->mload) {          if (spec->mload) {
                data[1] = 0;                    /* Medium Type */                data[1] = 0;            /* Medium Type */
                data[2] = 0;                    /* Device-Specific Parameter */                data[2] = 0;            /* Device-Specific Parameter */
                 if (spec->lu->readonly                  if (spec->lu->readonly
                        || (spec->mflags & ISTGT_LU_FLAG_MEDIA_READONLY)) {                    || (spec->mflags & ISTGT_LU_FLAG_MEDIA_READONLY)) {
                         BDADD8(&data[2], 1, 7);     /* WP */                          BDADD8(&data[2], 1, 7);     /* WP */
                 }                  }
         } else {          } else {
                data[1] = 0;                    /* Medium Type */                data[1] = 0;            /* Medium Type */
                data[2] = 0;                    /* Device-Specific Parameter */                data[2] = 0;            /* Device-Specific Parameter */
         }          }
         data[3] = 0;                    /* Block Descripter Length */          data[3] = 0;                    /* Block Descripter Length */
         hlen = 4;          hlen = 4;
Line 1472  istgt_lu_dvd_scsi_mode_sense6(ISTGT_LU_DVD *spec, CONN Line 1473  istgt_lu_dvd_scsi_mode_sense6(ISTGT_LU_DVD *spec, CONN
         data[3] = len;                  /* Block Descripter Length */          data[3] = len;                  /* Block Descripter Length */
   
         plen = istgt_lu_dvd_scsi_mode_sense_page(spec, conn, cdb, pc, page, subpage, &cp[0], alloc_len);          plen = istgt_lu_dvd_scsi_mode_sense_page(spec, conn, cdb, pc, page, subpage, &cp[0], alloc_len);
           if (plen < 0) {
                   return -1;
           }
         cp += plen;          cp += plen;
   
         total = hlen + len + plen;          total = hlen + len + plen;
Line 1489  istgt_lu_dvd_scsi_mode_sense10(ISTGT_LU_DVD *spec, CON Line 1493  istgt_lu_dvd_scsi_mode_sense10(ISTGT_LU_DVD *spec, CON
   
         DSET16(&data[0], 0);            /* Mode Data Length */          DSET16(&data[0], 0);            /* Mode Data Length */
         if (spec->mload) {          if (spec->mload) {
                data[2] = 0;                    /* Medium Type */                data[2] = 0;            /* Medium Type */
                data[3] = 0;                    /* Device-Specific Parameter */                data[3] = 0;            /* Device-Specific Parameter */
                 if (spec->lu->readonly                  if (spec->lu->readonly
                        || (spec->mflags & ISTGT_LU_FLAG_MEDIA_READONLY)) {                    || (spec->mflags & ISTGT_LU_FLAG_MEDIA_READONLY)) {
                         BDADD8(&data[3], 1, 7);     /* WP */                          BDADD8(&data[3], 1, 7);     /* WP */
                 }                  }
         } else {          } else {
                data[2] = 0;                    /* Medium Type */                data[2] = 0;            /* Medium Type */
                data[3] = 0;                    /* Device-Specific Parameter */                data[3] = 0;            /* Device-Specific Parameter */
         }          }
         if (llbaa) {          if (llbaa) {
                 BDSET8(&data[4], 1, 1);      /* Long LBA */                  BDSET8(&data[4], 1, 1);      /* Long LBA */
Line 1505  istgt_lu_dvd_scsi_mode_sense10(ISTGT_LU_DVD *spec, CON Line 1509  istgt_lu_dvd_scsi_mode_sense10(ISTGT_LU_DVD *spec, CON
                 BDSET8(&data[4], 0, 1);      /* Short LBA */                  BDSET8(&data[4], 0, 1);      /* Short LBA */
         }          }
         data[5] = 0;                    /* Reserved */          data[5] = 0;                    /* Reserved */
        DSET16(&data[6], 0);                /* Block Descripter Length */        DSET16(&data[6], 0);            /* Block Descripter Length */
         hlen = 8;          hlen = 8;
   
         cp = &data[8];          cp = &data[8];
Line 1552  istgt_lu_dvd_scsi_mode_sense10(ISTGT_LU_DVD *spec, CON Line 1556  istgt_lu_dvd_scsi_mode_sense10(ISTGT_LU_DVD *spec, CON
         DSET16(&data[6], len);          /* Block Descripter Length */          DSET16(&data[6], len);          /* Block Descripter Length */
   
         plen = istgt_lu_dvd_scsi_mode_sense_page(spec, conn, cdb, pc, page, subpage, &cp[0], alloc_len);          plen = istgt_lu_dvd_scsi_mode_sense_page(spec, conn, cdb, pc, page, subpage, &cp[0], alloc_len);
           if (plen < 0) {
                   return -1;
           }
         cp += plen;          cp += plen;
   
         total = hlen + len + plen;          total = hlen + len + plen;
Line 1566  istgt_lu_dvd_transfer_data(CONN_Ptr conn, ISTGT_LU_CMD Line 1573  istgt_lu_dvd_transfer_data(CONN_Ptr conn, ISTGT_LU_CMD
         int rc;          int rc;
   
         if (len > bufsize) {          if (len > bufsize) {
                ISTGT_ERRLOG("bufsize(%d) too small\n", bufsize);                ISTGT_ERRLOG("bufsize(%zd) too small\n", bufsize);
                 return -1;                  return -1;
         }          }
         rc = istgt_iscsi_transfer_out(conn, lu_cmd, buf, bufsize, len);          rc = istgt_iscsi_transfer_out(conn, lu_cmd, buf, bufsize, len);
Line 1580  istgt_lu_dvd_transfer_data(CONN_Ptr conn, ISTGT_LU_CMD Line 1587  istgt_lu_dvd_transfer_data(CONN_Ptr conn, ISTGT_LU_CMD
 static int  static int
 istgt_lu_dvd_scsi_mode_select_page(ISTGT_LU_DVD *spec, CONN_Ptr conn, uint8_t *cdb, int pf, int sp, uint8_t *data, size_t len)  istgt_lu_dvd_scsi_mode_select_page(ISTGT_LU_DVD *spec, CONN_Ptr conn, uint8_t *cdb, int pf, int sp, uint8_t *data, size_t len)
 {  {
           size_t hlen, plen;
         int ps, spf, page, subpage;          int ps, spf, page, subpage;
         int hlen, plen;  
         int rc;          int rc;
   
         if (pf == 0) {          if (pf == 0) {
Line 1662  istgt_lu_dvd_scsi_mode_select_page(ISTGT_LU_DVD *spec, Line 1669  istgt_lu_dvd_scsi_mode_select_page(ISTGT_LU_DVD *spec,
         return 0;          return 0;
 }  }
   
#define FEATURE_DESCRIPTOR_INIT(B,L,FC)                 \#define FEATURE_DESCRIPTOR_INIT(B,L,FC)                                 \
        do {                                                                            \        do {                                                            \
                 memset((B), 0, (L));                                    \                  memset((B), 0, (L));                                    \
                 DSET16(&(B)[0], (FC));                                  \                  DSET16(&(B)[0], (FC));                                  \
                (B)[3] = (L) - 4;                                               \                (B)[3] = (L) - 4;                                       \
         } while (0)          } while (0)
   
 static int  static int
istgt_lu_dvd_get_feature_descriptor(ISTGT_LU_DVD *spec, CONN_Ptr conn, uint8_t *cdb, int fc, uint8_t *data)istgt_lu_dvd_get_feature_descriptor(ISTGT_LU_DVD *spec, CONN_Ptr conn __attribute__((__unused__)), uint8_t *cdb __attribute__((__unused__)), int fc, uint8_t *data)
 {  {
         uint8_t *cp;          uint8_t *cp;
         int hlen = 0, len = 0, plen;          int hlen = 0, len = 0, plen;
Line 1713  istgt_lu_dvd_get_feature_descriptor(ISTGT_LU_DVD *spec Line 1720  istgt_lu_dvd_get_feature_descriptor(ISTGT_LU_DVD *spec
                 plen = 8 + 4;                  plen = 8 + 4;
                 FEATURE_DESCRIPTOR_INIT(data, plen, fc);                  FEATURE_DESCRIPTOR_INIT(data, plen, fc);
                 /* Version(5-2) Persistent(1) Current(0) */                  /* Version(5-2) Persistent(1) Current(0) */
                BDSET8W(&data[2], 0x01, 5, 4); /* MMC4 */                BDSET8W(&data[2], 0x01, 5, 4);          /* MMC4 */
                 BSET8(&data[2], 1);                     /* Persistent=1 */                  BSET8(&data[2], 1);                     /* Persistent=1 */
                 BSET8(&data[2], 0);                     /* Current=1 */                  BSET8(&data[2], 0);                     /* Current=1 */
                 hlen = 4;                  hlen = 4;
   
                 /* Physical Interface Standard */                  /* Physical Interface Standard */
                DSET32(&data[4], 0x00000000); /* Unspecified */                DSET32(&data[4], 0x00000000);           /* Unspecified */
                 /* DBE(0) */                  /* DBE(0) */
                 BCLR8(&data[8], 0);                     /* DBE=0*/                  BCLR8(&data[8], 0);                     /* DBE=0*/
                 len = 8;                  len = 8;
Line 1759  istgt_lu_dvd_get_feature_descriptor(ISTGT_LU_DVD *spec Line 1766  istgt_lu_dvd_get_feature_descriptor(ISTGT_LU_DVD *spec
                 /* Blocking */                  /* Blocking */
                 DSET16(&data[8], 1);                  DSET16(&data[8], 1);
                 /* PP(0) */                  /* PP(0) */
                BCLR8(&data[10], 0);            /* PP=0 */                BCLR8(&data[10], 0);                    /* PP=0 */
                 len = 4;                  len = 4;
                 break;                  break;
   
Line 1882  istgt_lu_dvd_scsi_get_configuration(ISTGT_LU_DVD *spec Line 1889  istgt_lu_dvd_scsi_get_configuration(ISTGT_LU_DVD *spec
 }  }
   
 static int  static int
istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_LU_DVD *spec, CONN_Ptr conn, uint8_t *cdb, int keep, int ncr, uint8_t *data)istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_LU_DVD *spec, CONN_Ptr conn __attribute__((__unused__)), uint8_t *cdb __attribute__((__unused__)), int keep __attribute__((__unused__)), int ncr, uint8_t *data)
 {  {
         uint8_t *cp;          uint8_t *cp;
         int hlen = 0, len = 0;          int hlen = 0, len = 0;
Line 1903  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_ Line 1910  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_
         }          }
         if (ncr & (1 << 1)) {          if (ncr & (1 << 1)) {
                 /* Operational Change */                  /* Operational Change */
                BDSET8W(&data[2], 0x01, 2, 3);  /* Notification Class */                BDSET8W(&data[2], 0x01, 2, 3);          /* Notification Class */
                 /* Event Code */                  /* Event Code */
                BDSET8W(&cp[0], 0x00, 3, 4);    /* NoChg */                BDSET8W(&cp[0], 0x00, 3, 4);            /* NoChg */
                 /* Persistent Prevented(7) Operational Status(3-0) */                  /* Persistent Prevented(7) Operational Status(3-0) */
                 BDSET8(&cp[1], 0, 7);                   /* not prevented */                  BDSET8(&cp[1], 0, 7);                   /* not prevented */
                 BDADD8W(&cp[1], 0, 3, 4);                  BDADD8W(&cp[1], 0, 3, 4);
Line 1916  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_ Line 1923  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_
         }          }
         if (ncr & (1 << 2)) {          if (ncr & (1 << 2)) {
                 /* Power Management */                  /* Power Management */
                BDSET8W(&data[2], 0x02, 2, 3);  /* Notification Class */                BDSET8W(&data[2], 0x02, 2, 3);          /* Notification Class */
                 /* Event Code */                  /* Event Code */
                BDSET8W(&cp[0], 0x00, 3, 4);    /* NoChg */                BDSET8W(&cp[0], 0x00, 3, 4);            /* NoChg */
                 /* Power Status */                  /* Power Status */
                cp[1] = 0x01;                                   /* Active */                cp[1] = 0x01;                           /* Active */
                 /* Reserved */                  /* Reserved */
                 cp[2] = 0;                  cp[2] = 0;
                 /* Reserved */                  /* Reserved */
Line 1930  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_ Line 1937  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_
         }          }
         if (ncr & (1 << 3)) {          if (ncr & (1 << 3)) {
                 /* External Request */                  /* External Request */
                BDSET8W(&data[2], 0x03, 2, 3);  /* Notification Class */                BDSET8W(&data[2], 0x03, 2, 3);          /* Notification Class */
                 /* Event Code */                  /* Event Code */
                BDSET8W(&cp[0], 0x00, 3, 4);    /* NoChg */                BDSET8W(&cp[0], 0x00, 3, 4);            /* NoChg */
                 /* Persistent Prevented(7) External Request Status(3-0) */                  /* Persistent Prevented(7) External Request Status(3-0) */
                 BDSET8(&cp[1], 0, 7);                   /* not prevented */                  BDSET8(&cp[1], 0, 7);                   /* not prevented */
                 BDADD8W(&cp[1], 0, 3, 4);               /* Ready */                  BDADD8W(&cp[1], 0, 3, 4);               /* Ready */
Line 1943  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_ Line 1950  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_
         }          }
         if (ncr & (1 << 4)) {          if (ncr & (1 << 4)) {
                 /* Media */                  /* Media */
                BDSET8W(&data[2], 0x04, 2, 3);  /* Notification Class */                BDSET8W(&data[2], 0x04, 2, 3);          /* Notification Class */
                 if (spec->mchanged) {                  if (spec->mchanged) {
                         if (spec->mwait > 0) {                          if (spec->mwait > 0) {
                                 spec->mwait--;                                  spec->mwait--;
Line 1956  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_ Line 1963  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_
                                 BDSET8W(&cp[0], 0x02, 3, 4);    /* NewMedia */                                  BDSET8W(&cp[0], 0x02, 3, 4);    /* NewMedia */
                                 /* Media Status */                                  /* Media Status */
                                 /* Media Present(1) Door or Tray open(0) */                                  /* Media Present(1) Door or Tray open(0) */
                                BDSET8(&cp[1], 1, 1);                   /* media present */                                BDSET8(&cp[1], 1, 1);           /* media present */
                                BDADD8(&cp[1], 0, 0);                   /* tray close */                                BDADD8(&cp[1], 0, 0);           /* tray close */
                         } else {                          } else {
                                 /* Event Code */                                  /* Event Code */
                                 BDSET8W(&cp[0], 0x03, 3, 4);    /* MediaRemoval */                                  BDSET8W(&cp[0], 0x03, 3, 4);    /* MediaRemoval */
                                 /* Media Status */                                  /* Media Status */
                                 /* Media Present(1) Door or Tray open(0) */                                  /* Media Present(1) Door or Tray open(0) */
                                BDSET8(&cp[1], 0, 1);                   /* media absent */                                BDSET8(&cp[1], 0, 1);           /* media absent */
                                BDADD8(&cp[1], 1, 0);                   /* tray open */                                BDADD8(&cp[1], 1, 0);           /* tray open */
                         }                          }
                 } else {                  } else {
                         if (spec->mwait > 0) {                          if (spec->mwait > 0) {
Line 1973  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_ Line 1980  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_
                                 BDSET8W(&cp[0], 0x01, 3, 4);    /* EjectRequest */                                  BDSET8W(&cp[0], 0x01, 3, 4);    /* EjectRequest */
                                 /* Media Status */                                  /* Media Status */
                                 /* Media Present(1) Door or Tray open(0) */                                  /* Media Present(1) Door or Tray open(0) */
                                BDSET8(&cp[1], 0, 1);                   /* media absent */                                BDSET8(&cp[1], 0, 1);           /* media absent */
                                BDADD8(&cp[1], 1, 0);                   /* tray open */                                BDADD8(&cp[1], 1, 0);           /* tray open */
                         } else {                          } else {
                                 if (spec->mload) {                                  if (spec->mload) {
                                         /* Event Code */                                          /* Event Code */
                                         BDSET8W(&cp[0], 0x00, 3, 4);    /* NoChg */                                          BDSET8W(&cp[0], 0x00, 3, 4);    /* NoChg */
                                         /* Media Status */                                          /* Media Status */
                                         /* Media Present(1) Door or Tray open(0) */                                          /* Media Present(1) Door or Tray open(0) */
                                        BDSET8(&cp[1], 1, 1);                   /* media present */                                        BDSET8(&cp[1], 1, 1);   /* media present */
                                        BDADD8(&cp[1], 0, 0);                   /* tray close */                                        BDADD8(&cp[1], 0, 0);   /* tray close */
                                 } else {                                  } else {
                                         /* Event Code */                                          /* Event Code */
                                         BDSET8W(&cp[0], 0x00, 3, 4);    /* NoChg */                                          BDSET8W(&cp[0], 0x00, 3, 4);    /* NoChg */
                                         /* Media Status */                                          /* Media Status */
                                         /* Media Present(1) Door or Tray open(0) */                                          /* Media Present(1) Door or Tray open(0) */
                                        BDSET8(&cp[1], 0, 1);                   /* media absent */                                        BDSET8(&cp[1], 0, 1);   /* media absent */
                                        BDADD8(&cp[1], 0, 0);                   /* tray close */                                        BDADD8(&cp[1], 0, 0);   /* tray close */
                                 }                                  }
                         }                          }
                 }                  }
Line 2002  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_ Line 2009  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_
         }          }
         if (ncr & (1 << 5)) {          if (ncr & (1 << 5)) {
                 /* Multi-Initiator */                  /* Multi-Initiator */
                BDSET8W(&data[2], 0x05, 2, 3);  /* Notification Class */                BDSET8W(&data[2], 0x05, 2, 3);          /* Notification Class */
                 /* Event Code */                  /* Event Code */
                BDSET8W(&cp[0], 0x00, 3, 4);    /* NoChg */                BDSET8W(&cp[0], 0x00, 3, 4);            /* NoChg */
                 /* Persistent Prevented(7) Multiple Initiator Status(3-0) */                  /* Persistent Prevented(7) Multiple Initiator Status(3-0) */
                 BDSET8(&cp[1], 0, 7);                   /* not prevented */                  BDSET8(&cp[1], 0, 7);                   /* not prevented */
                 BDADD8W(&cp[1], 0, 3, 4);               /* Ready */                  BDADD8W(&cp[1], 0, 3, 4);               /* Ready */
Line 2015  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_ Line 2022  istgt_lu_dvd_scsi_get_event_status_notification(ISTGT_
         }          }
         if (ncr & (1 << 6)) {          if (ncr & (1 << 6)) {
                 /* Device Busy */                  /* Device Busy */
                BDSET8W(&data[2], 0x06, 2, 3);  /* Notification Class */                BDSET8W(&data[2], 0x06, 2, 3);          /* Notification Class */
                 /* Event Code */                  /* Event Code */
                BDSET8W(&cp[0], 0x00, 3, 4);    /* NoChg */                BDSET8W(&cp[0], 0x00, 3, 4);            /* NoChg */
                 /* Media Status */                  /* Media Status */
                 /* Device Busy Status */                  /* Device Busy Status */
                cp[1] = 0;                                              /* Not Busy */                cp[1] = 0;                              /* Not Busy */
                 /* Time */                  /* Time */
                 DSET16(&cp[2], 0);                  DSET16(&cp[2], 0);
                 len = 4;                  len = 4;
Line 2044  event_available: Line 2051  event_available:
 }  }
   
 static int  static int
istgt_lu_dvd_scsi_mechanism_status(ISTGT_LU_DVD *spec, CONN_Ptr conn, uint8_t *cdb, uint8_t *data)istgt_lu_dvd_scsi_mechanism_status(ISTGT_LU_DVD *spec, CONN_Ptr conn __attribute__((__unused__)), uint8_t *cdb __attribute__((__unused__)), uint8_t *data)
 {  {
         uint8_t *cp;          uint8_t *cp;
         int hlen = 0, len = 0, plen;          int hlen = 0, len = 0, plen;
Line 2053  istgt_lu_dvd_scsi_mechanism_status(ISTGT_LU_DVD *spec, Line 2060  istgt_lu_dvd_scsi_mechanism_status(ISTGT_LU_DVD *spec,
         /* Mechanism Status Header */          /* Mechanism Status Header */
         /* Fault(7) Changer State(6-5) Current Slot(4-0) */          /* Fault(7) Changer State(6-5) Current Slot(4-0) */
         BDSET8(&data[0], 0, 7);          BDSET8(&data[0], 0, 7);
        BDADD8W(&data[0], 0x00, 6, 2);          /* Ready */        BDADD8W(&data[0], 0x00, 6, 2);                  /* Ready */
         BDADD8W(&data[0], (selected_slot & 0x1f), 4, 5); /* slot low bits */          BDADD8W(&data[0], (selected_slot & 0x1f), 4, 5); /* slot low bits */
         /* Mechanism State(7-5) Door open(4) Current Slot(2-0) */          /* Mechanism State(7-5) Door open(4) Current Slot(2-0) */
         BDSET8W(&data[1], 0x00, 7, 3);          /* Idle */          BDSET8W(&data[1], 0x00, 7, 3);          /* Idle */
Line 2073  istgt_lu_dvd_scsi_mechanism_status(ISTGT_LU_DVD *spec, Line 2080  istgt_lu_dvd_scsi_mechanism_status(ISTGT_LU_DVD *spec,
         if (spec->mchanged) {          if (spec->mchanged) {
                 if (spec->mload) {                  if (spec->mload) {
                         /* Disc Present(7) Change(0) */                          /* Disc Present(7) Change(0) */
                        BDSET8(&cp[0], 1, 7);                   /* disc in slot */                        BDSET8(&cp[0], 1, 7);           /* disc in slot */
                 } else {                  } else {
                         /* Disc Present(7) Change(0) */                          /* Disc Present(7) Change(0) */
                        BDSET8(&cp[0], 0, 7);                   /* no disc in slot */                        BDSET8(&cp[0], 0, 7);           /* no disc in slot */
                 }                  }
                BDADD8(&cp[0], 1, 0);                           /* disc changed */                BDADD8(&cp[0], 1, 0);                   /* disc changed */
         } else {          } else {
                 if (spec->mload) {                  if (spec->mload) {
                         /* Disc Present(7) Change(0) */                          /* Disc Present(7) Change(0) */
                        BDSET8(&cp[0], 1, 7);                   /* disc in slot */                        BDSET8(&cp[0], 1, 7);           /* disc in slot */
                 } else {                  } else {
                         /* Disc Present(7) Change(0) */                          /* Disc Present(7) Change(0) */
                        BDSET8(&cp[0], 0, 7);                   /* no disc in slot */                        BDSET8(&cp[0], 0, 7);           /* no disc in slot */
                 }                  }
                BDADD8(&cp[0], 0, 0);                           /* disc not changed */                BDADD8(&cp[0], 0, 0);                   /* disc not changed */
         }          }
         /* CWP_V(1) CWP(0) */          /* CWP_V(1) CWP(0) */
         BDSET8(&cp[1], 0, 1);                           /* non Cartridge Write Protection */          BDSET8(&cp[1], 0, 1);                           /* non Cartridge Write Protection */
Line 2106  istgt_lu_dvd_scsi_mechanism_status(ISTGT_LU_DVD *spec, Line 2113  istgt_lu_dvd_scsi_mechanism_status(ISTGT_LU_DVD *spec,
 }  }
   
 static int  static int
istgt_lu_dvd_scsi_read_toc(ISTGT_LU_DVD *spec, CONN_Ptr conn, uint8_t *cdb, int msf, int format, int track, uint8_t *data)istgt_lu_dvd_scsi_read_toc(ISTGT_LU_DVD *spec, CONN_Ptr conn __attribute__((__unused__)), uint8_t *cdb __attribute__((__unused__)), int msf, int format, int track __attribute__((__unused__)), uint8_t *data)
 {  {
         uint8_t *cp;          uint8_t *cp;
         int hlen = 0, len = 0, plen;          int hlen = 0, len = 0, plen;
Line 2337  istgt_lu_dvd_scsi_read_toc(ISTGT_LU_DVD *spec, CONN_Pt Line 2344  istgt_lu_dvd_scsi_read_toc(ISTGT_LU_DVD *spec, CONN_Pt
 }  }
   
 static int  static int
istgt_lu_dvd_scsi_read_disc_information(ISTGT_LU_DVD *spec, CONN_Ptr conn, uint8_t *cdb, int datatype, uint8_t *data)istgt_lu_dvd_scsi_read_disc_information(ISTGT_LU_DVD *spec __attribute__((__unused__)), CONN_Ptr conn __attribute__((__unused__)), uint8_t *cdb __attribute__((__unused__)), int datatype, uint8_t *data)
 {  {
         int hlen = 0, len = 0;          int hlen = 0, len = 0;
   
Line 2351  istgt_lu_dvd_scsi_read_disc_information(ISTGT_LU_DVD * Line 2358  istgt_lu_dvd_scsi_read_disc_information(ISTGT_LU_DVD *
                 /* State of last Session(3-2) Disc Status(1-0) */                  /* State of last Session(3-2) Disc Status(1-0) */
                 BDSET8W(&data[2], datatype, 7, 3);                  BDSET8W(&data[2], datatype, 7, 3);
                 BDADD8W(&data[2], 0, 4, 1);                  BDADD8W(&data[2], 0, 4, 1);
                BDADD8W(&data[2], 0x03, 3, 2);  /* Complete Session */                BDADD8W(&data[2], 0x03, 3, 2);          /* Complete Session */
                BDADD8W(&data[2], 0x02, 1, 2);  /* Finalized Disc */                BDADD8W(&data[2], 0x02, 1, 2);          /* Finalized Disc */
                 /* Number of First Track on Disc */                  /* Number of First Track on Disc */
                 data[3] = 1;                  data[3] = 1;
                 /* Number of Sessions (Least Significant Byte) */                  /* Number of Sessions (Least Significant Byte) */
Line 2368  istgt_lu_dvd_scsi_read_disc_information(ISTGT_LU_DVD * Line 2375  istgt_lu_dvd_scsi_read_disc_information(ISTGT_LU_DVD *
                 BDADD8(&data[7], 0, 4);                 /* Disc Application Code Valid */                  BDADD8(&data[7], 0, 4);                 /* Disc Application Code Valid */
                 BDADD8W(&data[7], 0, 1, 2);             /* BG Format Status */                  BDADD8W(&data[7], 0, 1, 2);             /* BG Format Status */
                 /* Disc Type */                  /* Disc Type */
                data[8] = 0x00;                                 /* CD-DA or CD-ROM Disc */                data[8] = 0x00;                         /* CD-DA or CD-ROM Disc */
                 /* Number of Sessions (Most Significant Byte) */                  /* Number of Sessions (Most Significant Byte) */
                 data[9] = (1 >> 8) & 0xff;                  data[9] = (1 >> 8) & 0xff;
                 /* First Track Number in Last Session (Most Significant Byte) */                  /* First Track Number in Last Session (Most Significant Byte) */
Line 2448  istgt_lu_dvd_scsi_read_disc_information(ISTGT_LU_DVD * Line 2455  istgt_lu_dvd_scsi_read_disc_information(ISTGT_LU_DVD *
 }  }
   
 static int  static int
istgt_lu_dvd_scsi_read_disc_structure(ISTGT_LU_DVD *spec, CONN_Ptr conn, uint8_t *cdb, int mediatype, int layernumber, int format, int agid, uint8_t *data)istgt_lu_dvd_scsi_read_disc_structure(ISTGT_LU_DVD *spec, CONN_Ptr conn __attribute__((__unused__)), uint8_t *cdb __attribute__((__unused__)), int mediatype, int layernumber __attribute__((__unused__)), int format, int agid __attribute__((__unused__)), uint8_t *data)
 {  {
         uint8_t *cp;          uint8_t *cp;
         int hlen = 0, len = 0;          int hlen = 0, len = 0;
Line 2475  istgt_lu_dvd_scsi_read_disc_structure(ISTGT_LU_DVD *sp Line 2482  istgt_lu_dvd_scsi_read_disc_structure(ISTGT_LU_DVD *sp
                 cp = &data[hlen + len];                  cp = &data[hlen + len];
   
                 /* Disk Category(7-4) Part Version(3-0) */                  /* Disk Category(7-4) Part Version(3-0) */
                BDSET8W(&cp[0], 0x00, 7, 4);    /* DVD-ROM */                BDSET8W(&cp[0], 0x00, 7, 4);            /* DVD-ROM */
                BDADD8W(&cp[0], 0x01, 3, 4);    /* part 1 */                BDADD8W(&cp[0], 0x01, 3, 4);            /* part 1 */
                 /* Disc Size(7-4) Maximum Rate(0-3) */                  /* Disc Size(7-4) Maximum Rate(0-3) */
                BDSET8W(&cp[1], 0x00, 7, 4);    /* 120mm */                BDSET8W(&cp[1], 0x00, 7, 4);            /* 120mm */
                BDADD8W(&cp[1], 0x0f, 3, 4);    /* Not Specified */                BDADD8W(&cp[1], 0x0f, 3, 4);            /* Not Specified */
                 /* Number of Layers(6-5) Track(4) Layer Type(3-0) */                  /* Number of Layers(6-5) Track(4) Layer Type(3-0) */
                BDSET8W(&cp[2], 0x00, 6, 2);    /* one layer */                BDSET8W(&cp[2], 0x00, 6, 2);            /* one layer */
                BDADD8W(&cp[2], 0x00, 4, 1);    /* Parallel Track Path */                BDADD8W(&cp[2], 0x00, 4, 1);            /* Parallel Track Path */
                BDADD8W(&cp[2], 0x00, 3, 4);    /* embossed data */                BDADD8W(&cp[2], 0x00, 3, 4);            /* embossed data */
                 /* Linear Density(7-4) Track Density(3-0) */                  /* Linear Density(7-4) Track Density(3-0) */
                BDSET8W(&cp[3], 0x00, 7, 4);    /* 0.267 um/bit */                BDSET8W(&cp[3], 0x00, 7, 4);            /* 0.267 um/bit */
                BDADD8W(&cp[3], 0x00, 3, 4);    /* 0.74 um/track */                BDADD8W(&cp[3], 0x00, 3, 4);            /* 0.74 um/track */
                 /* Starting Physical Sector Number of Data Area */                  /* Starting Physical Sector Number of Data Area */
                 DSET32(&cp[4], 0);                  DSET32(&cp[4], 0);
                 /* End Physical Sector Number of Data Area */                  /* End Physical Sector Number of Data Area */
Line 2517  istgt_lu_dvd_scsi_read_disc_structure(ISTGT_LU_DVD *sp Line 2524  istgt_lu_dvd_scsi_read_disc_structure(ISTGT_LU_DVD *sp
   
                 /* Copyright Protection System Type */                  /* Copyright Protection System Type */
                 cp[0] = 0x00;                  cp[0] = 0x00;
                //cp[0] = 0x01; /* CSS/CPPM */                //cp[0] = 0x01;                         /* CSS/CPPM */
                 /* Region Management Information */                  /* Region Management Information */
                 cp[1] = 0x00;                  cp[1] = 0x00;
                 //cp[1] = 0xff & ~(1 << (2 - 1));       /* 2=Japan */                  //cp[1] = 0xff & ~(1 << (2 - 1));       /* 2=Japan */
Line 2540  istgt_lu_dvd_scsi_read_disc_structure(ISTGT_LU_DVD *sp Line 2547  istgt_lu_dvd_scsi_read_disc_structure(ISTGT_LU_DVD *sp
 }  }
   
 static int  static int
istgt_lu_dvd_scsi_report_key(ISTGT_LU_DVD *spec, CONN_Ptr conn, uint8_t *cdb, int keyclass, int agid, int keyformat, uint8_t *data)istgt_lu_dvd_scsi_report_key(ISTGT_LU_DVD *spec __attribute__((__unused__)), CONN_Ptr conn __attribute__((__unused__)), uint8_t *cdb __attribute__((__unused__)), int keyclass, int agid __attribute__((__unused__)), int keyformat, uint8_t *data)
 {  {
         uint8_t *cp;          uint8_t *cp;
         int hlen = 0, len = 0;          int hlen = 0, len = 0;
Line 2602  istgt_lu_dvd_scsi_report_key(ISTGT_LU_DVD *spec, CONN_ Line 2609  istgt_lu_dvd_scsi_report_key(ISTGT_LU_DVD *spec, CONN_
 }  }
   
 static int  static int
istgt_lu_dvd_lbread(ISTGT_LU_DVD *spec, CONN_Ptr conn, ISTGT_LU_CMD_Ptr lu_cmd, uint64_t lba, uint32_t len)istgt_lu_dvd_lbread(ISTGT_LU_DVD *spec, CONN_Ptr conn __attribute__((__unused__)), ISTGT_LU_CMD_Ptr lu_cmd, uint64_t lba, uint32_t len)
 {  {
         uint8_t *data;          uint8_t *data;
         uint64_t maxlba;          uint64_t maxlba;
Line 2625  istgt_lu_dvd_lbread(ISTGT_LU_DVD *spec, CONN_Ptr conn, Line 2632  istgt_lu_dvd_lbread(ISTGT_LU_DVD *spec, CONN_Ptr conn,
         nbytes = llen * blen;          nbytes = llen * blen;
   
         ISTGT_TRACELOG(ISTGT_TRACE_SCSI,          ISTGT_TRACELOG(ISTGT_TRACE_SCSI,
                                   "Read: max=%"PRIu64", lba=%"PRIu64", len=%u\n",            "Read: max=%"PRIu64", lba=%"PRIu64", len=%u\n",
                                   maxlba, lba, len);            maxlba, lba, len);
   
         if (lba >= maxlba || llen > maxlba || lba > (maxlba - llen)) {          if (lba >= maxlba || llen > maxlba || lba > (maxlba - llen)) {
                 ISTGT_ERRLOG("end of media\n");                  ISTGT_ERRLOG("end of media\n");
Line 2634  istgt_lu_dvd_lbread(ISTGT_LU_DVD *spec, CONN_Ptr conn, Line 2641  istgt_lu_dvd_lbread(ISTGT_LU_DVD *spec, CONN_Ptr conn,
         }          }
   
         if (nbytes > lu_cmd->iobufsize) {          if (nbytes > lu_cmd->iobufsize) {
                ISTGT_ERRLOG("nbytes(%u) > iobufsize(%u)\n",                ISTGT_ERRLOG("nbytes(%zu) > iobufsize(%zu)\n",
                                         nbytes, lu_cmd->iobufsize);                    (size_t) nbytes, lu_cmd->iobufsize);
                 return -1;                  return -1;
         }          }
         data = lu_cmd->iobuf;          data = lu_cmd->iobuf;
Line 2652  istgt_lu_dvd_lbread(ISTGT_LU_DVD *spec, CONN_Ptr conn, Line 2659  istgt_lu_dvd_lbread(ISTGT_LU_DVD *spec, CONN_Ptr conn,
                 return -1;                  return -1;
         }          }
         ISTGT_TRACELOG(ISTGT_TRACE_SCSI, "Read %"PRId64"/%"PRIu64" bytes\n",          ISTGT_TRACELOG(ISTGT_TRACE_SCSI, "Read %"PRId64"/%"PRIu64" bytes\n",
                                   rc, nbytes);            rc, nbytes);
   
         lu_cmd->data = data;          lu_cmd->data = data;
         lu_cmd->data_len = rc;          lu_cmd->data_len = rc;
Line 2684  istgt_lu_dvd_lbwrite(ISTGT_LU_DVD *spec, CONN_Ptr conn Line 2691  istgt_lu_dvd_lbwrite(ISTGT_LU_DVD *spec, CONN_Ptr conn
         nbytes = llen * blen;          nbytes = llen * blen;
   
         ISTGT_TRACELOG(ISTGT_TRACE_SCSI,          ISTGT_TRACELOG(ISTGT_TRACE_SCSI,
                                   "Write: max=%"PRIu64", lba=%"PRIu64", len=%u\n",            "Write: max=%"PRIu64", lba=%"PRIu64", len=%u\n",
                                   maxlba, lba, len);            maxlba, lba, len);
   
         if (lba >= maxlba || llen > maxlba || lba > (maxlba - llen)) {          if (lba >= maxlba || llen > maxlba || lba > (maxlba - llen)) {
                 ISTGT_ERRLOG("end of media\n");                  ISTGT_ERRLOG("end of media\n");
Line 2694  istgt_lu_dvd_lbwrite(ISTGT_LU_DVD *spec, CONN_Ptr conn Line 2701  istgt_lu_dvd_lbwrite(ISTGT_LU_DVD *spec, CONN_Ptr conn
   
         if (nbytes > lu_cmd->iobufsize) {          if (nbytes > lu_cmd->iobufsize) {
                 ISTGT_ERRLOG("nbytes(%u) > iobufsize(%u)\n",                  ISTGT_ERRLOG("nbytes(%u) > iobufsize(%u)\n",
                                         nbytes, lu_cmd->iobufsize);                    nbytes, lu_cmd->iobufsize);
                 return -1;                  return -1;
         }          }
         data = lu_cmd->iobuf;          data = lu_cmd->iobuf;
   
         rc = istgt_lu_dvd_transfer_data(conn, lu_cmd, lu_cmd->iobuf,          rc = istgt_lu_dvd_transfer_data(conn, lu_cmd, lu_cmd->iobuf,
                                                                        lu_cmd->iobufsize, nbytes);            lu_cmd->iobufsize, nbytes);
         if (rc < 0) {          if (rc < 0) {
                 ISTGT_ERRLOG("lu_dvd_transfer_data() failed\n");                  ISTGT_ERRLOG("lu_dvd_transfer_data() failed\n");
                 return -1;                  return -1;
Line 2727  istgt_lu_dvd_lbwrite(ISTGT_LU_DVD *spec, CONN_Ptr conn Line 2734  istgt_lu_dvd_lbwrite(ISTGT_LU_DVD *spec, CONN_Ptr conn
                 return -1;                  return -1;
         }          }
         ISTGT_TRACELOG(ISTGT_TRACE_SCSI, "Wrote %"PRId64"/%"PRIu64" bytes\n",          ISTGT_TRACELOG(ISTGT_TRACE_SCSI, "Wrote %"PRId64"/%"PRIu64" bytes\n",
                                   rc, nbytes);            rc, nbytes);
   
         lu_cmd->data_len = rc;          lu_cmd->data_len = rc;
   
Line 2755  istgt_lu_dvd_lbsync(ISTGT_LU_DVD *spec, CONN_Ptr conn, Line 2762  istgt_lu_dvd_lbsync(ISTGT_LU_DVD *spec, CONN_Ptr conn,
         nbytes = llen * blen;          nbytes = llen * blen;
   
         ISTGT_TRACELOG(ISTGT_TRACE_SCSI,          ISTGT_TRACELOG(ISTGT_TRACE_SCSI,
                                   "Sync: max=%"PRIu64", lba=%"PRIu64", len=%u\n",            "Sync: max=%"PRIu64", lba=%"PRIu64", len=%u\n",
                                   maxlba, lba, len);            maxlba, lba, len);
   
         if (lba >= maxlba || llen > maxlba || lba > (maxlba - llen)) {          if (lba >= maxlba || llen > maxlba || lba > (maxlba - llen)) {
                 ISTGT_ERRLOG("end of media\n");                  ISTGT_ERRLOG("end of media\n");
Line 2774  istgt_lu_dvd_lbsync(ISTGT_LU_DVD *spec, CONN_Ptr conn, Line 2781  istgt_lu_dvd_lbsync(ISTGT_LU_DVD *spec, CONN_Ptr conn,
 #endif  #endif
   
 static int  static int
istgt_lu_dvd_build_sense_data(ISTGT_LU_DVD *spec, uint8_t *data, int sk, int asc, int ascq)istgt_lu_dvd_build_sense_data(ISTGT_LU_DVD *spec __attribute__((__unused__)), uint8_t *data, int sk, int asc, int ascq)
 {  {
         int rc;          int rc;
   
Line 2887  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 2894  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
         uint64_t lba;          uint64_t lba;
         uint32_t transfer_len;          uint32_t transfer_len;
         uint8_t *sense_data;          uint8_t *sense_data;
        int *sense_len;        size_t *sense_len;
         int rc;          int rc;
   
         if (lu_cmd == NULL)          if (lu_cmd == NULL)
Line 2915  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 2922  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
         } else {          } else {
                 lun = 0xffffU;                  lun = 0xffffU;
         }          }
        if (lun >= lu->maxlun) {        if (lun >= (uint64_t) lu->maxlun) {
 #ifdef ISTGT_TRACE_DVD  #ifdef ISTGT_TRACE_DVD
                 ISTGT_ERRLOG("LU%d: LUN%4.4"PRIx64" invalid\n",                  ISTGT_ERRLOG("LU%d: LUN%4.4"PRIx64" invalid\n",
                                          lu->num, lun);                                           lu->num, lun);
 #endif /* ISTGT_TRACE_DVD */  #endif /* ISTGT_TRACE_DVD */
                 if (cdb[0] == SPC_INQUIRY) {                  if (cdb[0] == SPC_INQUIRY) {
                         allocation_len = DGET16(&cdb[3]);                          allocation_len = DGET16(&cdb[3]);
                        if (allocation_len > data_alloc_len) {                        if (allocation_len > (size_t) data_alloc_len) {
                                 ISTGT_ERRLOG("data_alloc_len(%d) too small\n",                                  ISTGT_ERRLOG("data_alloc_len(%d) too small\n",
                                                         data_alloc_len);                                    data_alloc_len);
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 return -1;                                  return -1;
                         }                          }
Line 2936  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 2943  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         memset(&data[1], 0, data_len - 1);                          memset(&data[1], 0, data_len - 1);
                         /* ADDITIONAL LENGTH */                          /* ADDITIONAL LENGTH */
                         data[4] = data_len - 5;                          data[4] = data_len - 5;
                        lu_cmd->data_len = DMIN32(data_len, lu_cmd->transfer_len);                        lu_cmd->data_len = DMIN32((size_t)data_len, lu_cmd->transfer_len);
                         lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;                          lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;
                         return 0;                          return 0;
                 } else {                  } else {
Line 2957  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 2964  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
         }          }
   
         ISTGT_TRACELOG(ISTGT_TRACE_SCSI, "SCSI OP=0x%x, LUN=0x%16.16"PRIx64"\n",          ISTGT_TRACELOG(ISTGT_TRACE_SCSI, "SCSI OP=0x%x, LUN=0x%16.16"PRIx64"\n",
                                   cdb[0], lu_cmd->lun);            cdb[0], lu_cmd->lun);
 #ifdef ISTGT_TRACE_DVD  #ifdef ISTGT_TRACE_DVD
         if (cdb[0] != SPC_TEST_UNIT_READY          if (cdb[0] != SPC_TEST_UNIT_READY
                 && cdb[0] != MMC_GET_EVENT_STATUS_NOTIFICATION) {                  && cdb[0] != MMC_GET_EVENT_STATUS_NOTIFICATION) {
Line 2976  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 2983  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         return -1;                          return -1;
                 }                  }
                 allocation_len = DGET16(&cdb[3]);                  allocation_len = DGET16(&cdb[3]);
                if (allocation_len > data_alloc_len) {                if (allocation_len > (size_t) data_alloc_len) {
                         ISTGT_ERRLOG("data_alloc_len(%d) too small\n",                          ISTGT_ERRLOG("data_alloc_len(%d) too small\n",
                                                 data_alloc_len);                            data_alloc_len);
                         lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                          lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                         return -1;                          return -1;
                 }                  }
                 memset(data, 0, allocation_len);                  memset(data, 0, allocation_len);
                 data_len = istgt_lu_dvd_scsi_inquiry(spec, conn, cdb,                  data_len = istgt_lu_dvd_scsi_inquiry(spec, conn, cdb,
                                                                                         data, data_alloc_len);                    data, data_alloc_len);
                 if (data_len < 0) {                  if (data_len < 0) {
                         lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                          lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                         break;                          break;
                 }                  }
                 ISTGT_TRACEDUMP(ISTGT_TRACE_DEBUG, "INQUIRY", data, data_len);                  ISTGT_TRACEDUMP(ISTGT_TRACE_DEBUG, "INQUIRY", data, data_len);
                lu_cmd->data_len = DMIN32(data_len, lu_cmd->transfer_len);                lu_cmd->data_len = DMIN32((size_t)data_len, lu_cmd->transfer_len);
                 lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;                  lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;
                 break;                  break;
   
Line 3008  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3015  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "sel=%x\n", sel);                          ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "sel=%x\n", sel);
   
                         allocation_len = DGET32(&cdb[6]);                          allocation_len = DGET32(&cdb[6]);
                        if (allocation_len > data_alloc_len) {                        if (allocation_len > (size_t) data_alloc_len) {
                                 ISTGT_ERRLOG("data_alloc_len(%d) too small\n",                                  ISTGT_ERRLOG("data_alloc_len(%d) too small\n",
                                                         data_alloc_len);                                    data_alloc_len);
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 return -1;                                  return -1;
                         }                          }
Line 3028  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3035  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                                 break;                                  break;
                         }                          }
                         ISTGT_TRACEDUMP(ISTGT_TRACE_DEBUG, "REPORT LUNS", data, data_len);                          ISTGT_TRACEDUMP(ISTGT_TRACE_DEBUG, "REPORT LUNS", data, data_len);
                        lu_cmd->data_len = DMIN32(data_len, lu_cmd->transfer_len);                        lu_cmd->data_len = DMIN32((size_t)data_len, lu_cmd->transfer_len);
                         lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;                          lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;
                 }                  }
                 break;                  break;
Line 3201  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3208  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
   
                         /* Data-Out */                          /* Data-Out */
                         rc = istgt_lu_dvd_transfer_data(conn, lu_cmd, lu_cmd->iobuf,                          rc = istgt_lu_dvd_transfer_data(conn, lu_cmd, lu_cmd->iobuf,
                                                                                        lu_cmd->iobufsize, pllen);                            lu_cmd->iobufsize, pllen);
                         if (rc < 0) {                          if (rc < 0) {
                                 ISTGT_ERRLOG("lu_dvd_transfer_data() failed\n");                                  ISTGT_ERRLOG("lu_dvd_transfer_data() failed\n");
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
Line 3243  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3250  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
   
                         /* Data-Out */                          /* Data-Out */
                         rc = istgt_lu_dvd_transfer_data(conn, lu_cmd, lu_cmd->iobuf,                          rc = istgt_lu_dvd_transfer_data(conn, lu_cmd, lu_cmd->iobuf,
                                                                                        lu_cmd->iobufsize, pllen);                            lu_cmd->iobufsize, pllen);
                         if (rc < 0) {                          if (rc < 0) {
                                 ISTGT_ERRLOG("lu_dvd_transfer_data() failed\n");                                  ISTGT_ERRLOG("lu_dvd_transfer_data() failed\n");
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
Line 3297  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3304  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         subpage = cdb[3];                          subpage = cdb[3];
   
                         allocation_len = cdb[4];                          allocation_len = cdb[4];
                        if (allocation_len > data_alloc_len) {                        if (allocation_len > (size_t) data_alloc_len) {
                                 ISTGT_ERRLOG("data_alloc_len(%d) too small\n",                                  ISTGT_ERRLOG("data_alloc_len(%d) too small\n",
                                                         data_alloc_len);                                    data_alloc_len);
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 return -1;                                  return -1;
                         }                          }
Line 3307  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3314  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
   
                         data_len = istgt_lu_dvd_scsi_mode_sense6(spec, conn, cdb, dbd, pc, page, subpage, data, data_alloc_len);                          data_len = istgt_lu_dvd_scsi_mode_sense6(spec, conn, cdb, dbd, pc, page, subpage, data, data_alloc_len);
                         if (data_len < 0) {                          if (data_len < 0) {
                                   /* INVALID FIELD IN CDB */
                                   BUILD_SENSE(ILLEGAL_REQUEST, 0x24, 0x00);
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 break;                                  break;
                         }                          }
 #if 0  #if 0
                         istgt_dump("MODE SENSE(6)", data, data_len);                          istgt_dump("MODE SENSE(6)", data, data_len);
 #endif  #endif
                        lu_cmd->data_len = DMIN32(data_len, lu_cmd->transfer_len);                        lu_cmd->data_len = DMIN32((size_t)data_len, lu_cmd->transfer_len);
                         lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;                          lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;
                         break;                          break;
                 }                  }
Line 3336  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3345  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         subpage = cdb[3];                          subpage = cdb[3];
   
                         allocation_len = DGET16(&cdb[7]);                          allocation_len = DGET16(&cdb[7]);
                        if (allocation_len > data_alloc_len) {                        if (allocation_len > (size_t) data_alloc_len) {
                                 ISTGT_ERRLOG("data_alloc_len(%d) too small\n",                                  ISTGT_ERRLOG("data_alloc_len(%d) too small\n",
                                                         data_alloc_len);                                    data_alloc_len);
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 return -1;                                  return -1;
                         }                          }
Line 3346  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3355  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
   
                         data_len = istgt_lu_dvd_scsi_mode_sense10(spec, conn, cdb, llbaa, dbd, pc, page, subpage, data, data_alloc_len);                          data_len = istgt_lu_dvd_scsi_mode_sense10(spec, conn, cdb, llbaa, dbd, pc, page, subpage, data, data_alloc_len);
                         if (data_len < 0) {                          if (data_len < 0) {
                                   /* INVALID FIELD IN CDB */
                                   BUILD_SENSE(ILLEGAL_REQUEST, 0x24, 0x00);
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 break;                                  break;
                         }                          }
 #if 0  #if 0
                         istgt_dump("MODE SENSE(10)", data, data_len);                          istgt_dump("MODE SENSE(10)", data, data_len);
 #endif  #endif
                        lu_cmd->data_len = DMIN32(data_len, lu_cmd->transfer_len);                        lu_cmd->data_len = DMIN32((size_t)data_len, lu_cmd->transfer_len);
                         lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;                          lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;
                         break;                          break;
                 }                  }
   
 #if 0  
         case SPC_LOG_SELECT:          case SPC_LOG_SELECT:
         case SPC_LOG_SENSE:          case SPC_LOG_SENSE:
                 /* INVALID COMMAND OPERATION CODE */                  /* INVALID COMMAND OPERATION CODE */
                 BUILD_SENSE(ILLEGAL_REQUEST, 0x20, 0x00);                  BUILD_SENSE(ILLEGAL_REQUEST, 0x20, 0x00);
                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                 break;                  break;
 #endif  
   
         case SPC_REQUEST_SENSE:          case SPC_REQUEST_SENSE:
                 ISTGT_TRACELOG(ISTGT_TRACE_SCSI, "REQUEST_SENSE\n");                  ISTGT_TRACELOG(ISTGT_TRACE_SCSI, "REQUEST_SENSE\n");
Line 3407  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3416  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         }                          }
   
                         allocation_len = cdb[4];                          allocation_len = cdb[4];
                        if (allocation_len > data_alloc_len) {                        if (allocation_len > (size_t) data_alloc_len) {
                                 ISTGT_ERRLOG("data_alloc_len(%d) too small\n",                                  ISTGT_ERRLOG("data_alloc_len(%d) too small\n",
                                                         data_alloc_len);                                    data_alloc_len);
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 return -1;                                  return -1;
                         }                          }
Line 3435  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3444  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         data_len -= 2;                          data_len -= 2;
                         memcpy(data, sense_data + 2, data_len);                          memcpy(data, sense_data + 2, data_len);
   
                        lu_cmd->data_len = DMIN32(data_len, lu_cmd->transfer_len);                        lu_cmd->data_len = DMIN32((size_t)data_len, lu_cmd->transfer_len);
                         lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;                          lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;
                         break;                          break;
                 }                  }
Line 3462  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3471  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         }                          }
   
                         allocation_len = DGET16(&cdb[7]);                          allocation_len = DGET16(&cdb[7]);
                        if (allocation_len > data_alloc_len) {                        if (allocation_len > (size_t) data_alloc_len) {
                                 ISTGT_ERRLOG("data_alloc_len(%d) too small\n",                                  ISTGT_ERRLOG("data_alloc_len(%d) too small\n",
                                                         data_alloc_len);                                    data_alloc_len);
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 return -1;                                  return -1;
                         }                          }
Line 3477  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3486  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 break;                                  break;
                         }                          }
                        lu_cmd->data_len = DMIN32(data_len, lu_cmd->transfer_len);                        lu_cmd->data_len = DMIN32((size_t)data_len, lu_cmd->transfer_len);
                         lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;                          lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;
                         break;                          break;
                 }                  }
Line 3498  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3507  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         ncr = cdb[4];                          ncr = cdb[4];
   
                         allocation_len = DGET16(&cdb[7]);                          allocation_len = DGET16(&cdb[7]);
                        if (allocation_len > data_alloc_len) {                        if (allocation_len > (size_t) data_alloc_len) {
                                 ISTGT_ERRLOG("data_alloc_len(%d) too small\n",                                  ISTGT_ERRLOG("data_alloc_len(%d) too small\n",
                                                         data_alloc_len);                                    data_alloc_len);
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 return -1;                                  return -1;
                         }                          }
Line 3525  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3534  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                                 break;                                  break;
                         }                          }
                         ISTGT_TRACEDUMP(ISTGT_TRACE_DEBUG, "EVENT", data, data_len);                          ISTGT_TRACEDUMP(ISTGT_TRACE_DEBUG, "EVENT", data, data_len);
                        lu_cmd->data_len = DMIN32(data_len, lu_cmd->transfer_len);                        lu_cmd->data_len = DMIN32((size_t)data_len, lu_cmd->transfer_len);
                         lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;                          lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;
                         break;                          break;
                 }                  }
Line 3563  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3572  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         }                          }
   
                         allocation_len = DGET16(&cdb[8]);                          allocation_len = DGET16(&cdb[8]);
                        if (allocation_len > data_alloc_len) {                        if (allocation_len > (size_t) data_alloc_len) {
                                 ISTGT_ERRLOG("data_alloc_len(%d) too small\n",                                  ISTGT_ERRLOG("data_alloc_len(%d) too small\n",
                                                         data_alloc_len);                                    data_alloc_len);
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 return -1;                                  return -1;
                         }                          }
Line 3578  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3587  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 break;                                  break;
                         }                          }
                        lu_cmd->data_len = DMIN32(data_len, lu_cmd->transfer_len);                        lu_cmd->data_len = DMIN32((size_t)data_len, lu_cmd->transfer_len);
                         lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;                          lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;
                         break;                          break;
                 }                  }
Line 3606  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3615  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         track = cdb[6];                          track = cdb[6];
   
                         allocation_len = DGET16(&cdb[7]);                          allocation_len = DGET16(&cdb[7]);
                        if (allocation_len > data_alloc_len) {                        if (allocation_len > (size_t) data_alloc_len) {
                                 ISTGT_ERRLOG("data_alloc_len(%d) too small\n",                                  ISTGT_ERRLOG("data_alloc_len(%d) too small\n",
                                                         data_alloc_len);                                    data_alloc_len);
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 return -1;                                  return -1;
                         }                          }
Line 3621  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3630  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 break;                                  break;
                         }                          }
                        lu_cmd->data_len = DMIN32(data_len, lu_cmd->transfer_len);                        lu_cmd->data_len = DMIN32((size_t)data_len, lu_cmd->transfer_len);
                         lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;                          lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;
                         break;                          break;
                 }                  }
Line 3647  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3656  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         datatype = BGET8W(&cdb[1], 2, 3);                          datatype = BGET8W(&cdb[1], 2, 3);
   
                         allocation_len = DGET16(&cdb[7]);                          allocation_len = DGET16(&cdb[7]);
                        if (allocation_len > data_alloc_len) {                        if (allocation_len > (size_t) data_alloc_len) {
                                 ISTGT_ERRLOG("data_alloc_len(%d) too small\n",                                  ISTGT_ERRLOG("data_alloc_len(%d) too small\n",
                                                         data_alloc_len);                                    data_alloc_len);
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 return -1;                                  return -1;
                         }                          }
Line 3662  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3671  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 break;                                  break;
                         }                          }
                        lu_cmd->data_len = DMIN32(data_len, lu_cmd->transfer_len);                        lu_cmd->data_len = DMIN32((size_t)data_len, lu_cmd->transfer_len);
                         lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;                          lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;
                         break;                          break;
                 }                  }
Line 3691  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3700  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         agid = BGET8W(&cdb[10], 7, 2);                          agid = BGET8W(&cdb[10], 7, 2);
   
                         allocation_len = DGET16(&cdb[8]);                          allocation_len = DGET16(&cdb[8]);
                        if (allocation_len > data_alloc_len) {                        if (allocation_len > (size_t) data_alloc_len) {
                                 ISTGT_ERRLOG("data_alloc_len(%d) too small\n",                                  ISTGT_ERRLOG("data_alloc_len(%d) too small\n",
                                                         data_alloc_len);                                    data_alloc_len);
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 return -1;                                  return -1;
                         }                          }
Line 3706  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3715  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 break;                                  break;
                         }                          }
                        lu_cmd->data_len = DMIN32(data_len, lu_cmd->transfer_len);                        lu_cmd->data_len = DMIN32((size_t)data_len, lu_cmd->transfer_len);
                         lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;                          lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;
                         break;                          break;
                 }                  }
Line 3750  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3759  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         keyformat = BGET8W(&cdb[10], 5, 6);                          keyformat = BGET8W(&cdb[10], 5, 6);
   
                         allocation_len = DGET16(&cdb[8]);                          allocation_len = DGET16(&cdb[8]);
                        if (allocation_len > data_alloc_len) {                        if (allocation_len > (size_t) data_alloc_len) {
                                 ISTGT_ERRLOG("data_alloc_len(%d) too small\n",                                  ISTGT_ERRLOG("data_alloc_len(%d) too small\n",
                                                         data_alloc_len);                                    data_alloc_len);
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 return -1;                                  return -1;
                         }                          }
Line 3765  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3774  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                                 lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;                                  lu_cmd->status = ISTGT_SCSI_STATUS_CHECK_CONDITION;
                                 break;                                  break;
                         }                          }
                        lu_cmd->data_len = DMIN32(data_len, lu_cmd->transfer_len);                        lu_cmd->data_len = DMIN32((size_t)data_len, lu_cmd->transfer_len);
                         lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;                          lu_cmd->status = ISTGT_SCSI_STATUS_GOOD;
                         break;                          break;
                 }                  }
Line 3808  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3817  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         lba = (uint64_t) DGET32(&cdb[2]);                          lba = (uint64_t) DGET32(&cdb[2]);
                         transfer_len = (uint32_t) DGET16(&cdb[7]);                          transfer_len = (uint32_t) DGET16(&cdb[7]);
                         ISTGT_TRACELOG(ISTGT_TRACE_SCSI,                          ISTGT_TRACELOG(ISTGT_TRACE_SCSI,
                                                   "READ_10(lba %"PRIu64", len %u blocks)\n",                            "READ_10(lba %"PRIu64", len %u blocks)\n",
                                                   lba, transfer_len);                            lba, transfer_len);
                         rc = istgt_lu_dvd_lbread(spec, conn, lu_cmd, lba, transfer_len);                          rc = istgt_lu_dvd_lbread(spec, conn, lu_cmd, lba, transfer_len);
                         if (rc < 0) {                          if (rc < 0) {
                                 ISTGT_ERRLOG("lu_dvd_lbread() failed\n");                                  ISTGT_ERRLOG("lu_dvd_lbread() failed\n");
Line 3842  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3851  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
                         lba = (uint64_t) DGET32(&cdb[2]);                          lba = (uint64_t) DGET32(&cdb[2]);
                         transfer_len = (uint32_t) DGET32(&cdb[6]);                          transfer_len = (uint32_t) DGET32(&cdb[6]);
                         ISTGT_TRACELOG(ISTGT_TRACE_SCSI,                          ISTGT_TRACELOG(ISTGT_TRACE_SCSI,
                                                   "READ_12(lba %"PRIu64", len %u blocks)\n",                            "READ_12(lba %"PRIu64", len %u blocks)\n",
                                                   lba, transfer_len);                            lba, transfer_len);
                         rc = istgt_lu_dvd_lbread(spec, conn, lu_cmd, lba, transfer_len);                          rc = istgt_lu_dvd_lbread(spec, conn, lu_cmd, lba, transfer_len);
                         if (rc < 0) {                          if (rc < 0) {
                                 ISTGT_ERRLOG("lu_dvd_lbread() failed\n");                                  ISTGT_ERRLOG("lu_dvd_lbread() failed\n");
Line 3893  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l Line 3902  istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr l
         }          }
   
         ISTGT_TRACELOG(ISTGT_TRACE_SCSI,          ISTGT_TRACELOG(ISTGT_TRACE_SCSI,
                                   "SCSI OP=0x%x, LUN=0x%16.16"PRIx64" status=0x%x,"            "SCSI OP=0x%x, LUN=0x%16.16"PRIx64" status=0x%x,"
                                   " complete\n",            " complete\n",
                                   cdb[0], lu_cmd->lun, lu_cmd->status);            cdb[0], lu_cmd->lun, lu_cmd->status);
         return 0;          return 0;
 }  }

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>