Re: Linux Sense buffer (was: sane 0.71 and microtek E3)

Sean Reifschneider (jafo@tummy.com)
Sat, 18 Apr 1998 19:04:02 -0600

--5Pyd7+fXNt84Ff3A
Content-Type: text/plain; charset=us-ascii

>There is. I sent the appended patch to Linus a short while ago. Of
>course, you shouldn't rely on this patch being present until it has
>been folded into the regular sources.

How about the following patch? It creates "/proc/scsi/sg", which at the
moment only reports the SG_BIG_BUFF size. To detect if the patch is in
the currently-running kernel you just check the existance of
"/proc/scsi/sg" -- if it's not there you can default to 32K.

I'm including the code I have to do the detection (for Linux ONLY) -- the
problem is I don't know where to put it in SANE (admittedly, I didn't
look too hard -- I wrote the kernel patch at the beginning of vacation
:-).

Also included is a patch for 2.0.33 kernels and 2.1.97 kernels. I'd
appreciate it if folks would try applying it and verifying that
/proc/scsi/sg includes the appropriate information. If you can report
success or failure to me, I'll get it put into the kernel for 2.2.

Note that I haven't even compiled the 2.1 version -- let me know if
there are problems.

Thanks,
Sean

-- 
 "If all you have is a hammer, every problem tends to look like a nail."
Sean Reifschneider, Inimitably Superfluous <jafo@tummy.com>
URL: <http://www.tummy.com/xvscan> HP-UX/Linux/FreeBSD/BSDOS scanning software.

--5Pyd7+fXNt84Ff3A Content-Type: text/plain; charset=us-ascii Content-Description: C code to determine SG_BIG_BUFF size. Content-Disposition: attachment; filename="sgbufsz.c"

#include <stdio.h> #include <string.h> #include <stdlib.h>

#define SGPROCNAME "/proc/scsi/sg"

long sgbufsize(void) { FILE *fp = fopen(SGPROCNAME, "r"); char line[100]; long bufsize = 32768; /* default SG_BIG_BUFF */ long i;

if (fp) { while (fgets(line, sizeof(line), fp)) { if (strncmp(line, "<SG_BIG_BUFF_LEN=", 17) == 0) { if ((i = atol(line + 17)) != 0) { bufsize = i; break; } } } fclose(fp); }

return(bufsize); }

#ifdef MAIN int main() { printf("size: %ld\n", sgbufsize()); exit(0); } #endif

--5Pyd7+fXNt84Ff3A Content-Type: text/plain; charset=us-ascii Content-Description: 2.0.33 patch for /proc/scsi/sg Content-Disposition: attachment; filename="sg-2.0.33-proc.patch"

*** linux-2.0.33/drivers/scsi/sg.c.old Fri Apr 3 13:48:22 1998 --- linux-2.0.33/drivers/scsi/sg.c Fri Apr 3 19:10:50 1998 *************** *** 17,22 **** --- 17,23 ---- #include <linux/mtio.h> #include <linux/ioctl.h> #include <linux/fcntl.h> + #include <linux/proc_fs.h> #include <asm/io.h> #include <asm/segment.h> #include <asm/system.h> *************** *** 44,49 **** --- 45,65 ---- static int big_inuse=0; #endif + int sg_read_procmem(char *buf, char **start, off_t offset, int len, int unused) + { + return (sprintf(buf, "<SG_BIG_BUFF_LEN=%li>\n", (long) SG_BIG_BUFF)); + } + + struct proc_dir_entry sg_proc_entry = { + 0, /* low_ino: the inode number -- dynamic */ + 2, "sg", /* length of name and name */ + S_IFREG | S_IRUGO, /* file mode */ + 1, 0, 0, /* number of links, owner, group */ + 0, /* size (unused) */ + NULL, /* operations -- use default */ + &sg_read_procmem /* read function */ + }; + struct scsi_generic { Scsi_Device *device; *************** *** 632,643 **** #ifdef MODULE int init_module(void) { sg_template.usage_count = &mod_use_count_; ! return scsi_register_module(MODULE_SCSI_DEV, &sg_template); } void cleanup_module( void) { scsi_unregister_module(MODULE_SCSI_DEV, &sg_template); unregister_chrdev(SCSI_GENERIC_MAJOR, "sg"); --- 648,665 ---- #ifdef MODULE int init_module(void) { + int ret; + + sg_template.usage_count = &mod_use_count_; ! ret = scsi_register_module(MODULE_SCSI_DEV, &sg_template); ! proc_register_dynamic(&proc_scsi, &sg_proc_entry); ! return(ret); } void cleanup_module( void) { + proc_unregister(&proc_scsi, sg_proc_entry.low_ino); scsi_unregister_module(MODULE_SCSI_DEV, &sg_template); unregister_chrdev(SCSI_GENERIC_MAJOR, "sg");

--5Pyd7+fXNt84Ff3A Content-Type: text/plain; charset=us-ascii Content-Description: 2.1.97 patch for "/proc/scsi/sg" Content-Disposition: attachment; filename="sg-2.1.97-proc.patch"

*** linux-2.1.97/drivers/scsi/sg.c.orig Sat Apr 18 18:57:38 1998 --- linux-2.1.97/drivers/scsi/sg.c Sat Apr 18 19:01:38 1998 *************** *** 18,23 **** --- 18,24 ---- #include <linux/ioctl.h> #include <linux/fcntl.h> #include <linux/poll.h> + #include <linux/proc_fs.h> #include <asm/io.h> #include <asm/uaccess.h> #include <asm/system.h> *************** *** 47,52 **** --- 48,68 ---- static int big_inuse=0; #endif + int sg_read_procmem(char *buf, char **start, off_t offset, int len, int unused) + { + return (sprintf(buf, "<SG_BIG_BUFF_LEN=%li>\n", (long) SG_BIG_BUFF)); + } + + struct proc_dir_entry sg_proc_entry = { + 0, /* low_ino: the inode number -- dynamic */ + 2, "sg", /* length of name and name */ + S_IFREG | S_IRUGO, /* file mode */ + 1, 0, 0, /* number of links, owner, group */ + 0, /* size (unused) */ + NULL, /* operations -- use default */ + &sg_read_procmem /* read function */ + }; + struct scsi_generic { Scsi_Device *device; *************** *** 681,692 **** #ifdef MODULE int init_module(void) { sg_template.module = &__this_module; ! return scsi_register_module(MODULE_SCSI_DEV, &sg_template); } void cleanup_module( void) { scsi_unregister_module(MODULE_SCSI_DEV, &sg_template); unregister_chrdev(SCSI_GENERIC_MAJOR, "sg"); --- 697,714 ---- #ifdef MODULE int init_module(void) { + int ret; + + sg_template.module = &__this_module; ! ret = scsi_register_module(MODULE_SCSI_DEV, &sg_template); ! proc_register_dynamic(&proc_scsi, &sg_proc_entry); ! return(ret); } void cleanup_module( void) { + proc_unregister(&proc_scsi, sg_proc_entry.low_ino); scsi_unregister_module(MODULE_SCSI_DEV, &sg_template); unregister_chrdev(SCSI_GENERIC_MAJOR, "sg");

--5Pyd7+fXNt84Ff3A--

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