lib/sg_lib.c
int
sg_scsi_normalize_sense(const unsigned char * sensep, int sb_len,
                        struct sg_scsi_sense_hdr * sshp)
{
    if (sshp)
        memset(sshp, 0, sizeof(struct sg_scsi_sense_hdr));
    if ((NULL == sensep) || (0 == sb_len) || (0x70 != (0x70 & sensep[0])))
        return 0;
    if (sshp) {
        sshp->response_code = (0x7f & sensep[0]);
        if (sshp->response_code >= 0x72) {  /* descriptor format */
            if (sb_len > 1)
                sshp->sense_key = (0xf & sensep[1]);
            if (sb_len > 2)
                sshp->asc = sensep[2];
            if (sb_len > 3)
                sshp->ascq = sensep[3];
            if (sb_len > 7)
                sshp->additional_length = sensep[7];
        } else {                              /* fixed format */
            if (sb_len > 2)
                sshp->sense_key = (0xf & sensep[2]);
            if (sb_len > 7) {
                sb_len = (sb_len < (sensep[7] + 8)) ? sb_len :
                                                      (sensep[7] + 8);
                if (sb_len > 12)
                    sshp->asc = sensep[12];
                if (sb_len > 13)
                    sshp->ascq = sensep[13];
            }
        }
    }
    return 1;
}
/* See description in sg_lib.h header file */
See description in sg_lib.h header file
See description in sg_lib . h header file
int
sg_scsi_normalize_sense(const unsigned char * sensep, int sb_len,
                        struct sg_scsi_sense_hdr * sshp)
{
    if (sshp)
        memset(sshp, 0, sizeof(struct sg_scsi_sense_hdr));
    if ((NULL == sensep) || (0 == sb_len) || (0x70 != (0x70 & sensep[0])))
        return 0;
    if (sshp) {
        sshp->response_code = (0x7f & sensep[0]);
        if (sshp->response_code >= 0x72) {  
            if (sb_len > 1)
                sshp->sense_key = (0xf & sensep[1]);
            if (sb_len > 2)
                sshp->asc = sensep[2];
            if (sb_len > 3)
                sshp->ascq = sensep[3];
            if (sb_len > 7)
                sshp->additional_length = sensep[7];
        } else {                              
            if (sb_len > 2)
                sshp->sense_key = (0xf & sensep[2]);
            if (sb_len > 7) {
                sb_len = (sb_len < (sensep[7] + 8)) ? sb_len :
                                                      (sensep[7] + 8);
                if (sb_len > 12)
                    sshp->asc = sensep[12];
                if (sb_len > 13)
                    sshp->ascq = sensep[13];
            }
        }
    }
    return 1;
}
int sg_scsi_normalize_sense ( const unsigned char * sensep , int sb_len , struct sg_scsi_sense_hdr * sshp ) { if ( sshp ) memset ( sshp , 0 , sizeof ( struct sg_scsi_sense_hdr ) ) ; if ( ( NULL == sensep ) || ( 0 == sb_len ) || ( 0x70 != ( 0x70 & sensep [ 0 ] ) ) ) return 0 ; if ( sshp ) { sshp -> response_code = ( 0x7f & sensep [ 0 ] ) ; if ( sshp -> response_code >= 0x72 ) { if ( sb_len > 1 ) sshp -> sense_key = ( 0xf & sensep [ 1 ] ) ; if ( sb_len > 2 ) sshp -> asc = sensep [ 2 ] ; if ( sb_len > 3 ) sshp -> ascq = sensep [ 3 ] ; if ( sb_len > 7 ) sshp -> additional_length = sensep [ 7 ] ; } else { if ( sb_len > 2 ) sshp -> sense_key = ( 0xf & sensep [ 2 ] ) ; if ( sb_len > 7 ) { sb_len = ( sb_len < ( sensep [ 7 ] + 8 ) ) ? sb_len : ( sensep [ 7 ] + 8 ) ; if ( sb_len > 12 ) sshp -> asc = sensep [ 12 ] ; if ( sb_len > 13 ) sshp -> ascq = sensep [ 13 ] ; } } } return 1 ; }
See description in sg_lib.h header file
See description in sg_lib . h header file
/* descriptor format */ /* fixed format */