Deleted Added
full compact
scsi_cmds.c (225950) scsi_cmds.c (228462)
1/*
2 * SCSI Disk Emulator
3 *
4 * Copyright (c) 2002 Nate Lawson.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 11 unchanged lines hidden (view full) ---

20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
1/*
2 * SCSI Disk Emulator
3 *
4 * Copyright (c) 2002 Nate Lawson.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 11 unchanged lines hidden (view full) ---

20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD: head/share/examples/scsi_target/scsi_cmds.c 225950 2011-10-03 20:32:55Z ken $
28 * $FreeBSD: head/share/examples/scsi_target/scsi_cmds.c 228462 2011-12-13 11:13:28Z mav $
29 */
30
31#include <stdio.h>
32#include <stddef.h>
33#include <stdarg.h>
34#include <stdlib.h>
35#include <string.h>
36#include <err.h>

--- 61 unchanged lines hidden (view full) ---

98 { SERVICE_ACTION_IN, tcmd_rd_cap16, NULL },
99#endif
100 { ILLEGAL_CDB, NULL, NULL }
101};
102
103static struct scsi_inquiry_data inq_data;
104static struct initiator_state istates[MAX_INITIATORS];
105extern int debug;
29 */
30
31#include <stdio.h>
32#include <stddef.h>
33#include <stdarg.h>
34#include <stdlib.h>
35#include <string.h>
36#include <err.h>

--- 61 unchanged lines hidden (view full) ---

