SG_WRITE_BUFFER(8)
β¨ SG_WRITE_BUFFER(8) β SG3_UTILS β¨
π NAME
okay so the name of this tool is sg_write_buffer, and it's all about sending SCSI WRITE BUFFER commands π¦
π SYNOPSIS
sg_write_buffer [--bpw=CS] [--dry-run] [--help] [--id=ID] [--in=FILE]
[--length=LEN] [--mode=MO] [--offset=OFF] [--read-stdin] [--skip=SKIP]
[--specific=MS] [--timeout=TO] [--verbose] [--version] DEVICE
πΈ DESCRIPTION
bestie, this one sends one or more SCSI WRITE BUFFER commands to DEVICE, along with data you hand it π
sometimes no data is needed at all, or the data comes from the file you pass with --in=FILE, or it gets read from stdin when you use either --read-stdin or --in=- β¨
some WRITE BUFFER variants don't carry any data to the device at all π like activate_mc, which activates deferred microcode that got sent by earlier WRITE BUFFER commands. for downloading microcode to SES devices there's a different method, so go check out the sg_ses_microcode utility π§
π¦ OPTIONS
ok so long options need their arguments for the short versions too π the options are arranged in alphabetical order based on the long option name π
-b,--bpw=CSβ CS is your chunk size in bytes, aka the max number of bytes sent per WRITE BUFFER command π if CS is smaller than the effective length, multiple WRITE BUFFER commands get sent, each taking the next chunk of the read data and bumping the buffer offset field by the right amount β¨ the default is 0, which gets treated as a super huge number, so only one WRITE BUFFER command goes out πΈ this option should only be used with modes that "download microcode, with offsets ..." β so modes 0x6, 0x7, 0xd or 0xe, no exceptions bestie π₯ the number in CS can optionally be followed by,actor,activateπ«Ά when it's set, after the WRITE BUFFER commands have used up the effective length, another WRITE BUFFER command with its mode set to "Activate deferred microcode mode" [mode 0xf] gets sent π-d,--dry-runβ this does all the command line processing and sanity checks, including reading the input file π§ but right where a WRITE BUFFER SCSI command would go out, it skips that call, pretends it finished without errors, and keeps going π¦DEVICEstill gets opened, but it can be/dev/null(in Unix) π it's recommended to pair this with--verboseso you get an overview of what would have happened β¨-h,--helpβ outputs the usage message then exits π if you use it multiple times it also prints the mode names and their acronyms π-i,--id=IDβ sets the buffer id field in the cdb π ID is a value between 0 (default) and 255 inclusive π-I,--in=FILEβ reads data from file FILE, which gets sent with the WRITE BUFFER command π if FILE is-, then stdin gets read until an EOF is detected (same as--read-stdin) π«Ά data is read from the beginning of FILE, except when FILE is a regular file and--skip=SKIPis given π¦-l,--length=LENβ LEN is the length, in bytes, of the data to be written to the device β¨ if it's not given (and the length can't be deduced from--in=FILEor--read-stdin) it defaults to zero π if you do give it, and the length deduced from--in=FILEor--read-stdinis smaller (or no data is provided at all), then bytes of0xffare used as fill bytes π-m,--mode=MOβ sets the MODE field in the cdb πΈ MO is a value between 0 (default) and 31 inclusive π§ you can also give an abbreviation instead, 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-hhoption π₯-o,--offset=OFFβ sets the BUFFER OFFSET field in the cdb π OFF is a value between 0 (default) and2**24-1π it's a byte offset π-r,--read-stdinβ reads data from stdin until an EOF is detected π«Ά this data gets sent with the WRITE BUFFER command toDEVICEπ it does the same thing as--in=-β¨ back in the day this option's long name was--raw, and it may still be used for backward compatibility π¦-s,--skip=SKIPβ only active when--in=FILEis given and FILE is a regular file, not stdin πΈ data is read starting at byte offset SKIP, going to the end of the file (or the amount given by--length=LEN) π§ if it's not given, the byte offset defaults to 0, which is the start of the file π-S,--specific=MSβ MS is the MODE SPECIFIC field in the cdb π₯ it's a 3-bit field, so values 0 to 7 are accepted π this field was introduced in SPC-4 revision 32, and it can be used to specify extra events that activate deferred microcode (when MO is 0xD) π-t,--timeout=TOβ TO is the command timeout (in seconds) for each WRITE BUFFER command this utility issues π the default is 300 seconds (5 minutes), and you should only change it if that's not enough π-v,--verboseβ cranks up the verbosity level (aka more debug output) π§ β¨-V,--versionβ prints the version string, then exits π
π MODES
here's the list of WRITE BUFFER command settings for the MODE field π the first thing in each entry is the acronym that the MO argument of this utility accepts π«Ά right after it, in square brackets, are the matching decimal and hex values you can also give for MO π¦ they're listed in numerical order, obviously π
hd[0, 0x0] β combined header and data (obsolete in SPC-4) πvendor[1, 0x1] β vendor specific π§data[2, 0x2] β data (was called "Write Data" in SPC-3) πΈdmc[4, 0x4] β download microcode and activate (was called "Download microcode" in SPC-3) π₯dmc_save[5, 0x5] β download microcode, save, and activate (was called "Download microcode and save" in SPC-3) πdmc_offs[6, 0x6] β download microcode with offsets and activate (was called "Download microcode with offsets" in SPC-3) β¨dmc_offs_save[7, 0x7] β download microcode with offsets, save, and activate (was called "Download microcode with offsets and save" in SPC-3) πecho[10, 0xa] β write data to echo buffer (was called "Echo buffer" in SPC-3) πdmc_offs_ev_defer[13, 0xd] β download microcode with offsets, select activation events, save, and defer activate (introduced in SPC-4) πdmc_offs_defer[14, 0xe] β download microcode with offsets, save, and defer activate (introduced in SPC-4) π¦activate_mc[15, 0xf] β activate deferred microcode (introduced in SPC-4) πen_ex[26, 0x1A] β enable expander communications protocol and Echo buffer (obsolete in SPC-4) πdis_ex[27, 0x1B] β disable expander communications protocol (obsolete in SPC-4) πdeh[28, 0x1C] β download application client error history (was called "Download application log" in SPC-3) π
π NOTES
ngl these notes are important, so read carefully π if no --length=LEN is given, this utility reads up to 8 MiB of data from the given file FILE (or stdin) π
if you need more data than that, you should give the --length=LEN option π«Ά
the user should know that most operating systems put limits on how much data can go out with one SCSI command π on Linux that depends on the pass through mechanism in use (e.g. block SG_IO or the sg driver) and on various settings in sysfs in the Linux lk 2.6/3 series (e.g. /sys/block/sda/queue/max_sectors_kb) πΈ devices (i.e. logical units) also usually have limits on the max amount of data they can handle in one command π§ these two limits are why modes containing the word "offset" together with the --bpw=CS option are needed as firmware files get bigger and bigger π₯ and CS can be pretty small, like 4096 bytes, which means lots of WRITE BUFFER commands get sent π
trying to download a microcode/firmware file that's too large may cause an error in the pass-through layer (i.e. before the SCSI command is even issued) β οΈ on Linux those error reports can be super obscure, like "pass through os error invalid argument" π FreeBSD reports these errors well to the machine's console, but gives this utility a cryptic error message π
downloading incorrect microcode into a device can render that device inoperable π¨ one would hope the device vendor verifies the data before activating it π₯Ί if the SCSI WRITE BUFFER command gets values in its cdb (e.g. LEN) that are inappropriate (e.g. too large), the device should respond with a sense key of ILLEGAL REQUEST and an additional sense code of INVALID FIELD in CDB π if a WRITE BUFFER command (or a sequence of them) fails due to device vendor verification checks, it should respond with a sense key of ILLEGAL REQUEST and an additional sense code of COMMAND SEQUENCE ERROR π
all numbers given with options are assumed to be decimal π’ you can also use hexadecimal by putting either "0x" or "0X" in front (or a trailing "h" or "H") β¨
π EXAMPLES
the following sends new firmware to an enclosure π§ sending a 1.5 MB file in one WRITE BUFFER command made the enclosure lock up temporarily and didn't update the firmware π breaking the firmware file into 4 KB chunks (an educated guess) worked way better π«Ά
sg_write_buffer -b 4k -m dmc_offs_save -I firmware.bin /dev/sg4
the firmware update happens in the following enclosure power cycle π₯ with a modern enclosure, the Extended Inquiry VPD page shows which situations will trigger a firmware upgrade π
π EXIT STATUS
the exit status of sg_write_buffer is 0 when it's successful π otherwise see the sg3_utils(8) man page π
π AUTHORS
written by Luben Tuikov and Douglas Gilbert π«Ά
π¦ REPORTING BUGS
report bugs to <dgilbert at interlog dot com> π
πΈ COPYRIGHT
Copyright Β© 2006-2018 Luben Tuikov and Douglas Gilbert π this software is distributed under a BSD-2-Clause license π there is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE π
π§ SEE ALSO
sg_read_buffer, sg_ses_microcode(sg3_utils) β¨
bestie that's the whole page! π sg3_utils-1.45 from November 2018, all yours now π§π
π¦ where this page comes from
- alpine 3.24: sg3_utils-doc 1.48-r0 Β· BSD-2-Clause AND GPL-2.0-or-later
- arch rolling: sg3_utils 1.49-1 Β· GPL-2.0-or-later AND BSD-2-Clause
- centos-stream 10: sg3_utils 1.48-11.el10 Β· GPL-2.0-or-later AND BSD-2-Clause
- debian trixie: sg3-utils 1.48-3~deb13u1
- fedora 43: sg3_utils 1.48-10.fc43 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 43: sg3_utils 1.48-6.fc43 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 44: sg3_utils 1.48-10.fc44 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 44: sg3_utils 1.48-8.fc44 Β· GPL-2.0-or-later AND BSD-2-Clause
- nixos 26.05: sg3_utils 1.48
- nixpkgs unstable: sg3_utils 1.49
- ubuntu questing: sg3-utils 1.48-2ubuntu1
- ubuntu resolute: sg3-utils 1.48-3ubuntu3
- ubuntu resolute: sg3-utils 1.48-3ubuntu3.2
- ubuntu stonking: sg3-utils 1.48-3ubuntu5
- π girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms