1SG_WR_MODE(8)                      SG3_UTILS                     SG_WR_MODE(8)
2
3
4

NAME

6       sg_wr_mode - write (modify) SCSI mode page
7

SYNOPSIS

9       sg_wr_mode  [--contents=H,H...] [--dbd] [--force] [--help] [--len=10|6]
10       [--mask=M,M...] [--page=PG_H[,SPG_H]] [--rtd] [--save] [--six]  [--ver‐
11       bose] [--version] DEVICE
12

DESCRIPTION

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 the --rtd option is given then most other options apart from --save,
24       --len=10|6  and --six are ignored. In this case only a MODE SELECT com‐
25       mand is sent to the DEVICE with the RTD bit (Revert To  Defaults)  set.
26       This  bit  was  added  to  this  command in SPC-5 revision 11, so older
27       devices may not support it. The  Extended  Inquiry  VPD  page  has  the
28       RTD_SUP  bit to indicate whether the DEVICE supports the RTD bit in the
29       MODE SELECT(6 and 10) commands. When the --rtd option is given the rest
30       of this section can be ignored.
31
32       If  a  contents argument is not given then the various components (i.e.
33       header, block descriptor(s) and mode page) of the "current"  values  of
34       the  existing  mode page are printed out. In this case the mode page is
35       not altered on the device.
36
37       If the contents are specified, and a mask is not  specified,  then  the
38       contents  must  match  the existing mode page in various aspects unless
39       the --force option is given. These include length, mode page  code  and
40       subpage  code if applicable. If all is well then the contents string is
41       written to DEVICE as the new mode page.
42
43       If both contents and mask strings are specified then only bit positions
44       in  the  contents corresponding to set bits in the mask are taken while
45       the existing mode page supplies bit positions  corresponding  to  clear
46       bits.   When  a  mask is given then the mask and/or the contents may be
47       shorter than the existing mode page. If the mask is  shorter  than  the
48       contents  then  the remaining bytes are taken from the contents. If the
49       contents are shorter than the existing mode  page  then  the  remaining
50       bytes are taken from the existing mod page.
51
52       The  force  option  allows the contents string to be written as the new
53       mode page without any prior checks on  the  existing  mode  page.  This
54       should  only  be  required for vendor specific mode pages. The existing
55       mode data is ignored apart from the block descriptors which can be sup‐
56       pressed with the --dbd option if need be.
57
58       Changing  individual fields in a mode page is probably more easily done
59       with the sdparm utility. Fields can be identified by acronym  or  by  a
60       numerical descriptor.
61

OPTIONS

63       Arguments to long options are mandatory for short options as well.
64
65       -c, --contents=H,H...
66              where  H,H... is a string of comma separated hex numbers each of
67              which should resolve to a byte value (i.e. 0 to ff inclusive). A
68              (single)  space  separated string of hex numbers is also allowed
69              but the list needs to be in quotes. This is the new contents  of
70              the  mode  page to be written to DEVICE, potentially filtered by
71              the mask string.
72
73       -c, --contents=-
74              reads contents string from stdin. The hex numbers in the  string
75              may  be  comma, space, tab or linefeed (newline) separated. If a
76              line contains "#" then the remaining characters on that line are
77              ignored.  Otherwise  each non separator character should resolve
78              to a byte value (i.e. 0 to ff inclusive).  This  forms  the  new
79              contents  of  the mode page to be written to DEVICE, potentially
80              filtered by the mask string.
81
82       -d, --dbd
83              disable block descriptors (DBD flag in cdb). Some  device  types
84              include  block  descriptors  in the mode data returned by a MODE
85              SENSE command. If so the same block descriptors are  written  by
86              the  MODE  SELECT command.  This option instructs the MODE SENSE
87              command not to return any block descriptors.  This  would  be  a
88              sensible  default  for this utility apart from the fact that not
89              all SCSI devices support the DBD bit in the cdb.
90
91       -f, --force
92              force the contents string to be taken as the new mode  page,  or
93              at  least doesn't do checks on the existing mode page. Note that
94              DEVICE may still reject the new contents for the mode page. Can‐
95              not be given with the --mask=M,M... option.
96
97       -h, --help
98              output the usage message then exit.
99
100       -l, --len=10 | 6
101              length of the SCSI commands (cdb) sent to DEVICE. The default is
102              10 so 10 byte MODE SENSE and MODE SELECT  commands  are  issued.
103              Some  old  devices don't support the 10 byte variants hence this
104              option.
105
106       -m, --mask=M,M...
107              where M,M... is a string of comma separated hex numbers each  of
108              which should resolve to a byte value (i.e. 0 to ff inclusive). A
109              (single) space separated string of hex numbers is  also  allowed
110              but  the  list  needs  to be in quotes. The mask chooses (bit by
111              bit) whether the new mode page comes from the contents (mask bit
112              set)  or  from  the existing mode page (mask bit clear).  If the
113              mask string is shorter than the contents string then the remain‐
114              ing  bytes  are  taken from the contents string. If the contents
115              string is shorter than the existing mode page then the remaining
116              bytes  are taken from the existing mode page (i.e. they are left
117              unaltered).
118
119       -p, --page=PG_H
120              where PG_H is the page code value to fetch and modify. The  page
121              code  is in hex and should be between 0 and 3e inclusive. Notice
122              that page code 3f to fetch all mode pages is disallowed.
123
124       -p, --page=PG_H,SPG_H
125              where PG_H is the page code value and SPG_H is the subpage  code
126              value  to  fetch and modify. Both values are in hex. The subpage
127              code should be between 0 and fe inclusive. Notice  that  subpage
128              code ff to fetch all mode subpages (for a given mode page or all
129              mode pages in the case of 3f,ff) is disallowed.
130
131       -R, --rtd
132              when this option is given most other actions are bypassed and  a
133              MODE  SELECT(6 or 10) command is sent to the DEVICE with the RTD
134              bit set.  This will cause all current values (and  saved  values
135              if  the  --save  option  is  also given) of all mode pages to be
136              reverted to their default values.
137
138       -s, --save
139              changes the "saved" mode page when MODE SELECT is successful. By
140              default  (i.e.  when --save is not used) only the "current" mode
141              page values are changed when MODE SELECT is successful. In  this
142              case  the  new mode page will stay in effect until the device is
143              reset (e.g.  power cycled).  When it restarts the "saved" values
144              for  the mode page will be re-instated.  So to make changes per‐
145              manent use the --save option.
146              When used with the --rtd option then both the current and  saved
147              values  in  each mode page are reverted to their default values.
148              In the absence of --save option only the current values in  each
149              mode page are reverted to their default values.
150
151       -6, --six
152              this  option  will  cause  the 6 byte variants of MODE SENSE and
153              MODE SELECT commands to be used. The default is to  use  the  10
154              byte  options.  This  option  is equivalent to using the --len=6
155              option.
156
157
158       -v, --verbose
159              increase the level of verbosity, (i.e. debug output).
160
161       -V, --version
162              print the version string and then exit.
163

