static int ioreq_parse(struct ioreq *ioreq)

{

    struct XenBlkDev *blkdev = ioreq->blkdev;

    uintptr_t mem;

    size_t len;

    int i;



    xen_be_printf(&blkdev->xendev, 3,

		  "op %d, nr %d, handle %d, id %" PRId64 ", sector %" PRId64 "\n",

		  ioreq->req.operation, ioreq->req.nr_segments,

		  ioreq->req.handle, ioreq->req.id, ioreq->req.sector_number);

    switch (ioreq->req.operation) {

    case BLKIF_OP_READ:

	ioreq->prot = PROT_WRITE; /* to memory */

        if (ioreq->req.operation != BLKIF_OP_READ && blkdev->mode[0] != 'w') {

	    xen_be_printf(&blkdev->xendev, 0, "error: write req for ro device\n");

	    goto err;

	}

	break;

    case BLKIF_OP_WRITE_BARRIER:

	if (!syncwrite)

	    ioreq->presync = ioreq->postsync = 1;

	/* fall through */

    case BLKIF_OP_WRITE:

	ioreq->prot = PROT_READ; /* from memory */

	if (syncwrite)

	    ioreq->postsync = 1;

	break;

    default:

	xen_be_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n",

		      ioreq->req.operation);

	goto err;

    };



    ioreq->start = ioreq->req.sector_number * blkdev->file_blk;

    for (i = 0; i < ioreq->req.nr_segments; i++) {

	if (i == BLKIF_MAX_SEGMENTS_PER_REQUEST) {

	    xen_be_printf(&blkdev->xendev, 0, "error: nr_segments too big\n");

	    goto err;

	}

	if (ioreq->req.seg[i].first_sect > ioreq->req.seg[i].last_sect) {

	    xen_be_printf(&blkdev->xendev, 0, "error: first > last sector\n");

	    goto err;

	}

	if (ioreq->req.seg[i].last_sect * BLOCK_SIZE >= XC_PAGE_SIZE) {

	    xen_be_printf(&blkdev->xendev, 0, "error: page crossing\n");

	    goto err;

	}



	ioreq->domids[i] = blkdev->xendev.dom;

	ioreq->refs[i]   = ioreq->req.seg[i].gref;



	mem = ioreq->req.seg[i].first_sect * blkdev->file_blk;

	len = (ioreq->req.seg[i].last_sect - ioreq->req.seg[i].first_sect + 1) * blkdev->file_blk;

        qemu_iovec_add(&ioreq->v, (void*)mem, len);

    }

    if (ioreq->start + ioreq->v.size > blkdev->file_size) {

	xen_be_printf(&blkdev->xendev, 0, "error: access beyond end of file\n");

	goto err;

    }

    return 0;



err:

    ioreq->status = BLKIF_RSP_ERROR;

    return -1;

}

static int ioreq_parse(struct ioreq *ioreq)

