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