{
    "mode": "man",
    "parameter": "sg_write_verify",
    "section": "8",
    "url": "https://www.chedong.com/phpMan.php/man/sg_write_verify/8/json",
    "generated": "2026-06-14T13:02:55Z",
    "synopsis": "sgwriteverify  [--16]  [--bytchk=BC]  [--dpo] [--group=GN] [--help] [--ilen=ILEN] [--in=IF]\n--lba=LBA [--num=NUM] [--repeat] [--timeout=TO] [--verbose] [--version] [--wrprotect=WP]  DE‐\nVICE",
    "sections": {
        "NAME": {
            "content": "sgwriteandverify - send the SCSI WRITE AND VERIFY command\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "sgwriteverify  [--16]  [--bytchk=BC]  [--dpo] [--group=GN] [--help] [--ilen=ILEN] [--in=IF]\n--lba=LBA [--num=NUM] [--repeat] [--timeout=TO] [--verbose] [--version] [--wrprotect=WP]  DE‐\nVICE\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Send  a  SCSI WRITE AND VERIFY (10) or (16) command to DEVICE. The data to be written is read\nfrom the IF file or, in its absence, a buffer full of 0xff bytes is used. The length  of  the\ndata-out  buffer sent with the command is ILEN bytes or, if that is not given, then it is the\nlength of the IF file.\n\nThe write operation is to the DEVICE's medium (optionally to its cache) starting  at  logical\nblock  address  LBA  for NUM logical blocks.  After the write to medium is performed a verify\noperation takes place which may viewed as a medium read (with appropriate checks) but without\nthe  data  being  returned.  Additionally,  if  BS is set to one, the data read back from the\nmedium in the verify operation is compared to the original data-out buffer.\n\nThe relationship between the number of logical blocks to  be  written  (i.e.   NUM)  and  the\nlength  (in bytes) of the data-out buffer (i.e.  ILEN) may be simply found by multiplying the\nformer by the logical block size. However if the DEVICE has protection information (PI)  then\nit becomes a bit more complicated. Hence the calculation is left to the user with the default\nILEN, in the absence of the IF file, being set to NUM * 512.\n\nFor sending large amounts of data to contiguous logical blocks, a  single  WRITE  AND  VERIFY\ncommand  may not be appropriate (e.g. due to operating system limitations). In such cases see\nthe REPEAT section below.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "Arguments to long options are mandatory for short options as well.  The options are  arranged\nin alphabetical order based on the long option name.\n",
            "subsections": [
                {
                    "name": "-S --16",
                    "content": "Send  a  WRITE  AND  VERIFY(16) command. The default is to send a WRITE AND VERIFY(10)\ncommand unless LBA or NUM are too large for the 10 byte variant.\n",
                    "flag": "-S",
                    "long": "--16"
                },
                {
                    "name": "-b --bytchk",
                    "content": "where BC is the value to place in the command's BYTCHK field. Values between 0  and  3\n(inclusive)  are accepted. The default is value is 0 which implies only a write to the\nmedium then a verify operation are performed. The only other value  T10  defines  cur‐\nrently  is  1 which does performs an additional comparison between the data-out buffer\nthat was used by the write operation and the contents of the logical blocks read  back\nfrom the medium.\n",
                    "flag": "-b",
                    "long": "--bytchk"
                },
                {
                    "name": "-d --dpo",
                    "content": "Set the DPO (disable page out) bit in the command. The default is to leave it clear.\n",
                    "flag": "-d",
                    "long": "--dpo"
                },
                {
                    "name": "-g --group",
                    "content": "where  GN is the value to place in the command's GROUP NUMBER field.  Values between 0\nand 31 (inclusive) are accepted. The default is value is 0.\n",
                    "flag": "-g",
                    "long": "--group"
                },
                {
                    "name": "-h --help",
                    "content": "output the usage message then exit.\n",
                    "flag": "-h",
                    "long": "--help"
                },
                {
                    "name": "-I --ilen",
                    "content": "where ILEN is the number of bytes that will be placed in the data-out buffer.  If  the\nIF  file is given then no more than ILEN bytes are read from that file. If the IF file\ndoes not contain ILEN bytes then an error is reported. If the  IF file  is  not  given\nthen a data-out buffer with ILEN bytes of 0xff is sent.\n",
                    "flag": "-I",
                    "long": "--ilen"
                },
                {
                    "name": "-i --in",
                    "content": "read data (binary) from file named IF. If IF is \"-\" then stdin is used. This data will\nbecome the data-out buffer and will be written to the DEVICE's medium. If BC is 1 then\nthat data-out buffer will be held until after the verify operation and compared to the\ndata read back from the medium.\n",
                    "flag": "-i",
                    "long": "--in"
                },
                {
                    "name": "-l --lba",
                    "content": "where LBA is the logical block address to start the write to medium.  Assumed to be in\ndecimal unless prefixed with '0x' or has a trailing 'h'.  Must be provided.\n",
                    "flag": "-l",
                    "long": "--lba"
                },
                {
                    "name": "-n --num",
                    "content": "where  NUM  is  the number of blocks, starting at LBA, to write to the medium. The de‐\nfault value for NUM is 1.\n",
                    "flag": "-n",
                    "long": "--num"
                },
                {
                    "name": "-R --repeat",
                    "content": "this option will continue to do WRITE AND VERIFY commands until the  IF  file  is  ex‐\nhausted.  This  option  requires both the --ilen=ILEN and --in=IF options to be given.\nEach command starts at the next logical block address and is  for  no  more  than  NUM\nblocks.  The last command may be shorter with the number of blocks scaled as required.\nIf there are residue bytes a warning is sent to stderr. See the REPEAT section.\n",
                    "flag": "-R",
                    "long": "--repeat"
                },
                {
                    "name": "-t --timeout",
                    "content": "where TO is the command timeout value in seconds. The default value is 60 seconds.  If\nNUM  is  large then command may require considerably more time than 60 seconds to com‐\nplete.\n",
                    "flag": "-t",
                    "long": "--timeout"
                },
                {
                    "name": "-v --verbose",
                    "content": "increase the degree of verbosity (debug messages).\n",
                    "flag": "-v",
                    "long": "--verbose"
                },
                {
                    "name": "-V --version",
                    "content": "output version string then exit.\n",
                    "flag": "-V",
                    "long": "--version"
                },
                {
                    "name": "-w --wrprotect",
                    "content": "set the WRPROTECT field in the cdb to WP. The default value is 0 which implies no pro‐\ntection information is sent (along with the user data) in the data-out buffer.\n",
                    "flag": "-w",
                    "long": "--wrprotect"
                }
            ]
        },
        "REPEAT": {
            "content": "For  data  sizes  around  a  megabyte and larger, it may be appropriate to send multiple SCSI\nWRITE AND VERIFY commands due to operating system limitations (e.g. pass-through SCSI  inter‐\nfaces often limit the amount of data that can be passed with a SCSI command). With this util‐\nity the mechanism for doing that is the --repeat option.\n\nIn this mode the --ilen=ILEN and --in=IF options must be given. The ILEN and NUM  values  are\ntreated as a per SCSI command parameters. Up to ILEN bytes will be read from the IF file con‐\ntinually until it is exhausted. If the IF file is stdin, reading continues until  an  EOF  is\ndetected.  The  data read from each iteration becomes the data-out buffer for a new WRITE AND\nVERIFY command.\n\nThe last read from the file (or stdin) may read less than ILEN bytes in which case the number\nof logical blocks sent to the last WRITE AND VERIFY is scaled back accordingly. If there is a\nresidual number of bytes left after that scaling then that is reported to stderr.\n\nIf an error occurs then that is reported to stderr and via the exit status  and  the  utility\nstops at that point.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "Other  SCSI WRITE commands have a Force Unit Access (FUA) bit but that is set (implicitly) by\nWRITE AND VERIFY commands hence there is no option to set it. The data-out buffer  may  still\nadditionally  be  placed  in  the  DEVICE's cache and setting the DPO bit is a hint not to do\nthat.\n\nNormal SCSI WRITEs can be done with the ddpt and the sgdd utilities.  The  SCSI  WRITE  SAME\ncommand  can  be done with the sgwritesame utility while the SCSI COMPARE AND WRITE command\n(sgcompareandwrite utility) offers a \"test and set\" facility.\n\nVarious numeric arguments (e.g. LBA) may include multiplicative suffixes or be given in hexa‐\ndecimal. See the \"NUMERIC ARGUMENTS\" section in the sg3utils(8) man page.\n",
            "subsections": []
        },
        "EXIT STATUS": {
            "content": "The  exit status of sgwriteverify is 0 when it is successful. If the verify operation fails\nthat is typically indicated with a medium error which leads to an exit status of 3.\n\nIf BC is set to 1 and the comparison it causes fails this utility will indicate  the  miscom‐\npare  with  an exit status of 14. For other exit status values see the EXIT STATUS section in\nthe sg3utils(8) man page.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "To start with, a simple example: write 1 block of data held in file t.bin that is  512  bytes\nlong then write that block to LBA 0x1234 on /dev/sg4 .\n\n# sgwriteverify --lba=0x1234 --in=t.bin /dev/sg4\n\nSince  '--num='  is  not given then it defaults to 1. Further the ILEN value is obtained from\nthe file size of t.bin . To additionally do a data-out comparison to the read back data:\n\n# sgwriteverify -l 0x1234 -i t.bin --bytchk=1 /dev/sg4\n\nThe ddpt command can do copies between SCSI devices using READ and WRITE  commands.  However,\ncurrently  it  has  no facility to promote those WRITES to WRITE AND VERIFY commands. Using a\npipe, that could be done like this:\n\n# ddpt if=/dev/sg2 bs=512 bpt=8 count=11 of=- |\nsgwriteverify --in=- -l 0x567 -n 8 --ilen=4096 --repeat /dev/sg4\n\nBoth ddpt and sgwriteverify are configured for segments of 8 512 byte logical blocks. Since\n11  logical  blocks are read then first 8 logical blocks are copied followed by a copy of the\nremaining 3 blocks. Since it is assumed that there is  no  protection  information  then  the\ndata-in  and  data-out  buffers will be 4096 bytes each. For sgwriteverify this needs to be\nstated explicitly with the --ilen=4096 option.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "Bruno Goncalves and Douglas Gilbert.\n",
            "subsections": []
        },
        "REPORTING BUGS": {
            "content": "Report bugs to <dgilbert at interlog dot com>.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright © 2014-2018 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",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "ddpt(in a package of that name), sgcompareandwrite(8), sgdd(8), sgwritesame(8)\n\n\n\nsg3utils-1.43                                June 2018                          WRITE AND VERIFY(8)",
            "subsections": []
        }
    },
    "summary": "sgwriteandverify - send the SCSI WRITE AND VERIFY command",
    "flags": [
        {
            "flag": "-S",
            "long": "--16",
            "arg": null,
            "description": "Send a WRITE AND VERIFY(16) command. The default is to send a WRITE AND VERIFY(10) command unless LBA or NUM are too large for the 10 byte variant."
        },
        {
            "flag": "-b",
            "long": "--bytchk",
            "arg": null,
            "description": "where BC is the value to place in the command's BYTCHK field. Values between 0 and 3 (inclusive) are accepted. The default is value is 0 which implies only a write to the medium then a verify operation are performed. The only other value T10 defines cur‐ rently is 1 which does performs an additional comparison between the data-out buffer that was used by the write operation and the contents of the logical blocks read back from the medium."
        },
        {
            "flag": "-d",
            "long": "--dpo",
            "arg": null,
            "description": "Set the DPO (disable page out) bit in the command. The default is to leave it clear."
        },
        {
            "flag": "-g",
            "long": "--group",
            "arg": null,
            "description": "where GN is the value to place in the command's GROUP NUMBER field. Values between 0 and 31 (inclusive) are accepted. The default is value is 0."
        },
        {
            "flag": "-h",
            "long": "--help",
            "arg": null,
            "description": "output the usage message then exit."
        },
        {
            "flag": "-I",
            "long": "--ilen",
            "arg": null,
            "description": "where ILEN is the number of bytes that will be placed in the data-out buffer. If the IF file is given then no more than ILEN bytes are read from that file. If the IF file does not contain ILEN bytes then an error is reported. If the IF file is not given then a data-out buffer with ILEN bytes of 0xff is sent."
        },
        {
            "flag": "-i",
            "long": "--in",
            "arg": null,
            "description": "read data (binary) from file named IF. If IF is \"-\" then stdin is used. This data will become the data-out buffer and will be written to the DEVICE's medium. If BC is 1 then that data-out buffer will be held until after the verify operation and compared to the data read back from the medium."
        },
        {
            "flag": "-l",
            "long": "--lba",
            "arg": null,
            "description": "where LBA is the logical block address to start the write to medium. Assumed to be in decimal unless prefixed with '0x' or has a trailing 'h'. Must be provided."
        },
        {
            "flag": "-n",
            "long": "--num",
            "arg": null,
            "description": "where NUM is the number of blocks, starting at LBA, to write to the medium. The de‐ fault value for NUM is 1."
        },
        {
            "flag": "-R",
            "long": "--repeat",
            "arg": null,
            "description": "this option will continue to do WRITE AND VERIFY commands until the IF file is ex‐ hausted. This option requires both the --ilen=ILEN and --in=IF options to be given. Each command starts at the next logical block address and is for no more than NUM blocks. The last command may be shorter with the number of blocks scaled as required. If there are residue bytes a warning is sent to stderr. See the REPEAT section."
        },
        {
            "flag": "-t",
            "long": "--timeout",
            "arg": null,
            "description": "where TO is the command timeout value in seconds. The default value is 60 seconds. If NUM is large then command may require considerably more time than 60 seconds to com‐ plete."
        },
        {
            "flag": "-v",
            "long": "--verbose",
            "arg": null,
            "description": "increase the degree of verbosity (debug messages)."
        },
        {
            "flag": "-V",
            "long": "--version",
            "arg": null,
            "description": "output version string then exit."
        },
        {
            "flag": "-w",
            "long": "--wrprotect",
            "arg": null,
            "description": "set the WRPROTECT field in the cdb to WP. The default value is 0 which implies no pro‐ tection information is sent (along with the user data) in the data-out buffer."
        }
    ],
    "examples": [
        "To start with, a simple example: write 1 block of data held in file t.bin that is  512  bytes",
        "long then write that block to LBA 0x1234 on /dev/sg4 .",
        "# sgwriteverify --lba=0x1234 --in=t.bin /dev/sg4",
        "Since  '--num='  is  not given then it defaults to 1. Further the ILEN value is obtained from",
        "the file size of t.bin . To additionally do a data-out comparison to the read back data:",
        "# sgwriteverify -l 0x1234 -i t.bin --bytchk=1 /dev/sg4",
        "The ddpt command can do copies between SCSI devices using READ and WRITE  commands.  However,",
        "currently  it  has  no facility to promote those WRITES to WRITE AND VERIFY commands. Using a",
        "pipe, that could be done like this:",
        "# ddpt if=/dev/sg2 bs=512 bpt=8 count=11 of=- |",
        "sgwriteverify --in=- -l 0x567 -n 8 --ilen=4096 --repeat /dev/sg4",
        "Both ddpt and sgwriteverify are configured for segments of 8 512 byte logical blocks. Since",
        "11  logical  blocks are read then first 8 logical blocks are copied followed by a copy of the",
        "remaining 3 blocks. Since it is assumed that there is  no  protection  information  then  the",
        "data-in  and  data-out  buffers will be 4096 bytes each. For sgwriteverify this needs to be",
        "stated explicitly with the --ilen=4096 option."
    ],
    "see_also": [
        {
            "name": "sgcompareandwrite",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/sgcompareandwrite/8/json"
        },
        {
            "name": "sgdd",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/sgdd/8/json"
        },
        {
            "name": "sgwritesame",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/sgwritesame/8/json"
        },
        {
            "name": "VERIFY",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/VERIFY/8/json"
        }
    ]
}