{
    "content": [
        {
            "type": "text",
            "text": "# sg_wr_mode(8) (man)\n\n**Summary:** sgwrmode - write (modify) SCSI mode page\n\n**Synopsis:** sgwrmode   [--contents=H,H...]  [--dbd]  [--force]  [--help]  [--len=10|6]  [--mask=M,M...]\n[--page=PGH[,SPGH]] [--rtd] [--save] [--six] [--verbose] [--version] DEVICE\n\n## Flags\n\n| Flag | Long | Arg | Description |\n|------|------|-----|-------------|\n| -c | --contents | — | where H,H... is a string of comma separated hex numbers each of which should resolve to a byte value (i.e. 0 to ff inclu |\n| -c | --contents | — | reads contents string from stdin. The hex numbers in the string may be comma, space, tab or linefeed (newline) separated |\n| -d | --dbd | — | disable block descriptors (DBD flag in cdb). Some device types include block descrip‐ tors in the mode data returned by  |\n| -f | --force | — | force the contents string to be taken as the new mode page, or at least doesn't do checks on the existing mode page. Not |\n| -h | --help | — | output the usage message then exit. |\n| -l | --len | — | length of the SCSI commands (cdb) sent to DEVICE. The default is 10 so 10 byte MODE SENSE and MODE SELECT commands are i |\n| -m | --mask | — | where M,M... is a string of comma separated hex numbers each of which should resolve to a byte value (i.e. 0 to ff inclu |\n| -p | --page | — | where PGH is the page code value to fetch and modify. The page code is in hex and should be between 0 and 3e inclusive.  |\n| -p | --page | — | where PGH is the page code value and SPGH is the subpage code value to fetch and modify. Both values are in hex. The sub |\n| -R | --rtd | — | when this option is given most other actions are bypassed and a MODE SELECT(6 or 10) command is sent to the DEVICE with  |\n| -s | --save | — | changes the \"saved\" mode page when MODE SELECT is successful. By default (i.e. when --save is not used) only the \"curren |\n| -6 | --six | — | this option will cause the 6 byte variants of MODE SENSE and MODE SELECT commands to be used. The default is to use the  |\n| -v | --verbose | — | increase the level of verbosity, (i.e. debug output). |\n| -V | --version | — | print the version string and then exit. |\n\n## Examples\n\n- `This  utility  can be used together with the sgmodes utility. To re-instate the default mode`\n- `page values (i.e. the mode page values chosen by the manufacturer of the device) as both  the`\n- `current and saved mode page values the following sequence could be used:`\n- `$ sgmodes --control=2 --page=1a -r /dev/sda > t`\n- `$ sgwrmode --page=1a --contents=- --save /dev/sda < t`\n- `Next  is an example of using a mask to modify the \"idle condition counter\" of the \"power con‐`\n- `dition\" mode page (0x1a) from 0x28 to 0x37. Note that the change is not saved  so  the  \"idle`\n- `condition  counter\"  will revert to 0x28 after the next power cycle. The output from sgmodes`\n- `is abridged.`\n- `$ sgmodes --page=1a /dev/hdc`\n- `>> Power condition (mmc), pagecontrol: current`\n- `00     1a 0a 00 03 00 00 00 28  00 00 01 2c`\n- `$ sgwrmode -p 1a -c 0,0,0,0,0,0,0,37 -m 0,0,0,0,0,0,0,ff /dev/hdc`\n- `$ sgmodes -p 1a /dev/hdc`\n- `>> Power condition (mmc), pagecontrol: current`\n- `00     1a 0a 00 03 00 00 00 37  00 00 01 2c`\n\n## See Also\n\n- sdparm(sdparm)\n- sgmodes(sg3utils)\n- sginfo(sg3utils)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (3 lines)\n- **DESCRIPTION** (38 lines)\n- **OPTIONS** (2 lines) — 14 subsections\n  - -c --contents (5 lines)\n  - -c --contents (6 lines)\n  - -d --dbd (6 lines)\n  - -f --force (4 lines)\n  - -h --help (2 lines)\n  - -l --len (4 lines)\n  - -m --mask (9 lines)\n  - -p --page (4 lines)\n  - -p --page (5 lines)\n  - -R --rtd (5 lines)\n  - -s --save (9 lines)\n  - -6 --six (5 lines)\n  - -v --verbose (2 lines)\n  - -V --version (2 lines)\n- **NOTES** (23 lines)\n- **EXAMPLES** (22 lines)\n- **EXIT STATUS** (3 lines)\n- **AUTHORS** (2 lines)\n- **REPORTING BUGS** (2 lines)\n- **COPYRIGHT** (4 lines)\n- **SEE ALSO** (5 lines)\n\n## Full Content\n\n### NAME\n\nsgwrmode - write (modify) SCSI mode page\n\n### SYNOPSIS\n\nsgwrmode   [--contents=H,H...]  [--dbd]  [--force]  [--help]  [--len=10|6]  [--mask=M,M...]\n[--page=PGH[,SPGH]] [--rtd] [--save] [--six] [--verbose] [--version] DEVICE\n\n### DESCRIPTION\n\nWrites a modified mode page to DEVICE. Uses the SCSI MODE SENSE (6 or 10 byte  variant)  com‐\nmand  to  fetch  the existing mode data which includes a mode page (or subpage). It then com‐\nbines that with the contents, potentially masked, and writes the modified mode page with  the\nSCSI  MODE  SELECT (6 or 10 byte variant) command. This utility does not modify the block de‐\nscriptor(s); if any block descriptors are fetched by the MODE SENSE  command  then  the  same\nblock descriptors are written back with the following MODE SELECT command.\n\nIf  the --rtd option is given then most other options apart from --save, --len=10|6 and --six\nare ignored. In this case only a MODE SELECT command is sent to the DEVICE with the  RTD  bit\n(Revert  To  Defaults) set. This bit was added to this command in SPC-5 revision 11, so older\ndevices may not support it. The Extended Inquiry VPD page has the  RTDSUP  bit  to  indicate\nwhether the DEVICE supports the RTD bit in the MODE SELECT(6 and 10) commands. When the --rtd\noption is given the rest of this section can be ignored.\n\nIf a contents argument is not given then the various components (i.e.  header, block descrip‐\ntor(s)  and  mode page) of the \"current\" values of the existing mode page are printed out. In\nthis case the mode page is not altered on the device.\n\nIf the contents are specified, and a mask is not specified, then the contents must match  the\nexisting  mode  page  in  various  aspects  unless the --force option is given. These include\nlength, mode page code and subpage code if applicable. If  all  is  well  then  the  contents\nstring is written to DEVICE as the new mode page.\n\nIf  both contents and mask strings are specified then only bit positions in the contents cor‐\nresponding to set bits in the mask are taken while the existing mode page supplies bit  posi‐\ntions  corresponding  to  clear bits.  When a mask is given then the mask and/or the contents\nmay be shorter than the existing mode page. If the mask is shorter than the contents then the\nremaining  bytes  are  taken from the contents. If the contents are shorter than the existing\nmode page then the remaining bytes are taken from the existing mod page.\n\nThe force option allows the contents string to be written as the new mode  page  without  any\nprior checks on the existing mode page. This should only be required for vendor specific mode\npages. The existing mode data is ignored apart from the block descriptors which can  be  sup‐\npressed with the --dbd option if need be.\n\nChanging  individual fields in a mode page is probably more easily done with the sdparm util‐\nity. Fields can be identified by acronym or by a numerical descriptor.\n\n### OPTIONS\n\nArguments to long options are mandatory for short options as well.\n\n#### -c --contents\n\nwhere H,H... is a string of comma separated hex numbers each of which  should  resolve\nto  a  byte  value  (i.e. 0 to ff inclusive). A (single) space separated string of hex\nnumbers is also allowed but the list needs to be in quotes. This is the  new  contents\nof the mode page to be written to DEVICE, potentially filtered by the mask string.\n\n#### -c --contents\n\nreads  contents  string from stdin. The hex numbers in the string may be comma, space,\ntab or linefeed (newline) separated. If a line contains \"#\" then the remaining charac‐\nters  on  that line are ignored. Otherwise each non separator character should resolve\nto a byte value (i.e. 0 to ff inclusive). This forms the new contents of the mode page\nto be written to DEVICE, potentially filtered by the mask string.\n\n#### -d --dbd\n\ndisable  block descriptors (DBD flag in cdb). Some device types include block descrip‐\ntors in the mode data returned by a MODE SENSE command. If so the same block  descrip‐\ntors  are  written  by  the MODE SELECT command.  This option instructs the MODE SENSE\ncommand not to return any block descriptors. This would be a sensible default for this\nutility apart from the fact that not all SCSI devices support the DBD bit in the cdb.\n\n#### -f --force\n\nforce  the  contents  string  to be taken as the new mode page, or at least doesn't do\nchecks on the existing mode page. Note that DEVICE may still reject the  new  contents\nfor the mode page. Cannot be given with the --mask=M,M... option.\n\n#### -h --help\n\noutput the usage message then exit.\n\n#### -l --len\n\nlength  of  the  SCSI commands (cdb) sent to DEVICE. The default is 10 so 10 byte MODE\nSENSE and MODE SELECT commands are issued. Some old devices don't support the 10  byte\nvariants hence this option.\n\n#### -m --mask\n\nwhere  M,M...  is a string of comma separated hex numbers each of which should resolve\nto a byte value (i.e. 0 to ff inclusive). A (single) space  separated  string  of  hex\nnumbers  is  also allowed but the list needs to be in quotes. The mask chooses (bit by\nbit) whether the new mode page comes from the contents (mask bit set) or from the  ex‐\nisting  mode  page  (mask bit clear).  If the mask string is shorter than the contents\nstring then the remaining bytes are taken from the contents string.  If  the  contents\nstring  is shorter than the existing mode page then the remaining bytes are taken from\nthe existing mode page (i.e. they are left unaltered).\n\n#### -p --page\n\nwhere PGH is the page code value to fetch and modify. The page code  is  in  hex  and\nshould be between 0 and 3e inclusive. Notice that page code 3f to fetch all mode pages\nis disallowed.\n\n#### -p --page\n\nwhere PGH is the page code value and SPGH is the subpage code  value  to  fetch  and\nmodify. Both values are in hex. The subpage code should be between 0 and fe inclusive.\nNotice that subpage code ff to fetch all mode subpages (for a given mode page  or  all\nmode pages in the case of 3f,ff) is disallowed.\n\n#### -R --rtd\n\nwhen  this  option is given most other actions are bypassed and a MODE SELECT(6 or 10)\ncommand is sent to the DEVICE with the RTD bit set.  This will cause all current  val‐\nues  (and saved values if the --save option is also given) of all mode pages to be re‐\nverted to their default values.\n\n#### -s --save\n\nchanges the \"saved\" mode page when MODE SELECT is successful. By  default  (i.e.  when\n--save  is  not used) only the \"current\" mode page values are changed when MODE SELECT\nis successful. In this case the new mode page will stay in effect until the device  is\nreset  (e.g.   power  cycled).   When it restarts the \"saved\" values for the mode page\nwill be re-instated.  So to make changes permanent use the --save option.\nWhen used with the --rtd option then both the current and saved values  in  each  mode\npage  are  reverted  to their default values. In the absence of --save option only the\ncurrent values in each mode page are reverted to their default values.\n\n#### -6 --six\n\nthis option will cause the 6 byte variants of MODE SENSE and MODE SELECT  commands  to\nbe used. The default is to use the 10 byte options. This option is equivalent to using\nthe --len=6 option.\n\n#### -v --verbose\n\nincrease the level of verbosity, (i.e. debug output).\n\n#### -V --version\n\nprint the version string and then exit.\n\n### NOTES\n\nThis utility does not check whether the contents string is trying to modify parts of the mode\npage  which are changeable. The device should do that and if some part is not changeable then\nit should report: \"Invalid field in parameter list\".\n\nSome mode pages are not saveable. If so an attempt to use the --save option should  cause  an\nerror to be reported from the device: \"Illegal field in cdb\".\n\nThe  device  is  required  to  do  various checks before it accepts a new mode page. If these\nchecks fail then the mode page is not altered and either a \"parameter list length  error\"  or\nan \"invalid field in parameter list\" error is returned by the device in the sense data.\n\nThe  recommended  way to modify a mode page is to read it with a MODE SENSE, modify some part\nof it then write it back to the device with a MODE SELECT command. For  example,  reading  an\nexisting  mode  page  can  be accomplished with 'sgmodes -p=1a -r /dev/sdb > mp1a.txt' (the\npower condition mode page). The mp1a.txt file can be edited and then used  as  the  contents\nstring to this utility (e.g. 'sgwrmode -p 1a -s -c - /dev/sdb < mp1a.txt').\n\nTwo fields differ between what is read from the device with MODE SENSE and what is written to\nthe device with MODE SELECT: the mode data length is reserved (i.e. zero(es)) in a  MODE  SE‐\nLECT  command  while  the  PS bit ((sub)page byte 0 bit 7) in each mode (sub)page is reserved\n(zero) in a MODE SELECT command.  The PS bit given in the contents string  is  zeroed  unless\nthe --force option is selected.\n\n### EXAMPLES\n\nThis  utility  can be used together with the sgmodes utility. To re-instate the default mode\npage values (i.e. the mode page values chosen by the manufacturer of the device) as both  the\ncurrent and saved mode page values the following sequence could be used:\n\n$ sgmodes --control=2 --page=1a -r /dev/sda > t\n$ sgwrmode --page=1a --contents=- --save /dev/sda < t\n\nNext  is an example of using a mask to modify the \"idle condition counter\" of the \"power con‐\ndition\" mode page (0x1a) from 0x28 to 0x37. Note that the change is not saved  so  the  \"idle\ncondition  counter\"  will revert to 0x28 after the next power cycle. The output from sgmodes\nis abridged.\n\n$ sgmodes --page=1a /dev/hdc\n>> Power condition (mmc), pagecontrol: current\n00     1a 0a 00 03 00 00 00 28  00 00 01 2c\n\n$ sgwrmode -p 1a -c 0,0,0,0,0,0,0,37 -m 0,0,0,0,0,0,0,ff /dev/hdc\n\n$ sgmodes -p 1a /dev/hdc\n>> Power condition (mmc), pagecontrol: current\n00     1a 0a 00 03 00 00 00 37  00 00 01 2c\n\n### EXIT STATUS\n\nThe exit status of sgwrmode is 0 when it is successful. Otherwise see the sg3utils(8)  man\npage.\n\n### AUTHORS\n\nWritten by Douglas Gilbert.\n\n### REPORTING BUGS\n\nReport bugs to <dgilbert at interlog dot com>.\n\n### COPYRIGHT\n\nCopyright © 2004-2018 Douglas Gilbert\nThis software is distributed under a FreeBSD license. There is NO warranty; not even for MER‐\nCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n### SEE ALSO\n\nsdparm(sdparm), sgmodes(sg3utils), sginfo(sg3utils)\n\n\n\nsg3utils-1.43                               April 2018                                SGWRMODE(8)\n\n"
        }
    ],
    "structuredContent": {
        "command": "sg_wr_mode",
        "section": "8",
        "mode": "man",
        "summary": "sgwrmode - write (modify) SCSI mode page",
        "synopsis": "sgwrmode   [--contents=H,H...]  [--dbd]  [--force]  [--help]  [--len=10|6]  [--mask=M,M...]\n[--page=PGH[,SPGH]] [--rtd] [--save] [--six] [--verbose] [--version] DEVICE",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [
            {
                "flag": "-c",
                "long": "--contents",
                "arg": null,
                "description": "where H,H... is a string of comma separated hex numbers each of which should resolve to a byte value (i.e. 0 to ff inclusive). A (single) space separated string of hex numbers is also allowed but the list needs to be in quotes. This is the new contents of the mode page to be written to DEVICE, potentially filtered by the mask string."
            },
            {
                "flag": "-c",
                "long": "--contents",
                "arg": null,
                "description": "reads contents string from stdin. The hex numbers in the string may be comma, space, tab or linefeed (newline) separated. If a line contains \"#\" then the remaining charac‐ ters on that line are ignored. Otherwise each non separator character should resolve to a byte value (i.e. 0 to ff inclusive). This forms the new contents of the mode page to be written to DEVICE, potentially filtered by the mask string."
            },
            {
                "flag": "-d",
                "long": "--dbd",
                "arg": null,
                "description": "disable block descriptors (DBD flag in cdb). Some device types include block descrip‐ tors in the mode data returned by a MODE SENSE command. If so the same block descrip‐ tors are written by the MODE SELECT command. This option instructs the MODE SENSE command not to return any block descriptors. This would be a sensible default for this utility apart from the fact that not all SCSI devices support the DBD bit in the cdb."
            },
            {
                "flag": "-f",
                "long": "--force",
                "arg": null,
                "description": "force the contents string to be taken as the new mode page, or at least doesn't do checks on the existing mode page. Note that DEVICE may still reject the new contents for the mode page. Cannot be given with the --mask=M,M... option."
            },
            {
                "flag": "-h",
                "long": "--help",
                "arg": null,
                "description": "output the usage message then exit."
            },
            {
                "flag": "-l",
                "long": "--len",
                "arg": null,
                "description": "length of the SCSI commands (cdb) sent to DEVICE. The default is 10 so 10 byte MODE SENSE and MODE SELECT commands are issued. Some old devices don't support the 10 byte variants hence this option."
            },
            {
                "flag": "-m",
                "long": "--mask",
                "arg": null,
                "description": "where M,M... is a string of comma separated hex numbers each of which should resolve to a byte value (i.e. 0 to ff inclusive). A (single) space separated string of hex numbers is also allowed but the list needs to be in quotes. The mask chooses (bit by bit) whether the new mode page comes from the contents (mask bit set) or from the ex‐ isting mode page (mask bit clear). If the mask string is shorter than the contents string then the remaining bytes are taken from the contents string. If the contents string is shorter than the existing mode page then the remaining bytes are taken from the existing mode page (i.e. they are left unaltered)."
            },
            {
                "flag": "-p",
                "long": "--page",
                "arg": null,
                "description": "where PGH is the page code value to fetch and modify. The page code is in hex and should be between 0 and 3e inclusive. Notice that page code 3f to fetch all mode pages is disallowed."
            },
            {
                "flag": "-p",
                "long": "--page",
                "arg": null,
                "description": "where PGH is the page code value and SPGH is the subpage code value to fetch and modify. Both values are in hex. The subpage code should be between 0 and fe inclusive. Notice that subpage code ff to fetch all mode subpages (for a given mode page or all mode pages in the case of 3f,ff) is disallowed."
            },
            {
                "flag": "-R",
                "long": "--rtd",
                "arg": null,
                "description": "when this option is given most other actions are bypassed and a MODE SELECT(6 or 10) command is sent to the DEVICE with the RTD bit set. This will cause all current val‐ ues (and saved values if the --save option is also given) of all mode pages to be re‐ verted to their default values."
            },
            {
                "flag": "-s",
                "long": "--save",
                "arg": null,
                "description": "changes the \"saved\" mode page when MODE SELECT is successful. By default (i.e. when --save is not used) only the \"current\" mode page values are changed when MODE SELECT is successful. In this case the new mode page will stay in effect until the device is reset (e.g. power cycled). When it restarts the \"saved\" values for the mode page will be re-instated. So to make changes permanent use the --save option. When used with the --rtd option then both the current and saved values in each mode page are reverted to their default values. In the absence of --save option only the current values in each mode page are reverted to their default values."
            },
            {
                "flag": "-6",
                "long": "--six",
                "arg": null,
                "description": "this option will cause the 6 byte variants of MODE SENSE and MODE SELECT commands to be used. The default is to use the 10 byte options. This option is equivalent to using the --len=6 option."
            },
            {
                "flag": "-v",
                "long": "--verbose",
                "arg": null,
                "description": "increase the level of verbosity, (i.e. debug output)."
            },
            {
                "flag": "-V",
                "long": "--version",
                "arg": null,
                "description": "print the version string and then exit."
            }
        ],
        "examples": [
            "This  utility  can be used together with the sgmodes utility. To re-instate the default mode",
            "page values (i.e. the mode page values chosen by the manufacturer of the device) as both  the",
            "current and saved mode page values the following sequence could be used:",
            "$ sgmodes --control=2 --page=1a -r /dev/sda > t",
            "$ sgwrmode --page=1a --contents=- --save /dev/sda < t",
            "Next  is an example of using a mask to modify the \"idle condition counter\" of the \"power con‐",
            "dition\" mode page (0x1a) from 0x28 to 0x37. Note that the change is not saved  so  the  \"idle",
            "condition  counter\"  will revert to 0x28 after the next power cycle. The output from sgmodes",
            "is abridged.",
            "$ sgmodes --page=1a /dev/hdc",
            ">> Power condition (mmc), pagecontrol: current",
            "00     1a 0a 00 03 00 00 00 28  00 00 01 2c",
            "$ sgwrmode -p 1a -c 0,0,0,0,0,0,0,37 -m 0,0,0,0,0,0,0,ff /dev/hdc",
            "$ sgmodes -p 1a /dev/hdc",
            ">> Power condition (mmc), pagecontrol: current",
            "00     1a 0a 00 03 00 00 00 37  00 00 01 2c"
        ],
        "see_also": [
            {
                "name": "sdparm",
                "section": "sdparm",
                "url": "https://www.chedong.com/phpMan.php/man/sdparm/sdparm/json"
            },
            {
                "name": "sgmodes",
                "section": "sg3utils",
                "url": "https://www.chedong.com/phpMan.php/man/sgmodes/sg3utils/json"
            },
            {
                "name": "sginfo",
                "section": "sg3utils",
                "url": "https://www.chedong.com/phpMan.php/man/sginfo/sg3utils/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 38,
                "subsections": []
            },
            {
                "name": "OPTIONS",
                "lines": 2,
                "subsections": [
                    {
                        "name": "-c --contents",
                        "lines": 5,
                        "flag": "-c",
                        "long": "--contents"
                    },
                    {
                        "name": "-c --contents",
                        "lines": 6,
                        "flag": "-c",
                        "long": "--contents"
                    },
                    {
                        "name": "-d --dbd",
                        "lines": 6,
                        "flag": "-d",
                        "long": "--dbd"
                    },
                    {
                        "name": "-f --force",
                        "lines": 4,
                        "flag": "-f",
                        "long": "--force"
                    },
                    {
                        "name": "-h --help",
                        "lines": 2,
                        "flag": "-h",
                        "long": "--help"
                    },
                    {
                        "name": "-l --len",
                        "lines": 4,
                        "flag": "-l",
                        "long": "--len"
                    },
                    {
                        "name": "-m --mask",
                        "lines": 9,
                        "flag": "-m",
                        "long": "--mask"
                    },
                    {
                        "name": "-p --page",
                        "lines": 4,
                        "flag": "-p",
                        "long": "--page"
                    },
                    {
                        "name": "-p --page",
                        "lines": 5,
                        "flag": "-p",
                        "long": "--page"
                    },
                    {
                        "name": "-R --rtd",
                        "lines": 5,
                        "flag": "-R",
                        "long": "--rtd"
                    },
                    {
                        "name": "-s --save",
                        "lines": 9,
                        "flag": "-s",
                        "long": "--save"
                    },
                    {
                        "name": "-6 --six",
                        "lines": 5,
                        "flag": "-6",
                        "long": "--six"
                    },
                    {
                        "name": "-v --verbose",
                        "lines": 2,
                        "flag": "-v",
                        "long": "--verbose"
                    },
                    {
                        "name": "-V --version",
                        "lines": 2,
                        "flag": "-V",
                        "long": "--version"
                    }
                ]
            },
            {
                "name": "NOTES",
                "lines": 23,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 22,
                "subsections": []
            },
            {
                "name": "EXIT STATUS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "REPORTING BUGS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ]
    }
}