{

    struct XenBlkDev *blkdev = ioreq->blkdev;

    uintptr_t mem;

    size_t len;

    int i;



    xen_be_printf(&blkdev->xendev, 3,

		  "op %d, nr %d, handle %d, id %" PRId64 ", sector %" PRId64 "\n",

		  ioreq->req.operation, ioreq->req.nr_segments,

		  ioreq->req.handle, ioreq->req.id, ioreq->req.sector_number);

    switch (ioreq->req.operation) {

    case BLKIF_OP_READ:

	ioreq->prot = PROT_WRITE; 

        if (ioreq->req.operation != BLKIF_OP_READ && blkdev->mode[0] != 'w') {

	    xen_be_printf(&blkdev->xendev, 0, "error: write req for ro device\n");

	    goto err;

	}

	break;

    case BLKIF_OP_WRITE_BARRIER:

	if (!syncwrite)

	    ioreq->presync = ioreq->postsync = 1;

	

    case BLKIF_OP_WRITE:

	ioreq->prot = PROT_READ; 

	if (syncwrite)

	    ioreq->postsync = 1;

	break;

    default:

	xen_be_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n",

		      ioreq->req.operation);

	goto err;

    };



    ioreq->start = ioreq->req.sector_number * blkdev->file_blk;

    for (i = 0; i < ioreq->req.nr_segments; i++) {

	if (i == BLKIF_MAX_SEGMENTS_PER_REQUEST) {

	    xen_be_printf(&blkdev->xendev, 0, "error: nr_segments too big\n");

	    goto err;

	}

	if (ioreq->req.seg[i].first_sect > ioreq->req.seg[i].last_sect) {

	    xen_be_printf(&blkdev->xendev, 0, "error: first > last sector\n");

	    goto err;

	}

	if (ioreq->req.seg[i].last_sect * BLOCK_SIZE >= XC_PAGE_SIZE) {

	    xen_be_printf(&blkdev->xendev, 0, "error: page crossing\n");

	    goto err;

	}



	ioreq->domids[i] = blkdev->xendev.dom;

	ioreq->refs[i]   = ioreq->req.seg[i].gref;



	mem = ioreq->req.seg[i].first_sect * blkdev->file_blk;

	len = (ioreq->req.seg[i].last_sect - ioreq->req.seg[i].first_sect + 1) * blkdev->file_blk;

        qemu_iovec_add(&ioreq->v, (void*)mem, len);

    }

    if (ioreq->start + ioreq->v.size > blkdev->file_size) {

	xen_be_printf(&blkdev->xendev, 0, "error: access beyond end of file\n");

	goto err;

    }

    return 0;



