File: scsihack.c

package info (click to toggle)
sformat 3.5-1.2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,588 kB
  • ctags: 5,796
  • sloc: ansic: 32,949; sh: 2,138; makefile: 187; pascal: 42
file content (445 lines) | stat: -rw-r--r-- 9,975 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
/* @(#)scsihack.c	1.37 01/02/15 Copyright 1997,2000 J. Schilling */
#ifndef lint
static	char _sccsid[] =
	"@(#)scsihack.c	1.37 01/02/15 Copyright 1997,2000 J. Schilling";
#endif
/*
 *	Interface for other generic SCSI implementations.
 *	Emulate the functionality of /dev/scg? with the local
 *	SCSI user land implementation.
 *
 *	To add a new hack, add something like:
 *
 *	#ifdef	__FreeBSD__
 *	#define	SCSI_IMPL
 *	#include some code
 *	#endif
 *
 *	Warning: you may change this source or add new SCSI tranport
 *	implementations, but if you do that you need to change the
 *	_scg_version and _scg_auth* string that are returned by the
 *	SCSI transport code.
 *	Choose your name instead of "schily" and make clear that the version
 *	string is related to a modified source.
 *	If your version has been integrated into the main steam release,
 *	the return value will be set to "schily".
 *
 *	Copyright (c) 1997 J. Schilling
 */
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <mconfig.h>

#ifdef	HAVE_SYS_PARAM_H
#include <sys/param.h>	/* Include various defs needed with some OS */
#endif
#include <stdio.h>
#include <standard.h>
#include <stdxlib.h>
#include <unixstd.h>
#include <errno.h>
#include <timedefs.h>
#include <sys/ioctl.h>
#include <fctldefs.h>
#include <strdefs.h>
#include <schily.h>

#include <scg/scgcmd.h>
#include <scg/scsitransp.h>
#include "scgtimes.h"

#ifndef	HAVE_ERRNO_DEF
extern	int	errno;
#endif

LOCAL	int	scgo_send	__PR((SCSI *scgp));
LOCAL	char *	scgo_version	__PR((SCSI *scgp, int what));
LOCAL	int	scgo_open	__PR((SCSI *scgp, char *device));
LOCAL	int	scgo_close	__PR((SCSI *scgp));
LOCAL	long	scgo_maxdma	__PR((SCSI *scgp, long amt));
LOCAL	void *	scgo_getbuf	__PR((SCSI *scgp, long amt));
LOCAL	void	scgo_freebuf	__PR((SCSI *scgp));

LOCAL	BOOL	scgo_havebus	__PR((SCSI *scgp, int busno));
LOCAL	int	scgo_fileno	__PR((SCSI *scgp, int busno, int tgt, int tlun));
LOCAL	int	scgo_initiator_id __PR((SCSI *scgp));
LOCAL	int	scgo_isatapi	__PR((SCSI *scgp));
LOCAL	int	scgo_reset	__PR((SCSI *scgp, int what));

LOCAL	char	_scg_auth_schily[]	= "schily";	/* The author for this module	*/

EXPORT scg_ops_t scg_std_ops = {
	scgo_send,
	scgo_version,
	scgo_open,
	scgo_close,
	scgo_maxdma,
	scgo_getbuf,
	scgo_freebuf,
	scgo_havebus,
	scgo_fileno,
	scgo_initiator_id,
	scgo_isatapi,
	scgo_reset,
};

/*#undef sun*/
/*#undef __sun*/
/*#undef __sun__*/

#if defined(sun) || defined(__sun) || defined(__sun__)
#define	SCSI_IMPL		/* We have a SCSI implementation for Sun */

#include "scsi-sun.c"

#endif	/* Sun */


#ifdef	linux
#define	SCSI_IMPL		/* We have a SCSI implementation for Linux */

#ifdef	not_needed		/* We now have a local vrersion of pg.h  */
#ifndef	HAVE_LINUX_PG_H		/* If we are compiling on an old version */
#	undef	USE_PG_ONLY	/* there is no 'pg' driver and we cannot */
#	undef	USE_PG		/* include <linux/pg.h> which is needed  */
#endif				/* by the pg transport code.		 */
#endif

#ifdef	USE_PG_ONLY
#include "scsi-linux-pg.c"
#else
#include "scsi-linux-sg.c"
#endif

#endif	/* linux */

#if	defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#define	SCSI_IMPL		/* We have a SCSI implementation for *BSD */

#include "scsi-bsd.c"

#endif	/* *BSD */

