aboutsummaryrefslogtreecommitdiff
path: root/doc/sg3_utils.html
blob: 0c47ce2edf2af81b4da769edb5f05476e32ffc51 (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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>Linux sg3_utils package</title>
  <meta http-equiv="Content-Type"
 content="text/html; charset=iso-8859-1">
  <meta name="keywords" content="sg3_utils, SCSI utilities, linux">
  <meta name="GENERATOR"
 content="Mozilla/4.79 [en] (X11; U; Linux 2.5.31 i686) [Netscape]">
</head>
<body alink="#ff0000" background="paper.jpg" bgcolor="#ffffff"
 link="#0000ff" text="#000000" vlink="#000080">
<center>
<h1><a class="mozTocH1" name="mozTocId697451"></a> The&nbsp; Linux
sg3_utils package</h1>
</center>
<a href="#intro"></a>
<ol id="mozToc">
<!--mozToc h1 1 h2 2 h3 3 h4 4 h5 5 h6 6--><li><a href="#mozTocId697451">
The&nbsp; Linux
sg3_utils package</a>
    <ol>
      <li><a href="#mozTocId746876"> Introduction</a></li>
      <li><a href="#mozTocId832900"> Contents of sg3_utils</a></li>
      <li><a href="#mozTocId143590">Changing mode page
settings</a></li>
      <li><a href="#mozTocId301018">Examples</a></li>
      <li><a href="#mozTocId585558"> Notes</a></li>
      <li><a href="#mozTocId479511"> Download</a></li>
    </ol>
  </li>
</ol>
<h2><a class="mozTocH2" name="mozTocId746876"></a> Introduction</h2>
The <span style="font-weight: bold;">sg3_utils</span> package contains
utilities
that send SCSI commands to "SCSI" devices. As well as devices on
transports associated with SCSI (e.g. Fibre Channel (FCP) and the SCSI
Parallel Interface(SPI)) many
other devices use SCSI command sets. ATAPI cd/dvd drives
and SATA disks that use a translation layer or bridge device are
examples of devices that use SCSI command sets.<br>
<br>
SCSI command sets are divided into a common set and several device
class specific sets. The common set of commands is referred to as the
SCSI Primary Commands (SPC) with SPC-3 being the most recent standard.
The mandatory SCSI INQUIRY command is defined in SPC-3. The SCSI Block
Commands (SBC)
cover direct access devices such as disks. The MultiMedia Commands
(MMC) cover CD and DVD drives and the media within them. SCSI
command sets and transport
definitions can be found at the <a href="http://www.t10.org">www.t10.org</a>
site with this page giving a good diagrammatic overview: <a
 href="http://www.t10.org/scsi-3.htm">www.t10.org/scsi-3.htm</a> .<br>
<br>
The
<span style="font-weight: bold;">sg3_utils</span> package targets the
linux kernel 2.4 and 2.6 series and is
still being enhanced. An earlier package called sg_utils
targeted the linux kernel 2.2 series with some support for the
2.0 series. See an earlier version of this web <a href="uu_index.html">page</a>
for further information about sg_utils.&nbsp; This
document describes
<span style="font-weight: bold;">version 1.22</span> of <span
 style="font-weight: bold;">sg3_utils</span> .&nbsp; A subset of these
utilities have been ported to the FreeBSD, Tru64 and Windows operating
systems.<br>
<br>
In the linux kernel 2.4 series most of these utilities must be
used with a SCSI generic (sg) driver device name (e.g. <span
 style="font-family: monospace;">/dev/sg0</span>). In
the lk 2.6 series almost all of these utilities can be used with the
primary device names as well (e.g. <span
 style="font-family: monospace;">/dev/sda, /dev/scd0, /dev/st0</span>
and
<span style="font-family: monospace;">/dev/hdd</span> (if it is an
ATAPI device)). The SCSI generic (sg) interface
still represents a cleaner interface than the primary device names
since the drivers behind primary device names have their
own policies, may interfere with error processing and, in some cases,
run their own
state machines.<br>
<p>A list of SCSI and storage utility programs that was at the bottom
of this page has been moved to the <a href="tools.html">tools</a> page.<span
 style="font-weight: bold;"><br>
</span></p>
<h2><a class="mozTocH2" name="mozTocId832900"></a> Contents of sg3_utils</h2>
Here is a listing in alphabetical order of the utilities in the
sg3_utils package:<br>
<br>
<table style="width: 100%; text-align: left;" border="1" cellpadding="2"
 cellspacing="2">
  <caption align="bottom"><span style="font-weight: bold;">Table 1
Utilities in sg3_utils</span><br>
  </caption> <tbody>
    <tr>
      <td style="vertical-align: top;"><span style="font-weight: bold;">Utility</span><br>
      </td>
      <td style="vertical-align: top;"><span style="font-weight: bold;">Main
SCSI commands</span><br>
      </td>
      <td style="vertical-align: top;"><span style="font-weight: bold;">subdirectory<br>
      </span> </td>
      <td style="vertical-align: top;"><span style="font-weight: bold;">Ported</span><br>
      </td>
      <td style="vertical-align: top;"><span style="font-weight: bold;">Notes</span><br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">hxascdmp<br>
      </td>
      <td style="vertical-align: top;">-<br>
      </td>
      <td style="vertical-align: top;">utils<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">converts stdin (assumed binary)
to ASCII hex and ASCII, sending its output to stdout (like Unix <span
 style="font-weight: bold;">od</span> command)<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">rescan-scsi-bus.sh<br>
      </td>
      <td style="vertical-align: top;">-<br>
      </td>
      <td style="vertical-align: top;">archive<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">copy of Kurt Garloff's useful
script<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">scsi_inquiry<br>
      </td>
      <td style="vertical-align: top;">INQUIRY<br>
      </td>
      <td style="vertical-align: top;">examples<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">uses deprecated
SCSI_IOCTL_SEND_COMMAND ioctl<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sdparm<br>
      </td>
      <td style="vertical-align: top;">MODE SENSE/SELECT, INQUIRY<br>
      </td>
      <td style="vertical-align: top;">****<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">was in sg3_utils for a short
time; now in own package, see <a href="sdparm.html">sdparm</a> .
sdparm manipulates mode pages, reads VPD pages and sends simple
commands.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_chk_asc<br>
      </td>
      <td style="vertical-align: top;">-<br>
      </td>
      <td style="vertical-align: top;">utils<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">check asc/ascq codes from
www.t10.org page against sg3_utils table<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sginfo<br>
      </td>
      <td style="vertical-align: top;">MODE SENSE/SELECT, READ DEFECT<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">symbolic decoding (optional
changing) of mode pages. Can also output (disk) defect lists. In lk 2.4
can be given primary device nodes (e.g. /dev/sda) as well as sg device
nodes. See <span style="font-weight: bold;">scsiinfo</span> package
notes below.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sgm_dd<br>
      </td>
      <td style="vertical-align: top;">READ, WRITE<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">sg_dd variant that uses memory
