pre-0.63 patch

David Mosberger-Tang (davidm@azstarnet.com)
Wed, 13 Aug 1997 16:59:14 -0700

Below is a pre-patch for those interested in trying out the very
latest sources. The main change is that there should be now working
support for the Irix generic SCSI interface and prelimenary support
for the SCO generic SCSI interface. I'll be moving out of Tucson in a
few days to take a job in the Bay Area, so I wanted to get the latest
code out before tearing down the Internet connection. I hope to find
some time to make additional improvements to SANE between now and
Sep. 1st, but that depends a little bit on how hairy the move will
be... ;-)

So, for now, try out the code below if you're adventurous.

Happy hacking,

--david

diff -urN sane-0.62/ChangeLog sane-pre0.63/ChangeLog
--- sane-0.62/ChangeLog Sat Jul 26 16:43:43 1997
+++ sane-pre0.63/ChangeLog Fri Aug 8 07:18:13 1997
@@ -1,3 +1,35 @@
+1997-08-07 David Mosberger-Tang <davidm@azstarnet.com>
+
+ * backend/mustek.c (attach): Print Mustek scanner info at
+ debug level 2, not 3.
+
+1997-08-06 David Mosberger-Tang <davidm@azstarnet.com>
+
+ * frontend/preview.c (XSERVER_WITH_BUGGY_VISUALS): Make conditional
+ on #ifdef __alpha__ (Michael Sweet reports that the old code broke
+ SGI IRIX 6.3).
+
+1998-08-01 David Mosberger-Tang <davidm@azstarnet.com>
+
+ * include/sane/config.h.in (HAVE_SYS_SCSICMD_H, HAVE_SYS_DSREQ_H):
+ Undefine.
+
+ * configure.in (AC_CHECK_HEADERS): Mention sys/scsicmd.h and
+ sys/dsreq.h.
+
+ * sanei/sanei_scsi.c (SCO_OS55_INTERFACE, IRIX_INTERFACE,
+ SOLARIS_INTERFACE): Define.
+
+1997-07-27 David Mosberger-Tang <davidm@azstarnet.com>
+
+ * frontend/xscanimage.c (quit_xscan) [HAVE_LIBGIMP_GIMP_H]: When
+ running as a GIMP extension, call gimp_quit().
+ (init) [HAVE_LIBGIMP_GIMP_H]: Set GDK's xshm flag based on GIMP's
+ flag.
+
+ * doc/sane-mustek.man (SCSI ADAPTER TIPS): Try to make complete
+ sentences.
+
1997-07-25 David Mosberger-Tang <davidm@azstarnet.com>

* Version 0.62 released.
diff -urN sane-0.62/PROJECTS sane-pre0.63/PROJECTS
--- sane-0.62/PROJECTS Sun Jul 6 09:21:47 1997
+++ sane-pre0.63/PROJECTS Wed Aug 6 07:39:00 1997
@@ -1,4 +1,4 @@
-Sat Jun 28 10:02:05 1997
+Wed Aug 6 07:38:25 1997

Here is a list of projects that various people have expressed interest
in. Before starting working on one of these projects, it may be a
@@ -18,6 +18,7 @@

Backend: Status: Contact: available hw:
-------- ------- ---------------------------------------- -------------
+Coolscan planned Didier Carlier <carlierd@acm.org> Nikon Coolscan II
EpsPhoto wanted Jeff Tranter <tranter@software.Mitel.COM>PhotoPC500 (want)
Kodak wanted John Kodis <kodis@kodis.jagunet.com> Kodak DS-20 (want)
autoadj planned David Mosberger
diff -urN sane-0.62/README sane-pre0.63/README
--- sane-0.62/README Sat Jul 26 16:28:12 1997
+++ sane-pre0.63/README Sun Jul 27 08:06:11 1997
@@ -68,7 +68,8 @@

--disable-shared
Don't use shared libraries. Useful for debugging or when there
- is a problem building shared libraries.
+ is a problem building shared libraries. This implicitly turns
+ on --disable-dynamic as well.

--disable-ld-fix
Turn off a bug fix in the Mustek backend. See sane-mustek(5)
@@ -101,7 +102,7 @@
the compiler flags when using HP's C compiler (not gcc). This can be
done by invoking configure with:

- CPPFLAGS=-D_HPUX_SOURCE CFLAGS=-Aa ./configure
+ CC=cc CPPFLAGS=-D_HPUX_SOURCE CFLAGS=-Aa ./configure

* Build

diff -urN sane-0.62/backend/mustek.c sane-pre0.63/backend/mustek.c
--- sane-0.62/backend/mustek.c Fri Jul 25 16:30:42 1997
+++ sane-pre0.63/backend/mustek.c Thu Aug 7 08:09:53 1997
@@ -478,7 +478,7 @@
if (result[63] & (1 << 6))
dev->flags |= MUSTEK_FLAG_TA;

- DBG(3, "attach: found Mustek scanner model %s (%s), %s%s%s\n",
+ DBG(2, "attach: found Mustek scanner model %s (%s), %s%s%s\n",
dev->sane.model, dev->sane.type,
(dev->flags & MUSTEK_FLAG_SINGLE_PASS) ? "1-pass" : "3-pass",
(dev->flags & MUSTEK_FLAG_ADF) ? ", ADF" : "",
diff -urN sane-0.62/configure sane-pre0.63/configure
--- sane-0.62/configure Sat Jul 26 16:43:56 1997
+++ sane-pre0.63/configure Fri Aug 8 07:21:21 1997
@@ -1159,9 +1159,9 @@

fi

-for ac_hdr in fcntl.h unistd.h libintl.h libc.h sys/select.h \
- sys/scanio.h scsi.h sys/scsi.h sys/scsiio.h bsd/dev/scsireg.h \
- scsi/sg.h /usr/src/linux/include/scsi/sg.h io/cam/cam.h
+for ac_hdr in fcntl.h unistd.h libintl.h libc.h sys/dsreq.h sys/select.h \
+ sys/scanio.h scsi.h sys/scsi.h sys/scsicmd.h sys/scsiio.h \
+ bsd/dev/scsireg.h scsi/sg.h /usr/src/linux/include/scsi/sg.h io/cam/cam.h
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
diff -urN sane-0.62/configure.in sane-pre0.63/configure.in
--- sane-0.62/configure.in Sat Jul 26 16:43:21 1997
+++ sane-pre0.63/configure.in Fri Aug 8 07:19:43 1997
@@ -36,9 +36,9 @@

dnl Checks for header files.
AC_HEADER_STDC
-AC_CHECK_HEADERS(fcntl.h unistd.h libintl.h libc.h sys/select.h \
- sys/scanio.h scsi.h sys/scsi.h sys/scsiio.h bsd/dev/scsireg.h \
- scsi/sg.h /usr/src/linux/include/scsi/sg.h io/cam/cam.h)
+AC_CHECK_HEADERS(fcntl.h unistd.h libintl.h libc.h sys/dsreq.h sys/select.h \
+ sys/scanio.h scsi.h sys/scsi.h sys/scsicmd.h sys/scsiio.h \
+ bsd/dev/scsireg.h scsi/sg.h /usr/src/linux/include/scsi/sg.h io/cam/cam.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
diff -urN sane-0.62/doc/sane-mustek.man sane-pre0.63/doc/sane-mustek.man
--- sane-0.62/doc/sane-mustek.man Fri Jul 25 16:52:58 1997
+++ sane-pre0.63/doc/sane-mustek.man Sun Jul 27 08:18:49 1997
@@ -100,14 +100,18 @@
should consider that Mustek scanners do not support the SCSI-2
disconnect/reconnect protocol and hence tie up the SCSI bus while a
scan is in progress. This means that no other SCSI device on the same
-bus can be accessed while a scan is in progress. With
+bus can be accessed while a scan is in progress.
.PP
-In general, it is therefore recommended to purchase a separate (cheap)
-SCSI card for the Mustek scanners. For example, ncr810 based cards
-are known to work fine and can be had for around fifty US dollars.
+Because the Mustek-supplied adapter is not worth much and because
+Mustek scanners do not support the SCSI-2 disconnect/reconnect
+protocol, it is recommended to install a separate (cheap) SCSI
+controller for Mustek scanners. For example, ncr810 based cards are
+known to work fine and cost as little as fifty US dollars.
.PP
-Also, for Mustek scanners it is typically necessary to disable
-synchronous transfers, tagged command queuing, and target disconnects.
+For Mustek scanners, it is typically necessary to configure the
+low-level SCSI driver to disable synchronous transfers, tagged command
+queuing, and target disconnects. See sane-scsi(5) for driver and
+platform-specific information.
.SH FILES
.TP
.I @CONFIGDIR@/mustek.conf
diff -urN sane-0.62/frontend/preview.c sane-pre0.63/frontend/preview.c
--- sane-0.62/frontend/preview.c Fri Jul 18 21:49:38 1997
+++ sane-pre0.63/frontend/preview.c Wed Aug 6 07:48:39 1997
@@ -86,11 +86,13 @@

#define MM_PER_INCH 25.4

-/* This seems to be necessary for at least some XFree86 3.1.2 servers.
- It's known to be necessary for the XF86_TGA server for Linux/Alpha.
- Fortunately, it's no great loss so we turn this on by default for
- now. */
-#define XSERVER_WITH_BUGGY_VISUALS
+#ifdef __alpha__
+ /* This seems to be necessary for at least some XFree86 3.1.2
+ servers. It's known to be necessary for the XF86_TGA server for
+ Linux/Alpha. Fortunately, it's no great loss so we turn this on
+ by default for now. */
+# define XSERVER_WITH_BUGGY_VISUALS
+#endif

/* forward declarations */
static void scan_start (Preview *p);
diff -urN sane-0.62/frontend/xscanimage.c sane-pre0.63/frontend/xscanimage.c
--- sane-0.62/frontend/xscanimage.c Mon Jul 14 20:11:54 1997
+++ sane-pre0.63/frontend/xscanimage.c Sun Jul 27 14:49:07 1997
@@ -440,6 +440,10 @@
sane_close (gsg_dialog_get_device (dialog));
sane_exit ();
gtk_main_quit ();
+#ifdef HAVE_LIBGIMP_GIMP_H
+ if (ScanWin.mode == GIMP_EXTENSION)
+ gimp_quit ();
+#endif
exit (1);
}

@@ -1548,6 +1552,8 @@
gtk_init (&argc, &argv);
#ifdef HAVE_LIBGIMP_GIMP_H
gtk_rc_parse (gimp_gtkrc ());
+
+ gdk_set_use_xshm (gimp_use_xshm ());
#endif

gsg_make_path (sizeof (filename), filename, 0, "sane-style", 0, ".rc");
diff -urN sane-0.62/include/sane/config.h.in sane-pre0.63/include/sane/config.h.in
--- sane-0.62/include/sane/config.h.in Mon Jul 7 20:45:12 1997
+++ sane-pre0.63/include/sane/config.h.in Fri Aug 8 07:20:16 1997
@@ -211,8 +211,14 @@
/* Define if you have the "/usr/src/linux/include/scsi/sg.h" header file. */
#undef HAVE__USR_SRC_LINUX_INCLUDE_SCSI_SG_H

+/* Define if you have the <sys/dsreq.h> header file. */
+#undef HAVE_SYS_DSREQ_H
+
/* Define if you have the <sys/scsi.h> header file. */
#undef HAVE_SYS_SCSI_H
+
+/* Define if you have the <sys/scsicmd.h> header file. */
+#undef HAVE_SYS_SCSICMD_H

/* Define if you have the <sys/scsiio.h> header file. */
#undef HAVE_SYS_SCSIIO_H
diff -urN sane-0.62/sanei/sanei_scsi.c sane-pre0.63/sanei/sanei_scsi.c
--- sane-0.62/sanei/sanei_scsi.c Sat Jul 19 09:51:35 1997
+++ sane-pre0.63/sanei/sanei_scsi.c Fri Aug 8 07:21:07 1997
@@ -53,6 +53,7 @@

#include <sys/ioctl.h>
#include <sys/param.h>
+#include <sys/types.h>

#define STUBBED_INTERFACE 0
#define LINUX_INTERFACE 1
@@ -60,6 +61,9 @@
#define HPUX_INTERFACE 3
#define OPENSTEP_INTERFACE 4
#define DECUNIX_INTERFACE 5
+#define SCO_OS5_INTERFACE 6
+#define IRIX_INTERFACE 7
+#define SOLARIS_INTERFACE 8

#ifdef HAVE_SCSI_SG_H
# define USE LINUX_INTERFACE
@@ -69,13 +73,10 @@
# define USE LINUX_INTERFACE
# include "/usr/src/linux/include/scsi/sg.h"
# else
-# ifdef HAVE_SYS_SCSI_H
+# ifdef HAVE_SYS_SCSICMD
+# define USE SCSO_OS5_INTERFACE
# include <sys/scsi.h>
-# ifdef SCTL_READ
-# define USE HPUX_INTERFACE
-# else
- /* This happens for AIX... */
-# endif
+# include <sys/scsicmd.h>
# else
# ifdef HAVE_SYS_SCSIIO_H
# define USE BSD_INTERFACE
@@ -95,6 +96,20 @@
# include <io/cam/dec_cam.h>
# include <io/cam/uagt.h>
# include <io/cam/scsi_all.h>
+# else
+# ifdef HAVE_SYS_DSREQ_H
+# define USE IRIX_INTERFACE
+# include <sys/dsreq.h>
+# else
+# ifdef HAVE_SYS_SCSI_H
+# include <sys/scsi.h>
+# ifdef SCTL_READ
+# define USE HPUX_INTERFACE
+# else
+ /* This happens for AIX and possibly other platforms... */
+# endif
+# endif
+# endif
# endif
# endif
# endif
@@ -765,6 +780,61 @@
#endif /* USE == DECUNIX_INTERFACE */


+#if USE == SCO_OS5_INTERFACE
+SANE_Status
+sanei_scsi_cmd (int fd, const void * src, size_t src_size,
+ void * dst, size_t * dst_size)
+{
+ static u_char sense_buffer[256];
+ struct scsicmd2 sc2;
+ struct scsicmd *sc;
+ int cdb_size;
+ int opcode;
+ int i;
+
+ if (fd < 0)
+ return SANE_STATUS_IO_ERROR;
+
+ memset (&sc2, 0, sizeof (sc2));
+ sc = &sc2.cmd;
+ sc2.sense_len = sizeof (sense_buffer);
+ sc2.sense_ptr = sense_buffer;
+
+ cdb_size = CDB_SIZE (*(u_char *) src);
+ if (dst_size && *dst_size)
+ {
+ sc->is_write = 0;
+ sc->data_ptr = dst;
+ sc->data_len = *dst_size;
+ }
+ else
+ {
+ sc->data_len = src_size - cdb_size;
+ sc->data_ptr = (char *) src + cdb_size;
+ sc->is_write = 1;
+ }
+ memcpy (sc->cdb, src, cdb_size);
+ sc->cdb_len = cdb_size;
+
+ /* Send the command down via the "pass-through" interface */
+ if (ioctl (fd, SCSIUSERCMD2, &sc2) < 0)
+ {
+ DBG(1, "sanei_scsi_cmd: ioctl(SCSIUSERCMD2) failed: %s\n",
+ strerror (errno));
+ return SANE_STATUS_IO_ERROR;
+ }
+ if (sc->host_sts || sc->target_sts)
+ {
+ DBG(1, "sanei_scsi_cmd: SCSIUSERCMD2 completed with "
+ "host_sts=%x, target_sts=%x\n", sc->host_sts, sc->target_sts);
+ if (fd_info[fd].sense_handler)
+ return (*fd_info[fd].sense_handler) (fd, sense_buffer);
+ return SANE_STATUS_IO_ERROR;
+ }
+ return SANE_STATUS_GOOD;
+}
+#endif /* USE == SCO_OS5_INTERFACE */
+
#if USE == STUBBED_INTERFACE
SANE_Status
sanei_scsi_cmd (int fd, const void * src, size_t src_size,
@@ -773,6 +843,67 @@
return SANE_STATUS_UNSUPPORTED;
}
#endif /* USE == STUBBED_INTERFACE */
+
+#if USE == IRIX_INTERFACE
+SANE_Status
+sanei_scsi_cmd(int fd, const void *src, size_t src_size,
+ void *dst, size_t *dst_size)
+{
+ dsreq_t scsi_req; /* SCSI request */
+ u_char sensebuf[1024]; /* Request sense buffer */
+ size_t cdb_size; /* Size of SCSI command */
+
+ cdb_size = CDB_SIZE (*(u_char *)src);
+
+ memset (&scsi_req, 0, sizeof (scsi_req));
+
+ if (dst != NULL)
+ {
+ /*
+ * SCSI command returning/reading data...
+ */
+ scsi_req.ds_flags = DSRQ_READ | DSRQ_SENSE;
+ scsi_req.ds_time = 120 * 1000;
+ scsi_req.ds_cmdbuf = (caddr_t)src;
+ scsi_req.ds_cmdlen = cdb_size;
+ scsi_req.ds_databuf = (caddr_t)dst;
+ scsi_req.ds_datalen = *dst_size;
+ scsi_req.ds_sensebuf = (caddr_t)sensebuf;
+ scsi_req.ds_senselen = sizeof(sensebuf);
+ }
+ else
+ {
+ /*
+ * SCSI command sending/writing data...
+ */
+ scsi_req.ds_flags = DSRQ_WRITE | DSRQ_SENSE;
+ scsi_req.ds_time = 120 * 1000;
+ scsi_req.ds_cmdbuf = (caddr_t)src;
+ scsi_req.ds_cmdlen = cdb_size;
+ scsi_req.ds_databuf = (caddr_t)src + cdb_size;
+ scsi_req.ds_datalen = src_size - cdb_size;
+ scsi_req.ds_sensebuf = (caddr_t)sensebuf;
+ scsi_req.ds_senselen = sizeof(sensebuf);
+ }
+
+ if (ioctl(fd, DS_ENTER, &scsi_req) < 0 || scsi_req.ds_status != 0)
+ {
+ DBG(1, "sanei_scsi_cmd: SCSI command failed: %s\n", strerror(errno));
+
+ if (scsi_req.ds_status == STA_BUSY)
+ return SANE_STATUS_DEVICE_BUSY;
+ else if ((sensebuf[0] & 0x80) && fd_info[fd].sense_handler)
+ return (*fd_info[fd].sense_handler)(fd, sensebuf);
+ else
+ return SANE_STATUS_IO_ERROR;
+ }
+
+ if (dst_size != NULL)
+ *dst_size = scsi_req.ds_datasent;
+
+ return SANE_STATUS_GOOD;
+}
+#endif /* USE == IRIX_INTERFACE */

#ifndef WE_HAVE_ASYNC_SCSI

--
Source code, list archive, and docs: http://www.azstarnet.com/~axplinux/sane/
To unsubscribe: mail -s unsubscribe sane-devel-request@listserv.azstarnet.com