Deleted Added
full compact
scsi_target.c (120428) scsi_target.c (121184)
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_target.c 120428 2003-09-25 05:43:26Z simokawa $
28 * $FreeBSD: head/share/examples/scsi_target/scsi_target.c 121184 2003-10-18 04:54:08Z simokawa $
29 */
30
31#include <sys/types.h>
29 */
30
31#include <sys/types.h>
32#include <ctype.h>
32#include <errno.h>
33#include <err.h>
34#include <fcntl.h>
35#include <signal.h>
36#include <stddef.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>

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

56#define MAX_XFER MAXPHYS
57/* Maximum number of allocated CTIOs */
58#define MAX_CTIOS 32
59/* Maximum sector size for emulated volume */
60#define MAX_SECTOR 32768
61
62/* Global variables */
63int debug;
33#include <errno.h>
34#include <err.h>
35#include <fcntl.h>
36#include <signal.h>
37#include <stddef.h>
38#include <stdio.h>
39#include <stdlib.h>
40#include <string.h>

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

57#define MAX_XFER MAXPHYS
58/* Maximum number of allocated CTIOs */
59#define MAX_CTIOS 32
60/* Maximum sector size for emulated volume */
61#define MAX_SECTOR 32768
62
63/* Global variables */
64int debug;
64u_int32_t volume_size;
65size_t sector_size;
65off_t volume_size;
66u_int sector_size;
66size_t buf_size;
67
68/* Local variables */
69static int targ_fd;
70static int kq_fd;
71static int file_fd;
72static int num_ctios;
73static struct ccb_queue pending_queue;

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

136 errx(1, "Unreasonable buf size: %s", optarg);
137 break;
138 case 'c':
139 sector_size = atoi(optarg);
140 if (sector_size < 512 || sector_size > MAX_SECTOR)
141 errx(1, "Unreasonable sector size: %s", optarg);
142 break;
143 case 's':
67size_t buf_size;
68
69/* Local variables */
70static int targ_fd;
71static int kq_fd;
72static int file_fd;
73static int num_ctios;
74static struct ccb_queue pending_queue;

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

137 errx(1, "Unreasonable buf size: %s", optarg);
138 break;
139 case 'c':
140 sector_size = atoi(optarg);
141 if (sector_size < 512 || sector_size > MAX_SECTOR)
142 errx(1, "Unreasonable sector size: %s", optarg);
143 break;
144 case 's':
145 {
146 int last, shift = 0;
147
148 last = strlen(optarg) - 1;
149 if (last > 0) {
150 switch (tolower(optarg[last])) {
151 case 'e':
152 shift += 10;
153 /* FALLTHROUGH */
154 case 'p':
155 shift += 10;
156 /* FALLTHROUGH */
157 case 't':
158 shift += 10;
159 /* FALLTHROUGH */
160 case 'g':
161 shift += 10;
162 /* FALLTHROUGH */
163 case 'm':
164 shift += 10;
165 /* FALLTHROUGH */
166 case 'k':
167 shift += 10;
168 optarg[last] = 0;
169 break;
170 }
171 }
144 user_size = strtoll(optarg, (char **)NULL, /*base*/10);
172 user_size = strtoll(optarg, (char **)NULL, /*base*/10);
173 user_size <<= shift;
145 if (user_size < 0)
146 errx(1, "Unreasonable volume size: %s", optarg);
147 break;
174 if (user_size < 0)
175 errx(1, "Unreasonable volume size: %s", optarg);
176 break;
177 }
148 case 'W':
149 req_flags &= ~(SID_WBus16 | SID_WBus32);
150 switch (atoi(optarg)) {
151 case 8:
152 /* Leave req_flags zeroed */
153 break;
154 case 16:
155 req_flags |= SID_WBus16;

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

210 /* XXX get sector size by ioctl()?? */
211 volume_size = mediasize / sector_size;
212 } else
213#endif
214 volume_size = st.st_size / sector_size;
215 } else {
216 volume_size = user_size / sector_size;
217 }
178 case 'W':
179 req_flags &= ~(SID_WBus16 | SID_WBus32);
180 switch (atoi(optarg)) {
181 case 8:
182 /* Leave req_flags zeroed */
183 break;
184 case 16:
185 req_flags |= SID_WBus16;

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

240 /* XXX get sector size by ioctl()?? */
241 volume_size = mediasize / sector_size;
242 } else
243#endif
244 volume_size = st.st_size / sector_size;
245 } else {
246 volume_size = user_size / sector_size;
247 }
248 if (debug)
249#if __FreeBSD_version >= 500000
250 warnx("volume_size: %d bytes x %jd sectors",
251#else
252 warnx("volume_size: %d bytes x %lld sectors",
253#endif
254 sector_size, volume_size);
255
218 if (volume_size <= 0)
219 errx(1, "volume must be larger than %d", sector_size);
220
221 {
222 struct aiocb aio, *aiop;
223
224 /* Make sure we have working AIO support */
225 memset(&aio, 0, sizeof(aio));

--- 731 unchanged lines hidden ---
256 if (volume_size <= 0)
257 errx(1, "volume must be larger than %d", sector_size);
258
259 {
260 struct aiocb aio, *aiop;
261
262 /* Make sure we have working AIO support */
263 memset(&aio, 0, sizeof(aio));

--- 731 unchanged lines hidden ---