File: scsihack.c

package info (click to toggle)
cdrkit 9:1.1.11-3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 7,464 kB
  • sloc: ansic: 107,182; perl: 968; sh: 481; makefile: 229; sed: 4
file content (483 lines) | stat: -rw-r--r-- 11,435 bytes parent folder | download | duplicates (4)
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
/*
 * This file has been modified for the cdrkit suite.
 *
 * The behaviour and appearence of the program code below can differ to a major
 * extent from the version distributed by the original author(s).
 *
 * For details, see Changelog file distributed with the cdrkit package. If you
 * received this file from another source then ask the distributing person for
 * a log of modifications.
 *
 */

/* @(#)scsihack.c	1.44 06/01/30 Copyright 1997,2000,2001 J. Schilling */
/*
 *	Interface for other generic SCSI implementations.
 *	Emulate the functionality of /dev/usal? 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
 *	_usal_version and _usal_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,2000,2001 J. Schilling
 */
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 *
 * 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 <usal/usalcmd.h>
#include <usal/scsitransp.h>
#include "usaltimes.h"

#ifndef	HAVE_ERRNO_DEF
extern	int	errno;
#endif

static	int	usalo_send(SCSI *usalp);
static	char *usalo_version(SCSI *usalp, int what);
static	int	usalo_help(SCSI *usalp, FILE *f);
static	int	usalo_open(SCSI *usalp, char *device);
static	int	usalo_close(SCSI *usalp);
static	long	usalo_maxdma(SCSI *usalp, long amt);
static	void *usalo_getbuf(SCSI *usalp, long amt);
static	void	usalo_freebuf(SCSI *usalp);

static	BOOL	usalo_havebus(SCSI *usalp, int busno);
static	int	usalo_fileno(SCSI *usalp, int busno, int tgt, int tlun);
static char * usalo_natname(SCSI *usalp, int busno, int tgt, int tlun);
static	int	usalo_initiator_id(SCSI *usalp);
static	int	usalo_isatapi(SCSI *usalp);
static	int	usalo_reset(SCSI *usalp, int what);

static	char	_usal_auth_cdrkit[]	= "cdrkit-team";	/* The author for this module	*/

usal_ops_t usal_std_ops = {
	usalo_send,
	usalo_version,
	usalo_help,
	usalo_open,
	usalo_close,
	usalo_maxdma,
	usalo_getbuf,
	usalo_freebuf,
	usalo_havebus,
	usalo_fileno,
	usalo_initiator_id,
	usalo_isatapi,
	usalo_reset,
	usalo_natname,
};

/*#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__) || defined(__DragonFly__)  || defined(__FreeBSD_kernel__) 
#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)
/*
 *	This is the
 */
#define	SCSI_IMPL		/* We found a SCSI implementation for NextStep and Mac OS X */

#include "scsi-next.c"
#else

#define	SCSI_IMPL		/* We found a SCSI implementation for Mac OS X (Darwin-1.4) */

#include "scsi-mac-iokit.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	AMIGA			/* We have a SCSI implementation for AmigaOS */
#define	SCSI_IMPL
#include "scsi-amigaos.c"
#endif

#if	defined(__QNXNTO__) || defined(__QNX__)
#define	SCSI_IMPL		/* We have a SCSI implementation for QNX */
#include "scsi-qnx.c"
#endif	/* QNX */

#ifdef	__DJGPP__		/* We have a SCSI implementation for MS-DOS/DJGPP */
#define	SCSI_IMPL
#include "scsi-dos.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	usalo_dversion		usalo_version
#define	usalo_dhelp		usalo_help
#define	usalo_dopen		usalo_open
#define	usalo_dclose		usalo_close
#define	usalo_dmaxdma		usalo_maxdma
#define	usalo_dgetbuf		usalo_getbuf
#define	usalo_dfreebuf		usalo_freebuf
#define	usalo_dhavebus		usalo_havebus
#define	usalo_dfileno		usalo_fileno
#define	usalo_dinitiator_id	usalo_initiator_id
#define	usalo_disatapi		usalo_isatapi
#define	usalo_dreset		usalo_reset
#define	usalo_dsend		usalo_send
#endif	/* SCSI_IMPL */