mapped IO (only on sg devices)<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sgp_dd<br>
      </td>
      <td style="vertical-align: top;">READ, WRITE<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">sg_dd variant that uses POSIX
threads<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_dd<br>
      </td>
      <td style="vertical-align: top;">READ, WRITE<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">Unix <span
 style="font-weight: bold;">dd</span> command variant, uses
SG_IO ioctl to send SCSI commands to copy data. See the <a
 href="sg_dd.html">sg_dd</a> page. </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_emc_trespass<br>
      </td>
      <td style="vertical-align: top;">MODE SELECT<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">utility specialized for EMC
Clariion series<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_format<br>
      </td>
      <td style="vertical-align: top;">FORMAT<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w<br>
      </td>
      <td style="vertical-align: top;">format or resize a SCSI disk<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_get_config<br>
      </td>
      <td style="vertical-align: top;">GET CONFIGURATION<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">fetch features and profiles of a
cd/dvd drive and/or its current media<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_ident<br>
      </td>
      <td style="vertical-align: top;">REPORT/SET DEVICE IDENTIFIER<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">default is to report (fetch) the
device identifier. With the '--set' option a new identifier is sent
to the device.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_inq<br>
      </td>
      <td style="vertical-align: top;">INQUIRY<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">fetch standard response, VPD
pages (including device identification) or version descriptors. Also
can perform IDENTIFY (PACKET) DEVICE ATA command. VPD page decoding now
also performed by sg_vpd .<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_logs<br>
      </td>
      <td style="vertical-align: top;">LOG SENSE<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">fetch log sense pages, decode
standard pages<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_luns<br>
      </td>
      <td style="vertical-align: top;">REPORT LUNS<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">fetch luns reported by a device
(lun 0 or "well known lu")<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_map<br>
      </td>
      <td style="vertical-align: top;">INQUIRY<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">shows mapping between sg devices
and primary device node (if any). In lk 2.6 see <a
 href="../scsi/lsscsi.html">lsscsi</a> .<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_map26<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">maps between single sg device
and primary device node (and vice versa). Also does mapping in to, and
out of, sysfs. For the linux 2.6 series.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_modes<br>
      </td>
      <td style="vertical-align: top;">MODE SENSE<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">dump mode pages (mainly in hex)<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_opcodes<br>
      </td>
      <td style="vertical-align: top;">REPORT SUPPORTED OPERATION CODES<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fetch supported SCSI commands or
