{
    "content": [
        {
            "type": "text",
            "text": "# sg_write_buffer(8) (man)\n\n**Summary:** sgwritebuffer - send SCSI WRITE BUFFER commands\n\n**Synopsis:** sgwritebuffer   [--bpw=CS]   [--dry-run]   [--help]  [--id=ID]  [--in=FILE]  [--length=LEN]\n[--mode=MO]  [--offset=OFF]  [--read-stdin]  [--skip=SKIP]   [--specific=MS]   [--timeout=TO]\n[--verbose] [--version] DEVICE\n\n## Flags\n\n| Flag | Long | Arg | Description |\n|------|------|-----|-------------|\n| -b | --bpw | — | where CS is the chunk size in bytes. This will be the maximum number of bytes sent per WRITE BUFFER command. So if CS is |\n| -d | --dry-run | — | Do all the command line processing and sanity checks including reading the input file. However at the point where a WRIT |\n| -h | --help | — | output the usage message then exit. If used multiple times also prints the mode names and their acronyms. |\n| -i | --id | — | this option sets the buffer id field in the cdb. ID is a value between 0 (default) and 255 inclusive. |\n| -I | --in | — | read data from file FILE that will be sent with the WRITE BUFFER command. If FILE is '-' then stdin is read until an EOF |\n| -l | --length | — | where LEN is the length, in bytes, of data to be written to the device. If not given (and the length cannot be deduced f |\n| -m | --mode | — | this option sets the MODE field in the cdb. MO is a value between 0 (default) and 31 inclusive. Alternatively an abbrevi |\n| -o | --offset | — | this option sets the BUFFER OFFSET field in the cdb. OFF is a value between 0 (de‐ fault) and 224-1 . It is a byte offse |\n| -r | --read-stdin | — | read data from stdin until an EOF is detected. This data is sent with the WRITE BUFFER command to DEVICE. The action of  |\n| -s | --skip | — | this option is only active when --in=FILE is given and FILE is a regular file, rather than stdin. Data is read starting  |\n| -S | --specific | — | MS is the MODE SPECIFIC field in the cdb. This is a 3-bit field so the values 0 to 7 are accepted. This field was introd |\n| -t | --timeout | — | TO is the command timeout (in seconds) for each WRITE BUFFER command issued by this utility. Its default value is 300 se |\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- `The following sends new firmware to an enclosure. Sending a 1.5 MB file in one  WRITE  BUFFER`\n- `command caused the enclosure to lock up temporarily and did not update the firmware. Breaking`\n- `the firmware file into 4 KB chunks (an educated guess) was more successful:`\n- `sgwritebuffer -b 4k -m dmcoffssave -I firmware.bin /dev/sg4`\n- `The firmware update occurred in the following enclosure power cycle. With a modern  enclosure`\n- `the  Extended  Inquiry VPD page gives indications in which situations a firmware upgrade will`\n- `take place.`\n\n## See Also\n\n- sgsesmicrocode(sg3utils)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (4 lines)\n- **DESCRIPTION** (9 lines)\n- **OPTIONS** (3 lines) — 14 subsections\n  - -b --bpw (12 lines)\n  - -d --dry-run (6 lines)\n  - -h --help (3 lines)\n  - -i --id (3 lines)\n  - -I --in (5 lines)\n  - -l --length (5 lines)\n  - -m --mode (5 lines)\n  - -o --offset (3 lines)\n  - -r --read-stdin (4 lines)\n  - -s --skip (5 lines)\n  - -S --specific (4 lines)\n  - -t --timeout (4 lines)\n  - -v --verbose (2 lines)\n  - -V --version (2 lines)\n- **MODES** (52 lines)\n- **NOTES** (29 lines)\n- **EXAMPLES** (10 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\nsgwritebuffer - send SCSI WRITE BUFFER commands\n\n### SYNOPSIS\n\nsgwritebuffer   [--bpw=CS]   [--dry-run]   [--help]  [--id=ID]  [--in=FILE]  [--length=LEN]\n[--mode=MO]  [--offset=OFF]  [--read-stdin]  [--skip=SKIP]   [--specific=MS]   [--timeout=TO]\n[--verbose] [--version] DEVICE\n\n### DESCRIPTION\n\nSends one or more SCSI WRITE BUFFER commands to DEVICE, along with data provided by the user.\nIn some cases no data is required, or data can be read from the file given in  the  --in=FILE\noption, or data is read from stdin when either --read-stdin or --in=- is given.\n\nSome WRITE BUFFER command variants do not have associated data to send to the device. For ex‐\nample \"activatemc\" activates deferred microcode that was sent via prior  WRITE  BUFFER  com‐\nmands.  There  is  a  different  method  used  to  download microcode to SES devices, see the\nsgsesmicrocode utility.\n\n### OPTIONS\n\nArguments to long options are mandatory for short options as well.  The options are  arranged\nin alphabetical order based on the long option name.\n\n#### -b --bpw\n\nwhere CS is the chunk size in bytes. This will be the maximum number of bytes sent per\nWRITE BUFFER command. So if CS is less than the effective length then  multiple  WRITE\nBUFFER commands are sent, each taking the next chunk from the read data and increasing\nthe buffer offset field in the WRITE BUFFER command by the appropriate amount. The de‐\nfault  is a chunk size of 0 which is interpreted as a very large number hence only one\nWRITE BUFFER command will be sent. This option should only be  used  with  modes  that\n\"download microcode, with offsets ...\"; namely either mode 0x6, 0x7, 0xd or 0xe.\nThe  number  in  CS can optionally be followed by \",act\" or \",activate\".  In this case\nafter WRITE BUFFER commands have been sent until the effective length is exhausted an‐\nother  WRITE  BUFFER  command  with its mode set to \"Activate deferred microcode mode\"\n[mode 0xf] is sent.\n\n#### -d --dry-run\n\nDo all the command line processing and sanity checks including reading the input file.\nHowever  at  the  point  where a WRITE BUFFER SCSI command(s) would be sent, step over\nthat call and assume it completed without errors and continue. DEVICE is still  opened\nbut  can  be /dev/null (in Unix).  It is recommended to use --verbose with this option\nto get an overview of what would have happened.\n\n#### -h --help\n\noutput the usage message then exit. If used multiple times also prints the mode  names\nand their acronyms.\n\n#### -i --id\n\nthis option sets the buffer id field in the cdb. ID is a value between 0 (default) and\n255 inclusive.\n\n#### -I --in\n\nread data from file FILE that will be sent with the WRITE BUFFER command.  If FILE  is\n'-'  then  stdin  is  read  until  an  EOF  is  detected  (this  is the same action as\n--read-stdin). Data is read from the beginning of FILE except in the case when it is a\nregular file and the --skip=SKIP option is given.\n\n#### -l --length\n\nwhere  LEN is the length, in bytes, of data to be written to the device.  If not given\n(and the length cannot be deduced from --in=FILE or  --read-stdin)  then  defaults  to\nzero.  If the option is given and the length deduced from --in=FILE or --read-stdin is\nless (or no data is provided), then bytes of 0xff are used as fill bytes.\n\n#### -m --mode\n\nthis option sets the MODE field in the cdb. MO is a value between 0 (default)  and  31\ninclusive.  Alternatively  an abbreviation can be given.  See the MODES section below.\nTo list the available mode abbreviations  at  run  time  give  an  invalid  one  (e.g.\n'--mode=xxx') or use the '-hh' option.\n\n#### -o --offset\n\nthis  option  sets  the  BUFFER OFFSET field in the cdb. OFF is a value between 0 (de‐\nfault) and 224-1 . It is a byte offset.\n\n#### -r --read-stdin\n\nread data from stdin until an EOF is detected. This data is sent with the WRITE BUFFER\ncommand to DEVICE. The action of this option is the same as using '--in=-'. Previously\nthis option's long name was --raw and it may still be used for backward compatibility.\n\n#### -s --skip\n\nthis option is only active when --in=FILE is given and FILE is a regular file,  rather\nthan  stdin.  Data  is  read  starting  at byte offset SKIP to the end of file (or the\namount given by --length=LEN).  If not given the byte offset defaults to 0  (i.e.  the\nstart of the file).\n\n#### -S --specific\n\nMS  is  the MODE SPECIFIC field in the cdb. This is a 3-bit field so the values 0 to 7\nare accepted. This field was introduced in SPC-4 revision 32 and can be used to  spec‐\nify additional events that activate deferred microcode (when MO is 0xD).\n\n#### -t --timeout\n\nTO  is  the  command timeout (in seconds) for each WRITE BUFFER command issued by this\nutility. Its default value is 300 seconds (5 minutes) and should only  be  altered  if\nthis is not sufficient.\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### MODES\n\nFollowing is a list of WRITE BUFFER command settings for the MODE field.  First is an acronym\naccepted by the MO argument of this utility.  Following the acronym in  square  brackets  are\nthe  corresponding  decimal  and  hex values that may also be given for MO. The following are\nlisted in numerical order.\n\nhd  [0, 0x0]\nCombined header and data (obsolete in SPC-4).\n\nvendor  [1, 0x1]\nVendor specific.\n\ndata  [2, 0x2]\nData (was called \"Write Data\" in SPC-3).\n\ndmc  [4, 0x4]\nDownload microcode and activate (was called \"Download microcode\" in SPC-3).\n\ndmcsave  [5, 0x5]\nDownload microcode, save, and activate (was called \"Download microcode  and  save\"  in\nSPC-3).\n\ndmcoffs  [6, 0x6]\nDownload microcode with offsets and activate (was called \"Download microcode with off‐\nsets\" in SPC-3).\n\ndmcoffssave  [7, 0x7]\nDownload microcode with offsets, save, and activate (was  called  \"Download  microcode\nwith offsets and save\" in SPC-3).\n\necho  [10, 0xa]\nWrite data to echo buffer (was called \"Echo buffer\" in SPC-3).\n\ndmcoffsevdefer  [13, 0xd]\nDownload  microcode  with  offsets, select activation events, save, and defer activate\n(introduced in SPC-4).\n\ndmcoffsdefer  [14, 0xe]\nDownload microcode with offsets, save, and defer activate (introduced in SPC-4).\n\nactivatemc  [15, 0xf]\nActivate deferred microcode (introduced in SPC-4).\n\nenex  [26, 0x1A]\nEnable expander communications protocol and Echo buffer (obsolete in SPC-4).\n\ndisex  [27, 0x1B]\nDisable expander communications protocol (obsolete in SPC-4).\n\ndeh  [28, 0x1C]\nDownload application client error history (was called \"Download  application  log\"  in\nSPC-3).\n\n### NOTES\n\nIf  no  --length=LEN is given this utility reads up to 8 MiB of data from the given file FILE\n(or stdin). If a larger amount of data is required then the  --length=LEN  option  should  be\ngiven.\n\nThe  user  should be aware that most operating systems have limits on the amount of data that\ncan be sent with one SCSI command. In Linux this depends on the pass through  mechanism  used\n(e.g. block SGIO or the sg driver) and various setting in sysfs in the Linux lk 2.6/3 series\n(e.g. /sys/block/sda/queue/maxsectorskb). Devices (i.e. logical units) also typically  have\nlimits  on  the  maximum amount of data they can handle in one command. These two limitations\nsuggest that modes containing the word \"offset\" together with the  --bpw=CS  option  are  re‐\nquired  as  firmware files get larger and larger. And CS can be quite small, for example 4096\nbytes, resulting in many WRITE BUFFER commands being sent.\n\nAttempting to download a microcode/firmware file that is too large may cause an error to  oc‐\ncur  in  the pass-through layer (i.e. before the SCSI command is issued). In Linux such error\nreports can be obscure as in \"pass through os error invalid argument\". FreeBSD  reports  such\nerrors well to the machine's console but returns a cryptic error message to this utility.\n\nDownloading  incorrect microcode into a device has the ability to render that device inopera‐\nble. One would hope that the device vendor verifies the data before  activating  it.  If  the\nSCSI  WRITE BUFFER command is given values in its cdb (e.g. LEN) that are inappropriate (e.g.\ntoo large) then the device should respond with a sense key of ILLEGAL REQUEST  and  an  addi‐\ntional  sense code of INVALID FIELD in CDB. If a WRITE BUFFER command (or a sequence of them)\nfails due to device vendor verification checks then it should respond with a sense key of IL‐\nLEGAL REQUEST and an additional sense code of COMMAND SEQUENCE ERROR.\n\nAll numbers given with options are assumed to be decimal.  Alternatively numerical values can\nbe given in hexadecimal preceded by either \"0x\" or \"0X\" (or has a trailing \"h\" or \"H\").\n\n### EXAMPLES\n\nThe following sends new firmware to an enclosure. Sending a 1.5 MB file in one  WRITE  BUFFER\ncommand caused the enclosure to lock up temporarily and did not update the firmware. Breaking\nthe firmware file into 4 KB chunks (an educated guess) was more successful:\n\nsgwritebuffer -b 4k -m dmcoffssave -I firmware.bin /dev/sg4\n\nThe firmware update occurred in the following enclosure power cycle. With a modern  enclosure\nthe  Extended  Inquiry VPD page gives indications in which situations a firmware upgrade will\ntake place.\n\n### EXIT STATUS\n\nThe exit status of sgwritebuffer is 0 when it is successful. Otherwise see the sg3utils(8)\nman page.\n\n### AUTHORS\n\nWritten by Luben Tuikov and Douglas Gilbert.\n\n### REPORTING BUGS\n\nReport bugs to <dgilbert at interlog dot com>.\n\n### COPYRIGHT\n\nCopyright © 2006-2018 Luben Tuikov and 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\nsgreadbuffer, sgsesmicrocode(sg3utils)\n\n\n\nsg3utils-1.45                              November 2018                         SGWRITEBUFFER(8)\n\n"
        }
    ],
    "structuredContent": {
        "command": "sg_write_buffer",
        "section": "8",
        "mode": "man",
        "summary": "sgwritebuffer - send SCSI WRITE BUFFER commands",
        "synopsis": "sgwritebuffer   [--bpw=CS]   [--dry-run]   [--help]  [--id=ID]  [--in=FILE]  [--length=LEN]\n[--mode=MO]  [--offset=OFF]  [--read-stdin]  [--skip=SKIP]   [--specific=MS]   [--timeout=TO]\n[--verbose] [--version] DEVICE",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [
            {
                "flag": "-b",
                "long": "--bpw",
                "arg": null,
                "description": "where CS is the chunk size in bytes. This will be the maximum number of bytes sent per WRITE BUFFER command. So if CS is less than the effective length then multiple WRITE BUFFER commands are sent, each taking the next chunk from the read data and increasing the buffer offset field in the WRITE BUFFER command by the appropriate amount. The de‐ fault is a chunk size of 0 which is interpreted as a very large number hence only one WRITE BUFFER command will be sent. This option should only be used with modes that \"download microcode, with offsets ...\"; namely either mode 0x6, 0x7, 0xd or 0xe. The number in CS can optionally be followed by \",act\" or \",activate\". In this case after WRITE BUFFER commands have been sent until the effective length is exhausted an‐ other WRITE BUFFER command with its mode set to \"Activate deferred microcode mode\" [mode 0xf] is sent."
            },
            {
                "flag": "-d",
                "long": "--dry-run",
                "arg": null,
                "description": "Do all the command line processing and sanity checks including reading the input file. However at the point where a WRITE BUFFER SCSI command(s) would be sent, step over that call and assume it completed without errors and continue. DEVICE is still opened but can be /dev/null (in Unix). It is recommended to use --verbose with this option to get an overview of what would have happened."
            },
            {
                "flag": "-h",
                "long": "--help",
                "arg": null,
                "description": "output the usage message then exit. If used multiple times also prints the mode names and their acronyms."
            },
            {
                "flag": "-i",
                "long": "--id",
                "arg": null,
                "description": "this option sets the buffer id field in the cdb. ID is a value between 0 (default) and 255 inclusive."
            },
            {
                "flag": "-I",
                "long": "--in",
                "arg": null,
                "description": "read data from file FILE that will be sent with the WRITE BUFFER command. If FILE is '-' then stdin is read until an EOF is detected (this is the same action as --read-stdin). Data is read from the beginning of FILE except in the case when it is a regular file and the --skip=SKIP option is given."
            },
            {
                "flag": "-l",
                "long": "--length",
                "arg": null,
                "description": "where LEN is the length, in bytes, of data to be written to the device. If not given (and the length cannot be deduced from --in=FILE or --read-stdin) then defaults to zero. If the option is given and the length deduced from --in=FILE or --read-stdin is less (or no data is provided), then bytes of 0xff are used as fill bytes."
            },
            {
                "flag": "-m",
                "long": "--mode",
                "arg": null,
                "description": "this option sets the MODE field in the cdb. MO is a value between 0 (default) and 31 inclusive. Alternatively an abbreviation can be given. See the MODES section below. To list the available mode abbreviations at run time give an invalid one (e.g. '--mode=xxx') or use the '-hh' option."
            },
            {
                "flag": "-o",
                "long": "--offset",
                "arg": null,
                "description": "this option sets the BUFFER OFFSET field in the cdb. OFF is a value between 0 (de‐ fault) and 224-1 . It is a byte offset."
            },
            {
                "flag": "-r",
                "long": "--read-stdin",
                "arg": null,
                "description": "read data from stdin until an EOF is detected. This data is sent with the WRITE BUFFER command to DEVICE. The action of this option is the same as using '--in=-'. Previously this option's long name was --raw and it may still be used for backward compatibility."
            },
            {
                "flag": "-s",
                "long": "--skip",
                "arg": null,
                "description": "this option is only active when --in=FILE is given and FILE is a regular file, rather than stdin. Data is read starting at byte offset SKIP to the end of file (or the amount given by --length=LEN). If not given the byte offset defaults to 0 (i.e. the start of the file)."
            },
            {
                "flag": "-S",
                "long": "--specific",
                "arg": null,
                "description": "MS is the MODE SPECIFIC field in the cdb. This is a 3-bit field so the values 0 to 7 are accepted. This field was introduced in SPC-4 revision 32 and can be used to spec‐ ify additional events that activate deferred microcode (when MO is 0xD)."
            },
            {
                "flag": "-t",
                "long": "--timeout",
                "arg": null,
                "description": "TO is the command timeout (in seconds) for each WRITE BUFFER command issued by this utility. Its default value is 300 seconds (5 minutes) and should only be altered if this is not sufficient."
            },
            {
                "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": [
            "The following sends new firmware to an enclosure. Sending a 1.5 MB file in one  WRITE  BUFFER",
            "command caused the enclosure to lock up temporarily and did not update the firmware. Breaking",
            "the firmware file into 4 KB chunks (an educated guess) was more successful:",
            "sgwritebuffer -b 4k -m dmcoffssave -I firmware.bin /dev/sg4",
            "The firmware update occurred in the following enclosure power cycle. With a modern  enclosure",
            "the  Extended  Inquiry VPD page gives indications in which situations a firmware upgrade will",
            "take place."
        ],
        "see_also": [
            {
                "name": "sgsesmicrocode",
                "section": "sg3utils",
                "url": "https://www.chedong.com/phpMan.php/man/sgsesmicrocode/sg3utils/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "OPTIONS",
                "lines": 3,
                "subsections": [
                    {
                        "name": "-b --bpw",
                        "lines": 12,
                        "flag": "-b",
                        "long": "--bpw"
                    },
                    {
                        "name": "-d --dry-run",
                        "lines": 6,
                        "flag": "-d",
                        "long": "--dry-run"
                    },
                    {
                        "name": "-h --help",
                        "lines": 3,
                        "flag": "-h",
                        "long": "--help"
                    },
                    {
                        "name": "-i --id",
                        "lines": 3,
                        "flag": "-i",
                        "long": "--id"
                    },
                    {
                        "name": "-I --in",
                        "lines": 5,
                        "flag": "-I",
                        "long": "--in"
                    },
                    {
                        "name": "-l --length",
                        "lines": 5,
                        "flag": "-l",
                        "long": "--length"
                    },
                    {
                        "name": "-m --mode",
                        "lines": 5,
                        "flag": "-m",
                        "long": "--mode"
                    },
                    {
                        "name": "-o --offset",
                        "lines": 3,
                        "flag": "-o",
                        "long": "--offset"
                    },
                    {
                        "name": "-r --read-stdin",
                        "lines": 4,
                        "flag": "-r",
                        "long": "--read-stdin"
                    },
                    {
                        "name": "-s --skip",
                        "lines": 5,
                        "flag": "-s",
                        "long": "--skip"
                    },
                    {
                        "name": "-S --specific",
                        "lines": 4,
                        "flag": "-S",
                        "long": "--specific"
                    },
                    {
                        "name": "-t --timeout",
                        "lines": 4,
                        "flag": "-t",
                        "long": "--timeout"
                    },
                    {
                        "name": "-v --verbose",
                        "lines": 2,
                        "flag": "-v",
                        "long": "--verbose"
                    },
                    {
                        "name": "-V --version",
                        "lines": 2,
                        "flag": "-V",
                        "long": "--version"
                    }
                ]
            },
            {
                "name": "MODES",
                "lines": 52,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 29,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 10,
                "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": []
            }
        ]
    }
}