At a minimum, you need to supply the transfer length in addition to your other arguments:
sg_write_same --32 --lba=2468 --in=sg_modes.c --xferlen=512 /dev/sda
You may also find that your device doesn't support WRITE SAME(32). Try the --16 or --10 variants if it looks like it's not working.
WRITE_SAME writes a number of copies of the input data. In the example above, it's only writing one copy of the first logical block (512 bytes). There is an implicit (default) --num=1
when you run the command. If you want it to write the entire file, you'll have to specify --xferlen
equal to the size of the source file, and then divide by 512 to get the value for --num
. It's unlikely that it's evenly divisible by 512, however, so you'll have some head scratching to do.
By way of example, you can write 8 copies of the first 512 bytes of the file, starting at lba 2468, like this:
sg_write_same -v --32 --lba=2468 --num=8 --xferlen=512 --in=sg_modes.c /dev/sda
Then you should be able to observe the start of the file when you read at LBA 2468, 2469, 2470, and so on.
If, however, your intent is simply to write the file once, you probably just want regular old SCSI WRITE (16).