#if	defined(__bsdi__)	/* We have a SCSI implementation for BSD/OS 3.x (and later?) */
# include <sys/param.h>
# if (_BSDI_VERSION >= 199701)
#  define	SCSI_IMPL

#  include "scsi-bsd-os.c"

# endif	/* BSD/OS >= 3.0 */
#endif /* BSD/OS */

#ifdef	__sgi
#define	SCSI_IMPL		/* We have a SCSI implementation for SGI */

#include "scsi-sgi.c"

#endif	/* SGI */

#ifdef	__hpux
#define	SCSI_IMPL		/* We have a SCSI implementation for HP-UX */

#include "scsi-hpux.c"

#endif	/* HP-UX */

#if	defined(_IBMR2) || defined(_AIX)
#define	SCSI_IMPL		/* We have a SCSI implementation for AIX */

#include "scsi-aix.c"

#endif	/* AIX */

#if	defined(__NeXT__) || defined(IS_MACOS_X)
#if	defined(HAVE_BSD_DEV_SCSIREG_H)
#define	SCSI_IMPL		/* We found a SCSI implementation for NextStep and Mac OS X */

#include "scsi-next.c"
#endif	/* HAVE_BSD_DEV_SCSIREG_H */

#endif	/* NEXT / Mac OS X */

#if	defined(__osf__)
#define	SCSI_IMPL		/* We have a SCSI implementation for OSF/1 */

#include "scsi-osf.c"

#endif	/* OSF/1 */

#ifdef	VMS
#define	SCSI_IMPL		/* We have a SCSI implementation for VMS */

#include "scsi-vms.c"

#endif	/* VMS */

#ifdef	OPENSERVER
#define	SCSI_IMPL		/* We have a SCSI implementation for SCO OpenServer */

#include "scsi-openserver.c"

#endif  /* SCO */

#ifdef	UNIXWARE
#define	SCSI_IMPL		/* We have a SCSI implementation for SCO UnixWare */

#include "scsi-unixware.c"

#endif  /* UNIXWARE */

#ifdef	__OS2
#define	SCSI_IMPL		/* We have a SCSI implementation for OS/2 */

#include "scsi-os2.c"

#endif  /* OS/2 */

#ifdef	__BEOS__
#define	SCSI_IMPL		/* Yep, BeOS does that funky scsi stuff */
#include "scsi-beos.c"
#endif

#ifdef	__CYGWIN32__
#define	SCSI_IMPL		/* Yep, we support WNT and W9? */
#include "scsi-wnt.c"
#endif

#ifdef	apollo
#define	SCSI_IMPL		/* We have a SCSI implementation for Apollo Domain/OS */
#include "scsi-apollo.c"
#endif

#ifdef	__NEW_ARCHITECTURE
#define	SCSI_IMPL		/* We have a SCSI implementation for XXX */
/*
 * Add new hacks here
 */
#include "scsi-new-arch.c"
#endif


#ifndef	SCSI_IMPL
/*
 * To make scsihack.c compile on all architectures.
 * This does not mean that you may use it, but you can see
 * if other problems exist.
 */
#define	scgo_dversion		scgo_version
#define	scgo_dopen		scgo_open
#define	scgo_dclose		scgo_close
#define	scgo_dmaxdma		scgo_maxdma
#define	scgo_dgetbuf		scgo_getbuf
#define	scgo_dfreebuf		scgo_freebuf
#define	scgo_dhavebus		scgo_havebus
#define	scgo_dfileno		scgo_fileno
#define	scgo_dinitiator_id	scgo_initiator_id
#define	scgo_disatapi		scgo_isatapi
#define	scgo_dreset		scgo_reset
#define	scgo_dsend		scgo_send
#endif	/* SCSI_IMPL */

LOCAL	int	scgo_dsend	__PR((SCSI *scgp));
LOCAL	char *	scgo_dversion	__PR((SCSI *scgp, int what));
LOCAL	int	scgo_ropen	__PR((SCSI *scgp, char *device));
LOCAL	int	scgo_dopen	__PR((SCSI *scgp, char *device));
LOCAL	int	scgo_dclose	__PR((SCSI *scgp));
LOCAL	long	scgo_dmaxdma	__PR((SCSI *scgp, long amt));
LOCAL	void *	scgo_dgetbuf	__PR((SCSI *scgp, long amt));
LOCAL	void	scgo_dfreebuf	__PR((SCSI *scgp));
LOCAL	BOOL	scgo_dhavebus	__PR((SCSI *scgp, int busno));
LOCAL	int	scgo_dfileno	__PR((SCSI *scgp, int busno, int tgt, int tlun));
LOCAL	int	scgo_dinitiator_id __PR((SCSI *scgp));
LOCAL	int	scgo_disatapi	__PR((SCSI *scgp));
LOCAL	int	scgo_dreset	__PR((SCSI *scgp, int what));

