Subject: workman 1.2.2a patches for NetBSD -current
To: None <current-users@NetBSD.ORG>
From: Jan-Hinrich Fessel <oskar@zappa.unna.Ping.DE>
List: current-users
Date: 04/24/1995 19:12:18
This is a multipart MIME message.

--boundary=_0
Content-Type: text/plain; charset=us-ascii
--------

This may be the wrong group, but I found the workman in the packages distrib 
working poorly on NetBSD, especially it doesn't recognize the CDROM and 
doesn't eject it.
The appended patches work fine for me on -current as of 04/22/95.
Note that I do have a Toshiba XM3601, and Workman locks up with the Toshiba 
specific code.  It works fine with the generic SCSI driver.  This may be the 
case with the older ones too...

Gruesse
	Oskar

 ==============================================================================
 					Tragbar ist, was nicht herunterfaellt.
						    oskar@zappa.unna.ping.de
 ==============================================================================

--boundary=_0
Content-Type: text/plain; charset=us-ascii
Content-Description: ++PATCHES

--- Imakefile.orig	Wed Apr 20 03:13:45 1994
+++ Imakefile	Sat Apr 22 13:05:46 1995
@@ -22,10 +22,23 @@
 LOCAL_LIBRARIES = XViewClientLibs -lCD
 #else
 #if defined(__bsdi__) || defined(i386Bsdi)
-/* LOCALDEFS=-DSOUNDBLASTER */ /* turns on some different volume code */
+LOCALDEFS=-DSOUNDBLASTER /* turns on some different volume code */
 LOCAL_LIBRARIES = XViewClientLibs -lcdrom -lrpc -lcompat
 CFLAGS += -fwritable-strings
 #else
+#if defined(NetBSDArchitecture)
+LOCALDEFS=-D__386BSD__
+
+pkg: $(DESTDIR)$(BINDIR)/workman $(HELP_DEST)/workman.info \
+     $(DESTDIR)$(MANDIR)/workman.0 $(DESTDIR)$(FILEMANDIR)/workmandb.0 \
+     pkg.workman README.NetBSD.pkg +PATCHES
+	pkg_create -v -t /var/tmp/instmp.XXXXXX -d README.NetBSD.pkg \
+	-f pkg.workman \
+	-c -"WorkMan CD-Audio player, version 1.2.2a (`uname -m`)" \
+	workman_122a
++PATCHES: Imakefile plat_freebsd.c
+	-rcsdiff -ubw -r1.1 Imakefile plat_freebsd.c > +PATCHES 2>&1
+#endif
 LOCAL_LIBRARIES = XViewClientLibs
 #endif
 #endif
@@ -44,7 +57,7 @@
 
 ComplexProgramTarget(workman)
 
-InstallSpecialManPage(workmandb,$(DBMANSECTION))
+InstallManPage(workmandb,$(DESTDIR)$(MANSOURCEPATH)$(DBMANSECTION))
 
 #ifdef UltrixArchitecture
 SpecialObjectRule(database.o,database.c,-Olimit 600);
--- cdrom.c-	Mon Apr 11 19:05:42 1994
+++ cdrom.c	Sun Apr 23 17:43:35 1995
@@ -206,10 +206,13 @@
 
 	/* Open the drive.  This returns 1 if the device isn't ready. */
 	status = wmcd_open(&drive);
-	if (status < 0)
+	if (status < 0) {
+		perror("wcmd_open");
 		return (status);
-	if (status > 0)
+	}
+	if (status > 0) {
 		return (0);
+	}
 
 	/* If the user hit the stop button, don't pass PLAYING as oldmode. */
 	if (cur_cdmode == STOPPED)
@@ -240,6 +243,7 @@
 	if (cur_cdmode == EJECTED)
 	{
 		cur_pos_rel = cur_pos_abs = 0;
+
 
 		if ((cd = read_toc()) == NULL)
 			if (exit_on_eject)
--- scsi.c-	Thu Mar  3 21:26:06 1994
+++ scsi.c	Sun Apr 23 17:06:46 1995
@@ -169,8 +169,10 @@
 	unsigned char		*s, *t, buf[36];
 
 	if (sendscsi(d, buf, sizeof(buf), 1, SCMD_INQUIRY, 0, 0, 0,
-			sizeof(buf), 0))
+			sizeof(buf), 0)) {
+		perror("sendscsi");
 		return (-1);
+	}
 
 	memcpy(vendor, buf + 8, 8);
 	vendor[8] = '\0';
