Hi, On Mon, Feb 25, 2002 at 10:39:51PM +0000, Tim Waugh wrote: > On Mon, Feb 25, 2002 at 11:24:44PM +0100, Oliver Rauch wrote: > > > BTW: What happens when the user does not have the correct permissions > > for /dev/sg0 (or the device that is used to load modules)? > > Oh, good point: really it ought to try /dev/sg0, /dev/sg1, etc until > it finds one that works.
The problem is: can you detect if it works? Yes, you can check if the open was successful. But does this mean, that the correct SCSi driver was loaded? E.g. /dev/sg0 is a SCSI cdrom at controller A, /dev/sg1 is (would be) a scanner at controller A. The driver is manually loaded, B is loaded automatically by scsi_hostadapter. An open to /dev/sg0 will load the sg module and return without error. But would driver B be also loaded? I can't test here... I append another patch which just opens all the sg etc. devices. I'm using a maximum of 16 devices and the list from sanei_scsi.c: lx_dnl[] = { {"/dev/sg", 0}, {"/dev/sg", 'a'}, {"/dev/uk", 0}, {"/dev/gsc", 0} }; I don't think that dev/uk* and dev/gsc* are needed but I haven't touched this struct yet. uk is not mentioned in the Linux kernel devices.txt at all and gscd is a device file for a special CDROM. Here are some times for "time scanimage -L", sane-backends CVS default installation: Without SCSI scanner connected, no /dev/scanner link: without patch: with patch: real 0m0.100s real 0m1.058s user 0m0.040s user 0m0.400s sys 0m0.020s sys 0m0.260s Without SCSI scanner connected, with /dev/scanner link: real 0m0.371s real 0m1.286s user 0m0.150s user 0m0.550s sys 0m0.130s sys 0m0.300s With SCSI scanner connected (aic7xxx module loaded), no /dev/scanner link: real 0m0.133s real 0m0.148s user 0m0.030s user 0m0.030s sys 0m0.030s sys 0m0.030s With SCSI scanner connected (aic7xxx module loaded), with /dev/scanner link: real 0m0.273s real 0m0.277s user 0m0.040s user 0m0.040s sys 0m0.030s sys 0m0.040s So at least without a SCSI scanner the detection code is much slower. Maybe we can get this lower with omitting uk and gsc devices but I haven't tested yet. Maybe the number of devices (16 currently) can be reduced, too. The theoretical maximum with major/minor numbers is 256. Patch: Index: sanei/sanei_scsi.c =================================================================== RCS file: /cvsroot/external/sane/sane-backends/sanei/sanei_scsi.c,v retrieving revision 1.31 diff -u -u -r1.31 sanei_scsi.c --- sanei_scsi.c 2002/02/09 16:37:21 1.31 +++ sanei_scsi.c 2002/03/01 13:18:51 @@ -2424,6 +2424,34 @@ return 0; } +void +lx_preload_drivers () +{ + int device_number, i; + int fd; + char name[1024]; +#define LX_MAX_DEVICE_NUMBER 15 + + + for (i = 0; i < NELEMS(lx_dnl); i++) + { + for (device_number = 0; device_number <= LX_MAX_DEVICE_NUMBER; + device_number++) + { + if (lx_dnl[i].base) + snprintf (name, sizeof(name), "%s%c", lx_dnl[i].prefix, + lx_dnl[i].base + device_number); + else + snprintf (name, sizeof(name), "%s%d", lx_dnl[i].prefix, + device_number); + fd = open (name, O_RDONLY | O_NONBLOCK); + if (fd >= 0) + close (fd); + } + } + return; +} + void /* calls 'attach' function pointer with sg device file name iff match */ sanei_scsi_find_devices (const char *findvendor, const char *findmodel, const char *findtype, @@ -2484,6 +2512,8 @@ param[7].u.i = &lun; DBG_INIT (); + + lx_preload_drivers(); proc_fp = fopen (PROCFILE, "r"); if (!proc_fp)