SG_READ_LONG(8)

πŸ“¦
version 1.49 Β· 2 versions
, in alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– SG_READ_LONG(8) β€” sg_read_long πŸ’–

✨ NAME ✨

okay so sg_read_long is the command that sends a SCSI READ LONG command πŸŽ€

🌸 SYNOPSIS 🌸

sg_read_long [--16] [--correct] [--help] [--lba=LBA] [--out=OF]
[--pblock] [--readonly] [--verbose] [--version] [--xfer_len=BTL] DEVICE

πŸ¦‹ DESCRIPTION πŸ¦‹

bestie, this one is lowkey a big deal 😭 It sends a SCSI READ LONG command to DEVICE, then shows the read buffer as hex and ASCII on stdout, or drops it into a file. Ngl the data coming back is more than just the logical block data (usually 512 bytes on a disk) πŸ’… It also has the ECC info (the format is proprietary, so no peeking) plus maybe some other proprietary stuff too. And the logical block data might be encoded or encrypted, so don't be shocked if it looks like gibberish πŸ™ˆ

Also, the vibe shift: in SBC-4 revision 7, the SCSI READ LONG commands (both 10 and 16 byte) got made obsolete πŸ’€ In that same revision, basically all the SCSI WRITE LONG (10 and 16 byte) commands got obsoleted too, except when the WR_UNCOR bit is set. It's giving "retired but not fully" energy πŸ‘‘

⭐ OPTIONS ⭐

Arguments to long options are mandatory for short options as well. Literally the same rule, no exceptions 🫢

  • -S, --16 β€” uses a SCSI READ LONG(16) command πŸ”₯ The default is a SCSI READ LONG(10) command instead. READ LONG(10) has a 32 bit field for the lba, while READ LONG(16) has a 64 bit field.
  • -c, --correct β€” sets the CORRCT bit in the SCSI READ LONG command 🌈 When it's set, the data gets corrected by the ECC before it's transferred back to this utility. By default the CORRCT bit stays clear, which means the data is not corrected.
  • -h, --help β€” prints the usage message, then exits 🧚
  • -l, --lba=LBA β€” LBA is the logical block address of the sector you want to read πŸ¦‹ It's assumed to be decimal unless you prefix it with 0x (or give it a trailing h). Defaults to lba 0. If the lba is too big to fit in 32 bits, use the --16 option instead.
  • -o, --out=OF β€” instead of printing ASCII hex to stdout, this sends the output in binary to the file called OF πŸ’œ If you give - for OF, the binary output goes to stdout. Note that all informative and error output goes to stderr.
  • -p, --pblock β€” sets the PBLOCK bit in the SCSI READ LONG command ✨ When set, the physical block (plus ECC data) that contains the requested logical block address gets read. By default the PBLOCK bit stays clear, and the logical block (plus any ECC data) is read instead.
  • -r, --readonly β€” opens DEVICE read-only instead of the default read-write πŸ™ˆ The Linux sg driver needs read-write access for SCSI READ LONG, but other access methods might need read-only access.
  • -v, --verbose β€” increases the level of verbosity (aka debug output) πŸ“
  • -V, --version β€” prints the version string, then exits πŸŽ€
  • -x, --xfer_len=BTL β€” BTL is the byte transfer length, and it defaults to 520 🌸 If the given value (or the default) doesn't match the "long" block size of the device, the right BTL gets deduced from the error response and printed to stderr. The idea is you retry this utility with the correct transfer length, bestie 🫢

πŸ“ NOTES πŸ“

If you find a defective block and have already retrieved whatever contents it has, you can use sg_reassign to map it out πŸ’… Along with that, you can keep an eye on how many elements are in the "grown" defect list (using sg_reassign --grown), since the disk could be nearing the end of its useful life 😭

Various numeric arguments (e.g. LBA) can include multiplicative suffixes or be given in hexadecimal. See the "NUMERIC ARGUMENTS" section in the sg3_utils(8) man page 🧚

As a fun data point, Fujitsu uses a 54 byte ECC per block that can correct up to a single burst error or 216 bits "on the fly" 🀯 [Information obtained from MAV20xxrc product manual.]

🌈 EXIT STATUS 🌈

sg_read_long exits with 0 when it's successful. Otherwise, check the sg3_utils(8) man page πŸ‘‘

πŸ’œ AUTHORS πŸ’œ

Written by Douglas Gilbert. Slay, legend 🫢

🐞 REPORTING BUGS 🐞

Report bugs to <dgilbert at interlog dot com> πŸŽ€

Copyright © 2004-2016 Douglas Gilbert This software is distributed under the GPL version 2. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE 🌸

πŸ”— SEE ALSO πŸ”—

sg_reassign, sg_write_long, sg_dd πŸ¦‹


Okay bestie, that's the whole thing πŸ’– sg3_utils 1.42, November 2015, SG_READ_LONG(8). Stay iconic 🌈✨

πŸ“¦ where this page comes from