lib/sg_cmds_extra.c
int
sg_ll_3party_copy_out(int sg_fd, int sa, unsigned int list_id, int group_num,
                      int timeout_secs, void * paramp, int param_len,
                      int noisy, int verbose)
{
    int k, res, ret, sense_cat, tmout;
    unsigned char xcopyCmdBlk[THIRD_PARTY_COPY_OUT_CMDLEN] =
      {THIRD_PARTY_COPY_OUT_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    unsigned char sense_b[SENSE_BUFF_LEN];
    struct sg_pt_base * ptvp;
    char cname[80];

    sg_get_opcode_sa_name(THIRD_PARTY_COPY_OUT_CMD, sa, 0, sizeof(cname),
                          cname);
    xcopyCmdBlk[1] = (unsigned char)(sa & 0x1f);
    switch (sa) {
    case 0x0:   /* XCOPY(LID1) */
    case 0x1:   /* XCOPY(LID4) */
        xcopyCmdBlk[10] = (unsigned char)((param_len >> 24) & 0xff);
        xcopyCmdBlk[11] = (unsigned char)((param_len >> 16) & 0xff);
        xcopyCmdBlk[12] = (unsigned char)((param_len >> 8) & 0xff);
        xcopyCmdBlk[13] = (unsigned char)(param_len & 0xff);
        break;
    case 0x10:  /* POPULATE TOKEN (SBC-3) */
    case 0x11:  /* WRITE USING TOKEN (SBC-3) */
        xcopyCmdBlk[6] = (unsigned char)((list_id >> 24) & 0xff);
        xcopyCmdBlk[7] = (unsigned char)((list_id >> 16) & 0xff);
        xcopyCmdBlk[8] = (unsigned char)((list_id >> 8) & 0xff);
        xcopyCmdBlk[9] = (unsigned char)(list_id & 0xff);
        xcopyCmdBlk[10] = (unsigned char)((param_len >> 24) & 0xff);
        xcopyCmdBlk[11] = (unsigned char)((param_len >> 16) & 0xff);
        xcopyCmdBlk[12] = (unsigned char)((param_len >> 8) & 0xff);
        xcopyCmdBlk[13] = (unsigned char)(param_len & 0xff);
        xcopyCmdBlk[14] = (unsigned char)(group_num & 0x1f);
        break;
    case 0x1c:  /* COPY OPERATION ABORT */
        xcopyCmdBlk[2] = (unsigned char)((list_id >> 24) & 0xff);
        xcopyCmdBlk[3] = (unsigned char)((list_id >> 16) & 0xff);
        xcopyCmdBlk[4] = (unsigned char)((list_id >> 8) & 0xff);
        xcopyCmdBlk[5] = (unsigned char)(list_id & 0xff);
        break;
    default:
        pr2ws("sg_ll_3party_copy_out: unknown service action 0x%x\n", sa);
        return -1;
    }
    tmout = (timeout_secs > 0) ? timeout_secs : DEF_PT_TIMEOUT;

    if (verbose) {
        pr2ws("    %s cmd: ", cname);
        for (k = 0; k < THIRD_PARTY_COPY_OUT_CMDLEN; ++k)
            pr2ws("%02x ", xcopyCmdBlk[k]);
        pr2ws("\n");
        if ((verbose > 1) && paramp && param_len) {
            pr2ws("    %s parameter list:\n", cname);
            dStrHexErr((const char *)paramp, param_len, -1);
        }
    }

    ptvp = construct_scsi_pt_obj();
    if (NULL == ptvp) {
        pr2ws("%s: out of memory\n", cname);
        return -1;
    }
    set_scsi_pt_cdb(ptvp, xcopyCmdBlk, sizeof(xcopyCmdBlk));
    set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
    set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
    res = do_scsi_pt(ptvp, sg_fd, tmout, verbose);
    ret = sg_cmds_process_resp(ptvp, cname, res, 0, sense_b, noisy, verbose,
                               &sense_cat);
    if (-1 == ret)
        ;
    else if (-2 == ret) {
        switch (sense_cat) {
        case SG_LIB_CAT_RECOVERED:
        case SG_LIB_CAT_NO_SENSE:
            ret = 0;
            break;
        default:
            ret = sense_cat;
            break;
        }
    } else
        ret = 0;
    destruct_scsi_pt_obj(ptvp);
    return ret;
}
/* Handles various service actions associated with opcode 0x83 which is
 * called THIRD PARTY COPY OUT. These include the EXTENDED COPY(LID1 and
 * LID4), POPULATE TOKEN and WRITE USING TOKEN commands.
 * Return of 0 -> success,
 * various SG_LIB_CAT_* positive values or -1 -> other errors */
Handles various service actions associated with opcode 0x83 which is
called THIRD PARTY COPY OUT.
Handles various service actions associated with opcode 0x83 which is called THIRD PARTY COPY OUT .
int
sg_ll_3party_copy_out(int sg_fd, int sa, unsigned int list_id, int group_num,
                      int timeout_secs, void * paramp, int param_len,
                      int noisy, int verbose)
{
    int k, res, ret, sense_cat, tmout;
    unsigned char xcopyCmdBlk[THIRD_PARTY_COPY_OUT_CMDLEN] =
      {THIRD_PARTY_COPY_OUT_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    unsigned char sense_b[SENSE_BUFF_LEN];
    struct sg_pt_base * ptvp;
    char cname[80];
    sg_get_opcode_sa_name(THIRD_PARTY_COPY_OUT_CMD, sa, 0, sizeof(cname),
                          cname);
    xcopyCmdBlk[1] = (unsigned char)(sa & 0x1f);
    switch (sa) {
    case 0x0:   
    case 0x1:   
        xcopyCmdBlk[10] = (unsigned char)((param_len >> 24) & 0xff);
        xcopyCmdBlk[11] = (unsigned char)((param_len >> 16) & 0xff);
        xcopyCmdBlk[12] = (unsigned char)((param_len >> 8) & 0xff);
        xcopyCmdBlk[13] = (unsigned char)(param_len & 0xff);
        break;
    case 0x10:  
    case 0x11:  
        xcopyCmdBlk[6] = (unsigned char)((list_id >> 24) & 0xff);
        xcopyCmdBlk[7] = (unsigned char)((list_id >> 16) & 0xff);
        xcopyCmdBlk[8] = (unsigned char)((list_id >> 8) & 0xff);
        xcopyCmdBlk[9] = (unsigned char)(list_id & 0xff);
        xcopyCmdBlk[10] = (unsigned char)((param_len >> 24) & 0xff);
        xcopyCmdBlk[11] = (unsigned char)((param_len >> 16) & 0xff);
        xcopyCmdBlk[12] = (unsigned char)((param_len >> 8) & 0xff);
        xcopyCmdBlk[13] = (unsigned char)(param_len & 0xff);
        xcopyCmdBlk[14] = (unsigned char)(group_num & 0x1f);
        break;
    case 0x1c:  
        xcopyCmdBlk[2] = (unsigned char)((list_id >> 24) & 0xff);
        xcopyCmdBlk[3] = (unsigned char)((list_id >> 16) & 0xff);
        xcopyCmdBlk[4] = (unsigned char)((list_id >> 8) & 0xff);
        xcopyCmdBlk[5] = (unsigned char)(list_id & 0xff);
        break;
    default:
        pr2ws("sg_ll_3party_copy_out: unknown service action 0x%x\n", sa);
        return -1;
    }
    tmout = (timeout_secs > 0) ? timeout_secs : DEF_PT_TIMEOUT;
    if (verbose) {
        pr2ws("    %s cmd: ", cname);
        for (k = 0; k < THIRD_PARTY_COPY_OUT_CMDLEN; ++k)
            pr2ws("%02x ", xcopyCmdBlk[k]);
        pr2ws("\n");
        if ((verbose > 1) && paramp && param_len) {
            pr2ws("    %s parameter list:\n", cname);
            dStrHexErr((const char *)paramp, param_len, -1);
        }
    }
    ptvp = construct_scsi_pt_obj();
    if (NULL == ptvp) {
        pr2ws("%s: out of memory\n", cname);
        return -1;
    }
    set_scsi_pt_cdb(ptvp, xcopyCmdBlk, sizeof(xcopyCmdBlk));
    set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
    set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
    res = do_scsi_pt(ptvp, sg_fd, tmout, verbose);
    ret = sg_cmds_process_resp(ptvp, cname, res, 0, sense_b, noisy, verbose,
                               &sense_cat);
    if (-1 == ret)
        ;
    else if (-2 == ret) {
        switch (sense_cat) {
        case SG_LIB_CAT_RECOVERED:
        case SG_LIB_CAT_NO_SENSE:
            ret = 0;
            break;
        default:
            ret = sense_cat;
            break;
        }
    } else
        ret = 0;
    destruct_scsi_pt_obj(ptvp);
    return ret;
}
int sg_ll_3party_copy_out ( int sg_fd , int sa , unsigned int list_id , int group_num , int timeout_secs , void * paramp , int param_len , int noisy , int verbose ) { int k , res , ret , sense_cat , tmout ; unsigned char xcopyCmdBlk [ THIRD_PARTY_COPY_OUT_CMDLEN ] = { THIRD_PARTY_COPY_OUT_CMD , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ; unsigned char sense_b [ SENSE_BUFF_LEN ] ; struct sg_pt_base * ptvp ; char cname [ 80 ] ; sg_get_opcode_sa_name ( THIRD_PARTY_COPY_OUT_CMD , sa , 0 , sizeof ( cname ) , cname ) ; xcopyCmdBlk [ 1 ] = ( unsigned char ) ( sa & 0x1f ) ; switch ( sa ) { case 0x0 : case 0x1 : xcopyCmdBlk [ 10 ] = ( unsigned char ) ( ( param_len >> 24 ) & 0xff ) ; xcopyCmdBlk [ 11 ] = ( unsigned char ) ( ( param_len >> 16 ) & 0xff ) ; xcopyCmdBlk [ 12 ] = ( unsigned char ) ( ( param_len >> 8 ) & 0xff ) ; xcopyCmdBlk [ 13 ] = ( unsigned char ) ( param_len & 0xff ) ; break ; case 0x10 : case 0x11 : xcopyCmdBlk [ 6 ] = ( unsigned char ) ( ( list_id >> 24 ) & 0xff ) ; xcopyCmdBlk [ 7 ] = ( unsigned char ) ( ( list_id >> 16 ) & 0xff ) ; xcopyCmdBlk [ 8 ] = ( unsigned char ) ( ( list_id >> 8 ) & 0xff ) ; xcopyCmdBlk [ 9 ] = ( unsigned char ) ( list_id & 0xff ) ; xcopyCmdBlk [ 10 ] = ( unsigned char ) ( ( param_len >> 24 ) & 0xff ) ; xcopyCmdBlk [ 11 ] = ( unsigned char ) ( ( param_len >> 16 ) & 0xff ) ; xcopyCmdBlk [ 12 ] = ( unsigned char ) ( ( param_len >> 8 ) & 0xff ) ; xcopyCmdBlk [ 13 ] = ( unsigned char ) ( param_len & 0xff ) ; xcopyCmdBlk [ 14 ] = ( unsigned char ) ( group_num & 0x1f ) ; break ; case 0x1c : xcopyCmdBlk [ 2 ] = ( unsigned char ) ( ( list_id >> 24 ) & 0xff ) ; xcopyCmdBlk [ 3 ] = ( unsigned char ) ( ( list_id >> 16 ) & 0xff ) ; xcopyCmdBlk [ 4 ] = ( unsigned char ) ( ( list_id >> 8 ) & 0xff ) ; xcopyCmdBlk [ 5 ] = ( unsigned char ) ( list_id & 0xff ) ; break ; default : pr2ws ( " \n " , sa ) ; return -1 ; } tmout = ( timeout_secs > 0 ) ? timeout_secs : DEF_PT_TIMEOUT ; if ( verbose ) { pr2ws ( " " , cname ) ; for ( k = 0 ; k < THIRD_PARTY_COPY_OUT_CMDLEN ; ++ k ) pr2ws ( " " , xcopyCmdBlk [ k ] ) ; pr2ws ( " \n " ) ; if ( ( verbose > 1 ) && paramp && param_len ) { pr2ws ( " \n " , cname ) ; dStrHexErr ( ( const char * ) paramp , param_len , -1 ) ; } } ptvp = construct_scsi_pt_obj ( ) ; if ( NULL == ptvp ) { pr2ws ( " \n " , cname ) ; return -1 ; } set_scsi_pt_cdb ( ptvp , xcopyCmdBlk , sizeof ( xcopyCmdBlk ) ) ; set_scsi_pt_sense ( ptvp , sense_b , sizeof ( sense_b ) ) ; set_scsi_pt_data_out ( ptvp , ( unsigned char * ) paramp , param_len ) ; res = do_scsi_pt ( ptvp , sg_fd , tmout , verbose ) ; ret = sg_cmds_process_resp ( ptvp , cname , res , 0 , sense_b , noisy , verbose , & sense_cat ) ; if ( -1 == ret ) ; else if ( -2 == ret ) { switch ( sense_cat ) { case SG_LIB_CAT_RECOVERED : case SG_LIB_CAT_NO_SENSE : ret = 0 ; break ; default : ret = sense_cat ; break ; } } else ret = 0 ; destruct_scsi_pt_obj ( ptvp ) ; return ret ; }
Handles various service actions associated with opcode 0x83 which is
 called THIRD PARTY COPY OUT.
Handles various service actions associated with opcode 0x83 which is called THIRD PARTY COPY OUT .
/* XCOPY(LID1) */ /* XCOPY(LID4) */ /* POPULATE TOKEN (SBC-3) */ /* WRITE USING TOKEN (SBC-3) */ /* COPY OPERATION ABORT */