aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/scsi_debug.c
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2008-03-25 04:04:46 -0400
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2008-04-07 13:19:03 -0400
commitd5cdc9898b5589acc77db91a1e9c0feb9f32abef (patch)
treefababb50ec26bf696b30ff3bec43541392793064 /drivers/scsi/scsi_debug.c
parentb8e3d3aeabe3be471e448ff5e51b6e57b5819913 (diff)
[SCSI] scsi_debug: fix lba and data length calculation bugs
For example, `modprobe scsi_debug virtual_gb=1100` gives: scsi7 : scsi_debug, version 1.81 [20070104], dev_size_mb=8, opts=0x0 scsi 7:0:0:0: Direct-Access Linux scsi_debug 0004 PQ: 0 ANSI: 5 sd 7:0:0:0: [sdc] 2306867200 512-byte hardware sectors (1181116 MB) sd 7:0:0:0: [sdc] Write Protect is off sd 7:0:0:0: [sdc] Mode Sense: 73 00 10 08 sd 7:0:0:0: [sdc] Write cache: enabled, read cache: enabled, supports DPO and FUA sd 7:0:0:0: [sdc] 2306867200 512-byte hardware sectors (1181116 MB) sd 7:0:0:0: [sdc] Write Protect is off sd 7:0:0:0: [sdc] Mode Sense: 73 00 10 08 sd 7:0:0:0: [sdc] Write cache: enabled, read cache: enabled, supports DPO and FUA sdc: unknown partition table sd 7:0:0:0: [sdc] Attached SCSI disk sd 7:0:0:0: Attached scsi generic sg6 type 0 end_request: I/O error, dev sdc, sector 2306867072 Buffer I/O error on device sdc, logical block 288358384 end_request: I/O error, dev sdc, sector 2306867072 Buffer I/O error on device sdc, logical block 288358384 end_request: I/O error, dev sdc, sector 2306867192 (snip) Note that this converts all the calculations (including the correct calculations) for unification. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Acked-by: Douglas Gilbert <dougg@torque.net> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers/scsi/scsi_debug.c')
-rw-r--r--drivers/scsi/scsi_debug.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 5f348e7b1184..65c88dde72b4 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -252,33 +252,37 @@ static struct bus_type pseudo_lld_bus;
252static void get_data_transfer_info(unsigned char *cmd, 252static void get_data_transfer_info(unsigned char *cmd,
253 unsigned long long *lba, unsigned int *num) 253 unsigned long long *lba, unsigned int *num)
254{ 254{
255 int i;
256
257 switch (*cmd) { 255 switch (*cmd) {
258 case WRITE_16: 256 case WRITE_16:
259 case READ_16: 257 case READ_16:
260 for (*lba = 0, i = 0; i < 8; ++i) { 258 *lba = (u64)cmd[9] | (u64)cmd[8] << 8 |
261 if (i > 0) 259 (u64)cmd[7] << 16 | (u64)cmd[6] << 24 |
262 *lba <<= 8; 260 (u64)cmd[5] << 32 | (u64)cmd[4] << 40 |
263 *lba += cmd[2 + i]; 261 (u64)cmd[3] << 48 | (u64)cmd[2] << 56;
264 } 262
265 *num = cmd[13] + (cmd[12] << 8) + 263 *num = (u32)cmd[13] | (u32)cmd[12] << 8 | (u32)cmd[11] << 16 |
266 (cmd[11] << 16) + (cmd[10] << 24); 264 (u32)cmd[10] << 24;
267 break; 265 break;
268 case WRITE_12: 266 case WRITE_12:
269 case READ_12: 267 case READ_12:
270 *lba = cmd[5] + (cmd[4] << 8) + (cmd[3] << 16) + (cmd[2] << 24); 268 *lba = (u32)cmd[5] | (u32)cmd[4] << 8 | (u32)cmd[3] << 16 |
271 *num = cmd[9] + (cmd[8] << 8) + (cmd[7] << 16) + (cmd[6] << 24); 269 (u32)cmd[2] << 24;
270
271 *num = (u32)cmd[9] | (u32)cmd[8] << 8 | (u32)cmd[7] << 16 |
272 (u32)cmd[6] << 24;
272 break; 273 break;
273 case WRITE_10: 274 case WRITE_10:
274 case READ_10: 275 case READ_10:
275 case XDWRITEREAD_10: 276 case XDWRITEREAD_10:
276 *lba = cmd[5] + (cmd[4] << 8) + (cmd[3] << 16) + (cmd[2] << 24); 277 *lba = (u32)cmd[5] | (u32)cmd[4] << 8 | (u32)cmd[3] << 16 |
277 *num = cmd[8] + (cmd[7] << 8); 278 (u32)cmd[2] << 24;
279
280 *num = (u32)cmd[8] | (u32)cmd[7] << 8;
278 break; 281 break;
279 case WRITE_6: 282 case WRITE_6:
280 case READ_6: 283 case READ_6:
281 *lba = cmd[3] + (cmd[2] << 8) + ((cmd[1] & 0x1f) << 16); 284 *lba = (u32)cmd[3] | (u32)cmd[2] << 8 |
285 (u32)(cmd[1] & 0x1f) << 16;
282 *num = (0 == cmd[4]) ? 256 : cmd[4]; 286 *num = (0 == cmd[4]) ? 256 : cmd[4];
283 break; 287 break;
284 default: 288 default: