Hi,

the wodim device scan bug vanished and re-appeared with the Debian versions
although /dev/scd* did not re-appear. So there must be some other influence.

I think i can prove from the source code that on kernels with minor
revision number below 6 wodim enumerates /dev/sg*, whereas on kernels with
minor revision number of 6 or larger it tries to enumerate /dev/scd*.

/dev/sg* exist for any device under control of the SCSI driver.
/dev/scd* have become out of fashion. (One can work around the bug by
manually creating links from /dev/scd* to /dev/sr*.)

So with kernel 3.2 of Wheezy the bug vanished and with 3.16 of Jessie it
re-appeared. Early 4.X will not show the bug, but beginning with 4.6 it
will be back again. So Stretch with kernel 4.9 will have it.

Source study:

  https://sources.debian.net/src/cdrkit/9:1.1.11-3/libusal/scsi-linux-sg.c/#L509

                /* scan and maybe keep one open, sg_setup decides */
#define HDX 0
#define SCD 1
#define SG 2
...
                for(h=HDX; h <= (fake_atabus ? HDX : SG) ; h++) {
                        ...
                        switch(h) {
                                case(HDX): 
                                        {
                                                pattern="/dev/hd%c";
                                        ...
                                case(SCD):
                                        {
                                                if(!check_linux_26())
                                                        continue;
                                                pattern="/dev/scd%d";
                                        ...
                                case(SG):
                                        {
                                                if(check_linux_26())
                                                        continue; 
                                                ...
                                                pattern="/dev/sg%d";
                                        ...

So it looks for /dev/hd* (drives under old IDE driver) in any case.
If "check_linux_26()" is true, then it looks for /dev/scd*, which
are missing because out of fashion.
If "check_linux_26()" is false, then it looks for /dev/sg*, which exist.

Beginning with Linux 2.5.X it became possible to use /dev/sr*
for ioctl(SG_IO), which does the SCSI command transactions for wodim.
So obviously the test shall distinguish kernel 2.6 or younger from
kernel 2.5 or older.

But at
  https://sources.debian.net/src/cdrkit/9:1.1.11-3/libusal/scsi-linux-sg.c/#L251
there seems to be missing the check for the major kernel version:

BOOL check_linux_26() {
        int gen, tmp;
        struct utsname buf;
        return ( 0==uname( &buf ) && sscanf(buf.release, "%d.%d", &gen, &tmp)>1 
&& tmp>=6);
}

I tested this code on my Jessie. tmp has the value 16 and thus the
function returns 1. So my wodim looks for /dev/scd*.


If there is maintainer interest, then i would propose two code changes:

-------------------------------------------------------------------------
In libusal/scsi-linux-sg.c, check_linux_26(), line 254:

-        return ( 0==uname( &buf ) && sscanf(buf.release, "%d.%d", &gen, 
&tmp)>1 && tmp>=6);
+        return ( 0==uname( &buf ) && sscanf(buf.release, "%d.%d", &gen, 
&tmp)>1 && (gen>2 || tmp>=6));

This will not change the function result in Jessie and Stretch but maybe
in a future release with kernel 5.X. 

-------------------------------------------------------------------------
In libusal/scsi-linux-sg.c, usalo_open(), line 532:

-                                               pattern="/dev/scd%d";
+                                               pattern="/dev/sr%d";

This will fix the enumeration bug on all kernels not older than 2.6.
On older kernels /dev/sg* is still the right path to use.

-------------------------------------------------------------------------


Have a nice day :)

Thomas

Reply via email to