Confusion in disk write operation using DD command

455 views Asked by At



I am developing a low level SATA driver for an FPGA based embedded system. The driver is running fine.

When I read sectors from the disk using dd command, I can see that the SCSI read(10) command (opcode 0x28) is recived by my low level driver, which is I think correct. But, when I write sectors to the disk using dd command, the SCSI driver sends first read(10) command (opcode 0x28) for several times and then few write(10) commands (opcode 0x2A).

Can someone explain me, that why does SCSI driver send read() command during the write operation?


Edited: During a file write operation I can see that the driver first reads (DMA mode) from LBA 0 upto some 8 sectors. Then it writes (DMA) sg blocks and then it reads (PIO) disk specific information. After that it takes some random LBAs and performs several reads(DMA) finally it stops by reading device specific data read(PIO). This is a sequence for dd'ing 1KB file. The disk has no partition table and no file system (verified from fdisk utility ). Is it a normal behaviour of driver? If yes then is it not decreasing the speed of operation? As overall file reading is faster than writing due to extra reads in write operation.

Thank you

1

There are 1 answers

1
Mike Andrews On

It's hard to say concretely without knowing more about your system. Two possibilities come to mind:

  1. Linux is looking for partition tables. This is likely the case if the reads are to LBA 0 and the first few logical blocks, or if the reads are to the very end of the device, where there is a secondary GPT header.

  2. You're dd'ing a file on a filesystem, and the filesystem is reading in uncached metadata.