NOTES

165       This utility does not check whether the contents string  is  trying  to
166       modify  parts  of the mode page which are changeable. The device should
167       do that and if some part is  not  changeable  then  it  should  report:
168       "Invalid field in parameter list".
169
170       Some  mode  pages  are not saveable. If so an attempt to use the --save
171       option should cause an error to be reported from the  device:  "Illegal
172       field in cdb".
173
174       The  device  is  required  to do various checks before it accepts a new
175       mode page. If these checks fail then the mode page is not  altered  and
176       either  a "parameter list length error" or an "invalid field in parame‐
177       ter list" error is returned by the device in the sense data.
178
179       The recommended way to modify a mode page is to read  it  with  a  MODE
180       SENSE,  modify  some part of it then write it back to the device with a
181       MODE SELECT command. For example, reading an existing mode page can  be
182       accomplished  with  'sg_modes -p=1a -r /dev/sdb > mp_1a.txt' (the power
183       condition mode page). The mp_1a.txt file can be edited and then used as
184       the  contents  string  to  this utility (e.g. 'sg_wr_mode -p 1a -s -c -
185       /dev/sdb < mp_1a.txt').
186
187       Two fields differ between what is read from the device with MODE  SENSE
188       and  what  is  written  to  the  device with MODE SELECT: the mode data
189       length is reserved (i.e. zero(es)) in a MODE SELECT command  while  the
190       PS  bit  ((sub)page  byte  0  bit 7) in each mode (sub)page is reserved
191       (zero) in a MODE SELECT command.  The PS  bit  given  in  the  contents
192       string is zeroed unless the --force option is selected.
193

EXAMPLES

195       This  utility  can  be  used  together  with  the  sg_modes utility. To
196       re-instate the default mode page values (i.e. the mode page values cho‐
197       sen  by  the  manufacturer of the device) as both the current and saved
198       mode page values the following sequence could be used:
199
200         $ sg_modes --control=2 --page=1a -r /dev/sda > t
201         $ sg_wr_mode --page=1a --contents=- --save /dev/sda < t
202
203       Next is an example of using  a  mask  to  modify  the  "idle  condition
204       counter"  of  the "power condition" mode page (0x1a) from 0x28 to 0x37.
205       Note that the change is not saved so the "idle condition counter"  will
206       revert  to 0x28 after the next power cycle. The output from sg_modes is
207       abridged.
208
209        $ sg_modes --page=1a /dev/hdc
210        >> Power condition (mmc), page_control: current
211        00     1a 0a 00 03 00 00 00 28  00 00 01 2c
212
213        $ 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
214
215        $ sg_modes -p 1a /dev/hdc
216        >> Power condition (mmc), page_control: current
217        00     1a 0a 00 03 00 00 00 37  00 00 01 2c
218

EXIT STATUS

220       The exit status of sg_wr_mode is 0 when it is successful. Otherwise see
221       the sg3_utils(8) man page.
222

AUTHORS

224       Written by Douglas Gilbert.
225

REPORTING BUGS

227       Report bugs to <dgilbert at interlog dot com>.
228
230       Copyright © 2004-2018 Douglas Gilbert
231       This  software is distributed under a FreeBSD license. There is NO war‐
232       ranty; not even for MERCHANTABILITY or FITNESS FOR  A  PARTICULAR  PUR‐
233       POSE.
234

SEE ALSO

236       sdparm(sdparm), sg_modes(sg3_utils), sginfo(sg3_utils)
237
238
239
240sg3_utils-1.43                    April 2018                     SG_WR_MODE(8)
Impressum