summaryrefslogtreecommitdiff
path: root/sysutils/cdrtools/patches/patch-ai
blob: 6d19c903ee64146e51c298bb2f845931518312d3 (plain)
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
$NetBSD: patch-ai,v 1.5 2007/09/18 23:07:26 wiz Exp $

--- libscg/scsi-bsd.c.orig	2007-03-25 20:18:56.000000000 +0000
+++ libscg/scsi-bsd.c
@@ -44,6 +44,7 @@ static	char __sccsid[] =
 
 #undef	sense
 #include <sys/scsiio.h>
+#include <util.h>
 
 /*
  *	Warning: you may change this source, but if you do that
@@ -52,7 +53,7 @@ static	char __sccsid[] =
  *	Choose your name instead of "schily" and make clear that the version
  *	string is related to a modified source.
  */
-LOCAL	char	_scg_trans_version[] = "scsi-bsd.c-1.44";	/* The version for this transport*/
+LOCAL	char	_scg_trans_version[] = "scsi-bsd.c-1.44nb1";	/* The version for this transport */
 
 #define	MAX_SCG		16	/* Max # of SCSI controllers */
 #define	MAX_TGT		16
@@ -112,7 +113,7 @@ scgo_version(scgp, what)
 		 * return "schily" for the SCG_AUTHOR request.
 		 */
 		case SCG_AUTHOR:
-			return (_scg_auth_schily);
+			return ("frueauf");
 		case SCG_SCCS_ID:
 			return (__sccsid);
 		}
@@ -144,6 +145,10 @@ scgo_open(scgp, device)
 	register int	l;
 	register int	nopen = 0;
 	char		devname[64];
+#if defined(__NetBSD__)
+	struct scsi_addr mysaddr;
+	int		myslicename = getrawpartition();
+#endif
 
 	if (busno >= MAX_SCG || tgt >= MAX_TGT || tlun >= MAX_LUN) {
 		errno = EINVAL;
@@ -170,6 +175,60 @@ scgo_open(scgp, device)
 	if ((device != NULL && *device != '\0') || (busno == -2 && tgt == -2))
 		goto openbydev;
 
+
+/*
+ * I know of no method in NetBSD to probe the scsibus and get the mapping
+ * busnumber,target,lun --> devicename.
+ *
+ * Because of this implement a true bruteforce hack to find
+ * out what cdroms there are.
+ *
+ * Note that this method only finds cd0-cd7. Anything higher
+ * than this needs additional tweaks.
+ *
+ * Feel free to implement this cleanly if you have better knowledge.
+ * Until then this helps to get -scanbus und thus xcdroast working :-)
+ *
+ */
+#if defined(__NetBSD__)
+	if (busno >= 0 && tgt >= 0 && tlun >= 0) {
+		for (l=0; l < MAX_LUN ; l++) {
+			sprintf(devname, "/dev/rcd%d%c", l, 'a' + myslicename);
+			f = open(devname, O_RDWR);
+			if (f >= 0) {
+				if (ioctl(f, SCIOCIDENTIFY, &mysaddr) < 0) {
+					close(f);
+					errno = EINVAL;
+					return (0);
+				}
+				if (busno == SADDR_BUS(mysaddr) && tgt == SADDR_TARGET(mysaddr) && tlun == SADDR_LUN(mysaddr)) {
+					scglocal(scgp)->scgfiles[busno][tgt][tlun] = f;
+					return(1);
+				}
+			}
+		}
+	} else for (l=0; l < MAX_LUN ; l++) {
+			sprintf(devname, "/dev/rcd%d%c", l, 'a' + myslicename);
+			f = open(devname, O_RDWR);
+			if (f >= 0) {
+				if (ioctl(f, SCIOCIDENTIFY, &mysaddr) < 0) {
+					close(f);
+					errno = EINVAL;
+					return (0);
+				}
+				scg_scsibus(scgp) = busno   = SADDR_BUS(mysaddr);
+				scg_target(scgp)  = tgt     = SADDR_TARGET(mysaddr);
+				if ((tlun >= 0) && (tlun != SADDR_LUN(mysaddr))) {
+					close(f);
+					errno = EINVAL;
+					return (0);
+				}
+				scg_lun(scgp)     = tlun    = SADDR_LUN(mysaddr);
+				if (scg_setup(scgp, f, busno, tgt, tlun))
+					nopen++;
+			}
+		}
+#else /* not __NetBSD__ */
 	if (busno >= 0 && tgt >= 0 && tlun >= 0) {
 
 		js_snprintf(devname, sizeof (devname),
@@ -206,6 +265,7 @@ scgo_open(scgp, device)
 			}
 		}
 	}
+#endif /* end of not __NetBSD__ */
 	/*
 	 * Could not open /dev/su-* or got dev=devname:b,l,l / dev=devname:@,l
 	 * We do the apropriate tests and try our best.