scsi-compare-and-write · shipping · also SCSI atomic compare and write

SCSI COMPARE AND WRITE

SCSI COMPARE AND WRITE conditionally replaces a logical-block range when its contents match supplied comparison data, performing comparison and conditional replacement as one uninterrupted operation.

Related Observatory article: SCSI COMPARE AND WRITE on hesela.com

The host supplies expected and replacement buffers for the same LBA range; a mismatch reports MISCOMPARE without performing the replacement. The device executes comparison and conditional writing without interruption, unlike separate host read and write commands. [1]

The Block Limits VPD page reports MAXIMUM COMPARE AND WRITE LENGTH in logical blocks. A zero value in this field means the command is unsupported; a nonzero value is the largest accepted block count, not a byte count. [2]

The documented sg_compare_and_write utility calculates its default data-out length assuming 512 bytes per logical block, without querying READ CAPACITY. Other block sizes and protection-information settings require appropriate transfer sizing. [1]

In the pinned sg3_utils implementation, MISCOMPARE with valid sense Information reports the first differing byte offset; without valid Information it reports a mismatch without an offset. This byte offset is not a failing LBA. [3]

Hesela's interpretation: this conditional block update does not by itself make a multi-command workflow transactional or establish its power-loss durability; those require separate persistence and recovery contracts.

Relations

related
Compare-and-swap, NVMe Compare and Write, Conditional write, Force Unit Access, Logical block address, SCSI Information field

Citations

  1. sg3_utils: sg_compare_and_write manual, DESCRIPTION and OPTIONS; source commit 8799caa3741b2b1640970747aeb84f17dbbaad86. (accessed 2026-11-08)
  2. Seagate SCSI Commands Reference Manual, 100293068 Rev. L, November 2020, section 5.4.5, Table 520 and page 534. (accessed 2026-11-08)
  3. sg3_utils: sg_compare_and_write.c, scsi_compare_and_write MISCOMPARE branch; commit 8799caa3741b2b1640970747aeb84f17dbbaad86. (accessed 2026-11-08)
Sources & caveats
  • Source-based command explanation, not a device conformance or power-failure test.
  • The sg3_utils source is commit-pinned; its manpage header is not treated as the current package version.
  • Seagate Rev. L is used for the Block Limits VPD field, not as evidence that every SCSI device implements the optional command.

JSON: /data/terms/scsi-compare-and-write.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. SCSI COMPARE AND WRITE. Hesela. 2026-11-08. https://hesela.dev/terms/scsi-compare-and-write/