1 $NetBSD: patch-ab,v 1.1 2003/01/31 11:02:29 abs Exp $
3 --- libscg/scsi-bsd.c.orig Tue Jan 29 17:23:22 2002
5 @@ -48,7 +48,7 @@ static char __sccsid[] =
6 * Choose your name instead of "schily" and make clear that the version
7 * string is related to a modified source.
9 -LOCAL char _scg_trans_version[] = "scsi-bsd.c-1.40"; /* The version for this transport*/
10 +LOCAL char _scg_trans_version[] = "scsi-bsd.c-1.40nb1"; /* The version for this transport*/
12 #define MAX_SCG 16 /* Max # of SCSI controllers */
14 @@ -108,7 +108,7 @@ scgo_version(scgp, what)
15 * return "schily" for the SCG_AUTHOR request.
18 - return (_scg_auth_schily);
23 @@ -130,6 +130,15 @@ scgo_open(scgp, device)
25 register int nopen = 0;
27 +#if defined(__NetBSD__)
28 + struct scsi_addr mysaddr;
29 +#if defined(__i386__) || defined(__amd64__)
30 + char slicename[] = "d"; /* i386 is special */
32 + char slicename[] = "c"; /* this is what the rest uses */
34 + char *myslicename = slicename;
37 if (busno >= MAX_SCG || tgt >= MAX_TGT || tlun >= MAX_LUN) {
39 @@ -156,6 +165,60 @@ scgo_open(scgp, device)
40 if ((device != NULL && *device != '\0') || (busno == -2 && tgt == -2))
45 + * I know of no method in NetBSD to probe the scsibus and get the mapping
46 + * busnumber,target,lun --> devicename.
48 + * Because of this implement a true bruteforce hack to find
49 + * out what cdroms there are.
51 + * Note that this method only finds cd0-cd7. Anything higher
52 + * than this needs additional tweaks.
54 + * Feel free to implement this cleanly if you have better knowledge.
55 + * Until then this helps to get -scanbus und thus xcdroast working :-)
58 +#if defined(__NetBSD__)
59 + if (busno >= 0 && tgt >= 0 && tlun >= 0) {
60 + for (l=0; l < MAX_LUN ; l++) {
61 + sprintf(devname, "/dev/rcd%d%s", l, myslicename);
62 + f = open(devname, O_RDWR);
64 + if (ioctl(f, SCIOCIDENTIFY, &mysaddr) < 0) {
69 + if (busno == SADDR_BUS(mysaddr) && tgt == SADDR_TARGET(mysaddr) && tlun == SADDR_LUN(mysaddr)) {
70 + scglocal(scgp)->scgfiles[busno][tgt][tlun] = f;
73 + } else goto openbydev;
75 + } else for (l=0; l < MAX_LUN ; l++) {
76 + sprintf(devname, "/dev/rcd%d%s", l, myslicename);
77 + f = open(devname, O_RDWR);
79 + if (ioctl(f, SCIOCIDENTIFY, &mysaddr) < 0) {
84 + scg_scsibus(scgp) = busno = SADDR_BUS(mysaddr);
85 + scg_target(scgp) = tgt = SADDR_TARGET(mysaddr);
86 + if ((tlun >= 0) && (tlun != SADDR_LUN(mysaddr))) {
91 + scg_lun(scgp) = tlun = SADDR_LUN(mysaddr);
92 + if (scg_setup(scgp, f, busno, tgt, tlun))
96 +#else /* not __NetBSD__ */
97 if (busno >= 0 && tgt >= 0 && tlun >= 0) {
99 js_snprintf(devname, sizeof(devname),
100 @@ -192,6 +255,7 @@ scgo_open(scgp, device)
104 +#endif /* end of not __NetBSD__ */
106 * Could not open /dev/su-* or got dev=devname:b,l,l / dev=devname:@,l
107 * We do the apropriate tests and try our best.