[PARTIALLY SOLVED] "I/O error" with Kodak i1210 high-speed Scanner and saned over net

Background: A recurring problem with using saned over the network is an incomprehensible "I/O error" with a variety of scanners.

Platform: fresh install of Ubuntu lucid 10.04 and a freshly compiled sane-backends 1.0.22, with a new Kodak i1210 scanner

Author: Lawrence Widman
Date: 11/02/2011

Methods: I found the following:

Partial Solution: The following patch fixes the 4th situation (but not the 3rd) imperfectly: the first scanned page is lost completely. However, if the length is not set to zero, the first two pages are mixed together and only the third and subsequent pages of a batch are scanned and transmitted correctly. The patched version of sane is installed into /usr/local/sbin/ and the file /etc/xinetd.d/saned is updated accordingly:
 # server    = /usr/sbin/saned
 server      = /usr/local/sbin/saned
Thus, this patch allows the scanner to be used over the net using sane at the cost of having to place a placeholder sheet before the first page that is to be scanned (since the first scanned page is discarded, the placeholder is discarded and the first "real" sheet is the second in the batch to be scanned). The questions now are: I do not think the Kodak i1210 scanner is responsible because it works flawlessly via its local usb connection and because the same error has been reported with other scanners. Please note that I did not test this patch by actually jamming the scanner to make sure it would signal the error.

(submitted to the sane-devel maillist here.)

diff -rc sane-backends-1.0.22/frontend/saned.c sane-backends-1.0.22.new/frontend/saned.c
*** sane-backends-1.0.22/frontend/saned.c       2010-12-01 17:49:58.000000000 -0600
--- sane-backends-1.0.22.new/frontend/saned.c   2011-11-01 21:55:34.000000000 -0500
*** 1753,1758 ****
--- 1753,1772 ----
          status = sane_read (be_handle, buf + reader, nbytes, &length);
          DBG (DBG_INFO,
               "do_scan: read %d bytes from scanner\n", length);
+         /* 2011-11-01 L Widman */
+           // for some reason, the first bufferful comes with status SANE_STATUS_JAMMED
+           // which is separate from the scanner being empty later, and the first page
+           // is not read completely.
+           //   Setting the initial length to 0 essentially discards the first page and
+           // allows the remaining pages to be read and transmitted normally.
+           //   Note that reader == 4 only during the first iteration unless it exceeds sizeof(buf)
+           if( (reader == 4) && (status == SANE_STATUS_JAMMED) ){
+             DBG (DBG_INFO,
+                "do_scan: accepting %d bytes from scanner despite status %s\n", length, sane_strstatus(status));
+             status = SANE_STATUS_GOOD;
+             length = 0;
+           }
+         /* 2011-11-01 L Widman */

          reset_watchdog ();