[sane-devel] [fujitsu] scsi-buf-size patch

Paul Walmsley paul@booyaka.com
Tue, 6 Jul 2004 00:58:38 -0600 (MDT)


Hello,

Most Fujitsu M30xx series scanners without CMP-2 boards installed require
that all image data be read in a single SCSI read.  Otherwise, a partial 
page image is returned, with the rest of the page set to black.  

The user should be able to work around this problem by setting the
"scsi-buf-size" parameter in the fujitsu.conf configuration file to the
total size of the image, and setting the SANE_SG_BUFFERSIZE environment
variable to the same value.  However, a bug in sane-fujitsu currently
prevents any SCSI buffer size setting larger than the default
sanei_scsi_max_request_size from taking effect, and 
sanei_scsi_max_request_size is often much smaller than what is necessary.

The enclosed patch fixes this and applies to CVS head as well as
sane-backends-1.0.14.  It works well with the M3097G scanner that I've 
tested it with.  

(Note also that due to a quirk in sane-fujitsu's option parsing code, 
the "scsi-buf-size" directive must appear in the configuration file 
_before_ any "scsi" option.)

Thanks to the sane-fujitsu hackers for a very useful driver!


- Paul


--- sane-backends-1.0.14/backend/fujitsu.c	2004-03-04 13:09:56.000000000 -0700
+++ sane-backends-1.0.14-patched/backend/fujitsu.c	2004-07-05 23:25:15.241452840 -0600
@@ -501,20 +501,19 @@
             {
               int buf;
               lp += 16;
               lp = sanei_config_skip_whitespace (lp);
               buf = atoi (lp);
-              if ((buf >= 4096) && (buf <= sanei_scsi_max_request_size))
+              if (buf >= 4096)
                 {
                   scsiBuffer = buf;
                 }
               else
                 {
                   DBG (MSG_ERR, 
                        "sane_init: configuration option \"scsi-buffer-"
-                       "size\" is outside allowable range of 4096..%d",
-                       sanei_scsi_max_request_size);
+                       "size\" must be larger than 4096");
                 }
             }
           else
             {
               DBG (MSG_ERR,
@@ -2503,10 +2502,19 @@
 
   if (NULL == (dev = malloc (sizeof (*dev))))
     return SANE_STATUS_NO_MEM;
   memset(dev,0,sizeof(*dev));
 
+  if (scsiBuffer > sanei_scsi_max_request_size) {
+    scsiBuffer = sanei_scsi_max_request_size;
+    DBG (MSG_ERR, 
+	 "sane_init: configuration option \"scsi-buffer-"
+	 "size\" is larger than allowable maximum %d", 
+	 sanei_scsi_max_request_size);
+  };
+    
+  DBG (15, "attach_scanner: setting scsi_buf_size to %d\n", scsiBuffer);
   dev->scsi_buf_size = scsiBuffer;
 
   if ((dev->buffer = malloc (dev->scsi_buf_size)) == NULL)
     return SANE_STATUS_NO_MEM;