EXPORT scg_ops_t scg_remote_ops = {
	scgo_dsend,
	scgo_dversion,
	scgo_ropen,
	scgo_dclose,
	scgo_dmaxdma,
	scgo_dgetbuf,
	scgo_dfreebuf,
	scgo_dhavebus,
	scgo_dfileno,
	scgo_dinitiator_id,
	scgo_disatapi,
	scgo_dreset,
};

EXPORT scg_ops_t scg_dummy_ops = {
	scgo_dsend,
	scgo_dversion,
	scgo_dopen,
	scgo_dclose,
	scgo_dmaxdma,
	scgo_dgetbuf,
	scgo_dfreebuf,
	scgo_dhavebus,
	scgo_dfileno,
	scgo_dinitiator_id,
	scgo_disatapi,
	scgo_dreset,
};

/*
 *	Warning: you may change this source, but if you do that
 *	you need to change the _scg_version and _scg_auth* string below.
 *	You may not return "schily" for an SCG_AUTHOR request anymore.
 *	Choose your name instead of "schily" and make clear that the version
 *	string is related to a modified source.
 */
LOCAL	char	_scg_trans_dversion[] = "scsihack.c-1.37";	/* The version for this transport*/

/*
 * Return version information for the low level SCSI transport code.
 * This has been introduced to make it easier to trace down problems
 * in applications.
 */
LOCAL char *
scgo_dversion(scgp, what)
	SCSI	*scgp;
	int	what;
{
	if (scgp != (SCSI *)0) {
		switch (what) {

		case SCG_VERSION:
			return (_scg_trans_dversion);
		/*
		 * If you changed this source, you are not allowed to
		 * return "schily" for the SCG_AUTHOR request.
		 */
		case SCG_AUTHOR:
			return (_scg_auth_schily);
		case SCG_SCCS_ID:
			return (_sccsid);
		}
	}
	return ((char *)0);
}

LOCAL int
scgo_ropen(scgp, device)
	SCSI	*scgp;
	char	*device;
{
	comerrno(EX_BAD, "No remote SCSI transport available.\n");
	return (-1);	/* Keep lint happy */
}

#ifndef	SCSI_IMPL
LOCAL int
scgo_dopen(scgp, device)
	SCSI	*scgp;
	char	*device;
{
	comerrno(EX_BAD, "No local SCSI transport implementation for this architecture.\n");
	return (-1);	/* Keep lint happy */
}
#else
LOCAL int
scgo_dopen(scgp, device)
	SCSI	*scgp;
	char	*device;
{
	comerrno(EX_BAD, "SCSI open usage error.\n");
	return (-1);	/* Keep lint happy */
}
#endif	/* SCSI_IMPL */

LOCAL int
scgo_dclose(scgp)
	SCSI	*scgp;
{
	errno = EINVAL;
	return (-1);
}

LOCAL long
scgo_dmaxdma(scgp, amt)
	SCSI	*scgp;
	long	amt;
{
	errno = EINVAL;
	return	(0L);
}

LOCAL void *
scgo_dgetbuf(scgp, amt)
	SCSI	*scgp;
	long	amt;
{
	errno = EINVAL;
	return ((void *)0);
}

LOCAL void
scgo_dfreebuf(scgp)
	SCSI	*scgp;
{
}

LOCAL BOOL
scgo_dhavebus(scgp, busno)
	SCSI	*scgp;
	int	busno;
{
	return (FALSE);
}

LOCAL int
scgo_dfileno(scgp, busno, tgt, tlun)
	SCSI	*scgp;
	int	busno;
	int	tgt;
	int	tlun;
{
	return (-1);
}

LOCAL int
scgo_dinitiator_id(scgp)
	SCSI	*scgp;
{
	return (-1);
}

LOCAL int
scgo_disatapi(scgp)
	SCSI	*scgp;
{
	return (FALSE);
}

LOCAL int
scgo_dreset(scgp, what)
	SCSI	*scgp;
	int	what;
{
	errno = EINVAL;
	return (-1);
}

LOCAL int
scgo_dsend(scgp)
	SCSI	*scgp;
{
	errno = EINVAL;
	return (-1);
}