2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)scsihack.c 1.44 06/01/30 Copyright 1997,2000,2001 J. Schilling */
15 * Interface for other generic SCSI implementations.
16 * Emulate the functionality of /dev/usal? with the local
17 * SCSI user land implementation.
19 * To add a new hack, add something like:
26 * Warning: you may change this source or add new SCSI tranport
27 * implementations, but if you do that you need to change the
28 * _usal_version and _usal_auth* string that are returned by the
29 * SCSI transport code.
30 * Choose your name instead of "schily" and make clear that the version
31 * string is related to a modified source.
32 * If your version has been integrated into the main steam release,
33 * the return value will be set to "schily".
35 * Copyright (c) 1997,2000,2001 J. Schilling
38 * This program is free software; you can redistribute it and/or modify
39 * it under the terms of the GNU General Public License version 2
40 * as published by the Free Software Foundation.
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
47 * You should have received a copy of the GNU General Public License along with
48 * this program; see the file COPYING. If not, write to the Free Software
49 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
54 #ifdef HAVE_SYS_PARAM_H
55 #include <sys/param.h> /* Include various defs needed with some OS */
63 #include <sys/ioctl.h>
68 #include <usal/usalcmd.h>
69 #include <usal/scsitransp.h>
70 #include "usaltimes.h"
72 #ifndef HAVE_ERRNO_DEF
76 static int usalo_send(SCSI *usalp);
77 static char *usalo_version(SCSI *usalp, int what);
78 static int usalo_help(SCSI *usalp, FILE *f);
79 static int usalo_open(SCSI *usalp, char *device);
80 static int usalo_close(SCSI *usalp);
81 static long usalo_maxdma(SCSI *usalp, long amt);
82 static void *usalo_getbuf(SCSI *usalp, long amt);
83 static void usalo_freebuf(SCSI *usalp);
85 static BOOL usalo_havebus(SCSI *usalp, int busno);
86 static int usalo_fileno(SCSI *usalp, int busno, int tgt, int tlun);
87 static char * usalo_natname(SCSI *usalp, int busno, int tgt, int tlun);
88 static int usalo_initiator_id(SCSI *usalp);
89 static int usalo_isatapi(SCSI *usalp);
90 static int usalo_reset(SCSI *usalp, int what);
92 static char _usal_auth_cdrkit[] = "cdrkit-team"; /* The author for this module */
94 usal_ops_t usal_std_ops = {
115 #if defined(sun) || defined(__sun) || defined(__sun__)
116 #define SCSI_IMPL /* We have a SCSI implementation for Sun */
118 #include "scsi-sun.c"
124 #define SCSI_IMPL /* We have a SCSI implementation for Linux */
126 #ifdef not_needed /* We now have a local vrersion of pg.h */
127 #ifndef HAVE_LINUX_PG_H /* If we are compiling on an old version */
128 # undef USE_PG_ONLY /* there is no 'pg' driver and we cannot */
129 # undef USE_PG /* include <linux/pg.h> which is needed */
130 #endif /* by the pg transport code. */
134 #include "scsi-linux-pg.c"
136 #include "scsi-linux-sg.c"
141 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
142 #define SCSI_IMPL /* We have a SCSI implementation for *BSD */
144 #include "scsi-bsd.c"
148 #if defined(__bsdi__) /* We have a SCSI implementation for BSD/OS 3.x (and later?) */
149 # include <sys/param.h>
150 # if (_BSDI_VERSION >= 199701)
153 # include "scsi-bsd-os.c"
155 # endif /* BSD/OS >= 3.0 */
159 #define SCSI_IMPL /* We have a SCSI implementation for SGI */
161 #include "scsi-sgi.c"
166 #define SCSI_IMPL /* We have a SCSI implementation for HP-UX */
168 #include "scsi-hpux.c"
172 #if defined(_IBMR2) || defined(_AIX)
173 #define SCSI_IMPL /* We have a SCSI implementation for AIX */
175 #include "scsi-aix.c"
179 #if defined(__NeXT__) || defined(IS_MACOS_X)
180 #if defined(HAVE_BSD_DEV_SCSIREG_H)
184 #define SCSI_IMPL /* We found a SCSI implementation for NextStep and Mac OS X */
186 #include "scsi-next.c"
189 #define SCSI_IMPL /* We found a SCSI implementation for Mac OS X (Darwin-1.4) */
191 #include "scsi-mac-iokit.c"
193 #endif /* HAVE_BSD_DEV_SCSIREG_H */
195 #endif /* NEXT / Mac OS X */
198 #define SCSI_IMPL /* We have a SCSI implementation for OSF/1 */
200 #include "scsi-osf.c"
205 #define SCSI_IMPL /* We have a SCSI implementation for VMS */
207 #include "scsi-vms.c"
212 #define SCSI_IMPL /* We have a SCSI implementation for SCO OpenServer */
214 #include "scsi-openserver.c"
219 #define SCSI_IMPL /* We have a SCSI implementation for SCO UnixWare */
221 #include "scsi-unixware.c"
223 #endif /* UNIXWARE */
226 #define SCSI_IMPL /* We have a SCSI implementation for OS/2 */
228 #include "scsi-os2.c"
233 #define SCSI_IMPL /* Yep, BeOS does that funky scsi stuff */
234 #include "scsi-beos.c"
238 #define SCSI_IMPL /* Yep, we support WNT and W9? */
239 #include "scsi-wnt.c"
243 #define SCSI_IMPL /* We have a SCSI implementation for Apollo Domain/OS */
244 #include "scsi-apollo.c"
247 #ifdef AMIGA /* We have a SCSI implementation for AmigaOS */
249 #include "scsi-amigaos.c"
252 #if defined(__QNXNTO__) || defined(__QNX__)
253 #define SCSI_IMPL /* We have a SCSI implementation for QNX */
254 #include "scsi-qnx.c"
257 #ifdef __DJGPP__ /* We have a SCSI implementation for MS-DOS/DJGPP */
259 #include "scsi-dos.c"
262 #ifdef __NEW_ARCHITECTURE
263 #define SCSI_IMPL /* We have a SCSI implementation for XXX */
267 #include "scsi-new-arch.c"
273 * To make scsihack.c compile on all architectures.
274 * This does not mean that you may use it, but you can see
275 * if other problems exist.
277 #define usalo_dversion usalo_version
278 #define usalo_dhelp usalo_help
279 #define usalo_dopen usalo_open
280 #define usalo_dclose usalo_close
281 #define usalo_dmaxdma usalo_maxdma
282 #define usalo_dgetbuf usalo_getbuf
283 #define usalo_dfreebuf usalo_freebuf
284 #define usalo_dhavebus usalo_havebus
285 #define usalo_dfileno usalo_fileno
286 #define usalo_dinitiator_id usalo_initiator_id
287 #define usalo_disatapi usalo_isatapi
288 #define usalo_dreset usalo_reset
289 #define usalo_dsend usalo_send
290 #endif /* SCSI_IMPL */
292 static int usalo_dsend(SCSI *usalp);
293 static char *usalo_dversion(SCSI *usalp, int what);
294 static int usalo_dhelp(SCSI *usalp, FILE *f);
295 static int usalo_nohelp(SCSI *usalp, FILE *f);
296 static int usalo_ropen(SCSI *usalp, char *device);
297 static int usalo_dopen(SCSI *usalp, char *device);
298 static int usalo_dclose(SCSI *usalp);
299 static long usalo_dmaxdma(SCSI *usalp, long amt);
300 static void *usalo_dgetbuf(SCSI *usalp, long amt);
301 static void usalo_dfreebuf(SCSI *usalp);
302 static BOOL usalo_dhavebus(SCSI *usalp, int busno);
303 static int usalo_dfileno(SCSI *usalp, int busno, int tgt, int tlun);
304 static int usalo_dinitiator_id(SCSI *usalp);
305 static int usalo_disatapi(SCSI *usalp);
306 static int usalo_dreset(SCSI *usalp, int what);
308 usal_ops_t usal_remote_ops = {
325 usal_ops_t usal_dummy_ops = {
343 * Warning: you may change this source, but if you do that
344 * you need to change the _usal_version and _usal_auth* string below.
345 * You may not return "schily" for an SCG_AUTHOR request anymore.
346 * Choose your name instead of "schily" and make clear that the version
347 * string is related to a modified source.
349 static char _usal_trans_dversion[] = "scsihack.c-1.44"; /* The version for this transport*/
352 * Return version information for the low level SCSI transport code.
353 * This has been introduced to make it easier to trace down problems
357 usalo_dversion(SCSI *usalp, int what)
359 if (usalp != (SCSI *)0) {
363 return (_usal_trans_dversion);
365 * If you changed this source, you are not allowed to
366 * return "schily" for the SCG_AUTHOR request.
369 return (_usal_auth_cdrkit);
378 usalo_dhelp(SCSI *usalp, FILE *f)
385 usalo_nohelp(SCSI *usalp, FILE *f)
391 usalo_ropen(SCSI *usalp, char *device)
393 comerrno(EX_BAD, "No remote SCSI transport available.\n");
394 return (-1); /* Keep lint happy */
399 usalo_dopen(SCSI *usalp, char *device)
401 comerrno(EX_BAD, "No local SCSI transport implementation for this architecture.\n");
402 return (-1); /* Keep lint happy */
406 usalo_dopen(SCSI *usalp, char *device)
408 comerrno(EX_BAD, "SCSI open usage error.\n");
409 return (-1); /* Keep lint happy */
411 #endif /* SCSI_IMPL */
414 usalo_dclose(SCSI *usalp)
421 usalo_dmaxdma(SCSI *usalp, long amt)
428 usalo_dgetbuf(SCSI *usalp, long amt)
435 usalo_dfreebuf(SCSI *usalp)
440 usalo_dhavebus(SCSI *usalp, int busno)
446 usalo_dfileno(SCSI *usalp, int busno, int tgt, int tlun)
451 #ifndef HAVE_NAT_NAMES /* to be defined in included source if supported */
452 static char * usalo_natname(SCSI *usalp, int busno, int tgt, int tlun) {
453 static char namebuf[81];
454 snprintf(namebuf, 80, "%d,%d,%d", usal_scsibus(usalp), usal_target(usalp), usal_lun(usalp));
460 usalo_dinitiator_id(SCSI *usalp)
466 usalo_disatapi(SCSI *usalp)
472 usalo_dreset(SCSI *usalp, int what)
479 usalo_dsend(SCSI *usalp)