abel deuring wrote:
> That's my fault: In the recent version, sanei_scsi_open calls
> sanei_scsi_open_extended, which allows variable buffer sizes for recent
> kernels. For older kernels, a fixes buffer size of SCSIBUFFERSIZE (= 128
> * 1024) is used. And that cannot work, because SG_BIG_BUFF is by default
> set to 128 * 1024 - 512. I'll fix that this eveing. (Sorry, I can't do
> that right now at work)
> 
> And updating the man page is indeed a good idea...
So, here is the bugfix. sanei_scsi.c should now work again with
SG_BIG_BUFF = 128 * 1024 - 512. (If I remember right, that was the
maximum value for older kernels.)
I also added a paragraph to the sane-scsi man page: How to change buffer
size for the recent versions of the SG driver.
Both patches are also "committed" to teh CVS server.
Abel
--- sane-scsi.man.orig	Mon Aug  9 20:05:41 1999
+++ sane-scsi.man	Sat Feb  5 00:50:04 2000
@@ -148,6 +148,18 @@
 bytes.  After changing this value, it is necessary to recompile both
 the kernel (or the SCSI generic module) and the SCSI backends.
 .PP
+From version 2.0 on, the maximum buffer size of Linux SG driver can
+be changed at program run time, and the restriction to 127 kB is also
+removed. This driver version is part of the Linux kernels from version 
+2.2.7 on. If larger buffers are reasonable for your scanner, set the
+environment variable
+.B SANE_SG_BUFFERSIZE
+to the desired buffer size in bytes. It is not recommended to use more 
+than 1 MB, because for large values the probablility increases that the 
+SG driver cannot allocate the necessary buffer(s). For ISA cards, even 
+1 MB might be a too large value. For a detailed discussion of memory 
+issues of the SG driver, see http::/www.torque.net/sg.
+.PP
 A common issue with SCSI scanners is what to do when you booted
 the system while the scanner was turned off?  In such a case, the
 scanner won't be recognized by the kernel and SANE won't be able
--- sanei_scsi.c.orig	Sun Jan 30 13:30:25 2000
+++ sanei_scsi.c	Sat Feb  5 00:24:41 2000
@@ -1248,10 +1248,10 @@
 sanei_scsi_open (const char *dev, int *fdp,
                 SANEI_SCSI_Sense_Handler handler, void *handler_arg)
 {
-  int i = 0;
+  int i = 0, fd, len;
   int wanted_buffersize = SCSIBUFFERSIZE, real_buffersize;
   SANE_Status res;
-  char *cc, *cc1;
+  char *cc, *cc1, buf[32];
 
   cc = getenv("SANE_SG_BUFFERSIZE");
   if (cc)
@@ -1261,6 +1261,40 @@
         wanted_buffersize = i;
     }
 
+  /* wanted_buffersize might be too big, if we have the old SG driver.
+     Therefore, check the driver version, and reduce wante_buffersize,
+     if necessary. Otherwise, sanei_scsi_open_extended will fail.
+  */
+  fd = open(dev, O_RDWR);
+  if (fd < 0)
+    {
+      res = SANE_STATUS_INVAL;
+      if (errno == EACCES)
+        res = SANE_STATUS_ACCESS_DENIED;
+      DBG(1, "sanei_scsi_open: open of `%s' failed: %s",
+          dev, strerror(errno));
+      return res;
+    }
+  
+  i = ioctl(fd, SG_GET_VERSION_NUM, &i);
+  close(fd);
+  if (i < 0)
+    {
+      /* we have the old driver */
+      fd = open("proc/sys/kernel/sg-big-buff", O_RDONLY);
+      if (fd > 0 && (len = read (fd, buf, sizeof (buf) - 1)) > 0)
+	{
+	  buf[len] = '\0';
+	  i = atoi (buf);
+	  if (wanted_buffersize > i)
+	    wanted_buffersize = i;
+	  close(fd);
+	}
+      else
+        if (wanted_buffersize > SG_BIG_BUFF)
+          wanted_buffersize = SG_BIG_BUFF;
+    }
+  
   real_buffersize = wanted_buffersize;
   res = sanei_scsi_open_extended(dev, fdp, handler, handler_arg,
                                  &real_buffersize);
-- Source code, list archive, and docs: http://www.mostang.com/sane/ To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com
This archive was generated by hypermail 2b29 : Fri Feb 04 2000 - 16:58:12 PST