supported task management functions<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_persist<br>
      </td>
      <td style="vertical-align: top;">PERSISTENT RESERVE IN/OUT<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">control persistent reservations
and report
reservation status<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_prevent<br>
      </td>
      <td style="vertical-align: top;">PREVENT ALLOW MEDIUM REMOVAL<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">control media removal, mainly
for those SCSI devices which have removable media (e.g. CD/DVD and tape
drives)<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_rbuf<br>
      </td>
      <td style="vertical-align: top;">READ BUFFER<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">read from SCSI device cache.
Typically for testing the SCSI transport (for throughput or errors)<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_rdac<br>
      </td>
      <td style="vertical-align: top;">MODE SENSE/SELECT<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w</td>
      <td style="vertical-align: top;">display or modify RDAC redundant
controller mode page<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_read<br>
      </td>
      <td style="vertical-align: top;">READ<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">read continually from same
offset. Syntax similar to sg_dd (without write side). Can test SCSI
device cache and transport performance (like sg_rbuf).<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_readcap<br>
      </td>
      <td style="vertical-align: top;">READ CAPACITY<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">fetch the number of blocks and
the individual block size for disks and CD/DVD media<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_read_long<br>
      </td>
      <td style="vertical-align: top;">READ LONG<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">read data from given lba which
includes the block and ECC data.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_reassign<br>
      </td>
      <td style="vertical-align: top;">REASSIGN BLOCKS<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">reassign a lba from one sector
on a disk (typically damaged) to a new (spare) sector. User data copied
if it is recoverable.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_requests<br>
      </td>
      <td style="vertical-align: top;">REQUEST SENSE<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">fetch sense data from the given
SCSI device. Useful if no autosense , to get progress indication (e.g.
during a format) or find the power condition state.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_reset<br>
      </td>
      <td style="vertical-align: top;">-<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">Issue a driver, (SCSI) bus or
device (target or lun?) reset.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_rmsn<br>
      </td>
      <td style="vertical-align: top;">READ MEDIA SERIAL NUMBER<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">Relatively new command
added to SPC-3. Format of response is vendor specific so this utility
outputs it in hex (default) or binary.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_rtpg<br>
      </td>
      <td style="vertical-align: top;">REPORT TARGET PORT GROUPS<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">Specialized for multi-ported
SCSI devices where one port (or a group of them) is preferred for IO
over another (or others).<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_sat_identify<br>
      </td>
      <td style="vertical-align: top;">ATA PASS-THROUGH</td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w<br>
      </td>
      <td style="vertical-align: top;">Sends IDENTIFY DEVICE or
IDENTIFY PACKET DEVICE ATA commands via the SAT ATA PASS-THROUGH (16 or
12) SCSI command.</td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg__sat_identify<br>
      </td>
      <td style="vertical-align: top;">ATA PASS-THROUGH<br>
      </td>
      <td style="vertical-align: top;">examples<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">Simpler version of
sg_sat_identify that uses the linux SG_IO ioctl directly. See also
sg_sat_chk_power, sg_sat_set_features and sg_sat_smart_rd_data in the
examples subdirectory.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_scan<br>
      </td>
      <td style="vertical-align: top;">[INQUIRY]<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">w<br>
      </td>
      <td style="vertical-align: top;">maps each sg device name to
the corresponding numeric &lt;host, channel, target', lun&gt; tuple. In
lk 2.6 series the "<a href="scsi/lsscsi.html">lsscsi</a> -g" command is
similar. In Windows shows one device per line, with the device's
various names and INQUIRY response string on that line.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_senddiag<br>
      </td>
      <td style="vertical-align: top;">SEND DIAGNOSTIC<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">Issues either a default self
test or a short/extended foreground/background self test. With no
arguments it uses RECEIVE DIAGNOSTIC RESULTS to list all supported
diagnostic
pages.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_ses<br>
      </td>
      <td style="vertical-align: top;">SEND/RECEIVE DIAGNOSTIC<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">Fetches status diagnostic
pages from, and sends some control pages to, a SCSI Enclosure Services
(SES) device.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_simple1,2,3,4,5<br>
      </td>
      <td style="vertical-align: top;">INQUIRY, TEST UNIT READY<br>
      </td>
      <td style="vertical-align: top;">examples<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">Simple code examples of using
the scsi generic (sg) driver interface<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_simple16<br>
      </td>
      <td style="vertical-align: top;">READ<br>
      </td>
      <td style="vertical-align: top;">examples<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">Simple code example of sending a
16 byte cdb SCSI READ command<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_start<br>
      </td>
      <td style="vertical-align: top;">START STOP UNIT<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">Controls the power condition
state of a SCSI device. Primary use is to spin up and down SCSI disks.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_sync<br>
      </td>
      <td style="vertical-align: top;">SYNCHRONIZE CACHE<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">Causes disk caches to be flushed