static	int	usalo_dsend(SCSI *usalp);
static	char *usalo_dversion(SCSI *usalp, int what);
static	int	usalo_dhelp(SCSI *usalp, FILE *f);
static	int	usalo_nohelp(SCSI *usalp, FILE *f);
static	int	usalo_ropen(SCSI *usalp, char *device);
static	int	usalo_dopen(SCSI *usalp, char *device);
static	int	usalo_dclose(SCSI *usalp);
static	long	usalo_dmaxdma(SCSI *usalp, long amt);
static	void *usalo_dgetbuf(SCSI *usalp, long amt);
static	void	usalo_dfreebuf(SCSI *usalp);
static	BOOL	usalo_dhavebus(SCSI *usalp, int busno);
static	int	usalo_dfileno(SCSI *usalp, int busno, int tgt, int tlun);
static	int	usalo_dinitiator_id(SCSI *usalp);
static	int	usalo_disatapi(SCSI *usalp);
static	int	usalo_dreset(SCSI *usalp, int what);

usal_ops_t usal_remote_ops = {
	usalo_dsend,
	usalo_dversion,
	usalo_nohelp,
	usalo_ropen,
	usalo_dclose,
	usalo_dmaxdma,
	usalo_dgetbuf,
	usalo_dfreebuf,
	usalo_dhavebus,
	usalo_dfileno,
	usalo_dinitiator_id,
	usalo_disatapi,
	usalo_dreset,
  usalo_natname,
};

usal_ops_t usal_dummy_ops = {
	usalo_dsend,
	usalo_dversion,
	usalo_dhelp,
	usalo_dopen,
	usalo_dclose,
	usalo_dmaxdma,
	usalo_dgetbuf,
	usalo_dfreebuf,
	usalo_dhavebus,
	usalo_dfileno,
	usalo_dinitiator_id,
	usalo_disatapi,
	usalo_dreset,
  usalo_natname,
};

/*
 *	Warning: you may change this source, but if you do that
 *	you need to change the _usal_version and _usal_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.
 */
static	char	_usal_trans_dversion[] = "scsihack.c-1.44";	/* 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.
 */
static char *
usalo_dversion(SCSI *usalp, int what)
{
	if (usalp != (SCSI *)0) {
		switch (what) {

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

static int
usalo_dhelp(SCSI *usalp, FILE *f)
{
	printf("None.\n");
	return (0);
}

static int
usalo_nohelp(SCSI *usalp, FILE *f)
{
	return (0);
}

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

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

static int
usalo_dclose(SCSI *usalp)
{
	errno = EINVAL;
	return (-1);
}

static long
usalo_dmaxdma(SCSI *usalp, long amt)
{
	errno = EINVAL;
	return	(0L);
}

static void *
usalo_dgetbuf(SCSI *usalp, long amt)
{
	errno = EINVAL;
	return ((void *)0);
}

static void
usalo_dfreebuf(SCSI *usalp)
{
}

static BOOL
usalo_dhavebus(SCSI *usalp, int busno)
{
	return (FALSE);
}

static int
usalo_dfileno(SCSI *usalp, int busno, int tgt, int tlun)
{
	return (-1);
}

#ifndef HAVE_NAT_NAMES /* to be defined in included source if supported */
static char * usalo_natname(SCSI *usalp, int busno, int tgt, int tlun) {
   static char namebuf[81];
   snprintf(namebuf, 80, "%d,%d,%d", usal_scsibus(usalp), usal_target(usalp), usal_lun(usalp));
   return namebuf;
}
#endif

static int
usalo_dinitiator_id(SCSI *usalp)
{
	return (-1);
}

static int
usalo_disatapi(SCSI *usalp)
{
	return (FALSE);
}

static int
usalo_dreset(SCSI *usalp, int what)
{
	errno = EINVAL;
	return (-1);
}

static int
usalo_dsend(SCSI *usalp)
{
	errno = EINVAL;
	return (-1);
}