1

I am writing a file at particular lba with sg_write_same command. Then i am reading the particular block with the dd command. I am unable to retrieve the file. Here are the sequence of steps i follow.

a> sg_write_same --32 --lba=2468 --in=sg_modes.c /dev/sda
b> dd if=/dev/sda skip=2468 bs=512 of=file  count=10000.

But i can't retrieve the file sg_modes.c in of=file. #Please let me know how i can verify the writes and read.

Bussller
  • 1,961
  • 6
  • 36
  • 50

1 Answers1

0

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).

Mike Andrews
  • 3,045
  • 18
  • 28