diff options
author | Bart Van Assche <bvanassche@google.com> | 2022-11-23 18:56:18 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-11-23 18:56:18 +0000 |
commit | 71b9916bab71328ec690b8677524e512d580d28f (patch) | |
tree | 207cdb23f8257e270a30143fde23d2033901581f /examples/sg_compare_and_write.txt | |
parent | 8718296061e35ba33bf88847e7498f3d7e38f8f1 (diff) | |
parent | 448b67b18a80f8cc0feaaa669deaf169faa169f3 (diff) | |
download | sg3_utils-71b9916bab71328ec690b8677524e512d580d28f.tar.gz |
Merge remote-tracking branch 'aosp/upstream-main' into HEAD am: 448b67b18a
Original change: https://android-review.googlesource.com/c/platform/external/sg3_utils/+/2312210
Change-Id: I9653250a81928fffacf92bb5d9daffbc0ad7b2a8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'examples/sg_compare_and_write.txt')
-rw-r--r-- | examples/sg_compare_and_write.txt | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/examples/sg_compare_and_write.txt b/examples/sg_compare_and_write.txt new file mode 100644 index 00000000..86b166b3 --- /dev/null +++ b/examples/sg_compare_and_write.txt @@ -0,0 +1,67 @@ +# sg_compare_and_write.txt +# This file provides a usage example of sg_compare_and_write. +# sg_compare_and_write accepts a buffer containing 2 logical instances: +# - the verify instance: used to match the current content of the LBA range +# - the write instance: used to write to the LBA if the verify succeeds +# +# In case of failure to verify the data, the command will return with check +# condition with the sense code set to MISCOMPARE DURING VERIFY OPERATION. +# +# The following example shows initialization, successful and unsuccessful +# compare and write using sg3_utils. I am using caw_buf_zero2one and +# caw_buf_one2zero as shown below. + +$ hexdump /tmp/caw_buf_zero2one +0000000 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000200 1111 1111 1111 1111 1111 1111 1111 1111 +* +0000400 + +$ hexdump /tmp/caw_buf_one2zero +0000000 1111 1111 1111 1111 1111 1111 1111 1111 +* +0000200 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000400 + +$ sg_map -i -x +/dev/sg0 0 0 0 0 0 /dev/sda ATA ST3320613AS CC2H +/dev/sg1 3 0 0 0 5 /dev/scd0 HL-DT-ST DVD-RAM GH22NS30 1.01 +/dev/sg2 5 0 0 0 0 /dev/sdb KMNRIO K2 0000 +/dev/sg3 5 0 0 1 0 /dev/sdc KMNRIO K2 0000 + +# First I zero out the volume to make sure that the first compare and write +# will succeed +$ sg_write_same --16 -i /dev/zero -n 0x200000 -x 512 /dev/sdc + +$ dd if=/dev/sdc bs=512 count=1 skip=100 2>/dev/null | hexdump +0000000 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000200 + +$ ./sg_compare_and_write --in=/tmp/caw_buf_zero2one --lba=100 --xferlen=1024 /dev/sdc + +# contents of LBA 100 are a block of ones +$ dd if=/dev/sdc bs=512 count=1 skip=100 2>/dev/null | hexdump +0000000 1111 1111 1111 1111 1111 1111 1111 1111 +* +0000200 + +# We repeat the same compare and write command (zero2one input buffer). +# compare and write fails since the verify failed (compared the zero block to +# the actual 1 block in LBA 100 +$ ./sg_compare_and_write --in=/tmp/caw_buf_zero2one --lba=100 --xferlen=1024 /dev/sdc +COMPARE AND WRITE: Fixed format, current; Sense key: Miscompare + Additional sense: Miscompare during verify operation +sg_compare_and_write: SCSI COMPARE AND WRITE failed + +# Now we use the second buffer (one2zero) +$ ./sg_compare_and_write --in=/tmp/caw_buf_one2zero --lba=100 --xferlen=1024 /dev/sdc + +# operation succeeded, contents of LBA 100 are back to zero +$ dd if=/dev/sdc bs=512 count=1 skip=100 2>/dev/null | hexdump +0000000 0000 0000 0000 0000 0000 0000 0000 0000 +* +0000200 + |