static bool scsi_target_emulate_report_luns(SCSITargetReq *r)

{

    BusChild *kid;

    int i, len, n;

    int channel, id;

    bool found_lun0;



    if (r->req.cmd.xfer < 16) {

        return false;

    }

    if (r->req.cmd.buf[2] > 2) {

        return false;

    }

    channel = r->req.dev->channel;

    id = r->req.dev->id;

    found_lun0 = false;

    n = 0;

    QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) {

        DeviceState *qdev = kid->child;

        SCSIDevice *dev = SCSI_DEVICE(qdev);



        if (dev->channel == channel && dev->id == id) {

            if (dev->lun == 0) {

                found_lun0 = true;

            }

            n += 8;

        }

    }

    if (!found_lun0) {

        n += 8;

    }

    len = MIN(n + 8, r->req.cmd.xfer & ~7);

    if (len > sizeof(r->buf)) {

        /* TODO: > 256 LUNs? */

        return false;

    }



    memset(r->buf, 0, len);

    stl_be_p(&r->buf, n);

    i = found_lun0 ? 8 : 16;

    QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) {

        DeviceState *qdev = kid->child;

        SCSIDevice *dev = SCSI_DEVICE(qdev);



        if (dev->channel == channel && dev->id == id) {

            store_lun(&r->buf[i], dev->lun);

            i += 8;

        }

    }

    assert(i == n + 8);

    r->len = len;

    return true;

}

static bool scsi_target_emulate_report_luns(SCSITargetReq *r)

{

    BusChild *kid;

    int i, len, n;

    int channel, id;

    bool found_lun0;



    if (r->req.cmd.xfer < 16) {

        return false;

    }

    if (r->req.cmd.buf[2] > 2) {

        return false;

    }

    channel = r->req.dev->channel;

    id = r->req.dev->id;

    found_lun0 = false;

    n = 0;

    QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) {

        DeviceState *qdev = kid->child;

        SCSIDevice *dev = SCSI_DEVICE(qdev);



        if (dev->channel == channel && dev->id == id) {

            if (dev->lun == 0) {

                found_lun0 = true;

            }

            n += 8;

        }

    }

    if (!found_lun0) {

        n += 8;

    }

    len = MIN(n + 8, r->req.cmd.xfer & ~7);

    if (len > sizeof(r->buf)) {

        

        return false;

    }



    memset(r->buf, 0, len);

    stl_be_p(&r->buf, n);

    i = found_lun0 ? 8 : 16;

    QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) {

        DeviceState *qdev = kid->child;

        SCSIDevice *dev = SCSI_DEVICE(qdev);



        if (dev->channel == channel && dev->id == id) {

            store_lun(&r->buf[i], dev->lun);

            i += 8;

        }

    }

    assert(i == n + 8);

    r->len = len;

    return true;

}

    len = MIN(n + 8, r->req.cmd.xfer & ~7);     if (len > sizeof(r->buf)) {         return false;     stl_be_p(&r->buf, n);
static bool FUNC_0(SCSITargetReq *r)

{

    BusChild *kid;

    int VAR_0, VAR_1, VAR_2;

    int VAR_3, VAR_4;

    bool found_lun0;



    if (r->req.cmd.xfer < 16) {

        return false;

    }

    if (r->req.cmd.buf[2] > 2) {

        return false;

    }

    VAR_3 = r->req.dev->VAR_3;

    VAR_4 = r->req.dev->VAR_4;

    found_lun0 = false;

    VAR_2 = 0;

    QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) {

        DeviceState *qdev = kid->child;

        SCSIDevice *dev = SCSI_DEVICE(qdev);



        if (dev->VAR_3 == VAR_3 && dev->VAR_4 == VAR_4) {

            if (dev->lun == 0) {

                found_lun0 = true;

            }

            VAR_2 += 8;

        }

    }

    if (!found_lun0) {

        VAR_2 += 8;

    }

    VAR_1 = MIN(VAR_2 + 8, r->req.cmd.xfer & ~7);

    if (VAR_1 > sizeof(r->buf)) {

        

        return false;

    }



    memset(r->buf, 0, VAR_1);

    stl_be_p(&r->buf, VAR_2);

    VAR_0 = found_lun0 ? 8 : 16;

    QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) {

        DeviceState *qdev = kid->child;

        SCSIDevice *dev = SCSI_DEVICE(qdev);



        if (dev->VAR_3 == VAR_3 && dev->VAR_4 == VAR_4) {

            store_lun(&r->buf[VAR_0], dev->lun);

            VAR_0 += 8;

        }

    }

    assert(VAR_0 == VAR_2 + 8);

    r->VAR_1 = VAR_1;

    return true;

}

static bool FUNC_0(SCSITargetReq *r)
{ BusChild *kid; int VAR_0, VAR_1, VAR_2; int VAR_3, VAR_4; bool found_lun0; if (r->req.cmd.xfer < 16) { return false; } if (r->req.cmd.buf[2] > 2) { return false; } VAR_3 = r->req.dev->VAR_3; VAR_4 = r->req.dev->VAR_4; found_lun0 = false; VAR_2 = 0; QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) { DeviceState *qdev = kid->child; SCSIDevice *dev = SCSI_DEVICE(qdev); if (dev->VAR_3 == VAR_3 && dev->VAR_4 == VAR_4) { if (dev->lun == 0) { found_lun0 = true; } VAR_2 += 8; } } if (!found_lun0) { VAR_2 += 8; } VAR_1 = MIN(VAR_2 + 8, r->req.cmd.xfer & ~7); if (VAR_1 > sizeof(r->buf)) { return false; } memset(r->buf, 0, VAR_1); stl_be_p(&r->buf, VAR_2); VAR_0 = found_lun0 ? 8 : 16; QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) { DeviceState *qdev = kid->child; SCSIDevice *dev = SCSI_DEVICE(qdev); if (dev->VAR_3 == VAR_3 && dev->VAR_4 == VAR_4) { store_lun(&r->buf[VAR_0], dev->lun); VAR_0 += 8; } } assert(VAR_0 == VAR_2 + 8); r->VAR_1 = VAR_1; return true; }