int scsi_build_sense(uint8_t *in_buf, int in_len,

                     uint8_t *buf, int len, bool fixed)

{

    bool fixed_in;

    SCSISense sense;

    if (!fixed && len < 8) {

        return 0;

    }



    if (in_len == 0) {

        sense.key = NO_SENSE;

        sense.asc = 0;

        sense.ascq = 0;

    } else {

        fixed_in = (in_buf[0] & 2) == 0;



        if (fixed == fixed_in) {

            memcpy(buf, in_buf, MIN(len, in_len));

            return MIN(len, in_len);

        }



        if (fixed_in) {

            sense.key = in_buf[2];

            sense.asc = in_buf[12];

            sense.ascq = in_buf[13];

        } else {

            sense.key = in_buf[1];

            sense.asc = in_buf[2];

            sense.ascq = in_buf[3];

        }

    }



    memset(buf, 0, len);

    if (fixed) {

        /* Return fixed format sense buffer */

        buf[0] = 0xf0;

        buf[2] = sense.key;

        buf[7] = 10;

        buf[12] = sense.asc;

        buf[13] = sense.ascq;

        return MIN(len, 18);

    } else {

        /* Return descriptor format sense buffer */

        buf[0] = 0x72;

        buf[1] = sense.key;

        buf[2] = sense.asc;

        buf[3] = sense.ascq;

        return 8;

    }

}

int scsi_build_sense(uint8_t *in_buf, int in_len,

                     uint8_t *buf, int len, bool fixed)

{

    bool fixed_in;

    SCSISense sense;

    if (!fixed && len < 8) {

        return 0;

    }



    if (in_len == 0) {

        sense.key = NO_SENSE;

        sense.asc = 0;

        sense.ascq = 0;

    } else {

        fixed_in = (in_buf[0] & 2) == 0;



        if (fixed == fixed_in) {

            memcpy(buf, in_buf, MIN(len, in_len));

            return MIN(len, in_len);

        }



        if (fixed_in) {

            sense.key = in_buf[2];

            sense.asc = in_buf[12];

            sense.ascq = in_buf[13];

        } else {

            sense.key = in_buf[1];

            sense.asc = in_buf[2];

            sense.ascq = in_buf[3];

        }

    }



    memset(buf, 0, len);

    if (fixed) {

        

        buf[0] = 0xf0;

        buf[2] = sense.key;

        buf[7] = 10;

        buf[12] = sense.asc;

        buf[13] = sense.ascq;

        return MIN(len, 18);

    } else {

        

        buf[0] = 0x72;

        buf[1] = sense.key;

        buf[2] = sense.asc;

        buf[3] = sense.ascq;

        return 8;

    }

}

int FUNC_0(uint8_t *VAR_0, int VAR_1,

                     uint8_t *VAR_2, int VAR_3, bool VAR_4)

{

    bool fixed_in;

    SCSISense sense;

    if (!VAR_4 && VAR_3 < 8) {

        return 0;

    }



    if (VAR_1 == 0) {

        sense.key = NO_SENSE;

        sense.asc = 0;

        sense.ascq = 0;

    } else {

        fixed_in = (VAR_0[0] & 2) == 0;



        if (VAR_4 == fixed_in) {

            memcpy(VAR_2, VAR_0, MIN(VAR_3, VAR_1));

            return MIN(VAR_3, VAR_1);

        }



        if (fixed_in) {

            sense.key = VAR_0[2];

            sense.asc = VAR_0[12];

            sense.ascq = VAR_0[13];

        } else {

            sense.key = VAR_0[1];

            sense.asc = VAR_0[2];

            sense.ascq = VAR_0[3];

        }

    }



    memset(VAR_2, 0, VAR_3);

    if (VAR_4) {

        

        VAR_2[0] = 0xf0;

        VAR_2[2] = sense.key;

        VAR_2[7] = 10;

        VAR_2[12] = sense.asc;

        VAR_2[13] = sense.ascq;

        return MIN(VAR_3, 18);

    } else {

        

        VAR_2[0] = 0x72;

        VAR_2[1] = sense.key;

        VAR_2[2] = sense.asc;

        VAR_2[3] = sense.ascq;

        return 8;

    }

}

int FUNC_0(uint8_t *VAR_0, int VAR_1,
uint8_t *VAR_2, int VAR_3, bool VAR_4)
{ bool fixed_in; SCSISense sense; if (!VAR_4 && VAR_3 < 8) { return 0; } if (VAR_1 == 0) { sense.key = NO_SENSE; sense.asc = 0; sense.ascq = 0; } else { fixed_in = (VAR_0[0] & 2) == 0; if (VAR_4 == fixed_in) { memcpy(VAR_2, VAR_0, MIN(VAR_3, VAR_1)); return MIN(VAR_3, VAR_1); } if (fixed_in) { sense.key = VAR_0[2]; sense.asc = VAR_0[12]; sense.ascq = VAR_0[13]; } else { sense.key = VAR_0[1]; sense.asc = VAR_0[2]; sense.ascq = VAR_0[3]; } } memset(VAR_2, 0, VAR_3); if (VAR_4) { VAR_2[0] = 0xf0; VAR_2[2] = sense.key; VAR_2[7] = 10; VAR_2[12] = sense.asc; VAR_2[13] = sense.ascq; return MIN(VAR_3, 18); } else { VAR_2[0] = 0x72; VAR_2[1] = sense.key; VAR_2[2] = sense.asc; VAR_2[3] = sense.ascq; return 8; } }