static int execute_command(BlockDriverState *bdrv,

                           SCSIRequest *r, int direction,

			   BlockDriverCompletionFunc *complete)

{



    r->io_header.interface_id = 'S';

    r->io_header.dxfer_direction = direction;

    r->io_header.dxferp = r->buf;

    r->io_header.dxfer_len = r->buflen;

    r->io_header.cmdp = r->cmd;

    r->io_header.cmd_len = r->cmdlen;

    r->io_header.mx_sb_len = sizeof(r->dev->sensebuf);

    r->io_header.sbp = r->dev->sensebuf;

    r->io_header.timeout = MAX_UINT;

    r->io_header.usr_ptr = r;

    r->io_header.flags |= SG_FLAG_DIRECT_IO;



    if (bdrv_pwrite(bdrv, -1, &r->io_header, sizeof(r->io_header)) == -1) {

        BADF("execute_command: write failed ! (%d)\n", errno);

        return -1;

    }

    if (complete == NULL) {

        int ret;

        r->aiocb = NULL;

        while ((ret = bdrv_pread(bdrv, -1, &r->io_header,

                                           sizeof(r->io_header))) == -1 &&

                      errno == EINTR);

        if (ret == -1) {

            BADF("execute_command: read failed !\n");

            return -1;

        }

        return 0;

    }



    r->aiocb = bdrv_aio_read(bdrv, 0, (uint8_t*)&r->io_header,

                          -(int64_t)sizeof(r->io_header), complete, r);

    if (r->aiocb == NULL) {

        BADF("execute_command: read failed !\n");

        return -1;

    }



    return 0;

}

static int execute_command(BlockDriverState *bdrv,

                           SCSIRequest *r, int direction,

			   BlockDriverCompletionFunc *complete)

{



    r->io_header.interface_id = 'S';

    r->io_header.dxfer_direction = direction;

    r->io_header.dxferp = r->buf;

    r->io_header.dxfer_len = r->buflen;

    r->io_header.cmdp = r->cmd;

    r->io_header.cmd_len = r->cmdlen;

    r->io_header.mx_sb_len = sizeof(r->dev->sensebuf);

    r->io_header.sbp = r->dev->sensebuf;

    r->io_header.timeout = MAX_UINT;

    r->io_header.usr_ptr = r;

    r->io_header.flags |= SG_FLAG_DIRECT_IO;



    if (bdrv_pwrite(bdrv, -1, &r->io_header, sizeof(r->io_header)) == -1) {

        BADF("execute_command: write failed ! (%d)\n", errno);

        return -1;

    }

    if (complete == NULL) {

        int ret;

        r->aiocb = NULL;

        while ((ret = bdrv_pread(bdrv, -1, &r->io_header,

                                           sizeof(r->io_header))) == -1 &&

                      errno == EINTR);

        if (ret == -1) {

            BADF("execute_command: read failed !\n");

            return -1;

        }

        return 0;

    }



    r->aiocb = bdrv_aio_read(bdrv, 0, (uint8_t*)&r->io_header,

                          -(int64_t)sizeof(r->io_header), complete, r);

    if (r->aiocb == NULL) {

        BADF("execute_command: read failed !\n");

        return -1;

    }



    return 0;

}

static int FUNC_0(BlockDriverState *VAR_0,

                           SCSIRequest *VAR_1, int VAR_2,

			   BlockDriverCompletionFunc *VAR_3)

{



    VAR_1->io_header.interface_id = 'S';

    VAR_1->io_header.dxfer_direction = VAR_2;

    VAR_1->io_header.dxferp = VAR_1->buf;

    VAR_1->io_header.dxfer_len = VAR_1->buflen;

    VAR_1->io_header.cmdp = VAR_1->cmd;

    VAR_1->io_header.cmd_len = VAR_1->cmdlen;

    VAR_1->io_header.mx_sb_len = sizeof(VAR_1->dev->sensebuf);

    VAR_1->io_header.sbp = VAR_1->dev->sensebuf;

    VAR_1->io_header.timeout = MAX_UINT;

    VAR_1->io_header.usr_ptr = VAR_1;

    VAR_1->io_header.flags |= SG_FLAG_DIRECT_IO;



    if (bdrv_pwrite(VAR_0, -1, &VAR_1->io_header, sizeof(VAR_1->io_header)) == -1) {

        BADF("FUNC_0: write failed ! (%d)\n", errno);

        return -1;

    }

    if (VAR_3 == NULL) {

        int VAR_4;

        VAR_1->aiocb = NULL;

        while ((VAR_4 = bdrv_pread(VAR_0, -1, &VAR_1->io_header,

                                           sizeof(VAR_1->io_header))) == -1 &&

                      errno == EINTR);

        if (VAR_4 == -1) {

            BADF("FUNC_0: read failed !\n");

            return -1;

        }

        return 0;

    }



    VAR_1->aiocb = bdrv_aio_read(VAR_0, 0, (uint8_t*)&VAR_1->io_header,

                          -(int64_t)sizeof(VAR_1->io_header), VAR_3, VAR_1);

    if (VAR_1->aiocb == NULL) {

        BADF("FUNC_0: read failed !\n");

        return -1;

    }



    return 0;

}

static int FUNC_0(BlockDriverState *VAR_0,
SCSIRequest *VAR_1, int VAR_2,
BlockDriverCompletionFunc *VAR_3)
{ VAR_1->io_header.interface_id = 'S'; VAR_1->io_header.dxfer_direction = VAR_2; VAR_1->io_header.dxferp = VAR_1->buf; VAR_1->io_header.dxfer_len = VAR_1->buflen; VAR_1->io_header.cmdp = VAR_1->cmd; VAR_1->io_header.cmd_len = VAR_1->cmdlen; VAR_1->io_header.mx_sb_len = sizeof(VAR_1->dev->sensebuf); VAR_1->io_header.sbp = VAR_1->dev->sensebuf; VAR_1->io_header.timeout = MAX_UINT; VAR_1->io_header.usr_ptr = VAR_1; VAR_1->io_header.flags |= SG_FLAG_DIRECT_IO; if (bdrv_pwrite(VAR_0, -1, &VAR_1->io_header, sizeof(VAR_1->io_header)) == -1) { BADF("FUNC_0: write failed ! (%d)\n", errno); return -1; } if (VAR_3 == NULL) { int VAR_4; VAR_1->aiocb = NULL; while ((VAR_4 = bdrv_pread(VAR_0, -1, &VAR_1->io_header,
sizeof(VAR_1->io_header))) == -1 &&
errno == EINTR); if (VAR_4 == -1) { BADF("FUNC_0: read failed !\n"); return -1; } return 0; } VAR_1->aiocb = bdrv_aio_read(VAR_0, 0, (uint8_t*)&VAR_1->io_header,
-(int64_t)sizeof(VAR_1->io_header), VAR_3, VAR_1); if (VAR_1->aiocb == NULL) { BADF("FUNC_0: read failed !\n"); return -1; } return 0; }