1SG_MAP(8) SG3_UTILS SG_MAP(8)
2
3
4
6 sg_map - displays mapping between linux sg and other SCSI devices
7
9 sg_map [-a] [-h] [-i] [-n] [-scd] [-sd] [-sr] [-st] [-V] [-x]
10
12 Sometimes it is difficult to determine which SCSI device a sg device
13 name (e.g. /dev/sg0) refers to. This command loops through the sg
14 devices and finds the corresponding SCSI disk, cdrom or tape device
15 name (if any). Scanners are an example of SCSI devices that have no
16 alternate SCSI device name apart from their sg device name.
17
19 -a assume the sg devices have alphabetical device names and loop
20 through /dev/sga, /dev/sgb, etc. Default is numeric scan. Note
21 that sg device nodes with an alphabetical index have been depre‐
22 cated since the linux kernel 2.2 series.
23
24 -h print usage message then exit.
25
26 -i in addition do a standard INQUIRY and output vendor, product and
27 revision strings for devices that are found.
28
29 -n assume the sg devices have numeric device names and loop through
30 /dev/sg0, /dev/sg1, etc. Default is numeric scan
31
32 -scd display mappings to SCSI cdrom device names of the form
33 /dev/scd0, /dev/scd1 etc
34
35 -sd display mappings to SCSI disk device names
36
37 -sr display mappings to SCSI cdrom device names of the form
38 /dev/sr0, /dev/sr1 etc
39
40 -st display mappings to SCSI tape device names
41
42 -V print out version string then exit (without further ado).
43
44 -x after each active sg device name is displayed there are five
45 digits: <host_number> <bus> <scsi_id> <lun> <scsi_type>
46
48 If no options starting with "-s" are given then the mapping to all SCSI
49 disk, cdrom and tape device names is shown.
50
51 If the device file system (devfs) is present a line noting this is out‐
52 put. The "native" devfs scsi hierarchy makes the relationship between a
53 sg device name and any corresponding disk, cdrom or tape device name
54 easy to establish. This replaces the need for this command. However
55 many applications will continue to look for Linux SCSI device names in
56 their traditional places. [Devfs supplies a compatibility daemon called
57 devfsd whose default configuration adds back the Linux device names in
58 their traditional positions.
59
60 Quite often the mapping information can be derived by observing the
61 output of the command: "cat /proc/scsi/scsi". However if devices have
62 been added since boot this can be deceptive.
63
64 In the linux kernel 2.6 series something close to the mapping shown by
65 this utility can be found by analysing sysfs. The main difference is
66 that sysfs analysis will show the mapping between sg nodes and other
67 SCSI device nodes in terms of major and minor numbers. While major 8,
68 minor 16 will usually be /dev/sdb this is not necessarily so. Facili‐
69 ties associated with udev may assign major 8, minor 16 some other
70 device node name. This version of sg_map has been extended to cope with
71 sparse disk device node names of the form "/dev/sd<str>" where <str>
72 can be one of [a-z,aa-zz,aaa-zzz]. See the sg_map26 utility for a more
73 precise way (i.e. less directory scanning) for mapping between sg
74 device names and higher level names; including finding user defined
75 names.
76
77 This utility was written at a time when hotplugging of SCSI devices was
78 not supported in Linux. It used a simple algorithm to scan sg device
79 nodes in ascending numeric or alphabetical order, stopping after there
80 were 5 consecutive errors.
81
82 In the linux kernel 2.6 series, this utility uses sysfs to find which
83 sg device nodes are active and only checks those. Hence there can be
84 large "holes" in the numbering of sg device nodes (e.g. after an
85 adapter has been removed) and still all active sg device nodes will be
86 listed. This utility assumes that sg device nodes are named using the
87 normal conventions and searches from /dev/sg0 to /dev/sg4095 inclusive.
88
90 My system has a SCSI disk, a cd writer and a dvd player:
91 $ sg_map
92 # Note: the devfs pseudo file system is present
93 /dev/sg0 /dev/sda
94 /dev/sg1 /dev/sr0
95 /dev/sg2 /dev/sr1
96
97 In order to find which sg device name corresponds to the disk:
98 $ sg_map -sd
99 # Note: the devfs pseudo file system is present
100 /dev/sg0 /dev/sda
101 /dev/sg1
102 /dev/sg2
103
104 The "-x" option gives the following output:
105 sg_map -x
106 # Note: the devfs pseudo file system is present
107 /dev/sg0 1 0 1 0 0 /dev/sda
108 /dev/sg1 2 0 4 0 5 /dev/sr0
109 /dev/sg2 2 0 6 0 5 /dev/sr1
110
111 When a SCSI scanner is added the output becomes:
112 $ sg_map
113 # Note: the devfs pseudo file system is present
114 /dev/sg0 /dev/sda
115 /dev/sg1 /dev/sr0
116 /dev/sg2 /dev/sr1
117 /dev/sg3
118
119 By process of elimination /dev/sg3 must be the scanner.
120
122 The exit status of sg_map is 0 when it is successful. Otherwise see the
123 sg3_utils(8) man page.
124
126 Written by Doug Gilbert
127
129 Report bugs to <dgilbert at interlog dot com>.
130
132 Copyright © 2000-2006 Douglas Gilbert
133 This software is distributed under the GPL version 2. There is NO war‐
134 ranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
135 POSE.
136
138 sg_map26(8) , scsi_info(8) , scsidev(8) , devfsd(8)
139
140
141
142sg3_utils-1.23 December 2006 SG_MAP(8)