[patch] Updated patch for IRIX (and other UNIX's)

Michael Sweet (mike@easysw.com)
Mon, 21 Dec 1998 11:01:30 -0500

This is a multi-part message in MIME format.
--------------095D4C1A9D918F514478DFB5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Attached is an updated patch from the original SANE 1.00 sources.
This patch was generated with:

diff -rc sane-1.00 sane >sane2.patch

With any luck this patch should work with all versions of patch, GNU
or otherwise. You'll need to apply this at the directory above the
SANE distribution directory; that is, if your sane source is in
"/home/user/sane-1.00", you'll want to do:

cd /home/user
patch <sane2.patch

This patch fixes the following new problems:

- The Abaton backend needed the sanei_config object file.

- The IRIX SCSI support didn't handle misaligned SCSI buffers.
The new version here copies everything to and from aligned
buffers to prevent problems. This appears only to be an
issue with older SGI machines (Indigo, Indigo2, etc.) and
not with any of the newer "O" series machines.

Enjoy!

-- 
______________________________________________________________________
Michael Sweet, Easy Software Products                  mike@easysw.com
Printing Software for UNIX                       http://www.easysw.com
--------------095D4C1A9D918F514478DFB5
Content-Type: text/plain; charset=us-ascii;
 name="sane2.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="sane2.patch"

diff -rc sane-1.00/backend/Makefile.in sane/backend/Makefile.in *** sane-1.00/backend/Makefile.in Sat Nov 21 22:57:33 1998 --- sane/backend/Makefile.in Thu Dec 10 15:50:15 1998 *************** *** 152,157 **** --- 152,158 ---- # to any of the sanei routines. These explicit dependencies take care of # this: + libsane-abaton.la: ../sanei/sanei_config2.lo libsane-abaton.la: ../sanei/sanei_constrain_value.lo libsane-abaton.la: ../sanei/sanei_scsi.lo libsane-agfafocus.la: ../sanei/sanei_config2.lo *************** *** 198,203 **** --- 199,205 ---- libsane-pint.la: ../sanei/sanei_constrain_value.lo libsane-pnm.la: ../sanei/sanei_constrain_value.lo libsane-qcam.la: ../sanei/sanei_constrain_value.lo + libsane-ricoh.la: ../sanei/sanei_config2.lo libsane-ricoh.la: ../sanei/sanei_constrain_value.lo libsane-ricoh.la: ../sanei/sanei_scsi.lo libsane-s9036.la: ../sanei/sanei_config2.lo diff -rc sane-1.00/backend/abaton.c sane/backend/abaton.c *** sane-1.00/backend/abaton.c Sat Nov 21 21:54:14 1998 --- sane/backend/abaton.c Thu Dec 10 13:30:26 1998 *************** *** 68,73 **** --- 68,77 ---- #include "abaton.h" + #ifndef HAVE_STRNDUP + extern char *strndup(const char *, int); + #endif /* !HAVE_STRNDUP */ + #define BACKEND_NAME abaton #include <sane/sanei_backend.h> *************** *** 229,235 **** return status; } } - return SANE_STATUS_INVAL; } static SANE_Status --- 233,238 ---- *************** *** 261,268 **** DBG (ERROR_MESSAGE, "Sense: Unknown Sense Key. Read more...\n"); return SANE_STATUS_IO_ERROR; } - - return SANE_STATUS_GOOD; } static SANE_Status --- 264,269 ---- *************** *** 493,498 **** --- 494,505 ---- } static SANE_Status + attach_one (const char *devname) + { + return attach (devname, 0, SANE_FALSE); + } + + static SANE_Status calc_parameters (Abaton_Scanner * s) { SANE_String val = s->val[OPT_MODE].s; *************** *** 876,882 **** continue; } ! attach (dev_name, 0, SANE_FALSE); } fclose (fp); return SANE_STATUS_GOOD; --- 883,889 ---- continue; } ! sanei_config_attach_matching_devices (dev_name, attach_one); } fclose (fp); return SANE_STATUS_GOOD; *************** *** 976,982 **** prev = 0; for (s = first_handle; s; s = s->next) { ! if (s == handle) break; prev = s; } --- 983,989 ---- prev = 0; for (s = first_handle; s; s = s->next) { ! if (s == (Abaton_Scanner *)handle) break; prev = s; } *************** *** 1113,1119 **** case OPT_Y_RESOLUTION: if (s->val[OPT_PREVIEW].w || s->val[OPT_RESOLUTION_BIND].w) { ! s->val[OPT_X_RESOLUTION] = *(SANE_Word *)val; if (info) *info |= SANE_INFO_RELOAD_OPTIONS; } --- 1120,1126 ---- case OPT_Y_RESOLUTION: if (s->val[OPT_PREVIEW].w || s->val[OPT_RESOLUTION_BIND].w) { ! s->val[OPT_X_RESOLUTION].w = *(SANE_Word *)val; if (info) *info |= SANE_INFO_RELOAD_OPTIONS; } *************** *** 1265,1271 **** u_int8_t read[10]; u_int8_t result[12]; ! ssize_t size; SANE_Int data_av = 0; SANE_Int data_length = 0; SANE_Int offset = 0; --- 1272,1278 ---- u_int8_t read[10]; u_int8_t result[12]; ! size_t size; SANE_Int data_av = 0; SANE_Int data_length = 0; SANE_Int offset = 0; diff -rc sane-1.00/backend/abaton.conf sane/backend/abaton.conf *** sane-1.00/backend/abaton.conf Sat Nov 21 20:15:29 1998 --- sane/backend/abaton.conf Thu Dec 10 13:27:33 1998 *************** *** 1 **** --- 1,2 ---- + scsi ABATON /dev/scanner diff -rc sane-1.00/backend/abaton.h sane/backend/abaton.h *** sane-1.00/backend/abaton.h Sat Nov 21 20:15:29 1998 --- sane/backend/abaton.h Wed Dec 9 15:32:28 1998 *************** *** 52,58 **** { ABATON_MODE_LINEART=0, ABATON_MODE_HALFTONE, ! ABATON_MODE_GRAY, }; enum Abaton_Option --- 52,58 ---- { ABATON_MODE_LINEART=0, ABATON_MODE_HALFTONE, ! ABATON_MODE_GRAY }; enum Abaton_Option *************** *** 94,100 **** enum ScannerModels { ABATON_300GS, ! ABATON_300S, }; typedef struct Abaton_Device --- 94,100 ---- enum ScannerModels { ABATON_300GS, ! ABATON_300S }; typedef struct Abaton_Device diff -rc sane-1.00/backend/apple.c sane/backend/apple.c *** sane-1.00/backend/apple.c Tue Nov 10 00:31:37 1998 --- sane/backend/apple.c Wed Dec 9 15:51:01 1998 *************** *** 65,71 **** --- 65,75 ---- #include <sane/sanei_scsi.h> #include <apple.h> + #ifndef HAVE_STRNDUP + extern char *strndup(const char *, int); + #endif /* !HAVE_STRNDUP */ + /* SCSI commands that the Apple scanners understand: */ #define APPLE_SCSI_TEST_UNIT_READY 0x00 #define APPLE_SCSI_REQUEST_SENSE 0x03 *************** *** 2432,2438 **** #endif u_int8_t result[12]; ! ssize_t size; SANE_Int data_length = 0; SANE_Int data_av = 0; SANE_Int offset = 0; --- 2436,2442 ---- #endif u_int8_t result[12]; ! size_t size; SANE_Int data_length = 0; SANE_Int data_av = 0; SANE_Int offset = 0; diff -rc sane-1.00/backend/artec.conf sane/backend/artec.conf *** sane-1.00/backend/artec.conf Fri Apr 3 03:16:14 1998 --- sane/backend/artec.conf Thu Dec 10 13:25:27 1998 *************** *** 1,2 **** --- 1,3 ---- + scsi ULTIMA /dev/scanner diff -rc sane-1.00/backend/artec.h sane/backend/artec.h *** sane-1.00/backend/artec.h Tue Nov 3 00:15:31 1998 --- sane/backend/artec.h Wed Dec 9 15:38:56 1998 *************** *** 136,142 **** ARTEC_FILTER_MONO = 0, ARTEC_FILTER_RED, ARTEC_FILTER_GREEN, ! ARTEC_FILTER_BLUE, } ARTEC_Filter_Type; --- 136,142 ---- ARTEC_FILTER_MONO = 0, ARTEC_FILTER_RED, ARTEC_FILTER_GREEN, ! ARTEC_FILTER_BLUE } ARTEC_Filter_Type; diff -rc sane-1.00/backend/dc210.c sane/backend/dc210.c *** sane-1.00/backend/dc210.c Sat Nov 21 23:18:48 1998 --- sane/backend/dc210.c Wed Dec 9 16:02:45 1998 *************** *** 63,69 **** #include <unistd.h> #include <fcntl.h> #include <limits.h> ! #include <cdjpeg.h> #include <sys/ioctl.h> #include <sane/sane.h> --- 63,69 ---- #include <unistd.h> #include <fcntl.h> #include <limits.h> ! #include "cdjpeg.h" #include <sys/ioctl.h> #include <sane/sane.h> *************** *** 341,347 **** --- 341,354 ---- } /* send a break to get it back to a known state */ + #ifdef TCSBRKP ioctl (camera->fd, TCSBRKP, 4); + #elif defined(TCSBRK) + ioctl (camera->fd, TCSBRK, 4); + #else + tcsendbreak(camera->fd, 4); /* Use the POSIX call... */ + #endif /* TCSBRKP */ + /* and wait for it to recover from the break */ usleep (breakpause); *************** *** 592,603 **** fp = sanei_config_open (DC210_CONFIG_FILE); /* defaults */ Camera.baud = B115200; ! Camera.tty_name = "/dev/ttyS0"; if (!fp) { ! /* default to /dev/ttyS0 instead of insisting on config file */ DBG (1, "%s: missing config file '%s'\n", DC210_CONFIG_FILE, f); } else --- 599,625 ---- fp = sanei_config_open (DC210_CONFIG_FILE); /* defaults */ + #ifdef B115200 Camera.baud = B115200; ! #else ! Camera.baud = B38400; ! #endif /* B115200 */ ! ! #ifdef __sgi ! Camera.tty_name = "/dev/ttyd1"; /* IRIX */ ! #elif defined(__sun) ! Camera.tty_name = "/dev/term/a"; /* Solaris */ ! #elif defined(hpux) ! Camera.tty_name = "/dev/tty1d0"; /* HP-UX */ ! #elif defined(__osf__) ! Camera.tty_name = "/dev/tty00"; /* Digital UNIX + OSF/1 */ ! #else ! Camera.tty_name = "/dev/ttyS0"; /* Linux */ ! #endif /* __sgi */ if (!fp) { ! /* default to /dev/... instead of insisting on config file */ DBG (1, "%s: missing config file '%s'\n", DC210_CONFIG_FILE, f); } else *************** *** 636,647 **** --- 658,673 ---- case 38400: Camera.baud = B38400; break; + #ifdef B57600 case 57600: Camera.baud = B57600; break; + #endif /* B57600 */ + #ifdef B115200 case 115200: Camera.baud = B115200; break; + #endif /* B115200 */ } DBG (20, "Config file baud=%d\n", Camera.baud); diff -rc sane-1.00/backend/dc210.conf sane/backend/dc210.conf *** sane-1.00/backend/dc210.conf Sat Nov 21 22:53:55 1998 --- sane/backend/dc210.conf Thu Dec 10 13:26:59 1998 *************** *** 1,8 **** # Serial port where the camera is connected ! port=/dev/ttyS6 # Max baud rate for download. Camera always starts at 9600 baud, then # switches to the higher rate baud=115200 # Prints some extra information during the init phase. This can be # handy, but note that printing anything to stderr breaks the saned # network scanning. --- 1,20 ---- # Serial port where the camera is connected ! ## Linux ! port=/dev/ttyS0 ! ## IRIX ! #port=/dev/ttyd1 ! ## Solaris ! #port=/dev/term/a ! ## HP-UX ! #port=/dev/tty0p0 ! ## Digital UNIX ! #port=/dev/tty01 # Max baud rate for download. Camera always starts at 9600 baud, then # switches to the higher rate + ## This works for Linux and some versions of IRIX (6.3 or higher) baud=115200 + ## This works for most UNIX's + #baud=38400 # Prints some extra information during the init phase. This can be # handy, but note that printing anything to stderr breaks the saned # network scanning. diff -rc sane-1.00/backend/dc210.h sane/backend/dc210.h *** sane-1.00/backend/dc210.h Sat Nov 21 22:53:55 1998 --- sane/backend/dc210.h Wed Dec 9 15:46:10 1998 *************** *** 158,170 **** unsigned char pkt_code[2]; }; ! #define NUM_OF_SPEEDS 5 ! ! #define SPEEDS { { B9600, { 0x96, 0x00 } }, \ ! { B19200, { 0x19, 0x20 } }, \ ! { B38400, { 0x38, 0x40 } }, \ ! { B57600, { 0x57, 0x60 } }, \ ! { B115200, { 0x11, 0x52 } } } #define HIGH_RES 0 #define LOW_RES 1 --- 158,176 ---- unsigned char pkt_code[2]; }; ! #if defined(B57600) && defined(B115200) ! # define NUM_OF_SPEEDS 5 ! # define SPEEDS { { B9600, { 0x96, 0x00 } }, \ ! { B19200, { 0x19, 0x20 } }, \ ! { B38400, { 0x38, 0x40 } }, \ ! { B57600, { 0x57, 0x60 } }, \ ! { B115200, { 0x11, 0x52 } } } ! #else ! # define NUM_OF_SPEEDS 5 ! # define SPEEDS { { B9600, { 0x96, 0x00 } }, \ ! { B19200, { 0x19, 0x20 } }, \ ! { B38400, { 0x38, 0x40 } } } ! #endif /* B57600 && B115200 */ #define HIGH_RES 0 #define LOW_RES 1 diff -rc sane-1.00/backend/dc25.conf sane/backend/dc25.conf *** sane-1.00/backend/dc25.conf Tue Jul 21 01:38:25 1998 --- sane/backend/dc25.conf Thu Dec 10 13:19:01 1998 *************** *** 1,8 **** # Serial port where the camera is connected ! port=/dev/ttyS6 # Max baud rate for download. Camera always starts at 9600 baud, then # switches to the higher rate baud=115200 # Prints some extra information during the init phase. This can be # handy, but note that printing anything to stderr breaks the saned # network scanning. --- 1,20 ---- # Serial port where the camera is connected ! ## Linux ! port=/dev/ttyS0 ! ## IRIX ! #port=/dev/ttyd1 ! ## Solaris ! #port=/dev/term/a ! ## HP-UX ! #port=/dev/tty0p0 ! ## Digital UNIX ! #port=/dev/tty01 # Max baud rate for download. Camera always starts at 9600 baud, then # switches to the higher rate + ## This works for Linux and some versions of IRIX (6.3 or higher) baud=115200 + ## This works for most UNIX's + #baud=38400 # Prints some extra information during the init phase. This can be # handy, but note that printing anything to stderr breaks the saned # network scanning. diff -rc sane-1.00/backend/dll.c sane/backend/dll.c *** sane-1.00/backend/dll.c Thu Oct 29 02:06:14 1998 --- sane/backend/dll.c Thu Dec 10 13:47:08 1998 *************** *** 55,60 **** --- 55,64 ---- #include <stdlib.h> #include <string.h> + #ifndef HAVE_STRSEP + extern char *strsep(char **, const char *); + #endif /* !HAVE_STRSEP */ + #if defined(HAVE_DLOPEN) && defined(HAVE_DLFCN_H) # include <dlfcn.h> diff -rc sane-1.00/backend/dll.conf sane/backend/dll.conf *** sane-1.00/backend/dll.conf Sat Nov 21 22:53:55 1998 --- sane/backend/dll.conf Thu Dec 10 13:16:43 1998 *************** *** 1,5 **** ! # enable the next line if you want to allow access through the network: ! #net abaton agfafocus apple --- 1,8 ---- ! # disable the next line if you don't want to allow access through the network: ! net ! # the pnm "test" device; disabled by default ! #pnm ! # the rest are real scanners and cameras abaton agfafocus apple *************** *** 15,21 **** microtek2 mustek pint - pnm qcam ricoh s9036 --- 18,23 ---- diff -rc sane-1.00/backend/epson.conf sane/backend/epson.conf *** sane-1.00/backend/epson.conf Mon Mar 23 06:53:51 1998 --- sane/backend/epson.conf Thu Dec 10 13:26:00 1998 *************** *** 1 **** --- 1,2 ---- + scsi EPSON /dev/scanner diff -rc sane-1.00/backend/hp-accessor.c sane/backend/hp-accessor.c *** sane-1.00/backend/hp-accessor.c Wed Oct 28 02:05:34 1998 --- sane/backend/hp-accessor.c Thu Dec 10 12:21:01 1998 *************** *** 100,105 **** --- 100,118 ---- size_t newsize = this->bufsiz; size_t offset = this->length; + /* + * mike@easysw.com: + * + * The following code is REQUIRED so that pointers, etc. aren't + * misaligned. This causes MAJOR problems on all SPARC, ALPHA, + * and MIPS processors, and possibly others. + * + * The workaround is to ensure that all allocations are in multiples + * of 8 bytes. + */ + + sz = (sz + 7) & ~7; + while (newsize < this->length + sz) newsize += DATA_SIZE_INCREMENT; hp_data_resize(this, newsize); diff -rc sane-1.00/backend/hp-device.c sane/backend/hp-device.c *** sane-1.00/backend/hp-device.c Sat Nov 14 07:41:39 1998 --- sane/backend/hp-device.c Fri Dec 11 13:14:28 1998 *************** *** 69,75 **** { SCL_HP_MODEL_8, "4P", HP_COMPAT_4P }, { SCL_HP_MODEL_9, "5P", HP_COMPAT_5P }, { SCL_HP_MODEL_10, "Photo Scanner", HP_COMPAT_PS }, ! { SCL_HP_MODEL_14, "6200C", HP_COMPAT_6200C } }; int i; char buf[8]; --- 69,76 ---- { SCL_HP_MODEL_8, "4P", HP_COMPAT_4P }, { SCL_HP_MODEL_9, "5P", HP_COMPAT_5P }, { SCL_HP_MODEL_10, "Photo Scanner", HP_COMPAT_PS }, ! { SCL_HP_MODEL_14, "6200C", HP_COMPAT_6200C }, ! { SCL_HP_MODEL_14, "6250C", HP_COMPAT_6200C } }; int i; char buf[8]; *************** *** 167,173 **** status = sanei_hp_device_probe(&(this->compat), scsi); if (!FAILED(status)) ! status = sanei_hp_optset_new(&this->options, scsi, this); sanei_hp_scsi_destroy(scsi); if (FAILED(status)) --- 168,174 ---- status = sanei_hp_device_probe(&(this->compat), scsi); if (!FAILED(status)) ! status = sanei_hp_optset_new(&(this->options), scsi, this); sanei_hp_scsi_destroy(scsi); if (FAILED(status)) diff -rc sane-1.00/backend/hp.c sane/backend/hp.c *** sane-1.00/backend/hp.c Sat Nov 14 17:05:40 1998 --- sane/backend/hp.c Thu Dec 10 10:46:49 1998 *************** *** 239,244 **** --- 239,251 ---- } static SANE_Status + hp_attach (const char *devname) + { + return hp_get_dev (devname, 0); + } + + + static SANE_Status hp_read_config (void) { FILE * fp; *************** *** 259,267 **** continue; /* ignore comments and blank lines */ dev_name[strcspn(dev_name, " \t\n")] = '\0'; /* truncate at WS */ ! status = hp_get_dev(dev_name, 0); ! if (status != SANE_STATUS_GOOD && status != SANE_STATUS_UNSUPPORTED) ! return status; } fclose (fp); } --- 266,272 ---- continue; /* ignore comments and blank lines */ dev_name[strcspn(dev_name, " \t\n")] = '\0'; /* truncate at WS */ ! sanei_config_attach_matching_devices (dev_name, hp_attach); } fclose (fp); } diff -rc sane-1.00/backend/net.c sane/backend/net.c *** sane-1.00/backend/net.c Thu Oct 29 02:42:27 1998 --- sane/backend/net.c Thu Dec 10 13:41:46 1998 *************** *** 57,62 **** --- 57,66 ---- # include <libc.h> /* NeXTStep/OpenStep */ #endif + #ifndef HAVE_STRSEP + extern char *strsep(char **, const char *); + #endif /* !HAVE_STRSEP */ + #include <sys/time.h> #include <sys/types.h> diff -rc sane-1.00/backend/pnm.c sane/backend/pnm.c *** sane-1.00/backend/pnm.c Fri Oct 30 01:19:13 1998 --- sane/backend/pnm.c Thu Dec 10 13:44:13 1998 *************** *** 59,64 **** --- 59,70 ---- #include <sane/sanei.h> #include <sane/saneopts.h> + #ifdef HAVE_ALLOCA_H + # include <alloca.h> + #else + extern void *alloca(unsigned); + #endif /* HAVE_ALLOCA_H */ + #define BACKEND_NAME pnm #include <sane/sanei_backend.h> diff -rc sane-1.00/backend/ricoh.c sane/backend/ricoh.c *** sane-1.00/backend/ricoh.c Wed Oct 28 02:46:12 1998 --- sane/backend/ricoh.c Thu Dec 10 13:08:08 1998 *************** *** 296,301 **** --- 296,307 ---- } static SANE_Status + attach_one(const char *devnam) + { + attach (devnam, NULL); + } + + static SANE_Status init_options (Ricoh_Scanner * s) { int i; *************** *** 495,501 **** } fclose (fp); } ! attach (devnam, NULL); DBG (11, "<< sane_init\n"); return SANE_STATUS_GOOD; } --- 501,507 ---- } fclose (fp); } ! sanei_config_attach_matching_devices (devnam, attach_one); DBG (11, "<< sane_init\n"); return SANE_STATUS_GOOD; } diff -rc sane-1.00/backend/ricoh.conf sane/backend/ricoh.conf *** sane-1.00/backend/ricoh.conf Tue Jun 2 16:41:10 1998 --- sane/backend/ricoh.conf Thu Dec 10 13:06:10 1998 *************** *** 1 **** --- 1,2 ---- + scsi RICOH IS60 /dev/scanner diff -rc sane-1.00/backend/s9036.conf sane/backend/s9036.conf *** sane-1.00/backend/s9036.conf Sun Dec 7 14:56:40 1997 --- sane/backend/s9036.conf Thu Dec 10 13:22:26 1998 *************** *** 1,2 **** --- 1,3 ---- + scsi /dev/scanner diff -rc sane-1.00/backend/saned.conf sane/backend/saned.conf *** sane-1.00/backend/saned.conf Fri Jul 24 01:06:35 1998 --- sane/backend/saned.conf Thu Dec 10 13:10:04 1998 *************** *** 5,17 **** # names that are permitted by saned to use local SANE # devices in a networked configuration. Note that the # hostnames need to be spelled _exactly_ the way gethostbyname() ! # returns them (the matching is case-sensitive). Typically, # you can find the right spelling by doing "nslookup HOSTNAME" # or by looking in /etc/hosts. # - #scan-client.somedomain.firm - #localhost - # # NOTE: /etc/inetd.conf and /etc/services must also # be properly configured to start the saned daemon as # documented in saned(1), services(4) and inetd.conf(4) --- 5,14 ---- # names that are permitted by saned to use local SANE # devices in a networked configuration. Note that the # hostnames need to be spelled _exactly_ the way gethostbyname() ! # returns them (the matching is case-insensitive). Typically, # you can find the right spelling by doing "nslookup HOSTNAME" # or by looking in /etc/hosts. # # NOTE: /etc/inetd.conf and /etc/services must also # be properly configured to start the saned daemon as # documented in saned(1), services(4) and inetd.conf(4) *************** *** 21,23 **** --- 18,28 ---- # # and /etc/inetd.conf might contain a line: # sane stream tcp nowait root /usr/local/sbin/saned saned + # + + ## Specify individual hosts like this: + #scan-client.somedomain.firm + #localhost + + ## Allow all hosts like this: + + diff -rc sane-1.00/backend/snapscan.conf sane/backend/snapscan.conf *** sane-1.00/backend/snapscan.conf Wed Nov 12 07:20:24 1997 --- sane/backend/snapscan.conf Thu Dec 10 13:21:15 1998 *************** *** 1,2 **** /dev/scanner - /dev/sga --- 1,3 ---- + scsi AGFA + scsi COLOR /dev/scanner diff -rc sane-1.00/backend/tamarack.conf sane/backend/tamarack.conf *** sane-1.00/backend/tamarack.conf Tue Dec 9 03:22:17 1997 --- sane/backend/tamarack.conf Thu Dec 10 13:23:21 1998 *************** *** 1,2 **** --- 1,3 ---- + scsi TAMARACK /dev/scanner diff -rc sane-1.00/frontend/gtkglue.c sane/frontend/gtkglue.c *** sane-1.00/frontend/gtkglue.c Sat Nov 21 18:35:18 1998 --- sane/frontend/gtkglue.c Thu Dec 10 13:56:30 1998 *************** *** 29,34 **** --- 29,35 ---- #include <pwd.h> #include <stdio.h> #include <stdlib.h> + #include <string.h> #include <unistd.h> #include <sys/types.h> /* Apollo/DomainOS needs this _before_ sys/stat.h */ diff -rc sane-1.00/frontend/saned.c sane/frontend/saned.c *** sane-1.00/frontend/saned.c Thu Oct 29 02:42:17 1998 --- sane/frontend/saned.c Thu Dec 10 13:12:37 1998 *************** *** 371,377 **** if (!len) continue; /* ignore empty lines */ ! if (strcasecmp (rhost, he->h_name) == 0) access_ok = 1; for (i = 0; he->h_aliases[i]; ++i) if (strcasecmp (rhost, he->h_aliases[i]) == 0) --- 371,378 ---- if (!len) continue; /* ignore empty lines */ ! if (strcasecmp (rhost, he->h_name) == 0 || ! strcmp(rhost, "+") == 0) access_ok = 1; for (i = 0; he->h_aliases[i]; ++i) if (strcasecmp (rhost, he->h_aliases[i]) == 0) diff -rc sane-1.00/sanei/sanei_config.c sane/sanei/sanei_config.c *** sane-1.00/sanei/sanei_config.c Sat May 9 13:16:05 1998 --- sane/sanei/sanei_config.c Thu Dec 10 13:35:46 1998 *************** *** 45,50 **** --- 45,58 ---- #include <stdlib.h> #include <string.h> + #ifndef HAVE_STRNDUP + extern char *strndup(const char *, size_t); + #endif /* !HAVE_STRNDUP */ + + #ifndef HAVE_STRSEP + extern char *strsep(char **, const char *); + #endif /* !HAVE_STRSEP */ + #include <sys/param.h> #include <sane/sanei.h> diff -rc sane-1.00/sanei/sanei_scsi.c sane/sanei/sanei_scsi.c *** sane-1.00/sanei/sanei_scsi.c Thu Oct 29 01:38:12 1998 --- sane/sanei/sanei_scsi.c Mon Dec 21 09:35:25 1998 *************** *** 111,116 **** --- 111,117 ---- #elif defined (HAVE_SYS_DSREQ_H) # define USE IRIX_INTERFACE # include <sys/dsreq.h> + # include <invent.h> #elif defined (HAVE_SYS_SCSI_H) # include <sys/scsi.h> # ifdef SCTL_READ *************** *** 182,188 **** #if USE == IRIX_INTERFACE /* Actually, the limit varies from 256MB to 1GB :) */ ! # define MAX_DATA (8*1024*1024) #endif #if USE == FREEBSD_CAM_INTERFACE --- 183,189 ---- #if USE == IRIX_INTERFACE /* Actually, the limit varies from 256MB to 1GB :) */ ! # define MAX_DATA (256*1024) #endif #if USE == FREEBSD_CAM_INTERFACE *************** *** 2204,2222 **** #endif /* USE == STUBBED_INTERFACE */ #if USE == IRIX_INTERFACE SANE_Status sanei_scsi_cmd (int fd, const void *src, size_t src_size, void *dst, size_t * dst_size) { ! dsreq_t scsi_req; /* SCSI request */ ! u_char sensebuf[1024], /* Request sense buffer */ ! databuf[65536]; /* Command data buffer */ ! size_t cdb_size; /* Size of SCSI command */ ! cdb_size = CDB_SIZE (*(u_char *) src); ! memset (&scsi_req, 0, sizeof (scsi_req)); if (dst != NULL) { --- 2205,2244 ---- #endif /* USE == STUBBED_INTERFACE */ #if USE == IRIX_INTERFACE + #define WE_HAVE_FIND_DEVICES + SANE_Status sanei_scsi_cmd (int fd, const void *src, size_t src_size, void *dst, size_t * dst_size) { ! dsreq_t scsi_req; /* SCSI request */ ! size_t cdb_size; /* Size of SCSI command */ ! static u_char *cmdbuf = NULL, /* Command buffer */ ! *sensebuf = NULL, /* Request sense buffer */ ! *databuf = NULL; /* Data buffer */ ! /* ! * Allocate the sense and command data buffers as necessary; we ! * have to do this to avoid buffer alignment problems, since ! * some hardware requires these buffers to be 32-bit aligned. ! */ ! ! if (cmdbuf == NULL) ! { ! cmdbuf = malloc(64); ! sensebuf = malloc(1024); ! databuf = malloc(MAX_DATA); ! ! if (cmdbuf == NULL || sensebuf == NULL || databuf == NULL) ! return SANE_STATUS_NO_MEM; ! } ! ! /* ! * Build the SCSI request... ! */ ! cdb_size = CDB_SIZE (*(u_char *) src); if (dst != NULL) { *************** *** 2223,2236 **** /* * SCSI command returning/reading data... */ ! scsi_req.ds_flags = DSRQ_READ | DSRQ_SENSE; ! scsi_req.ds_time = 120 * 1000; ! scsi_req.ds_cmdbuf = (caddr_t) src; ! scsi_req.ds_cmdlen = cdb_size; ! scsi_req.ds_databuf = (caddr_t) dst; ! scsi_req.ds_datalen = *dst_size; scsi_req.ds_sensebuf = (caddr_t) sensebuf; scsi_req.ds_senselen = sizeof (sensebuf); } else { --- 2245,2265 ---- /* * SCSI command returning/reading data... */ ! ! scsi_req.ds_flags = DSRQ_READ | DSRQ_SENSE; ! scsi_req.ds_time = 120 * 1000; ! scsi_req.ds_cmdbuf = (caddr_t) cmdbuf; ! scsi_req.ds_cmdlen = cdb_size; ! scsi_req.ds_databuf = (caddr_t) databuf; ! scsi_req.ds_datalen = *dst_size; scsi_req.ds_sensebuf = (caddr_t) sensebuf; scsi_req.ds_senselen = sizeof (sensebuf); + + /* + * Copy command to cmdbuf to assure 32-bit alignment. + */ + + memcpy(cmdbuf, src, cdb_size); } else { *************** *** 2237,2263 **** /* * SCSI command sending/writing data... */ ! scsi_req.ds_flags = DSRQ_WRITE | DSRQ_SENSE; ! scsi_req.ds_time = 120 * 1000; ! scsi_req.ds_cmdbuf = (caddr_t) src; ! scsi_req.ds_cmdlen = cdb_size; ! scsi_req.ds_databuf = (caddr_t) databuf; ! scsi_req.ds_datalen = src_size - cdb_size; scsi_req.ds_sensebuf = (caddr_t) sensebuf; scsi_req.ds_senselen = sizeof (sensebuf); /* ! * Copy data portion to local buffer to ensure 32-bit alignment... */ memcpy (databuf, (u_char *) src + cdb_size, src_size - cdb_size); } if (ioctl (fd, DS_ENTER, &scsi_req) < 0) return SANE_STATUS_IO_ERROR; ! if (dst_size != NULL) ! *dst_size = scsi_req.ds_datasent; if (scsi_req.ds_status != 0) { if (scsi_req.ds_status == STA_BUSY) --- 2266,2311 ---- /* * SCSI command sending/writing data... */ ! scsi_req.ds_flags = DSRQ_WRITE | DSRQ_SENSE; ! scsi_req.ds_time = 120 * 1000; ! scsi_req.ds_cmdbuf = (caddr_t) cmdbuf; ! scsi_req.ds_cmdlen = cdb_size; ! scsi_req.ds_databuf = (caddr_t) databuf; ! scsi_req.ds_datalen = src_size - cdb_size; scsi_req.ds_sensebuf = (caddr_t) sensebuf; scsi_req.ds_senselen = sizeof (sensebuf); /* ! * Copy command and data to local buffers to ensure 32-bit alignment... */ + memcpy (cmdbuf, (u_char *) src, cdb_size); memcpy (databuf, (u_char *) src + cdb_size, src_size - cdb_size); } + + /* + * Do SCSI request... + */ + if (ioctl (fd, DS_ENTER, &scsi_req) < 0) return SANE_STATUS_IO_ERROR; ! /* ! * Set the incoming data size and copy the destination data as needed... ! */ + if (dst != NULL) + { + *dst_size = scsi_req.ds_datasent; + + if (scsi_req.ds_datasent > 0) + memcpy(dst, databuf, scsi_req.ds_datasent); + } + + /* + * Return the appropriate status code... + */ + if (scsi_req.ds_status != 0) { if (scsi_req.ds_status == STA_BUSY) *************** *** 2268,2274 **** --- 2316,2454 ---- else return SANE_STATUS_IO_ERROR; } + return SANE_STATUS_GOOD; + } + + void + sanei_scsi_find_devices (const char *findvendor, const char *findmodel, + const char *findtype, + int findbus, int findchannel, int findid, int findlun, + SANE_Status (*attach) (const char *dev)) + { + size_t findvendor_len = 0, findmodel_len = 0; + /* Lengths of search strings */ + inventory_t *inv; /* Current hardware inventory entry */ + int bus, id, lun; /* Current Bus, ID, and LUN */ + char dev_name[128]; /* SCSI device name */ + int fd; /* SCSI file */ + size_t inqsize; /* Size of returned inquiry data */ + char vendor[9], /* Vendor name */ + model[17]; /* Model/product name */ + static u_char *inqdata = NULL, /* Inquiry data buffer */ + *inqcommand = NULL; /* Inquiry command (0x12) buffer */ + + + /* + * Allocate the data and command buffers as necessary; we + * have to do this to avoid buffer alignment problems, since + * some hardware requires these buffers to be 32-bit aligned. + */ + + if (inqdata == NULL) + { + inqdata = malloc(128); + inqcommand = malloc(6); + + if (inqdata == NULL || inqcommand == NULL) + return; + } + + vendor[0] = model[0] = '\0'; + if (findvendor) + findvendor_len = strlen (findvendor); + if (findmodel) + findmodel_len = strlen (findmodel); + + if (findvendor != NULL) + DBG (1, "sanei_scsi_find_devices: looking for vendors starting with \"%s\".\n", + findvendor); + + if (findmodel != NULL) + DBG (1, "sanei_scsi_find_devices: looking for models starting with \"%s\".\n", + findmodel); + + setinvent(); + + while ((inv = getinvent()) != NULL) + { + if (inv->inv_class != INV_SCSI || + (inv->inv_type != INV_SCANNER && inv->inv_type != INV_CPU)) + continue; + + bus = inv->inv_controller; + id = inv->inv_unit; + lun = inv->inv_state >> 8; + + DBG (1, "sanei_scsi_find_devices: found %s on controller %d, ID %d, LUN %d.\n", + inv->inv_type == INV_SCANNER ? "scanner" : "processor", bus, id, lun); + + if ((findbus >= 0 && bus != findbus) || + (findid >= 0 && id != findid) || + (findlun >= 0 && lun != findlun)) { + DBG (1, "sanei_scsi_find_devices: ignoring this device.\n"); + continue; + } + + sprintf(dev_name, "/dev/scsi/sc%dd%dl%d", bus, id, lun); + DBG (1, "sanei_scsi_find_devices: device name is \"%s\".\n", dev_name); + + /* + * Open the SCSI device and get the inquiry data... + */ + + if (sanei_scsi_open(dev_name, &fd, NULL, NULL) != SANE_STATUS_GOOD) { + DBG (1, "sanei_scsi_find_devices: unable to open device file - %s.\n", + strerror(errno)); + continue; + } + + DBG (1, "sanei_scsi_find_devices: device fd = %d.\n", fd); + + inqsize = sizeof(inqdata); + + inqcommand[0] = 0x12; + inqcommand[1] = 0; + inqcommand[2] = 0; + inqcommand[3] = sizeof(inqdata) >> 8; + inqcommand[4] = sizeof(inqdata); + inqcommand[5] = 0; + + if (sanei_scsi_cmd(fd, inqcommand, sizeof(inqcommand), inqdata, + &inqsize) != SANE_STATUS_GOOD) { + DBG (1, "sanei_scsi_find_devices: unable to get inquiry data - %s.\n", + strerror(errno)); + continue; + } + + sanei_scsi_close(fd); + + strncpy(vendor, (char *)inqdata + 8, 8); + vendor[8] = '\0'; + strncpy(model, (char *)inqdata + 16, 16); + model[16] = '\0'; + + DBG (1, "sanei_scsi_find_devices: vendor = \'%s\', model = \'%s'.\n", + vendor, model); + + /* + * Compare as necessary... + */ + + if ((findvendor != NULL && strncmp(findvendor, vendor, findvendor_len)) || + (findmodel != NULL && strncmp(findmodel, model, findmodel_len))) { + DBG (1, "sanei_scsi_find_devices: ignoring this device.\n"); + continue; + } + + /* + * OK, this one matches, so use it! + */ + + DBG (1, "sanei_scsi_find_devices: attaching this device.\n"); + + (*attach)(dev_name); + } } #endif /* USE == IRIX_INTERFACE */

--------------095D4C1A9D918F514478DFB5--

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