98 { SERVICE_ACTION_IN, tcmd_rd_cap16, NULL },
99#endif
100 { ILLEGAL_CDB, NULL, NULL }
101};
102
103static struct scsi_inquiry_data inq_data;
104static struct initiator_state istates[MAX_INITIATORS];
105extern int debug;
106extern uint64_t volume_size;
107extern size_t sector_size;
106extern off_t volume_size;
107extern u_int sector_size;
108extern size_t buf_size;
109
110cam_status
111tcmd_init(u_int16_t req_inq_flags, u_int16_t sim_inq_flags)
112{
113 struct initiator_state *istate;
114 int i, ret;
115

--- 488 unchanged lines hidden (view full) ---

604 c_descr->aiocb.aio_offset = c_descr->offset;
605 c_descr->aiocb.aio_nbytes = ctio->dxfer_len;
606
607 /* If DIR_IN, start read from target, otherwise begin CTIO xfer. */
608 ret = 1;
609 if (dir == CAM_DIR_IN) {
610 if (notaio) {
611 if (debug)
108extern size_t buf_size;
109
110cam_status
111tcmd_init(u_int16_t req_inq_flags, u_int16_t sim_inq_flags)
112{
113 struct initiator_state *istate;
114 int i, ret;
115

--- 488 unchanged lines hidden (view full) ---

604 c_descr->aiocb.aio_offset = c_descr->offset;
605 c_descr->aiocb.aio_nbytes = ctio->dxfer_len;
606
607 /* If DIR_IN, start read from target, otherwise begin CTIO xfer. */
608 ret = 1;
609 if (dir == CAM_DIR_IN) {
610 if (notaio) {
611 if (debug)
612 warnx("read sync %lud @ block " OFF_FMT,
612 warnx("read sync %lu @ block " OFF_FMT,
613 (unsigned long)
614 (ctio->dxfer_len / sector_size),
615 c_descr->offset / sector_size);
616 if (lseek(c_descr->aiocb.aio_fildes,
617 c_descr->aiocb.aio_offset, SEEK_SET) < 0) {
618 perror("lseek");
619 err(1, "lseek");
620 }
621 if (read(c_descr->aiocb.aio_fildes,
622 (void *)c_descr->aiocb.aio_buf,
623 ctio->dxfer_len) != ctio->dxfer_len) {
624 err(1, "read");
625 }
626 } else {
627 if (debug)
613 (unsigned long)
614 (ctio->dxfer_len / sector_size),
615 c_descr->offset / sector_size);
616 if (lseek(c_descr->aiocb.aio_fildes,
617 c_descr->aiocb.aio_offset, SEEK_SET) < 0) {
618 perror("lseek");
619 err(1, "lseek");
620 }
621 if (read(c_descr->aiocb.aio_fildes,
622 (void *)c_descr->aiocb.aio_buf,
623 ctio->dxfer_len) != ctio->dxfer_len) {
624 err(1, "read");
625 }
626 } else {
627 if (debug)
628 warnx("read async %lud @ block " OFF_FMT,
628 warnx("read async %lu @ block " OFF_FMT,
629 (unsigned long)
630 (ctio->dxfer_len / sector_size),
631 c_descr->offset / sector_size);
632 if (aio_read(&c_descr->aiocb) < 0) {
633 err(1, "aio_read"); /* XXX */
634 }
635 }
636 a_descr->targ_req += ctio->dxfer_len;

--- 83 unchanged lines hidden (view full) ---

720 errx(1, "CTIO failed, status %#x", ctio->ccb_h.status);
721 }
722 a_descr->init_ack += ctio->dxfer_len;
723 if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_OUT &&
724 ctio->dxfer_len > 0) {
725 a_descr->targ_req += ctio->dxfer_len;
726 if (notaio) {
727 if (debug)
629 (unsigned long)
630 (ctio->dxfer_len / sector_size),
631 c_descr->offset / sector_size);
632 if (aio_read(&c_descr->aiocb) < 0) {
633 err(1, "aio_read"); /* XXX */
634 }
635 }
636 a_descr->targ_req += ctio->dxfer_len;

--- 83 unchanged lines hidden (view full) ---

720 errx(1, "CTIO failed, status %#x", ctio->ccb_h.status);
721 }
722 a_descr->init_ack += ctio->dxfer_len;
723 if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_OUT &&
724 ctio->dxfer_len > 0) {
725 a_descr->targ_req += ctio->dxfer_len;
726 if (notaio) {
727 if (debug)
728 warnx("write sync %lud @ block "
728 warnx("write sync %lu @ block "
729 OFF_FMT, (unsigned long)
730 (ctio->dxfer_len / sector_size),
731 c_descr->offset / sector_size);
732 if (lseek(c_descr->aiocb.aio_fildes,
733 c_descr->aiocb.aio_offset, SEEK_SET) < 0) {
734 perror("lseek");
735 err(1, "lseek");
736 }
737 if (write(c_descr->aiocb.aio_fildes,
738 (void *) c_descr->aiocb.aio_buf,
739 ctio->dxfer_len) != ctio->dxfer_len) {
740 err(1, "write");
741 }
742 tcmd_rdwr_done(atio, ctio, AIO_DONE);
743 } else {
744 if (debug)
729 OFF_FMT, (unsigned long)
730 (ctio->dxfer_len / sector_size),
731 c_descr->offset / sector_size);
732 if (lseek(c_descr->aiocb.aio_fildes,
733 c_descr->aiocb.aio_offset, SEEK_SET) < 0) {
734 perror("lseek");
735 err(1, "lseek");
736 }
737 if (write(c_descr->aiocb.aio_fildes,
738 (void *) c_descr->aiocb.aio_buf,
739 ctio->dxfer_len) != ctio->dxfer_len) {
740 err(1, "write");
741 }
742 tcmd_rdwr_done(atio, ctio, AIO_DONE);
743 } else {
744 if (debug)
745 warnx("write async %lud @ block "
745 warnx("write async %lu @ block "
746 OFF_FMT, (unsigned long)
747 (ctio->dxfer_len / sector_size),
748 c_descr->offset / sector_size);
749 if (aio_write(&c_descr->aiocb) < 0) {
750 err(1, "aio_write"); /* XXX */
751 }
752 }
753 } else {

--- 60 unchanged lines hidden ---
746 OFF_FMT, (unsigned long)
747 (ctio->dxfer_len / sector_size),
748 c_descr->offset / sector_size);
749 if (aio_write(&c_descr->aiocb) < 0) {
750 err(1, "aio_write"); /* XXX */
751 }
752 }
753 } else {

--- 60 unchanged lines hidden ---