aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/mtools/files/use-sg_io.patch
blob: 33867deb1aadd14b139949f0151bca1342778aa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
08.scsi.c.dpatch by Thomas Richter <thor@mail.math.tu-berlin.de>
#393878 mzip unreliable on 2.6.18

--- mtools-3.9.10/scsi.c	2002-11-02 13:09:28.000000000 +0100
+++ mtools-3.9.10/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
--- mtools-3.9.10/scsi.c	2007-05-26 19:02:56.000000000 +1000
+++ mtools-3.9.10/scsi.c	2008-04-08 20:30:16.000000000 +1000
@@ -148,37 +148,33 @@ int scsi_cmd(int fd, unsigned char *cdb,
 	return 0;
 	
 #elif defined OS_linux
-	struct scsi_ioctl_command my_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(my_scsi_cmd.cmd, cdb, cmdlen);        /* copy command */
-
-	switch (mode) {
-		case SCSI_IO_READ:
-			my_scsi_cmd.inlen = 0;
-			my_scsi_cmd.outlen = len;
-			break;
-		case SCSI_IO_WRITE:
-			my_scsi_cmd.inlen = len;
-			my_scsi_cmd.outlen = 0;
-			memcpy(my_scsi_cmd.cmd + cmdlen,data,len);
-			break;
-	}
-	
-	if (ioctl(fd, SCSI_IOCTL_SEND_COMMAND, &my_scsi_cmd) < 0) {
+	if (ioctl(fd, SG_IO,&scsi_cmd) < 0) {
 		perror("scsi_io");
 		return -1;
 	}
 	
-	switch (mode) {
-		case SCSI_IO_READ:
-			memcpy(data, &my_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 my_scsi_cmd;