--- workman_stubs.c-	Sat Apr  9 03:51:37 1994
+++ workman_stubs.c	Sun Apr 23 13:36:12 1995
@@ -290,7 +290,7 @@
 			(int) xv_get(ip->button3, XV_X) + spacing, NULL);
 		xv_set(ip->button4, XV_X, (int) xv_get(ip->button2, XV_WIDTH) +
 			(int) xv_get(ip->button2, XV_X) + spacing, NULL);
-		xv_set(quitbutton, XV_Y, (int) xv_get(Workman_window1->button2,
+		xv_set(quitbutton, XV_Y, (int) xv_get(ip->button2,
 			XV_Y), XV_X, (int) xv_get(ip->controls1, XV_WIDTH) -
 			(int) xv_get(quitbutton, XV_WIDTH) - spacing, NULL);
 #undef ip
@@ -431,7 +431,7 @@
 	static enum	cd_modes old_cdmode;
 	Xv_opaque	old_image;
 
-	if (xv_get(ip->mode, PANEL_VALUE) != 5 || ! dont_retry)
+	if (xv_get(ip->mode, PANEL_VALUE) != 5 || ! dont_retry) {
 		switch (cd_status()) {
 		case 0:		/* No CD in drive */
 			cur_cdmode = EJECTED;
@@ -460,6 +460,7 @@
 			new_cd_inserted(ip);
 			break;
 		}
+	}
 
 	old_cdmode = cur_cdmode;
 
--- plat_freebsd.c.orig	Thu Mar 31 21:12:20 1994
+++ plat_freebsd.c	Sun Apr 23 17:39:21 1995
@@ -8,11 +8,12 @@
  */
 static char *ident = "@(#)plat_freebsd.c	1.1 3/31/94";
 
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__NetBSD__)
 
 #include <errno.h>
 #include <stdio.h>
 #include <sys/types.h>
+#include <sys/param.h>
 #include <sys/mount.h>
 #include <fcntl.h>
 #include <sys/param.h>
@@ -22,8 +23,16 @@
 #include <sys/ioctl.h>
 #include <sys/cdio.h>
 #include <sys/scsiio.h>
+#ifdef __NetBSD__
+#define MSF_MINUTES 1
+#define MSF_SECONDS 2
+#define MSF_FRAMES 3
+#include "/sys/scsi/scsi_all.h"
+#include "/sys/scsi/scsi_cd.h"
+#else
 #include <scsi/scsi_all.h>
 #include <scsi/scsi_cd.h>
+#endif
 
 #include "struct.h"
 
@@ -31,8 +40,10 @@
 
 void *malloc();
 
-int	min_volume = 0;
-int	max_volume = 128;
+extern int	intermittent_dev;
+
+int	min_volume = 10;
+int	max_volume = 255;
 
 extern char	*cd_device;
 
@@ -89,9 +100,15 @@
 
 	*data = (toc_buffer.control != 0);
 
+#ifdef __NetBSD__
+	*startframe = toc_buffer.addr[MSF_MINUTES]*60*75 +
+		toc_buffer.addr[MSF_SECONDS] * 75 +
+		toc_buffer.addr[MSF_FRAMES];
+#else
 	*startframe = toc_buffer.addr.msf.minute*60*75 +
 		toc_buffer.addr.msf.second * 75 +
 		toc_buffer.addr.msf.frame;
+#endif
 
 	return (0);
 }
@@ -108,33 +125,8 @@
 	struct ioc_toc_header		hdr;
 	int status;
 
-	/*
-
-	*** FIX THIS ***
-
-	I can't figure out how to find the length of the last track.
-	The CDIOREADTOCENTRYS ioctl() in gen_get_trackinfo() returns an
-	error if I try to read past the last track returned by the
-	CDIOREADTOCHEADER ioctl().  There doesn't seem to be any other
-	way in cdio.h to get the length of a track.
-
-	This hack simply adds 10 minutes to the start of the last track
-	and returns the result as the total cd length.
-
-	Todd Pfaff
-	03/20/94
-
-	*/
-
-	if (ioctl(d->fd, CDIOREADTOCHEADER, &hdr))
-		return (-1);
-
-	if(gen_get_trackinfo(d, hdr.ending_track, &tmp, frames) == -1)
-		return (-1);
-
-	*frames += 10*60*75;
-
-	return(0);
+#define LEADOUT 0xaa			/* see scsi.c.  what a hack! */
+	return gen_get_trackinfo(d, LEADOUT, &tmp, frames);
 }
 
 /*
@@ -172,16 +164,23 @@
 		}
 	}
 
-	if (ioctl(d->fd, CDIOCREADSUBCHANNEL, &sc))
+	if (ioctl(d->fd, CDIOCREADSUBCHANNEL, &sc)) {
 		return (0);	/* ejected */
