Re: SG_BIG_BUFF woes on Linux

Andreas Dilger (adilger@enel.ucalgary.ca)
Mon, 25 Jan 1999 22:28:39 -0700 (MST)

Gerald Turner writes:
> This function would indeed be nice, but the value is only used once to
> create this structure:
>
> static struct req
> {
> int fd;
> u_int running:1, done:1;
> SANE_Status status;
> size_t *dst_len;
> void *dst;
> struct
> {
> struct sg_header hdr;
> u_int8_t data[SG_BIG_BUFF];
> }
> cdb;
> struct req *next;
> }

Not quite true. It appears that SG_BIG_BUFF is also used to set the value:

> #ifdef SG_BIG_BUFF
> # define MAX_DATA SG_BIG_BUFF
> #endif
.
.
.
> int sanei_scsi_max_request_size = MAX_DATA;

so it would be possible to have a function which returns this value. If I
look farther down in sanei_scsi.c, I see that:

#if USE == LINUX_INTERFACE
if (first_time)
{
char buf[32];
size_t len;
int fd;

first_time = 0;

fd = open ("/proc/sys/kernel/sg-big-buff", O_RDONLY);
if (fd > 0 && (len = read (fd, buf, sizeof (buf) - 1)) > 0)
{
buf[len] = '\0';
sanei_scsi_max_request_size = atoi (buf);
DBG (1, "sanei_scsi_open: sanei_scsi_max_request_size=%d bytes\n",
sanei_scsi_max_request_size);
}
}
#endif

so it appears we are already doing what everyone wanted to do (ie have
dynamic SG_BIG_BUFF for Linux), at least partially. However, we still
have a fixed value for the size of the buffer in req->cdb.data, which
can easily be changed to req->cdb->data in all occurrences, and simply
change the type of cdb.data to be *u_int8_t, and malloc cdb.data in
sanei_scsi_req_enter() and free it in ??? - where are req structs freed?

I'm not 100% sure this will work, since it is possible that the SCSI IOCTL
which needs the format of the cdb struct as-is. Will have to dig deeper...

Cheers, Andreas

-- 
Andreas Dilger  University of Calgary \ "If a man ate a pound of pasta and
                Micronet Research Group \ a pound of antipasto, would they
Dept of Electrical & Computer Engineering \  cancel out, leaving him still
<http://www-mddsp.enel.ucalgary.ca/People/adilger/>    hungry?" -- Dogbert

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