127
121
int main( int argc, char *argv[] )
129
123
int b,bstart=0,bstep=1;
132
125
unsigned char *cmd;
133
unsigned int capacity, sectorsize;
126
int capacity, sectorsize;
134
127
int this_count, block;
136
129
double starttime, endtime;
137
int read_len = 10; /* length of read command */
138
int fua = 0; /* "force unit access" for READ(10): don't read from cache but from media */
144
while (argc>c && argv[c][0] == '-') {
145
for(i=1; i < strlen(argv[c]); i++)
146
switch (argv[c][i]) {
147
case 'v': verbose = 1; break;
149
case 'i': legacy_ioctl = 1; break;
151
case 'f': fua = 1; break;
152
case '6': read_len = 6; break;
158
infile = fopen( argv[c], "r" );
164
if (argc>c+1) bstart = atoi(argv[c+1]);
165
if (argc>c+2) bstep = atoi(argv[c+2]);
167
if (infile == NULL || argc==1 || argc>c+3) {
169
printf("usage: sraw [-v]%s scsi-device [ bstart [ bstep ] ]\n",
179
memset(buffer, 0, sizeof(buffer));
132
printf("usage: srawread scsi-device [ bstart [ bstop ] ]\n");
136
infile = fopen( argv[1], "r" );
139
if (argc>2) bstart = atoi(argv[2]);
140
if (argc>3) bstep = atoi(argv[2]);
142
for (i=0; i<10*1024; i++)
181
147
*( (int *) buffer ) = 0; /* length of input data */
182
148
*( ((int *) buffer) + 1 ) = read_size; /* length of output buffer */
184
cmd = (unsigned char *) ( ((int *) buffer) + 2 );
150
cmd = (char *) ( ((int *) buffer) + 2 );
186
cmd[0] = 0x25; /* READ CAPICTY (10 bytes)*/
187
cmd[1] = 0x00; /* b7-5: lun=0, b4-1: reserved, b0: reladdr=0 */
188
/* cmd[2..5] = 0x00; logical block address = 0 */
189
/* cmd[6..8] = 0x00; (reserved), cmd[8].b0=PMI(0) */
190
/* cmd[9] = 0x00; control */
152
cmd[0] = 0x25; /* INQUIRY */
153
cmd[1] = 0x00; /* lun=0, evpd=0 */
154
cmd[2] = 0x00; /* page code = 0 */
155
cmd[3] = 0x00; /* (reserved) */
156
cmd[4] = 0x00; /* allocation length */
157
cmd[5] = 0x00; /* control */
193
if (! legacy_ioctl) {
194
memset(&sgbuf, 0, sizeof(sgbuf));
195
sgbuf.interface_id = 'S'; /* SCSI Generic Interface */
196
sgbuf.dxfer_direction = SG_DXFER_FROM_DEV;
199
sgbuf.dxfer_len = 8; /* send back 8 bytes of data (capacity, sectorsize) */
201
sgbuf.timeout = 2000;
202
status = ioctl( fileno(infile), SG_IO, &sgbuf );
206
159
status = ioctl( fileno(infile), 1 /* SCSI_IOCTL_SEND_COMMAND */, buffer );
211
161
capacity = (buffer[8] << 24) | (buffer[9] << 16) | (buffer[10] << 8) | buffer[11];
212
162
sectorsize = (buffer[12] << 24) | (buffer[13] << 16) | (buffer[14] << 8) | buffer[15];
214
printf("Size %llu bytes, sectorsize %u\n", ((uint64_t)capacity) * sectorsize, sectorsize);
163
printf("Size %d sectorsize %d\n", capacity * (sectorsize >> 9), sectorsize);
218
167
for (i=0; i<10*1024; i++)
224
173
this_count = read_size / sectorsize;
225
174
starttime = time_so_far();
227
176
*( (int *) buffer ) = 0; /* length of input data */
228
177
*( ((int *) buffer) + 1 ) = read_size; /* length of output buffer */
230
cmd = (unsigned char *) ( ((int *) buffer) + 2 );
179
cmd = (char *) ( ((int *) buffer) + 2 );
232
181
b = bstart + bstep * block;
233
if (read_len == 10) {
234
cmd[0] = 0x28; /* read_10 */
238
cmd[2] = (b >> 24) & 0xff;
239
cmd[3] = (b >> 16) & 0xff;
240
cmd[4] = (b >> 8) & 0xff;
243
cmd[7] = (this_count >> 8) & 0xff; /* transfer length */
244
cmd[8] = this_count & 0xff;
245
cmd[9] = 0x00; /* control */
248
cmd[0] = 0x08; /* read_6 */
249
cmd[1] = (b >> 16) & 0x1f;
250
cmd[2] = (b >> 8) & 0xff;
256
if (! legacy_ioctl) {
257
memset(&sgbuf, 0, sizeof(sgbuf));
258
sgbuf.interface_id = 'S'; /* SCSI Generic Interface */
259
sgbuf.dxfer_direction = SG_DXFER_FROM_DEV;
260
sgbuf.cmd_len = read_len;
262
sgbuf.dxfer_len = read_size;
264
sgbuf.timeout = 2000;
265
status = ioctl( fileno(infile), SG_IO, &sgbuf );
183
cmd[0] = 0x28; /* read_10 */
188
cmd[2] = (b >> 24) & 0xff;
189
cmd[3] = (b >> 16) & 0xff;
190
cmd[4] = (b >> 8) & 0xff;
193
cmd[7] = (this_count >> 8) & 0xff; /* transfer length */
194
cmd[8] = this_count & 0xff;
195
cmd[9] = 0x00; /* control */
196
#else /* USE_READ_10 */
197
cmd[0] = 0x08; /* read_6 */
198
cmd[1] = (b >> 16) & 0x1f;
199
cmd[2] = (b >> 8) & 0xff;
203
#endif /* USE_READ_10 */
269
205
status = ioctl( fileno(infile), 3 /* SCSI_IOCTL_BENCHMARK_COMMAND */, buffer );
272
printf("ioctl: %s\n", strerror(errno));
274
printf("(%d) ", status);
206
if(status) fprintf(stderr,"%x ", status);
276
207
block += this_count;
277
208
} while(block < (10000 / (sectorsize >> 9)));
278
209
endtime = time_so_far() - starttime;
279
210
rate = (block * sectorsize) / endtime;
281
printf("%6d %10.4f %6d %8d \n",
282
read_size, endtime, block, rate);
284
printf("Blocksize %d, time elapsed %1.4f seconds, %d blocks. Throughput = %d bytes/sec\n",
285
read_size, endtime, block, rate);
211
#ifdef LESS_VERBOSE_OUTPUT
212
printf("%6d %10.4f %6d %8d \n",
213
read_size, endtime, block, rate);
214
#else /* LESS_VERBOSE_OUTPUT */
215
printf("Blocksize %d, time elapsed %1.4f seconds, %d blocks. Throughput = %d bytes/sec\n",
216
read_size, endtime, block, rate);
217
#endif /* LESS_VERBOSE_OUTPUT */
287
219
read_size += 4096;
288
220
} while(read_size <= 2*64*1024);