to media<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_test_rwbuf<br>
      </td>
      <td style="vertical-align: top;">READ/WRITE BUFFER<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">Random pattern written to SCSI
device buffer then read back and checked. Used in testing for data
corruption.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_turs<br>
      </td>
      <td style="vertical-align: top;">TEST UNIT READY<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">Issue one or more Test Unit
Ready commands. Can be used to time SCSI command overhead.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_verify</td>
      <td style="vertical-align: top;">VERIFY</td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">reads indicated blocks on a SCSI
disks, stops on the first error found. Does not yield any data. Useful
for media scans.</td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_vpd<br>
      </td>
      <td style="vertical-align: top;">INQUIRY<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w<br>
      </td>
      <td style="vertical-align: top;">Decodes standard and some vendor
Vital Product Data (VPD) pages.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_write_long<br>
      </td>
      <td style="vertical-align: top;">WRITE LONG<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">writes to a lba, data which
includes the block and ECC data. Suitable data typically fetched by
prior
sg_read_long utility.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">sg_wr_mode<br>
      </td>
      <td style="vertical-align: top;">MODE SELECT<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">fb,t64,w </td>
      <td style="vertical-align: top;">writes mode pages supplied in
ASCII hex (e.g. from "sg_modes -r") to the given SCSI device. See <a
 href="sdparm.html">sdparm</a> for another method of setting mode page
parameters.<br>
      </td>
    </tr>
  </tbody>
</table>
<br>
More SCSI commands may be issued than shown in the "main SCSI
commands" column. For example many utilities issue a SCSI INQUIRY
command to find out the peripheral device type of the given SCSI
device. Some SCSI commands listed above are only relevant to a specific
device type (e.g. FORMAT UNIT) and should not be sent to a device
belonging to other peripheral device types (and in some cases these
utilities will
block inappropriate attempts). See the COVERAGE file in the main
directory of the tarball for a more exhaustive list of SCSI (and ATA)
commands
issued by the sg3_utils utilities.<br>
<br>
If the "subdirectory"
column is empty in the above table then that utility is in the main
directory and more
documentation can be found in its "man" page. All utilities in the main
directory have "man" pages and some in the subdirectories have "man"
pages. <br>
<br>
If the "Ported" column is empty then the utility is only found in
Linux. Support for other ports is indicated by "fb" for FreeBSD, "t64"
for Tru64 (OSF) and "w" for Windows. See the README.freebsd,
README.tru64 and README.win32 files
for more information.<br>
<br>
This paragraph contains Linux specific information. In the above table
all utilities in the main directory except sgp_dd
issue SG_IO ioctls when they want to send SCSI commands to the given
device. The sgp_dd utility issues SCSI commands using the sg
driver's asynchronous ( write()/read() ) interface to device nodes that
have the sg driver's major device number (i.e. "char" major 21). This
means that all utilities in the main directory are "safe" with any
given device node. If the device node does not support the SG_IO ioctl
then that is reported and the utility exits. [In version 1.14 sgm_dd
also use the sg
driver's asynchronous ( write()/read() ) interface but that has been
changed to the SG_IO ioctl in version 1.15 since the asynchronous
action is not needed. sgm_dd will only use mmapped IO on sg device
nodes.]<br>
<br>
Irrespective of the device node used to access a device, care
should be taken not to interfere with a device while it is "active".
For example invoking a "sg_format -F" utility on a disk with mounted
file
systems on it is going to cause damage.<br>
<br>
Each process containing one of these command line utilities completes
with an exit status 0 when
successful. Prior to version 1.21 all errors yielded an exit status of
1. From version 1.21 the exit status is one of:<br>
<ul>
  <li><span style="font-weight: bold;">1</span>&nbsp;&nbsp; syntax
error in command line options or their arguments, or an illegal
combination of options.</li>
  <li><span style="font-weight: bold;">2</span>&nbsp;&nbsp; the device
reports that it is not ready for the operation requested. The device
may be in the process of becoming ready (e.g. spinning up but not at
speed) so the utility may work a little while later.</li>
  <li><span style="font-weight: bold;">3</span>&nbsp;&nbsp; the device
reports a medium or hardware error (or a blank check). For example an
attempt to read a corrupted block on a disk will yield this value. <br>
  </li>
  <li><span style="font-weight: bold;">5</span>&nbsp;&nbsp; the device
reports an "illegal request" with an additional sense code other than
"invalid operation code". This is often a supported command with a
field set requesting an unsupported capability. For commands that
require a "service action" field (e.g. READ CAPACITY(16) ) this value
can indicate that the
command is not supported.</li>
  <li><span style="font-weight: bold;">6</span>&nbsp;&nbsp; the device
