Re: Sane on NeXT/OpenStep - a plea for help

David Mosberger-Tang (davidm@azstarnet.com)
Sun, 15 Jun 1997 16:33:29 -0700

>>>>> On 15 Jun 1997 17:12:59 -0600, Gordon Matzigkeit <gord@m-tech.ab.ca> said:

Gord> If you want to give me access to your OpenStep box, which you
Gord> offered, then I would be more than happy to help port SANE to
Gord> OpenStep. If you're interested, I like accounts named
Gord> `gord'. ;)

I already offered the same to Neville, but wouldn't mind if you'd take
over. Here are the patches I have come up with based on the OpenStep
version of pnmscan. They probably won't compile, but should be really
close to what's needed.

Happy hacking,

--david

--
diff -urN sane-0.6/configure.in sane-0.61/configure.in
--- sane-0.6/configure.in	Fri Jun 13 18:28:34 1997
+++ sane-0.61/configure.in	Sun Jun 15 10:08:42 1997
@@ -31,7 +31,8 @@
 dnl Checks for header files.
 AC_HEADER_STDC
 AC_CHECK_HEADERS(fcntl.h unistd.h libintl.h sys/scanio.h \
-    scsi.h sys/scsi.h sys/scsiio.h scsi/sg.h /usr/src/linux/include/scsi/sg.h)
+    scsi.h sys/scsi.h sys/scsiio.h bsd/dev/scsireg.h \
+    scsi/sg.h /usr/src/linux/include/scsi/sg.h)
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
diff -urN sane-0.6/include/sane/config.h.in sane-0.61/include/sane/config.h.in
--- sane-0.6/include/sane/config.h.in	Fri Jun 13 18:51:05 1997
+++ sane-0.61/include/sane/config.h.in	Sun Jun 15 10:09:39 1997
@@ -199,6 +199,9 @@
 /* Define if you have the <sys/scanio.h> header file. */
 #undef HAVE_SYS_SCANIO_H
 
+/* Define if you have the <bsd/dev/scsireg.h> header file. */
+#undef HAVE_BSD_DEV_SCSIREG_H
+
 /* Define if you have the <unistd.h> header file.  */
 #undef HAVE_UNISTD_H
 
diff -urN sane-0.6/sanei/sanei_scsi.c sane-0.61/sanei/sanei_scsi.c
--- sane-0.6/sanei/sanei_scsi.c	Sat Jun 14 14:33:48 1997
+++ sane-0.61/sanei/sanei_scsi.c	Sun Jun 15 10:19:11 1997
@@ -44,6 +44,7 @@
 
 #include <lalloca.h>	/* MUST come first for AIX! */
 
+#include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdlib.h>
@@ -67,6 +68,9 @@
 #    ifdef HAVE_SCSI_H
 #     include <scsi.h>
 #     define scsireq_t struct scsireq_t
+#     ifdef HAVE_BSD_DEV_SCSIREG_H
+#      include <bsd/dev/scsireg.h>
+#     endif
 #    endif
 #   endif
 #  endif
@@ -90,6 +94,8 @@
 static int num_handlers_alloced = 0;
 static SANEI_SCSI_Sense_Handler *sense_handler = 0;
 
+static u_char cdb_size[8] = {6, 10, 10, 12, 12, 12, 10, 10};
+#define CDB_SIZE(opcode)	(((opcode) >> 5) & 7)
 
 SANE_Status
 sanei_scsi_open (const char * dev, int * fdp, SANEI_SCSI_Sense_Handler handler)
@@ -222,32 +228,30 @@
 sanei_scsi_cmd (int fd, const void * src, size_t src_size,
 		void * dst, size_t * dst_size)
 {
+  size_t cdb_size;
   scsireq_t hdr;
-  size_t cmd_len;
 
-  cmd_len = ((u_char *) src)[0] == 0x55 ? 10 : 6;
+  cdb_size = CDB_SIZE (*(u_char *) src);
 
   memset (&hdr, 0, sizeof (hdr));
-  memcpy (hdr.cmd, src, cmd_len);
-  src_size -= cmd_len;
-  src = (char *) src + cmd_len;
-
   if (*dst_size)
     {
+      assert (cdb_size == src_size);
       hdr.flags = SCCMD_READ;
       hdr.databuf = dst;
     }
   else
     {
+      assert (cdb_size <= src_size);
       hdr.flags = SCCMD_WRITE;
-      hdr.databuf = src;
+      hdr.databuf = (char *) src + cdb_size;
     }
+  memcpy (hdr.cmd, src, cdb_size);
   hdr.timeout = 60000;			/* 1 minute timeout */
 
   if (scsireq_enter (fd, &hdr) < 0)
     {
-      DBG(1, "sanei_scsi_cmd: scsi_reqenter() failed: %s\n",
-	  strerror (errno));
+      DBG(1, "sanei_scsi_cmd: scsi_reqenter() failed: %s\n", strerror (errno));
       return SANE_STATUS_IO_ERROR;
     }
 
@@ -301,6 +305,53 @@
   return SANE_STATUS_UNSUPPORTED;
 }
 
+#   ifdef /* HAVE_BSD_DEV_SCSIREG_H */
+
+/* This is for NeXtStep/OpenStep and possibility other Mach 2.5 based
+   systems.  */
+
+SANE_Status
+sanei_scsi_cmd (int fd, const void * src, size_t src_size,
+		void * dst, size_t * dst_size)
+{
+  struct scsi_req hdr;
+  size_t cdb_size;
+
+  cdb_size = CDB_SIZE (*(u_char *) src);
+
+  memset (&hdr, 0, sizeof (sr));
+  if (*dst_size)
+    {
+      assert (cdb_size == src_size);
+      hdr.sr_dma_dir = SR_DMA_RD;
+      hdr.sr_addr = dst;
+      hdr.sr_dma_max = dst_size;
+    }
+  else
+    {
+      assert (cdb_size <= src_size);
+      hdr.sr_dma_dir = SR_DMA_WR;
+      hdr.sr_addr = (char *) src + cdb_size;
+      hdr.sr_dma_max = src_size - cdb_size;
+    }
+  memcpy (&hdr.sr_cdb, src, cdb_size);
+  hdr.sr_ioto = 60;		/* I/O timeout in seconds */
+
+  if (ioctl (fd, SGIOCREQ, &hdr) == -1)
+    {
+      DBG(1, "sanei_scsi_cmd: ioctl(SGIOCREQ) failed: %s\n", strerror (errno));
+      return SANE_STATUS_IO_ERROR;
+    }
+  if (hdr.sr_io_status)
+    DBG(1, "sanei_scsi_cmd: SGIOCREQ completed with sr_io_status=%d\n",
+	hdr.sr_io_status);
+  if ((hdr.sr_sense[0] & 0x80)
+      && (fd < num_handlers_alloced) && sense_handler[fd])
+    return (*sense_handler[fd]) (fd, hdr.sense);
+  return SANE_STATUS_GOOD;
+}
+
+#   endif /* !HAVE_BSD_DEV_SCSIREG_H */
 #  endif /* !HAVE_SYS_SCSI_H */
 # endif /* !HAVE_SYS_SCSIIO_H */
 #endif /* !HAVE_SCSI_SG_H */

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