Package: scsitools / 0.12-3

scsidev.patch Patch series | download
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
Description: Select SG_IO or SCSI_IOCTL_SEND_COMMAND at runtime instead
 of compile time (allow to deal with sg devices as well as sd/sr/...).
Forwarded: no
Author: Eric Delaunay <delaunay@debian.org>

--- a/scsidev/scsidev.8
+++ b/scsidev/scsidev.8
@@ -61,7 +61,7 @@
 is a utility that is used to guarantee that the same device node can be used
 for the same scsi device, no matter what other scsi devices are added or
 removed from the scsi chain.  The need for this tool arose because device
-numbers are assigned dynamicly at boot time, and if a new disk were added
+numbers are assigned dynamically at boot time, and if a new disk were added
 to the system (or if some disk didn't spin up), then fixed device nodes would
 cause the wrong filesystems to be mounted, checked, etc.  This can also result
 in security holes, as some device nodes may have permissions that allow
@@ -112,7 +112,8 @@
 an Adaptec 1542.  The "-334" is a means of identifying which 1542
 the device is attached to (since linux supports more than one 1542 in
 the system at the same time) and (in this case) corresponds to the IO
-Port number (hex) of the controller.  The "c0" represents the channel 
+Port number (hex) of the controller (this is the host adapter id number).
+The "c0" represents the channel 
 number (since some host adapters can drive multiple scsi busses).  The
 "i0l0" indicates that this device is scsi ID 0, with lun 0.  Finally
 the "p1" indicated partition number 1.
@@ -183,7 +184,7 @@
 Instructs 
 .B scsidev 
 to use devfs like names, i.e. using the cbtu (controller, bus, target
-unit) chraracters instead of hcil (host, channel, scsi Id, scsi Lun) to
+unit) characters instead of hcil (host, channel, scsi Id, scsi Lun) to
 build the device name.
 .TP
 .I \-o
@@ -280,7 +281,8 @@
 the alias will match all partitions on the disk.
 .TP
 .I hostid=
-Specifies the host adapter id number.
+Specifies the host adapter id number (0x334 part of sdh4-334c0i0l0p1 for
+example).
 .TP
 .I hostnum=
 Specifies the unique number that each host adpater driver returns.
@@ -320,9 +322,8 @@
 (General Public License) Version 2 (or any later version, at your option).
 Note, that the GNU GPL implies, that there is 
 .B NO WARRANTY 
-at all. See file 
-.B COPYING
-for details.
+at all.
+Full text of the GPL can be found in /usr/share/common-licenses/GPL file.
 .SH AVAILABILITY
 .B scsidev
 is available from 
--- a/scsidev/scsidev.c
+++ b/scsidev/scsidev.c
@@ -1792,7 +1792,7 @@
 
 unsigned int find_ioport (const char* nm)
 {
-	unsigned char lnbuf[128];
+	char lnbuf[128];
 	char nm2[64]; char *nmptr;
 	char * buf;
 	FILE * iop = fopen ("/proc/ioports", "r");
@@ -2945,7 +2945,7 @@
 }
 
 
-char* getstr (char* page, int start, int stop)
+char* getstr (unsigned char* page, int start, int stop)
 {
 	int ln;
 	char* str;
@@ -3060,7 +3060,7 @@
 	return no_wwid;
 }
 
-#ifndef SG_IO
+//#ifndef SG_IO
 void my_memmove(unsigned char* dst, unsigned char* src, unsigned int ln)
 {
 	if (src > dst) {
@@ -3072,7 +3072,7 @@
 			*(--dst) = *(--src);
 	}
 }
-#endif
+//#endif
 
 int scsi_cmd(int file, int rlen,
 	     unsigned char* cmd, int cmdlen, 
@@ -3098,21 +3098,27 @@
 	memset(buf, 0, buflen);
 
 	ret = ioctl(file, SG_IO, &sghdr);
+	if (ret >= 0) {
+		if (verbose >= 2)
+			printf("SG_IO %02x %02x %02x: ret=%i, status=%i (host %i, drv %i), read=%i/%i\n",
+			   cmd[0], cmd[1], cmd[2],	
+			   ret, sghdr.status, sghdr.host_status, sghdr.driver_status,
+			   rlen-sghdr.resid, rlen);
+		return ret + sghdr.status;
+	}
 	if (verbose >= 2)
-		printf("SG_IO %02x %02x %02x: ret=%i, status=%i (host %i, drv %i), read=%i/%i\n",
-		       cmd[0], cmd[1], cmd[2],	
-		       ret, sghdr.status, sghdr.host_status, sghdr.driver_status,
-		       rlen-sghdr.resid, rlen);
-	return ret + sghdr.status;
-#else
+	    printf("SG_IO error: %i, fallback to old SCSI_IOCTL_SEND_COMMAND\n", errno);
+#endif
 	memset(buf, 0, buflen);
 	*(  (int *) buf)     = 0;	/* Length of input data */
-	*( ((int *) buf+1) ) = rlen;	/* Length of output data */
+	*( ((int *) buf+1) ) = rlen-8;	/* Length of output data */
 	memcpy(buf+8, cmd, cmdlen);
 	ret = ioctl(file, SCSI_IOCTL_SEND_COMMAND, buf);
+	if (ret < 0 && verbose >= 2)
+		printf("SCSI_IOCTL_SEND_COMMAND %02x %02x %02x: ret=%i, errno=%i\n",
+		       cmd[0], cmd[1], cmd[2], ret, errno);
 	my_memmove(buf, buf+8, buflen-8);
 	return ret;
-#endif
 }
 
 #define INQBUFSZ 512