reports a "unit attention" condition. This usually indicates that
something unrelated to the requested command has occurred (e.g. a
device reset) potentially before the current SCSI command was sent. The
requested command has not been executed by the device. Note that unit
attention conditions are usually only reported once by a device.</li>
  <li><span style="font-weight: bold;">9</span>&nbsp;&nbsp; the device
reports an illegal request with an additional sense code of "invalid
operation code" which means that it doesn't support the requested
command.</li>
  <li><span style="font-weight: bold;">11</span>&nbsp; the device (or
transport) reports an aborted command. In some cases this can be caused
by congestion on the transport and retrying the command may be
successful.<br>
  </li>
  <li><span style="font-weight: bold;">15</span> &nbsp; the utility is
unable to open, close or use the given device. The given file name
could be incorrect or there may be permission problems. Adding the '-v'
option may give more information.</li>
  <li><span style="font-weight: bold;">20</span>&nbsp;&nbsp; the
&lt;scsi_device&gt; reports it has a check condition but "no sense".
Some polling commands (e.g. REQUEST SENSE) can react this way. It is
unlikely that this value will occur as an exit status.</li>
  <li><span style="font-weight: bold;">21</span>&nbsp;&nbsp; the device
reports a "recovered error". The requested command was successful. Most
likely a utility will report a recovered error to stderr and continue,
probably leaving the utility with an exit status of 0 .</li>
  <li><span style="font-weight: bold;">33</span>&nbsp;&nbsp; the
command sent to the device has timed out. This appears on in Linux, in
other ports a command timeout will appear as a transport (or OS) error.<br>
  </li>
  <li><span style="font-weight: bold;">97</span>&nbsp;&nbsp; the
response to a SCSI command failed sanity checks.</li>
  <li><span style="font-weight: bold;">98</span>&nbsp;&nbsp; the device
reports it has a check condition but the error doesn't fit into any of
the above categories.</li>
  <li><span style="font-weight: bold;">99</span>&nbsp;&nbsp; any errors
that can't be categorized into values 1 to 98 may yield this value.
This includes transport and operating system errors.<br>
  </li>
</ul>
Many of the above exit statuses will be repeatable so executing the
utility again with one or more '-v' options may yield more information.
Unit attentions (exit status 6) are only reported once per condition.
Notice that some of the lower exit status values correspond to the SCSI
sense key values that they correspond to.<br>
<h2><a class="mozTocH2" name="mozTocId143590"></a>Changing mode page
settings</h2>
SCSI devices store settings (metadata) that could possibly be changed
by the user (called the "application client" in SCSI jargon) in mode
pages. It is a common requirement to find mode page settings and in
some cases change them. An example is the Writeback Cache Enable (WCE)
bit
in the Caching mode page of SCSI disks. Usually the manufacturer's
default setting for WCE is set (on) however in some RAID configurations
it may be cleared (off). <br>
<br>
Generic command line tools to change mode page settings tend to be
difficult to use (which in some small part is due to the SCSI rules for
manipulating mode pages). Here is a list of some linux utilities for
changing
mode pages followed by some notes:<br>
<ul>
  <li><span style="font-weight: bold;">scsiinfo</span> (old utility):
awkward command line interface with double invocation (first to get,
second to set). Only mode page fields that the utility knows about can
be changed.<br>
  </li>
  <li><span style="font-weight: bold;">sginfo</span> (sg3_utils version
of scsiinfo): same awkward interface as scsiinfo but the mode pages are
more up to date. Supports other modern features such as mode subpages.<br>
  </li>
  <li><span style="font-weight: bold;">sg_wr_mode</span> (sg3_utils):
low level mode page settings based on ASCII hex representation. Used
with sg_modes to get a mode page in raw form and assumes ACSII hex will
be edited. Low level but general.</li>
  <li><span style="font-weight: bold;">sdparm</span> (sdparm): uses
acronyms (e.g. WCE) or numeric addressing to fetch and/or change mode
page settings.
Allows device to be reset to default settings for a specific mode page.
The user can choose whether changes are also made to the "saved" mode
page values. The
numeric addressing allows arbitrary fields to be changed (i.e. sdparm
doesn't need to know about a mode page or its field structure in
advance).<br>
  </li>
  <li><span style="font-weight: bold;">sgmode</span> (scsirastools):
interactive utility for setting mode pages with data held in preset
".mdf" files. Useful to setting a large number of disks to preset mode
page values but awkward for manipulating a specific mode page field.</li>
  <li><span style="font-weight: bold;">hdparm</span> (hdparm):
abstracts over ATA (mainly) and SCSI (where convenient) disks. Write
caching can be turned on and off but that is one of the few mode fields
that can be changed on a SCSI device.<br>
  </li>
  <li><span style="font-weight: bold;">blktool</span> (blktool): much
