Re: SG_BIG_BUFF woes on Linux

Gerald Turner (gturner@retina.net)
Tue, 26 Jan 1999 00:08:21 -0800 (PST)

On Mon, 25 Jan 1999, Andreas Dilger wrote:

> 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

I can't believe I completely overlooked this, it appears that the changes
that I was talking about are already here (Oops!). In the case of Linux
sanei_scsi_max_request_size is set to SG_BIG_BUFF and then later it is set
to /proc/sys/kernel/sg-big-buff, just as I was requesting.

> 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...

Great! I just greped through the source a bit, and it looks like cdb.data
element is only used in two places (both memcpy()) and as for cdb being
used in IOCTL, I don't think so, the cdb.hdr element, is the only part
that probably needs to be as-is. Perhaps the structures could be freed
in sanei_scsi_close(). Of course I may be overlooking something again,
I'm too tired now, but maybe tomorrow, I will actually modify some code
and see if I can get it working this way.

Thank you,
Gerald Turner
http://www.retina.net/~gturner/

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