err:

    ioreq->status = BLKIF_RSP_ERROR;

    return -1;

}

        if (ioreq->req.operation != BLKIF_OP_READ && blkdev->mode[0] != 'w') { 	    xen_be_printf(&blkdev->xendev, 0, "error: write req for ro device\n"); 	    goto err;
static int FUNC_0(struct VAR_0 *VAR_0)

{

    struct XenBlkDev *VAR_1 = VAR_0->VAR_1;

    uintptr_t mem;

    size_t len;

    int VAR_2;



    xen_be_printf(&VAR_1->xendev, 3,

		  "op %d, nr %d, handle %d, id %" PRId64 ", sector %" PRId64 "\n",

		  VAR_0->req.operation, VAR_0->req.nr_segments,

		  VAR_0->req.handle, VAR_0->req.id, VAR_0->req.sector_number);

    switch (VAR_0->req.operation) {

    case BLKIF_OP_READ:

	VAR_0->prot = PROT_WRITE; 

        if (VAR_0->req.operation != BLKIF_OP_READ && VAR_1->mode[0] != 'w') {

	    xen_be_printf(&VAR_1->xendev, 0, "error: write req for ro device\n");

	    goto err;

	}

	break;

    case BLKIF_OP_WRITE_BARRIER:

	if (!syncwrite)

	    VAR_0->presync = VAR_0->postsync = 1;

	

    case BLKIF_OP_WRITE:

	VAR_0->prot = PROT_READ; 

	if (syncwrite)

	    VAR_0->postsync = 1;

	break;

    default:

	xen_be_printf(&VAR_1->xendev, 0, "error: unknown operation (%d)\n",

		      VAR_0->req.operation);

	goto err;

    };



    VAR_0->start = VAR_0->req.sector_number * VAR_1->file_blk;

    for (VAR_2 = 0; VAR_2 < VAR_0->req.nr_segments; VAR_2++) {

	if (VAR_2 == BLKIF_MAX_SEGMENTS_PER_REQUEST) {

	    xen_be_printf(&VAR_1->xendev, 0, "error: nr_segments too big\n");

	    goto err;

	}

	if (VAR_0->req.seg[VAR_2].first_sect > VAR_0->req.seg[VAR_2].last_sect) {

	    xen_be_printf(&VAR_1->xendev, 0, "error: first > last sector\n");

	    goto err;

	}

	if (VAR_0->req.seg[VAR_2].last_sect * BLOCK_SIZE >= XC_PAGE_SIZE) {

	    xen_be_printf(&VAR_1->xendev, 0, "error: page crossing\n");

	    goto err;

	}



	VAR_0->domids[VAR_2] = VAR_1->xendev.dom;

	VAR_0->refs[VAR_2]   = VAR_0->req.seg[VAR_2].gref;



	mem = VAR_0->req.seg[VAR_2].first_sect * VAR_1->file_blk;

	len = (VAR_0->req.seg[VAR_2].last_sect - VAR_0->req.seg[VAR_2].first_sect + 1) * VAR_1->file_blk;

        qemu_iovec_add(&VAR_0->v, (void*)mem, len);

    }

    if (VAR_0->start + VAR_0->v.size > VAR_1->file_size) {

	xen_be_printf(&VAR_1->xendev, 0, "error: access beyond end of file\n");

	goto err;

    }

    return 0;



err:

    VAR_0->status = BLKIF_RSP_ERROR;

    return -1;

}

static int FUNC_0(struct VAR_0 *VAR_0)
{ struct XenBlkDev *VAR_1 = VAR_0->VAR_1; uintptr_t mem; size_t len; int VAR_2; xen_be_printf(&VAR_1->xendev, 3,
"op %d, nr %d, handle %d, id %" PRId64 ", sector %" PRId64 "\n",
VAR_0->req.operation, VAR_0->req.nr_segments,
VAR_0->req.handle, VAR_0->req.id, VAR_0->req.sector_number); switch (VAR_0->req.operation) { case BLKIF_OP_READ:
VAR_0->prot = PROT_WRITE; if (VAR_0->req.operation != BLKIF_OP_READ && VAR_1->mode[0] != 'w') { xen_be_printf(&VAR_1->xendev, 0, "error: write req for ro device\n"); goto err; } break; case BLKIF_OP_WRITE_BARRIER:
if (!syncwrite)
VAR_0->presync = VAR_0->postsync = 1; case BLKIF_OP_WRITE:
VAR_0->prot = PROT_READ; if (syncwrite)
VAR_0->postsync = 1; break; default:
xen_be_printf(&VAR_1->xendev, 0, "error: unknown operation (%d)\n",
VAR_0->req.operation); goto err; }; VAR_0->start = VAR_0->req.sector_number * VAR_1->file_blk; for (VAR_2 = 0; VAR_2 < VAR_0->req.nr_segments; VAR_2++) { if (VAR_2 == BLKIF_MAX_SEGMENTS_PER_REQUEST) { xen_be_printf(&VAR_1->xendev, 0, "error: nr_segments too big\n"); goto err; } if (VAR_0->req.seg[VAR_2].first_sect > VAR_0->req.seg[VAR_2].last_sect) { xen_be_printf(&VAR_1->xendev, 0, "error: first > last sector\n"); goto err; } if (VAR_0->req.seg[VAR_2].last_sect * BLOCK_SIZE >= XC_PAGE_SIZE) { xen_be_printf(&VAR_1->xendev, 0, "error: page crossing\n"); goto err; } VAR_0->domids[VAR_2] = VAR_1->xendev.dom; VAR_0->refs[VAR_2]   = VAR_0->req.seg[VAR_2].gref; mem = VAR_0->req.seg[VAR_2].first_sect * VAR_1->file_blk; len = (VAR_0->req.seg[VAR_2].last_sect - VAR_0->req.seg[VAR_2].first_sect + 1) * VAR_1->file_blk; qemu_iovec_add(&VAR_0->v, (void*)mem, len); } if (VAR_0->start + VAR_0->v.size > VAR_1->file_size) { xen_be_printf(&VAR_1->xendev, 0, "error: access beyond end of file\n"); goto err; } return 0; err:
VAR_0->status = BLKIF_RSP_ERROR; return -1; }