newer and cleaner version of hdparm which targets the linux kernel 2.6
series.
For SCSI devices only a relatively small (but important) number of mode
page fields can be changed.</li>
  <li>vendor specific (e.g. seatools from Seagate): several vendors
have utilities like this. Worth investigating and often useful with
disks from other manufacturers. Vendor extensions can be controlled
(e.g. Seagate's desktop/server mode (also see sdparm's man page about
this particular feature)).<br>
  </li>
</ul>
The author's recommendation is to use <a href="sdparm.html">sdparm</a>
unless the features of
another utility better suit your needs.<br>
<h2><a class="mozTocH2" name="mozTocId301018"></a>Examples</h2>
The fundamental SCSI command whose support is mandatory for all SCSI
devices is INQUIRY. All devices should respond to a "standard" (i.e.
when no Vital Product Pages are requested) INQUIRY.<br>
<br>
<span style="font-family: monospace;">$ sg_inq /dev/sda</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">standard INQUIRY:</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; PQual=0&nbsp;
Device_type=0&nbsp; RMB=0&nbsp; version=0x03&nbsp; [SPC]</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; [AERC=0]&nbsp;
[TrmTsk=0]&nbsp; NormACA=0&nbsp; HiSUP=1&nbsp; Resp_data_format=2</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; SCCS=0&nbsp; ACC=0&nbsp;
TGPS=0&nbsp; 3PC=0&nbsp; Protect=0</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; BQue=0&nbsp;
EncServ=0&nbsp; MultiP=0&nbsp; MChngr=0&nbsp; [ACKREQQ=0]&nbsp; Addr16=1</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; [RelAdr=0]&nbsp;
WBus16=1&nbsp; Sync=1&nbsp; Linked=1&nbsp; [TranDis=1]&nbsp; CmdQue=1</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; Clocking=0x3&nbsp;
QAS=0&nbsp; IUS=0</span><br style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp; length=144
(0x90)&nbsp;&nbsp; Peripheral device type: disk</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;Vendor identification:
SEAGATE</span><br style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;Product identification:
ST318451LW</span><br style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;Product revision level: 0003</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;Unit serial number:
xxxxxxxxx</span><br>
<br>
Some SCSI devices have version descriptor information showing which
standards (and drafts) they support:<br>
<br>
<span style="font-family: monospace;">$ sg_inq -d /dev/sdb</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">standard INQUIRY:</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; PQual=0&nbsp;
Device_type=0&nbsp; RMB=0&nbsp; version=0x03&nbsp; [SPC]</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; [AERC=0]&nbsp;
[TrmTsk=0]&nbsp; NormACA=0&nbsp; HiSUP=0&nbsp; Resp_data_format=2</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; SCCS=0&nbsp; ACC=0&nbsp;
TGPS=0&nbsp; 3PC=0&nbsp; Protect=0</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; BQue=0&nbsp;
EncServ=0&nbsp; MultiP=0&nbsp; MChngr=0&nbsp; [ACKREQQ=0]&nbsp; Addr16=1</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; [RelAdr=0]&nbsp;
WBus16=1&nbsp; Sync=1&nbsp; Linked=1&nbsp; [TranDis=1]&nbsp; CmdQue=1</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; Clocking=0x0&nbsp;
QAS=0&nbsp; IUS=0</span><br style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp; length=96
(0x60)&nbsp;&nbsp; Peripheral device type: disk</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;Vendor identification:
FUJITSU</span><br style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;Product identification:
MAM3184MP</span><br style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;Product revision level: 0106</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;Unit serial number:
xxxxxxxxx</span><br style="font-family: monospace;">
<br style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; Version descriptors:</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp; SAM-2 (no
version claimed)</span><br style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp; SPI-3
T10/1302-D revision 10</span><br style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp; SPC ANSI
X3.301:1997</span><br style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp; SBC T10/0996-D
revision 08c</span><br>
<br>
Many modern SCSI devices also support "Vital Product Data" (VPD) pages.
Here is a request to list available VPD pages:<br>
<br>
<span style="font-family: monospace;">$ sg_inq -e /dev/sg1</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">VPD INQUIRY, page code=0x00:</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp; [PQual=0&nbsp;
Peripheral device type: disk]</span><br style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp; Supported VPD pages:</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;
0x0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Supported VPD pages</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;
0x80&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Unit serial number</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;
0x83&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Device identification</span><br>
<br>
For displaying VPD pages, sg_vpd (or sdparm) may be a better choice
than sg_inq as sg_vpd has a simpler, less cluttered command line
interface and additional support for vendor specific VPD pages.<br>
<br>
<span style="font-family: monospace;"># sg_vpd /dev/sdh</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">Supported VPD pages VPD page:</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; Supported VPD pages [sv]</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; Unit serial number [sn]</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; Implemented operating
definition (obs) [iod]</span><br style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; Device identification [di]</span><br>
<br>
The following displays a subset of the device identification VPD page,
namely the designators for the target port:<br>
<br>
<span style="font-family: monospace;"># sg_vpd --page=di_port /dev/sdh</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">Device Identification VPD page:</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp; Target port:</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp; desig_type:
NAA,&nbsp; code_set: Binary</span><br style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;
transport: Serial Attached SCSI (SAS)</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
0x5000c500005208ee</span><br style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp; desig_type:
Relative target port,&nbsp; code_set: Binary</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;
transport: Serial Attached SCSI (SAS)</span><br
 style="font-family: monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Relative target port: 0x2</span><br>