+	}
 
 	switch (scd.header.audio_status) {
 	case CD_AS_PLAY_IN_PROGRESS:
 		*mode = PLAYING;
 dopos:
+#ifdef __NetBSD__
+		*pos = scd.what.position.absaddr[MSF_MINUTES] * 60 * 75 +
+			scd.what.position.absaddr[MSF_SECONDS] * 75 +
+			scd.what.position.absaddr[MSF_FRAMES];
+#else
 		*pos = scd.what.position.absaddr.msf.minute * 60 * 75 +
 			scd.what.position.absaddr.msf.second * 75 +
 			scd.what.position.absaddr.msf.frame;
+#endif
 		*track = scd.what.position.track_number;
 		*index = scd.what.position.index_number;
 		break;
@@ -235,8 +234,7 @@
 scale_volume(vol, max)
 	int	vol, max;
 {
-	return ((max * max - (max - vol) * (max - vol)) *
-		(max_volume - min_volume) / (max * max) + min_volume);
+    return ((vol * (max_volume - min_volume)) / max + min_volume);
 }
 
 /*
@@ -250,6 +248,10 @@
 {
 	struct ioc_vol vol;
 
+	if (left < 0)	/* don't laugh, I saw this happen once! */
+	    left = 0;
+	if (right < 0)
+	    right = 0;
 	left = scale_volume(left, 100);
 	right = scale_volume(right, 100);
 
@@ -330,6 +332,7 @@
 	/* On some systems, we can check to see if the CD is mounted. */
 	struct stat	stbuf;
 	struct statfs	buf;
+	int rval;
 
 	if (fstat(d->fd, &stbuf) != 0)
 		return (-2);
@@ -338,7 +341,24 @@
 	if (fstatfs(stbuf.st_rdev, &buf) == 0)
 		return (-3);
 
-	return (ioctl(d->fd, CDIOCEJECT));
+#ifdef __NetBSD__
+	/* XXX the SCSI system locks up if an open disc is ejected.  sigh. */
+	rval = ioctl(d->fd, CDIOCALLOW);
+	if (rval == 0)
+#endif
+	    rval = ioctl(d->fd, CDIOCEJECT);
+#ifdef __NetBSD__
+	if (rval == 0)
+	    rval = ioctl(d->fd, CDIOCPREVENT);
+#endif
+	/* Close the device if it needs to vanish. */
+	if (intermittent_dev)
+	{
+		close(d->fd);
+		d->fd = -1;
+	}
+
+	return rval;
 }
 
 /*
@@ -419,6 +439,19 @@
 	int		retbuflen;
 	int		getreply;
 {
+#ifdef __NetBSD__
+
+#include <sys/scsiio.h>
+	scsireq_t sr;
+
+	sr.timeout = 1000;
+	memcpy(sr.cmd, cdb, 12);
+	sr.cmdlen = cdblen;
+	sr.databuf = retbuf;
+	sr.datalen = retbuflen;
+	sr.senselen = SENSEBUFLEN;
+	return(ioctl(d->fd, SCIOCCOMMAND, &sr));
+#endif
 	return (-1);
 }
 
@@ -437,6 +470,9 @@
 	if (d->fd >= 0)		/* Device already open? */
 		return (0);
 
+#ifdef __NetBSD__
+	intermittent_dev = 1;
+#endif
 	if (cd_device == NULL)
 		cd_device = DEFAULT_CD_DEVICE;
 
@@ -469,7 +505,10 @@
 
 	vendor[0] = model[0] = rev[0] = '\0';
 
+	wm_scsi_get_drive_type(d, vendor, model, rev);
+
 	*d = *(find_drive_struct(vendor, model, rev));
+	about_set_drivetype(d->vendor, d->model, rev);
 
 	(d->init)(d);
 
--boundary=_0--