Package: mtools
Version: 3.9.10.ds1-3

The mzip command, used to set passwords on ZIP and JAZ mediums do not
seem to work reliably anymore with the 2.6.18 kernel. Symptoms are
that, sometimes, mzip reports "bad password" even though the password
is, in fact, correct. (Yes, the password is indeed correct, I used the
one letter password 'x' for testing, and that's really hard to forget,
and the problem is reproducable ;-) The problem is likely in the
emulation of the obsolete SCSI ioctl in the kernel used by mzip (to be
handled in a separate bug report) but nevertheless, the following
patch makes use of the more modern SG_IO iotcl for the same job, and
in my tests, fixes mzip.

The following patch to "scsi.c" addresses this issue, and also avoids
a kernel warning on the obsolete interface.

Greetings,
        Thomas

/*---- snip ----*/

--- /tmp/mtools-3.9.10/scsi.c   2002-11-02 13:09:28.000000000 +0100
+++ scsi.c      2006-10-17 21:11:01.000000000 +0200
@@ -37,12 +37,7 @@
 #endif
 
 #ifdef OS_linux
-#define SCSI_IOCTL_SEND_COMMAND 1
-struct scsi_ioctl_command {
-    int  inlen;
-    int  outlen;
-    char cmd[5008];
-};
+#include <scsi/sg.h>
 #endif
 
 #ifdef _SCO_DS
@@ -148,37 +143,33 @@
        return 0;
        
 #elif defined OS_linux
-       struct scsi_ioctl_command scsi_cmd;
+       struct sg_io_hdr scsi_cmd;
 
+       /*
+       ** Init the command
+       */
+       memset(&scsi_cmd,0,sizeof(scsi_cmd));
+       scsi_cmd.interface_id    = 'S';
+       scsi_cmd.dxfer_direction = (mode == 
SCSI_IO_READ)?(SG_DXFER_FROM_DEV):(SG_DXFER_TO_DEV);
+       scsi_cmd.cmd_len         = cmdlen;
+       scsi_cmd.mx_sb_len       = 0;
+       scsi_cmd.dxfer_len       = len;
+       scsi_cmd.dxferp          = data;
+       scsi_cmd.cmdp            = cdb;
+       scsi_cmd.timeout         = ~0; /* where is MAX_UINT defined??? */
+       
+#if DEBUG
+       printf("CMD(%d): %02x%02x%02x%02x%02x%02x 
%sdevice\n",cmdlen,cdb[0],cdb[1],cdb[2],cdb[3],cdb[4],cdb[5],
+              (mode==SCSI_IO_READ)?("<-"):("->"));
+       printf("DATA   : len = %d\n",len);
+#endif
 
-       memcpy(scsi_cmd.cmd, cdb, cmdlen);        /* copy command */
-
-       switch (mode) {
-               case SCSI_IO_READ:
-                       scsi_cmd.inlen = 0;
-                       scsi_cmd.outlen = len;
-                       break;
-               case SCSI_IO_WRITE:
-                       scsi_cmd.inlen = len;
-                       scsi_cmd.outlen = 0;
-                       memcpy(scsi_cmd.cmd + cmdlen,data,len);
-                       break;
-       }
-       
-       if (ioctl(fd, SCSI_IOCTL_SEND_COMMAND, &scsi_cmd) < 0) {
+       if (ioctl(fd, SG_IO,&scsi_cmd) < 0) {
                perror("scsi_io");
                return -1;
        }
-       
-       switch (mode) {
-               case SCSI_IO_READ:
-                       memcpy(data, &scsi_cmd.cmd[0], len);
-                       break;
-               case SCSI_IO_WRITE:
-                       break;
-    }
 
-       return 0;  /* where to get scsi status? */
+       return 0;
 
 #elif (defined _SCO_DS) && (defined SCSIUSERCMD)
        struct scsicmd scsi_cmd;

/*---- snip ----*/


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to