1SG_WR_MODE(8) SG3_UTILS SG_WR_MODE(8)
2
3
4
6 sg_wr_mode - write mode page
7
9 sg_wr_mode [--contents=H,H...] [--dbd] [--force] [--help] [--len=10|6]
10 [--mask=M,M...] [--page=PG[,SPG]] [--save] [--verbose] [--version]
11 DEVICE
12
14 Writes a modified mode page to DEVICE. Uses the SCSI MODE SENSE (6 or
15 10 byte variant) command to fetch the existing mode data which includes
16 a mode page (or subpage). It then combines that with the contents,
17 potentially masked, and writes the modified mode page with the SCSI
18 MODE SELECT (6 or 10 byte variant) command. This utility does not mod‐
19 ify the block descriptor(s); if any block descriptors are fetched by
20 the MODE SENSE command then the same block descriptors are written back
21 with the following MODE SELECT command.
22
23 If a contents argument is not given then the various components (i.e.
24 header, block descriptor(s) and mode page) of the "current" values of
25 the existing mode page are printed out. In this case the mode page is
26 not altered on the device.
27
28 If the contents are specified, and a mask is not specified, then the
29 contents must match the existing mode page in various aspects unless
30 the --force option is given. These include length, mode page code and
31 subpage code if applicable. If all is well then the contents string is
32 written to DEVICE as the new mode page.
33
34 If both contents and mask strings are specified then only bit positions
35 in the contents corresponding to set bits in the mask are taken while
36 the existing mode page supplies bit positions corresponding to clear
37 bits. When a mask is given then the mask and/or the contents may be
38 shorter than the existing mode page. If the mask is shorter than the
39 contents then the remaining bytes are taken from the contents. If the
40 contents are shorter than the existing mode page then the remaining
41 bytes are taken from the existing mod page.
42
43 The force option allows the contents string to be written as the new
44 mode page without any prior checks on the existing mode page. This
45 should only be required for vendor specific mode pages. The existing
46 mode data is ignored apart from the block descriptors which can be sup‐
47 pressed with the --dbd option if need be.
48
49 Changing individual fields in a mode page is probably more easily done
50 with the sdparm utility. Fields can be identified by acronym or by a
51 numerical descriptor.
52
54 Arguments to long options are mandatory for short options as well.
55
56 -c, --contents=H,H...
57 where H,H... is a string of comma separated hex numbers each of
58 which should resolve to a byte value (i.e. 0 to ff inclusive).
59 This is the new contents of the mode page to be written to
60 DEVICE, potentially filtered by the mask string.
61
62 -c, --contents=-
63 reads contents string from stdin. The numbers in the string may
64 be comma, space, tab or linefeed (newline) separated. If a line
65 contains "#" then the remaining characters on that line are
66 ignored. Otherwise each non separator character should resolve
67 to a byte value (i.e. 0 to ff inclusive). This forms the new
68 contents of the mode page to be written to DEVICE, potentially
69 filtered by the mask string.
70
71 -d, --dbd
72 disable block descriptors (DBD flag in cdb). Some device types
73 include block descriptors in the mode data returned by a MODE
74 SENSE command. If so the same block descriptors are written by
75 the MODE SELECT command. This option instructs the MODE SENSE
76 command not to return any block descriptors. This would be a
77 sensible default for this utility apart from the fact that not
78 all SCSI devices support the DBD bit in the cdb.
79
80 -f, --force
81 force the contents string to be taken as the new mode page, or
82 at least doesn't do checks on the existing mode page. Note that
83 DEVICE may still reject the new contents for the mode page. Can‐
84 not be given with the --mask=M,M... option.
85
86 -h, --hex
87 output the usage message then exit.
88
89 -l, --len=10 | 6
90 length of the SCSI commands (cdb) sent to DEVICE. The default is
91 10 so 10 byte MODE SENSE and MODE SELECT commands are issued.
92 Some old devices don't support the 10 byte variants hence this
93 option.
94
95 -m, --mask=M,M...
96 where M,M... is a string of comma separated hex numbers each of
97 which should resolve to a byte value (i.e. 0 to ff inclusive).
98 The mask chooses (bit by bit) whether the new mode page comes
99 from the contents (mask bit set) or from the existing mode page
100 (mask bit clear). If the mask string is shorter than the con‐
101 tents string then the remaining bytes are taken from the con‐
102 tents string. If the contents string is shorter than the exist‐
103 ing mode page then the remaining bytes are taken from the exist‐
104 ing mode page (i.e. they are left unaltered).
105
106 -p, --page=PG
107 where PG is the page code value to fetch and modify. The page
108 code is in hex and should be between 0 and 3e inclusive. Notice
109 that page code 3f to fetch all mode pages is disallowed.
110
111 -p, --page=PG,SPG
112 where PG is the page code value and SPG is the subpage code
113 value to fetch and modify. Both values are in hex. The subpage
114 code should be between 0 and fe inclusive. Notice that subpage
115 code ff to fetch all mode subpages (for a given mode page or all
116 mode pages in the case of 3f,ff) is disallowed.
117
118 -s, --save
119 changes the "saved" mode page when MODE SELECT is successful. By
120 default (i.e. when --save is not used) only the "current" mode
121 page values are changed when MODE SELECT is successful. In this
122 case the new mode page will stay in effect until the device is
123 reset (e.g. power cycled). When it restarts the "saved" values
124 for the mode page will be re-instated. So to make changes per‐
125 manent use the --save option.
126
127 -v, --verbose
128 increase the level of verbosity, (i.e. debug output).
129
130 -V, --version
131 print the version string and then exit.
132
134 This utility does not check whether the contents string is trying to
135 modify parts of the mode page which are changeable. The device should
136 do that and if some part is not changeable then it should report:
137 "Invalid field in parameter list".
138
139 Some mode pages are not savable. If so an attempt to use the --save
140 option should cause an error to be reported from the device: "Illegal
141 field in cdb".
142
143 The device is required to do various checks before it accepts a new
144 mode page. If these checks fail then the mode page is not altered and
145 either a "parameter list length error" or an "invalid field in parame‐
146 ter list" error is returned by the device in the sense data.
147
148 The recommended way to modify a mode page is to read it with a MODE
149 SENSE, modify some part of it then write it back to the device with a
150 MODE SELECT command. For example, reading an existing mode page can be
151 accomplished with 'sg_modes -p=1a -r /dev/sdb > mp_1a.txt' (the power
152 condition mode page). The mp_1a.txt file can be edited and then used as
153 the contents string to this utility (e.g. 'sg_wr_mode -p 1a -s -c -
154 /dev/sdb < mp_1a.txt').
155
156 Two fields differ between what is read from the device with MODE SENSE
157 and what is written to the device with MODE SELECT: the mode data
158 length is reserved (i.e. zero(es)) in a MODE SELECT command while the
159 PS bit ((sub)page byte 0 bit 7) in each mode (sub)page is reserved
160 (zero) in a MODE SELECT command. The PS bit given in the contents
161 string is zeroed unless the --force option is selected.
162
164 This utility can be used together with the sg_modes utility. To
165 re-instate the default mode page values (i.e. the mode page values cho‐
166 sen by the manufacturer of the device) as both the current and saved
167 mode page values the following sequence could be used:
168
169 $ sg_modes -c=2 -p=1a -r /dev/sda > t
170 $ sg_wr_mode --page=1a --contents=- --save /dev/sda < t
171
172 Next is an example of using a mask to modify the "idle condition
173 counter" of the "power condition" mode page (0x1a) from 0x28 to 0x37.
174 Note that the change is not saved so the "idle condition counter" will
175 revert to 0x28 after the next power cycle. The output from sg_modes is
176 abridged.
177
178 $ sg_modes -p=1a /dev/hdc
179 >> Power condition (mmc), page_control: current
180 00 1a 0a 00 03 00 00 00 28 00 00 01 2c
181
182 $ sg_wr_mode -p 1a -c 0,0,0,0,0,0,0,37 -m 0,0,0,0,0,0,0,ff /dev/hdc
183
184 $ sg_modes -p=1a /dev/hdc
185 >> Power condition (mmc), page_control: current
186 00 1a 0a 00 03 00 00 00 37 00 00 01 2c
187
189 The exit status of sg_wr_mode is 0 when it is successful. Otherwise see
190 the sg3_utils(8) man page.
191
193 Written by Douglas Gilbert.
194
196 Report bugs to <dgilbert at interlog dot com>.
197
199 Copyright © 2004-2007 Douglas Gilbert
200 This software is distributed under a FreeBSD license. There is NO war‐
201 ranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
202 POSE.
203
205 sdparm(sdparm), sg_modes(sg3_utils), sginfo(sg3_utils)
206
207
208
209sg3_utils-1.23 January 2007 SG_WR_MODE(8)