lib/sg_lib.c
char *
sg_get_asc_ascq_str(int asc, int ascq, int buff_len, char * buff)
{
    int k, num, rlen;
    int found = 0;
    struct sg_lib_asc_ascq_t * eip;
    struct sg_lib_asc_ascq_range_t * ei2p;

    if (1 == buff_len) {
        buff[0] = '\0';
        return buff;
    }
    for (k = 0; sg_lib_asc_ascq_range[k].text; ++k) {
        ei2p = &sg_lib_asc_ascq_range[k];
        if ((ei2p->asc == asc) &&
            (ascq >= ei2p->ascq_min)  &&
            (ascq <= ei2p->ascq_max)) {
            found = 1;
            num = my_snprintf(buff, buff_len, "Additional sense: ");
            rlen = buff_len - num;
            num += my_snprintf(buff + num, ((rlen > 0) ? rlen : 0),
                               ei2p->text, ascq);
        }
    }
    if (found)
        return buff;

    for (k = 0; sg_lib_asc_ascq[k].text; ++k) {
        eip = &sg_lib_asc_ascq[k];
        if (eip->asc == asc &&
            eip->ascq == ascq) {
            found = 1;
            my_snprintf(buff, buff_len, "Additional sense: %s", eip->text);
        }
    }
    if (! found) {
        if (asc >= 0x80)
            my_snprintf(buff, buff_len, "vendor specific ASC=%02x, "
                        "ASCQ=%02x (hex)", asc, ascq);
        else if (ascq >= 0x80)
            my_snprintf(buff, buff_len, "ASC=%02x, vendor specific "
                        "qualification ASCQ=%02x (hex)", asc, ascq);
        else
            my_snprintf(buff, buff_len, "ASC=%02x, ASCQ=%02x (hex)", asc,
                        ascq);
    }
    return buff;
}
/* Yield string associated with ASC/ASCQ values. Returns 'buff'. */
Yield string associated with ASC/ASCQ values. Returns 'buff'.
Yield string associated with ASC / ASCQ values . Returns ' buff ' .
char *
sg_get_asc_ascq_str(int asc, int ascq, int buff_len, char * buff)
{
    int k, num, rlen;
    int found = 0;
    struct sg_lib_asc_ascq_t * eip;
    struct sg_lib_asc_ascq_range_t * ei2p;
    if (1 == buff_len) {
        buff[0] = '\0';
        return buff;
    }
    for (k = 0; sg_lib_asc_ascq_range[k].text; ++k) {
        ei2p = &sg_lib_asc_ascq_range[k];
        if ((ei2p->asc == asc) &&
            (ascq >= ei2p->ascq_min)  &&
            (ascq <= ei2p->ascq_max)) {
            found = 1;
            num = my_snprintf(buff, buff_len, "Additional sense: ");
            rlen = buff_len - num;
            num += my_snprintf(buff + num, ((rlen > 0) ? rlen : 0),
                               ei2p->text, ascq);
        }
    }
    if (found)
        return buff;
    for (k = 0; sg_lib_asc_ascq[k].text; ++k) {
        eip = &sg_lib_asc_ascq[k];
        if (eip->asc == asc &&
            eip->ascq == ascq) {
            found = 1;
            my_snprintf(buff, buff_len, "Additional sense: %s", eip->text);
        }
    }
    if (! found) {
        if (asc >= 0x80)
            my_snprintf(buff, buff_len, "vendor specific ASC=%02x, "
                        "ASCQ=%02x (hex)", asc, ascq);
        else if (ascq >= 0x80)
            my_snprintf(buff, buff_len, "ASC=%02x, vendor specific "
                        "qualification ASCQ=%02x (hex)", asc, ascq);
        else
            my_snprintf(buff, buff_len, "ASC=%02x, ASCQ=%02x (hex)", asc,
                        ascq);
    }
    return buff;
}
char * sg_get_asc_ascq_str ( int asc , int ascq , int buff_len , char * buff ) { int k , num , rlen ; int found = 0 ; struct sg_lib_asc_ascq_t * eip ; struct sg_lib_asc_ascq_range_t * ei2p ; if ( 1 == buff_len ) { buff [ 0 ] = ' \0 ' ; return buff ; } for ( k = 0 ; sg_lib_asc_ascq_range [ k ] . text ; ++ k ) { ei2p = & sg_lib_asc_ascq_range [ k ] ; if ( ( ei2p -> asc == asc ) && ( ascq >= ei2p -> ascq_min ) && ( ascq <= ei2p -> ascq_max ) ) { found = 1 ; num = my_snprintf ( buff , buff_len , " " ) ; rlen = buff_len - num ; num += my_snprintf ( buff + num , ( ( rlen > 0 ) ? rlen : 0 ) , ei2p -> text , ascq ) ; } } if ( found ) return buff ; for ( k = 0 ; sg_lib_asc_ascq [ k ] . text ; ++ k ) { eip = & sg_lib_asc_ascq [ k ] ; if ( eip -> asc == asc && eip -> ascq == ascq ) { found = 1 ; my_snprintf ( buff , buff_len , " " , eip -> text ) ; } } if ( ! found ) { if ( asc >= 0x80 ) my_snprintf ( buff , buff_len , " " " " , asc , ascq ) ; else if ( ascq >= 0x80 ) my_snprintf ( buff , buff_len , " " " " , asc , ascq ) ; else my_snprintf ( buff , buff_len , " " , asc , ascq ) ; } return buff ; }
Yield string associated with ASC/ASCQ values.
Yield string associated with ASC / ASCQ values .