lib/sg_lib.c
int
sg_vpd_dev_id_iter(const unsigned char * initial_desig_desc, int page_len,
                   int * off, int m_assoc, int m_desig_type, int m_code_set)
{
    const unsigned char * ucp;
    int k, c_set, assoc, desig_type;

    for (k = *off, ucp = initial_desig_desc ; (k + 3) < page_len; ) {
        k = (k < 0) ? 0 : (k + ucp[k + 3] + 4);
        if ((k + 4) > page_len)
            break;
        c_set = (ucp[k] & 0xf);
        if ((m_code_set >= 0) && (m_code_set != c_set))
            continue;
        assoc = ((ucp[k + 1] >> 4) & 0x3);
        if ((m_assoc >= 0) && (m_assoc != assoc))
            continue;
        desig_type = (ucp[k + 1] & 0xf);
        if ((m_desig_type >= 0) && (m_desig_type != desig_type))
            continue;
        *off = k;
        return 0;
    }
    return (k == page_len) ? -1 : -2;
}
/* Iterates to next designation descriptor in the device identification
 * VPD page. The 'initial_desig_desc' should point to start of first
 * descriptor with 'page_len' being the number of valid bytes in that
 * and following descriptors. To start, 'off' should point to a negative
 * value, thereafter it should point to the value yielded by the previous
 * call. If 0 returned then 'initial_desig_desc + *off' should be a valid
 * descriptor; returns -1 if normal end condition and -2 for an abnormal
 * termination. Matches association, designator_type and/or code_set when
 * any of those values are greater than or equal to zero. */
Iterates to next designation descriptor in the device identification
VPD page. The 'initial_desig_desc' should point to start of first
descriptor with 'page_len' being the number of valid bytes in that
and following descriptors. To start, 'off' should point to a negative
value, thereafter it should point to the value yielded by the previous
call. If 0 returned then 'initial_desig_desc + *off' should be a valid
descriptor; returns -1 if normal end condition and -2 for an abnormal
termination. Matches association, designator_type and/or code_set when
any of those values are greater than or equal to zero.
Iterates to next designation descriptor in the device identification VPD page . The ' initial_desig_desc ' should point to start of first descriptor with ' page_len ' being the number of valid bytes in that and following descriptors . To start ' off ' should point to a negative value thereafter it should point to the value yielded by the previous call . If 0 returned then ' initial_desig_desc + * off ' should be a valid descriptor ; returns - 1 if normal end condition and - 2 for an abnormal termination . Matches association designator_type and / or code_set when any of those values are greater than or equal to zero .
int
sg_vpd_dev_id_iter(const unsigned char * initial_desig_desc, int page_len,
                   int * off, int m_assoc, int m_desig_type, int m_code_set)
{
    const unsigned char * ucp;
    int k, c_set, assoc, desig_type;
    for (k = *off, ucp = initial_desig_desc ; (k + 3) < page_len; ) {
        k = (k < 0) ? 0 : (k + ucp[k + 3] + 4);
        if ((k + 4) > page_len)
            break;
        c_set = (ucp[k] & 0xf);
        if ((m_code_set >= 0) && (m_code_set != c_set))
            continue;
        assoc = ((ucp[k + 1] >> 4) & 0x3);
        if ((m_assoc >= 0) && (m_assoc != assoc))
            continue;
        desig_type = (ucp[k + 1] & 0xf);
        if ((m_desig_type >= 0) && (m_desig_type != desig_type))
            continue;
        *off = k;
        return 0;
    }
    return (k == page_len) ? -1 : -2;
}
int sg_vpd_dev_id_iter ( const unsigned char * initial_desig_desc , int page_len , int * off , int m_assoc , int m_desig_type , int m_code_set ) { const unsigned char * ucp ; int k , c_set , assoc , desig_type ; for ( k = * off , ucp = initial_desig_desc ; ( k + 3 ) < page_len ; ) { k = ( k < 0 ) ? 0 : ( k + ucp [ k + 3 ] + 4 ) ; if ( ( k + 4 ) > page_len ) break ; c_set = ( ucp [ k ] & 0xf ) ; if ( ( m_code_set >= 0 ) && ( m_code_set != c_set ) ) continue ; assoc = ( ( ucp [ k + 1 ] >> 4 ) & 0x3 ) ; if ( ( m_assoc >= 0 ) && ( m_assoc != assoc ) ) continue ; desig_type = ( ucp [ k + 1 ] & 0xf ) ; if ( ( m_desig_type >= 0 ) && ( m_desig_type != desig_type ) ) continue ; * off = k ; return 0 ; } return ( k == page_len ) ? -1 : -2 ; }
Iterates to next designation descriptor in the device identification
 VPD page.
Iterates to next designation descriptor in the device identification VPD page .