lib/sg_lib.c
const unsigned char *
sg_scsi_sense_desc_find(const unsigned char * sensep, int sense_len,
                        int desc_type)
{
    int add_sb_len, add_d_len, desc_len, k;
    const unsigned char * descp;

    if ((sense_len < 8) || (0 == (add_sb_len = sensep[7])))
        return NULL;
    if ((sensep[0] < 0x72) || (sensep[0] > 0x73))
        return NULL;
    add_sb_len = (add_sb_len < (sense_len - 8)) ?
                         add_sb_len : (sense_len - 8);
    descp = &sensep[8];
    for (desc_len = 0, k = 0; k < add_sb_len; k += desc_len) {
        descp += desc_len;
        add_d_len = (k < (add_sb_len - 1)) ? descp[1]: -1;
        desc_len = add_d_len + 2;
        if (descp[0] == desc_type)
            return descp;
        if (add_d_len < 0) /* short descriptor ?? */
            break;
    }
    return NULL;
}
/* Attempt to find the first SCSI sense data descriptor that matches the
 * given 'desc_type'. If found return pointer to start of sense data
 * descriptor; otherwise (including fixed format sense data) returns NULL. */
Attempt to find the first SCSI sense data descriptor that matches the
given 'desc_type'. If found return pointer to start of sense data
descriptor; otherwise (including fixed format sense data) returns NULL.
Attempt to find the first SCSI sense data descriptor that matches the given ' desc_type ' . If found return pointer to start of sense data descriptor ; otherwise ( including fixed format sense data ) returns NULL .
const unsigned char *
sg_scsi_sense_desc_find(const unsigned char * sensep, int sense_len,
                        int desc_type)
{
    int add_sb_len, add_d_len, desc_len, k;
    const unsigned char * descp;
    if ((sense_len < 8) || (0 == (add_sb_len = sensep[7])))
        return NULL;
    if ((sensep[0] < 0x72) || (sensep[0] > 0x73))
        return NULL;
    add_sb_len = (add_sb_len < (sense_len - 8)) ?
                         add_sb_len : (sense_len - 8);
    descp = &sensep[8];
    for (desc_len = 0, k = 0; k < add_sb_len; k += desc_len) {
        descp += desc_len;
        add_d_len = (k < (add_sb_len - 1)) ? descp[1]: -1;
        desc_len = add_d_len + 2;
        if (descp[0] == desc_type)
            return descp;
        if (add_d_len < 0) 
            break;
    }
    return NULL;
}
const unsigned char * sg_scsi_sense_desc_find ( const unsigned char * sensep , int sense_len , int desc_type ) { int add_sb_len , add_d_len , desc_len , k ; const unsigned char * descp ; if ( ( sense_len < 8 ) || ( 0 == ( add_sb_len = sensep [ 7 ] ) ) ) return NULL ; if ( ( sensep [ 0 ] < 0x72 ) || ( sensep [ 0 ] > 0x73 ) ) return NULL ; add_sb_len = ( add_sb_len < ( sense_len - 8 ) ) ? add_sb_len : ( sense_len - 8 ) ; descp = & sensep [ 8 ] ; for ( desc_len = 0 , k = 0 ; k < add_sb_len ; k += desc_len ) { descp += desc_len ; add_d_len = ( k < ( add_sb_len - 1 ) ) ? descp [ 1 ] : -1 ; desc_len = add_d_len + 2 ; if ( descp [ 0 ] == desc_type ) return descp ; if ( add_d_len < 0 ) break ; } return NULL ; }
Attempt to find the first SCSI sense data descriptor that matches the
 given 'desc_type'.
Attempt to find the first SCSI sense data descriptor that matches the given ' desc_type ' .
/* short descriptor ?? */