<br>
The sg_scan and sg_map utilities show the relationships between sg
devices and their &lt;bus, channel, target, lun&gt; tuples and their
primary device node names:<br>
<p>Example: given these 3 SCSI devices: <br>
<tt style="font-family: monospace;">$ cat /proc/scsi/scsi</tt><span
 style="font-family: monospace;"> </span><br
 style="font-family: monospace;">
<tt style="font-family: monospace;">Attached devices:</tt><span
 style="font-family: monospace;"> </span><br
 style="font-family: monospace;">
<tt style="font-family: monospace;">Host: scsi1 Channel: 00 Id: 00 Lun:
00</tt><span style="font-family: monospace;"> </span><br
 style="font-family: monospace;">
<tt style="font-family: monospace;">&nbsp; Vendor: SEAGATE&nbsp; Model:
ST318451LW&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Rev: 0003</tt><span
 style="font-family: monospace;"> </span><br
 style="font-family: monospace;">
<tt style="font-family: monospace;">&nbsp; Type:&nbsp;&nbsp;
Direct-Access&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
ANSI SCSI revision: 03</tt><span style="font-family: monospace;"> </span><br
 style="font-family: monospace;">
<tt style="font-family: monospace;">Host: scsi2 Channel: 00 Id: 04 Lun:
00</tt><span style="font-family: monospace;"> </span><br
 style="font-family: monospace;">
<tt style="font-family: monospace;">&nbsp; Vendor: PIONEER&nbsp; Model:
DVD-ROM DVD-303&nbsp; Rev: 1.10</tt><span
 style="font-family: monospace;">
</span><br style="font-family: monospace;">
<tt style="font-family: monospace;">&nbsp; Type:&nbsp;&nbsp;
CD-ROM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
ANSI SCSI revision: 02</tt><span style="font-family: monospace;"> </span><br
 style="font-family: monospace;">
<tt style="font-family: monospace;">Host: scsi2 Channel: 00 Id: 06 Lun:
00</tt><span style="font-family: monospace;"> </span><br
 style="font-family: monospace;">
<tt style="font-family: monospace;">&nbsp; Vendor: YAMAHA&nbsp;&nbsp;
Model:
CRW4416S&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Rev: 1.0g</tt><span
 style="font-family: monospace;">
</span><br style="font-family: monospace;">
<tt style="font-family: monospace;">&nbsp; Type:&nbsp;&nbsp;
CD-ROM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
ANSI SCSI revision: 02</tt> </p>
<p>then the output from sg_scan is: <br>
<tt style="font-family: monospace;">$ sg_scan</tt><span
 style="font-family: monospace;"> </span><br
 style="font-family: monospace;">
<tt style="font-family: monospace;">/dev/sg0: scsi1 channel=0 id=0
lun=0&nbsp; type=0</tt><span style="font-family: monospace;"> </span><tt
 style="font-family: monospace;"><br>
/dev/sg1: scsi2 channel=0 id=4 lun=0&nbsp; type=5</tt><span
 style="font-family: monospace;"> </span><br
 style="font-family: monospace;">
