lib/sg_lib.c
int
sg_get_sense_progress_fld(const unsigned char * sensep, int sb_len,
                          int * progress_outp)
{
    const unsigned char * ucp;
    int sk, sk_pr;

    if (sb_len < 7)
        return 0;
    switch (sensep[0] & 0x7f) {
    case 0x70:
    case 0x71:
        sk = (sensep[2] & 0xf);
        if ((sb_len < 18) ||
            ((SPC_SK_NO_SENSE != sk) && (SPC_SK_NOT_READY != sk)))
            return 0;
        if (sensep[15] & 0x80) {        /* SKSV bit set */
            if (progress_outp)
                *progress_outp = (sensep[16] << 8) + sensep[17];
            return 1;
        } else
            return 0;
    case 0x72:
    case 0x73:
        /* sense key specific progress (0x2) or progress descriptor (0xa) */
        sk = (sensep[1] & 0xf);
        sk_pr = (SPC_SK_NO_SENSE == sk) || (SPC_SK_NOT_READY == sk);
        if (sk_pr && ((ucp = sg_scsi_sense_desc_find(sensep, sb_len, 2))) &&
            (0x6 == ucp[1]) && (0x80 & ucp[4])) {
            if (progress_outp)
                *progress_outp = (ucp[5] << 8) + ucp[6];
            return 1;
        } else if (((ucp = sg_scsi_sense_desc_find(sensep, sb_len, 0xa))) &&
                   ((0x6 == ucp[1]))) {
            if (progress_outp)
                *progress_outp = (ucp[6] << 8) + ucp[7];
            return 1;
        } else
            return 0;
    default:
        return 0;
    }
}
/* Returns 1 if SKSV is set and sense key is NO_SENSE or NOT_READY. Also
 * returns 1 if progress indication sense data descriptor found. Places
 * progress field from sense data where progress_outp points. If progress
 * field is not available returns 0 and *progress_outp is unaltered. Handles
 * both fixed and descriptor sense formats.
 * Hint: if 1 is returned *progress_outp may be multiplied by 100 then
 * divided by 65536 to get the percentage completion. */
Returns 1 if SKSV is set and sense key is NO_SENSE or NOT_READY. Also
returns 1 if progress indication sense data descriptor found. Places
progress field from sense data where progress_outp points. If progress
field is not available returns 0 and *progress_outp is unaltered. Handles
both fixed and descriptor sense formats.
Hint: if 1 is returned *progress_outp may be multiplied by 100 then
divided by 65536 to get the percentage completion.
Returns 1 if SKSV is set and sense key is NO_SENSE or NOT_READY . Also returns 1 if progress indication sense data descriptor found . Places progress field from sense data where progress_outp points . If progress field is not available returns 0 and * progress_outp is unaltered . Handles both fixed and descriptor sense formats . Hint : if 1 is returned * progress_outp may be multiplied by 100 then divided by 65536 to get the percentage completion .
int
sg_get_sense_progress_fld(const unsigned char * sensep, int sb_len,
                          int * progress_outp)
{
    const unsigned char * ucp;
    int sk, sk_pr;
    if (sb_len < 7)
        return 0;
    switch (sensep[0] & 0x7f) {
    case 0x70:
    case 0x71:
        sk = (sensep[2] & 0xf);
        if ((sb_len < 18) ||
            ((SPC_SK_NO_SENSE != sk) && (SPC_SK_NOT_READY != sk)))
            return 0;
        if (sensep[15] & 0x80) {        
            if (progress_outp)
                *progress_outp = (sensep[16] << 8) + sensep[17];
            return 1;
        } else
            return 0;
    case 0x72:
    case 0x73:
        sk = (sensep[1] & 0xf);
        sk_pr = (SPC_SK_NO_SENSE == sk) || (SPC_SK_NOT_READY == sk);
        if (sk_pr && ((ucp = sg_scsi_sense_desc_find(sensep, sb_len, 2))) &&
            (0x6 == ucp[1]) && (0x80 & ucp[4])) {
            if (progress_outp)
                *progress_outp = (ucp[5] << 8) + ucp[6];
            return 1;
        } else if (((ucp = sg_scsi_sense_desc_find(sensep, sb_len, 0xa))) &&
                   ((0x6 == ucp[1]))) {
            if (progress_outp)
                *progress_outp = (ucp[6] << 8) + ucp[7];
            return 1;
        } else
            return 0;
    default:
        return 0;
    }
}
int sg_get_sense_progress_fld ( const unsigned char * sensep , int sb_len , int * progress_outp ) { const unsigned char * ucp ; int sk , sk_pr ; if ( sb_len < 7 ) return 0 ; switch ( sensep [ 0 ] & 0x7f ) { case 0x70 : case 0x71 : sk = ( sensep [ 2 ] & 0xf ) ; if ( ( sb_len < 18 ) || ( ( SPC_SK_NO_SENSE != sk ) && ( SPC_SK_NOT_READY != sk ) ) ) return 0 ; if ( sensep [ 15 ] & 0x80 ) { if ( progress_outp ) * progress_outp = ( sensep [ 16 ] << 8 ) + sensep [ 17 ] ; return 1 ; } else return 0 ; case 0x72 : case 0x73 : sk = ( sensep [ 1 ] & 0xf ) ; sk_pr = ( SPC_SK_NO_SENSE == sk ) || ( SPC_SK_NOT_READY == sk ) ; if ( sk_pr && ( ( ucp = sg_scsi_sense_desc_find ( sensep , sb_len , 2 ) ) ) && ( 0x6 == ucp [ 1 ] ) && ( 0x80 & ucp [ 4 ] ) ) { if ( progress_outp ) * progress_outp = ( ucp [ 5 ] << 8 ) + ucp [ 6 ] ; return 1 ; } else if ( ( ( ucp = sg_scsi_sense_desc_find ( sensep , sb_len , 0xa ) ) ) && ( ( 0x6 == ucp [ 1 ] ) ) ) { if ( progress_outp ) * progress_outp = ( ucp [ 6 ] << 8 ) + ucp [ 7 ] ; return 1 ; } else return 0 ; default : return 0 ; } }
Returns 1 if SKSV is set and sense key is NO_SENSE or NOT_READY.
Returns 1 if SKSV is set and sense key is NO_SENSE or NOT_READY .
/* SKSV bit set */ /* sense key specific progress (0x2) or progress descriptor (0xa) */