1 /* @(#)scsihack.c 1.60 13/07/30 Copyright 1997,2000-2013 J. Schilling */
2 #ifndef lint
3 static char _sccsid[] =
4 "@(#)scsihack.c 1.60 13/07/30 Copyright 1997,2000-2013 J. Schilling";
5 #endif
6 /*
7 * Interface for other generic SCSI implementations.
8 * Emulate the functionality of /dev/scg? with the local
9 * SCSI user land implementation.
10 *
11 * To add a new hack, add something like:
12 *
13 * #ifdef __FreeBSD__
14 * #define SCSI_IMPL
15 * #include some code
16 * #endif
17 *
18 * Warning: you may change this source or add new SCSI tranport
19 * implementations, but if you do that you need to change the
20 * _scg_version and _scg_auth* string that are returned by the
21 * SCSI transport code.
22 * Choose your name instead of "schily" and make clear that the version
23 * string is related to a modified source.
24 * If your version has been integrated into the main steam release,
25 * the return value will be set to "schily".
26 *
27 * Copyright (c) 1997,2000-2013 J. Schilling
28 */
29 /*
30 * The contents of this file are subject to the terms of the
31 * Common Development and Distribution License, Version 1.0 only
32 * (the "License"). You may not use this file except in compliance
33 * with the License.
34 *
35 * See the file CDDL.Schily.txt in this distribution for details.
36 * A copy of the CDDL is also available via the Internet at
37 * http://www.opensource.org/licenses/cddl1.txt
38 *
39 * The following exceptions apply:
40 * CDDL �3.6 needs to be replaced by: "You may create a Larger Work by
41 * combining Covered Software with other code if all other code is governed by
42 * the terms of a license that is OSI approved (see www.opensource.org) and
43 * you may distribute the Larger Work as a single product. In such a case,
44 * You must make sure the requirements of this License are fulfilled for
45 * the Covered Software."
46 *
47 * When distributing Covered Code, include this CDDL HEADER in each
48 * file and include the License file CDDL.Schily.txt from this distribution.
49 */
50
51 #include <schily/mconfig.h>
52
53 #include <schily/param.h> /* Include various defs needed with some OS */
54 #include <schily/stdio.h>
55 #include <schily/standard.h>
56 #include <schily/stdlib.h>
57 #include <schily/unistd.h>
58 #include <schily/errno.h>
59 #include <schily/time.h>
60 #include <schily/ioctl.h>
61 #include <schily/fcntl.h>
62 #include <schily/string.h>
63 #include <schily/schily.h>
64
65 #include <scg/scgcmd.h>
66 #include <scg/scsitransp.h>
67 #include "scgtimes.h"
68
69 LOCAL int scgo_send __PR((SCSI *scgp));
70 LOCAL char * scgo_version __PR((SCSI *scgp, int what));
71 LOCAL int scgo_help __PR((SCSI *scgp, FILE *f));
72 LOCAL int scgo_open __PR((SCSI *scgp, char *device));
73 LOCAL int scgo_close __PR((SCSI *scgp));
74 LOCAL long scgo_maxdma __PR((SCSI *scgp, long amt));
75 LOCAL void * scgo_getbuf __PR((SCSI *scgp, long amt));
76 LOCAL void scgo_freebuf __PR((SCSI *scgp));
77
78 LOCAL int scgo_numbus __PR((SCSI *scgp));
79 LOCAL BOOL scgo_havebus __PR((SCSI *scgp, int busno));
80 LOCAL int scgo_fileno __PR((SCSI *scgp, int busno, int tgt, int tlun));
81 LOCAL int scgo_initiator_id __PR((SCSI *scgp));
82 LOCAL int scgo_isatapi __PR((SCSI *scgp));
83 LOCAL int scgo_reset __PR((SCSI *scgp, int what));
84
85 LOCAL char _scg_auth_schily[] = "schily"; /* The author for this module */
86
87 EXPORT scg_ops_t scg_std_ops = {
88 scgo_send,
89 scgo_version,
90 scgo_help,
91 scgo_open,
92 scgo_close,
93 scgo_maxdma,
94 scgo_getbuf,
95 scgo_freebuf,
96 scgo_numbus,
97 scgo_havebus,
98 scgo_fileno,
99 scgo_initiator_id,
100 scgo_isatapi,
101 scgo_reset,
102 };
103
104 #ifndef NO_SCSI_IMPL
105
106 /*#undef sun*/
107 /*#undef __sun*/
108 /*#undef __sun__*/
109
110 #if defined(sun) || defined(__sun) || defined(__sun__)
111 #define SCSI_IMPL /* We have a SCSI implementation for Sun */
112
113 #include "scsi-sun.c"
114
115 #endif /* Sun */
116
117
118 #ifdef linux
119 #define SCSI_IMPL /* We have a SCSI implementation for Linux */
120
121 #ifdef not_needed /* We now have a local vrersion of pg.h */
122 #ifndef HAVE_LINUX_PG_H /* If we are compiling on an old version */
123 # undef USE_PG_ONLY /* there is no 'pg' driver and we cannot */
124 # undef USE_PG /* include <linux/pg.h> which is needed */
125 #endif /* by the pg transport code. */
126 #endif
127
128 #ifdef USE_PG_ONLY
129 #include "scsi-linux-pg.c"
130 #else
131 #if (defined(HAVE_SCSI_SCSI_H) || defined(HAVE_LINUX_SCSI_H)) && \
132 (defined(HAVE_SCSI_SG_H) || defined(HAVE_LINUX_SG_H))
133 #include "scsi-linux-sg.c"
134 #else
135 #undef SCSI_IMPL /* We have no SCSI for this Linux variant */
136 #endif
137 #endif
138
139 #endif /* linux */
140
141 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
142 defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
143 #define SCSI_IMPL /* We have a SCSI implementation for *BSD */
144
145 #include "scsi-bsd.c"
146
147 #endif /* *BSD */
148
149 #if defined(__bsdi__) /* We have a SCSI implementation for BSD/OS 3.x (and later?) */
150 # if (_BSDI_VERSION >= 199701) /* From sys/param.h included via schily/param.h */
151 # define SCSI_IMPL
152
153 # include "scsi-bsd-os.c"
154
155 # endif /* BSD/OS >= 3.0 */
156 #endif /* BSD/OS */
157
158 #ifdef __sgi
159 #define SCSI_IMPL /* We have a SCSI implementation for SGI */
160
161 #include "scsi-sgi.c"
162
163 #endif /* SGI */
164
165 #ifdef __hpux
166 #define SCSI_IMPL /* We have a SCSI implementation for HP-UX */
167
168 #include "scsi-hpux.c"
169
170 #endif /* HP-UX */
171
172 #if defined(_IBMR2) || defined(_AIX)
173 #define SCSI_IMPL /* We have a SCSI implementation for AIX */
174
175 #include "scsi-aix.c"
176
177 #endif /* AIX */
178
179 #if defined(__NeXT__) || defined(IS_MACOS_X)
180 #if defined(HAVE_BSD_DEV_SCSIREG_H)
181 /*
182 * This is the
183 */
184 #define SCSI_IMPL /* We found a SCSI implementation for NextStep and Mac OS X */
185
186 #include "scsi-next.c"
187 #else
188
189 #define SCSI_IMPL /* We found a SCSI implementation for Mac OS X (Darwin-1.4) */
190
191 #include "scsi-mac-iokit.c"
192
193 #endif /* HAVE_BSD_DEV_SCSIREG_H */
194
195 #endif /* NEXT / Mac OS X */
196
197 #if defined(__osf__)
198 #define SCSI_IMPL /* We have a SCSI implementation for OSF/1 */
199
200 #include "scsi-osf.c"
201
202 #endif /* OSF/1 */
203
204 #ifdef VMS
205 #define SCSI_IMPL /* We have a SCSI implementation for VMS */
206
207 #include "scsi-vms.c"
208
209 #endif /* VMS */
210
211 #ifdef OPENSERVER
212 #define SCSI_IMPL /* We have a SCSI implementation for SCO OpenServer */
213
214 #include "scsi-openserver.c"
215
216 #endif /* SCO */
217
218 #ifdef UNIXWARE
219 #define SCSI_IMPL /* We have a SCSI implementation for SCO UnixWare */
220
221 #include "scsi-unixware.c"
222
223 #endif /* UNIXWARE */
224
225 #ifdef __OS2
226 #define SCSI_IMPL /* We have a SCSI implementation for OS/2 */
227
228 #include "scsi-os2.c"
229
230 #endif /* OS/2 */
231
232 #if defined(__BEOS__) || defined(__HAIKU__)
233 #define SCSI_IMPL /* Yep, BeOS does that funky scsi stuff */
234 #include "scsi-beos.c"
235 #endif
236
237 #if defined(__CYGWIN32__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER)
238 #define SCSI_IMPL /* Yep, we support WNT and W9? */
239 #include "scsi-wnt.c"
240 #endif
241
242 #ifdef apollo
243 #define SCSI_IMPL /* We have a SCSI implementation for Apollo Domain/OS */
244 #include "scsi-apollo.c"
245 #endif
246
247 #ifdef AMIGA /* We have a SCSI implementation for AmigaOS */
248 #define SCSI_IMPL
249 #include "scsi-amigaos.c"
250 #endif
251
252 #if defined(__QNXNTO__) || defined(__QNX__)
253 #define SCSI_IMPL /* We have a SCSI implementation for QNX */
254 #include "scsi-qnx.c"
255 #endif /* QNX */
256
257 #ifdef __DJGPP__ /* We have a SCSI implementation for MS-DOS/DJGPP */
258 #define SCSI_IMPL
259 #include "scsi-dos.c"
260 #endif
261
262 #ifdef __MINT__ /* We have a SCSI implementation for ATARI/FreeMINT */
263 #define SCSI_IMPL
264 #include "scsi-atari.c"
265 #endif
266
267 #if defined(__SYLLABLE__) || defined(__PYRO__)
268 #define SCSI_IMPL /* We have a SCSI implementation for Syllable and Pyro */
269 #include "scsi-syllable.c"
270 #endif
271
272 #ifdef __NEW_ARCHITECTURE
273 #define SCSI_IMPL /* We have a SCSI implementation for XXX */
274 /*
275 * Add new hacks here
276 */
277 #include "scsi-new-arch.c"
278 #endif
279
280 #endif /* !NO_SCSI_IMPL */
281
282 #ifndef SCSI_IMPL
283 /*
284 * To make scsihack.c compile on all architectures.
285 * This does not mean that you may use it, but you can see
286 * if other problems exist.
287 */
288 #define scgo_dversion scgo_version
289 #define scgo_dhelp scgo_help
290 #define scgo_dopen scgo_open
291 #define scgo_dclose scgo_close
292 #define scgo_dmaxdma scgo_maxdma
293 #define scgo_dgetbuf scgo_getbuf
294 #define scgo_dfreebuf scgo_freebuf
295 #define scgo_dnumbus scgo_numbus
296 #define scgo_dhavebus scgo_havebus
297 #define scgo_dfileno scgo_fileno
298 #define scgo_dinitiator_id scgo_initiator_id
299 #define scgo_disatapi scgo_isatapi
300 #define scgo_dreset scgo_reset
301 #define scgo_dsend scgo_send
302 #endif /* SCSI_IMPL */
303
304 LOCAL int scgo_dsend __PR((SCSI *scgp));
305 LOCAL char * scgo_dversion __PR((SCSI *scgp, int what));
306 LOCAL int scgo_dhelp __PR((SCSI *scgp, FILE *f));
307 LOCAL int scgo_nohelp __PR((SCSI *scgp, FILE *f));
308 LOCAL int scgo_ropen __PR((SCSI *scgp, char *device));
309 LOCAL int scgo_dopen __PR((SCSI *scgp, char *device));
310 LOCAL int scgo_dclose __PR((SCSI *scgp));
311 LOCAL long scgo_dmaxdma __PR((SCSI *scgp, long amt));
312 LOCAL void * scgo_dgetbuf __PR((SCSI *scgp, long amt));
313 LOCAL void scgo_dfreebuf __PR((SCSI *scgp));
314 LOCAL int scgo_dnumbus __PR((SCSI *scgp));
315 LOCAL BOOL scgo_dhavebus __PR((SCSI *scgp, int busno));
316 LOCAL int scgo_dfileno __PR((SCSI *scgp, int busno, int tgt, int tlun));
317 LOCAL int scgo_dinitiator_id __PR((SCSI *scgp));
318 LOCAL int scgo_disatapi __PR((SCSI *scgp));
319 LOCAL int scgo_dreset __PR((SCSI *scgp, int what));
320
321 EXPORT scg_ops_t scg_remote_ops = {
322 scgo_dsend,
323 scgo_dversion,
324 scgo_nohelp,
325 scgo_ropen,
326 scgo_dclose,
327 scgo_dmaxdma,
328 scgo_dgetbuf,
329 scgo_dfreebuf,
330 scgo_dnumbus,
331 scgo_dhavebus,
332 scgo_dfileno,
333 scgo_dinitiator_id,
334 scgo_disatapi,
335 scgo_dreset,
336 };
337
338 EXPORT scg_ops_t scg_dummy_ops = {
339 scgo_dsend,
340 scgo_dversion,
341 scgo_dhelp,
342 scgo_dopen,
343 scgo_dclose,
344 scgo_dmaxdma,
345 scgo_dgetbuf,
346 scgo_dfreebuf,
347 scgo_dnumbus,
348 scgo_dhavebus,
349 scgo_dfileno,
350 scgo_dinitiator_id,
351 scgo_disatapi,
352 scgo_dreset,
353 };
354
355 /*
356 * Warning: you may change this source, but if you do that
357 * you need to change the _scg_version and _scg_auth* string below.
358 * You may not return "schily" for an SCG_AUTHOR request anymore.
359 * Choose your name instead of "schily" and make clear that the version
360 * string is related to a modified source.
361 */
362 LOCAL char _scg_trans_dversion[] = "scsihack.c-1.60"; /* The version for this transport*/
363
364 /*
365 * Return version information for the low level SCSI transport code.
366 * This has been introduced to make it easier to trace down problems
367 * in applications.
368 */
369 LOCAL char *
scgo_dversion(scgp,what)370 scgo_dversion(scgp, what)
371 SCSI *scgp;
372 int what;
373 {
374 if (scgp != (SCSI *)0) {
375 switch (what) {
376
377 case SCG_VERSION:
378 return (_scg_trans_dversion);
379 /*
380 * If you changed this source, you are not allowed to
381 * return "schily" for the SCG_AUTHOR request.
382 */
383 case SCG_AUTHOR:
384 return (_scg_auth_schily);
385 case SCG_SCCS_ID:
386 return (_sccsid);
387 }
388 }
389 return ((char *)0);
390 }
391
392 LOCAL int
scgo_dhelp(scgp,f)393 scgo_dhelp(scgp, f)
394 SCSI *scgp;
395 FILE *f;
396 {
397 printf("None.\n");
398 return (0);
399 }
400
401 LOCAL int
scgo_nohelp(scgp,f)402 scgo_nohelp(scgp, f)
403 SCSI *scgp;
404 FILE *f;
405 {
406 return (0);
407 }
408
409 LOCAL int
scgo_ropen(scgp,device)410 scgo_ropen(scgp, device)
411 SCSI *scgp;
412 char *device;
413 {
414 comerrno(EX_BAD, "No remote SCSI transport available.\n");
415 return (-1); /* Keep lint happy */
416 }
417
418 #ifndef SCSI_IMPL
419 LOCAL int
scgo_dopen(scgp,device)420 scgo_dopen(scgp, device)
421 SCSI *scgp;
422 char *device;
423 {
424 comerrno(EX_BAD, "No local SCSI transport implementation for this architecture.\n");
425 return (-1); /* Keep lint happy */
426 }
427 #else
428 LOCAL int
scgo_dopen(scgp,device)429 scgo_dopen(scgp, device)
430 SCSI *scgp;
431 char *device;
432 {
433 comerrno(EX_BAD, "SCSI open usage error.\n");
434 return (-1); /* Keep lint happy */
435 }
436 #endif /* SCSI_IMPL */
437
438 LOCAL int
scgo_dclose(scgp)439 scgo_dclose(scgp)
440 SCSI *scgp;
441 {
442 errno = EINVAL;
443 return (-1);
444 }
445
446 LOCAL long
scgo_dmaxdma(scgp,amt)447 scgo_dmaxdma(scgp, amt)
448 SCSI *scgp;
449 long amt;
450 {
451 errno = EINVAL;
452 return (0L);
453 }
454
455 LOCAL void *
scgo_dgetbuf(scgp,amt)456 scgo_dgetbuf(scgp, amt)
457 SCSI *scgp;
458 long amt;
459 {
460 errno = EINVAL;
461 return ((void *)0);
462 }
463
464 LOCAL void
scgo_dfreebuf(scgp)465 scgo_dfreebuf(scgp)
466 SCSI *scgp;
467 {
468 }
469
470 LOCAL BOOL
scgo_dnumbus(scgp)471 scgo_dnumbus(scgp)
472 SCSI *scgp;
473 {
474 return (0);
475 }
476
477 LOCAL BOOL
scgo_dhavebus(scgp,busno)478 scgo_dhavebus(scgp, busno)
479 SCSI *scgp;
480 int busno;
481 {
482 return (FALSE);
483 }
484
485 LOCAL int
scgo_dfileno(scgp,busno,tgt,tlun)486 scgo_dfileno(scgp, busno, tgt, tlun)
487 SCSI *scgp;
488 int busno;
489 int tgt;
490 int tlun;
491 {
492 return (-1);
493 }
494
495 LOCAL int
scgo_dinitiator_id(scgp)496 scgo_dinitiator_id(scgp)
497 SCSI *scgp;
498 {
499 return (-1);
500 }
501
502 LOCAL int
scgo_disatapi(scgp)503 scgo_disatapi(scgp)
504 SCSI *scgp;
505 {
506 return (FALSE);
507 }
508
509 LOCAL int
scgo_dreset(scgp,what)510 scgo_dreset(scgp, what)
511 SCSI *scgp;
512 int what;
513 {
514 errno = EINVAL;
515 return (-1);
516 }
517
518 LOCAL int
scgo_dsend(scgp)519 scgo_dsend(scgp)
520 SCSI *scgp;
521 {
522 errno = EINVAL;
523 return (-1);
524 }
525