<tt style="font-family: monospace;">/dev/sg2: scsi2 channel=0 id=6
lun=0&nbsp; type=5</tt> </p>
<p>INQUIRY data can be added to that output with the "-i" option. The
sg_map utility shows the mapping between scsi generic (sg) devices and
the corresponding primary device node. For some peripheral device
types, SCSI enclosures for example, there is no mapping and the
enclosure device must be accessed via a sg device node.<br>
</p>
<p style="font-family: monospace;">$ sg_map <br>
/dev/sg0&nbsp; /dev/sda <br>
/dev/sg1&nbsp; /dev/scd0 <br>
/dev/sg2&nbsp; /dev/scd1</p>
In the lk 2.6 series of kernels sg_scan and sg_map are less important
as most
utilities in the sg3_utils package can be issued directly against the
primary device node (e.g. /dev/sda).&nbsp; However the sg driver is
still needed to "talk" to devices such as enclosures which have no
specialized driver in linux.<br>
<h2><a class="mozTocH2" name="mozTocId585558"></a> Notes</h2>
Starting with sg3_utils-1.09 a library called libsgutils is built and
is required by most utilities. The library is made up of two source
files: sg_lib.c and sg_cmds.c; and their associated header files . The
sg_lib.c file contains SCSI
command,
sense key and additional sense code strings and various related helper
functions. The sg_cmds.c file contains low level wrapper functions for
commonly used SCSI commands. The library is built both as a shared
object and a static library. The binary rpm package only contains the
shared library while the sg3_utils-devel rpm package contains the
static library, sg_lib.h and sg_cmds.h . If users do not want libraries
(shared or static) then they can refer to the "no_lib" subdirectory
in the tarball which contains "no_lib" versions of the Makefile and the
rpm "spec" file.<br>
<br>
Many of the utilities in the sg3_utils package use the SG_IO ioctl
(rather than the older write()/read() interface) in the sg driver. In
the lk 2.6&nbsp; series the SG_IO ioctl (or at least a stripped
down version of it) has been implemented in the block subsystem. That
means that commands that previously only worked on sg device names will
now work on block device names as well (e.g. "sg_inq /dev/sda"). To use
this facility safely version sg3_utils-1.02 or later should be used.
Note that SCSI tape devices (both st and osst device drivers) are char
devices and support the SG_IO ioctl from lk 2.6.6 onwards.<br>
<p>See the notes about header file problems in the README file inside
each package. </p>
<h2><a class="mozTocH2" name="mozTocId479511"></a> Download</h2>
Various tarballs that include the source, a README, CHANGELOG, INSTALL
and a Makefile can be found in the <a
 href="http://www.torque.net/sg/index.html#mozTocId566194"><span
 style="text-decoration: underline;">table 2</span></a> on the <a
 href="index.html">main</a>
page. There are also source,
i386 binary rpm and deb packages available. There is no './configure'
logic so the correct Makefile must be chosen for the OS.<br>
<br>
<table style="width: 100%; text-align: left;" border="1" cellpadding="2"
 cellspacing="2">
  <caption align="bottom"><span style="font-weight: bold;">Table 2
Building from source tarball</span><br>
  </caption><tbody>
    <tr>
      <td style="vertical-align: top;"><span style="font-weight: bold;">OS</span><br>
      </td>
      <td style="vertical-align: top;"><span style="font-weight: bold;">build
to use shared library</span><br>
      </td>
      <td style="vertical-align: top;"><span style="font-weight: bold;">build
without library</span><br>
      </td>
      <td style="vertical-align: top;"><span style="font-weight: bold;">build
static executables</span><br>
      </td>
      <td style="vertical-align: top;"><span style="font-weight: bold;">Notes</span><br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;"><span style="font-weight: bold;">Linux</span><br>
      </td>
      <td style="vertical-align: top;">make<br>
      </td>
      <td style="vertical-align: top;">./make_no_lib.sh<br>
      </td>
      <td style="vertical-align: top;">./make_no_lib_static.sh<br>
      </td>
      <td style="vertical-align: top;">rpm spec file and debian
subdirectory included<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;"><span style="font-weight: bold;">FreeBSD</span><br>
      </td>
      <td style="vertical-align: top;">make -f Makefile.freebsd<br>
      </td>
      <td style="vertical-align: top;">./make_no_lib_freebsd.sh<br>
      </td>
      <td style="vertical-align: top;">&nbsp;<br>
      </td>
      <td style="vertical-align: top;">&nbsp;<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;"><span style="font-weight: bold;">Tru64
(OSF1)</span><br>
      </td>
      <td style="vertical-align: top;">make -f Makefile.osf1<br>
      </td>
      <td style="vertical-align: top;">./make_no_lib_osf1.sh<br>
      </td>
      <td style="vertical-align: top;">&nbsp;<br>
      </td>
      <td style="vertical-align: top;">&nbsp;<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;"><span style="font-weight: bold;">Windows</span><br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">make -f Makefile.win32<br>
      </td>
      <td style="vertical-align: top;">&nbsp;<br>
      </td>
      <td style="vertical-align: top;">Windows NT and latter supported
(uses SPT interface). Builds in a cygwin environment and requires
cygwin1.dll to run.<br>
      </td>
    </tr>
  </tbody>
</table>
<br>
<br>
Both sg3_utils and the
older sg_utils packages can
be found on http://freshmeat.net .<br>
<br>
<p>Return to <a href="index.html">main</a> page. </p>
<center>
<p>Last updated: 14th October 2006<br>
<br>
</p>
</center>
</body>
</html>