find-scanner & SCSI generic test [patch]

Nick Lamb (njl98r@ecs.soton.ac.uk)
Sat, 22 May 1999 04:28:21 +0100 (GMT)

After I sent my original patch to the list a week or so ago, I was asked
to alter it so that future kernel changes were less likely to disrupt
operation on any Linux or Linux-like system. Here's the new version of
the patch (you'll have to back the old one out if you've applied it)

For those who missed this the first time -
Not all SANE first-timers realise that they need SCSI drivers, and in
particular SCSI generic drivers, before SANE can talk to their scanner.
This patch checks (on Linux only so far) for SCSI Generic support in
the OS kernel. If NOT present it tells the user they may need SG drivers

Nick.

--- find-scanner.c.old Tue May 11 15:30:07 1999
+++ find-scanner.c Sat May 22 04:14:46 1999
@@ -74,6 +74,38 @@
fprintf (stderr, "\t%s\n", msg);
}

+/* if SCSI generic is optional on your OS, and there is a software test
+ which will determine if it is included, add it here. If you are sure
+ that SCSI generic was found, return 1. If SCSI generic is always
+ available in your OS, return 1 */
+
+int
+check_sg (void)
+{
+#if defined(__linux__)
+ /* Assumption: /proc/devices lines are shorter than 256 characters */
+ char line[256], driver[256]= "";
+ FILE *stream;
+
+ stream= fopen("/proc/devices", "r");
+ /* Likely reason for failure, no /proc => probably no SG either */
+ if (stream == NULL) return 0;
+
+ while (fgets(line, 255, stream)) {
+ if (sscanf(line, " %*d %s\n", driver) > 0 && !strcmp(driver, "sg"))
+ break;
+ }
+ fclose(stream);
+
+ if (strcmp(driver, "sg")) {
+ return 0;
+ } else {
+ return 1;
+ }
+#endif
+ return 1; /* Give up, and assume yes to avoid false negatives */
+}
+
void
scanner_do_inquiry (unsigned char *buffer, int sfd)
{
@@ -408,6 +440,13 @@
sanei_scsi_close (sfd);
}
}
+ if (!check_sg()) {
+ printf (
+ "# If your scanner uses SCSI, you must have a driver for your SCSI\n"
+ "# adaptor and support for SCSI Generic (sg) in your Operating System\n"
+ "# in order for the scanner to be used with SANE. If your scanner is\n"
+ "# NOT listed above, check that you have installed the drivers.\n\n");
+ }
if (verbose)
printf ("%s: done\n", prog_name);
return 0;

--
Source code, list archive, and docs: http://www.mostang.com/sane/
To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com